This commit is contained in:
Lucio Lelii 2017-02-09 16:34:15 +00:00
parent 8b8eec0ff2
commit af7232707d
3 changed files with 107 additions and 200 deletions

View File

@ -1,84 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource xmlns:p1="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID>24175c70-997f-11dd-b66d-82c61f8d0a26</ID>
<Type>Service</Type>
<Profile>
<Description>Perform local deployment/undeployment of GCUBE packages</Description>
<Class>VREManagement</Class>
<Name>ResourceManager</Name>
<Version>1.0.0</Version>
<Packages>
<Main deployable="false">
<Description>Allow deployment/undeployment operations of gCube packages in the local gHN</Description>
<Name>ResourceManager-service</Name>
<Version>2.1.1-SNAPSHOT</Version>
<MavenCoordinates>
<groupId>org.gcube.resourcemanagement</groupId>
<artifactId>resource-manager-service</artifactId>
<version>2.1.1-SNAPSHOT</version>
</MavenCoordinates>
<Mandatory level="GHN"/>
<Shareable level="VO"/>
<GHNRequirements>
<Requirement category="Site" requirement="string" value="java1.6_*" operator="ge"/>
</GHNRequirements>
<GARArchive>resource-manager-service-2.1.1-SNAPSHOT.gar</GARArchive>
<PortType>
<Name>gcube/vremanagement/resourcemanager/binder</Name>
<Security/>
<WSDL/>
</PortType>
<PortType>
<Name>gcube/vremanagement/resourcemanager/scopecontroller</Name>
<Security/>
<WSDL/>
</PortType>
<PortType>
<Name>gcube/vremanagement/resourcemanager/reporting</Name>
<Security/>
<WSDL/>
</PortType>
<PortType>
<Name>gcube/vremanagement/resourcemanager/administration</Name>
<Security/>
<WSDL/>
</PortType>
</Main>
<Software>
<Description>Stubs for ResourceManager: provide facilities to interact with a ResourceManager instance</Description>
<Name>ResourceManager-stubs</Name>
<Version>2.1.1-SNAPSHOT</Version>
<MavenCoordinates>
<groupId>org.gcube.resourcemanagement</groupId>
<artifactId>resource-manager-stubs</artifactId>
<version>2.1.1-SNAPSHOT</version>
</MavenCoordinates>
<MultiVersion value="true"/>
<Shareable level="VO"/>
<GHNRequirements>
<Requirement category="Site" operator="ge" requirement="string" value="java1.5"/>
</GHNRequirements>
<Type>application</Type>
<Files>
<File>resource-manager-stubs-2.1.1-SNAPSHOT.jar</File>
</Files>
</Software>
<Software>
<Description>Test-suite for ResourceManager: provide test usages of interaction with a ResourceManager instance</Description>
<Name>ResourceManager-test-suite</Name>
<Version>2.1.1-SNAPSHOT</Version>
<MavenCoordinates>
<groupId>org.gcube.resourcemanagement</groupId>
<artifactId>resource-manager-test-suite</artifactId>
<version>2.1.1-SNAPSHOT</version>
</MavenCoordinates>
<MultiVersion value="true"/>
<Shareable level="VO"/>
<Type>application</Type>
<Files>
<File>resource-manager-test-suite-2.1.1-SNAPSHOT.jar</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

View File

