org.jclouds.compute.domain.NodeMetadata Java Examples

The following examples show how to use org.jclouds.compute.domain.NodeMetadata. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultConnectivityResolver.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected Iterable<String> getResolvableAddressesWithMode(NodeMetadata node) {
    Iterable<String> base;
    switch (getNetworkMode()) {
    case ONLY_PRIVATE:
        base = node.getPrivateAddresses();
        break;
    case ONLY_PUBLIC:
        base = node.getPublicAddresses();
        break;
    case PREFER_PRIVATE:
        base = Iterables.concat(node.getPrivateAddresses(), node.getPublicAddresses());
        break;
    case PREFER_PUBLIC:
    default:
        base = Iterables.concat(node.getPublicAddresses(), node.getPrivateAddresses());
    }
    return FluentIterable.from(base)
            .filter(new AddressResolvable());
}
 
Example #2
Source File: CloudServersPublish.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
public static Set<? extends NodeMetadata> getPublishedCloudServers(List<String> args) throws IOException {
   CloudServersPublish cloudServersPublish = new CloudServersPublish(args);
   Set<? extends NodeMetadata> nodes = null;

   try {
      nodes = cloudServersPublish.createServer();
      cloudServersPublish.configureAndStartWebserver(nodes);

      return nodes;
   }
   catch (Exception e) {
      e.printStackTrace();
   }
   finally {
      cloudServersPublish.close();
   }

   return nodes;
}
 
Example #3
Source File: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
/**
 * Brings an existing machine with the given details under management.
 * <p/>
 * Note that this method does <b>not</b> call the lifecycle methods of any
 * {@link #getCustomizers(ConfigBag) customizers} attached to this location.
 *
 * @param flags See {@link #registerMachine(ConfigBag)} for a description of required fields.
 * @see #registerMachine(ConfigBag)
 */
@Override
public JcloudsMachineLocation resumeMachine(Map<?, ?> flags) {
    ConfigBag setup = ConfigBag.newInstanceExtending(config().getBag(), flags);
    LOG.info("{} using resuming node matching properties: {}", this, Sanitizer.sanitize(setup));
    ComputeService computeService = getComputeService(setup);
    NodeMetadata node = findNodeOrThrow(setup);
    LOG.debug("{} resuming {}", this, node);
    computeService.resumeNode(node.getId());
    // Load the node a second time once it is resumed to get an object with
    // hostname and addresses populated.
    node = findNodeOrThrow(setup);
    LOG.debug("{} resumed {}", this, node);
    JcloudsMachineLocation registered = registerMachineLocation(setup, node);
    LOG.info("{} resumed and registered {}", this, registered);
    return registered;
}
 
Example #4
Source File: JcloudsLocationUsageTrackingTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Override
protected NodeCreator newNodeCreator() {
    return new AbstractNodeCreator() {
        @Override protected NodeMetadata newNode(String group, Template template) {
            NodeMetadata result = new NodeMetadataBuilder()
                    .id("myNodeId")
                    .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build())
                    .loginPort(serverSocket.getLocalPort())
                    .status(Status.RUNNING)
                    .publicAddresses(ImmutableList.of(serverSocket.getInetAddress().getHostAddress()))
                    .privateAddresses(ImmutableList.of("1.2.3.4"))
                    .imageId(template.getImage().getId())
                    .tags(template.getOptions().getTags())
                    .hardware(includeNodeHardwareMetadata ? template.getHardware() : null)
                    .group(template.getOptions().getGroups().isEmpty() ? "myGroup" : Iterables.get(template.getOptions().getGroups(), 0))
                    .build();
            return result;
        }
    };
}
 
Example #5
Source File: DefaultConnectivityResolverTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
private NodeMetadata newNodeMetadata() {
    return new NodeMetadataBuilder()
            .id("id")
            .backendStatus("backendStatus")
            .credentials(credential)
            .group("group")
            .hostname("hostname")
            .loginPort(22)
            .name("DefaultConnectivityResolverTest")
            .publicAddresses(ImmutableList.of("10.0.0.1", "10.0.0.2"))
            .privateAddresses(ImmutableList.of("192.168.0.1", "192.168.0.2"))
            .status(NodeMetadata.Status.RUNNING)
            .tags(ImmutableList.<String>of())
            .userMetadata(ImmutableMap.<String, String>of())
            .build();
}
 
