Search in sources :

Example 1 with CloudImageDescription

use of es.bsc.compss.types.resources.description.CloudImageDescription in project compss by bsc-wdc.

the class ResourceOptimizer method getBestIncreaseOnProvider.

public static CloudMethodResourceDescription getBestIncreaseOnProvider(CloudProvider cp, Integer amount, MethodResourceDescription requirements, boolean contained) {
    RUNTIME_LOGGER.debug("[Resource Optimizer] Getting best increase in provider " + cp.getName());
    // Check Cloud capabilities
    if (!cp.canHostMoreInstances()) {
        RUNTIME_LOGGER.warn(WARN_NO_MORE_INSTANCES);
        return null;
    }
    // Select all the compatible types
    List<CloudInstanceTypeDescription> instances = cp.getCompatibleTypes(requirements);
    RUNTIME_LOGGER.debug("[Resource Optimizer] There are " + instances.size() + " instances compatible.");
    if (instances.isEmpty()) {
        RUNTIME_LOGGER.warn(WARN_NO_COMPATIBLE_TYPE);
        return null;
    }
    CloudMethodResourceDescription result = null;
    CloudInstanceTypeDescription type = null;
    if (contained) {
        type = selectContainedInstance(instances, requirements, amount);
    } else {
        type = selectContainingInstance(instances, requirements, amount);
    }
    // Pick an image to be loaded in the Type (or return null)
    if (type != null) {
        // Select all the compatible images
        List<CloudImageDescription> images = cp.getCompatibleImages(requirements);
        RUNTIME_LOGGER.debug("[Resource Optimizer] There are " + images.size() + " images compatible.");
        if (!images.isEmpty()) {
            CloudImageDescription image = images.get(0);
            result = new CloudMethodResourceDescription(type, image);
            result.setValue(cp.getInstanceCostPerHour(result));
        } else {
            RUNTIME_LOGGER.warn(WARN_NO_COMPATIBLE_IMAGE);
        }
    } else {
        RUNTIME_LOGGER.warn(WARN_NO_VALID_INSTANCE);
    }
    return result;
}
Also used : CloudInstanceTypeDescription(es.bsc.compss.types.resources.description.CloudInstanceTypeDescription) CloudImageDescription(es.bsc.compss.types.resources.description.CloudImageDescription) CloudMethodResourceDescription(es.bsc.compss.types.resources.description.CloudMethodResourceDescription)

Example 2 with CloudImageDescription

use of es.bsc.compss.types.resources.description.CloudImageDescription in project compss by bsc-wdc.

the class Test method cloudManagerTest.

/*
     * *********************************** CLOUD MANAGER TEST IMPLEMENTATION ***********************************
     */
