use of es.bsc.compss.types.resources.description.CloudInstanceTypeDescription in project compss by bsc-wdc.
the class ResourceManagerTest method addProvider.
private static CloudProvider addProvider() {
String providerName = "Provider" + (int) (Math.random() * 10000);
Map<String, String> properties = new HashMap<>();
CloudProvider cp = null;
try {
cp = ResourceManager.registerCloudProvider(providerName, 0, RUNTIME_CONNECTOR, null, null, properties);
} catch (Exception e) {
fail("Could not create the Cloud Provider");
}
String imageName = "IMAGE" + (int) (Math.random() * 10000);
CloudImageDescription cid = new CloudImageDescription(imageName, new HashMap<>());
cp.addCloudImage(cid);
String typeName = "TYPE" + (int) (Math.random() * 10000);
float type1Memory = (float) Math.random() * 5;
MethodResourceDescription mrd1 = new MethodResourceDescription();
mrd1.setMemorySize(type1Memory);
CloudInstanceTypeDescription citd = new CloudInstanceTypeDescription(typeName, mrd1);
cp.addInstanceType(citd);
return cp;
}
use of es.bsc.compss.types.resources.description.CloudInstanceTypeDescription in project compss by bsc-wdc.
the class ResourceManagerTest method createResourceDescriptionFromProvider.
private CloudMethodResourceDescription createResourceDescriptionFromProvider(CloudProvider cp1) {
CloudImageDescription cid = null;
CloudInstanceTypeDescription citd = null;
for (String imageName : cp1.getAllImageNames()) {
cid = cp1.getImage(imageName);
break;
}
for (String instanceType : cp1.getAllInstanceTypeNames()) {
citd = cp1.getInstanceType(instanceType);
break;
}
return new CloudMethodResourceDescription(citd, cid);
}
use of es.bsc.compss.types.resources.description.CloudInstanceTypeDescription in project compss by bsc-wdc.
the class ResourceManagerTest method testMultipleCloudWorkersOperations.
@Test
public void testMultipleCloudWorkersOperations() {
ResourceManager.setCloudVMsBoundaries(3, 5, 8);
CloudProvider cp1 = addProvider();
CloudProvider cp2 = addProvider();
CloudMethodResourceDescription cmrd1 = createResourceDescriptionFromProvider(cp1);
ResourceCreationRequest rcr1 = cp1.requestResourceCreation(cmrd1);
CloudMethodResourceDescription cmrd2 = createResourceDescriptionFromProvider(cp2);
ResourceCreationRequest rcr2 = cp2.requestResourceCreation(cmrd1);
CloudMethodResourceDescription cmrd3 = createResourceDescriptionFromProvider(cp1);
ResourceCreationRequest rcr3 = cp1.requestResourceCreation(cmrd3);
if (ResourceManager.getPendingCreationRequests().size() != 3 || !ResourceManager.getPendingCreationRequests().contains(rcr1) || !ResourceManager.getPendingCreationRequests().contains(rcr2) || !ResourceManager.getPendingCreationRequests().contains(rcr3)) {
fail("ResourceManager is not properly registering the pending resouce creations");
}
String vmName1 = "VM" + (int) (Math.random() * 1000);
ExtendedCloudMethodWorker cmw1 = new ExtendedCloudMethodWorker(vmName1, cp1, cmrd1, new FakeNode(vmName1), 0, new HashMap<>());
ResourceManager.addCloudWorker(rcr1, cmw1, cmrd1);
if (ResourceManager.getPendingCreationRequests().size() != 2 || ResourceManager.getPendingCreationRequests().contains(rcr1)) {
fail("ResourceManager is not properly registering the pending resouce creations");
}
if (ResourceManager.getDynamicResources().size() != 1 || ResourceManager.getAllWorkers().size() != 1 || ResourceManager.getDynamicResource(vmName1) != cmw1 || ResourceManager.getWorker(vmName1) != cmw1) {
fail("ResourceManager is not properly adding the new cloud resources");
}
String vmName2 = "VM" + (int) (Math.random() * 1000);
ExtendedCloudMethodWorker cmw2 = new ExtendedCloudMethodWorker(vmName2, cp2, cmrd2, new FakeNode(vmName2), 0, new HashMap<>());
ResourceManager.addCloudWorker(rcr2, cmw2, cmrd2);
if (ResourceManager.getPendingCreationRequests().size() != 1 || ResourceManager.getPendingCreationRequests().contains(rcr2)) {
fail("ResourceManager is not properly registering the pending resouce creations");
}
if (ResourceManager.getDynamicResources().size() != 2 || ResourceManager.getAllWorkers().size() != 2 || ResourceManager.getDynamicResource(vmName2) != cmw2 || ResourceManager.getWorker(vmName2) != cmw2) {
fail("ResourceManager is not properly adding the new cloud resources");
}
CloudMethodResourceDescription reduction1 = new CloudMethodResourceDescription(cmrd1);
ResourceManager.reduceResource(cmw1, new PendingReduction<>(reduction1));
ResourceManager.terminateCloudResource(cmw1, reduction1);
if (ResourceManager.getPendingCreationRequests().size() != 1) {
fail("ResourceManager is not properly registering the pending resouce creations");
}
if (ResourceManager.getCurrentVMCount() != 2) {
fail("ResourceManager is not properly keeping track of the created VMs");
}
if (ResourceManager.getDynamicResources().size() != 1 || ResourceManager.getAllWorkers().size() != 1 || ResourceManager.getDynamicResource(vmName1) != null || ResourceManager.getWorker(vmName1) != null) {
fail("ResourceManager is not properly removing the new cloud resources");
}
if (!cmw1.isTerminated()) {
fail("ResourceManager is not properly requesting the resource shutdown");
}
String vmName3 = "VM" + (int) (Math.random() * 1000);
ExtendedCloudMethodWorker cmw3 = new ExtendedCloudMethodWorker(vmName3, cp1, cmrd3, new FakeNode(vmName3), 0, new HashMap<>());
ResourceManager.addCloudWorker(rcr3, cmw3, cmrd3);
if (!ResourceManager.getPendingCreationRequests().isEmpty()) {
fail("ResourceManager is not properly registering the pending resouce creations");
}
if (ResourceManager.getDynamicResources().size() != 2 || ResourceManager.getAllWorkers().size() != 2 || ResourceManager.getDynamicResource(vmName3) != cmw3 || ResourceManager.getWorker(vmName3) != cmw3) {
fail("ResourceManager is not properly adding the new cloud resources");
}
CloudMethodResourceDescription reduction2 = new CloudMethodResourceDescription(cmrd2);
ResourceManager.reduceResource(cmw2, new PendingReduction<>(reduction2));
ResourceManager.terminateCloudResource(cmw2, reduction2);
if (ResourceManager.getDynamicResources().size() != 1 || ResourceManager.getAllWorkers().size() != 1 || ResourceManager.getDynamicResource(vmName2) != null || ResourceManager.getWorker(vmName2) != null) {
fail("ResourceManager is not properly removing the new cloud resources");
}
if (!cmw2.isTerminated()) {
fail("ResourceManager is not properly requesting the resource shutdown");
}
if (ResourceManager.getCurrentVMCount() != 1) {
fail("ResourceManager is not properly keeping track of the created VMs");
}
CloudMethodResourceDescription cmrd4 = createResourceDescriptionFromProvider(cp1);
ResourceCreationRequest rcr4 = cp1.requestResourceCreation(cmrd4);
if (ResourceManager.getPendingCreationRequests().size() != 1 || !ResourceManager.getPendingCreationRequests().contains(rcr4)) {
fail("ResourceManager is not properly registering the pending resouce creations");
}
if (ResourceManager.getCurrentVMCount() != 2) {
fail("ResourceManager is not properly keeping track of the created VMs");
}
for (java.util.Map.Entry<CloudInstanceTypeDescription, int[]> entry : cmw3.getDescription().getTypeComposition().entrySet()) {
if (entry.getValue()[0] != 1) {
fail("ResourceManager is not properly keeping track of the amount of instances of each type");
}
}
ResourceManager.increasedCloudWorker(rcr4, cmw3, cmrd4);
if (!ResourceManager.getPendingCreationRequests().isEmpty()) {
fail("ResourceManager is not properly registering the pending resouce creations");
}
if (ResourceManager.getDynamicResources().size() != 1 || ResourceManager.getAllWorkers().size() != 1 || ResourceManager.getDynamicResource(vmName3) != cmw3 || ResourceManager.getWorker(vmName3) != cmw3) {
fail("ResourceManager is not properly removing the new cloud resources");
}
if (ResourceManager.getCurrentVMCount() != 2) {
fail("ResourceManager is not properly keeping track of the created VMs");
}
for (java.util.Map.Entry<CloudInstanceTypeDescription, int[]> entry : cmw3.getDescription().getTypeComposition().entrySet()) {
if (entry.getValue()[0] != 2) {
fail("ResourceManager is not properly keeping track of the amount of instances of each type");
}
}
CloudMethodResourceDescription reduction4 = new CloudMethodResourceDescription(cmrd4);
ResourceManager.reduceResource(cmw3, new PendingReduction<>(reduction4));
ResourceManager.terminateCloudResource(cmw3, reduction4);
if (ResourceManager.getDynamicResources().size() != 1 || ResourceManager.getAllWorkers().size() != 1 || ResourceManager.getDynamicResource(vmName3) != cmw3 || ResourceManager.getWorker(vmName3) != cmw3) {
fail("ResourceManager is not properly removing the new cloud resources");
}
if (ResourceManager.getCurrentVMCount() != 1) {
fail("ResourceManager is not properly keeping track of the created VMs");
}
for (java.util.Map.Entry<CloudInstanceTypeDescription, int[]> entry : cmw3.getDescription().getTypeComposition().entrySet()) {
if (entry.getValue()[0] != 1) {
fail("ResourceManager is not properly keeping track of the amount of instances of each type");
}
}
CloudMethodResourceDescription reduction3 = new CloudMethodResourceDescription(cmrd3);
ResourceManager.reduceResource(cmw3, new PendingReduction<>(reduction3));
ResourceManager.terminateCloudResource(cmw3, reduction3);
if (!ResourceManager.getDynamicResources().isEmpty() || !ResourceManager.getAllWorkers().isEmpty() || ResourceManager.getDynamicResource(vmName3) != null || ResourceManager.getWorker(vmName3) != null) {
fail("ResourceManager is not properly removing the new cloud resources");
}
if (ResourceManager.getCurrentVMCount() != 0) {
fail("ResourceManager is not properly keeping track of the created VMs");
}
for (java.util.Map.Entry<CloudInstanceTypeDescription, int[]> entry : cmw3.getDescription().getTypeComposition().entrySet()) {
if (entry.getValue()[0] != 0) {
fail("ResourceManager is not properly keeping track of the amount of instances of each type");
}
}
}
use of es.bsc.compss.types.resources.description.CloudInstanceTypeDescription in project compss by bsc-wdc.
the class ResourceOptimizer method mandatoryReduction.
private void mandatoryReduction(float[] destroyRecommendations) {
List<CloudMethodWorker> critical = trimReductionOptions(ResourceManager.getCriticalDynamicResources(), destroyRecommendations);
// LinkedList<CloudMethodWorker> critical = checkCriticalSafeness
// (critical);
List<CloudMethodWorker> nonCritical = trimReductionOptions(ResourceManager.getNonCriticalDynamicResources(), destroyRecommendations);
Object[] criticalSolution = getBestDestruction(critical, destroyRecommendations);
Object[] nonCriticalSolution = getBestDestruction(nonCritical, destroyRecommendations);
boolean criticalIsBetter;
if (criticalSolution == null) {
if (nonCriticalSolution == null) {
return;
} else {
criticalIsBetter = false;
}
} else if (nonCriticalSolution == null) {
criticalIsBetter = true;
} else {
criticalIsBetter = false;
float[] noncriticalValues = (float[]) nonCriticalSolution[2];
float[] criticalValues = (float[]) criticalSolution[2];
if (noncriticalValues[0] == criticalValues[0]) {
if (noncriticalValues[1] == criticalValues[1]) {
if (noncriticalValues[2] < criticalValues[2]) {
criticalIsBetter = true;
}
} else if (noncriticalValues[1] > criticalValues[1]) {
criticalIsBetter = true;
}
} else if (noncriticalValues[0] > criticalValues[0]) {
criticalIsBetter = true;
}
}
CloudMethodWorker res;
CloudMethodResourceDescription cmrd;
// float[] record;
// int[][] slotsRemovingCount;
CloudInstanceTypeDescription citd;
if (criticalIsBetter) {
res = (CloudMethodWorker) criticalSolution[0];
citd = (CloudInstanceTypeDescription) criticalSolution[1];
} else {
if (nonCriticalSolution == null) {
return;
}
res = (CloudMethodWorker) nonCriticalSolution[0];
citd = (CloudInstanceTypeDescription) nonCriticalSolution[1];
}
cmrd = (CloudMethodResourceDescription) res.getDescription();
CloudImageDescription cid = cmrd.getImage();
CloudMethodResourceDescription finalDescription = new CloudMethodResourceDescription(citd, cid);
finalDescription.setName(res.getName());
ResourceManager.reduceCloudWorker(res, finalDescription);
}
use of es.bsc.compss.types.resources.description.CloudInstanceTypeDescription in project compss by bsc-wdc.
the class ResourceOptimizer method selectContainedInstance.
private static CloudInstanceTypeDescription selectContainedInstance(List<CloudInstanceTypeDescription> instances, MethodResourceDescription constraints, int amount) {
CloudInstanceTypeDescription bestType = null;
MethodResourceDescription bestDescription = null;
float bestDistance = Integer.MAX_VALUE;
for (CloudInstanceTypeDescription type : instances) {
MethodResourceDescription rd = type.getResourceDescription();
int slots = rd.canHostSimultaneously(constraints);
float distance = slots - amount;
RUNTIME_LOGGER.debug("[Resource Optimizer] Can host: slots = " + slots + " amount = " + amount + " distance = " + distance + " bestDistance = " + bestDistance);
if (distance < 0.0) {
continue;
}
if (distance < bestDistance) {
bestType = type;
bestDescription = type.getResourceDescription();
bestDistance = distance;
} else if (distance == bestDistance && bestDescription != null) {
if (bestDescription.getValue() != null && rd.getValue() != null && bestDescription.getValue() > rd.getValue()) {
// Evaluate optimal candidate
bestType = type;
bestDescription = type.getResourceDescription();
bestDistance = distance;
}
}
}
if (bestType == null) {
return null;
}
return bestType;
}
Aggregations