Example #6
Source File: JcloudsTemplateOptionsStubbedTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Override
protected NodeCreator newNodeCreator() {
    return new AbstractNodeCreator() {
        @Override protected NodeMetadata newNode(String group, Template template) {
            NodeMetadata result = new NodeMetadataBuilder()
                    .id("myid")
                    .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build())
                    .loginPort(22)
                    .status(Status.RUNNING)
                    .publicAddresses(ImmutableList.of("173.194.32.123"))
                    .privateAddresses(ImmutableList.of("172.168.10.11"))
                    .build();
            return result;
        }
    };
}
 
Example #7
Source File: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected String getPrivateHostname(NodeMetadata node, Optional<HostAndPort> sshHostAndPort, Supplier<? extends LoginCredentials> userCredentials, ConfigBag setup) {
    Boolean useMachinePublicAddressAsPrivateAddress = (setup != null) ? setup.get(USE_MACHINE_PUBLIC_ADDRESS_AS_PRIVATE_ADDRESS) : false;
    if(useMachinePublicAddressAsPrivateAddress) {
        LOG.debug("Overriding private hostname as public hostname because config "+ USE_MACHINE_PUBLIC_ADDRESS_AS_PRIVATE_ADDRESS.getName()+" is set to true");
        return getPublicHostname(node, sshHostAndPort, userCredentials, setup);
    }

    String provider = (setup != null) ? setup.get(CLOUD_PROVIDER) : null;
    Boolean lookupAwsHostname = (setup != null) ? setup.get(LOOKUP_AWS_HOSTNAME) : null;
    if (provider == null) provider = getProvider();

    // TODO Discouraged to do cloud-specific things; think of this code for aws as an
    // exceptional situation rather than a pattern to follow. We need a better way to
    // do cloud-specific things.
    if ("aws-ec2".equals(provider) && Boolean.TRUE.equals(lookupAwsHostname)) {
        Maybe<String> result = getHostnameAws(node, sshHostAndPort, userCredentials, setup);
        if (result.isPresent()) return result.get();
    }

    Optional<String> preferredAddress = sshHostAndPort.isPresent() ? Optional.of(sshHostAndPort.get().getHostText()) : Optional.<String>absent();
    return getPrivateHostnameGeneric(node, setup, preferredAddress);
}
 
Example #8
Source File: Ec2Launcher.java    From karamel with Apache License 2.0 6 votes vote down vote up
private void cleanupFailedNodes(Map<NodeMetadata, Throwable> failedNodes) {
  if (failedNodes.size() > 0) {
    Set<String> lostIds = Sets.newLinkedHashSet();
    for (Map.Entry<NodeMetadata, Throwable> lostNode : failedNodes.entrySet()) {
      lostIds.add(lostNode.getKey().getId());
    }
    logger.info(String.format("Destroying failed nodes with ids: %s", lostIds.toString()));
    Set<? extends NodeMetadata> destroyedNodes = context.getComputeService().destroyNodesMatching(
        Predicates.in(failedNodes.keySet()));
    lostIds.clear();
    for (NodeMetadata destroyed : destroyedNodes) {
      lostIds.add(destroyed.getId());
    }
    logger.info("Failed nodes destroyed ;)");
  }
}
 
Example #9
Source File: NovaV3Launcher.java    From karamel with Apache License 2.0 6 votes vote down vote up
public boolean cleanupFailedNodes(Map<NodeMetadata, Throwable> failedNodes) {
  boolean success = false;
  /*/
  if (failedNodes.size() > 0) {
    Set<String> lostIds = Sets.newLinkedHashSet();
    for (Map.Entry<NodeMetadata, Throwable> lostNode : failedNodes.entrySet()) {
      lostIds.add(lostNode.getKey().getId());
    }
    int numberOfNodesToDelete = lostIds.size();
    logger.info(String.format("Destroying failed nodes with ids: %s", lostIds.toString()));
    Set<? extends NodeMetadata> destroyedNodes = novaContext.getComputeService().destroyNodesMatching(
            Predicates.in(failedNodes.keySet()));
    lostIds.clear();
    for (NodeMetadata destroyed : destroyedNodes) {
      lostIds.add(destroyed.getId());
    }
    logger.info("Failed nodes destroyed ;)");
    int numberOfNodesSuccesfullyDeleted = lostIds.size();
    success = numberOfNodesSuccesfullyDeleted == numberOfNodesToDelete;
  } else {
    success = true;
  }*/
  return success;

}
 
Example #10
Source File: NovaLauncher.java    From karamel with Apache License 2.0 6 votes vote down vote up
public static Predicate<NodeMetadata> withPredicate(final Set<String> ids, final Set<String> names,
                                                    final Set<String> groupNames) {
  return new Predicate<NodeMetadata>() {
    @Override
    public boolean apply(NodeMetadata nodeMetadata) {
      String id = nodeMetadata.getId();
      String name = nodeMetadata.getName();
      String group = nodeMetadata.getGroup();
      return ((id != null && ids.contains(id)) || (name != null && names.contains(name) ||
              (group != null && groupNames.contains(group))));
    }

    @Override
    public String toString() {
      return "machines predicate";
    }
  };
}
 
Example #11
Source File: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected void releaseNode(String instanceId) {
    ComputeService computeService;
    try {
        computeService = getComputeService(config().getBag());
        // FIXME revert to computeService.destroyNode(instanceId); once JCLOUDS-1332 gets fixed
        Set<? extends NodeMetadata> destroyed = computeService.destroyNodesMatching(withIds(instanceId));
        LOG.debug("Destroyed nodes %s%n", destroyed);

    } finally {
    /*
        // we don't close the compute service; this means if we provision add'l it is fast;
        // however it also means an explicit System.exit may be needed for termination
        if (computeService != null) {
            try {
                computeService.getContext().close();
            } catch (Exception e) {
                LOG.error "Problem closing compute-service's context; continuing...", e
            }
        }
     */
    }
}
 
Example #12
Source File: JcloudsIaas.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
protected InstanceMetadata createInstanceMetadata(NodeMetadata nodeMetadata) {
    InstanceMetadata instanceMetadata = new InstanceMetadata();
    instanceMetadata.setHostname(nodeMetadata.getHostname());
    instanceMetadata.setImageId(nodeMetadata.getImageId());
    instanceMetadata.setLoginPort(nodeMetadata.getLoginPort());
    if (nodeMetadata.getHardware() != null) {
        instanceMetadata.setHypervisor(nodeMetadata.getHardware().getHypervisor());
        instanceMetadata.setRam(String.valueOf(nodeMetadata.getHardware().getRam()));
    }
    if (nodeMetadata.getOperatingSystem() != null) {
        instanceMetadata.setOperatingSystemName(nodeMetadata.getOperatingSystem().getName());
        instanceMetadata.setOperatingSystemVersion(nodeMetadata.getOperatingSystem().getVersion());
        instanceMetadata.setOperatingSystem64bit(nodeMetadata.getOperatingSystem().is64Bit());
    }
    return instanceMetadata;
}
 
Example #13
Source File: StubbedComputeServiceRegistry.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public NodeMetadata getCreatedNode(String nodeId) {
    for (NodeMetadata node : created) {
        if (node.getId().equals(nodeId)) {
            return node;
        }
    }
    return null;
}
 
Example #14
Source File: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected void setHostnameUpdatingCredentials(ConfigBag setup, NodeMetadata metadata) {
    List<String> usersTried = new ArrayList<String>();

    String originalUser = getUser(setup);
    if (groovyTruth(originalUser)) {
        if (setHostname(setup, metadata, false)) return;
        usersTried.add(originalUser);
    }

    LoginCredentials credentials = metadata.getCredentials();
    if (credentials!=null) {
        if (Strings.isNonBlank(credentials.getUser())) setup.put(USER, credentials.getUser());
        if (Strings.isNonBlank(credentials.getOptionalPrivateKey().orNull())) setup.put(PRIVATE_KEY_DATA, credentials.getOptionalPrivateKey().orNull());
        if (setHostname(setup, metadata, false)) {
            if (originalUser!=null && !originalUser.equals(getUser(setup))) {
                LOG.warn("Switching to cloud-specified user at "+metadata+" as "+getUser(setup)+" (failed to connect using: "+usersTried+")");
            }
            return;
        }
        usersTried.add(getUser(setup));
    }

    for (String u: COMMON_USER_NAMES_TO_TRY) {
        setup.put(USER, u);
        if (setHostname(setup, metadata, false)) {
            LOG.warn("Auto-detected user at "+metadata+" as "+getUser(setup)+" (failed to connect using: "+usersTried+")");
            return;
        }
        usersTried.add(getUser(setup));
    }
    // just repeat, so we throw exception
    LOG.warn("Failed to log in to "+metadata+", tried as users "+usersTried+" (throwing original exception)");
    setup.put(USER, originalUser);
    setHostname(setup, metadata, true);
}
 
Example #15
Source File: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static int getLoginPortOrDefault(NodeMetadata node, int defaultPort) {
    int loginPort = node.getLoginPort();
    if (loginPort > 0) {
        return loginPort;
    }
    return defaultPort;
}
 
Example #16
Source File: JcloudsRebindLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected void runTest(String locSpec, Map<String, ?> obtainFlags) throws Exception {
    JcloudsLocation location = (JcloudsLocation) mgmt().getLocationRegistry().getLocationManaged(locSpec);
    
    JcloudsMachineLocation origMachine = obtainMachine(location, obtainFlags);
    String origHostname = origMachine.getHostname();
    NodeMetadata origNode = origMachine.getNode();
    assertConnectable(origMachine);

    rebind();
    
    // Check the machine is as before; but won't have persisted node+template.
    // We'll be able to re-create the node object by querying the cloud-provider again though.
    JcloudsMachineLocation newMachine = (JcloudsMachineLocation) newManagementContext.getLocationManager().getLocation(origMachine.getId());
    JcloudsLocation newLocation = newMachine.getParent();
    String newHostname = newMachine.getHostname();
    if (newMachine instanceof JcloudsSshMachineLocation) {
        assertFalse(((JcloudsSshMachineLocation)newMachine).getOptionalTemplate().isPresent());
        assertNull(((JcloudsSshMachineLocation)newMachine).peekNode());
    } else if (newMachine instanceof JcloudsWinRmMachineLocation) {
        assertNull(((JcloudsWinRmMachineLocation)newMachine).peekNode());
    } else {
        fail("Unexpected new machine type: machine="+newMachine+"; type="+(newMachine == null ? null : newMachine.getClass()));
    }
    NodeMetadata newNode = newMachine.getOptionalNode().get();
    assertConnectable(newMachine);
    
    assertEquals(newHostname, origHostname);
    assertEquals(origNode.getId(), newNode.getId());
}
 
Example #17
Source File: JcloudsSshMachineLocation.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public String getHostname() {
    // Changed behaviour in Brooklyn 0.9.0. Previously it just did node.getHostname(), which
    // was wrong on some clouds (e.g. vcloud-director, where VMs are often given a random 
    // hostname that does not resolve on the VM and is not in any DNS).
    // Now delegates to jcloudsParent.getPublicHostname(node).
    if (hostname == null) {
        Optional<NodeMetadata> node = getOptionalNode();
        if (node.isPresent()) {
            HostAndPort sshHostAndPort = getSshHostAndPort();
            Supplier<LoginCredentials> creds = getLoginCredentialsSupplier();
            hostname = jcloudsParent.getPublicHostname(node.get(), Optional.of(sshHostAndPort), creds, config().getBag());
            requestPersist();

        } else {
            // Fallback: impl taken (mostly) from jcloudsParent.getPublicHostnameGeneric(NodeMetadata, ConfigBag).
            // But we won't have a node object (e.g. after rebind, and VM has been terminated).
            // We also resort to address.getHostAddress as final fallback.
            if (groovyTruth(getPublicAddresses())) {
                hostname = getPublicAddresses().iterator().next();
            } else if (groovyTruth(getPrivateAddresses())) {
                hostname = getPrivateAddresses().iterator().next();
            } else {
                hostname = getAddress().getHostAddress();
            }
        }
        LOG.debug("Resolved hostname {} for {}", hostname, this);
        requestPersist();
    }
    return hostname;
}
 
Example #18
Source File: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected MachineManagementMixins.MachineMetadata getMachineMetadata(ComputeMetadata node) {
    if (node==null)
        return null;
    return new BasicMachineMetadata(node.getId(), node.getName(),
        ((node instanceof NodeMetadata) ? Iterators.tryFind( ((NodeMetadata)node).getPublicAddresses().iterator(), Predicates.alwaysTrue() ).orNull() : null),
        ((node instanceof NodeMetadata) ? ((NodeMetadata)node).getStatus()==Status.RUNNING : null),
        node);
}
 
Example #19
Source File: JcloudsImageChoiceStubbedLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
protected NodeCreator newNodeCreator() {
    return new BasicNodeCreator() {
        @Override protected NodeMetadata newNode(String group, Template template) {
            JcloudsImageChoiceStubbedLiveTest.this.template = template;
            return super.newNode(group, template);
        }
    };
}
 
