resource-manager-gcore/src/org/gcube/vremanagement/resourcemanager/impl/operators/AddResourcesOperator.java

70 lines
2.3 KiB
Java

package org.gcube.vremanagement.resourcemanager.impl.operators;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.vremanagement.resourcemanager.impl.contexts.ServiceContext;
import org.gcube.vremanagement.resourcemanager.stubs.resourcemanager.AddResourcesParameters;
import org.gcube.vremanagement.resourcemanager.stubs.resourcemanager.ResourceList;
import org.gcube.vremanagement.resourcemanager.stubs.resourcemanager.ServiceList;
/**
* A Resources Operator that coordinates the adding of resources to the scope
*
* @author Manuele Simi (ISTI-CNR)
*
*/
public class AddResourcesOperator extends Operator {
protected final GCUBELog logger = new GCUBELog(this, ServiceContext.getContext());
private AddResourcesParameters resourceList;
private OperatorConfig configuration;
/**
* Creates a new operator to manage the input resource list
*
* @param scopeState
* @param target
* @param operationID
*/
public AddResourcesOperator(OperatorConfig configuration, AddResourcesParameters resourceList){
this.resourceList = resourceList;
this.configuration = configuration;
}
/**
* {@inheritDoc}
*/
public void exec() throws Exception {
// deploy the services, if any
ServiceList services = resourceList.getServices();
if ((services == null) || (services.getService() == null) || (services.getService().length == 0)) {
logger.warn("The list of services to deploy is empty");
} else {
try {
new DeployServiceOperator(configuration, services, ACTION.ADD).run();
} catch (Exception e) {
logger.error("Unable to activate the deployment of the given service(s)", e);
throw new Exception("Unable to activate the deployment of the given service(s)", e);
}
}
//add the resources to the PublishedScopeResource, if any
ResourceList resources = resourceList.getResources();
if ((resources == null) || (resources.getResource() == null) || (resources.getResource().length == 0))
logger.warn("The list of resource to add is empty");
else {
try {
new ScopedResourceManagerOperator(configuration, resources, ACTION.ADD).run();
}catch (Exception e) {
logger.error("Unable to manage the given resource(s)", e);
throw new Exception("Unable to manage the given resource(s)", e);
}
}
//save the report
this.configuration.report.save();
}
}