EC2CloudManager extends TimerTask implements InstanceManager { @Override public InstanceType getSuitableInstanceType(final int minNumComputeUnits, final int minNumCPUCores, final int minMemorySize, final int minDiskCapacity, final int maxPricePerHour) { for (final InstanceType i : availableInstanceTypes) { if ((i.getNumberOfComputeUnits() >= minNumComputeUnits) && (i.getNumberOfCores() >= minNumCPUCores) && (i.getMemorySize() >= minMemorySize) && (i.getDiskCapacity() >= minDiskCapacity) && (i.getPricePerHour() <= maxPricePerHour)) { return i; } } return null; } EC2CloudManager(); @Override InstanceType getSuitableInstanceType(final int minNumComputeUnits, final int minNumCPUCores,
			final int minMemorySize, final int minDiskCapacity, final int maxPricePerHour); @Override synchronized void releaseAllocatedResource(final JobID jobID, final Configuration conf,
			final AllocatedResource allocatedResource); @Override synchronized void reportHeartBeat(final InstanceConnectionInfo instanceConnectionInfo,
			final HardwareDescription hardwareDescription); @Override void requestInstance(final JobID jobID, Configuration conf, final InstanceRequestMap instanceRequestMap,
			final List<String> splitAffinityList); @Override void run(); @Override InstanceType getDefaultInstanceType(); @Override synchronized InstanceType getInstanceTypeByName(String instanceTypeName); @Override void shutdown(); @Override NetworkTopology getNetworkTopology(final JobID jobID); @Override void setInstanceListener(final InstanceListener instanceListener); @Override Map<InstanceType, InstanceTypeDescription> getMapOfAvailableInstanceTypes(); @Override AbstractInstance getInstanceByName(final String name); @Override void cancelPendingRequests(final JobID jobID);  }
@Test public void testGetSuitableInstanceType() { GlobalConfiguration.loadConfiguration(System.getProperty("user.dir") + "/correct-conf"); MyInstanceListener myInstanceListener = new MyInstanceListener(); EC2CloudManager cm = new EC2CloudManager(); cm.setInstanceListener(myInstanceListener); InstanceType type1 = cm.getSuitableInstanceType(16, 16, 2048, 40, 80); InstanceType type2 = cm.getSuitableInstanceType(2, 2, 2048, 40, 10); InstanceType type3 = cm.getSuitableInstanceType(2, 2, 6144, 100, 50); InstanceType type4 = cm.getSuitableInstanceType(2, 2, 12288, 280, 100); assertNull(type1); assertNull(type2); assertEquals("m1.large", type3.getIdentifier()); assertEquals(4, type3.getNumberOfComputeUnits()); assertEquals(4, type3.getNumberOfCores()); assertEquals(6144, type3.getMemorySize()); assertEquals(160, type3.getDiskCapacity()); assertEquals(40, type3.getPricePerHour()); assertEquals("c1.xlarge", type4.getIdentifier()); assertEquals(8, type4.getNumberOfComputeUnits()); assertEquals(8, type4.getNumberOfCores()); assertEquals(28672, type4.getMemorySize()); assertEquals(280, type4.getDiskCapacity()); assertEquals(80, type4.getPricePerHour()); }