private static void cloudManagerTest() {
    // Print Out CloudManager static structures
    System.out.println("[LOG] CloudManager Static Structures definition");
    // Check for each implementation the correctness of its resources
    coreCount = CoreManager.getCoreCount();
    CloudProvider cp = ResourceManager.getCloudProvider("BSC");
    for (int coreId = 0; coreId < coreCount; coreId++) {
        System.out.println("[LOG] Checking Core" + coreId);
        for (Implementation impl : CoreManager.getCoreImplementations(coreId)) {
            if (impl.getTaskType().equals(TaskType.METHOD)) {
                System.out.println("[LOG]\t Checking Implementation: " + impl.getImplementationId());
                System.out.println("\t\t Checking obtained compatible cloud images");
                MethodImplementation mImpl = (MethodImplementation) impl;
                for (CloudImageDescription cid_gci : cp.getCompatibleImages(mImpl.getRequirements())) {
                    System.out.println("\t\t\t Checking compatible Image: " + cid_gci.getImageName());
                    String res = checkImplementationAssignedToCloudImage(mImpl.getRequirements(), cid_gci);
                    if (res != null) {
                        String error = "[ERROR] Implementation: Core = " + coreId + " Impl = " + impl.getImplementationId() + ". ";
                        error = error.concat("Implementation and cloud image not matching on: " + res);
                        System.out.println(error);
                        System.exit(-1);
                    }
                }
                System.out.println("\t\t Checking obtained compatible cloud types");
                for (CloudInstanceTypeDescription type : cp.getCompatibleTypes(new CloudMethodResourceDescription(mImpl.getRequirements()))) {
                    if (type.getResourceDescription().canHostSimultaneously(mImpl.getRequirements()) < 1) {
                        continue;
                    }
                    System.out.println("\t\t\t Checking compatible Type: " + type.getName());
                    String res = checkImplementationAssignedToType(mImpl.getRequirements(), type.getResourceDescription());
                    if (res != null) {
                        String error = "[ERROR] Implementation: Core = " + coreId + " Impl = " + impl.getImplementationId() + ". ";
                        error = error.concat("Implementation and type not matching on: " + res);
                        System.out.println(error);
                        System.exit(-1);
                    }
                }
            }
        }
    }
    // Return success value
    System.out.println("[LOG] * CloudManager test passed");
}
Also used : MethodImplementation(es.bsc.compss.types.implementations.MethodImplementation) CloudProvider(es.bsc.compss.types.CloudProvider) CloudImageDescription(es.bsc.compss.types.resources.description.CloudImageDescription) CloudInstanceTypeDescription(es.bsc.compss.types.resources.description.CloudInstanceTypeDescription) CloudMethodResourceDescription(es.bsc.compss.types.resources.description.CloudMethodResourceDescription) MethodImplementation(es.bsc.compss.types.implementations.MethodImplementation) Implementation(es.bsc.compss.types.implementations.Implementation)

Example 3 with CloudImageDescription

use of es.bsc.compss.types.resources.description.CloudImageDescription in project compss by bsc-wdc.

the class CloudProviderTest method testCreateTwoVMOneResource.

@Test
public void testCreateTwoVMOneResource() {
    Map<String, String> properties = new HashMap<>();
    CloudProvider cp = null;
    try {
        cp = new CloudProvider(PROVIDER_NAME, 0, RUNTIME_CONNECTOR, null, null, properties);
    } catch (Exception e) {
        fail("Could not create the Cloud Provider");
        return;
    }
    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);
    CloudMethodResourceDescription cmrd = new CloudMethodResourceDescription(citd, cid);
    ResourceCreationRequest crc = cp.requestResourceCreation(cmrd);
    CloudMethodResourceDescription cmrd2 = new CloudMethodResourceDescription(citd, cid);
    ResourceCreationRequest crc2 = cp.requestResourceCreation(cmrd2);
    String vmName = "VM" + (int) (Math.random() * 1000);
    CloudMethodWorker cmw = new CloudMethodWorker(vmName, cp, cmrd, new FakeNode(vmName), 0, 0, 0, 0, new HashMap<>());
    CloudMethodResourceDescription granted = new CloudMethodResourceDescription(citd, cid);
    cp.confirmedCreation(crc, cmw, granted);
    if (cp.getCurrentVMCount() != 2) {
        fail("Cloud Provider is not properly accounting the number of requested VMs");
    }
    List<ResourceCreationRequest> pendingRequests = cp.getPendingRequests();
    Set<CloudMethodWorker> workers = cp.getHostedWorkers();
    if (pendingRequests.size() != 1) {
        fail("Cloud Provider is not properly registering the pending creations requests");
    }
    if (workers.size() != 1) {
        fail("Cloud Provider is not properly registering the hosted workers");
    }
    if (!workers.contains(cmw)) {
        fail("Cloud Provider is not properly registering the hosted workers");
    }
    granted = new CloudMethodResourceDescription(citd, cid);
    cp.confirmedCreation(crc2, cmw, granted);
    if (cp.getCurrentVMCount() != 2) {
        fail("Cloud Provider is not properly accounting the number of requested VMs");
    }
    pendingRequests = cp.getPendingRequests();
    workers = cp.getHostedWorkers();
    if (!pendingRequests.isEmpty()) {
        fail("Cloud Provider is not properly registering the pending creations requests");
    }
    if (workers.size() != 1) {
        fail("Cloud Provider is not properly registering the hosted workers");
    }
    if (!workers.contains(cmw)) {
        fail("Cloud Provider is not properly registering the hosted workers");
    }
}
Also used : HashMap(java.util.HashMap) CloudImageDescription(es.bsc.compss.types.resources.description.CloudImageDescription) CloudMethodResourceDescription(es.bsc.compss.types.resources.description.CloudMethodResourceDescription) FakeNode(es.bsc.compss.types.fake.FakeNode) CloudInstanceTypeDescription(es.bsc.compss.types.resources.description.CloudInstanceTypeDescription) CloudMethodWorker(es.bsc.compss.types.resources.CloudMethodWorker) CloudMethodResourceDescription(es.bsc.compss.types.resources.description.CloudMethodResourceDescription) MethodResourceDescription(es.bsc.compss.types.resources.MethodResourceDescription) Test(org.junit.Test)

