Search in sources :

Example 31 with CloudInstanceTypeDescription

use of es.bsc.compss.types.resources.description.CloudInstanceTypeDescription 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 32 with CloudInstanceTypeDescription

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

Example 33 with CloudInstanceTypeDescription

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

the class CloudProviderTest method testDestroyTwoVMOneResource.

@Test
public void testDestroyTwoVMOneResource() {
    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<>());
    CloudMethodResourceDescription granted = new CloudMethodResourceDescription(citd, cid);
    cp.confirmedCreation(crc, cmw, granted);
    granted = new CloudMethodResourceDescription(citd, cid);
    cmw.getDescription().increase(granted);
    cp.confirmedCreation(crc2, cmw, 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(cmw)) {
        fail("Cloud Provider is not properly registering the hosted workers");
    }
    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");
    }
    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 34 with CloudInstanceTypeDescription

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

the class CloudProviderTest method testCreateOneVMOneResourceDifferentDescription.

@Test
public void testCreateOneVMOneResourceDifferentDescription() {
    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);
    CloudMethodWorker cmw = new CloudMethodWorker(vmName, cp, cmrd, new FakeNode(vmName), 0, 0, 0, 0, new HashMap<>());
    CloudMethodResourceDescription granted = new CloudMethodResourceDescription(citd, cid);
    granted.addInstance(citd);
    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.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 35 with CloudInstanceTypeDescription

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

Aggregations

CloudInstanceTypeDescription (es.bsc.compss.types.resources.description.CloudInstanceTypeDescription)39 CloudMethodResourceDescription (es.bsc.compss.types.resources.description.CloudMethodResourceDescription)29 CloudImageDescription (es.bsc.compss.types.resources.description.CloudImageDescription)22 MethodResourceDescription (es.bsc.compss.types.resources.MethodResourceDescription)21 HashMap (java.util.HashMap)21 Test (org.junit.Test)13 CloudMethodWorker (es.bsc.compss.types.resources.CloudMethodWorker)10 CloudProvider (es.bsc.compss.types.CloudProvider)9 FakeNode (es.bsc.compss.types.fake.FakeNode)8 Map (java.util.Map)6 Implementation (es.bsc.compss.types.implementations.Implementation)5 ResourceCreationRequest (es.bsc.compss.types.ResourceCreationRequest)4 MOProfile (es.bsc.compss.scheduler.multiobjective.types.MOProfile)3 JSONObject (org.json.JSONObject)3 es.bsc.compss.types.project.jaxb (es.bsc.compss.types.project.jaxb)2 LinkedList (java.util.LinkedList)2 ConstructConfigurationException (es.bsc.compss.exceptions.ConstructConfigurationException)1 NoResourceAvailableException (es.bsc.compss.exceptions.NoResourceAvailableException)1 ExtendedCloudMethodWorker (es.bsc.compss.types.ExtendedCloudMethodWorker)1 MethodImplementation (es.bsc.compss.types.implementations.MethodImplementation)1