@Override public boolean apply(MachineType input) { return input.deprecated() == null && contains(zones, input.zone()); } });
public MachineType build() { return new MachineType(id, creationTimestamp, selfLink, name, description, guestCpus, memoryMb, imageSpaceGb, scratchDisks.build(), maximumPersistentDisks, maximumPersistentDisksSizeGb, zone, deprecated); }
public Builder fromMachineType(MachineType in) { return super.fromResource(in).memoryMb(in.getMemoryMb()).scratchDisks(in .getScratchDisks()).maximumPersistentDisks(in.getMaximumPersistentDisks()) .maximumPersistentDisksSizeGb(in.getMaximumPersistentDisksSizeGb()).zone(in.getZone()) .deprecated(in.getDeprecated().orNull()); } }
@Override public Hardware apply(MachineType input) { URI zoneLink = URI.create( input.selfLink().toString().replace("/machineTypes/" + input.name(), "")); Location zone = locationsByUri.get().get(zoneLink); if (zone == null) { throw new IllegalStateException( String.format("zone %s not present in %s", zoneLink, locationsByUri.get().keySet())); } return new HardwareBuilder() .id(input.selfLink().toString()) .providerId(input.id()) .location(zone) .name(input.name()) .hypervisor("kvm") .processor(new Processor(input.guestCpus(), 1.0)) .providerId(input.id()) .ram(input.memoryMb()) .uri(input.selfLink()) .volumes(collectVolumes(input)) .supportsImage(Predicates.<Image>alwaysTrue()) .build(); }
@Override public Hardware apply(final MachineTypeInZone input) { Iterable<? extends Location> zonesForMachineType = filter(locations.get().values(), new Predicate<Location>() { @Override public boolean apply(Location l) { return l.getId().equals(input.getMachineType().getZone()); } }); Location location = checkNotNull(getOnlyElement(zonesForMachineType), "location for %s", input.getMachineType().getZone()); // TODO Figure out a robust way to deal with machineTypes with imageSizeGb==0 rather than just blocking them. return new HardwareBuilder() .id(SlashEncodedIds.fromTwoIds(input.getMachineType().getZone(), input.getMachineType().getName()).slashEncode()) .location(location) .name(input.getMachineType().getName()) .hypervisor("kvm") .processor(new Processor(input.getMachineType().getGuestCpus(), 1.0)) .providerId(input.getMachineType().getId()) .ram(input.getMachineType().getMemoryMb()) .uri(input.getMachineType().getSelfLink()) .userMetadata(ImmutableMap.of("imageSpaceGb", Integer.toString(input.getMachineType().getImageSpaceGb()))) .volumes(collectVolumes(input.getMachineType())) .supportsImage(input.getMachineType().getImageSpaceGb() > 0 ? Predicates.<Image>alwaysTrue() : Predicates.<Image>alwaysFalse()) .build(); }
public void testListHardwareProfiles() throws Exception { GoogleComputeEngineApi api = client.getContext().unwrapApi(GoogleComputeEngineApi.class); ImmutableSet.Builder<String> deprecatedMachineTypes = ImmutableSet.builder(); for (MachineType machine : api.machineTypesInZone(DEFAULT_ZONE_NAME).list().next()) { if (machine.deprecated() != null) { deprecatedMachineTypes.add(machine.id()); } } ImmutableSet<String> deprecatedMachineTypeIds = deprecatedMachineTypes.build(); for (Hardware hardwareProfile : client.listHardwareProfiles()) { assertFalse(contains(deprecatedMachineTypeIds, hardwareProfile.getId())); } }
@Override public boolean apply(MachineType input) { return input.deprecated() == null; } });
private Iterable<Volume> collectVolumes(MachineType input) { ImmutableSet.Builder<Volume> volumes = ImmutableSet.builder(); for (MachineType.ScratchDisk disk : input.scratchDisks()) { volumes.add(new VolumeBuilder() .type(Volume.Type.LOCAL) .size(Float.valueOf(disk.diskGb())) .bootDevice(true) .durable(false).build()); } return volumes.build(); } }
@Override public Hardware apply(MachineType input) { URI zoneLink = URI.create( input.selfLink().toString().replace("/machineTypes/" + input.name(), "")); Location zone = locationsByUri.get().get(zoneLink); if (zone == null) { throw new IllegalStateException( String.format("zone %s not present in %s", zoneLink, locationsByUri.get().keySet())); } return new HardwareBuilder() .id(input.selfLink().toString()) .providerId(input.id()) .location(zone) .name(input.name()) .hypervisor("kvm") .processor(new Processor(input.guestCpus(), 1.0)) .providerId(input.id()) .ram(input.memoryMb()) .uri(input.selfLink()) .volumes(collectVolumes(input)) .supportsImage(Predicates.<Image>alwaysTrue()) .build(); }
@Override public Hardware apply(final MachineTypeInZone input) { Iterable<? extends Location> zonesForMachineType = filter(locations.get().values(), new Predicate<Location>() { @Override public boolean apply(Location l) { return l.getId().equals(input.getMachineType().getZone()); } }); Location location = checkNotNull(getOnlyElement(zonesForMachineType), "location for %s", input.getMachineType().getZone()); return new HardwareBuilder() .id(SlashEncodedIds.fromTwoIds(input.getMachineType().getZone(), input.getMachineType().getName()).slashEncode()) .location(location) .name(input.getMachineType().getName()) .hypervisor("kvm") .processor(new Processor(input.getMachineType().getGuestCpus(), 1.0)) .providerId(input.getMachineType().getId()) .ram(input.getMachineType().getMemoryMb()) .uri(input.getMachineType().getSelfLink()) .volumes(collectVolumes(input.getMachineType())) .supportsImage(Predicates.<Image>alwaysTrue()) .build(); }
@Override public boolean apply(MachineType input) { return input.deprecated() == null; } });
private Iterable<Volume> collectVolumes(MachineType input) { ImmutableSet.Builder<Volume> volumes = ImmutableSet.builder(); for (MachineType.ScratchDisk disk : input.scratchDisks()) { volumes.add(new VolumeBuilder() .type(Volume.Type.LOCAL) .size(Float.valueOf(disk.diskGb())) .bootDevice(true) .durable(false).build()); } return volumes.build(); } }
@Test(groups = "live", dependsOnMethods = "testListMachineType") public void testGetMachineType() { MachineType machineType = api().get(this.machineType.name()); assertNotNull(machineType); assertMachineTypeEquals(machineType, this.machineType); }
@Override public Hardware apply(MachineType input) { URI zoneLink = URI.create( input.selfLink().toString().replace("/machineTypes/" + input.name(), "")); Location zone = locationsByUri.get().get(zoneLink); if (zone == null) { throw new IllegalStateException( String.format("zone %s not present in %s", zoneLink, locationsByUri.get().keySet())); } return new HardwareBuilder() .id(input.selfLink().toString()) .providerId(input.id()) .location(zone) .name(input.name()) .hypervisor("kvm") .processor(new Processor(input.guestCpus(), 1.0)) .providerId(input.id()) .ram(input.memoryMb()) .uri(input.selfLink()) .volumes(collectVolumes(input)) .supportsImage(Predicates.<Image>alwaysTrue()) .build(); }
public Builder fromMachineType(MachineType in) { return super.fromResource(in).memoryMb(in.getMemoryMb()).imageSpaceGb(in.getImageSpaceGb()).scratchDisks(in .getScratchDisks()).maximumPersistentDisks(in.getMaximumPersistentDisks()) .maximumPersistentDisksSizeGb(in.getMaximumPersistentDisksSizeGb()).zone(in.getZone()) .deprecated(in.getDeprecated().orNull()); } }
@Override public boolean apply(MachineType input) { return input.deprecated() == null; } });
private Iterable<Volume> collectVolumes(MachineType input) { ImmutableSet.Builder<Volume> volumes = ImmutableSet.builder(); for (MachineType.ScratchDisk disk : input.scratchDisks()) { volumes.add(new VolumeBuilder() .type(Volume.Type.LOCAL) .size(Float.valueOf(disk.diskGb())) .bootDevice(true) .durable(false).build()); } return volumes.build(); } }
public MachineType build() { return new MachineType(id, creationTimestamp, selfLink, name, description, guestCpus, memoryMb, scratchDisks.build(), maximumPersistentDisks, maximumPersistentDisksSizeGb, zone, deprecated); }
@Override public Hardware apply(MachineType input) { URI zoneLink = URI.create( input.selfLink().toString().replace("/machineTypes/" + input.name(), "")); Location zone = locationsByUri.get().get(zoneLink); if (zone == null) { throw new IllegalStateException( String.format("zone %s not present in %s", zoneLink, locationsByUri.get().keySet())); } return new HardwareBuilder() .id(input.selfLink().toString()) .providerId(input.id()) .location(zone) .name(input.name()) .hypervisor("kvm") .processor(new Processor(input.guestCpus(), 1.0)) .providerId(input.id()) .ram(input.memoryMb()) .uri(input.selfLink()) .volumes(collectVolumes(input)) .supportsImage(Predicates.<Image>alwaysTrue()) .build(); }