Package org.jclouds.compute.domain

Examples of org.jclouds.compute.domain.NodeMetadataBuilder


    ClusterControllerFactory factory = mock(ClusterControllerFactory.class);
    ClusterController controller = mock(ClusterController.class);
    when(factory.create((String) any())).thenReturn(controller);

    NodeMetadata node1 = new NodeMetadataBuilder().name("name1").ids("id1")
        .location(new LocationBuilder().scope(LocationScope.PROVIDER)
          .id("location-id1").description("location-desc1").build())
        .imageId("image-id").state(NodeState.RUNNING)
        .publicAddresses(Lists.newArrayList("127.0.0.1"))
        .privateAddresses(Lists.newArrayList("127.0.0.1")).build();

    NodeMetadata node2 = new NodeMetadataBuilder().name("name2").ids("id2")
        .location(new LocationBuilder().scope(LocationScope.PROVIDER)
          .id("location-id2").description("location-desc2").build())
        .imageId("image-id").state(NodeState.RUNNING)
        .publicAddresses(Lists.newArrayList("127.0.0.2"))
        .privateAddresses(Lists.newArrayList("127.0.0.2")).build();
View Full Code Here


      this.credentialStore = checkNotNull(credentialStore, "credentialStore cannot be null");
   }

   @Override
   public NodeMetadata apply(Droplet input) {
      NodeMetadataBuilder builder = new NodeMetadataBuilder();
      builder.ids(String.valueOf(input.getId()));
      builder.name(input.getName());
      builder.hostname(input.getName());
      builder.group(groupNamingConvention.extractGroup(input.getName()));

      builder.hardware(getHardware(input.getSizeId()));
      builder.location(getLocation(input.getRegionId()));

      Optional<? extends Image> image = findImage(input.getImageId());
      if (image.isPresent()) {
         builder.imageId(image.get().getId());
         builder.operatingSystem(image.get().getOperatingSystem());
      } else {
         logger.info(">> image with id %s for droplet %s was not found. "
               + "This might be because the image that was used to create the droplet has a new id.",
               input.getImageId(), input.getId());
      }

      builder.status(toPortableStatus.apply(input.getStatus()));
      builder.backendStatus(input.getStatus().name());

      if (input.getIp() != null) {
         builder.publicAddresses(ImmutableSet.of(input.getIp()));
      }
      if (input.getPrivateIp() != null) {
         builder.privateAddresses(ImmutableSet.of(input.getPrivateIp()));
      }

      // DigitalOcean does not provide a way to get the credentials.
      // Try to return them from the credential store
      Credentials credentials = credentialStore.get("node#" + input.getId());
      if (credentials instanceof LoginCredentials) {
         builder.credentials(LoginCredentials.class.cast(credentials));
      }

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

   @Test
   public void testConvertDroplet() throws ParseException {
      Droplet droplet = new Droplet(1, "mock-droplet", 1, 1, 1, false, ImmutableList.of(), ImmutableList.of(),
            "84.45.69.3", "192.168.2.5", false, ACTIVE, new Date());

      NodeMetadata expected = new NodeMetadataBuilder().ids("1").hardware(getOnlyElement(hardwares))
            .imageId("ubuntu-1404-x86").status(RUNNING).location(getOnlyElement(locations)).name("mock-droplet")
            .hostname("mock-droplet").group("mock").credentials(credentials)
            .publicAddresses(ImmutableSet.of("84.45.69.3")).privateAddresses(ImmutableSet.of("192.168.2.5"))
            .providerId("1").backendStatus(ACTIVE.name()).operatingSystem(getOnlyElement(images).getOperatingSystem())
            .build();
View Full Code Here

   public void testConvertDropletOldImage() throws ParseException {
      // Use an image id that is not in the list of images
      Droplet droplet = new Droplet(1, "mock-droplet", 9999, 1, 1, false, ImmutableList.of(), ImmutableList.of(),
            "84.45.69.3", "192.168.2.5", false, ACTIVE, new Date());

      NodeMetadata expected = new NodeMetadataBuilder().ids("1").hardware(getOnlyElement(hardwares)).imageId(null)
            .status(RUNNING).location(getOnlyElement(locations)).name("mock-droplet").hostname("mock-droplet")
            .group("mock").credentials(credentials).publicAddresses(ImmutableSet.of("84.45.69.3"))
            .privateAddresses(ImmutableSet.of("192.168.2.5")).providerId("1").backendStatus(ACTIVE.name())
            .operatingSystem(null).build();
View Full Code Here

   @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

   @Override
   public NodeMetadata apply(Container container) {
      String name = cleanUpName(container.getName());
      String group = nodeNamingConvention.extractGroup(name);
      NodeMetadataBuilder builder = new NodeMetadataBuilder();
      builder.ids(container.getId())
              .name(name)
              .group(group)
              .hostname(container.getContainerConfig().getHostname())
               // TODO Set up hardware
              .hardware(new HardwareBuilder()
                      .id("")
                      .ram(container.getContainerConfig().getMemory())
                      .processor(new Processor(container.getContainerConfig().getCpuShares(), container.getContainerConfig().getCpuShares()))
                      .build());
      builder.status(toPortableStatus.apply(container.getState()));
      builder.imageId(container.getImage());
      builder.loginPort(getLoginPort(container));
      builder.publicAddresses(getPublicIpAddresses());
      builder.privateAddresses(getPrivateIpAddresses(container));
      builder.location(Iterables.getOnlyElement(locations.get()));
      Image image = images.get().get(container.getImage());
      builder.imageId(image.getId());
      builder.operatingSystem(image.getOperatingSystem());

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

      VirtualBoxManager manager = createMock(VirtualBoxManager.class);
      Factory runScriptOnNodeFactory = createMock(Factory.class);
      RunScriptOnNode runScriptOnNode = createMock(RunScriptOnNode.class);
      RetryIfSocketNotYetOpen client = createMock(RetryIfSocketNotYetOpen.class);
      HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata = createMock(HardcodedHostToHostNodeMetadata.class);
      NodeMetadata host = new NodeMetadataBuilder().id("host").status(Status.RUNNING).build();
      URI provider = URI.create("http://localhost:18083/");
      expect(client.seconds(3)).andReturn(client);
      expect(client.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))).andReturn(true).anyTimes();
      manager.connect(provider.toASCIIString(), "", "");
      expectLastCall().anyTimes();
View Full Code Here

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

   @Override
   public NodeMetadata apply(final VirtualMachine vm) {
      NodeMetadataBuilder builder = new NodeMetadataBuilder();
      builder.ids(vm.getId().toString());
      builder.uri(vm.getURI());
      builder.name(vm.getNameLabel());
      builder.group(vm.getVirtualAppliance().getName());

      // TODO: Node credentials still not present in Abiquo template metadata
      // Will be added in Abiquo 2.4:
      // http://jira.abiquo.com/browse/ABICLOUDPREMIUM-3647

      // Location details
      VirtualDatacenter vdc = vm.getVirtualDatacenter();
      builder.location(virtualDatacenterToLocation.apply(vdc));

      // Image details
      VirtualMachineTemplate template = vm.getTemplate();
      Image image = virtualMachineTemplateToImage.apply(template);
      builder.imageId(image.getId().toString());
      builder.operatingSystem(image.getOperatingSystem());

      // Hardware details
      Hardware defaultHardware = virtualMachineTemplateToHardware.apply(new VirtualMachineTemplateInVirtualDatacenter(
            template, vdc));

      Hardware hardware = HardwareBuilder
            .fromHardware(defaultHardware)
            .ram(vm.getRam())
            .processors(
                  Lists.newArrayList(new Processor(vm.getCpu(),
                        VirtualMachineTemplateInVirtualDatacenterToHardware.DEFAULT_CORE_SPEED))) //
            .build();

      builder.hardware(hardware);

      // Networking configuration
      Iterable<Ip<?, ?>> nics = vm.listAttachedNics();
      builder.privateAddresses(ips(filter(nics, Predicates.instanceOf(PrivateIp.class))));
      builder.publicAddresses(ips(filter(nics, Predicates.not(Predicates.instanceOf(PrivateIp.class)))));

      // Node state
      VirtualMachineState state = vm.getState();
      builder.status(virtualMachineStateToNodeState.apply(state));
      builder.backendStatus(state.name());

      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

      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

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.