Search in sources :

Example 31 with CloudImageDescription

use of es.bsc.compss.types.resources.description.CloudImageDescription 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)

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