Package org.jclouds.compute.domain

Examples of org.jclouds.compute.domain.NodeMetadataBuilder


   }

   @Override
   public NodeMetadata apply(final VirtualMachine from) {
      // convert the result object to a jclouds NodeMetadata
      NodeMetadataBuilder builder = new NodeMetadataBuilder();
      builder.ids(from.getId() + "");
      builder.name(from.getName());
      // TODO: in cloudstack 2.2.12, when "name" was set fine on the backend,
      // but wrong API response was returned to the user
      // http://bugs.cloud.com/show_bug.cgi?id=11664
      //
      // we set displayName to the same value as name, but this could be wrong
      // on hosts not started with jclouds
      builder.hostname(from.getDisplayName());
      builder.location(FluentIterable.from(locations.get()).firstMatch(idEquals(from.getZoneId())).orNull());
      builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getDisplayName()));
      Image image = FluentIterable.from(images.get()).firstMatch(new Predicate<Image>() {
         @Override
         public boolean apply(Image input) {
            return input.getProviderId().equals(from.getTemplateId() + "")
            // either location free image (location is null) or in the same zone as the VM
                  && (input.getLocation() == null || input.getId().equals(from.getZoneId() + ""));
         }
      }).orNull();
      if (image != null) {
         builder.imageId(image.getId());
         builder.operatingSystem(image.getOperatingSystem());
      }

      builder.hardware(new HardwareBuilder()
        .ids(from.getServiceOfferingId() + "")
        .name(from.getServiceOfferingName() + "")
         // .tags() TODO
        .processors(ImmutableList.of(new Processor(from.getCpuCount(), from.getCpuSpeed())))
        .ram((int)from.getMemory())//
        .hypervisor(from.getHypervisor())//
        .build());

      builder.status(vmStateToNodeStatus.get(from.getState()));

      Set<String> publicAddresses = newHashSet();
      Set<String> privateAddresses = newHashSet();
      if (from.getIPAddress() != null) {
         boolean isPrivate = isPrivateIPAddress(from.getIPAddress());
         if (isPrivate) {
            privateAddresses.add(from.getIPAddress());
         } else {
            publicAddresses.add(from.getIPAddress());
         }
      }
      if (from.getPublicIP() != null) {
          publicAddresses.add(from.getPublicIP());
      }
      for (NIC nic : from.getNICs()) {
         if (nic.getIPAddress() != null) {
            if (isPrivateIPAddress(nic.getIPAddress())) {
               privateAddresses.add(nic.getIPAddress());
            } else {
               publicAddresses.add(nic.getIPAddress());
            }
         }
      }
      try {
         /* Also add to the list of public IPs any public IP address that has a
            forwarding rule that links to this machine */
         Iterables.addAll(publicAddresses, transform(
            filter(getIPForwardingRulesByVirtualMachine.getUnchecked(from.getId()),
               new Predicate<IPForwardingRule>() {
                  @Override
                  public boolean apply(IPForwardingRule rule) {
                     return !"Deleting".equals(rule.getState());
                  }
               }), new Function<IPForwardingRule, String>() {
            @Override
            public String apply(IPForwardingRule rule) {
               return rule.getIPAddress();
            }
         }));
      } catch (UncheckedExecutionException e) {
         if (Throwables2.getFirstThrowableOfType(e, ResourceNotFoundException.class) == null) {
            Throwables.propagateIfPossible(e.getCause());
            throw e;
         }
      }
      return builder.privateAddresses(privateAddresses).publicAddresses(publicAddresses).build();
   }
View Full Code Here


      this.images = checkNotNull(images, "images");
   }

   @Override
   public NodeMetadata apply(ServerDetails from) {
      NodeMetadataBuilder builder = new NodeMetadataBuilder();
      builder.ids(from.getId() + "");
      builder.name(from.getHostname());
      builder.hostname(from.getHostname());
      Location location = FluentIterable.from(locations.get()).firstMatch(idEquals(from.getDatacenter())).orNull();
      checkState(location != null, "no location matched ServerDetails %s", from);
      builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getHostname()));
     
      // TODO: get glesys to stop stripping out equals and commas!
      if (!isNullOrEmpty(from.getDescription()) && from.getDescription().matches("^[0-9A-Fa-f]+$")) {
         String decoded = new String(base16().lowerCase().decode(from.getDescription()), UTF_8);
         addMetadataAndParseTagsFromCommaDelimitedValue(builder,
                  Splitter.on('\n').withKeyValueSeparator("=").split(decoded));
      }

      builder.imageId(from.getTemplateName() + "");
      builder.operatingSystem(parseOperatingSystem(from));
      builder.hardware(new HardwareBuilder().ids(from.getId() + "").ram(from.getMemorySizeMB())
            .processors(ImmutableList.of(new Processor(from.getCpuCores(), 1.0)))
            .volumes(ImmutableList.<Volume> of(new VolumeImpl((float) from.getDiskSizeGB(), true, true)))
            .hypervisor(from.getPlatform()).build());
      builder.status(serverStateToNodeStatus.get(from.getState()));
      Iterable<String> addresses = Iterables.filter(Iterables.transform(from.getIps(), new Function<Ip, String>() {

         @Override
         public String apply(Ip arg0) {
            return Strings.emptyToNull(arg0.getIp());
         }

      }), Predicates.notNull());
      builder.publicAddresses(Iterables.filter(addresses, Predicates.not(IsPrivateIPAddress.INSTANCE)));
      builder.privateAddresses(Iterables.filter(addresses, IsPrivateIPAddress.INSTANCE));
      return builder.build();
   }
