Package org.jclouds.compute.domain

Examples of org.jclouds.compute.domain.NodeMetadataBuilder


   @BeforeMethod
   public void setUp() {
      Injector injector = createInjector();
      injector.injectMembers(this);
      this.nodeMeta1 = new NodeMetadataBuilder().id("testmeta1").status(Status.ERROR).build();
      this.nodeMeta2 = new NodeMetadataBuilder().id("testmeta2").status(Status.ERROR).build();
      this.templateOptions = new TemplateOptions().overrideLoginUser("testuser").overrideLoginPassword("testpass")
               .overrideAuthenticateSudo(true).userMetadata("testmetakey", "testmetavalue")
               .overrideLoginPrivateKey("pk").userMetadata("testmetakey2", "testmetavalue2")
               .tags(ImmutableList.of("tag1", "tag2"));
   }
View Full Code Here


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

   @Override
   public NodeMetadata apply(VM from) {
      NodeMetadataBuilder builder = new NodeMetadataBuilder();
      builder.ids(from.getHref().toASCIIString());
      builder.name(from.getName());
      String locationId = Iterables.get(from.getNetworkSection().getNetworks(), 0).getName();
      builder.location(from(locations.get()).firstMatch(LocationPredicates.idEquals(locationId)).orNull());
      builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName()));
      try {
         builder.operatingSystem(CIMOperatingSystem.toComputeOs(from.getOperatingSystemSection()));
      } catch (NullPointerException e) {
         // os section was null
      }
      // TODO build from resource allocation section
      // builder.hardware(findHardwareForVM.apply(from));
      builder.status(VAPPSTATUS_TO_NODESTATE.get(from.getStatus()));
      Set<String> addresses = Utils.getIpsFromVM(from);
      builder.publicAddresses(filter(addresses, not(IsPrivateIPAddress.INSTANCE)));
      builder.privateAddresses(filter(addresses, IsPrivateIPAddress.INSTANCE));
      return builder.build();
   }
View Full Code Here

            "namingConvention").createWithoutPrefix();
   }

   @Override
   public NodeMetadata apply(VServerMetadata from) {
      NodeMetadataBuilder builder = new NodeMetadataBuilder();

      builder.ids(from.getId());
      builder.name(from.getName());
      builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from
            .getName()));
      if (from.getStatus() == null)
         System.out.println("status null for: " + from.getId() + ": "
               + from.getName());

      builder.status(vServerToStatus.get(from.getStatus()));
      builder.privateAddresses(ImmutableSet.<String> of());
      builder.publicAddresses(ImmutableSet.<String> of());

      //
      // if (from.getIps() != null) {
      //
      // builder.publicAddresses(Collections2.transform(from.getIps(),
      // new Function<PublicIP, String>() {
      //
      // @Override
      // public String apply(PublicIP input) {
      // return input.getAddress();
      // }
      //
      // }));
      // }

      if (from.getServer() != null) {

         builder.imageId(from.getServer().getDiskimageId());
         builder.hardware(parseHardware(from.getServer().getType()));

         LoginCredentials.Builder credentialsBuilder = LoginCredentials
               .builder().password(from.getInitialPassword());

         Image image = parseImage(from.getServer());
         // image will not be found if server was created a while back and
         // the image has since been destroyed or discontinued (like an old
         // CentOS version)
         if (image != null) {

            builder.operatingSystem(image.getOperatingSystem());
            String user = image.getDefaultCredentials().getUser();
            credentialsBuilder.identity(user);
         }

         builder.credentials(credentialsBuilder.build());

         if (from.getServer() instanceof VServerWithVNICs) {

            VServerWithVNICs server = (VServerWithVNICs) from.getServer();
            builder.location(parseLocation(server));
            List<String> ips = Lists.newArrayList();
            if (server.getVnics() != null && server.getVnics().iterator().next().getPrivateIp() != null) {
               ips.add(server.getVnics().iterator().next().getPrivateIp());
            }
            builder.privateAddresses(ips);
         }
      }
      if (from.getTemplate() != null) {
         // when creating a new node
         builder.location(from.getTemplate().getLocation());
      }

      return builder.build();
   }
