some change on operators
This commit is contained in:
parent
f8b8b0d124
commit
10a452073a
|
@ -13,10 +13,9 @@ import org.gcube.vremanagement.contextmanager.handlers.ContextContainer;
|
|||
import org.gcube.vremanagement.contextmanager.model.exceptions.InvalidContextException;
|
||||
import org.gcube.vremanagement.contextmanager.model.operators.context.CustomContextOperator;
|
||||
import org.gcube.vremanagement.contextmanager.model.operators.context.MandatoryContextOperator;
|
||||
import org.gcube.vremanagement.contextmanager.model.operators.parameters.OperatorParameters;
|
||||
import org.gcube.vremanagement.contextmanager.model.report.OperationResult;
|
||||
import org.gcube.vremanagement.contextmanager.model.report.Report;
|
||||
import org.gcube.vremanagement.contextmanager.model.report.ReportEntry;
|
||||
import org.gcube.vremanagement.contextmanager.model.report.ReportGroup;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.Context;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.Context.Type;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -33,21 +32,21 @@ public class ContextManager {
|
|||
|
||||
@Inject
|
||||
@Any
|
||||
private Instance<CustomContextOperator> customContextOperators;
|
||||
private Instance<CustomContextOperator<?,?>> customContextOperators;
|
||||
|
||||
@Inject
|
||||
private ContextContainer contextContainer;
|
||||
|
||||
@Inject
|
||||
private ResourceManager resourceManager;
|
||||
|
||||
public Report createContext(String parentContextId, String vreName, List<String> resourcesIds) throws InvalidContextException {
|
||||
public Report createContext(String parentContextId, String vreName, List<OperatorParameters> parameters, String user) throws InvalidContextException {
|
||||
|
||||
Context parentContext = contextContainer.getContextById(parentContextId);
|
||||
|
||||
log.debug("parent context is null?? {}",(parentContext==null));
|
||||
|
||||
Context newContext = new Context(parentContext, vreName, vreName, Type.VRE);
|
||||
|
||||
Report report = new Report(newContext.getId(), vreName, newContext.getType(), "createContext", AuthorizationProvider.instance.get().getClient().getId());
|
||||
Report report = new Report(newContext.getId(), vreName, newContext.getType(), "createContext", user );
|
||||
|
||||
try {
|
||||
contextContainer.addContext(newContext );
|
||||
|
@ -57,13 +56,8 @@ public class ContextManager {
|
|||
return report;
|
||||
}
|
||||
|
||||
ReportGroup reportResGroup = new ReportGroup("addResources");
|
||||
for (String resourceId: resourcesIds) {
|
||||
resourceManager.addResourceToContext(newContext, resourceId);
|
||||
reportResGroup.addEntry(new ReportEntry(resourceId, "add resource with id "+resourceId, OperationResult.success()));
|
||||
}
|
||||
|
||||
|
||||
// TODO: run all the operation passed
|
||||
|
||||
report.setResult(OperationResult.success());
|
||||
return report;
|
||||
|
|
|
@ -8,6 +8,8 @@ import javax.xml.bind.annotation.XmlElement;
|
|||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.gcube.vremanagement.contextmanager.model.types.ScopedResource;
|
||||
|
||||
@XmlRootElement(name = "Body")
|
||||
@XmlAccessorType (XmlAccessType.FIELD)
|
||||
public class ScopeDescriptor {
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.gcube.vremanagement.contextmanager.handlers.ContextContainer;
|
|||
import org.gcube.vremanagement.contextmanager.model.exceptions.InvalidContextException;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.Context;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.Context.Type;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.ScopedResource;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@Singleton
|
||||
|
@ -59,7 +60,7 @@ public class ScopeInitializer {
|
|||
try {
|
||||
Context context = createEntireContext(new ScopeBean(scope));
|
||||
for (ScopedResource res : scopeDescr.scopedResources)
|
||||
contextContainer.addResource(context.getId(), res.id);
|
||||
contextContainer.addResource(context.getId(), res.getId());
|
||||
} catch (InvalidContextException e) {
|
||||
logger.error("invalid context {}", scope,e);
|
||||
}
|
||||
|
@ -93,7 +94,9 @@ public class ScopeInitializer {
|
|||
actual = new Context(parentContext,context, name, Type.values()[level]);
|
||||
contextContainer.addContext(actual);
|
||||
} catch (ContextAlreadyExistsException e) {
|
||||
logger.warn("context {} already exists", context,e);
|
||||
logger.warn("context {} already exists", context);
|
||||
} catch (InvalidContextException ice) {
|
||||
logger.warn(ice.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
package org.gcube.vremanagement.contextmanager;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement
|
||||
@XmlAccessorType (XmlAccessType.FIELD)
|
||||
public class ScopedResource {
|
||||
|
||||
@XmlElement(name = "ResourceID")
|
||||
String id;
|
||||
|
||||
@XmlElement(name = "ResourceType")
|
||||
String type;
|
||||
|
||||
@XmlElement(name = "JointTime")
|
||||
String jointTime;
|
||||
|
||||
@XmlElement(name = "HostedOn")
|
||||
String hostedOn;
|
||||
|
||||
protected ScopedResource() {}
|
||||
|
||||
public ScopedResource(String id, String type, String jointTime) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
this.jointTime = jointTime;
|
||||
}
|
||||
|
||||
public ScopedResource(String id, String type, String jointTime, String hostedOn) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
this.jointTime = jointTime;
|
||||
this.hostedOn = hostedOn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ScopedResource [id=" + id + ", type=" + type + ", jointTime=" + jointTime + ", hostedOn=" + hostedOn
|
||||
+ "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -26,13 +26,12 @@ import org.gcube.common.scope.api.ScopeProvider;
|
|||
import org.gcube.common.scope.api.ServiceMap;
|
||||
import org.gcube.common.scope.impl.ScopedServiceMap;
|
||||
import org.gcube.vremanagement.contextmanager.Utils;
|
||||
import org.gcube.vremanagement.contextmanager.model.collectors.CollectorsBackend;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.Context;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@Singleton
|
||||
@Default
|
||||
public class LegacyISConnector implements CollectorsBackend {
|
||||
public class LegacyISConnector {
|
||||
|
||||
@Inject Logger log;
|
||||
|
||||
|
@ -46,16 +45,13 @@ public class LegacyISConnector implements CollectorsBackend {
|
|||
return parseResource(res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createContext(Context context, String parentContextId, List<String> resourceIds) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeContext(Context context) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addResourceToContext(Context context, Resource resource) {
|
||||
String completeContext = Utils.getScopeFromContext(context);
|
||||
resource.scopes().asCollection().add(completeContext);
|
||||
|
@ -67,7 +63,6 @@ public class LegacyISConnector implements CollectorsBackend {
|
|||
return response.getStatusInfo().getFamily()==Family.SUCCESSFUL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeResourceFromContext(Context context, Resource resource) {
|
||||
|
||||
String completeContext = Utils.getScopeFromContext(context);
|
||||
|
@ -87,7 +82,6 @@ public class LegacyISConnector implements CollectorsBackend {
|
|||
return response.getStatusInfo().getFamily()==Family.SUCCESSFUL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateResource(Resource resource) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
|
|
|
@ -5,9 +5,10 @@ import java.util.List;
|
|||
import org.gcube.vremanagement.contextmanager.exceptions.ContextAlreadyExistsException;
|
||||
import org.gcube.vremanagement.contextmanager.model.exceptions.InvalidContextException;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.Context;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.ContextRetriever;
|
||||
|
||||
|
||||
public interface ContextContainer {
|
||||
public interface ContextContainer extends ContextRetriever{
|
||||
|
||||
List<String> getAvailableContexts();
|
||||
|
||||
|
|
|
@ -53,22 +53,23 @@ public class ContextContainerImpl implements ContextContainer, ContextRetriever
|
|||
return context;
|
||||
}
|
||||
|
||||
public synchronized void addResource(String contextId, String resourceId) throws InvalidContextException {
|
||||
public synchronized boolean addResource(String contextId, String resourceId) throws InvalidContextException {
|
||||
Context context = contextTree.getContext(contextId);
|
||||
if (context==null) throw new InvalidContextException("context with id "+contextId+" not found");
|
||||
|
||||
if (!resourceMap.containsKey(contextId))
|
||||
resourceMap.put(contextId, new ArrayList<>());
|
||||
resourceMap.get(contextId).add(resourceId);
|
||||
return resourceMap.get(contextId).add(resourceId);
|
||||
|
||||
}
|
||||
|
||||
public synchronized void removeResource(String contextId, String resourceId) throws InvalidContextException {
|
||||
public synchronized boolean removeResource(String contextId, String resourceId) throws InvalidContextException {
|
||||
Context context = contextTree.getContext(contextId);
|
||||
if (context==null) throw new InvalidContextException("context with id "+contextId+" not found");
|
||||
|
||||
if (resourceMap.containsKey(contextId))
|
||||
resourceMap.get(contextId).remove(resourceId);
|
||||
return resourceMap.get(contextId).remove(resourceId);
|
||||
else return false;
|
||||
}
|
||||
|
||||
public List<String> getResources(String contextId) throws InvalidContextException {
|
||||
|
|
|
@ -20,7 +20,7 @@ public class ContextTree {
|
|||
@Inject Logger log;
|
||||
|
||||
|
||||
private static TreeItem root;
|
||||
private TreeItem root;
|
||||
|
||||
private Map<String, TreeItem> values = new HashMap<>();
|
||||
|
||||
|
@ -41,14 +41,15 @@ public class ContextTree {
|
|||
log.debug("creating item {} with parentId {}", context, parentId);
|
||||
TreeItem item;
|
||||
if (parentId==null) {
|
||||
if (root!=null) throw new IllegalArgumentException("root is already set");
|
||||
if (root!=null) throw new InvalidContextException("root is already set");
|
||||
if (context.getType()!=Type.INFRASTRUCTURE) throw new InvalidContextException("this context is not a root context");
|
||||
item = new TreeItem(null, context);
|
||||
root= item;
|
||||
} else {
|
||||
TreeItem parentItem = values.get(parentId);
|
||||
log.debug("parent id is {} and is present ? {} and values {}", parentId, parentItem!=null, values.keySet());
|
||||
if (context.getType().getPossibleParent()!=parentItem.getContext().getType())
|
||||
throw new IllegalArgumentException("parent not valid");
|
||||
throw new InvalidContextException("parent not valid");
|
||||
item = new TreeItem(parentItem, context);
|
||||
parentItem.addChild(item);
|
||||
}
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
package org.gcube.vremanagement.contextmanager.handlers.impl;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.enterprise.inject.Any;
|
||||
import javax.enterprise.inject.Instance;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.common.resources.gcore.Resource.Type;
|
||||
import org.gcube.vremanagement.contextmanager.handlers.ResourceHandler;
|
||||
import org.gcube.vremanagement.contextmanager.model.collectors.CollectorsBackend;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.Context;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@Singleton
|
||||
public class StaticResourceHandler implements ResourceHandler {
|
||||
|
||||
@Inject
|
||||
Logger log;
|
||||
|
||||
@Inject
|
||||
@Any
|
||||
Instance<CollectorsBackend> connectors;
|
||||
|
||||
@Override
|
||||
public List<Type> getManagedResources() {
|
||||
return Arrays.asList(Type.GENERIC, Type.ENDPOINT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResource(Context context, Resource resource) {
|
||||
for (CollectorsBackend connector : connectors)
|
||||
try {
|
||||
connector.addResourceToContext(context, resource);
|
||||
}catch (Exception e) {
|
||||
log.warn("error adding context {} in resource with id {} ",context.getName() ,resource.id() ,e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeResource(Context context, Resource resource) {
|
||||
for (CollectorsBackend connector : connectors)
|
||||
try {
|
||||
connector.removeResourceFromContext(context, resource);
|
||||
}catch (Exception e) {
|
||||
log.warn("error removing context {} in resource with id {} ",context.getName() ,resource.id(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createResourceNotified(Context context, Resource resource) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeResourceNotified(Context context, Resource resource) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -12,7 +12,7 @@ import org.gcube.vremanagement.contextmanager.model.report.OperationResult;
|
|||
import org.gcube.vremanagement.contextmanager.model.types.Context;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.Context.Type;
|
||||
|
||||
public class StorageHubOperation implements MandatoryContextOperator{
|
||||
public class StorageHubOperator implements MandatoryContextOperator{
|
||||
|
||||
StorageHubClient client = new StorageHubClient();
|
||||
|
|
@ -1,26 +1,24 @@
|
|||
package org.gcube.vremanagement.contextmanager.operators;
|
||||
package org.gcube.vremanagement.contextmanager.operators.resources;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.gcube.vremanagement.contextmanager.ResourceManager;
|
||||
import org.gcube.vremanagement.contextmanager.ScopedResource;
|
||||
import org.gcube.vremanagement.contextmanager.model.exceptions.InvalidContextException;
|
||||
import org.gcube.vremanagement.contextmanager.model.exceptions.InvalidParameterException;
|
||||
import org.gcube.vremanagement.contextmanager.model.exceptions.OperationException;
|
||||
import org.gcube.vremanagement.contextmanager.model.operators.AddResourceParameter;
|
||||
import org.gcube.vremanagement.contextmanager.model.operators.OperatorParameters;
|
||||
import org.gcube.vremanagement.contextmanager.model.operators.context.CustomContextOperator;
|
||||
import org.gcube.vremanagement.contextmanager.model.operators.parameters.AddResourceParameters;
|
||||
import org.gcube.vremanagement.contextmanager.model.operators.parameters.OperatorParameters;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.Context;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.Context.Type;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.ContextRetriever;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.ScopedResource;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class AddResourceOperation extends CustomContextOperator<ScopedResource, AddResourceParameter> {
|
||||
public class AddResourceOperator extends CustomContextOperator<ScopedResource, AddResourceParameters> {
|
||||
|
||||
@Inject
|
||||
private Logger log;
|
||||
|
@ -28,11 +26,6 @@ public class AddResourceOperation extends CustomContextOperator<ScopedResource,
|
|||
@Inject
|
||||
private ResourceManager resourceManager;
|
||||
|
||||
@Inject
|
||||
private ContextRetriever contextRetriever;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Set<Type> getAllowedContextType() {
|
||||
return new HashSet<>(Arrays.asList(Type.values()));
|
||||
|
@ -49,11 +42,10 @@ public class AddResourceOperation extends CustomContextOperator<ScopedResource,
|
|||
}
|
||||
|
||||
@Override
|
||||
public ScopedResource execute(Context context, AddResourceParameter params) throws OperationException {
|
||||
log.debug("executing operation %s",this.getOperationId());
|
||||
public ScopedResource execute(Context context, AddResourceParameters params) throws OperationException {
|
||||
log.debug("executing operation {}",this.getOperationId());
|
||||
try {
|
||||
Context toAddTo = contextRetriever.getContextById(params.getContextId());
|
||||
ScopedResource res = resourceManager.addResourceToContext(toAddTo, params.getResourceId());
|
||||
ScopedResource res = resourceManager.addResourceToContext(context, params.getResourceId());
|
||||
return res;
|
||||
}catch (InvalidContextException e) {
|
||||
//it should never happen
|
||||
|
@ -68,16 +60,9 @@ public class AddResourceOperation extends CustomContextOperator<ScopedResource,
|
|||
}
|
||||
|
||||
@Override
|
||||
protected AddResourceParameter checkAndTrasformParameters(Context context, OperatorParameters params)
|
||||
protected AddResourceParameters checkAndTrasformParameters(Context context, OperatorParameters params)
|
||||
throws InvalidParameterException {
|
||||
AddResourceParameter addParams = AddResourceParameter.class.cast(params);
|
||||
if (addParams.getContextId()==null)
|
||||
throw new InvalidParameterException("contextId is null");
|
||||
try {
|
||||
contextRetriever.getContextById(addParams.getContextId());
|
||||
}catch (InvalidContextException e) {
|
||||
throw new InvalidParameterException("contextId "+addParams.getContextId()+" doesn't exist");
|
||||
}
|
||||
AddResourceParameters addParams = AddResourceParameters.class.cast(params);
|
||||
if (addParams.getResourceId()==null)
|
||||
throw new InvalidParameterException("resourceId is null");
|
||||
return addParams;
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.vremanagement.contextmanager.handlers.impl;
|
||||
package org.gcube.vremanagement.contextmanager.operators.resources;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -7,7 +7,6 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.common.resources.gcore.Resource.Type;
|
||||
import org.gcube.vremanagement.contextmanager.handlers.ResourceHandler;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.Context;
|
||||
|
||||
@Singleton
|
||||
|
@ -20,14 +19,13 @@ public class DynamicResourceHandler implements ResourceHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void addResource(Context context, Resource resource) {
|
||||
// TODO Auto-generated method stub
|
||||
public boolean addResource(Context context, Resource resource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeResource(Context context, Resource resource) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public boolean removeResource(Context context, Resource resource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
|
@ -0,0 +1,72 @@
|
|||
package org.gcube.vremanagement.contextmanager.operators.resources;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.gcube.vremanagement.contextmanager.model.exceptions.InvalidContextException;
|
||||
import org.gcube.vremanagement.contextmanager.model.exceptions.InvalidParameterException;
|
||||
import org.gcube.vremanagement.contextmanager.model.exceptions.OperationException;
|
||||
import org.gcube.vremanagement.contextmanager.model.operators.context.CustomContextOperator;
|
||||
import org.gcube.vremanagement.contextmanager.model.operators.parameters.OperatorParameters;
|
||||
import org.gcube.vremanagement.contextmanager.model.operators.parameters.RemoveResourceParameters;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.Context;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.Context.Type;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.ScopedResource;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class RemoveResourceOperator extends CustomContextOperator<ScopedResource, RemoveResourceParameters> {
|
||||
|
||||
@Inject
|
||||
private Logger log;
|
||||
|
||||
@Inject
|
||||
private ResourceManager resourceManager;
|
||||
|
||||
|
||||
@Override
|
||||
public Set<Type> getAllowedContextType() {
|
||||
return new HashSet<>(Arrays.asList(Type.values()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOperationId() {
|
||||
return "remove-resource";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Removes resource from context";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScopedResource execute(Context context, RemoveResourceParameters params) throws OperationException {
|
||||
log.debug("executing operation {}",this.getOperationId());
|
||||
try {
|
||||
ScopedResource res = resourceManager.removeResourceFromContext(context, params.getResourceId());
|
||||
return res;
|
||||
}catch (InvalidContextException e) {
|
||||
//it should never happen
|
||||
throw new InvalidParameterException("unknown exception");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScopedResource undo(Context context, OperatorParameters params) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RemoveResourceParameters checkAndTrasformParameters(Context context, OperatorParameters params)
|
||||
throws InvalidParameterException {
|
||||
RemoveResourceParameters removeParams = RemoveResourceParameters.class.cast(params);
|
||||
if (removeParams.getResourceId()==null)
|
||||
throw new InvalidParameterException("resourceId is null");
|
||||
return removeParams;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.vremanagement.contextmanager.handlers;
|
||||
package org.gcube.vremanagement.contextmanager.operators.resources;
|
||||
|
||||
|
||||
import java.util.List;
|
|
@ -1,20 +1,19 @@
|
|||
package org.gcube.vremanagement.contextmanager;
|
||||
package org.gcube.vremanagement.contextmanager.operators.resources;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.enterprise.inject.Any;
|
||||
import javax.enterprise.inject.Default;
|
||||
import javax.enterprise.inject.Instance;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.common.resources.gcore.Resource.Type;
|
||||
import org.gcube.vremanagement.contextmanager.collector.LegacyISConnector;
|
||||
import org.gcube.vremanagement.contextmanager.handlers.ContextContainer;
|
||||
import org.gcube.vremanagement.contextmanager.handlers.ResourceHandler;
|
||||
import org.gcube.vremanagement.contextmanager.model.collectors.CollectorsBackend;
|
||||
import org.gcube.vremanagement.contextmanager.model.exceptions.InvalidContextException;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.Context;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.ScopedResource;
|
||||
import org.jboss.weld.exceptions.IllegalArgumentException;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
|
@ -27,11 +26,10 @@ public class ResourceManager {
|
|||
Instance<ResourceHandler> resourcesHandlers;
|
||||
|
||||
@Inject
|
||||
@Default
|
||||
CollectorsBackend defaultCollector;
|
||||
ContextContainer contextContainer;
|
||||
|
||||
@Inject
|
||||
ContextContainer contextContainer;
|
||||
LegacyISConnector connector;
|
||||
|
||||
@Inject Logger log;
|
||||
|
||||
|
@ -53,7 +51,7 @@ public class ResourceManager {
|
|||
}
|
||||
|
||||
private Resource retrieveResource(String id) {
|
||||
return defaultCollector.find(id);
|
||||
return connector.find(id);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package org.gcube.vremanagement.contextmanager.operators.resources;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.common.resources.gcore.Resource.Type;
|
||||
import org.gcube.vremanagement.contextmanager.collector.LegacyISConnector;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.Context;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@Singleton
|
||||
public class StaticResourceHandler implements ResourceHandler {
|
||||
|
||||
@Inject
|
||||
Logger log;
|
||||
|
||||
@Override
|
||||
public List<Type> getManagedResources() {
|
||||
return Arrays.asList(Type.GENERIC, Type.ENDPOINT);
|
||||
}
|
||||
|
||||
@Inject
|
||||
LegacyISConnector connector;
|
||||
|
||||
@Override
|
||||
public boolean addResource(Context context, Resource resource) {
|
||||
return connector.addResourceToContext(context, resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeResource(Context context, Resource resource) {
|
||||
return connector.removeResourceFromContext(context, resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createResourceNotified(Context context, Resource resource) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeResourceNotified(Context context, Resource resource) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -15,16 +15,17 @@ import javax.ws.rs.Produces;
|
|||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
import org.gcube.vremanagement.contextmanager.ContextManager;
|
||||
import org.gcube.vremanagement.contextmanager.ContextServiceAppManager;
|
||||
import org.gcube.vremanagement.contextmanager.ResourceManager;
|
||||
import org.gcube.vremanagement.contextmanager.Utils;
|
||||
import org.gcube.vremanagement.contextmanager.handlers.ContextContainer;
|
||||
import org.gcube.vremanagement.contextmanager.model.exceptions.InvalidContextException;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.Context;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.StringList;
|
||||
import org.gcube.vremanagement.contextmanager.operators.resources.ResourceManager;
|
||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
|
@ -75,7 +76,7 @@ public class ContextService {
|
|||
|
||||
try {
|
||||
//validate Call
|
||||
contextHandler.createContext(contextId, vreName, resourceIds.getValues());
|
||||
contextHandler.createContext(contextId, vreName, resourceIds.getValues(), AuthorizationProvider.instance.get().getClient().getId());
|
||||
}catch (Exception e) {
|
||||
log.error("error creating context {}",contextId,e);
|
||||
throw new WebApplicationException(e);
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
package org.gcube.vremanagement.contextmanager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.enterprise.inject.Default;
|
||||
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.vremanagement.contextmanager.model.collectors.CollectorsBackend;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.Context;
|
||||
|
||||
@Default
|
||||
public class BackendCollectorTester implements CollectorsBackend {
|
||||
|
||||
@Override
|
||||
public Resource find(String resourceId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createContext(Context context, String parentContextId, List<String> resourceIds) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeContext(Context context) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addResourceToContext(Context context, Resource resource) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeResourceFromContext(Context context, Resource resource) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateResource(Resource resource) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -11,12 +11,15 @@ import org.gcube.common.scope.api.ScopeProvider;
|
|||
import org.gcube.vremanagement.contextmanager.collector.LegacyISConnector;
|
||||
import org.gcube.vremanagement.contextmanager.handlers.ContextContainer;
|
||||
import org.gcube.vremanagement.contextmanager.handlers.impl.ContextContainerImpl;
|
||||
import org.gcube.vremanagement.contextmanager.handlers.impl.DynamicResourceHandler;
|
||||
import org.gcube.vremanagement.contextmanager.handlers.impl.StaticResourceHandler;
|
||||
import org.gcube.vremanagement.contextmanager.model.collectors.CollectorsBackend;
|
||||
import org.gcube.vremanagement.contextmanager.model.exceptions.InvalidContextException;
|
||||
import org.gcube.vremanagement.contextmanager.model.exceptions.OperationException;
|
||||
import org.gcube.vremanagement.contextmanager.model.operators.parameters.AddResourceParameters;
|
||||
import org.gcube.vremanagement.contextmanager.model.operators.parameters.RemoveResourceParameters;
|
||||
import org.gcube.vremanagement.contextmanager.model.types.Context;
|
||||
import org.gcube.vremanagement.contextmanager.operations.MandatoryVREOperationTest;
|
||||
import org.gcube.vremanagement.contextmanager.operators.resources.AddResourceOperator;
|
||||
import org.gcube.vremanagement.contextmanager.operators.resources.DynamicResourceHandler;
|
||||
import org.gcube.vremanagement.contextmanager.operators.resources.RemoveResourceOperator;
|
||||
import org.gcube.vremanagement.contextmanager.operators.resources.StaticResourceHandler;
|
||||
import org.jglue.cdiunit.AdditionalClasses;
|
||||
import org.jglue.cdiunit.CdiRunner;
|
||||
import org.junit.Before;
|
||||
|
@ -26,7 +29,7 @@ import org.slf4j.Logger;
|
|||
|
||||
@RunWith(CdiRunner.class)
|
||||
@AdditionalClasses({ContextContainerImpl.class, Factories.class,
|
||||
LegacyISConnector.class, DynamicResourceHandler.class, StaticResourceHandler.class, MandatoryVREOperationTest.class })
|
||||
DynamicResourceHandler.class, StaticResourceHandler.class })
|
||||
public class ScopeTester {
|
||||
|
||||
@Inject ScopeInitializer scopeInitializer;
|
||||
|
@ -35,11 +38,13 @@ public class ScopeTester {
|
|||
|
||||
@Inject ContextManager contextManager;
|
||||
|
||||
@Inject CollectorsBackend is;
|
||||
@Inject LegacyISConnector is;
|
||||
|
||||
@Inject Logger log;
|
||||
|
||||
@Inject ResourceManager resourceManager;
|
||||
@Inject AddResourceOperator addResourceOp;
|
||||
|
||||
@Inject RemoveResourceOperator removeResourceOp;
|
||||
|
||||
private static String resourceId = "eabfe9bb-001d-48bc-92dc-586eefdc2006";
|
||||
|
||||
|
@ -70,20 +75,29 @@ public class ScopeTester {
|
|||
|
||||
@Test
|
||||
public void addAndRemoveResourceScopeTest() throws InvalidContextException {
|
||||
Context context = container.getContextById(vreContext);
|
||||
resourceManager.addResourceToContext(context, resourceId);
|
||||
Context current = container.getContextById(ScopeProvider.instance.get());
|
||||
try {
|
||||
addResourceOp.execute(current, new AddResourceParameters(vreContext, resourceId, Resource.Type.GENERIC));
|
||||
} catch (OperationException e) {
|
||||
log.error("operation error",e);
|
||||
}
|
||||
assertTrue(container.getResources(vreContext).contains(resourceId));
|
||||
Resource res = is.find(resourceId);
|
||||
assertTrue(res.scopes().asCollection().contains(vreContext));
|
||||
log.debug("scopes are {}",res.scopes().asCollection());
|
||||
resourceManager.removeResourceFromContext(context, resourceId);
|
||||
try {
|
||||
removeResourceOp.execute(current, new RemoveResourceParameters(vreContext, resourceId));
|
||||
} catch (OperationException e) {
|
||||
log.error("operation error",e);
|
||||
}
|
||||
assertTrue(!container.getResources(vreContext).contains(resourceId));
|
||||
assertTrue(!is.find(resourceId).scopes().contains(vreContext));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createContextTest() throws InvalidContextException {
|
||||
contextManager.createContext(context, "newVRE", Collections.emptyList());
|
||||
contextManager.createContext(context, "newVRE", Collections.emptyList(), "user");
|
||||
assertTrue(container.getAvailableContexts().contains("newVRE"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package org.gcube.vremanagement.contextmanager.operations;
|
||||
|
||||
public class AddResourceOperatorTest {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package org.gcube.vremanagement.contextmanager.operations;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -12,24 +13,14 @@ import org.slf4j.Logger;
|
|||
|
||||
public class MandatoryVREOperationTest implements MandatoryContextOperator{
|
||||
|
||||
static String id = UUID.randomUUID().toString();
|
||||
|
||||
@Inject Logger log;
|
||||
|
||||
@Override
|
||||
public Type getApplicationContextType() {
|
||||
return Type.VRE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOperationId() {
|
||||
return id;
|
||||
return "test-op";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "testOp";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
|
@ -48,4 +39,9 @@ public class MandatoryVREOperationTest implements MandatoryContextOperator{
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Type> getAllowedContextType() {
|
||||
return Collections.singleton(Type.VRE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue