Search in sources :

Example 1 with EndpointType

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

Aggregations

ConstructConfigurationException (es.bsc.compss.exceptions.ConstructConfigurationException)1 NoResourceAvailableException (es.bsc.compss.exceptions.NoResourceAvailableException)1 CloudProvider (es.bsc.compss.types.CloudProvider)1 ProjectFileValidationException (es.bsc.compss.types.project.exceptions.ProjectFileValidationException)1 es.bsc.compss.types.project.jaxb (es.bsc.compss.types.project.jaxb)1 CloudImageDescription (es.bsc.compss.types.resources.description.CloudImageDescription)1 CloudInstanceTypeDescription (es.bsc.compss.types.resources.description.CloudInstanceTypeDescription)1 ResourcesFileValidationException (es.bsc.compss.types.resources.exceptions.ResourcesFileValidationException)1 EndpointType (es.bsc.compss.types.resources.jaxb.EndpointType)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 JAXBException (javax.xml.bind.JAXBException)1 SAXException (org.xml.sax.SAXException)1