@Override
 public NodeMetadata apply(VirtualGuest from) {
   NodeMetadataBuilder builder = new NodeMetadataBuilder();
   builder.ids(from.getId() + "");
   builder.name(from.getHostname());
   builder.hostname(from.getFullyQualifiedDomainName());
   if (from.getDatacenter() != null) {
     builder.location(
         from(locations.get())
             .firstMatch(LocationPredicates.idEquals(from.getDatacenter().getName()))
             .orNull());
   }
   builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getHostname()));
   builder.hardware(virtualGuestToHardware.apply(from));
   Image image = virtualGuestToImage.apply(from);
   if (image != null) {
     builder.imageId(image.getId());
     builder.operatingSystem(image.getOperatingSystem());
   }
   if (from.getPowerState() != null) {
     builder.status(serverStateToNodeStatus.get(from.getPowerState().getKeyName()));
   }
   if (from.getPrimaryIpAddress() != null)
     builder.publicAddresses(ImmutableSet.of(from.getPrimaryIpAddress()));
   if (from.getPrimaryBackendIpAddress() != null)
     builder.privateAddresses(ImmutableSet.of(from.getPrimaryBackendIpAddress()));
   // TODO simplify once we move domain classes to AutoValue
   if (from.getOperatingSystem() != null
       && from.getOperatingSystem().getPasswords() != null
       && !from.getOperatingSystem().getPasswords().isEmpty()) {
     Password password = getBestPassword(from.getOperatingSystem().getPasswords(), from);
     builder.credentials(
         LoginCredentials.builder()
             .identity(password.getUsername())
             .credential(password.getPassword())
             .build());
   }
   if (from.getTagReferences() != null && !from.getTagReferences().isEmpty()) {
     List<String> tags = Lists.newArrayList();
     for (TagReference tagReference : from.getTagReferences()) {
       if (tagReference != null) {
         tags.add(tagReference.getTag().getName());
       }
     }
     builder.tags(tags);
   }
   return builder.build();
 }
  @Override
  public NodeMetadata apply(final VirtualGuest from) {

    // convert the result object to a jclouds NodeMetadata
    NodeMetadataBuilder builder = new NodeMetadataBuilder();
    builder.ids(from.getId() + "");
    builder.name(from.getHostname());
    builder.hostname(from.getHostname());
    builder.status(serverStateToNodeStatus.get(from.getPowerState().getKeyName()));

    // These are null for 'bad' guest orders in the HALTED state.
    if (from.getPrimaryIpAddress() != null)
      builder.publicAddresses(ImmutableSet.<String>of(from.getPrimaryIpAddress()));
    if (from.getPrimaryBackendIpAddress() != null)
      builder.privateAddresses(ImmutableSet.<String>of(from.getPrimaryBackendIpAddress()));
    return builder.build();
  }
  protected NodeMetadataBuilder buildInstance(
      final RunningInstance instance, NodeMetadataBuilder builder) {
    builder.providerId(instance.getId());
    builder.id(instance.getRegion() + "/" + instance.getId());
    String group = getGroupForInstance(instance);
    builder.group(group);
    // standard convention from aws-ec2, which might not be re-used outside.
    if (instance.getPrivateDnsName() != null)
      builder.hostname(instance.getPrivateDnsName().replaceAll("\\..*", ""));
    addCredentialsForInstance(builder, instance);
    builder.status(instanceToNodeStatus.get(instance.getInstanceState()));
    builder.backendStatus(instance.getRawState());

    // collect all ip addresses into one bundle in case the api mistakenly put a private address
    // into the public address field
    Builder<String> addressesBuilder = ImmutableSet.builder();
    if (Strings.emptyToNull(instance.getIpAddress()) != null)
      addressesBuilder.add(instance.getIpAddress());
    // Add dnsName (if available) to addresses, when the IPAddress is null
    // happens on Eucalyptus sometimes.
    else if (Strings.emptyToNull(instance.getDnsName()) != null)
      addressesBuilder.add(instance.getDnsName());
    if (Strings.emptyToNull(instance.getPrivateIpAddress()) != null)
      addressesBuilder.add(instance.getPrivateIpAddress());

    Set<String> addresses = addressesBuilder.build();

    builder.publicAddresses(filter(addresses, not(IsPrivateIPAddress.INSTANCE)));
    builder.privateAddresses(filter(addresses, IsPrivateIPAddress.INSTANCE));
    builder.hardware(parseHardware(instance));
    Location location = getLocationForAvailabilityZoneOrRegion(instance);
    builder.location(location);
    builder.imageId(instance.getRegion() + "/" + instance.getImageId());

    // extract the operating system from the image
    RegionAndName regionAndName = new RegionAndName(instance.getRegion(), instance.getImageId());
    try {
      Image image = imageMap.get().getUnchecked(regionAndName);
      if (image != null) builder.operatingSystem(image.getOperatingSystem());
    } catch (CacheLoader.InvalidCacheLoadException e) {
      logger.debug("image not found for %s: %s", regionAndName, e);
    } catch (UncheckedExecutionException e) {
      logger.debug("error getting image for %s: %s", regionAndName, e);
    }
    return builder;
  }
  @Override
  public NodeMetadata apply(ServerInZone serverInZone) {
    Location zone = locationIndex.get().get(serverInZone.getZone());
    checkState(
        zone != null,
        "location %s not in locationIndex: %s",
        serverInZone.getZone(),
        locationIndex.get());
    Server from = serverInZone.getServer();

    NodeMetadataBuilder builder = new NodeMetadataBuilder();
    builder.id(serverInZone.slashEncode());
    builder.providerId(from.getId());
    builder.name(from.getName());
    builder.hostname(from.getName());
    builder.location(
        from.getHostId() != null
            ? new LocationBuilder()
                .scope(LocationScope.HOST)
                .id(from.getHostId())
                .description(from.getHostId())
                .parent(zone)
                .build()
            : zone);
    addMetadataAndParseTagsFromCommaDelimitedValue(builder, from.getMetadata());
    builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName()));
    builder.imageId(
        ZoneAndId.fromZoneAndId(serverInZone.getZone(), from.getImage().getId()).slashEncode());
    builder.operatingSystem(findOperatingSystemForServerOrNull(serverInZone));
    builder.hardware(findHardwareForServerOrNull(serverInZone));
    builder.status(from.getStatus().getNodeStatus());
    builder.publicAddresses(
        filter(
            transform(
                filter(from.getAddresses().values(), Predicates.not(isPrivateAddress)),
                AddressToStringTransformationFunction.INSTANCE),
            isInet4Address));
    builder.privateAddresses(
        filter(
            transform(
                filter(from.getAddresses().values(), isPrivateAddress),
                AddressToStringTransformationFunction.INSTANCE),
            isInet4Address));

    return builder.build();
  }
Esempio n. 5
0
 @Override
 public NodeMetadata apply(Server from) {
   NodeMetadataBuilder builder = new NodeMetadataBuilder();
   builder.ids(from.getId() + "");
   builder.name(from.getName());
   builder.hostname(from.getName());
   builder.location(
       new LocationBuilder()
           .scope(LocationScope.HOST)
           .id(from.getHostId())
           .description(from.getHostId())
           .parent(location.get())
           .build());
   addMetadataAndParseTagsFromCommaDelimitedValue(builder, from.getMetadata());
   builder.group(groupFromMapOrName(from.getMetadata(), from.getName(), nodeNamingConvention));
   builder.imageId(from.getImageId() + "");
   builder.operatingSystem(parseOperatingSystem(from));
   builder.hardware(parseHardware(from));
   builder.status(serverToNodeStatus.get(from.getStatus()));
   builder.publicAddresses(from.getAddresses().getPublicAddresses());
   builder.privateAddresses(from.getAddresses().getPrivateAddresses());
   return builder.build();
 }