static Hardware stub(String type, int cores, int ram, float disk) { return new org.jclouds.compute.domain.HardwareBuilder().ids(type).name(type) .processors(ImmutableList.of(new Processor(cores, 1.0))).ram(ram) .volumes(ImmutableList.<Volume> of(new VolumeImpl(disk, true, false))).build(); }
@Override public Hardware apply(org.jclouds.servermanager.Hardware from) { HardwareBuilder builder = new HardwareBuilder(); builder.ids(from.id + ""); builder.name(from.name); builder.processors(ImmutableList.of(new Processor(from.cores, 1.0))); builder.ram(from.ram); builder.volumes(ImmutableList.<Volume> of(new VolumeImpl(from.disk, true, false))); return builder.build(); }
protected Hardware parseHardware(final RunningInstance instance) { Hardware hardware = getHardwareForInstance(instance); if (hardware != null) { hardware = HardwareBuilder.fromHardware(hardware).volumes(addEBS(instance, hardware.getVolumes())).build(); } return hardware; }
@Override public Hardware getHardware(VirtualGuest guest) { return new HardwareBuilder().ids("mocked hardware").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(); } }
/** * 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 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 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)); }
/** * 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)); }
@Test public void testWhenNoHardwareOrImageMatchServerScopedIdsImageIdIsStillSet() { Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/FOOOOOOOO").providerId("FOOOOOOOO") .location(zone).build(); Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/FOOOOOOOO") .operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build()) .providerId("FOOOOOOOO").description("foobuntu").location(zone).status(Image.Status.AVAILABLE).build(); checkHardwareAndImageStatus(null, existingHardware, "az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54", null, existingImage); }
@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); }