Search in sources :

Example 21 with CloudImageDescription

use of es.bsc.compss.types.resources.description.CloudImageDescription 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);
            }
        }
    }
}
Also used : CloudProvider(es.bsc.compss.types.CloudProvider) CloudInstanceTypeDescription(es.bsc.compss.types.resources.description.CloudInstanceTypeDescription) CloudImageDescription(es.bsc.compss.types.resources.description.CloudImageDescription)

Example 22 with CloudImageDescription

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

the class ExternalAdaptationManager method cloudCreation.

private void cloudCreation(String providerName, String typeName, String imageName) {
    if (providerName != null && typeName != null && imageName != null) {
        CloudProvider cp = ResourceManager.getCloudProvider(providerName);
        if (cp != null) {
            CloudImageDescription imageDescription = cp.getImage(imageName);
            CloudInstanceTypeDescription typeDescription = cp.getInstanceType(typeName);
            CloudMethodResourceDescription cmrd = new CloudMethodResourceDescription(typeDescription, imageDescription);
            ResourceCreationRequest rcr = cp.requestResourceCreation(cmrd);
            if (rcr != null) {
                RUNTIME_LOGGER.info(LOG_PREFIX + "Submited external request for creating (" + typeName + ", " + imageName + ") in " + providerName);
                rcr.print(RESOURCES_LOGGER, DEBUG);
                writePipe(resultPipe, ACK);
            } else {
                RUNTIME_LOGGER.error(LOG_PREFIX + "ERROR: Creating resource (" + typeName + ", " + imageName + ") in " + providerName);
                writePipe(resultPipe, "ERROR: Error creating resource(" + typeName + ", " + imageName + ") in " + providerName);
            }
        } else {
            RUNTIME_LOGGER.error(LOG_PREFIX + "ERROR: Provider " + providerName + " not found.");
            writePipe(resultPipe, "ERROR: Provider " + providerName + " not found");
        }
    } else {
        RUNTIME_LOGGER.error(LOG_PREFIX + "ERROR: One of the parameters is incorrect (" + typeName + ", " + imageName + "," + providerName + ")");
        writePipe(resultPipe, "ERROR: One of the parameters is incorrect (" + typeName + ", " + imageName + "," + providerName + ")");
    }
}
Also used : ResourceCreationRequest(es.bsc.compss.types.ResourceCreationRequest) 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)

Example 23 with CloudImageDescription

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

the class ResourceLoader method createImage.

