brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aledsage <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: JcloudsLocation: fix waitForWinRm...
Date Fri, 04 Dec 2015 09:52:12 GMT
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/1087#discussion_r46664936
  
    --- Diff: locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
---
    @@ -2537,28 +2563,53 @@ protected LoginCredentials waitForWinRmAvailable(final ComputeService
computeSer
                 timeout = Duration.parse(WAIT_FOR_WINRM_AVAILABLE.getDefaultValue());
             }
             
    -        String user = expectedCredentials.getUser();
    -        String password = expectedCredentials.getOptionalPassword().orNull();
    -        int vmPort = hostAndPortOverride.isPresent() 
    -                ? hostAndPortOverride.get().getPortOrDefault(5985) 
    -                : 5985; // WinRM port
    -        String vmIp = hostAndPortOverride.isPresent() 
    -                ? hostAndPortOverride.get().getHostText() 
    -                : getFirstReachableAddress(NodeMetadataBuilder.fromNodeMetadata(node).loginPort(vmPort).build(),
setup);
    -
    -        final Session session = WinRMFactory.INSTANCE.createSession(vmIp+":"+vmPort,
user, password);
    -
    +        Set<String> users = Sets.newLinkedHashSet();
    +        for (LoginCredentials creds : credentialsToTry) {
    +            users.add(creds.getUser());
    +        }
    +        String user = (users.size() == 1) ? Iterables.getOnlyElement(users) : "{" + Joiner.on(",").join(users)
+ "}";
    +        String vmIp = hostAndPortOverride.isPresent() ? hostAndPortOverride.get().getHostText()
: getFirstReachableAddress(node, setup);
             if (vmIp==null) LOG.warn("Unable to extract IP for "+node+" ("+setup.getDescription()+"):
subsequent connection attempt will likely fail");
    +        int vmPort = hostAndPortOverride.isPresent() ? hostAndPortOverride.get().getPortOrDefault(5985)
: 5985;
     
    -        Callable<Boolean> checker = new Callable<Boolean>() {
    -            public Boolean call() {
    -                return session.run_cmd("hostname").getStatusCode() == 0;
    -            }};
             String connectionDetails = user + "@" + vmIp + ":" + vmPort;
    +        final HostAndPort hostAndPort = hostAndPortOverride.isPresent() ? hostAndPortOverride.get()
: HostAndPort.fromParts(vmIp, vmPort);
    +        final AtomicReference<LoginCredentials> credsSuccessful = new AtomicReference<LoginCredentials>();
     
    -        waitForReachable(checker, connectionDetails, ImmutableList.of(expectedCredentials),
setup, timeout);
    -        
    -        return expectedCredentials;
    +        // Don't use config that relates to the final user credentials (those have nothing
to do 
    +        // with the initial credentials of the VM returned by the cloud provider).
    +        // The createTemporaryWinRmMachineLocation deals with removing that.
    +        ConfigBag winrmProps = ConfigBag.newInstanceCopying(setup);
    +
    +        final Map<WinRmMachineLocation, LoginCredentials> machinesToTry = Maps.newLinkedHashMap();
    +        for (LoginCredentials creds : credentialsToTry) {
    +            machinesToTry.put(createTemporaryWinRmMachineLocation(hostAndPort, creds,
winrmProps), creds);
    +        }
    +        try {
    +            Callable<Boolean> checker = new Callable<Boolean>() {
    +                public Boolean call() {
    +                    for (Map.Entry<WinRmMachineLocation, LoginCredentials> entry
: machinesToTry.entrySet()) {
    +                        WinRmMachineLocation machine = entry.getKey();
    +                        WinRmToolResponse response = machine.executeScript(
    +                                ImmutableMap.of(WinRmTool.PROP_EXEC_TRIES.getName(),
1), 
    +                                ImmutableList.of("echo testing"));
    +                        boolean success = (response.getStatusCode() == 0);
    +                        if (success) {
    +                            credsSuccessful.set(entry.getValue());
    +                            return true;
    +                        }
    +                    }
    +                    return false;
    +                }};
    +    
    +            waitForReachable(checker, connectionDetails, credentialsToTry, setup, timeout);
    --- End diff --
    
    We want to wait a *very long time* because we might be waiting for the Windows machine
to boot up, download security patches, etc. We start calling this method when the cloud provider
says the VM is "ready", but that mean the OS has booted up.
    
    We wait for 30 minutes by default, with it being configurable using `waitForWinRmAvailable`
(it is 5 minutes for  `waitForSshable`).


---
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.
---

Mime
View raw message