View Full Code Here

   }

   @Override
   public NodeMetadata apply(VM from) {
      // convert the result object to a jclouds NodeMetadata
      NodeMetadataBuilder builder = new NodeMetadataBuilder();
      builder.ids(from.getUuid() + "");
      builder.name(from.getAlias());
      builder.location(from(locations.get()).firstMatch(LocationPredicates.idEquals(from.getUuid() + "")).orNull());
      builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getType()));
      builder.imageId(from.getType() + "");
      Image image = from(images.get()).firstMatch(ImagePredicates.idEquals(from.getUuid() + "")).orNull();
      if (image != null)
         builder.operatingSystem(image.getOperatingSystem());
      builder.hardware(from(hardware.get()).firstMatch(HardwarePredicates.idEquals(from.getUuid() + "")).orNull());
      builder.status(serverStatusToNodeStatus.get(from.getState()));
      try {
         if (from.getState() == VM.State.RUNNING) {
            Optional<String> ip = from.getPublicAddress();
            if (ip.isPresent()) {
               builder.publicAddresses(ImmutableSet.<String> of(ip.get()));
               builder.privateAddresses(ImmutableSet.<String> of(ip.get()));
            }
         }
      } catch (Exception ex) {
         // None?
      }
      // builder.privateAddresses(ImmutableSet.<String> of(from.privateAddress));
      builder.credentials(LoginCredentials.fromCredentials(credentialStore.get(from.getUuid() + "")));
      return builder.build();
   }
View Full Code Here

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

   public NodeMetadata apply(Vm from) {
      NodeMetadataBuilder builder = new NodeMetadataBuilder();
      builder.ids(from.getHref().toASCIIString());
      builder.uri(from.getHref());
      builder.name(from.getName());
      builder.hostname(from.getName());
      builder.location(findLocationForResourceInVDC.apply(
            Iterables.find(from.getLinks(), LinkPredicates.typeEquals(VCloudDirectorMediaType.VDC))));
      builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName()));
      builder.operatingSystem(toComputeOs(from));
      builder.hardware(hardwareForVm.apply(from));
      builder.status(vAppStatusToNodeStatus.get(from.getStatus()));
      Set<String> addresses = getIpsFromVm(from);
      builder.publicAddresses(filter(addresses, not(IsPrivateIPAddress.INSTANCE)));
      builder.privateAddresses(filter(addresses, IsPrivateIPAddress.INSTANCE));

      // normally, we don't affect the credential store when reading vApps.
      // However, login user, etc, is actually in the metadata, so lets see
      Credentials fromApi = getCredentialsFrom(from);
      if (fromApi != null && !credentialStore.containsKey("node#" + from.getHref().toASCIIString()))
         credentialStore.put("node#" + from.getHref().toASCIIString(), fromApi);
      return builder.build();
   }
View Full Code Here

      Location zone = locationIndex.get().get(machineInDatacenter.getDatacenter());
      checkState(zone != null, "location %s not in locationIndex: %s", machineInDatacenter.getDatacenter(),
            locationIndex.get());
      Machine from = machineInDatacenter.get();

      NodeMetadataBuilder builder = new NodeMetadataBuilder();
      builder.id(machineInDatacenter.slashEncode());
      builder.providerId(from.getId());
      builder.name(from.getName());
      builder.hostname(from.getId());
      builder.location(zone);
      Map<String, String> metadataMap = filterKeys(from.getMetadata(), new Predicate<String>() {

         @Override
         public boolean apply(String input) {
            // TODO make this more efficient
            for (Metadata key : Metadata.values())
               if (key.key().equals(input))
                  return false;
            return true;
         }

      });
      addMetadataAndParseTagsFromCommaDelimitedValue(builder, metadataMap);

      builder.group(groupFromMapOrName(metadataMap, from.getName(), nodeNamingConvention));

      builder.imageId(DatacenterAndName.fromDatacenterAndName(machineInDatacenter.getDatacenter(), from.getDatasetURN())
            .slashEncode());
      builder.operatingSystem(findOperatingSystemForMachineOrNull(machineInDatacenter));
      builder.hardware(findHardwareForMachineOrNull(machineInDatacenter));
      builder.status(toPortableNodeStatus.get(from.getState()));
      builder.publicAddresses(filter(from.getIps(), not(InetAddresses2.IsPrivateIPAddress.INSTANCE)));
      builder.privateAddresses(filter(from.getIps(), InetAddresses2.IsPrivateIPAddress.INSTANCE));
      return builder.build();
   }
