protected static Location getLocation(Supplier<Set<? extends Location>> locations, final String locationName) { return find(locations.get(), idEquals(nullToEmpty(locationName)), null); }
protected static Location getLocation(Supplier<Set<? extends Location>> locations, final String locationName) { return find(locations.get(), idEquals(nullToEmpty(locationName)), null); }
public Location apply(String bucket) { Set<? extends Location> locations = this.locations.get(); if (locations.size() == 1) return get(locations, 0); final Optional<String> region = bucketToRegion.apply(bucket); if (region.isPresent()) { try { return find(locations, idEquals(region.get())); } catch (NoSuchElementException e) { logger.debug("could not get location for region %s in %s", region, locations); } } else { logger.debug("could not get region for %s", bucket); } return null; } }
@Override public LoadBalancerMetadata apply(LoadBalancer input) { Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(input.getRegion())); String id = input.getRegion() + "/" + input.getId(); // TODO Builder return new LoadBalancerMetadataImpl(LoadBalancerType.LB, String.valueOf(input.getId()), input.getName(), id, location, null, ImmutableMap.<String, String> of(), Iterables.transform(input.getVirtualIPs(), new Function<VirtualIPWithId, String>() { @Override public String apply(VirtualIPWithId arg0) { return arg0.getAddress(); } })); } }
@Override public LoadBalancerMetadata apply(LoadBalancer input) { Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(input.getRegion())); String id = input.getRegion() + "/" + input.getId(); // TODO Builder return new LoadBalancerMetadataImpl(LoadBalancerType.LB, String.valueOf(input.getId()), input.getName(), id, location, null, ImmutableMap.<String, String> of(), Iterables.transform(input.getVirtualIPs(), new Function<VirtualIPWithId, String>() { @Override public String apply(VirtualIPWithId arg0) { return arg0.getAddress(); } })); } }
@Override public LoadBalancerMetadata apply(LoadBalancer input) { Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(input.getRegion())); String id = input.getRegion() + "/" + input.getId(); // TODO Builder return new LoadBalancerMetadataImpl(LoadBalancerType.LB, String.valueOf(input.getId()), input.getName(), id, location, null, ImmutableMap.<String, String> of(), Iterables.transform(input.getVirtualIPs(), new Function<VirtualIPWithId, String>() { @Override public String apply(VirtualIPWithId arg0) { return arg0.getAddress(); } })); } }
@Override public LoadBalancerMetadata apply(LoadBalancer input) { Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(input.getRegion())); String id = input.getRegion() + "/" + input.getId(); // TODO Builder return new LoadBalancerMetadataImpl(LoadBalancerType.LB, String.valueOf(input.getId()), input.getName(), id, location, null, ImmutableMap.<String, String> of(), Iterables.transform(input.getVirtualIPs(), new Function<VirtualIPWithId, String>() { @Override public String apply(VirtualIPWithId arg0) { return arg0.getAddress(); } })); } }
@Override public LoadBalancerMetadata apply(LoadBalancer input) { Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(input.getRegion())); String id = input.getRegion() + "/" + input.getId(); // TODO Builder return new LoadBalancerMetadataImpl(LoadBalancerType.LB, String.valueOf(input.getId()), input.getName(), id, location, null, ImmutableMap.<String, String> of(), Iterables.transform(input.getVirtualIPs(), new Function<VirtualIPWithId, String>() { @Override public String apply(VirtualIPWithId arg0) { return arg0.getAddress(); } })); } }
@Override public LoadBalancerMetadata apply(LoadBalancer input) { Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(input.getRegion())); String id = input.getRegion() + "/" + input.getId(); // TODO Builder return new LoadBalancerMetadataImpl(LoadBalancerType.LB, input.getName(), input.getName(), id, location, null, ImmutableMap.<String, String> of(), Iterables.transform(input.getVirtualIPs(), new Function<VirtualIP, String>() { @Override public String apply(VirtualIP arg0) { return arg0.getAddress(); } })); } }
@Override public NodeMetadata apply(Server from) { // convert the result object to a jclouds NodeMetadata NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.id + ""); builder.name(from.name); builder.location(from(locations.get()).firstMatch(LocationPredicates.idEquals(from.datacenter)).orNull()); builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.name)); builder.imageId(from.imageId + ""); Image image = from(images.get()).firstMatch(ImagePredicates.idEquals(from.imageId + "")).orNull(); if (image != null) builder.operatingSystem(image.getOperatingSystem()); builder.hardware(from(hardware.get()).firstMatch(HardwarePredicates.idEquals(from.hardwareId + "")).orNull()); builder.status(serverStatusToNodeStatus.get(from.status)); builder.publicAddresses(ImmutableSet.<String> of(from.publicAddress)); builder.privateAddresses(ImmutableSet.<String> of(from.privateAddress)); builder.credentials(LoginCredentials.fromCredentials(credentialStore.get(from.id + ""))); return builder.build(); } }
@Override public Image apply(Template template) { checkNotNull(template, "template"); OperatingSystem os = templateToOperatingSystem.apply(template); ImageBuilder builder = new ImageBuilder().ids(template.getId() + "").name(template.getName()) .description(template.getDisplayText()).operatingSystem(os); if (!template.isCrossZones()) builder.location(FluentIterable.from(locations.get()).firstMatch(idEquals(template.getZoneId())).orNull()); //TODO: implement status mapping!!! builder.status(Status.AVAILABLE); return builder.build(); } }
@Override public Image apply(Template template) { checkNotNull(template, "template"); OperatingSystem os = templateToOperatingSystem.apply(template); ImageBuilder builder = new ImageBuilder().ids(template.getId() + "").name(template.getName()) .description(template.getDisplayText()).operatingSystem(os); if (!template.isCrossZones()) builder.location(FluentIterable.from(locations.get()).firstMatch(idEquals(template.getZoneId())).orNull()); //TODO: implement status mapping!!! builder.status(Status.AVAILABLE); return builder.build(); } }
@Override public Image apply(Template template) { checkNotNull(template, "template"); OperatingSystem os = templateToOperatingSystem.apply(template); ImageBuilder builder = new ImageBuilder().ids(template.getId() + "").name(template.getName()) .description(template.getDisplayText()).operatingSystem(os); if (!template.isCrossZones()) builder.location(FluentIterable.from(locations.get()).firstMatch(idEquals(template.getZoneId())).orNull()); //TODO: implement status mapping!!! builder.status(Status.AVAILABLE); return builder.build(); } }
@Override public Hardware apply(ServerSpec spec) { Location location = FluentIterable.from(locations.get()).firstMatch(idEquals(spec.getDatacenter())).orNull(); assert location != null : String.format("no location matched ServerSpec %s", spec); return new HardwareBuilder().ids(spec.toString()).ram(spec.getMemorySizeMB()).processors( ImmutableList.of(new Processor(spec.getCpuCores(), 1.0))).volumes( ImmutableList.<Volume> of(new VolumeImpl((float) spec.getDiskSizeGB(), true, true))).hypervisor( spec.getPlatform()).location(location).supportsImage( ImagePredicates.idEquals(spec.getTemplateName())).build(); } }
@Override public Hardware apply(ServerSpec spec) { Location location = FluentIterable.from(locations.get()).firstMatch(idEquals(spec.getDatacenter())).orNull(); assert location != null : String.format("no location matched ServerSpec %s", spec); return new HardwareBuilder().ids(spec.toString()).ram(spec.getMemorySizeMB()).processors( ImmutableList.of(new Processor(spec.getCpuCores(), 1.0))).volumes( ImmutableList.<Volume> of(new VolumeImpl((float) spec.getDiskSizeGB(), true, true))).hypervisor( spec.getPlatform()).location(location).supportsImage( ImagePredicates.idEquals(spec.getTemplateName())).build(); } }
@Override public Image apply(final OSImage image) { final ImageBuilder builder = new ImageBuilder() .id(image.name()) .name(image.label()) .description(image.description()) .status(Image.Status.AVAILABLE) .uri(image.mediaLink()) .providerId(image.name()) .location(FluentIterable.from(locations.get()) .firstMatch(LocationPredicates.idEquals(image.location())).orNull()); final OperatingSystem.Builder osBuilder = osFamily().apply(image); return builder.operatingSystem(osBuilder.build()).build(); }
@Override public NodeMetadata apply(Server from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getName()); Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(from.getDatacenter().getId() + "")); builder.location(location); builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName())); builder.hardware(parseHardware(from)); builder.imageId(from.getImage().getId() + ""); Image image = parseImage(from); if (image != null) builder.operatingSystem(image.getOperatingSystem()); builder.status(serverStateToNodeStatus.get(from.getState())); builder.publicAddresses(ImmutableSet.of(from.getIp().getIp())); return builder.build(); }
@Override public NodeMetadata apply(Server from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getName()); Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(from.getDatacenter().getId() + "")); builder.location(location); builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName())); builder.hardware(parseHardware(from)); builder.imageId(from.getImage().getId() + ""); Image image = parseImage(from); if (image != null) builder.operatingSystem(image.getOperatingSystem()); builder.status(serverStateToNodeStatus.get(from.getState())); builder.publicAddresses(ImmutableSet.of(from.getIp().getIp())); return builder.build(); }
@Override public NodeMetadata apply(Server from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getName()); Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(from.getDatacenter().getId() + "")); builder.location(location); builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName())); builder.hardware(parseHardware(from)); builder.imageId(from.getImage().getId() + ""); Image image = parseImage(from); if (image != null) builder.operatingSystem(image.getOperatingSystem()); builder.status(serverStateToNodeStatus.get(from.getState())); builder.publicAddresses(ImmutableSet.of(from.getIp().getIp())); return builder.build(); }
@Override public NodeMetadata apply(Server from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getName()); Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(from.getDatacenter().getId() + "")); builder.location(location); builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName())); builder.hardware(parseHardware(from)); builder.imageId(from.getImage().getId() + ""); Image image = parseImage(from); if (image != null) builder.operatingSystem(image.getOperatingSystem()); builder.status(serverStateToNodeStatus.get(from.getState())); builder.publicAddresses(ImmutableSet.of(from.getIp().getIp())); return builder.build(); }