@Test public void testConvertDroplet() throws ParseException { Droplet droplet = Droplet.create( 1, "mock-droplet", 1, 1, 1, false, new Date(), Droplet.Status.ACTIVE, ImmutableList.<Integer> of(), ImmutableList.<Integer> of(), ImmutableList.<String> of(), region, image, null, "2gb", Networks.create( ImmutableList.of(Address.create("84.45.69.3", "255.255.255.0", "84.45.69.1", "public"), Address.create("192.168.2.5", "255.255.255.0", "192.168.2.1", "private")), ImmutableList.<Networks.Address> of()), null); NodeMetadata expected = new NodeMetadataBuilder().ids("1").hardware(getOnlyElement(hardwares)) .imageId("sfo1/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(); NodeMetadata actual = function.apply(droplet); assertNodeEquals(actual, expected); }
@Override public NodeMetadata apply(Droplet input) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(String.valueOf(input.id())); builder.name(input.name()); builder.hostname(input.name()); builder.group(groupNamingConvention.extractGroup(input.name())); builder.hardware(getHardware(input.sizeSlug())); builder.location(getLocation(input.region())); Optional<? extends Image> image = findImage(input.image(), input.region().slug()); 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.image().id(), input.id()); } builder.status(toPortableStatus.apply(input.status())); builder.backendStatus(input.status().name()); if (!input.getPublicAddresses().isEmpty()) { builder.publicAddresses(FluentIterable .from(input.getPublicAddresses()) .transform(new Function<Networks.Address, String>() { @Override public String apply(final Networks.Address input) { return input.ip(); } }) ); } if (!input.getPrivateAddresses().isEmpty()) { builder.privateAddresses(FluentIterable .from(input.getPrivateAddresses()) .transform(new Function<Networks.Address, String>() { @Override public String apply(final Networks.Address input) { return input.ip(); } }) ); } Credentials credentials = credentialStore.get("node#" + input.id()); if (credentials instanceof LoginCredentials) { builder.credentials(LoginCredentials.class.cast(credentials)); } return builder.build(); }
DropletToNodeMetadata implements Function<Droplet, NodeMetadata> { @Override public NodeMetadata apply(Droplet input) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(String.valueOf(input.id())); builder.name(input.name()); builder.hostname(input.name()); builder.group(groupNamingConvention.extractGroup(input.name())); builder.hardware(getHardware(input.sizeSlug())); builder.location(getLocation(input.region())); Optional<? extends Image> image = findImage(input.image(), input.region().slug()); 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.image().id(), input.id()); } builder.status(toPortableStatus.apply(input.status())); builder.backendStatus(input.status().name()); if (!input.getPublicAddresses().isEmpty()) { builder.publicAddresses(FluentIterable .from(input.getPublicAddresses()) .transform(new Function<Networks.Address, String>() { @Override public String apply(final Networks.Address input) { return input.ip(); } }) ); } if (!input.getPrivateAddresses().isEmpty()) { builder.privateAddresses(FluentIterable .from(input.getPrivateAddresses()) .transform(new Function<Networks.Address, String>() { @Override public String apply(final Networks.Address input) { return input.ip(); } }) ); } Credentials credentials = credentialStore.get("node#" + input.id()); if (credentials instanceof LoginCredentials) { builder.credentials(LoginCredentials.class.cast(credentials)); } return builder.build(); } }
DropletToNodeMetadata implements Function<Droplet, NodeMetadata> { @Override public NodeMetadata apply(Droplet input) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(String.valueOf(input.id())); builder.name(input.name()); builder.hostname(input.name()); builder.group(groupNamingConvention.extractGroup(input.name())); builder.hardware(getHardware(input.sizeSlug())); builder.location(getLocation(input.region())); Optional<? extends Image> image = findImage(input.image(), input.region().slug()); 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.image().id(), input.id()); } builder.status(toPortableStatus.apply(input.status())); builder.backendStatus(input.status().name()); if (!input.getPublicAddresses().isEmpty()) { builder.publicAddresses(FluentIterable .from(input.getPublicAddresses()) .transform(new Function<Networks.Address, String>() { @Override public String apply(final Networks.Address input) { return input.ip(); } }) ); } if (!input.getPrivateAddresses().isEmpty()) { builder.privateAddresses(FluentIterable .from(input.getPrivateAddresses()) .transform(new Function<Networks.Address, String>() { @Override public String apply(final Networks.Address input) { return input.ip(); } }) ); } Credentials credentials = credentialStore.get("node#" + input.id()); if (credentials instanceof LoginCredentials) { builder.credentials(LoginCredentials.class.cast(credentials)); } return builder.build(); } @Inject  DropletToNodeMetadata(Supplier<Map<String, ? extends Image>> images,
         Supplier<Map<String, ? extends Hardware>> hardwares, @Memoized Supplier<Set<? extends Location>> locations,
         Function<Droplet.Status, Status> toPortableStatus, GroupNamingConvention.Factory groupNamingConvention,
         Map<String, Credentials> credentialStore); }
