@Override public EC2HardwareBuilder location(Location location) { return EC2HardwareBuilder.class.cast(super.location(location)); }
@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(); } }
/** * When locations are equal */ @Test public void testReturnFalseWhenISpecifyALocationWhichTheSameScopeByNotEqualToInputLocationAndParentsAreNull() { NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(region)); Hardware md = new HardwareBuilder().id("foo").location(otherRegion).build(); assertFalse(predicate.apply(md)); }
@Override public Hardware apply(FlavorInZone flavorInZone) { Location location = locationIndex.get().get(flavorInZone.getZone()); checkState(location != null, "location %s not in locationIndex: %s", flavorInZone.getZone(), locationIndex.get()); Flavor flavor = flavorInZone.getFlavor(); return new HardwareBuilder().id(flavorInZone.slashEncode()).providerId(flavor.getId()).name(flavor.getName()) .ram(flavor.getRam()).processor(new Processor(flavor.getVcpus(), 1.0)).volume( new VolumeImpl(Float.valueOf(flavor.getDisk()), true, true)).location(location).build(); } }
@Test public void testReturnTrueWhenISpecifyARegionAndInputLocationIsProvider() { NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(region)); Hardware md = new HardwareBuilder().id("foo").location(provider).build(); assertTrue(predicate.apply(md)); }
/** * Only the PROVIDER scope should have a null parent, It is an illegal state if a ZONE or REGION are orphaned * */ @Test(expectedExceptions = IllegalArgumentException.class) public void testThrowIllegalArgumentExceptionWhenWhenISpecifyAnOrphanedRegion() { NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(orphanedRegion)); Hardware md = new HardwareBuilder().id("foo").location(region).build(); predicate.apply(md); }
/** * Only the PROVIDER scope should have a null parent, It is an illegal state if a ZONE or REGION are orphaned * */ @Test(expectedExceptions = IllegalArgumentException.class) public void testThrowIllegalArgumentExceptionWhenWhenISpecifyAnOrphanedZone() { NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(orphanedZone)); Hardware md = new HardwareBuilder().id("foo").location(region).build(); predicate.apply(md); }
/** * If the input location is null, then the data isn't location sensitive */ public void testReturnTrueWhenISpecifyALocationAndInputLocationIsNull() { NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(region)); Hardware md = new HardwareBuilder().id("foo").location(null).build(); assertTrue(predicate.apply(md)); }
/** * Only the PROVIDER scope should have a null parent, It is an illegal state if a ZONE or REGION are orphaned * */ @Test(expectedExceptions = IllegalStateException.class) public void testThrowIllegalStateExceptionWhenInputIsAnOrphanedZone() { NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(region)); Hardware md = new HardwareBuilder().id("foo").location(orphanedZone).build(); predicate.apply(md); }
/** * If the input location is null, then the data isn't location sensitive */ public void testReturnTrueWhenIDontSpecifyALocationAndInputLocationIsNull() { NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.<Location> ofInstance(null)); Hardware md = new HardwareBuilder().id("foo").location(null).build(); assertTrue(predicate.apply(md)); }
/** * If the input location is a grandparent of the specified location, then we * are ok. */ public void testReturnFalseWhenISpecifyALocationWhichIsNotAGrandChildOfInput() { NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(host)); Hardware md = new HardwareBuilder().id("foo").location(otherRegion).build(); assertFalse(predicate.apply(md)); }
/** * Only the PROVIDER scope should have a null parent, It is an illegal state if a ZONE or REGION are orphaned * */ @Test(expectedExceptions = IllegalStateException.class) public void testThrowIllegalStateExceptionWhenInputIsAnOrphanedRegion() { NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(region)); Hardware md = new HardwareBuilder().id("foo").location(orphanedRegion).build(); predicate.apply(md); }
/** * If the input location is a grandparent of the specified location, then we * are ok. */ public void testReturnTrueWhenISpecifyALocationWhichIsAGrandChildOfInput() { NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(host)); Hardware md = new HardwareBuilder().id("foo").location(host).build(); assertTrue(predicate.apply(md)); }
/** * If the current location id is null, then we don't care where to launch a */ public void testReturnTrueWhenIDontSpecifyALocation() { NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.<Location> ofInstance(null)); Hardware md = new HardwareBuilder().id("foo").location(region).build(); assertTrue(predicate.apply(md)); }
/** * If the input location is null, then the data isn't location sensitive */ public void testReturnFalseWhenISpecifyALocationWhichTheSameScopeByNotEqualToInputLocationAndParentsAreNotNull() { NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(zone)); Hardware md = new HardwareBuilder().id("foo").location(otherZone).build(); assertFalse(predicate.apply(md)); }
/** * If the input location is a parent of the specified location, then we are * ok. */ public void testReturnTrueWhenISpecifyALocationWhichIsAChildOfInput() { NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(zone)); Hardware md = new HardwareBuilder().id("foo").location(region).build(); assertTrue(predicate.apply(md)); }
/** * If the input location is a parent of the specified location, then we are * ok. */ public void testReturnFalseWhenISpecifyALocationWhichIsNotAChildOfInput() { NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(zone)); Hardware md = new HardwareBuilder().id("foo").location(otherRegion).build(); assertFalse(predicate.apply(md)); }
@SuppressWarnings("unchecked") public static HardwareBuilder fromHardware(Hardware in) { return new HardwareBuilder().id(in.getId()).providerId(in.getProviderId()).location(in.getLocation()).name( in.getName()).uri(in.getUri()).userMetadata(in.getUserMetadata()).tags(in.getTags()).processors( List.class.cast(in.getProcessors())).ram(in.getRam()).volumes(List.class.cast(in.getVolumes())) .supportsImage(in.supportsImage()).hypervisor(in.getHypervisor()); } }
@SuppressWarnings("unchecked") public static HardwareBuilder fromHardware(Hardware in) { return new HardwareBuilder().id(in.getId()).providerId(in.getProviderId()).location(in.getLocation()).name( in.getName()).uri(in.getUri()).userMetadata(in.getUserMetadata()).tags(in.getTags()).processors( List.class.cast(in.getProcessors())).ram(in.getRam()).volumes(List.class.cast(in.getVolumes())) .supportsImage(in.supportsImage()).hypervisor(in.getHypervisor()); } }
@Test public void testWhenNoHardwareAndImageMatchServerScopedIdsHardwareOperatingSystemAndImageIdAreSet() { Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f216543fd") .providerId("52415800-8b69-11e0-9b19-734f216543fd").location(zone).build(); Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54") .operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build()) .providerId("52415800-8b69-11e0-9b19-734f6f006e54").description("foobuntu").status(Image.Status.AVAILABLE) .location(zone).build(); checkHardwareAndImageStatus(existingHardware, existingHardware, existingImage.getId(), existingImage.getOperatingSystem(), existingImage); }