use of es.bsc.compss.types.resources.CloudMethodWorker in project compss by bsc-wdc.
the class CloudProviderTest method testCreateOneVMOneResourceSameDescription.
@Test
public void testCreateOneVMOneResourceSameDescription() {
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);
if (cp.getCurrentVMCount() != 1) {
fail("Cloud Provider is not properly accounting the number of requested VMs");
}
List<ResourceCreationRequest> pendingRequests = cp.getPendingRequests();
Set<CloudMethodWorker> workers = cp.getHostedWorkers();
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");
}
if (!workers.isEmpty()) {
fail("Cloud Provider is not properly registering the hosted workers");
}
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() != 1) {
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");
}
}
use of es.bsc.compss.types.resources.CloudMethodWorker in project compss by bsc-wdc.
the class CreationThread method run.
@Override
public void run() {
boolean check = operations.getCheck();
RUNTIME_LOGGER.debug("Operations check = " + check);
CloudMethodResourceDescription requested = rcr.getRequested();
VM granted;
if (reused == null) {
// If the resources does not exist --> Create
this.setName("Creation Thread " + name);
try {
granted = createResourceOnProvider(requested);
} catch (Exception e) {
RUNTIME_LOGGER.error(ERROR_ASKING_NEW_RESOURCE + provider, e);
notifyFailure();
return;
}
if (DEBUG) {
RUNTIME_LOGGER.debug("Resource " + granted.getName() + " with id " + granted.getEnvId() + " has been created ");
}
RESOURCE_LOGGER.info("RESOURCE_GRANTED = [\n\tNAME = " + granted.getName() + "\n\tSTATUS = ID " + granted.getEnvId() + " CREATED\n]");
} else {
granted = reused;
if (DEBUG) {
RUNTIME_LOGGER.debug("Resource " + granted.getName() + " with id " + granted.getEnvId() + " has been reused ");
}
RESOURCE_LOGGER.info("RESOURCE_GRANTED = [\n\tNAME = " + reused.getName() + "\n\tSTATUS = ID " + granted.getEnvId() + " REUSED\n]");
}
String grantedName = granted.getName();
this.setName("Creation Thread " + grantedName);
CloudMethodWorker r = ResourceManager.getDynamicResource(granted.getName());
if (r == null) {
// Resources are provided in a new VM
if (reused == null) {
// And are new --> Initiate VM
try {
if (DEBUG) {
RUNTIME_LOGGER.debug(" Preparing new worker resource " + granted.getName() + ".");
}
r = prepareNewResource(granted);
operations.vmReady(granted);
} catch (Exception e) {
RUNTIME_LOGGER.error(ERROR_PREPARING_VM, e);
powerOff(granted);
notifyFailure();
return;
}
} else {
int limitOfTasks = granted.getDescription().getTotalCPUComputingUnits();
int limitGPUTasks = granted.getDescription().getTotalGPUComputingUnits();
int limitFPGATasks = granted.getDescription().getTotalFPGAComputingUnits();
int limitOTHERTasks = granted.getDescription().getTotalOTHERComputingUnits();
r = new CloudMethodWorker(grantedName, provider, granted.getDescription(), granted.getNode(), limitOfTasks, limitGPUTasks, limitFPGATasks, limitOTHERTasks, rcr.getRequested().getImage().getSharedDisks());
if (DEBUG) {
RUNTIME_LOGGER.debug("Worker for new resource " + grantedName + " set.");
}
}
granted.setWorker(r);
ResourceManager.addCloudWorker(rcr, r, granted.getDescription());
} else {
// Resources are provided in an existing VM
ResourceManager.increasedCloudWorker(rcr, r, granted.getDescription());
}
COUNT.decrementAndGet();
}
use of es.bsc.compss.types.resources.CloudMethodWorker in project compss by bsc-wdc.
the class CloudProvider method getCurrentState.
/*
* ----------------------------------------- ------------- Debug Queries -------------
* ----------------------------------------
*/
public String getCurrentState(String prefix) {
StringBuilder sb = new StringBuilder();
sb.append(prefix).append("PROVIDER = [").append("\n");
sb.append(prefix).append("\t").append("NAME = ").append(name).append("\n");
sb.append(prefix).append("\t").append("CURRENT_VM = ").append(currentVMCount).append("\n");
sb.append(prefix).append("\t").append("LIMIT_VM = ").append(limitOfVMs).append("\n");
sb.append(imgManager.getCurrentState(prefix + "\t"));
sb.append(typeManager.getCurrentState(prefix + "\t"));
// Virtual Instances
sb.append(prefix).append("\t").append("VIRTUAL_INSTANCES = [").append("\n");
for (CloudMethodWorker vm : hostedWorkers) {
CloudMethodResourceDescription cmrd = vm.getDescription();
sb.append(cmrd.getCurrentState(prefix + "\t")).append("\n");
}
sb.append(prefix).append("\t").append("]").append("\n");
sb.append(prefix).append("]").append("\n");
return sb.toString();
}
use of es.bsc.compss.types.resources.CloudMethodWorker in project compss by bsc-wdc.
the class TaskScheduler method reducedWorkerResources.
@SuppressWarnings("unchecked")
private <T extends WorkerResourceDescription> void reducedWorkerResources(ResourceScheduler<T> worker, ResourceUpdate<T> modification) {
CloudMethodWorker cloudWorker = (CloudMethodWorker) worker.getResource();
if (!cloudWorker.getDescription().getTypeComposition().isEmpty()) {
synchronized (workers) {
workers.remove(((ResourceScheduler<WorkerResourceDescription>) worker).getResource());
int coreCount = CoreManager.getCoreCount();
List<Implementation>[] runningCoreImpls = worker.getExecutableImpls();
for (int coreId = 0; coreId < coreCount; coreId++) {
for (Implementation impl : runningCoreImpls[coreId]) {
Profile p = worker.getProfile(impl);
if (p != null) {
offVMsProfiles[coreId][impl.getImplementationId()].accumulate(p);
}
}
}
}
this.workerRemoved((ResourceScheduler<WorkerResourceDescription>) worker);
StopWorkerAction action = new StopWorkerAction(generateSchedulingInformation(worker), worker, this, modification);
try {
action.schedule((ResourceScheduler<WorkerResourceDescription>) worker, (Score) null);
action.tryToLaunch();
} catch (BlockedActionException | UnassignedActionException | InvalidSchedulingException e) {
// Can not be blocked nor unassigned
}
} else {
ResourceManager.terminateCloudResource(cloudWorker, (CloudMethodResourceDescription) modification.getModification());
}
}
use of es.bsc.compss.types.resources.CloudMethodWorker in project compss by bsc-wdc.
the class ResourceOptimizer method mandatoryReduction.
private void mandatoryReduction(float[] destroyRecommendations) {
List<CloudMethodWorker> critical = trimReductionOptions(ResourceManager.getCriticalDynamicResources(), destroyRecommendations);
// LinkedList<CloudMethodWorker> critical = checkCriticalSafeness
// (critical);
List<CloudMethodWorker> nonCritical = trimReductionOptions(ResourceManager.getNonCriticalDynamicResources(), destroyRecommendations);
Object[] criticalSolution = getBestDestruction(critical, destroyRecommendations);
Object[] nonCriticalSolution = getBestDestruction(nonCritical, destroyRecommendations);
boolean criticalIsBetter;
if (criticalSolution == null) {
if (nonCriticalSolution == null) {
return;
} else {
criticalIsBetter = false;
}
} else if (nonCriticalSolution == null) {
criticalIsBetter = true;
} else {
criticalIsBetter = false;
float[] noncriticalValues = (float[]) nonCriticalSolution[2];
float[] criticalValues = (float[]) criticalSolution[2];
if (noncriticalValues[0] == criticalValues[0]) {
if (noncriticalValues[1] == criticalValues[1]) {
if (noncriticalValues[2] < criticalValues[2]) {
criticalIsBetter = true;
}
} else if (noncriticalValues[1] > criticalValues[1]) {
criticalIsBetter = true;
}
} else if (noncriticalValues[0] > criticalValues[0]) {
criticalIsBetter = true;
}
}
CloudMethodWorker res;
CloudMethodResourceDescription cmrd;
// float[] record;
// int[][] slotsRemovingCount;
CloudInstanceTypeDescription citd;
if (criticalIsBetter) {
res = (CloudMethodWorker) criticalSolution[0];
citd = (CloudInstanceTypeDescription) criticalSolution[1];
} else {
if (nonCriticalSolution == null) {
return;
}
res = (CloudMethodWorker) nonCriticalSolution[0];
citd = (CloudInstanceTypeDescription) nonCriticalSolution[1];
}
cmrd = (CloudMethodResourceDescription) res.getDescription();
CloudImageDescription cid = cmrd.getImage();
CloudMethodResourceDescription finalDescription = new CloudMethodResourceDescription(citd, cid);
finalDescription.setName(res.getName());
ResourceManager.reduceCloudWorker(res, finalDescription);
}
Aggregations