use of es.bsc.compss.types.CloudProvider in project compss by bsc-wdc.
the class CloudManagerTest method createProvider.
private static CloudProvider createProvider(CloudManager cm) {
String providerName = "Provider" + (int) (Math.random() * 10000);
Map<String, String> properties = new HashMap<>();
CloudProvider cp = null;
try {
cp = cm.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.CloudProvider 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.CloudProvider 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.CloudProvider in project compss by bsc-wdc.
the class ResourceOptimizer method askForResources.
/**
* The CloudManager ask for resources that can execute certain amount of cores at the same time. It checks the best
* resource that each provider can offer to execute that amount of cores and picks one of them. It constructs a
* resourceRequest describing the resource and which cores can be executed on it. This ResourceRequest will be used
* to ask for that resource creation to the Cloud Provider and returned if the application is accepted.
*
* @param amount
* amount of slots
* @param requirements
* features of the resource
* @param contained
* {@literal true} if we want the request to ask for a resource contained in the description; else, the
* result contains the passed in description.
* @return
*/
public static ResourceCreationRequest askForResources(Integer amount, MethodResourceDescription requirements, boolean contained) {
// Search best resource
CloudProvider bestProvider = null;
CloudMethodResourceDescription bestConstraints = null;
Float bestValue = Float.MAX_VALUE;
for (CloudProvider cp : ResourceManager.getAvailableCloudProviders()) {
CloudMethodResourceDescription rc = getBestIncreaseOnProvider(cp, amount, requirements, contained);
if (rc != null && rc.getValue() < bestValue) {
bestProvider = cp;
bestConstraints = rc;
bestValue = rc.getValue();
} else if (rc != null && bestConstraints == null) {
bestProvider = cp;
bestConstraints = rc;
bestValue = rc.getValue();
} else {
RUNTIME_LOGGER.warn(WARN_NO_POSIBLE_INCREASE + " (" + cp.getName() + ")");
}
}
if (bestConstraints == null) {
RUNTIME_LOGGER.warn(WARN_NO_RESOURCE_MATCHES);
return null;
}
return bestProvider.requestResourceCreation(bestConstraints);
}
use of es.bsc.compss.types.CloudProvider in project compss by bsc-wdc.
the class MOResourceOptimizer method generatePossibleResourceAcquisitions.
private void generatePossibleResourceAcquisitions(LinkedList<Action> actions, Resource<?>[] allResources, int[] load) {
for (CloudProvider cp : ResourceManager.getAvailableCloudProviders()) {
if (!cp.canHostMoreInstances()) {
continue;
}
for (CloudInstanceTypeDescription citd : cp.getAllTypes()) {
for (CloudImageDescription cid : cp.getAllImages()) {
Resource<?>[] resources = new Resource[allResources.length + 1];
System.arraycopy(allResources, 0, resources, 0, allResources.length);
resources[allResources.length] = createResourceForComponent(citd, cid);
ConfigurationCost cc = simulate(load, resources, 0, 0, 0);
Action a = new ActionAdd(cp, citd, cid, cc);
addToLog(a.toString());
actions.add(a);
}
}
}
}
Aggregations