private static CloudImageDescription createImage(ImageType im_project, es.bsc.compss.types.resources.jaxb.ImageType im_resources, Map<String, String> properties) {
    String imageName = im_project.getName();
    LOGGER.debug("Loading Image" + imageName);
    CloudImageDescription cid = new CloudImageDescription(imageName, properties);
    /* Add properties given by the resources file **************************************** */
    cid.setOperatingSystemType(resources.getOperatingSystemType(im_resources));
    cid.setOperatingSystemDistribution(resources.getOperatingSystemDistribution(im_resources));
    cid.setOperatingSystemVersion(resources.getOperatingSystemVersion(im_resources));
    List<String> apps = resources.getApplications(im_resources);
    if (apps != null) {
        for (String appName : apps) {
            cid.addApplication(appName);
        }
    }
    es.bsc.compss.types.resources.jaxb.PriceType p = resources.getPrice(im_resources);
    if (p != null) {
        cid.setPriceTimeUnit(p.getTimeUnit());
        cid.setPricePerUnit(p.getPricePerUnit());
    }
    cid.setCreationTime(resources.getCreationTime(im_resources));
    // Add Shared Disks (Name, mountpoint)
    Map<String, String> sharedDisks = resources.getSharedDisks(im_resources);
    if (sharedDisks != null) {
        List<String> declaredSharedDisks = resources.getSharedDisks_names();
        for (String diskName : sharedDisks.keySet()) {
            if (declaredSharedDisks == null || !declaredSharedDisks.contains(diskName)) {
                ErrorManager.warn("SharedDisk " + diskName + " defined in the Image " + imageName + " is not defined in the resources.xml. Skipping");
                sharedDisks.remove(diskName);
            // TODO: Check the disk information (size and type)
            }
        }
    }
    cid.setSharedDisks(sharedDisks);
    // Add the adaptors properties (queue types and adaptor properties)
    // TODO Support multiple adaptor properties
    String loadedAdaptor = System.getProperty(COMPSsConstants.COMM_ADAPTOR);
    List<String> queues_project = project.getAdaptorQueues(im_project, loadedAdaptor);
    List<String> queues_resources = resources.getAdaptorQueues(im_resources, loadedAdaptor);
    for (String queue : queues_resources) {
        if (queues_project.contains(queue)) {
            cid.addQueue(queue);
        }
    }
    Object adaptorProperties_project = project.getAdaptorProperties(im_project, loadedAdaptor);
    Object adaptorProperties_resources = resources.getAdaptorProperties(im_resources, loadedAdaptor);
    MethodConfiguration config = null;
    try {
        config = (MethodConfiguration) Comm.constructConfiguration(loadedAdaptor, adaptorProperties_project, adaptorProperties_resources);
    } catch (ConstructConfigurationException cce) {
        ErrorManager.warn("Adaptor configuration constructor failed", cce);
        return null;
    }
    // If we have reached this point the mp is SURELY not null
    /* Add properties given by the project file **************************************** */
    config.setHost(im_project.getName());
    config.setUser(project.getUser(im_project));
    config.setInstallDir(project.getInstallDir(im_project));
    config.setWorkingDir(project.getWorkingDir(im_project));
    config.setLimitOfTasks(project.getLimitOfTasks(im_project));
    ApplicationType app = project.getApplication(im_project);
    if (app != null) {
        config.setAppDir(app.getAppDir());
        config.setLibraryPath(app.getLibraryPath());
        config.setClasspath(app.getClasspath());
        config.setPythonpath(app.getClasspath());
    }
    List<PackageType> packages = project.getPackages(im_project);
    for (PackageType pack : packages) {
        cid.addPackage(pack.getSource(), pack.getTarget());
        SoftwareListType software = pack.getIncludedSoftware();
        if (software != null) {
            cid.addAllApplications(software.getApplication());
        }
    }
    // Add configuration to image
    cid.setConfig(config);
    return cid;
}
Also used : CloudImageDescription(es.bsc.compss.types.resources.description.CloudImageDescription) ConstructConfigurationException(es.bsc.compss.exceptions.ConstructConfigurationException) es.bsc.compss.types.project.jaxb(es.bsc.compss.types.project.jaxb) MethodConfiguration(es.bsc.compss.types.resources.configuration.MethodConfiguration)

Example 24 with CloudImageDescription

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

the class ResourceLoader method loadCloudProvider.

