Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9F6EB200C80 for ; Thu, 25 May 2017 11:31:32 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9E397160BC7; Thu, 25 May 2017 09:31:32 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id ED25D160BD5 for ; Thu, 25 May 2017 11:31:31 +0200 (CEST) Received: (qmail 97097 invoked by uid 500); 25 May 2017 09:31:31 -0000 Mailing-List: contact dev-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list dev@brooklyn.apache.org Received: (qmail 96919 invoked by uid 99); 25 May 2017 09:31:30 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 May 2017 09:31:30 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 16D46E0898; Thu, 25 May 2017 09:31:29 +0000 (UTC) From: geomacy To: dev@brooklyn.apache.org Reply-To: dev@brooklyn.apache.org References: In-Reply-To: Subject: [GitHub] brooklyn-server pull request #690: External ip config for winrm byon locatio... Content-Type: text/plain Message-Id: <20170525093130.16D46E0898@git1-us-west.apache.org> Date: Thu, 25 May 2017 09:31:29 +0000 (UTC) archived-at: Thu, 25 May 2017 09:31:32 -0000 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 tcpPortMappings = (Map) 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 tcpPortMappings = (Map) 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 infrastructure@apache.org or file a JIRA ticket with INFRA. ---