View Full Code Here

   }

   @Override
   public NodeMetadata apply(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());
      if (from.getDatacenter() != null)
         builder.location(from(locations.get()).firstMatch(
               LocationPredicates.idEquals(from.getDatacenter().getId() + "")).orNull());
      builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getHostname()));

      Image image = images.getImage(from);
      if (image != null) {
         builder.imageId(image.getId());
         builder.operatingSystem(image.getOperatingSystem());
      }

      builder.hardware(hardware.getHardware(from));

      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();
   }
View Full Code Here

      NodeMetadata node = parser.apply(guest);

      assertEquals(
            node,
            new NodeMetadataBuilder().ids("416788").name("node1000360500").hostname("node1000360500")
                  .location(expectedLocation).status(Status.PENDING)
                  .publicAddresses(ImmutableSet.of("173.192.29.186"))
                  .privateAddresses(ImmutableSet.of("10.37.102.194"))
                  .hardware(new GetHardwareForVirtualGuestMock().getHardware(guest))
                  .imageId(new GetImageForVirtualGuestMock().getImage(guest).getId())
View Full Code Here

      NodeMetadata node = parser.apply(guest);

      assertEquals(
            node,
            new NodeMetadataBuilder().ids("413348").name("foo-ef4").hostname("foo-ef4").group("foo")
                  .status(Status.PENDING).hardware(new GetHardwareForVirtualGuestMock().getHardware(guest))
                  .imageId(new GetImageForVirtualGuestMock().getImage(guest).getId())
                  .operatingSystem(new GetImageForVirtualGuestMock().getImage(guest).getOperatingSystem()).build());

   }
View Full Code Here

      NodeMetadata node = parser.apply(guest);

      assertEquals(
            node,
            new NodeMetadataBuilder().ids("416700").name("node1703810489").hostname("node1703810489")
                  .location(expectedLocation).status(Status.PENDING)
                  .publicAddresses(ImmutableSet.of("173.192.29.187"))
                  .privateAddresses(ImmutableSet.of("10.37.102.195"))
                  .hardware(new GetHardwareForVirtualGuestMock().getHardware(guest))
                  .imageId(new GetImageForVirtualGuestMock().getImage(guest).getId())
View Full Code Here

      NodeMetadata node = parser.apply(guest);

      assertEquals(
            node,
            new NodeMetadataBuilder().ids("416700").name("node1703810489").hostname("node1703810489")
                  .location(expectedLocation).status(Status.SUSPENDED)
                  .publicAddresses(ImmutableSet.of("173.192.29.187"))
                  .privateAddresses(ImmutableSet.of("10.37.102.195"))
                  .hardware(new GetHardwareForVirtualGuestMock().getHardware(guest))
                  .imageId(new GetImageForVirtualGuestMock().getImage(guest).getId())
View Full Code Here

      NodeMetadata node = parser.apply(guest);

      assertEquals(
            node,
            new NodeMetadataBuilder().ids("416700").name("node1703810489").hostname("node1703810489")
                  .location(expectedLocation).status(Status.RUNNING)
                  .publicAddresses(ImmutableSet.of("173.192.29.187"))
                  .privateAddresses(ImmutableSet.of("10.37.102.195"))
                  .hardware(new GetHardwareForVirtualGuestMock().getHardware(guest))
                  .imageId(new GetImageForVirtualGuestMock().getImage(guest).getId())
View Full Code Here

      this.vAppStatusToNodeStatus = checkNotNull(vAppStatusToNodeStatus, "vAppStatusToNodeStatus");
   }

   @Override
   public NodeMetadata apply(VApp from) {
      NodeMetadataBuilder builder = new NodeMetadataBuilder();
      builder.ids(from.getHref().toASCIIString());
      builder.uri(from.getHref());
      builder.name(from.getName());
      builder.hostname(from.getName());
      Location vdcLocation = findLocationForResourceInVDC.apply(from.getVDC());
      builder.location(vdcLocation);
      if (from.getOsType() != null && OSType.fromValue(from.getOsType()) != OSType.UNRECOGNIZED) {
         builder.operatingSystem(new CIMOperatingSystem(OSType.fromValue(from.getOsType()), "", null, from
                  .getOperatingSystemDescription()));
      } else if (from.getOperatingSystemDescription() != null) {
         OperatingSystem.Builder osBuilder = new OperatingSystem.Builder();
         if (from.getOsType() != null)
            osBuilder.name(from.getOsType() + "");
         osBuilder.family(ComputeServiceUtils.parseOsFamilyOrUnrecognized(from.getOperatingSystemDescription()));
         osBuilder.version("");
         osBuilder.is64Bit(from.getOperatingSystemDescription().indexOf("64") != -1);
         osBuilder.description(from.getOperatingSystemDescription());
         builder.operatingSystem(osBuilder.build());
      }
      builder.hardware(hardwareForVCloudExpressVApp.apply(from));
      builder.status(vAppStatusToNodeStatus.get(from.getStatus()));
      builder.publicAddresses(computeClient.getPublicAddresses(from.getHref()));
      builder.privateAddresses(computeClient.getPrivateAddresses(from.getHref()));
      builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName()));
      builder.credentials(LoginCredentials.fromCredentials(credentialStore
               .get("node#" + from.getHref().toASCIIString())));
      return builder.build();
   }
View Full Code Here

   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(toPortableNodeStatus.get(from.getStatus()));
      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));
     
      for (Link link: from.getLinks()) {
         if (link.getRelation().equals(Link.Relation.SELF)) {
            builder.uri(link.getHref());
         }
      }
     
      return builder.build();
   }
View Full Code Here

TOP

Related Classes of org.jclouds.compute.domain.NodeMetadataBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.