Github user geomacy commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/690#discussion_r118445933
  
    --- Diff: 
core/src/main/java/org/apache/brooklyn/location/byon/ByonLocationResolver.java 
---
    @@ -152,49 +153,55 @@ protected ConfigBag extractConfig(Map<?,?> 
locationFlags, String spec, LocationR
             
             String osFamily = (String) 
machineConfig.remove(OS_FAMILY.getName());
             String ssh = (String) machineConfig.remove("ssh");
    -        String winrm = (String) machineConfig.remove("winrm");
    -        Map<Integer, String> tcpPortMappings = (Map<Integer, String>) 
machineConfig.get("tcpPortMappings");
    -        
    -        checkArgument(ssh != null ^ winrm != null, "Must specify exactly 
one of 'ssh' or 'winrm' for machine: %s", valSanitized);
    -        
    -        UserAndHostAndPort userAndHostAndPort;
    -        String host;
    -        int port;
    -        if (ssh != null) {
    -            userAndHostAndPort = parseUserAndHostAndPort(ssh, 22);
    +        if (machineConfig.containsKey("winrm") && 
!(machineConfig.get("winrm") instanceof String)) {
    +            machineConfig.put("address", machineConfig.get("winrm"));
    +            machineConfig.remove("winrm");
             } else {
    -            // TODO set to null and rely on the MachineLocation. If not 
then make a dependency to WinRmMachineLocation and use its config key name.
    -            userAndHostAndPort = parseUserAndHostAndPort(winrm, 
vals.get("winrm.useHttps") != null && (Boolean)vals.get("winrm.useHttps") ? 
5986 : 5985);
    -        }
    -        
    -        // If there is a tcpPortMapping defined for the connection-port, 
then use that for ssh/winrm machine
    -        port = userAndHostAndPort.getHostAndPort().getPort();
    -        if (tcpPortMappings != null && tcpPortMappings.containsKey(port)) {
    -            String override = tcpPortMappings.get(port);
    -            HostAndPort hostAndPortOverride = 
HostAndPort.fromString(override);
    -            if (!hostAndPortOverride.hasPort()) {
    -                throw new IllegalArgumentException("Invalid portMapping 
('"+override+"') for port "+port+" in "+specForErrMsg);
    +            String winrm = (String) machineConfig.remove("winrm");
    +
    +            Map<Integer, String> tcpPortMappings = (Map<Integer, String>) 
machineConfig.get("tcpPortMappings");
    +
    +            checkArgument(ssh != null ^ winrm != null, "Must specify 
exactly one of 'ssh' or 'winrm' for machine: %s", valSanitized);
    +
    +            UserAndHostAndPort userAndHostAndPort;
    +            String host;
    +            int port;
    +            if (ssh != null) {
    +                userAndHostAndPort = parseUserAndHostAndPort(ssh, 22);
    +            } else {
    +                // TODO set to null and rely on the MachineLocation. If 
not then make a dependency to WinRmMachineLocation and use its config key name.
    +                userAndHostAndPort = parseUserAndHostAndPort(winrm, 
vals.get("winrm.useHttps") != null && (Boolean)vals.get("winrm.useHttps") ? 
5986 : 5985);
                 }
    -            port = hostAndPortOverride.getPort();
    -            host = hostAndPortOverride.getHostText().trim();
    -        } else {
    -            host = 
userAndHostAndPort.getHostAndPort().getHostText().trim();
    -        }
    -        
    -        machineConfig.put("address", host);
    -        try {
    -            InetAddress.getByName(host);
    -        } catch (Exception e) {
    -            throw new IllegalArgumentException("Invalid host '"+host+"' 
specified in '"+specForErrMsg+"': "+e);
    -        }
     
    -        if (userAndHostAndPort.getUser() != null) {
    -            checkArgument(!vals.containsKey("user"), "Must not specify 
user twice for machine: %s", valSanitized);
    -            machineConfig.put("user", userAndHostAndPort.getUser());
    -        }
    -        if (userAndHostAndPort.getHostAndPort().hasPort()) {
    -            checkArgument(!vals.containsKey("port"), "Must not specify 
port twice for machine: %s", valSanitized);
    -            machineConfig.put("port", port);
    +            // If there is a tcpPortMapping defined for the 
connection-port, then use that for ssh/winrm machine
    +            port = userAndHostAndPort.getHostAndPort().getPort();
    +            if (tcpPortMappings != null && 
tcpPortMappings.containsKey(port)) {
    --- End diff --
    
    I would do this `if` in a separate method, this one is long enough already!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to