|
34 | 34 | import org.apache.brooklyn.core.config.Sanitizer;
|
35 | 35 | import org.apache.brooklyn.core.location.AbstractLocationResolver;
|
36 | 36 | import org.apache.brooklyn.core.mgmt.internal.LocalLocationManager;
|
| 37 | +import org.apache.brooklyn.core.objs.BasicConfigurableObject; |
37 | 38 | import org.apache.brooklyn.util.collections.MutableMap;
|
38 | 39 | import org.apache.brooklyn.util.core.ClassLoaderUtils;
|
39 | 40 | import org.apache.brooklyn.util.core.config.ConfigBag;
|
@@ -152,49 +153,55 @@ protected LocationSpec<? extends MachineLocation> parseMachine(Map<String, ?> va
|
152 | 153 |
|
153 | 154 | String osFamily = (String) machineConfig.remove(OS_FAMILY.getName());
|
154 | 155 | 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"); |
165 | 159 | } 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); |
177 | 174 | }
|
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 |
| - } |
190 | 175 |
|
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 | + } |
198 | 205 | }
|
199 | 206 | for (Map.Entry<String, ?> entry : defaults.entrySet()) {
|
200 | 207 | if (!machineConfig.containsKey(entry.getKey())) {
|
|
0 commit comments