View Full Code Here

      return new Supplier<NodeMetadata>() {

         @Override
         public NodeMetadata get() {
            String privateKey = readRsaIdentity();
            return new NodeMetadataBuilder()
                                    .id(HOST_ID)
                                    .name("host installing virtualbox")
                                    .hostname(HOSTNAME)
                                    .operatingSystem(OperatingSystem.builder()
                                                                    .family(OsFamily.LINUX)
View Full Code Here

         logger.debug("<< deleted an existing snapshot of vm(%s)", master.getMachine().getName());
      }
   }

   private NodeMetadata buildPartialNodeMetadata(IMachine clone, String guestOsUser, String guestOsPassword) {
      NodeMetadataBuilder nodeMetadataBuilder = new NodeMetadataBuilder();
      nodeMetadataBuilder.id(clone.getName());
      nodeMetadataBuilder.status(VirtualBoxComputeServiceContextModule.toPortableNodeStatus.get(clone.getState()));
      nodeMetadataBuilder.publicAddresses(ImmutableSet.of(networkUtils.getValidHostOnlyIpFromVm(clone.getName())));
      nodeMetadataBuilder.credentials(LoginCredentials.builder()
                                                      .user(guestOsUser)
                                                      .password(guestOsPassword)
                                                      .authenticateSudo(true).build());
      return nodeMetadataBuilder.build();
   }
View Full Code Here

         name = encodedInVmName[3];
      } else {
         name = encodedInVmName[1];
      }
     
      NodeMetadataBuilder nodeMetadataBuilder = new NodeMetadataBuilder();
      nodeMetadataBuilder.name(name).ids(vm.getName()).group(group);
      // TODO Set up location properly
      LocationBuilder locationBuilder = new LocationBuilder();
      locationBuilder.description("");
      locationBuilder.id("");
      locationBuilder.scope(LocationScope.HOST);
      nodeMetadataBuilder.location(locationBuilder.build());
      nodeMetadataBuilder.hostname(vm.getName());

      MachineState vmState = vm.getState();
      NodeMetadata.Status nodeState = toPortableNodeStatus.get(vmState);
      if (nodeState == null)
         nodeState = Status.UNRECOGNIZED;
      nodeMetadataBuilder.status(nodeState);
      nodeMetadataBuilder = getIpAddresses(vm, nodeMetadataBuilder);
     
      IGuestOSType guestOSType = virtualboxManager.get().getVBox().getGuestOSType(vm.getOSTypeId());
      OsFamily family = parseOsFamilyOrUnrecognized(guestOSType.getDescription());
      String version = parseVersionOrReturnEmptyString(family, guestOSType.getDescription(), osVersionMap);
      OperatingSystem os = OperatingSystem.builder().description(guestOSType.getDescription()).family(family)
               .version(version).is64Bit(guestOSType.getIs64Bit()).build();
      nodeMetadataBuilder.operatingSystem(os);

      String guestOsUser = vm.getExtraData(GUEST_OS_USER);
      String guestOsPassword = vm.getExtraData(GUEST_OS_PASSWORD);
      nodeMetadataBuilder.credentials(LoginCredentials.builder()
                                                      .user(guestOsUser)
                                                      .password(guestOsPassword)
                                                      .authenticateSudo(true).build());
      return nodeMetadataBuilder.build();
   }
View Full Code Here

   public NodeMetadata apply(Instance input) {
      Map<URI, ? extends Image> imagesMap = images.get();
      Image image = checkNotNull(imagesMap.get(checkNotNull(input.getImage(), "image")),
              "no image for %s. images: %s", input.getImage(), imagesMap.values());

      return new NodeMetadataBuilder()
              .id(input.getName())
              .name(input.getName())
              .providerId(input.getId())
              .hostname(input.getName())
              .imageId(image.getId())
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.