Example 4 with CloudImageDescription

use of es.bsc.compss.types.resources.description.CloudImageDescription in project compss by bsc-wdc.

the class CloudProviderTest method testDestroyOneVMOneResource.

@Test
public void testDestroyOneVMOneResource() {
    Map<String, String> properties = new HashMap<>();
    CloudProvider cp = null;
    try {
        cp = new CloudProvider(PROVIDER_NAME, 0, RUNTIME_CONNECTOR, null, null, properties);
    } catch (Exception e) {
        fail("Could not create the Cloud Provider");
        return;
    }
    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);
    CloudMethodResourceDescription cmrd = new CloudMethodResourceDescription(citd, cid);
    ResourceCreationRequest crc = cp.requestResourceCreation(cmrd);
    String vmName = "VM" + (int) (Math.random() * 1000);
    ExtendedCloudMethodWorker cmw = new ExtendedCloudMethodWorker(vmName, cp, cmrd, new FakeNode(vmName), 0, new HashMap<>());
    CloudMethodResourceDescription granted = new CloudMethodResourceDescription(citd, cid);
    cp.confirmedCreation(crc, cmw, granted);
    CloudMethodResourceDescription reduction = new CloudMethodResourceDescription(citd, cid);
    cmw.getDescription().reduce(reduction);
    cp.requestResourceReduction(cmw, reduction);
    if (cp.getCurrentVMCount() != 0) {
        fail("Cloud Provider is not properly accounting the number of requested VMs");
    }
    List<ResourceCreationRequest> pendingRequests = cp.getPendingRequests();
    Set<CloudMethodWorker> workers = cp.getHostedWorkers();
    if (!pendingRequests.isEmpty()) {
        fail("Cloud Provider is not properly registering the pending creations requests");
    }
    if (!workers.isEmpty()) {
        fail("Cloud Provider is not properly registering the hosted workers");
    }
}
Also used : HashMap(java.util.HashMap) CloudImageDescription(es.bsc.compss.types.resources.description.CloudImageDescription) CloudMethodResourceDescription(es.bsc.compss.types.resources.description.CloudMethodResourceDescription) FakeNode(es.bsc.compss.types.fake.FakeNode) CloudInstanceTypeDescription(es.bsc.compss.types.resources.description.CloudInstanceTypeDescription) CloudMethodWorker(es.bsc.compss.types.resources.CloudMethodWorker) CloudMethodResourceDescription(es.bsc.compss.types.resources.description.CloudMethodResourceDescription) MethodResourceDescription(es.bsc.compss.types.resources.MethodResourceDescription) Test(org.junit.Test)

Example 5 with CloudImageDescription

use of es.bsc.compss.types.resources.description.CloudImageDescription in project compss by bsc-wdc.

the class CloudProviderTest method testTurnOn.

