Skip to content

Commit 7bffcd6

Browse files
committed
External ip config for winrm byon location
1 parent 3d7a35f commit 7bffcd6

File tree

2 files changed

+59
-46
lines changed

2 files changed

+59
-46
lines changed

camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/WinRmMachineLocationExternalConfigYamlTest.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ protected LocalManagementContext newTestManagementContext() {
4141
BrooklynProperties props = BrooklynProperties.Factory.newEmpty();
4242
props.put("brooklyn.external.inPlaceSupplier1", "org.apache.brooklyn.core.config.external.InPlaceExternalConfigSupplier");
4343
props.put("brooklyn.external.inPlaceSupplier1.byonPassword", "passw0rd");
44+
props.put("brooklyn.external.inPlaceSupplier1.byonUser", "admin");
45+
props.put("brooklyn.external.inPlaceSupplier1.ip", "127.0.0.1");
4446

4547
return LocalManagementContextForTests.builder(true)
4648
.useProperties(props)
@@ -49,13 +51,13 @@ protected LocalManagementContext newTestManagementContext() {
4951
}
5052

5153
@Test()
52-
public void testWindowsMachinesPasswordExternalProvider() throws Exception {
54+
public void testWindowsMachinesExternalProvider() throws Exception {
5355
RecordingWinRmTool.constructorProps.clear();
5456
final String yaml = Joiner.on("\n").join("location:",
5557
" byon:",
5658
" hosts:",
57-
" - winrm: 127.0.0.1",
58-
" user: admin",
59+
" - winrm: $brooklyn:external(\"inPlaceSupplier1\", \"ip\")",
60+
" user: $brooklyn:external(\"inPlaceSupplier1\", \"byonUser\")",
5961
" brooklyn.winrm.config.winrmToolClass: org.apache.brooklyn.util.core.internal.winrm.RecordingWinRmTool",
6062
" password: $brooklyn:external(\"inPlaceSupplier1\", \"byonPassword\")",
6163
" osFamily: windows",
@@ -67,17 +69,19 @@ public void testWindowsMachinesPasswordExternalProvider() throws Exception {
6769

6870
BasicApplication app = (BasicApplication) createAndStartApplication(yaml);
6971
waitForApplicationTasks(app);
72+
assertEquals(RecordingWinRmTool.constructorProps.get(0).get(WinRmMachineLocation.ADDRESS.getName()), "127.0.0.1");
73+
assertEquals(RecordingWinRmTool.constructorProps.get(0).get(WinRmMachineLocation.USER.getName()), "admin");
7074
assertEquals(RecordingWinRmTool.constructorProps.get(0).get(WinRmMachineLocation.PASSWORD.getName()), "passw0rd");
7175
}
7276

7377
@Test()
74-
public void testWindowsMachinesNoPasswordExternalProvider() throws Exception {
78+
public void testWindowsMachinesNoExternalProvider() throws Exception {
7579
RecordingWinRmTool.constructorProps.clear();
7680
final String yaml = Joiner.on("\n").join("location:",
7781
" byon:",
7882
" hosts:",
79-
" - winrm: 127.0.0.1",
80-
" user: admin",
83+
" - winrm: $brooklyn:external(\"inPlaceSupplier1\", \"ipEmpty\")",
84+
" user: $brooklyn:external(\"inPlaceSupplier1\", \"byonUserEmpty\")",
8185
" brooklyn.winrm.config.winrmToolClass: org.apache.brooklyn.util.core.internal.winrm.RecordingWinRmTool",
8286
" password: $brooklyn:external(\"inPlaceSupplier1\", \"byonPasswordddd\")",
8387
" osFamily: windows",
@@ -89,6 +93,8 @@ public void testWindowsMachinesNoPasswordExternalProvider() throws Exception {
8993

9094
BasicApplication app = (BasicApplication) createAndStartApplication(yaml);
9195
waitForApplicationTasks(app);
96+
assertNull(RecordingWinRmTool.constructorProps.get(0).get(WinRmMachineLocation.ADDRESS.getName()));
97+
assertNull(RecordingWinRmTool.constructorProps.get(0).get(WinRmMachineLocation.USER.getName()));
9298
assertNull(RecordingWinRmTool.constructorProps.get(0).get(WinRmMachineLocation.PASSWORD.getName()));
9399
}
94100

core/src/main/java/org/apache/brooklyn/location/byon/ByonLocationResolver.java

+47-40
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.apache.brooklyn.core.config.Sanitizer;
3535
import org.apache.brooklyn.core.location.AbstractLocationResolver;
3636
import org.apache.brooklyn.core.mgmt.internal.LocalLocationManager;
37+
import org.apache.brooklyn.core.objs.BasicConfigurableObject;
3738
import org.apache.brooklyn.util.collections.MutableMap;
3839
import org.apache.brooklyn.util.core.ClassLoaderUtils;
3940
import org.apache.brooklyn.util.core.config.ConfigBag;
@@ -152,49 +153,55 @@ protected LocationSpec<? extends MachineLocation> parseMachine(Map<String, ?> va
152153

153154
String osFamily = (String) machineConfig.remove(OS_FAMILY.getName());
154155
String ssh = (String) machineConfig.remove("ssh");
155-
String winrm = (String) machineConfig.remove("winrm");
156-
Map<Integer, String> tcpPortMappings = (Map<Integer, String>) machineConfig.get("tcpPortMappings");
157-
158-
checkArgument(ssh != null ^ winrm != null, "Must specify exactly one of 'ssh' or 'winrm' for machine: %s", valSanitized);
159-
160-
UserAndHostAndPort userAndHostAndPort;
161-
String host;
162-
int port;
163-
if (ssh != null) {
164-
userAndHostAndPort = parseUserAndHostAndPort(ssh, 22);
156+
if (machineConfig.containsKey("winrm") && !(machineConfig.get("winrm") instanceof String)) {
157+
machineConfig.put("address", machineConfig.get("winrm"));
158+
machineConfig.remove("winrm");
165159
} else {
166-
// TODO set to null and rely on the MachineLocation. If not then make a dependency to WinRmMachineLocation and use its config key name.
167-
userAndHostAndPort = parseUserAndHostAndPort(winrm, vals.get("winrm.useHttps") != null && (Boolean)vals.get("winrm.useHttps") ? 5986 : 5985);
168-
}
169-
170-
// If there is a tcpPortMapping defined for the connection-port, then use that for ssh/winrm machine
171-
port = userAndHostAndPort.getHostAndPort().getPort();
172-
if (tcpPortMappings != null && tcpPortMappings.containsKey(port)) {
173-
String override = tcpPortMappings.get(port);
174-
HostAndPort hostAndPortOverride = HostAndPort.fromString(override);
175-
if (!hostAndPortOverride.hasPort()) {
176-
throw new IllegalArgumentException("Invalid portMapping ('"+override+"') for port "+port+" in "+specForErrMsg);
160+
String winrm = (String) machineConfig.remove("winrm");
161+
162+
Map<Integer, String> tcpPortMappings = (Map<Integer, String>) machineConfig.get("tcpPortMappings");
163+
164+
checkArgument(ssh != null ^ winrm != null, "Must specify exactly one of 'ssh' or 'winrm' for machine: %s", valSanitized);
165+
166+
UserAndHostAndPort userAndHostAndPort;
167+
String host;
168+
int port;
169+
if (ssh != null) {
170+
userAndHostAndPort = parseUserAndHostAndPort(ssh, 22);
171+
} else {
172+
// TODO set to null and rely on the MachineLocation. If not then make a dependency to WinRmMachineLocation and use its config key name.
173+
userAndHostAndPort = parseUserAndHostAndPort(winrm, vals.get("winrm.useHttps") != null && (Boolean)vals.get("winrm.useHttps") ? 5986 : 5985);
177174
}
178-
port = hostAndPortOverride.getPort();
179-
host = hostAndPortOverride.getHostText().trim();
180-
} else {
181-
host = userAndHostAndPort.getHostAndPort().getHostText().trim();
182-
}
183-
184-
machineConfig.put("address", host);
185-
try {
186-
InetAddress.getByName(host);
187-
} catch (Exception e) {
188-
throw new IllegalArgumentException("Invalid host '"+host+"' specified in '"+specForErrMsg+"': "+e);
189-
}
190175

191-
if (userAndHostAndPort.getUser() != null) {
192-
checkArgument(!vals.containsKey("user"), "Must not specify user twice for machine: %s", valSanitized);
193-
machineConfig.put("user", userAndHostAndPort.getUser());
194-
}
195-
if (userAndHostAndPort.getHostAndPort().hasPort()) {
196-
checkArgument(!vals.containsKey("port"), "Must not specify port twice for machine: %s", valSanitized);
197-
machineConfig.put("port", port);
176+
// If there is a tcpPortMapping defined for the connection-port, then use that for ssh/winrm machine
177+
port = userAndHostAndPort.getHostAndPort().getPort();
178+
if (tcpPortMappings != null && tcpPortMappings.containsKey(port)) {
179+
String override = tcpPortMappings.get(port);
180+
HostAndPort hostAndPortOverride = HostAndPort.fromString(override);
181+
if (!hostAndPortOverride.hasPort()) {
182+
throw new IllegalArgumentException("Invalid portMapping ('"+override+"') for port "+port+" in "+specForErrMsg);
183+
}
184+
port = hostAndPortOverride.getPort();
185+
host = hostAndPortOverride.getHostText().trim();
186+
} else {
187+
host = userAndHostAndPort.getHostAndPort().getHostText().trim();
188+
}
189+
190+
machineConfig.put("address", host);
191+
try {
192+
InetAddress.getByName(host);
193+
} catch (Exception e) {
194+
throw new IllegalArgumentException("Invalid host '"+host+"' specified in '"+specForErrMsg+"': "+e);
195+
}
196+
197+
if (userAndHostAndPort.getUser() != null) {
198+
checkArgument(!vals.containsKey("user"), "Must not specify user twice for machine: %s", valSanitized);
199+
machineConfig.put("user", userAndHostAndPort.getUser());
200+
}
201+
if (userAndHostAndPort.getHostAndPort().hasPort()) {
202+
checkArgument(!vals.containsKey("port"), "Must not specify port twice for machine: %s", valSanitized);
203+
machineConfig.put("port", port);
204+
}
198205
}
199206
for (Map.Entry<String, ?> entry : defaults.entrySet()) {
200207
if (!machineConfig.containsKey(entry.getKey())) {

0 commit comments

Comments
 (0)