Search in sources :

Example 41 with CloudMethodResourceDescription

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

the class CloudProviderTest method testDestroyTwoVMTwoResources.

@Test
public void testDestroyTwoVMTwoResources() {
    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);
    ExtendedCloudMethodWorker cmw = new ExtendedCloudMethodWorker(vmName, cp, cmrd, new FakeNode(vmName), 0, new HashMap<>());
    String vmName2 = "VM" + (int) (Math.random() * 1000);
    ExtendedCloudMethodWorker cmw2 = new ExtendedCloudMethodWorker(vmName, cp, cmrd2, new FakeNode(vmName2), 0, new HashMap<>());
    CloudMethodResourceDescription granted = new CloudMethodResourceDescription(citd, cid);
    cp.confirmedCreation(crc, cmw, granted);
    granted = new CloudMethodResourceDescription(citd, cid);
    cp.confirmedCreation(crc2, cmw2, granted);
    CloudMethodResourceDescription reduction = new CloudMethodResourceDescription(citd, cid);
    cmw.getDescription().reduce(reduction);
    cp.requestResourceReduction(cmw, reduction);
    if (cp.getCurrentVMCount() != 1) {
        fail("Cloud Provider is not properly accounting the number of requested VMs");
    }
    Set<CloudMethodWorker> workers = cp.getHostedWorkers();
    if (workers.size() != 1) {
        fail("Cloud Provider is not properly registering the hosted workers");
    }
    if (!workers.contains(cmw2)) {
        fail("Cloud Provider is not properly registering the hosted workers");
    }
    reduction = new CloudMethodResourceDescription(citd, cid);
    cmw2.getDescription().reduce(reduction);
    cp.requestResourceReduction(cmw2, reduction);
    if (cp.getCurrentVMCount() != 0) {
        fail("Cloud Provider is not properly accounting the number of requested VMs");
    }
    workers = cp.getHostedWorkers();
    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 42 with CloudMethodResourceDescription

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

the class CloudProviderTest method testCreateTwoVMTwoResources.