@Test
public void testTurnOn() {
    Map<String, String> properties = new HashMap<>();
    CloudProvider cp = null;
    try {
        cp = new CloudProvider(PROVIDER_NAME, 0, RUNTIME_CONNECTOR, null, null, properties);
    } catch (Exception e) {
        fail("Could not create the Cloud Provider");
        return;
    }
    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);
    if (cp.getCurrentVMCount() != 0) {
        fail("Cloud Provider is not properly intialized the number of requested VMs should be 0");
    }
    CloudMethodResourceDescription cmrd = new CloudMethodResourceDescription(citd, cid);
    ResourceCreationRequest crc = cp.requestResourceCreation(cmrd);
    if (!FakeConnector.getProcessedRequests().contains(crc)) {
        fail("Turn on has not reached the connector");
    }
    if (cp.getCurrentVMCount() != 1) {
        fail("Cloud Provider is not properly accounting the number of requested VMs");
    }
    List<ResourceCreationRequest> pendingRequests = cp.getPendingRequests();
    if (!pendingRequests.contains(crc)) {
        fail("Cloud Provider is not properly registering the pending creations requests");
    }
    if (pendingRequests.size() != 1) {
        fail("Cloud Provider is not properly registering the pending creations requests");
    }
    cmrd = new CloudMethodResourceDescription(citd, cid);
    cmrd.addInstance(citd);
    ResourceCreationRequest crc2 = cp.requestResourceCreation(cmrd);
    pendingRequests = cp.getPendingRequests();
    if (!pendingRequests.contains(crc)) {
        fail("Cloud Provider is not properly registering the pending creations requests");
    }
    if (!pendingRequests.contains(crc2)) {
        fail("Cloud Provider is not properly registering the pending creations requests");
    }
    if (pendingRequests.size() != 2) {
        fail("Cloud Provider is not properly registering the pending creations requests");
    }
    if (!FakeConnector.getProcessedRequests().contains(crc)) {
        fail("Turn on has not reached the connector");
    }
    if (cp.getCurrentVMCount() != 3) {
        fail("Cloud Provider is not properly accounting the number of requested VMs");
    }
}
Also used : HashMap(java.util.HashMap) CloudImageDescription(es.bsc.compss.types.resources.description.CloudImageDescription) CloudMethodResourceDescription(es.bsc.compss.types.resources.description.CloudMethodResourceDescription) CloudInstanceTypeDescription(es.bsc.compss.types.resources.description.CloudInstanceTypeDescription) CloudMethodResourceDescription(es.bsc.compss.types.resources.description.CloudMethodResourceDescription) MethodResourceDescription(es.bsc.compss.types.resources.MethodResourceDescription) Test(org.junit.Test)

Aggregations

CloudImageDescription (es.bsc.compss.types.resources.description.CloudImageDescription)31 CloudMethodResourceDescription (es.bsc.compss.types.resources.description.CloudMethodResourceDescription)23 CloudInstanceTypeDescription (es.bsc.compss.types.resources.description.CloudInstanceTypeDescription)22 HashMap (java.util.HashMap)15 MethodResourceDescription (es.bsc.compss.types.resources.MethodResourceDescription)12 Test (org.junit.Test)12 CloudMethodWorker (es.bsc.compss.types.resources.CloudMethodWorker)9 FakeNode (es.bsc.compss.types.fake.FakeNode)7 CloudProvider (es.bsc.compss.types.CloudProvider)6 MethodConfiguration (es.bsc.compss.types.resources.configuration.MethodConfiguration)3 ConstructConfigurationException (es.bsc.compss.exceptions.ConstructConfigurationException)2 es.bsc.compss.types.project.jaxb (es.bsc.compss.types.project.jaxb)2 LinkedList (java.util.LinkedList)2 ConnectorException (es.bsc.compss.connectors.ConnectorException)1 NoResourceAvailableException (es.bsc.compss.exceptions.NoResourceAvailableException)1 ResourceCreationRequest (es.bsc.compss.types.ResourceCreationRequest)1 Implementation (es.bsc.compss.types.implementations.Implementation)1 MethodImplementation (es.bsc.compss.types.implementations.MethodImplementation)1 ProjectFileValidationException (es.bsc.compss.types.project.exceptions.ProjectFileValidationException)1 ShutdownListener (es.bsc.compss.types.resources.ShutdownListener)1