@ -11,7 +11,7 @@
<artifactId>resource-manager-service</artifactId>
<name>Resource Manager Service</name>
<description>A service for managing subsets of gCube resources in a given scope</description>
<dependencyManagement>
<dependencies>
<dependency>
@ -23,7 +23,7 @@
</dependency>
</dependencies>
</dependencyManagement>
<scm>
<connection>scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/ResourceManager</connection>
<developerConnection>scm:svn:https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/ResourceManager</developerConnection>
@ -39,6 +39,12 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.resources</groupId>
<artifactId>registry-publisher</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.resourcemanagement</groupId>
<artifactId>resource-manager-stubs</artifactId>
@ -47,7 +53,7 @@
<dependency>
<groupId>org.gcube.resourcemanagement</groupId>
<artifactId>softwaregateway-stubs</artifactId>
<scope>provided</scope>
<scope>provided</scope>
</dependency>
<dependency>
@ -55,54 +61,47 @@
<artifactId>ghnmanager-stubs</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.informationsystem</groupId>
<artifactId>is-client</artifactId>
<version>[1.5.0-SNAPSHOT, 1.6.0-SNAPSHOT]</version>
<groupId>org.gcube.informationsystem</groupId>
<artifactId>is-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gcube.informationsystem</groupId>
<artifactId>is-collector-stubs</artifactId>
<version>3.0.0-SNAPSHOT</version>
<scope>test</scope>
<groupId>org.gcube.informationsystem</groupId>
<artifactId>is-collector-stubs</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gcube.resourcemanagement</groupId>
<artifactId>resourcebroker-serialization</artifactId>
<version>[1.2.0-SNAPSHOT,1.3.0-SNAPSHOT)</version>
<groupId>org.gcube.resourcemanagement</groupId>
<artifactId>resourcebroker-serialization</artifactId>
<version>[1.2.0-SNAPSHOT,1.3.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.resourcemanagement</groupId>
<artifactId>rbstubs</artifactId>
<version>[1.2.2-SNAPSHOT,1.3.0-SNAPSHOT)</version>
<groupId>org.gcube.resourcemanagement</groupId>
<artifactId>rbstubs</artifactId>
<version>[1.2.2-SNAPSHOT,1.3.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.resourcemanagement</groupId>
<artifactId>deployer-stubs</artifactId>
<version>[2.4.0-SNAPSHOT,2.5.0-SNAPSHOT)</version>
<scope>provided</scope>
<groupId>org.gcube.resourcemanagement</groupId>
<artifactId>deployer-stubs</artifactId>
<version>[2.4.0-SNAPSHOT,2.5.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<!-- test dependencies -->
<!--dependency>
<groupId>org.gcube.tools</groupId>
<artifactId>my-container</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency-->
<!--dependency> <groupId>org.gcube.tools</groupId> <artifactId>my-container</artifactId>
<version>1.0.0</version> <scope>test</scope> </dependency -->
<dependency>
<groupId>org.gcube.tools</groupId>
<artifactId>my-container</artifactId>
@ -124,9 +123,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gcube.resourcemanagement</groupId>
<artifactId>whn-manager-client</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<groupId>org.gcube.resourcemanagement</groupId>
<artifactId>whn-manager-client</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
</dependencies>
<profiles>
@ -177,27 +176,12 @@
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<!--execution>
<id>install-my-container</id>
<phase>generate-test-resources</phase>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.gcube.tools</groupId>
<artifactId>my-container</artifactId>
<version>1.0.0</version>
<type>tar.gz</type>
<classifier>distro</classifier>
<overWrite>false</overWrite>
<outputDirectory>${project.basedir}</outputDirectory>
</artifactItem>
</artifactItems>
<markersDirectory>${project.basedir}</markersDirectory>
</configuration>
<goals>
<goal>unpack</goal>
</goals>
</execution-->
<!--execution> <id>install-my-container</id> <phase>generate-test-resources</phase>
<configuration> <artifactItems> <artifactItem> <groupId>org.gcube.tools</groupId>
<artifactId>my-container</artifactId> <version>1.0.0</version> <type>tar.gz</type>
<classifier>distro</classifier> <overWrite>false</overWrite> <outputDirectory>${project.basedir}</outputDirectory>
</artifactItem> </artifactItems> <markersDirectory>${project.basedir}</markersDirectory>
</configuration> <goals> <goal>unpack</goal> </goals> </execution -->
<execution>
<id>install-my-container</id>
<phase>generate-test-resources</phase>
@ -234,8 +218,9 @@
</execution>
</executions>
</plugin>
<!-- the following is to allow test-suite sources to access protected methods -->
<!-- the following is to allow test-suite sources to access protected
methods -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>

View File

@ -1,32 +1,24 @@
package org.gcube.vremanagement.resourcemanager.impl.resources;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.util.Collections;
import java.util.List;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.resources.GCUBECS;
import org.gcube.common.core.resources.GCUBECSInstance;
import org.gcube.common.core.resources.GCUBECollection;
import org.gcube.common.core.resources.GCUBEExternalRunningInstance;
import org.gcube.common.core.resources.GCUBEGenericResource;
import org.gcube.common.core.resources.GCUBEMCollection;
import org.gcube.common.core.resources.GCUBEResource;
import org.gcube.common.core.resources.GCUBERuntimeResource;
import org.gcube.common.core.resources.GCUBEService;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.vremanagement.resourcemanager.impl.contexts.ServiceContext;
import org.gcube.common.core.informationsystem.client.AtomicCondition;
import org.gcube.common.core.informationsystem.client.ISClient;
import org.gcube.common.core.informationsystem.client.ISTemplateQuery;
import org.gcube.common.core.informationsystem.client.queries.GCUBECSInstanceQuery;
import org.gcube.common.core.informationsystem.client.queries.GCUBECSQuery;
import org.gcube.common.core.informationsystem.client.queries.GCUBECollectionQuery;
import org.gcube.common.core.informationsystem.client.queries.GCUBEExternalRIQuery;
import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericResourceQuery;
import org.gcube.common.core.informationsystem.client.queries.GCUBEMCollectionQuery;
import org.gcube.common.core.informationsystem.client.queries.GCUBERuntimeResourceQuery;
import org.gcube.common.core.informationsystem.client.queries.GCUBEServiceQuery;
import org.gcube.common.core.informationsystem.publisher.ISPublisher;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.impl.XQuery;
import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.common.resources.gcore.Resource;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.Software;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
import org.gcube.informationsystem.publisher.ScopedPublisher;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
@ -41,12 +33,12 @@ import com.thoughtworks.xstream.annotations.XStreamOmitField;
public final class ScopedAnyResource extends ScopedResource {
@XStreamOmitField
GCUBEResource profile = null;
Resource profile = null;
@SuppressWarnings("rawtypes")
@XStreamOmitField
Class profileClass = null;
protected ScopedAnyResource(String id, String type, GCUBEScope scope) {
super(id, type, scope);
}
@ -56,52 +48,59 @@ public final class ScopedAnyResource extends ScopedResource {
* @throws Exception if the resource was not found
*/
@Override
@SuppressWarnings({ "unchecked", "rawtypes"})
protected void find() throws Exception {
ISClient client = GHNContext.getImplementation(ISClient.class);
Class query = null;
if (this.type.compareToIgnoreCase(GCUBECollection.TYPE) == 0) {query = GCUBECollectionQuery.class; profileClass = GCUBECollection.class;}
else if (this.type.compareToIgnoreCase(GCUBEMCollection.TYPE) == 0) {query = GCUBEMCollectionQuery.class; profileClass = GCUBEMCollection.class;}
else if (this.type.compareToIgnoreCase(GCUBEGenericResource.TYPE) == 0) {query = GCUBEGenericResourceQuery.class; profileClass = GCUBEGenericResource.class;}
else if (this.type.compareToIgnoreCase(GCUBEExternalRunningInstance.TYPE) == 0) {query = GCUBEExternalRIQuery.class; profileClass = GCUBEExternalRunningInstance.class;}
else if (this.type.compareToIgnoreCase(GCUBECS.TYPE) == 0) {query = GCUBECSQuery.class; profileClass = GCUBECS.class;}
else if (this.type.compareToIgnoreCase(GCUBECSInstance.TYPE) == 0) {query = GCUBECSInstanceQuery.class; profileClass = GCUBECSInstance.class;}
else if (this.type.compareToIgnoreCase(GCUBEService.TYPE) == 0) {query = GCUBEServiceQuery.class; profileClass = GCUBEService.class;}
else if (this.type.compareToIgnoreCase(GCUBERuntimeResource.TYPE) == 0) {query = GCUBERuntimeResourceQuery.class; profileClass = GCUBERuntimeResource.class;}
else throw new Exception("Unknown resource type: " + this.type);
List <GCUBEResource> profiles=null;
ISTemplateQuery realquery =null;
try {
realquery = (ISTemplateQuery) client.getQuery(query);
logger.info("execution query "+query+" on scope "+scope+" with id: "+this.id);
realquery.addAtomicConditions(new AtomicCondition("/ID",this.id));
profiles = client.execute(realquery, GCUBEScope.getScope(this.scope));
if ((profiles != null) && (profiles.size() > 0)){
logger.info("profile found ");
this.profile = profiles.get(0);
}else{
GCUBEScope enclosingScope=GCUBEScope.getScope(this.scope).getEnclosingScope();
Class<? extends Resource> queryType = null;
if (this.type.compareToIgnoreCase(GCUBEGenericResource.TYPE) == 0) {queryType = GenericResource.class; profileClass = GCUBEGenericResource.class;}
else if (this.type.compareToIgnoreCase(GCUBEService.TYPE) == 0) {queryType = Software.class; profileClass = GCUBEService.class;}
else if (this.type.compareToIgnoreCase(GCUBERuntimeResource.TYPE) == 0) {queryType = ServiceEndpoint.class; profileClass = GCUBERuntimeResource.class;}
else throw new Exception("Unknown resource type: " + this.type);
List<? extends Resource> profiles=null;
try {
XQuery query = queryFor(queryType);
query.addCondition(String.format("$resource/ID/string() eq '%s'",this.id));
logger.info("execution query "+query+" on scope "+scope+" with id: "+this.id);
DiscoveryClient<? extends Resource> client = clientFor(queryType);
//I'm not sure the scopeProvider is set in this thread
ScopeProvider.instance.set(this.getScope().toString());
profiles = client.submit(query);
if ((profiles != null) && (profiles.size() > 0)){
logger.info("profile found ");
this.profile = profiles.get(0);
}else{
String enclosingScope = GCUBEScope.getScope(this.scope).getEnclosingScope().toString();
try{
ScopeProvider.instance.set(GCUBEScope.getScope(this.scope).getEnclosingScope().toString());
logger.info("profile not found. Try on enclosing scope: "+enclosingScope);
// obviously, in the case of adding, the resource is not in the current scope, therefore we look upstairs (the enclosing scope)
this.profile = (GCUBEResource) client.execute(realquery, enclosingScope).get(0);
this.profile = client.submit(query).get(0);
}finally{
ScopeProvider.instance.set(this.scope.toString());
}
}
} catch (Throwable e) {
getLogger().error("bad query. Caused by: "+e.getCause());
throw new Exception("unable to find the target resource (ID=" + id + "). Possible cause: " + e.getMessage(), e);
}
}
@Override
protected void addToScope() throws ResourceNotFound, Exception {
this.findResource();
getLogger().debug("Adding scope to resource profile");
try {
profile.addScope(this.getScope());
getLogger().debug("republish the resource "+profile.getID()+" with scope added "+this.getScope()+"with GCubeScope: "+ ServiceContext.getContext().getScope()+" in context "+ServiceContext.getContext());
getLogger().debug("republish the resource "+profile.id()+" with scope added "+this.getScope());
//patch: serviceContext altered by is-publisher
GCUBEScope currentServiceContext=ServiceContext.getContext().getScope();
/*GCUBEScope currentServiceContext=ServiceContext.getContext().getScope();
//republish the resource
ISPublisher publisher = GHNContext.getImplementation(ISPublisher.class);
publisher.updateGCUBEResource(this.profile, ServiceContext.getContext().getScope(), ServiceContext.getContext());
@ -115,8 +114,12 @@ public final class ScopedAnyResource extends ScopedResource {
}
getLogger().debug(": "+profile.getID()+"\n\t the ServiceContext is "+ServiceContext.getContext().getScope());
//patch: serviceContext altered by is-publisher
ServiceContext.getContext().setScope(currentServiceContext);
getLogger().debug("ServiceContext scope restored to: "+currentServiceContext);
ServiceContext.getContext().setScope(currentServiceContext);*/
ScopedPublisher publisher = RegistryPublisherFactory.scopedPublisher();
publisher.create(profile, Collections.singletonList(this.getScope().toString()));
} catch (Exception e) {
this.noHopeForMe("Failed to add the scope ("+ this.getScope()+") to resource " + this.getId(), e);
}
@ -128,7 +131,7 @@ public final class ScopedAnyResource extends ScopedResource {
getLogger().debug("Removing scope from resource profile");
try {
//patch: serviceContext altered by is-publisher
GCUBEScope currentServiceContext=ServiceContext.getContext().getScope();
/*GCUBEScope currentServiceContext=ServiceContext.getContext().getScope();
profile.removeScope(this.getScope());
//republish the resource
ISPublisher publisher = GHNContext.getImplementation(ISPublisher.class);
@ -141,10 +144,13 @@ public final class ScopedAnyResource extends ScopedResource {
}
//patch: serviceContext altered by is-publisher
ServiceContext.getContext().setScope(currentServiceContext);
*/
ScopedPublisher publisher = RegistryPublisherFactory.scopedPublisher();
publisher.remove(profile, Collections.singletonList(this.getScope().toString()));
} catch (Exception e) {
this.noHopeForMe("Failed to remove the scope ("+ this.getScope()+") from resource " + this.getId(), e);
}
}
}