private static boolean loadCloudProvider(CloudProviderType cp_project, es.bsc.compss.types.resources.jaxb.CloudProviderType cp_resources) {
    String cpName = cp_project.getName();
    String runtimeConnector = System.getProperty(COMPSsConstants.CONN);
    String connectorJarPath = "";
    String connectorMainClass = "";
    Map<String, String> properties = new HashMap<>();
    /* Add Endpoint information from resources.xml */
    EndpointType endpoint = cp_resources.getEndpoint();
    connectorJarPath = resources.getConnectorJarPath(endpoint);
    connectorMainClass = resources.getConnectorMainClass(endpoint);
    /* Add properties information ****************** */
    properties.put(AbstractConnector.PROP_SERVER, resources.getServer(endpoint));
    properties.put(AbstractConnector.PROP_PORT, resources.getPort(endpoint));
    List<Object> objList = cp_project.getImagesOrInstanceTypesOrLimitOfVMs();
    if (objList != null) {
        for (Object obj : objList) {
            if (obj instanceof CloudPropertiesType) {
                CloudPropertiesType cloud_props = (CloudPropertiesType) obj;
                for (CloudPropertyType prop : cloud_props.getProperty()) {
                    // TODO CloudProperties have context, name, value. Consider context (it is ignored now)
                    properties.put(prop.getName(), prop.getValue());
                }
            }
        }
    }
    // Add application name property for some connectors (i.e. docker, vmm)
    String appName = System.getProperty(COMPSsConstants.APP_NAME);
    appName = appName.toLowerCase();
    appName = appName.replace('.', '-');
    properties.put(AbstractConnector.PROP_APP_NAME, appName);
    /* Add images/instances information ******************** */
    int limitOfVMs = -1;
    // Seconds
    int maxCreationTime = -1;
    LinkedList<CloudImageDescription> images = new LinkedList<>();
    LinkedList<CloudInstanceTypeDescription> instanceTypes = new LinkedList<>();
    objList = cp_project.getImagesOrInstanceTypesOrLimitOfVMs();
    if (objList != null) {
        for (Object obj : objList) {
            if (obj instanceof ImagesType) {
                // Load images
                ImagesType imageList = (ImagesType) obj;
                for (ImageType im_project : imageList.getImage()) {
                    // Try to create image
                    es.bsc.compss.types.resources.jaxb.ImageType im_resources = resources.getImage(cp_resources, im_project.getName());
                    CloudImageDescription cid = createImage(im_project, im_resources, properties);
                    // Add to images list
                    if (cid != null) {
                        images.add(cid);
                        // Update max creation time
                        int localCT = cid.getCreationTime();
                        if (localCT > maxCreationTime) {
                            maxCreationTime = localCT;
                        }
                    }
                }
            } else if (obj instanceof InstanceTypesType) {
                // Load images
                InstanceTypesType instancesList = (InstanceTypesType) obj;
                for (InstanceTypeType instance_project : instancesList.getInstanceType()) {
                    // Try to create instance
                    String instanceName = instance_project.getName();
                    es.bsc.compss.types.resources.jaxb.InstanceTypeType instance_resources = resources.getInstance(cp_resources, instanceName);
                    if (instance_resources != null) {
                        CloudInstanceTypeDescription cmrd = createInstance(instance_resources);
                        // Add to instance list
                        if (cmrd != null) {
                            instanceTypes.add(cmrd);
                        }
                    } else {
                        ErrorManager.warn("Instance " + instanceName + " not defined in resources.xml. Skipping");
                    }
                }
            } else if (obj instanceof Integer) {
                // Limit Of VMs
                limitOfVMs = (Integer) obj;
            }
        }
    }
    if (maxCreationTime > 0) {
        properties.put(AbstractConnector.PROP_MAX_VM_CREATION_TIME, Integer.toString(maxCreationTime));
    }
    // Add Cloud Provider to CloudManager *****************************************/
    CloudProvider provider;
    try {
        provider = ResourceManager.registerCloudProvider(cpName, limitOfVMs, runtimeConnector, connectorJarPath, connectorMainClass, properties);
    } catch (Exception e) {
        ErrorManager.warn("Exception loading CloudProvider " + cpName, e);
        return false;
    }
    for (CloudImageDescription cid : images) {
        provider.addCloudImage(cid);
    }
    for (CloudInstanceTypeDescription instance : instanceTypes) {
        provider.addInstanceType(instance);
    }
    /* If we reach this point CP is loaded **************************************** */
    return true;
}
Also used : HashMap(java.util.HashMap) es.bsc.compss.types.project.jaxb(es.bsc.compss.types.project.jaxb) CloudProvider(es.bsc.compss.types.CloudProvider) EndpointType(es.bsc.compss.types.resources.jaxb.EndpointType) CloudImageDescription(es.bsc.compss.types.resources.description.CloudImageDescription) LinkedList(java.util.LinkedList) NoResourceAvailableException(es.bsc.compss.exceptions.NoResourceAvailableException) ProjectFileValidationException(es.bsc.compss.types.project.exceptions.ProjectFileValidationException) ResourcesFileValidationException(es.bsc.compss.types.resources.exceptions.ResourcesFileValidationException) JAXBException(javax.xml.bind.JAXBException) ConstructConfigurationException(es.bsc.compss.exceptions.ConstructConfigurationException) SAXException(org.xml.sax.SAXException) CloudInstanceTypeDescription(es.bsc.compss.types.resources.description.CloudInstanceTypeDescription)

Example 25 with CloudImageDescription

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

the class CloudProviderTest method testRefusedTwoTurnOn.

@Test
public void testRefusedTwoTurnOn() {
    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;
    }
    if (cp.getCurrentVMCount() != 0) {
        fail("Cloud Provider is not properly intialized the number of requested VMs should be 0");
    }
    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);
    if (!FakeConnector.getProcessedRequests().contains(crc)) {
        fail("Turn on has not reached the connector");
    }
    CloudMethodResourceDescription cmrd2 = new CloudMethodResourceDescription(citd, cid);
    cmrd2.addInstance(citd);
    ResourceCreationRequest crc2 = cp.requestResourceCreation(cmrd2);
    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");
    }
    cp.refusedCreation(crc2);
    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");
    }
    cp.refusedCreation(crc);
    if (cp.getCurrentVMCount() != 0) {
        fail("Cloud Provider is not properly accounting the number of requested VMs");
    }
    if (!pendingRequests.isEmpty()) {
        fail("Cloud Provider is not properly registering the pending creations requests");
    }
}
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