DropletToNodeMetadata implements Function<Droplet, NodeMetadata> { @Override public NodeMetadata apply(Droplet input) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(String.valueOf(input.id())); builder.name(input.name()); builder.hostname(input.name()); builder.group(groupNamingConvention.extractGroup(input.name())); builder.hardware(getHardware(input.sizeSlug())); builder.location(getLocation(input.region())); Optional<? extends Image> image = findImage(input.image(), input.region().slug()); 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.image().id(), input.id()); } builder.status(toPortableStatus.apply(input.status())); builder.backendStatus(input.status().name()); if (!input.getPublicAddresses().isEmpty()) { builder.publicAddresses(FluentIterable .from(input.getPublicAddresses()) .transform(new Function<Networks.Address, String>() { @Override public String apply(final Networks.Address input) { return input.ip(); } }) ); } if (!input.getPrivateAddresses().isEmpty()) { builder.privateAddresses(FluentIterable .from(input.getPrivateAddresses()) .transform(new Function<Networks.Address, String>() { @Override public String apply(final Networks.Address input) { return input.ip(); } }) ); } Credentials credentials = credentialStore.get("node#" + input.id()); if (credentials instanceof LoginCredentials) { builder.credentials(LoginCredentials.class.cast(credentials)); } return builder.build(); } @Inject  DropletToNodeMetadata(Supplier<Map<String, ? extends Image>> images,
         Supplier<Map<String, ? extends Hardware>> hardwares, @Memoized Supplier<Set<? extends Location>> locations,
         Function<Droplet.Status, Status> toPortableStatus, GroupNamingConvention.Factory groupNamingConvention,
         Map<String, Credentials> credentialStore); @Override NodeMetadata apply(Droplet input); }
DropletToNodeMetadata implements Function<Droplet, NodeMetadata> { @Override public NodeMetadata apply(Droplet input) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(String.valueOf(input.id())); builder.name(input.name()); builder.hostname(input.name()); builder.group(groupNamingConvention.extractGroup(input.name())); builder.hardware(getHardware(input.sizeSlug())); builder.location(getLocation(input.region())); Optional<? extends Image> image = findImage(input.image(), input.region().slug()); 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.image().id(), input.id()); } builder.status(toPortableStatus.apply(input.status())); builder.backendStatus(input.status().name()); if (!input.getPublicAddresses().isEmpty()) { builder.publicAddresses(FluentIterable .from(input.getPublicAddresses()) .transform(new Function<Networks.Address, String>() { @Override public String apply(final Networks.Address input) { return input.ip(); } }) ); } if (!input.getPrivateAddresses().isEmpty()) { builder.privateAddresses(FluentIterable .from(input.getPrivateAddresses()) .transform(new Function<Networks.Address, String>() { @Override public String apply(final Networks.Address input) { return input.ip(); } }) ); } Credentials credentials = credentialStore.get("node#" + input.id()); if (credentials instanceof LoginCredentials) { builder.credentials(LoginCredentials.class.cast(credentials)); } return builder.build(); } @Inject  DropletToNodeMetadata(Supplier<Map<String, ? extends Image>> images,
         Supplier<Map<String, ? extends Hardware>> hardwares, @Memoized Supplier<Set<? extends Location>> locations,
         Function<Droplet.Status, Status> toPortableStatus, GroupNamingConvention.Factory groupNamingConvention,
         Map<String, Credentials> credentialStore); @Override NodeMetadata apply(Droplet input);  }