Example #20
Source File: CloudDistributedTLCJob.java    From tlaplus with MIT License 5 votes vote down vote up
private void throwExceptionOnErrorResponse(final NodeMetadata node, final ExecResponse execResponse, final String step) {
		// If the script above failed on any number of nodes for whatever reason, don't
		// continue but destroy all nodes.
		if (execResponse.getExitStatus() > 0) {
			throw new ScriptException(node, execResponse, step);
		}
}
 
Example #21
Source File: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected LoginCredentials waitForSshableGuessCredentials(final ComputeService computeService, final NodeMetadata node, HostAndPort managementHostAndPort, ConfigBag setup) {
    // See https://issues.apache.org/jira/browse/BROOKLYN-186
    // Handle where jclouds gives us the wrong login user (!) and both a password + ssh key.
    // Try all the permutations to find the one that works.
    Iterable<LoginCredentials> credentialsToTry = generateCredentials(node.getCredentials(), setup.get(LOGIN_USER));
    return waitForSshable(computeService, node, managementHostAndPort, credentialsToTry, setup);
}
 
Example #22
Source File: JcloudsSshMachineLocation.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated since 0.6; use LocationSpec (which calls no-arg constructor)
 */
@Deprecated
public JcloudsSshMachineLocation(Map<?,?> flags, JcloudsLocation jcloudsParent, NodeMetadata node) {
    super(flags);
    this.jcloudsParent = jcloudsParent;
    
    init();
}
 
Example #23
Source File: JcloudsUtil.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/** @see #getReachableAddresses(NodeMetadata, Duration, Predicate) */
public static String getFirstReachableAddress(NodeMetadata node, Duration timeout, Predicate<? super HostAndPort> socketTester) {
    Iterable<HostAndPort> addresses = getReachableAddresses(node, timeout, socketTester);
    HostAndPort address = Iterables.getFirst(addresses, null);
    if (address != null) {
        return address.getHostText();
    } else {
        throw new IllegalStateException("No reachable IPs for " + node + "; check whether the node is " +
                "reachable and whether it meets the requirements of the HostAndPort tester: " + socketTester);
    }
}
 
Example #24
Source File: JcloudsByonLocationResolverStubbedRebindTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public Set<? extends NodeMetadata> listNodesDetailsMatching(Predicate<? super NodeMetadata> filter) {
    NodeMetadata result = new NodeMetadataBuilder()
            .id(nodeId)
            .credentials(LoginCredentials.builder().identity("dummy").credential("dummy").build())
            .loginPort(22)
            .status(Status.RUNNING)
            .publicAddresses(ImmutableList.of(nodePublicAddress))
            .privateAddresses(ImmutableList.of(nodePrivateAddress))
            .build();
    return ImmutableSet.copyOf(Iterables.filter(ImmutableList.of(result), filter));
}
 
Example #25
Source File: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected JcloudsSshMachineLocation registerJcloudsSshMachineLocation(
        ComputeService computeService, NodeMetadata node, Optional<Template> template,
        LoginCredentials credentials, HostAndPort managementHostAndPort, ConfigBag setup) throws IOException {
    JcloudsSshMachineLocation machine = createJcloudsSshMachineLocation(computeService, node, template, credentials, managementHostAndPort, setup);
    registerJcloudsMachineLocation(node.getId(), machine);
    return machine;
}
 
Example #26
Source File: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected JcloudsWinRmMachineLocation registerWinRmMachineLocation(
        ComputeService computeService, NodeMetadata node, Optional<Template> template,
        LoginCredentials credentials, HostAndPort managementHostAndPort, ConfigBag setup) {
    JcloudsWinRmMachineLocation machine = createWinRmMachineLocation(computeService, node, template, credentials, managementHostAndPort, setup);
    registerJcloudsMachineLocation(node.getId(), machine);
    return machine;
}
 