@Test
public void testCreateTwoVMTwoResources() {
    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);
    if (cp.getCurrentVMCount() != 2) {
        fail("Cloud Provider is not properly accounting the number of requested VMs");
    }
    String vmName = "VM" + (int) (Math.random() * 1000);
    CloudMethodWorker cmw = new CloudMethodWorker(vmName, cp, cmrd, new FakeNode(vmName), 0, 0, 0, 0, new HashMap<>());
    String vmName2 = "VM" + (int) (Math.random() * 1000);
    CloudMethodWorker cmw2 = new CloudMethodWorker(vmName2, cp, cmrd, new FakeNode(vmName2), 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, cmw2, 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() != 2) {
        fail("Cloud Provider is not properly registering the hosted workers");
    }
    if (!workers.contains(cmw)) {
        fail("Cloud Provider is not properly registering the hosted workers");
    }
    if (!workers.contains(cmw2)) {
        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 43 with CloudMethodResourceDescription

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

the class CreationThread method createResourceOnProvider.

private VM createResourceOnProvider(CloudMethodResourceDescription requested) throws ConnectorException {
    VM granted;
    Object envID;
    // ASK FOR THE VIRTUAL RESOURCE
    try {
        // Turn on the VM and expects the new mr description
        envID = operations.poweron(name, requested);
    } catch (ConnectorException e) {
        RUNTIME_LOGGER.error(ERROR_ASKING_NEW_RESOURCE + provider + "\n", e);
        RESOURCE_LOGGER.error("ERROR_MSG = [\n\t" + ERROR_ASKING_NEW_RESOURCE + provider + "\n]", e);
        throw e;
    }
    if (envID == null) {
        RUNTIME_LOGGER.info(WARN_CANNOT_PROVIDE_VM);
        RESOURCE_LOGGER.info("INFO_MSG = [\n\t" + provider + WARN_CANNOT_PROVIDE_VM + "\n]");
        throw new ConnectorException(WARN_CANNOT_PROVIDE_VM);
    }
    // WAITING FOR THE RESOURCES TO BE RUNNING
    try {
        // Wait until the VM has been created
        granted = operations.waitCreation(envID, requested);
    } catch (ConnectorException e) {
        RUNTIME_LOGGER.error(ERROR_WAITING_VM + provider + "\n", e);
        RESOURCE_LOGGER.error("ERROR_MSG = [\n\t" + ERROR_WAITING_VM + provider + "\n]", e);
        try {
            operations.destroy(envID);
        } catch (ConnectorException ex) {
            RUNTIME_LOGGER.error(ERROR_POWEROFF_VM);
            RESOURCE_LOGGER.error("ERROR_MSG = [\n\t" + ERROR_POWEROFF_VM + "\n]");
        }
        throw new ConnectorException("Error waiting for the vm");
    }
    if (granted != null) {
        RESOURCE_LOGGER.debug("CONNECTOR_REQUEST = [");
        RESOURCE_LOGGER.debug("\tPROC_CPU_CU = " + requested.getTotalCPUComputingUnits());
        RESOURCE_LOGGER.debug("\tPROC_GPU_CU = " + requested.getTotalGPUComputingUnits());
        RESOURCE_LOGGER.debug("\tPROC_FPGA_CU = " + requested.getTotalFPGAComputingUnits());
        RESOURCE_LOGGER.debug("\tPROC_OTHER_CU = " + requested.getTotalOTHERComputingUnits());
        RESOURCE_LOGGER.debug("\tOS = " + requested.getOperatingSystemType());
        RESOURCE_LOGGER.debug("\tMEM = " + requested.getMemorySize());
        RESOURCE_LOGGER.debug("]");
        CloudMethodResourceDescription desc = granted.getDescription();
        RESOURCE_LOGGER.debug("CONNECTOR_GRANTED = [");
        RESOURCE_LOGGER.debug("\tPROC_CPU_CU = " + desc.getTotalCPUComputingUnits());
        RESOURCE_LOGGER.debug("\tPROC_GPU_CU = " + desc.getTotalGPUComputingUnits());
        RESOURCE_LOGGER.debug("\tPROC_FPGA_CU = " + desc.getTotalFPGAComputingUnits());
        RESOURCE_LOGGER.debug("\tPROC_OTHER_CU = " + desc.getTotalOTHERComputingUnits());
        RESOURCE_LOGGER.debug("\tOS = " + desc.getOperatingSystemType());
        RESOURCE_LOGGER.debug("\tMEM = " + desc.getMemorySize());
        RESOURCE_LOGGER.debug("]");
    } else {
        throw new ConnectorException(ERROR_GRANTED_NULL);
    }
    return granted;
}
Also used : VM(es.bsc.compss.connectors.VM) ConnectorException(es.bsc.compss.connectors.ConnectorException) CloudMethodResourceDescription(es.bsc.compss.types.resources.description.CloudMethodResourceDescription)

Example 44 with CloudMethodResourceDescription

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

the class CreationThread method prepareNewResource.

private CloudMethodWorker prepareNewResource(VM vm) throws ConnectorException {
    CloudMethodResourceDescription granted = vm.getDescription();
    CloudImageDescription cid = granted.getImage();
    Map<String, String> workerProperties = cid.getProperties();
    String user = cid.getConfig().getUser();
    String password = workerProperties.get(AbstractConnector.PROPERTY_PASSW_NAME);
    try {
        operations.configureAccess(granted.getName(), user, password);
    } catch (ConnectorException e) {
        RUNTIME_LOGGER.error(ERROR_CONFIGURE_ACCESS_VM + granted.getName(), e);
        RESOURCE_LOGGER.error("ERROR_MSG = [\n\t" + ERROR_CONFIGURE_ACCESS_VM + "\n\tNAME = " + granted.getName() + "\n\tPROVIDER =  " + provider + "\n]", e);
        throw e;
    }
    try {
        operations.prepareMachine(granted.getName(), cid);
    } catch (ConnectorException e) {
        RUNTIME_LOGGER.error(ERROR_PREPARING_VM + granted.getName(), e);
        RESOURCE_LOGGER.error("ERROR_MSG = [\n\t" + ERROR_PREPARING_VM + granted.getName() + "]", e);
        throw e;
    }
    CloudMethodWorker worker;
    MethodConfiguration mc = cid.getConfig();
    int limitOfTasks = mc.getLimitOfTasks();
    int computingUnits = granted.getTotalCPUComputingUnits();
    if (limitOfTasks < 0 && computingUnits < 0) {
        mc.setLimitOfTasks(0);
        mc.setTotalComputingUnits(0);
    } else {
        mc.setLimitOfTasks(Math.max(limitOfTasks, computingUnits));
        mc.setTotalComputingUnits(Math.max(limitOfTasks, computingUnits));
    }
    mc.setHost(granted.getName());
    mc.setLimitOfGPUTasks(granted.getTotalGPUComputingUnits());
    mc.setTotalGPUComputingUnits(granted.getTotalGPUComputingUnits());
    mc.setLimitOfFPGATasks(granted.getTotalFPGAComputingUnits());
    mc.setTotalFPGAComputingUnits(granted.getTotalFPGAComputingUnits());
    mc.setLimitOfOTHERSTasks(granted.getTotalOTHERComputingUnits());
    mc.setTotalOTHERComputingUnits(granted.getTotalOTHERComputingUnits());
    worker = new CloudMethodWorker(granted.getName(), provider, granted, mc, cid.getSharedDisks());
    try {
        worker.announceCreation();
    } catch (Exception e) {
        RUNTIME_LOGGER.error("Machine " + granted.getName() + " shut down because an error announcing creation");
        RESOURCE_LOGGER.error("ERROR_MSG = [\n\t" + ERROR_ANNOUNCE_VM + "\n\tNAME = " + granted.getName() + "\n\tPROVIDER =  " + provider + "\n]", e);
        throw new ConnectorException(e);
    }
    // Add the new machine to ResourceManager
    if (operations.getTerminate()) {
        RESOURCE_LOGGER.info("INFO_MSG = [\n\t" + WARN_VM_REFUSED + "\n\tRESOURCE_NAME = " + granted.getName() + "\n]");
        try {
            worker.announceDestruction();
        } catch (Exception e) {
            RESOURCE_LOGGER.error("ERROR_MSG = [\n\t" + ERROR_ANNOUNCE_VM_DESTROY + "\n\tVM_NAME = " + granted.getName() + "\n]", e);
        }
        Semaphore sem = new Semaphore(0);
        ShutdownListener sl = new ShutdownListener(sem);
        worker.stop(sl);
        sl.enable();
        try {
            sem.acquire();
        } catch (Exception e) {
            RESOURCE_LOGGER.error(ERROR_WORKER_SHUTDOWN);
        }
        throw new ConnectorException(ERROR_USELESS_VM);
    }
    return worker;
}
Also used : ShutdownListener(es.bsc.compss.types.resources.ShutdownListener) MethodConfiguration(es.bsc.compss.types.resources.configuration.MethodConfiguration) CloudImageDescription(es.bsc.compss.types.resources.description.CloudImageDescription) ConnectorException(es.bsc.compss.connectors.ConnectorException) CloudMethodWorker(es.bsc.compss.types.resources.CloudMethodWorker) CloudMethodResourceDescription(es.bsc.compss.types.resources.description.CloudMethodResourceDescription) Semaphore(java.util.concurrent.Semaphore) ConnectorException(es.bsc.compss.connectors.ConnectorException)

Example 45 with CloudMethodResourceDescription

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

the class CloudMethodWorker method applyReduction.

public synchronized void applyReduction(PendingReduction<MethodResourceDescription> pRed) {
    CloudMethodResourceDescription reduction = (CloudMethodResourceDescription) pRed.getModification();
    synchronized (description) {
        ((CloudMethodResourceDescription) this.description).reduce(reduction);
    }
    synchronized (available) {
        if (!hasAvailable(reduction) && this.getUsedCPUTaskCount() > 0) {
            // This resource is still running tasks. Wait for them to finish...
            // Mark to remove and enqueue pending reduction
            LOGGER.debug("Resource in use. Adding pending reduction");
            synchronized (toRemove) {
                toRemove.increase(reduction);
            }
            synchronized (pendingReductions) {
                pendingReductions.add(pRed);
            }
        } else {
            // Resource is not executing tasks. We can erase it, nothing to do
            available.reduce(reduction);
            pRed.notifyCompletion();
        }
    }
    updatedFeatures();
}
Also used : CloudMethodResourceDescription(es.bsc.compss.types.resources.description.CloudMethodResourceDescription)

Aggregations

CloudMethodResourceDescription (es.bsc.compss.types.resources.description.CloudMethodResourceDescription)45 CloudInstanceTypeDescription (es.bsc.compss.types.resources.description.CloudInstanceTypeDescription)23 CloudImageDescription (es.bsc.compss.types.resources.description.CloudImageDescription)21 MethodResourceDescription (es.bsc.compss.types.resources.MethodResourceDescription)16 HashMap (java.util.HashMap)14 Test (org.junit.Test)14 CloudMethodWorker (es.bsc.compss.types.resources.CloudMethodWorker)12 FakeNode (es.bsc.compss.types.fake.FakeNode)11 CloudProvider (es.bsc.compss.types.CloudProvider)9 ResourceCreationRequest (es.bsc.compss.types.ResourceCreationRequest)7 Implementation (es.bsc.compss.types.implementations.Implementation)5 ConnectorException (es.bsc.compss.connectors.ConnectorException)4 ExtendedCloudMethodWorker (es.bsc.compss.types.ExtendedCloudMethodWorker)4 Map (java.util.Map)4 MOProfile (es.bsc.compss.scheduler.multiobjective.types.MOProfile)3 VM (es.bsc.compss.connectors.VM)2 MethodImplementation (es.bsc.compss.types.implementations.MethodImplementation)2 PerformedIncrease (es.bsc.compss.types.resources.updates.PerformedIncrease)2 VirtualResource (es.bsc.conn.types.VirtualResource)2 LinkedList (java.util.LinkedList)2