Search in sources :

Example 11 with CloudInstanceTypeDescription

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

the class CloudProviderTest method testCreateTwoVMOneResource.

@Test
public void testCreateTwoVMOneResource() {
    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);
    CloudMethodWorker cmw = new CloudMethodWorker(vmName, cp, cmrd, new FakeNode(vmName), 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, cmw, 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() != 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 12 with CloudInstanceTypeDescription

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

the class CloudProviderTest method testDestroyOneVMOneResource.

@Test
public void testDestroyOneVMOneResource() {
    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);
    ExtendedCloudMethodWorker cmw = new ExtendedCloudMethodWorker(vmName, cp, cmrd, new FakeNode(vmName), 0, new HashMap<>());
    CloudMethodResourceDescription granted = new CloudMethodResourceDescription(citd, cid);
    cp.confirmedCreation(crc, cmw, granted);
    CloudMethodResourceDescription 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");
    }
    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.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 13 with CloudInstanceTypeDescription

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

the class CloudProviderTest method testTurnOn.

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

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

the class CloudProviderTest method testTwoInstanceType.

@Test
public void testTwoInstanceType() {
    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 type1Name = "TYPE" + (int) (Math.random() * 10000);
    float type1Memory = (float) Math.random() * 5;
    MethodResourceDescription mrd1 = new MethodResourceDescription();
    mrd1.setMemorySize(type1Memory);
    CloudInstanceTypeDescription citd1 = new CloudInstanceTypeDescription(type1Name, mrd1);
    cp.addInstanceType(citd1);
    String type2Name = "TYPE" + (int) (Math.random() * 10000);
    float type2Memory = (float) Math.random() * 5;
    MethodResourceDescription mrd2 = new MethodResourceDescription();
    mrd2.setMemorySize(type1Memory);
    CloudInstanceTypeDescription citd2 = new CloudInstanceTypeDescription(type2Name, mrd2);
    cp.addInstanceType(citd2);
    Set<String> instanceNames = cp.getAllInstanceTypeNames();
    int contains = 0;
    if (instanceNames.contains(type1Name)) {
        contains++;
    }
    if (instanceNames.contains(type2Name)) {
        contains++;
    }
    switch(contains) {
        case 0:
            fail("Cloud Provider is not storing properly the Templates. Cannot find any template name on the two templates scenario.");
            break;
        case 1:
            fail("Cloud Provider is not storing properly the Templates. Cannot find one template name on the two templates scenario.");
            break;
        default:
    }
    if (instanceNames.size() != 2) {
        fail("Cloud Provider is not storing properly the Templates. only two templates are supposed to be in the set.");
    }
    CloudInstanceTypeDescription retrieved1 = cp.getInstanceType(type1Name);
    try {
        checkRetrievedType(retrieved1, type1Name, type1Memory);
    } catch (Exception e) {
        fail("Cloud Provider is not storing properly the Templates. The provider " + e.getMessage() + " on the two templates scenario.");
    }
    CloudInstanceTypeDescription retrieved2 = cp.getInstanceType(type2Name);
    try {
        checkRetrievedType(retrieved2, type2Name, type2Memory);
    } catch (Exception e) {
        fail("Cloud Provider is not storing properly the Templates. The provider " + e.getMessage() + " on the two templates scenario.");
    }
}
Also used : HashMap(java.util.HashMap) 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 15 with CloudInstanceTypeDescription

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

the class CloudProviderTest method testRefusedOneTurnOn.

@Test
public void testRefusedOneTurnOn() {
    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");
    }
    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");
    }
    pendingRequests = cp.getPendingRequests();
    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

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