Example #27
Source File: JcloudsPortForwardingStubbedTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testPortForwardingCallsForwarder() throws Exception {
    PortForwardManager pfm = new PortForwardManagerImpl();
    RecordingJcloudsPortForwarderExtension portForwarder = new RecordingJcloudsPortForwarderExtension(pfm);
    
    JcloudsSshMachineLocation machine = obtainMachine(ImmutableMap.<ConfigKey<?>,Object>of(
            JcloudsLocation.USE_PORT_FORWARDING, true,
            JcloudsLocation.PORT_FORWARDER, portForwarder));
    
    NodeMetadata created = getNodeCreator().created.get(0);
    assertEquals(getNodeCreator().created.size(), 1, "created="+getNodeCreator().created+"; machine="+machine);
    assertEquals(machine.getOptionalNode().get(), created);
    assertEquals(portForwarder.opens.size(), 1, "opens="+portForwarder.opens+"; machine="+machine);
    assertEquals(portForwarder.opens.get(0).get(0), created);
    assertEquals(portForwarder.opens.get(0).get(1), 22);
    assertEquals(portForwarder.opens.get(0).get(3), Protocol.TCP);
    assertEquals(portForwarder.opens.get(0).get(4), Cidr.UNIVERSAL);
    assertEquals(machine.getSshHostAndPort(), HostAndPort.fromParts("1.2.3.4", 12345));
    
    releaseMachine(machine);
    String destroyed = getNodeCreator().destroyed.get(0);
    assertEquals(getNodeCreator().destroyed.size(), 1, "destroyed="+getNodeCreator().destroyed+"; machine="+machine);
    assertEquals(destroyed, created.getId());
    assertEquals(portForwarder.closes.size(), 1, "closes="+portForwarder.closes+"; machine="+machine);
    assertEquals(portForwarder.closes.get(0).get(0), created);
    assertEquals(portForwarder.closes.get(0).get(1), 22);
    assertEquals(portForwarder.closes.get(0).get(2), HostAndPort.fromParts("1.2.3.4", 12345));
    assertEquals(portForwarder.closes.get(0).get(3), Protocol.TCP);
}
 
Example #28
Source File: JcloudsPortForwardingStubbedTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testReleaseVmDoesNotImpactOtherVms() throws Exception {
    PortForwardManager pfm = new PortForwardManagerImpl();
    RecordingJcloudsPortForwarderExtension portForwarder = new RecordingJcloudsPortForwarderExtension(pfm);
    
    JcloudsSshMachineLocation machine1 = obtainMachine(ImmutableMap.<ConfigKey<?>,Object>of(
            JcloudsLocation.USE_PORT_FORWARDING, true,
            JcloudsLocation.PORT_FORWARDER, portForwarder,
            JcloudsLocation.PORT_FORWARDING_MANAGER, pfm));
    
    JcloudsSshMachineLocation machine2 = obtainMachine(ImmutableMap.<ConfigKey<?>,Object>of(
            JcloudsLocation.USE_PORT_FORWARDING, true,
            JcloudsLocation.PORT_FORWARDER, portForwarder,
            JcloudsLocation.PORT_FORWARDING_MANAGER, pfm));
    
    NodeMetadata node1 = getNodeCreator().created.get(0);

    // Add an association for machine2 - expect that not to be touched when machine1 is released.
    HostAndPort publicHostAndPort = HostAndPort.fromParts("1.2.3.4", 1234);
    pfm.associate("mypublicip", publicHostAndPort, machine2, 80);

    // Release machine1
    releaseMachine(machine1);
    
    // Expect machine2 to still be registered
    assertEquals(pfm.lookup(machine2, 80), publicHostAndPort);
    assertEquals(pfm.lookup("mypublicip", 80), publicHostAndPort);
    
    // And no calls to "close" for machine2; just for machine1's port 22
    assertEquals(portForwarder.closes.size(), 1, "closes="+portForwarder.closes+"; machine1="+machine1);
    assertEquals(portForwarder.closes.get(0).get(0), node1);
    assertEquals(portForwarder.closes.get(0).get(1), 22);
}
 
Example #29
Source File: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected Map<String,Object> extractWinrmConfig(ConfigBag setup, NodeMetadata node) {
    ConfigBag nodeConfig = new ConfigBag();
    if (node!=null && node.getCredentials() != null) {
        nodeConfig.putIfNotNull(PASSWORD, node.getCredentials().getOptionalPassword().orNull());
        nodeConfig.putIfNotNull(PRIVATE_KEY_DATA, node.getCredentials().getOptionalPrivateKey().orNull());
    }
    return extractWinrmConfig(setup, nodeConfig).getAllConfig();
}
 
Example #30
Source File: AWSEC2GetNodeMetadataStrategy.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
@Inject
protected AWSEC2GetNodeMetadataStrategy(AWSEC2Api client,
         Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
         SpotInstanceRequestToAWSRunningInstance spotConverter) {
   super(client, runningInstanceToNodeMetadata);
   this.client = checkNotNull(client, "client");
   this.spotConverter = checkNotNull(spotConverter, "spotConverter");
}