in the way to the FWS, 50 percent ported so far
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/admin/rmp-common-library@81279 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
274dbf124a
commit
878cc7ffc5
|
@ -0,0 +1,2 @@
|
|||
disabled=06target
|
||||
eclipse.preferences.version=1
|
30
pom.xml
30
pom.xml
|
@ -11,7 +11,7 @@
|
|||
|
||||
<groupId>org.gcube.portlets.admin</groupId>
|
||||
<artifactId>rmp-common-library</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<name>Resource Management Library</name>
|
||||
<description>
|
||||
gCube Resource Management Library is a common library containing shared code for Information System Operations
|
||||
|
@ -24,7 +24,7 @@
|
|||
</scm>
|
||||
<properties>
|
||||
<!-- Convenience property to set the GWT version -->
|
||||
<gwtVersion>2.4.0</gwtVersion>
|
||||
<gwtVersion>2.5.1</gwtVersion>
|
||||
<distroDirectory>distro</distroDirectory>
|
||||
<!-- GWT needs at least java 1.6 -->
|
||||
<maven.compiler.source>1.6</maven.compiler.source>
|
||||
|
@ -61,11 +61,33 @@
|
|||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>org.gcube.resourcemanagement</groupId> -->
|
||||
<!-- <artifactId>resource-manager-stubs</artifactId> -->
|
||||
<!-- <version>[2.0.1-SNAPSHOT, 3.0.0-SNAPSHOT)</version> -->
|
||||
<!-- </dependency> -->
|
||||
<!-- FWS DEPS -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.resources.discovery</groupId>
|
||||
<artifactId>ic-client</artifactId>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.resourcemanagement</groupId>
|
||||
<artifactId>resource-manager-stubs</artifactId>
|
||||
<version>[2.0.1-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
<artifactId>resourcemanager-client</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.resources</groupId>
|
||||
<artifactId>registry-publisher</artifactId>
|
||||
<version>[1.1.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.resourcemanagement</groupId>
|
||||
<artifactId>ghn-manager-client</artifactId>
|
||||
<version>[1.1.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<!-- END FWS -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.resourcemanagement</groupId>
|
||||
<artifactId>ghnmanager-stubs</artifactId>
|
||||
|
|
|
@ -24,53 +24,52 @@ public enum ResourceTypeDecorator {
|
|||
/****************************************
|
||||
* RESOURCES IN THE TREE
|
||||
****************************************/
|
||||
GHN("gCube Hosting Node", "ghn-icon"),
|
||||
RunningInstance("Running Instances", "runninginstance-icon"),
|
||||
Service("Software", "service-icon"),
|
||||
VIEW("View", "metadatacollection-icon"),
|
||||
GenericResource("Generic Resources", "genericresource-icon"),
|
||||
Collection("Collection", "collection-icon"),
|
||||
WSResource("WSResource", "wsresources-icon"),
|
||||
Empty("Empty Tree", "empty-icon"),
|
||||
RuntimeResource("Runtime Resources", "runtimeresource-icon"),
|
||||
GHN("gCube Hosting Node", "ghn-icon","Hosting Node"),
|
||||
RunningInstance("Running Instances", "runninginstance-icon", "GCore Endpoint"),
|
||||
Service("Software", "service-icon","Software"),
|
||||
VIEW("View", "metadatacollection-icon",""),
|
||||
GenericResource("Generic Resources", "genericresource-icon","Generic Resource"),
|
||||
Collection("Collection", "collection-icon",""),
|
||||
WSResource("WSResource", "wsresources-icon",""),
|
||||
Empty("Empty Tree", "empty-icon",""),
|
||||
RuntimeResource("Runtime Resources", "runtimeresource-icon", "Service Endpoint"),
|
||||
|
||||
/****************************************
|
||||
* Other components
|
||||
****************************************/
|
||||
// For deploying services - similar to the software but with an
|
||||
// extension to handle checkbox for install
|
||||
InstallableSoftware("InstallableSoftware", "empty-icon"),
|
||||
InstallableSoftware("InstallableSoftware", "empty-icon",""),
|
||||
// In the taskbar for handlig the refresh of deployment reports
|
||||
DeployReport("Deploy Report", "report-big-icon"),
|
||||
AddScopeReport("Add Scope Report", "report-big-icon"),
|
||||
DeployReport("Deploy Report", "report-big-icon",""),
|
||||
AddScopeReport("Add Scope Report", "report-big-icon",""),
|
||||
|
||||
|
||||
/****************************************
|
||||
* Related resources
|
||||
****************************************/
|
||||
GHNRelated("Running Instances", "runninginstance-icon"),
|
||||
ServiceRelated("Running Instances", "runninginstance-icon"),
|
||||
RunningInstanceRelated("Running Instances", "runninginstance-icon"),
|
||||
GHNRelated("Running Instances", "runninginstance-icon",""),
|
||||
ServiceRelated("Running Instances", "runninginstance-icon",""),
|
||||
RunningInstanceRelated("Running Instances", "runninginstance-icon",""),
|
||||
|
||||
/****************************************
|
||||
* Models for SWEEPER
|
||||
***************************************/
|
||||
Sweeper_GHN("gCube Hosting Node", "ghn-icon"),
|
||||
Sweeper_RI("Running Instance", "runninginstance-icon"),
|
||||
Sweeper_RI_Orphan("Orphan Running Instance", "orphan-runninginstance-icon"),
|
||||
Sweeper_GHN_Expired("Expired gHN", "expired-ghn-icon"),
|
||||
Sweeper_GHN_Dead("Dead gHN", "dead-ghn-icon");
|
||||
|
||||
Sweeper_GHN("gCube Hosting Node", "ghn-icon",""),
|
||||
Sweeper_RI("Running Instance", "runninginstance-icon",""),
|
||||
Sweeper_RI_Orphan("Orphan Running Instance", "orphan-runninginstance-icon",""),
|
||||
Sweeper_GHN_Expired("Expired gHN", "expired-ghn-icon",""),
|
||||
Sweeper_GHN_Dead("Dead gHN", "dead-ghn-icon","");
|
||||
|
||||
|
||||
private String fwsName = null;
|
||||
private String label = null;
|
||||
private String icon = null;
|
||||
|
||||
ResourceTypeDecorator(
|
||||
final String label,
|
||||
final String icon) {
|
||||
ResourceTypeDecorator(final String label, final String icon, final String fwsName) {
|
||||
this.label = label;
|
||||
this.icon = icon;
|
||||
this.fwsName = fwsName;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
|
@ -80,4 +79,10 @@ public enum ResourceTypeDecorator {
|
|||
public String getIcon() {
|
||||
return this.icon;
|
||||
}
|
||||
|
||||
public String getFWSName() {
|
||||
if (this.fwsName == null || this.fwsName.equals(""))
|
||||
return this.label;
|
||||
return this.fwsName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,12 @@
|
|||
|
||||
package org.gcube.resourcemanagement.support.server.gcube;
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
|
@ -30,6 +33,8 @@ import java.util.Map;
|
|||
import java.util.StringTokenizer;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Templates;
|
||||
import javax.xml.transform.Transformer;
|
||||
|
@ -39,17 +44,16 @@ import javax.xml.transform.stream.StreamSource;
|
|||
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.informationsystem.client.ISClient;
|
||||
import org.gcube.common.core.informationsystem.client.QueryParameter;
|
||||
import org.gcube.common.core.informationsystem.client.XMLResult;
|
||||
import org.gcube.common.core.informationsystem.client.XMLResult.ISResultEvaluationException;
|
||||
import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericQuery;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.utils.logging.GCUBEClientLog;
|
||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.resourcemanagement.support.client.views.ResourceTypeDecorator;
|
||||
import org.gcube.resourcemanagement.support.server.gcube.queries.QueryLoader;
|
||||
import org.gcube.resourcemanagement.support.server.gcube.queries.QueryLocation;
|
||||
|
||||
|
||||
import org.gcube.resourcemanagement.support.server.managers.scope.ScopeManager;
|
||||
import org.gcube.resourcemanagement.support.server.utils.ServerConsole;
|
||||
import org.gcube.resourcemanagement.support.shared.plugins.GenericResourcePlugin;
|
||||
|
@ -57,10 +61,16 @@ import org.gcube.resourcemanagement.support.shared.plugins.TMPluginFormField;
|
|||
import org.gcube.resourcemanagement.support.shared.types.Tuple;
|
||||
import org.gcube.resourcemanagement.support.shared.types.datamodel.CompleteResourceProfile;
|
||||
import org.gcube.resourcemanagement.support.shared.types.datamodel.ResourceDescriptor;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
||||
import org.gcube.resources.discovery.client.queries.impl.QueryTemplate;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -78,43 +88,47 @@ public class ISClientRequester {
|
|||
CACHE.empty();
|
||||
}
|
||||
|
||||
private static final ArrayList<String> getResourceTypes(
|
||||
final CacheManager status,
|
||||
final GCUBEScope queryScope)
|
||||
throws Exception {
|
||||
List<XMLResult> results = null;
|
||||
ISClient client = GHNContext.getImplementation(ISClient.class);
|
||||
GCUBEGenericQuery isQuery = null;
|
||||
isQuery = client.getQuery(GCUBEGenericQuery.class);
|
||||
isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_TREE_TYPES));
|
||||
private static final ArrayList<String> getResourceTypes(final CacheManager status, final ScopeBean queryScope) throws Exception {
|
||||
|
||||
List<String> resultz = null;
|
||||
|
||||
//set the scope
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(queryScope.toString());
|
||||
|
||||
Query isQuery = new QueryBox(QueryLoader.getQuery(QueryLocation.GET_TREE_TYPES));
|
||||
DiscoveryClient<String> client = client();
|
||||
|
||||
// Handles the cache
|
||||
ISQueryCacheKeyT cacheKey = new ISQueryCacheKeyT(queryScope.toString(),
|
||||
isQuery.getExpression(),
|
||||
isQuery.expression(),
|
||||
"getResourcesTypes");
|
||||
|
||||
if (status.isUsingCache() && CACHE.contains(cacheKey) && CACHE.get(cacheKey) != null) {
|
||||
results = CACHE.get(cacheKey);
|
||||
resultz = CACHE.get(cacheKey);
|
||||
} else {
|
||||
try {
|
||||
results = client.execute(isQuery, queryScope);
|
||||
|
||||
resultz = client.submit(isQuery);
|
||||
if (status.isUsingCache()) {
|
||||
CACHE.insert(cacheKey, results);
|
||||
CACHE.insert(cacheKey, resultz);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new Exception(e.getMessage());
|
||||
}
|
||||
}
|
||||
if (results == null || results.size() == 0) {
|
||||
if (resultz == null || resultz.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String type = null;
|
||||
ArrayList<String> types = new ArrayList<String>();
|
||||
try {
|
||||
for (XMLResult elem : results) {
|
||||
|
||||
type = elem.evaluate("/type/text()").get(0);
|
||||
for (String elem : resultz) {
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Node node = docBuilder.parse(new InputSource(new StringReader(elem))).getDocumentElement();
|
||||
XPathHelper helper = new XPathHelper(node);
|
||||
type = helper.evaluate("/type/text()").get(0);
|
||||
if (type != null && type.trim().length() > 0) {
|
||||
types.add(type.trim());
|
||||
}
|
||||
|
@ -122,37 +136,39 @@ public class ISClientRequester {
|
|||
//**** CHANGES TO KNOW IF VIEWS AND GCUBECollection are present
|
||||
types.remove("MetadataCollection");
|
||||
|
||||
isQuery.setExpression("declare namespace vm = 'http://gcube-system.org/namespaces/contentmanagement/viewmanager';"+
|
||||
isQuery = new QueryBox("declare namespace vm = 'http://gcube-system.org/namespaces/contentmanagement/viewmanager';"+
|
||||
"declare namespace gc = 'http://gcube-system.org/namespaces/common/core/porttypes/GCUBEProvider';"+
|
||||
"declare namespace is = 'http://gcube-system.org/namespaces/informationsystem/registry';" +
|
||||
"for $data in collection(\"/db/Properties\")//Document, $view in $data/Data where $view/gc:ServiceName/string() eq \"ViewManager\" " +
|
||||
" and $view/gc:ServiceClass/string() eq \"ContentManagement\" and count($view//vm:View)>0 return <a>true</a>");
|
||||
|
||||
if (client.execute(isQuery, queryScope).size() > 0)
|
||||
if (client.submit(isQuery).size() > 0)
|
||||
types.add("VIEW");
|
||||
|
||||
isQuery.setExpression("declare namespace gc = 'http://gcube-system.org/namespaces/common/core/porttypes/GCUBEProvider';"+
|
||||
isQuery = new QueryBox("declare namespace gc = 'http://gcube-system.org/namespaces/common/core/porttypes/GCUBEProvider';"+
|
||||
"declare namespace is = 'http://gcube-system.org/namespaces/informationsystem/registry';" +
|
||||
"for $data in collection(\"/db/Profiles/GenericResource\")//Document/Data/is:Profile/Resource where $data/Profile/SecondaryType eq \"GCUBECollection\" " +
|
||||
" return <a>true</a>");
|
||||
|
||||
if (client.execute(isQuery, queryScope).size() > 0)
|
||||
if (client.submit(isQuery).size() > 0)
|
||||
types.add("Collection");
|
||||
|
||||
} catch (ISResultEvaluationException e) {
|
||||
_log.error("error during getResourcesTypes");
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
// ignore exception
|
||||
}
|
||||
|
||||
ScopeProvider.instance.set(currScope);
|
||||
return types;
|
||||
}
|
||||
|
||||
private static final ArrayList<String> getResourceSubTypes(
|
||||
final CacheManager status,
|
||||
final GCUBEScope queryScope,
|
||||
final String resourceType)
|
||||
throws Exception {
|
||||
/**
|
||||
*
|
||||
* @param status
|
||||
* @param queryScope
|
||||
* @param resourceType
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private static final ArrayList<String> getResourceSubTypes(final CacheManager status, final ScopeBean queryScope, final String resourceType) throws Exception {
|
||||
|
||||
ArrayList<String> subtypes = new ArrayList<String>();
|
||||
if (resourceType.equals("Collection")) {
|
||||
|
@ -165,52 +181,58 @@ public class ISClientRequester {
|
|||
return subtypes;
|
||||
}
|
||||
|
||||
List<XMLResult> results = null;
|
||||
ISClient client = GHNContext.getImplementation(ISClient.class);
|
||||
GCUBEGenericQuery isQuery = null;
|
||||
isQuery = client.getQuery(GCUBEGenericQuery.class);
|
||||
isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_TREE_SUBTYPES));
|
||||
|
||||
isQuery.addParameters(new QueryParameter("RES_TYPE", resourceType));
|
||||
List<String> resultz = null;
|
||||
|
||||
//set the scope
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(queryScope.toString());
|
||||
|
||||
QueryTemplate isQuery = new QueryTemplate(QueryLoader.getQuery(QueryLocation.GET_TREE_SUBTYPES));
|
||||
DiscoveryClient<String> client = client();
|
||||
|
||||
isQuery.addParameter("RES_TYPE", resourceType);
|
||||
isQuery.addParameter("SUBTYPE", "<subtype>{$subtype}</subtype>");
|
||||
|
||||
// Handles the cache
|
||||
ISQueryCacheKeyT cacheKey = new ISQueryCacheKeyT(queryScope.toString(),
|
||||
isQuery.getExpression(),
|
||||
isQuery.expression(),
|
||||
"getResourcesSubTypes");
|
||||
|
||||
if (status.isUsingCache() && CACHE.contains(cacheKey) && CACHE.get(cacheKey) != null) {
|
||||
results = CACHE.get(cacheKey);
|
||||
resultz = CACHE.get(cacheKey);
|
||||
} else {
|
||||
try {
|
||||
results = client.execute(isQuery, queryScope);
|
||||
resultz = client.submit(isQuery);
|
||||
if (status.isUsingCache()) {
|
||||
CACHE.insert(cacheKey, results);
|
||||
CACHE.insert(cacheKey, resultz);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new Exception(e.getMessage());
|
||||
}
|
||||
}
|
||||
if (results == null || results.size() == 0) {
|
||||
if (resultz == null || resultz.size() == 0)
|
||||
return null;
|
||||
}
|
||||
|
||||
String subtype = null;
|
||||
|
||||
for (XMLResult elem : results) {
|
||||
for (String elem : resultz) {
|
||||
try {
|
||||
subtype = elem.evaluate("/subtype/text()").get(0);
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Node node = docBuilder.parse(new InputSource(new StringReader(elem))).getDocumentElement();
|
||||
XPathHelper helper = new XPathHelper(node);
|
||||
String subtype = helper.evaluate("/subtype/text()").get(0);
|
||||
if (subtype != null && subtype.trim().length() > 0) {
|
||||
subtypes.add(subtype.trim());
|
||||
}
|
||||
} catch (ISResultEvaluationException e) {
|
||||
_log.error("error during getResourcesTypes");
|
||||
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
// ignore exception
|
||||
}
|
||||
}
|
||||
ScopeProvider.instance.set(currScope);
|
||||
return subtypes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For all the resource in the scope retrieves their
|
||||
* (type, subtype) values.
|
||||
|
@ -218,10 +240,7 @@ public class ISClientRequester {
|
|||
* @return a list of string tuples (type, subtype)
|
||||
* @throws Exception
|
||||
*/
|
||||
public static final HashMap<String, ArrayList<String>> getResourcesTree( //qui si perde
|
||||
final CacheManager status,
|
||||
final GCUBEScope queryScope)
|
||||
throws Exception {
|
||||
public static final HashMap<String, ArrayList<String>> getResourcesTree(final CacheManager status, final ScopeBean queryScope) throws Exception {
|
||||
HashMap<String, ArrayList<String>> retval = new HashMap<String, ArrayList<String>>();
|
||||
|
||||
// Loads the Resources
|
||||
|
@ -240,35 +259,32 @@ public class ISClientRequester {
|
|||
}
|
||||
|
||||
// Loads the WSResources
|
||||
// This types is statically handled since it is a particular
|
||||
// case of resource.
|
||||
List<XMLResult> results = null;
|
||||
ISClient client = GHNContext.getImplementation(ISClient.class);
|
||||
GCUBEGenericQuery isQuery = null;
|
||||
isQuery = client.getQuery(GCUBEGenericQuery.class);
|
||||
isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_WSRES_TYPES));
|
||||
results = client.execute(isQuery, queryScope);
|
||||
if (results == null || results.size() == 0) {
|
||||
// This types is statically handled since it is a particular case of resource.
|
||||
|
||||
|
||||
List<String> resultz = null;
|
||||
|
||||
//set the scope
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(queryScope.toString());
|
||||
|
||||
Query isQuery = new QueryBox(QueryLoader.getQuery(QueryLocation.GET_WSRES_TYPES));
|
||||
DiscoveryClient<String> client = client();
|
||||
|
||||
resultz = client.submit(isQuery);
|
||||
if (resultz == null || resultz.size() == 0) {
|
||||
return retval;
|
||||
}
|
||||
subtypes = new ArrayList<String>();
|
||||
for (XMLResult elem : results) {
|
||||
for (String elem : resultz) {
|
||||
subtypes.add(elem.toString());
|
||||
}
|
||||
retval.put("WSResource", subtypes);
|
||||
ScopeProvider.instance.set(currScope);
|
||||
return retval;
|
||||
}
|
||||
|
||||
public static final List<String> getRelatedResources(
|
||||
final CacheManager status,
|
||||
final String type,
|
||||
final String id,
|
||||
final GCUBEScope queryScope)
|
||||
throws Exception {
|
||||
ISClient client = GHNContext.getImplementation(ISClient.class);
|
||||
GCUBEGenericQuery isQuery = null;
|
||||
isQuery = client.getQuery(GCUBEGenericQuery.class);
|
||||
|
||||
public static final List<String> getRelatedResources(final CacheManager status, final String type, final String id, final ScopeBean queryScope) throws Exception {
|
||||
QueryLocation queryPath = null;
|
||||
try {
|
||||
queryPath = QueryLocation.valueOf("LIST_RELATED_" + type);
|
||||
|
@ -276,31 +292,38 @@ public class ISClientRequester {
|
|||
ServerConsole.error(LOG_PREFIX, "Getting the resource query.", e);
|
||||
throw new Exception(e.getMessage());
|
||||
}
|
||||
isQuery.setExpression(QueryLoader.getQuery(queryPath));
|
||||
isQuery.addParameters(new QueryParameter("RES_ID", id.trim()));
|
||||
|
||||
ISQueryCacheKeyT cacheKey = new ISQueryCacheKeyT(queryScope.toString(),
|
||||
isQuery.getExpression(),
|
||||
"getResourceRelated");
|
||||
//set the scope
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(queryScope.toString());
|
||||
|
||||
List<XMLResult> results = null;
|
||||
QueryTemplate isQuery = new QueryTemplate(QueryLoader.getQuery(queryPath));
|
||||
DiscoveryClient<String> client = client();
|
||||
|
||||
isQuery.addParameter("RES_ID", id.trim());
|
||||
|
||||
|
||||
|
||||
ISQueryCacheKeyT cacheKey = new ISQueryCacheKeyT(queryScope.toString(), isQuery.expression(), "getResourceRelated");
|
||||
|
||||
List<String> resultz = null;
|
||||
// Handle cache
|
||||
if (status.isUsingCache() && CACHE.contains(cacheKey) && CACHE.get(cacheKey) != null) {
|
||||
results = CACHE.get(cacheKey);
|
||||
resultz = CACHE.get(cacheKey);
|
||||
} else {
|
||||
results = client.execute(isQuery, queryScope);
|
||||
resultz = client.submit(isQuery);
|
||||
if (status.isUsingCache()) {
|
||||
CACHE.insert(cacheKey, results);
|
||||
CACHE.insert(cacheKey, resultz);
|
||||
}
|
||||
}
|
||||
if (results == null || results.size() == 0) {
|
||||
if (resultz == null || resultz.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
// ENDOF Handle cache
|
||||
|
||||
List<String> retval = new Vector<String>();
|
||||
List<String> retval = new ArrayList<String>();
|
||||
|
||||
for (XMLResult elem : results) {
|
||||
for (String elem : resultz) {
|
||||
// Removes the resources with no ID or empty
|
||||
try {
|
||||
String toAdd = elem.toString();
|
||||
|
@ -313,71 +336,83 @@ public class ISClientRequester {
|
|||
ServerConsole.debug(LOG_PREFIX, "[getResourcesRelated] found and invalid resource");
|
||||
}
|
||||
}
|
||||
//ServerConsole.trace(LOG_PREFIX, "Retrieved (" + retval.size() + ") ServiceDetails for type: " + type);
|
||||
ScopeProvider.instance.set(currScope);
|
||||
ServerConsole.trace(LOG_PREFIX, "Retrieved (" + retval.size() + ") ServiceDetails for type: " + type);
|
||||
return retval;
|
||||
}
|
||||
|
||||
public static final List<String> getResourcesByType(
|
||||
final CacheManager status,
|
||||
final GCUBEScope queryScope,
|
||||
final String type,
|
||||
final String subType)
|
||||
throws Exception {
|
||||
ISClient client = GHNContext.getImplementation(ISClient.class);
|
||||
GCUBEGenericQuery isQuery = null;
|
||||
isQuery = client.getQuery(GCUBEGenericQuery.class);
|
||||
/**
|
||||
*
|
||||
* @param status
|
||||
* @param queryScope
|
||||
* @param type
|
||||
* @param subType
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static final List<String> getResourcesByType(final CacheManager status, final ScopeBean queryScope, final String type, final String subType) throws Exception {
|
||||
|
||||
QueryLocation queryPath = null;
|
||||
QueryLocation returnPath = null;
|
||||
try {
|
||||
if (type.equals(ResourceTypeDecorator.WSResource.name())) {
|
||||
queryPath = QueryLocation.GET_WSRES_DETAILS_BYSUBTYPE;
|
||||
} else {
|
||||
queryPath = QueryLocation.valueOf("LIST_" + type);
|
||||
returnPath = QueryLocation.valueOf("RETURN_" + type);
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ServerConsole.error(LOG_PREFIX, "Getting the resource query.", e);
|
||||
throw new Exception(e.getMessage());
|
||||
}
|
||||
|
||||
isQuery.setExpression(QueryLoader.getQuery(queryPath));
|
||||
//set the scope
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(queryScope.toString());
|
||||
|
||||
QueryTemplate isQuery = new QueryTemplate(QueryLoader.getQuery(queryPath));
|
||||
DiscoveryClient<String> client = client();
|
||||
|
||||
if (type.equals(ResourceTypeDecorator.WSResource.name())) {
|
||||
if (subType != null && subType.length() > 0) {
|
||||
isQuery.addParameters(new QueryParameter("RES_SUBTYPE",
|
||||
subType.trim()));
|
||||
isQuery.addParameter("RES_SUBTYPE", subType.trim());
|
||||
}
|
||||
} else {
|
||||
if (subType != null && subType.length() > 0) {
|
||||
if (subType.equalsIgnoreCase("User") || subType.equalsIgnoreCase("System")) {
|
||||
isQuery.addParameters(new QueryParameter("RES_SUBTYPE", " and $profiles/Profile/Body/CollectionInfo/user/text() = \"" + ((subType.trim().equals("User")) ? "true" : "false") + "\""));
|
||||
isQuery.addParameter("RES_SUBTYPE", " and $profiles/Profile/Body/CollectionInfo/user/text() = \"" + ((subType.trim().equals("User")) ? "true" : "false") + "\"");
|
||||
}
|
||||
else
|
||||
isQuery.addParameters(new QueryParameter("RES_SUBTYPE", "where $subtype = \"" + subType.trim() + "\""));
|
||||
isQuery.addParameter("RES_SUBTYPE", "where $subtype = \"" + subType.trim() + "\"");
|
||||
}
|
||||
}
|
||||
//add the return statement
|
||||
isQuery.addParameter("RESOURCE", QueryLoader.getQuery(returnPath));
|
||||
|
||||
ISQueryCacheKeyT cacheKey = new ISQueryCacheKeyT(queryScope.toString(),
|
||||
isQuery.getExpression(),
|
||||
"getResourcesTypes");
|
||||
ISQueryCacheKeyT cacheKey = new ISQueryCacheKeyT(queryScope.toString(), isQuery.expression(), "getResourcesTypes");
|
||||
|
||||
List<XMLResult> results = null;
|
||||
List<String> resultz = null;
|
||||
|
||||
if (status.isUsingCache() && CACHE.contains(cacheKey) && CACHE.get(cacheKey) != null) {
|
||||
results = CACHE.get(cacheKey);
|
||||
resultz = CACHE.get(cacheKey);
|
||||
} else {
|
||||
results = client.execute(isQuery, queryScope);
|
||||
resultz = client.submit(isQuery);
|
||||
if (status.isUsingCache()) {
|
||||
CACHE.insert(cacheKey, results);
|
||||
CACHE.insert(cacheKey, resultz);
|
||||
}
|
||||
}
|
||||
if (results == null || results.size() == 0) {
|
||||
if (resultz == null || resultz.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
List<String> retval = new Vector<String>();
|
||||
|
||||
for (XMLResult elem : results) {
|
||||
for (String elem : resultz) {
|
||||
// Removes the resources with no ID or empty
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Node node = docBuilder.parse(new InputSource(new StringReader(elem))).getDocumentElement();
|
||||
XPathHelper helper = new XPathHelper(node);
|
||||
try {
|
||||
if (elem.evaluate("//ID").get(0) != null && elem.evaluate("//ID").get(0).trim().length() > 0) {
|
||||
if (helper.evaluate("//ID").get(0) != null && helper.evaluate("//ID").get(0).trim().length() > 0) {
|
||||
retval.add(elem.toString());
|
||||
//ServerConsole.debug("", elem.toString());// Print the result
|
||||
} else {
|
||||
|
@ -389,45 +424,54 @@ public class ISClientRequester {
|
|||
}
|
||||
}
|
||||
//ServerConsole.trace(LOG_PREFIX, "Retrieved (" + retval.size() + ") ServiceDetails for type: " + type);
|
||||
ScopeProvider.instance.set(currScope);
|
||||
return retval;
|
||||
}
|
||||
/**
|
||||
* @param queryScope
|
||||
* @param type
|
||||
* @param subType
|
||||
* @param additionalMaps
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static final List<ResourceDescriptor> getResourceModels(final ScopeBean queryScope, final String type, final String subType, final List<Tuple<String>> additionalMaps) throws Exception {
|
||||
|
||||
//set the scope
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(queryScope.toString());
|
||||
|
||||
QueryTemplate isQuery = null;
|
||||
DiscoveryClient<String> client = client();
|
||||
|
||||
public static final List<ResourceDescriptor> getResourceModels(
|
||||
final GCUBEScope queryScope,
|
||||
final String type,
|
||||
final String subType,
|
||||
final List<Tuple<String>> additionalMaps)
|
||||
throws Exception {
|
||||
ISClient client = GHNContext.getImplementation(ISClient.class);
|
||||
GCUBEGenericQuery isQuery = null;
|
||||
isQuery = client.getQuery(GCUBEGenericQuery.class);
|
||||
if (subType != null && subType.trim().length() > 0) {
|
||||
isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_RES_DETAILS_BYSUBTYPE));
|
||||
isQuery.addParameters(
|
||||
new QueryParameter("RES_TYPE", type)
|
||||
);
|
||||
isQuery.addParameters(
|
||||
new QueryParameter("RES_SUBTYPE", subType)
|
||||
);
|
||||
isQuery = new QueryTemplate(QueryLoader.getQuery(QueryLocation.GET_RES_DETAILS_BYSUBTYPE));
|
||||
isQuery.addParameter("RES_TYPE", type.trim());
|
||||
isQuery.addParameter("RES_SUBTYPE", subType.trim());
|
||||
//add the return statement
|
||||
isQuery.addParameter("RESOURCE", QueryLoader.getQuery(QueryLocation.RETURN_GET_RES_DETAILS_BYSUBTYPE));
|
||||
} else {
|
||||
isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_RES_DETAILS_BYTYPE));
|
||||
isQuery.addParameters(
|
||||
new QueryParameter("RES_TYPE", type)
|
||||
);
|
||||
isQuery = new QueryTemplate(QueryLoader.getQuery(QueryLocation.GET_RES_DETAILS_BYTYPE));
|
||||
isQuery.addParameter("RES_TYPE", type);
|
||||
isQuery.addParameter("RESOURCE", QueryLoader.getQuery(QueryLocation.RETURN_GET_RES_DETAILS_BYTYPE));
|
||||
}
|
||||
List<XMLResult> results = client.execute(isQuery, queryScope);
|
||||
List<String> resultz = client.submit(isQuery);
|
||||
|
||||
List<ResourceDescriptor> retval = new Vector<ResourceDescriptor>();
|
||||
ResourceDescriptor toAdd = null;
|
||||
for (XMLResult elem : results) {
|
||||
for (String elem : resultz) {
|
||||
// Removes the resources with no ID or empty
|
||||
try {
|
||||
if (elem.evaluate("//ID").get(0) != null) {
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Node node = docBuilder.parse(new InputSource(new StringReader(elem))).getDocumentElement();
|
||||
XPathHelper helper = new XPathHelper(node);
|
||||
|
||||
if (helper.evaluate("//ID").get(0) != null) {
|
||||
toAdd = new ResourceDescriptor(
|
||||
elem.evaluate("//Type/text()").get(0),
|
||||
elem.evaluate("//SubType/text()").get(0),
|
||||
elem.evaluate("//ID/text()").get(0),
|
||||
elem.evaluate("//Name/text()").get(0));
|
||||
helper.evaluate("//Type/text()").get(0),
|
||||
helper.evaluate("//SubType/text()").get(0),
|
||||
helper.evaluate("//ID/text()").get(0),
|
||||
helper.evaluate("//Name/text()").get(0));
|
||||
|
||||
// Additional mappings can be defined by the requester.
|
||||
// e.g. new Tuple("description", "//Profile/Description/text()");
|
||||
|
@ -435,7 +479,7 @@ public class ISClientRequester {
|
|||
for (Tuple<String> map : additionalMaps) {
|
||||
try {
|
||||
toAdd.addProperty(map.get(0),
|
||||
elem.evaluate(map.get(1)).get(0));
|
||||
helper.evaluate(map.get(1)).get(0));
|
||||
} catch (final Exception e) {
|
||||
toAdd.addProperty(map.get(0),
|
||||
"");
|
||||
|
@ -450,55 +494,68 @@ public class ISClientRequester {
|
|||
}
|
||||
}
|
||||
//ServerConsole.trace(LOG_PREFIX, "Retrieved (" + retval.size() + ") ServiceDetails for type: " + type);
|
||||
ScopeProvider.instance.set(currScope);
|
||||
return retval;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param queryScope
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static final List<String> getWSResources(final ScopeBean queryScope) throws Exception {
|
||||
|
||||
|
||||
public static final List<String> getWSResources(
|
||||
final GCUBEScope queryScope)
|
||||
throws Exception {
|
||||
ISClient client = GHNContext.getImplementation(ISClient.class);
|
||||
GCUBEGenericQuery isQuery = null;
|
||||
isQuery = client.getQuery(GCUBEGenericQuery.class);
|
||||
isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_WSRES_DETAILS_BYTYPE));
|
||||
List<XMLResult> results = client.execute(isQuery, queryScope);
|
||||
List<String> resultz = null;
|
||||
|
||||
//set the scope
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(queryScope.toString());
|
||||
|
||||
Query isQuery = new QueryBox(QueryLoader.getQuery(QueryLocation.GET_WSRES_DETAILS_BYTYPE));
|
||||
DiscoveryClient<String> client = client();
|
||||
|
||||
List<String> retval = new Vector<String>();
|
||||
resultz = client.submit(isQuery);
|
||||
|
||||
for (XMLResult elem : results) {
|
||||
for (String elem : resultz) {
|
||||
retval.add(elem.toString());
|
||||
}
|
||||
//ServerConsole.trace(LOG_PREFIX, "Retrieved (" + retval.size() + ") ServiceDetails for type: " + ResourceTypeDecorator.WSResource.name());
|
||||
ScopeProvider.instance.set(currScope);
|
||||
return retval;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param xmlFilePath
|
||||
* @param queryScope
|
||||
* @param resType
|
||||
* @param resID
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static final CompleteResourceProfile getResourceByID(String xmlFilePath, ScopeBean queryScope, String resType, String resID) throws Exception {
|
||||
|
||||
//set the scope
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(queryScope.toString());
|
||||
|
||||
QueryTemplate isQuery = null;
|
||||
DiscoveryClient<String> client = client();
|
||||
|
||||
|
||||
public static final CompleteResourceProfile getResourceByID(
|
||||
final String xmlFilePath,
|
||||
final GCUBEScope queryScope,
|
||||
final String resType,
|
||||
final String resID)
|
||||
throws Exception {
|
||||
ISClient client = GHNContext.getImplementation(ISClient.class);
|
||||
GCUBEGenericQuery isQuery = null;
|
||||
isQuery = client.getQuery(GCUBEGenericQuery.class);
|
||||
if (resType == null) {
|
||||
isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_RESOURCE_BYID));
|
||||
isQuery.addParameters(
|
||||
new QueryParameter("RES_ID", resID)
|
||||
);
|
||||
isQuery = new QueryTemplate(QueryLoader.getQuery(QueryLocation.GET_RESOURCE_BYID));
|
||||
isQuery.addParameter("RES_ID", resID);
|
||||
} else if (resType.equalsIgnoreCase(ResourceTypeDecorator.WSResource.name())) {
|
||||
isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_WSRESOURCE_BYID));
|
||||
isQuery.addParameters(
|
||||
new QueryParameter("RES_ID", resID)
|
||||
);
|
||||
isQuery = new QueryTemplate(QueryLoader.getQuery(QueryLocation.GET_WSRESOURCE_BYID));
|
||||
isQuery.addParameter("RES_ID", resID);
|
||||
} else {
|
||||
isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_RESOURCE_BYID));
|
||||
isQuery.addParameters(
|
||||
new QueryParameter("RES_ID", resID),
|
||||
new QueryParameter("RES_TYPE", resType)
|
||||
);
|
||||
isQuery = new QueryTemplate(QueryLoader.getQuery(QueryLocation.GET_RESOURCE_BYID));
|
||||
isQuery.addParameter("RES_ID", resID);
|
||||
isQuery.addParameter("RES_TYPE", resType);
|
||||
}
|
||||
List<XMLResult> results = client.execute(isQuery, queryScope);
|
||||
List<String> results = client.submit(isQuery);
|
||||
|
||||
|
||||
//ServerConsole.trace(LOG_PREFIX, "Retrieved (" + retval.size() + ") Resource for ID: " + resID);
|
||||
|
@ -507,7 +564,10 @@ public class ISClientRequester {
|
|||
String type = null;
|
||||
if (resType == null) {
|
||||
try {
|
||||
type = results.get(0).evaluate("/Resource/Type/text()").get(0);
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Node node = docBuilder.parse(new InputSource(new StringReader(results.get(0)))).getDocumentElement();
|
||||
XPathHelper helper = new XPathHelper(node);
|
||||
type = helper.evaluate("/Resource/Type/text()").get(0);
|
||||
} catch (Exception e) {
|
||||
ServerConsole.error(LOG_PREFIX, e);
|
||||
}
|
||||
|
@ -516,8 +576,10 @@ public class ISClientRequester {
|
|||
}
|
||||
String xmlRepresentation = results.get(0).toString();
|
||||
String htmlRepresentation = XML2HTML(xmlRepresentation, xmlFilePath);
|
||||
ScopeProvider.instance.set(currScope);
|
||||
return new CompleteResourceProfile(resID, ResourceTypeDecorator.valueOf(type), getResourceName(type, resID, results.get(0)), xmlRepresentation, htmlRepresentation);
|
||||
}
|
||||
ScopeProvider.instance.set(currScope);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -683,12 +745,12 @@ public class ISClientRequester {
|
|||
formFields = getPluginFormFromXml(xmlToParse);
|
||||
}
|
||||
}
|
||||
// if (params.getLength()>1)
|
||||
// if (params.getLength()>1)
|
||||
retval.put(name + ":" + requestName, formFields);
|
||||
|
||||
}
|
||||
if (foundRequest == false){
|
||||
retval.put(name, formFields);
|
||||
retval.put(name, formFields);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -762,69 +824,80 @@ public class ISClientRequester {
|
|||
* @param ID the identifier of the resource
|
||||
* @param node the XML node from which retrieve the information
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @throws SAXException
|
||||
*/
|
||||
private static String getResourceName(String type, String ID, XMLResult node) {
|
||||
private static String getResourceName(String type, String ID, String node) throws Exception {
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Node xnode = docBuilder.parse(new InputSource(new StringReader(node))).getDocumentElement();
|
||||
XPathHelper helper = new XPathHelper(xnode);
|
||||
|
||||
if (type.equalsIgnoreCase(ResourceTypeDecorator.GHN.name())) {
|
||||
try {
|
||||
return node.evaluate("/Resource/Profile/GHNDescription/Name/text()").get(0);
|
||||
return helper.evaluate("/Resource/Profile/GHNDescription/Name/text()").get(0);
|
||||
} catch (Exception e) {
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
if (type.equalsIgnoreCase(ResourceTypeDecorator.Collection.name())) {
|
||||
try {
|
||||
return node.evaluate("/Resource/Profile/Name/text()").get(0);
|
||||
return helper.evaluate("/Resource/Profile/Name/text()").get(0);
|
||||
} catch (Exception e) {
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
if (type.equalsIgnoreCase(ResourceTypeDecorator.Service.name())) {
|
||||
try {
|
||||
return node.evaluate("/Resource/Profile/Name/text()").get(0);
|
||||
return helper.evaluate("/Resource/Profile/Name/text()").get(0);
|
||||
} catch (Exception e) {
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
if (type.equalsIgnoreCase(ResourceTypeDecorator.RunningInstance.name())) {
|
||||
try {
|
||||
return node.evaluate("/Resource/Profile/ServiceName/text()").get(0);
|
||||
return helper.evaluate("/Resource/Profile/ServiceName/text()").get(0);
|
||||
} catch (Exception e) {
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
if (type.equalsIgnoreCase(ResourceTypeDecorator.VIEW.name())) {
|
||||
try {
|
||||
return node.evaluate("/Resource/Profile/Name/text()").get(0);
|
||||
return helper.evaluate("/Resource/Profile/Name/text()").get(0);
|
||||
} catch (Exception e) {
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
if (type.equalsIgnoreCase(ResourceTypeDecorator.RuntimeResource.name())) {
|
||||
try {
|
||||
return node.evaluate("/Resource/Profile/Name/text()").get(0);
|
||||
return helper.evaluate("/Resource/Profile/Name/text()").get(0);
|
||||
} catch (Exception e) {
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
if (type.equalsIgnoreCase(ResourceTypeDecorator.GenericResource.name())) {
|
||||
try {
|
||||
return node.evaluate("/Resource/Profile/Name/text()").get(0);
|
||||
return helper.evaluate("/Resource/Profile/Name/text()").get(0);
|
||||
} catch (Exception e) {
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
if (type.equalsIgnoreCase(ResourceTypeDecorator.WSResource.name())) {
|
||||
try {
|
||||
return node.evaluate("/Document/Data/child::*[local-name()='ServiceName']/text()").get(0);
|
||||
return helper.evaluate("/Document/Data/child::*[local-name()='ServiceName']/text()").get(0);
|
||||
} catch (Exception e) {
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String XML2HTML(final String xml, final String xslt)
|
||||
throws Exception {
|
||||
/**
|
||||
* transform an xml in a readable xml by using HTML
|
||||
* @param xml
|
||||
* @param xslt
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String XML2HTML(final String xml, final String xslt) throws Exception {
|
||||
TransformerFactory tf = TransformerFactory.newInstance();
|
||||
|
||||
InputStream stream = new FileInputStream(xslt);
|
||||
|
|
|
@ -67,9 +67,9 @@ class ISQueryCacheKeyT {
|
|||
*
|
||||
*/
|
||||
public class ISQueryCache {
|
||||
Map<ISQueryCacheKeyT, List<XMLResult>> results = new HashMap<ISQueryCacheKeyT, List<XMLResult>>();
|
||||
Map<ISQueryCacheKeyT, List<String>> results = new HashMap<ISQueryCacheKeyT, List<String>>();
|
||||
|
||||
public void insert(ISQueryCacheKeyT key, List<XMLResult> elem) {
|
||||
public void insert(ISQueryCacheKeyT key, List<String> elem) {
|
||||
this.results.put(key, elem);
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ public class ISQueryCache {
|
|||
return this.results.containsKey(key);
|
||||
}
|
||||
|
||||
public List<XMLResult> get(ISQueryCacheKeyT key) {
|
||||
public List<String> get(ISQueryCacheKeyT key) {
|
||||
if (key != null && this.results.containsKey(key)) {
|
||||
return this.results.get(key);
|
||||
}
|
||||
|
|
|
@ -33,12 +33,18 @@ public enum QueryLocation {
|
|||
// Customized queries to retrieve the relevant data from resources
|
||||
// according to their type
|
||||
LIST_GHN("resources/GHN.xq"),
|
||||
RETURN_GHN("resources/RETURN_GHN.xq"),
|
||||
LIST_Collection("resources/Collection.xq"),
|
||||
RETURN_Collection("resources/RETURN_Collection.xq"),
|
||||
LIST_VIEW("resources/VIEW.xq"),
|
||||
LIST_Service("resources/Service.xq"),
|
||||
RETURN_Service("resources/RETURN_Service.xq"),
|
||||
LIST_GenericResource("resources/GenericResource.xq"),
|
||||
RETURN_GenericResource("resources/RETURN_GenericResource.xq"),
|
||||
LIST_RunningInstance("resources/RunningInstance.xq"),
|
||||
RETURN_RunningInstance("resources/RETURN_RunningInstance.xq"),
|
||||
LIST_RuntimeResource("resources/RuntimeResource.xq"),
|
||||
RETURN_RuntimeResource("resources/RETURN_RuntimeResource.xq"),
|
||||
|
||||
// To retrieve the list of generic resources publishing plugins
|
||||
// to deploy activation records
|
||||
|
@ -60,7 +66,9 @@ public enum QueryLocation {
|
|||
// Used to build the gwt model representation inside dialogs.
|
||||
// see getResourceModels inside ISClientRequester.
|
||||
GET_RES_DETAILS_BYTYPE("getResourcesDetails.xq"),
|
||||
RETURN_GET_RES_DETAILS_BYTYPE("RETURN_getResourcesDetails.xq"),
|
||||
GET_RES_DETAILS_BYSUBTYPE("getResourcesDetailsSubtype.xq"),
|
||||
RETURN_GET_RES_DETAILS_BYSUBTYPE("RETURN_getResourcesDetailsSubtype.xq"),
|
||||
|
||||
GET_RESOURCE_BYID("getResourceByID.xq"),
|
||||
GET_WSRES_TYPES("getWSResourcesTypes.xq"),
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<Resource>
|
||||
{$profiles//Resource/child::*}
|
||||
<SubType>{$subtype}</SubType>
|
||||
<gcf-version>{$gcf-version}</gcf-version>
|
||||
<ghn-version>{$ghn-version}</ghn-version>
|
||||
<scopes>{$scopes}</scopes>
|
||||
<ghn-name>{$ghn-name}</ghn-name>
|
||||
</Resource>
|
|
@ -0,0 +1,8 @@
|
|||
<Resource>
|
||||
{$profiles//Resource/child::*}
|
||||
<SubType>{$subtype}</SubType>
|
||||
<gcf-version>{$gcf-version}</gcf-version>
|
||||
<ghn-version>{$ghn-version}</ghn-version>
|
||||
<scopes>{$scopes}</scopes>
|
||||
<ghn-name>{$ghn-name}</ghn-name>
|
||||
</Resource>
|
|
@ -1,8 +1,3 @@
|
|||
#
|
||||
# Params: RES_ID the ID of looked up resource
|
||||
# RES_TYPE (option) the type of searched resource
|
||||
|
||||
|
||||
for $resource in collection('/db/Profiles/<RES_TYPE ISdefault =''>')//Resource
|
||||
for $resource in collection('/db/Profiles/<RES_TYPE ISdefault ='' />')//Resource
|
||||
where $resource/ID/string() eq '<RES_ID/>'
|
||||
return $resource
|
|
@ -4,7 +4,7 @@
|
|||
# RES_TYPE the main type of the resource
|
||||
# This query is used by forms
|
||||
|
||||
for $profiles in collection('/db/Profiles/<RES_TYPE ISdefault ='GHN'>')//Resource
|
||||
for $profiles in collection('/db/Profiles/<RES_TYPE ISdefault ='GHN' />')//Resource
|
||||
let $ghn-name := $profiles//Resource/Profile/GHN/@UniqueID/string()
|
||||
let $gcf-version := $profiles//Resource/Profile/GHNDescription/RunTimeEnv/Variable[Key/text() = 'gCF-version']/Value/text()
|
||||
let $ghn-version := $profiles//Resource/Profile/GHNDescription/RunTimeEnv/Variable[Key/text() = 'GHN-distribution-version']/Value/text()
|
||||
|
@ -26,11 +26,4 @@ let $subtype :=
|
|||
then "System"
|
||||
else ""
|
||||
return
|
||||
<Resource>
|
||||
{$profiles//Resource/child::*}
|
||||
<SubType>{$subtype}</SubType>
|
||||
<gcf-version>{$gcf-version}</gcf-version>
|
||||
<ghn-version>{$ghn-version}</ghn-version>
|
||||
<scopes>{$scopes}</scopes>
|
||||
<ghn-name>{$ghn-name}</ghn-name>
|
||||
</Resource>
|
||||
<RESOURCE/>
|
|
@ -4,7 +4,7 @@
|
|||
# RES_TYPE the main type of the resource
|
||||
# This query is used by forms
|
||||
|
||||
for $profiles in collection('/db/Profiles/<RES_TYPE ISdefault ='GHN'>')//Resource
|
||||
for $profiles in collection('/db/Profiles/<RES_TYPE ISdefault ='GHN' />')//Resource
|
||||
let $ghn-name := $profiles//Resource/Profile/GHN/@UniqueID/string()
|
||||
let $gcf-version := $profiles//Resource/Profile/GHNDescription/RunTimeEnv/Variable[Key/text() = 'gCF-version']/Value/text()
|
||||
let $ghn-version := $profiles//Resource/Profile/GHNDescription/RunTimeEnv/Variable[Key/text() = 'GHN-distribution-version']/Value/text()
|
||||
|
@ -27,11 +27,4 @@ let $subtype :=
|
|||
else ""
|
||||
where $subtype eq '<RES_SUBTYPE ISdefault='isti.cnr.it'/>'
|
||||
return
|
||||
<Resource>
|
||||
{$profiles//Resource/child::*}
|
||||
<SubType>{$subtype}</SubType>
|
||||
<gcf-version>{$gcf-version}</gcf-version>
|
||||
<ghn-version>{$ghn-version}</ghn-version>
|
||||
<scopes>{$scopes}</scopes>
|
||||
<ghn-name>{$ghn-name}</ghn-name>
|
||||
</Resource>
|
||||
<RESOURCE/>
|
|
@ -24,4 +24,4 @@ let $subtypes :=
|
|||
-->
|
||||
for $subtype in distinct-values($subtypes)
|
||||
return
|
||||
<subtype>{$subtype}</subtype>
|
||||
<SUBTYPE/>
|
|
@ -1,23 +1,8 @@
|
|||
<!--
|
||||
RES_SUBTYPE subtype parameters can be passed by expressing:
|
||||
|
||||
where $subtype = "TheSubType" and $wsresource/Data//child::*[local-name()='Type'][0]/string() eq 'gDocRead'
|
||||
-->
|
||||
|
||||
for $profiles in collection('/db/Profiles/GenericResource')//Resource, $wsresource in collection('/db/Properties')//Document
|
||||
let $scopes := string-join( $profiles/Scopes//Scope/text(), ';')
|
||||
let $subtype := $profiles//Resource/Profile/SecondaryType/text()
|
||||
where $subtype = "DataSource" and $profiles//Resource/ID eq $wsresource/SourceKey and $wsresource/Data//child::*[local-name()='ServiceName']/string() eq 'tree-manager-service'
|
||||
<RES_SUBTYPE ISdefault =''/>
|
||||
return
|
||||
<Resource>
|
||||
{$profiles//Resource/ID}
|
||||
<Type>{$profiles//Resource/Type/text()}</Type>
|
||||
<SubType>{$subtype}</SubType>
|
||||
<Scopes>{$scopes}</Scopes>
|
||||
<Name>{$profiles//Resource/Profile/Name/text()}</Name>
|
||||
<CreationTime>{$profiles//Resource/Profile/Body/SourceProperties/creationTime/text()}</CreationTime>
|
||||
<UserCollection>{$profiles//Resource/Profile/Body/SourceProperties/user/text()}</UserCollection>
|
||||
<LastUpdateTime>{$wsresource/LastUpdateHuman/text()}</LastUpdateTime>
|
||||
<NumberOfMembers>{$wsresource//child::*[local-name()='Cardinality']/text()}</NumberOfMembers>
|
||||
</Resource>
|
||||
<RESOURCE/>
|
||||
|
|
@ -1,8 +1,3 @@
|
|||
<!--
|
||||
gets the compressed description of all GHNs published in a scope
|
||||
-->
|
||||
|
||||
|
||||
for $profiles in collection('/db/Profiles/GHN')//Resource
|
||||
let $gcf-version := $profiles//Resource/Profile/GHNDescription/RunTimeEnv/Variable[Key/text() = 'gCF-version']/Value/text()
|
||||
let $ghn-version := $profiles//Resource/Profile/GHNDescription/RunTimeEnv/Variable[Key/text() = 'GHN-distribution-version']/Value/text()
|
||||
|
@ -10,21 +5,4 @@ let $scopes := string-join( $profiles/Scopes//Scope/text(), ';')
|
|||
let $subtype := $profiles//Resource/Profile/Site/Domain/text()
|
||||
<RES_SUBTYPE ISdefault =''/>
|
||||
return
|
||||
<Resource>
|
||||
{$profiles//Resource/ID}
|
||||
<Type>{$profiles//Resource/Type/text()}</Type>
|
||||
<SubType>{$subtype}</SubType>
|
||||
<Status>{$profiles//Resource/Profile/GHNDescription/Status/text()}</Status>
|
||||
<Name>{$profiles//Resource/Profile/GHNDescription/Name/text()}</Name>
|
||||
<Uptime>{$profiles//Resource/Profile/GHNDescription/Uptime/text()}</Uptime>
|
||||
<LastUpdate>{$profiles//Resource/Profile/GHNDescription/LastUpdate/text()}</LastUpdate>
|
||||
<LocalAvailableSpace>{$profiles//Resource/Profile/GHNDescription/LocalAvailableSpace/text()}</LocalAvailableSpace>
|
||||
<VirtualSize>{$profiles//Resource/Profile/GHNDescription/MainMemory/string(@VirtualSize)}</VirtualSize>
|
||||
<VirtualAvailable>{$profiles//Resource/Profile/GHNDescription/MainMemory/string(@VirtualAvailable)}</VirtualAvailable>
|
||||
<LoadLast1Min>{$profiles//Resource/Profile/GHNDescription/Load/string(@Last1Min)}</LoadLast1Min>
|
||||
<LoadLast5Min>{$profiles//Resource/Profile/GHNDescription/Load/string(@Last5Min)}</LoadLast5Min>
|
||||
<LoadLast15Min>{$profiles//Resource/Profile/GHNDescription/Load/string(@Last15Min)}</LoadLast15Min>
|
||||
<gcf-version>{$gcf-version}</gcf-version>
|
||||
<ghn-version>{$ghn-version}</ghn-version>
|
||||
<Scopes>{$scopes}</Scopes>
|
||||
</Resource>
|
||||
<RESOURCE/>
|
||||
|
|
|
@ -1,16 +1,6 @@
|
|||
|
||||
|
||||
|
||||
for $profiles in collection('/db/Profiles/GenericResource')//Resource
|
||||
let $scopes := string-join( $profiles/Scopes//Scope/text(), ';')
|
||||
let $subtype := $profiles//Resource/Profile/SecondaryType/text()
|
||||
<RES_SUBTYPE ISdefault =''/>
|
||||
return
|
||||
<Resource>
|
||||
{$profiles//Resource/ID}
|
||||
<Type>{$profiles//Resource/Type/text()}</Type>
|
||||
<SubType>{$subtype}</SubType>
|
||||
<Scopes>{$scopes}</Scopes>
|
||||
<Name>{$profiles//Resource/Profile/Name/text()}</Name>
|
||||
<Description>{$profiles//Resource/Profile/Description/text()}</Description>
|
||||
</Resource>
|
||||
<RESOURCE/>
|
|
@ -0,0 +1,11 @@
|
|||
<Resource>
|
||||
{$profiles//Resource/ID}
|
||||
<Type>{$profiles//Resource/Type/text()}</Type>
|
||||
<SubType>{$subtype}</SubType>
|
||||
<Scopes>{$scopes}</Scopes>
|
||||
<Name>{$profiles//Resource/Profile/Name/text()}</Name>
|
||||
<CreationTime>{$profiles//Resource/Profile/Body/SourceProperties/creationTime/text()}</CreationTime>
|
||||
<UserCollection>{$profiles//Resource/Profile/Body/SourceProperties/user/text()}</UserCollection>
|
||||
<LastUpdateTime>{$wsresource/LastUpdateHuman/text()}</LastUpdateTime>
|
||||
<NumberOfMembers>{$wsresource//child::*[local-name()='Cardinality']/text()}</NumberOfMembers>
|
||||
</Resource>
|
|
@ -0,0 +1,18 @@
|
|||
<Resource>
|
||||
{$profiles//Resource/ID}
|
||||
<Type>{$profiles//Resource/Type/text()}</Type>
|
||||
<SubType>{$subtype}</SubType>
|
||||
<Status>{$profiles//Resource/Profile/GHNDescription/Status/text()}</Status>
|
||||
<Name>{$profiles//Resource/Profile/GHNDescription/Name/text()}</Name>
|
||||
<Uptime>{$profiles//Resource/Profile/GHNDescription/Uptime/text()}</Uptime>
|
||||
<LastUpdate>{$profiles//Resource/Profile/GHNDescription/LastUpdate/text()}</LastUpdate>
|
||||
<LocalAvailableSpace>{$profiles//Resource/Profile/GHNDescription/LocalAvailableSpace/text()}</LocalAvailableSpace>
|
||||
<VirtualSize>{$profiles//Resource/Profile/GHNDescription/MainMemory/string(@VirtualSize)}</VirtualSize>
|
||||
<VirtualAvailable>{$profiles//Resource/Profile/GHNDescription/MainMemory/string(@VirtualAvailable)}</VirtualAvailable>
|
||||
<LoadLast1Min>{$profiles//Resource/Profile/GHNDescription/Load/string(@Last1Min)}</LoadLast1Min>
|
||||
<LoadLast5Min>{$profiles//Resource/Profile/GHNDescription/Load/string(@Last5Min)}</LoadLast5Min>
|
||||
<LoadLast15Min>{$profiles//Resource/Profile/GHNDescription/Load/string(@Last15Min)}</LoadLast15Min>
|
||||
<gcf-version>{$gcf-version}</gcf-version>
|
||||
<ghn-version>{$ghn-version}</ghn-version>
|
||||
<Scopes>{$scopes}</Scopes>
|
||||
</Resource>
|
|
@ -0,0 +1,8 @@
|
|||
<Resource>
|
||||
{$profiles//Resource/ID}
|
||||
<Type>{$profiles//Resource/Type/text()}</Type>
|
||||
<SubType>{$subtype}</SubType>
|
||||
<Scopes>{$scopes}</Scopes>
|
||||
<Name>{$profiles//Resource/Profile/Name/text()}</Name>
|
||||
<Description>{$profiles//Resource/Profile/Description/text()}</Description>
|
||||
</Resource>
|
|
@ -0,0 +1,11 @@
|
|||
<Resource>
|
||||
{$profiles/ID}
|
||||
<Type>{$profiles/Type/text()}</Type>
|
||||
<SubType>{$subtype}</SubType>
|
||||
<Scopes>{$scopes}</Scopes>
|
||||
<ServiceClass>{$profiles/Profile/ServiceClass/text()}</ServiceClass>
|
||||
<ServiceName>{$profiles/Profile/ServiceName/text()}</ServiceName>
|
||||
<Version>{$profiles/Profile/Version/text()}</Version>
|
||||
<Status>{$profiles/Profile/DeploymentData/Status/text()}</Status>
|
||||
<ghn-name>{$ghn-name}</ghn-name>
|
||||
</Resource>
|
|
@ -0,0 +1,7 @@
|
|||
<Resource>
|
||||
{$profiles//Resource/ID}
|
||||
<Type>{$profiles//Resource/Type/text()}</Type>
|
||||
<SubType>{$subtype}</SubType>
|
||||
<Scopes>{$scopes}</Scopes>
|
||||
<Name>{$profiles//Resource/Profile/Name/text()}</Name>
|
||||
</Resource>
|
|
@ -0,0 +1,10 @@
|
|||
<Resource>
|
||||
{$profiles//Resource/ID}
|
||||
<Type>{$profiles//Resource/Type/text()}</Type>
|
||||
<SubType>{$subtype}</SubType>
|
||||
<Scopes>{$scopes}</Scopes>
|
||||
<ServiceClass>{$profiles//Resource/Profile/Class/text()}</ServiceClass>
|
||||
<ServiceName>{$profiles//Resource/Profile/Name/text()}</ServiceName>
|
||||
<Version>{$profiles//Resource/Profile/Packages/Software[1]/Version/text()}</Version>
|
||||
<Shareable>{$profiles//Resource/Profile/Packages/Software/Shareable/string(@level)}</Shareable>
|
||||
</Resource>
|
|
@ -1,9 +1,4 @@
|
|||
|
||||
|
||||
for $profiles in collection('/db/Profiles/RunningInstance')//Resource
|
||||
<!--
|
||||
let $ghn-name := $profiles/Profile/GHN/@UniqueID/string()
|
||||
-->
|
||||
let $ghns := collection('/db/Profiles/GHN')//Resource
|
||||
let $_ghn-name := for $ghn in $ghns
|
||||
where $ghn/ID/string() eq $profiles/Profile/GHN/@UniqueID/string()
|
||||
|
@ -13,14 +8,4 @@ let $scopes := string-join( $profiles/Scopes//Scope/text(), ';')
|
|||
let $subtype := $profiles/Profile/ServiceClass/text()
|
||||
<RES_SUBTYPE ISdefault =''/>
|
||||
return
|
||||
<Resource>
|
||||
{$profiles/ID}
|
||||
<Type>{$profiles/Type/text()}</Type>
|
||||
<SubType>{$subtype}</SubType>
|
||||
<Scopes>{$scopes}</Scopes>
|
||||
<ServiceClass>{$profiles/Profile/ServiceClass/text()}</ServiceClass>
|
||||
<ServiceName>{$profiles/Profile/ServiceName/text()}</ServiceName>
|
||||
<Version>{$profiles/Profile/Version/text()}</Version>
|
||||
<Status>{$profiles/Profile/DeploymentData/Status/text()}</Status>
|
||||
<ghn-name>{$ghn-name}</ghn-name>
|
||||
</Resource>
|
||||
<RESOURCE/>
|
||||
|
|
|
@ -3,10 +3,5 @@ let $scopes := string-join( $profiles/Scopes//Scope/text(), ';')
|
|||
let $subtype := $profiles//Resource/Profile/Category/text()
|
||||
<RES_SUBTYPE ISdefault =''/>
|
||||
return
|
||||
<Resource>
|
||||
{$profiles//Resource/ID}
|
||||
<Type>{$profiles//Resource/Type/text()}</Type>
|
||||
<SubType>{$subtype}</SubType>
|
||||
<Scopes>{$scopes}</Scopes>
|
||||
<Name>{$profiles//Resource/Profile/Name/text()}</Name>
|
||||
</Resource>
|
||||
<RESOURCE/>
|
||||
|
|
@ -1,18 +1,6 @@
|
|||
|
||||
|
||||
for $profiles in collection('/db/Profiles/Service')//Resource
|
||||
let $scopes := string-join( $profiles/Scopes//Scope/text(), ';')
|
||||
let $subtype := $profiles//Resource/Profile/Class/text()
|
||||
<RES_SUBTYPE ISdefault =''/>
|
||||
return
|
||||
<Resource>
|
||||
{$profiles//Resource/ID}
|
||||
<Type>{$profiles//Resource/Type/text()}</Type>
|
||||
<SubType>{$subtype}</SubType>
|
||||
<Scopes>{$scopes}</Scopes>
|
||||
<ServiceClass>{$profiles//Resource/Profile/Class/text()}</ServiceClass>
|
||||
<ServiceName>{$profiles//Resource/Profile/Name/text()}</ServiceName>
|
||||
<!-- if many software defined takes the version of the first one -->
|
||||
<Version>{$profiles//Resource/Profile/Packages/Software[1]/Version/text()}</Version>
|
||||
<Shareable>{$profiles//Resource/Profile/Packages/Software/Shareable/string(@level)}</Shareable>
|
||||
</Resource>
|
||||
<RESOURCE/>
|
|
@ -16,24 +16,20 @@
|
|||
|
||||
package org.gcube.resourcemanagement.support.server.managers.resources;
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Vector;
|
||||
import org.apache.axis.message.addressing.EndpointReferenceType;
|
||||
import org.gcube.common.core.contexts.GCUBERemotePortTypeContext;
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.informationsystem.client.AtomicCondition;
|
||||
import org.gcube.common.core.informationsystem.client.ISClient;
|
||||
import org.gcube.common.core.informationsystem.client.XMLResult;
|
||||
import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericQuery;
|
||||
import org.gcube.common.core.informationsystem.client.queries.GCUBERIQuery;
|
||||
import org.gcube.common.core.informationsystem.publisher.ISPublisher;
|
||||
import org.gcube.common.core.resources.GCUBEResource;
|
||||
import org.gcube.common.core.resources.GCUBERunningInstance;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.scope.GCUBEScope.Type;
|
||||
|
||||
import org.gcube.common.core.security.GCUBESecurityManagerImpl;
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.common.resources.gcore.ScopeGroup;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
||||
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
||||
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.AbstractResourceException;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.ResourceAccessException;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.ResourceOperationException;
|
||||
|
@ -41,20 +37,19 @@ import org.gcube.resourcemanagement.support.server.exceptions.ResourceParameterE
|
|||
import org.gcube.resourcemanagement.support.server.managers.report.ReportBuilder;
|
||||
import org.gcube.resourcemanagement.support.server.managers.report.ReportEntry;
|
||||
import org.gcube.resourcemanagement.support.server.managers.report.ReportOperation;
|
||||
import org.gcube.resourcemanagement.support.server.managers.scope.ScopeManager;
|
||||
import org.gcube.resourcemanagement.support.server.types.AllowedResourceTypes;
|
||||
import org.gcube.resourcemanagement.support.server.utils.Assertion;
|
||||
import org.gcube.resourcemanagement.support.server.utils.ServerConsole;
|
||||
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.AddResourcesParameters;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.RemoveResourcesParameters;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.ResourceBinderPortType;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.ResourceItem;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.ResourceList;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.service.ResourceBinderServiceAddressingLocator;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.reporting.ReportingPortType;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.reporting.service.ReportingServiceAddressingLocator;
|
||||
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
||||
import org.gcube.vremanagement.resourcemanager.client.RMBinderLibrary;
|
||||
import org.gcube.vremanagement.resourcemanager.client.RMReportingLibrary;
|
||||
import org.gcube.vremanagement.resourcemanager.client.fws.Types.AddResourcesParameters;
|
||||
import org.gcube.vremanagement.resourcemanager.client.fws.Types.RemoveResourcesParameters;
|
||||
import org.gcube.vremanagement.resourcemanager.client.fws.Types.ResourceItem;
|
||||
import org.gcube.vremanagement.resourcemanager.client.fws.Types.ResourceList;
|
||||
import org.gcube.vremanagement.resourcemanager.client.proxies.Proxies;
|
||||
|
||||
/**
|
||||
* The minimal interface all the resource managers must implement.
|
||||
|
@ -68,16 +63,15 @@ public abstract class AbstractResourceManager {
|
|||
private String name = null;
|
||||
private AllowedResourceTypes type = null;
|
||||
private String subType = null;
|
||||
private ISClient client = null;
|
||||
private GCUBESecurityManagerImpl managerSec = null;
|
||||
private ISPublisher publisher = null;
|
||||
private RegistryPublisher publisher = null;
|
||||
private static final String LOG_PREFIX = "[AbstractResMgr]";
|
||||
|
||||
/**
|
||||
* @deprecated discouraged use. With no ID some operations cannot be accessed. For internal use only.
|
||||
*/
|
||||
public AbstractResourceManager(final AllowedResourceTypes type)
|
||||
throws ResourceParameterException, ResourceAccessException {
|
||||
throws ResourceParameterException, ResourceAccessException {
|
||||
Assertion<ResourceParameterException> checker = new Assertion<ResourceParameterException>();
|
||||
checker.validate(type != null, new ResourceParameterException("Invalid Parameter type"));
|
||||
|
||||
|
@ -93,13 +87,7 @@ public abstract class AbstractResourceManager {
|
|||
};
|
||||
|
||||
try {
|
||||
client = GHNContext.getImplementation(ISClient.class);
|
||||
} catch (Exception e) {
|
||||
throw new ResourceAccessException("Cannot instantiate the ISClient");
|
||||
}
|
||||
|
||||
try {
|
||||
this.publisher = GHNContext.getImplementation(ISPublisher.class);
|
||||
this.publisher = RegistryPublisherFactory.create();
|
||||
} catch (Exception e) {
|
||||
ServerConsole.error(LOG_PREFIX, e);
|
||||
}
|
||||
|
@ -114,10 +102,7 @@ public abstract class AbstractResourceManager {
|
|||
* @throws ResourceParameterException
|
||||
* @throws ResourceAccessException
|
||||
*/
|
||||
public AbstractResourceManager(
|
||||
final String id,
|
||||
final AllowedResourceTypes type)
|
||||
throws ResourceParameterException, ResourceAccessException {
|
||||
public AbstractResourceManager(String id, AllowedResourceTypes type) throws ResourceParameterException, ResourceAccessException {
|
||||
this(type);
|
||||
|
||||
Assertion<ResourceParameterException> checker = new Assertion<ResourceParameterException>();
|
||||
|
@ -126,45 +111,27 @@ public abstract class AbstractResourceManager {
|
|||
this.id = id.trim();
|
||||
}
|
||||
|
||||
public AbstractResourceManager(
|
||||
final String id,
|
||||
final String name,
|
||||
final AllowedResourceTypes type) throws ResourceParameterException, ResourceAccessException {
|
||||
public AbstractResourceManager(String id, String name, AllowedResourceTypes type) throws ResourceParameterException, ResourceAccessException {
|
||||
this(id, type);
|
||||
Assertion<ResourceParameterException> checker = new Assertion<ResourceParameterException>();
|
||||
checker.validate(name != null && name.trim().length() > 0, new ResourceParameterException("Invalid Parameter name"));
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public AbstractResourceManager(
|
||||
final String id,
|
||||
final String name,
|
||||
final AllowedResourceTypes type,
|
||||
final String subtype)
|
||||
throws ResourceParameterException, ResourceAccessException {
|
||||
public AbstractResourceManager(String id, String name, AllowedResourceTypes type, String subtype) throws ResourceParameterException, ResourceAccessException {
|
||||
this(id, name, type);
|
||||
if (subtype != null) {
|
||||
this.subType = subtype.trim();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The singleton ISClient instance is preferred.
|
||||
* All resource managers can internally access this instance
|
||||
* to make queries to the IS.
|
||||
* @return
|
||||
*/
|
||||
protected final ISClient getISClient() {
|
||||
return this.client;
|
||||
}
|
||||
|
||||
/**
|
||||
* The singleton ISPublisher instance is preferred.
|
||||
* All resource managers can internally access this instance
|
||||
* to interact with ISPublisher to handle resources.
|
||||
* @return
|
||||
*/
|
||||
public final ISPublisher getISPublisher() {
|
||||
public final RegistryPublisher getRegistryPublisher() {
|
||||
return publisher;
|
||||
}
|
||||
|
||||
|
@ -226,134 +193,6 @@ public abstract class AbstractResourceManager {
|
|||
return this.subType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internally used by {@link AbstractResourceManager#getResourceManager(GCUBEScope)}.
|
||||
* @param scope
|
||||
* @return a raw list of resource manager descriptors.
|
||||
* @throws Exception
|
||||
*/
|
||||
private List<GCUBERunningInstance> getResourceManagerFromScope(final GCUBEScope scope) throws Exception {
|
||||
System.out.println("Looking for ResourceManager in scope: " + scope);
|
||||
GCUBERIQuery query = this.client.getQuery(GCUBERIQuery.class);
|
||||
query.addAtomicConditions(new AtomicCondition("//Profile/ServiceClass", "VREManagement"));
|
||||
query.addAtomicConditions(new AtomicCondition("//Profile/ServiceName", "ResourceManager"));
|
||||
|
||||
List<GCUBERunningInstance> result = client.execute(query, scope);
|
||||
List<GCUBERunningInstance> toReturn = new ArrayList<GCUBERunningInstance>();
|
||||
for (GCUBERunningInstance ri : result) {
|
||||
if (ri.getScopes().containsValue(scope)) {
|
||||
toReturn.add(ri);
|
||||
}
|
||||
}
|
||||
System.out.println("Found " + toReturn.size() +" ResourceManager in scope: " + scope);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* The the list of resource managers able to handle the resource in a given scope.
|
||||
* @param scope the scope in which to operate
|
||||
* @return all the available managers
|
||||
* @throws ResourceAccessException if no manager can be instantiated
|
||||
* @throws ResourceParameterException if the parameters are invalid
|
||||
*/
|
||||
public final List<ResourceBinderPortType> getResourceManagers(final GCUBEScope scope) throws ResourceAccessException, ResourceParameterException {
|
||||
Assertion<ResourceParameterException> checker = new Assertion<ResourceParameterException>();
|
||||
checker.validate(scope != null, new ResourceParameterException("Invalid scope"));
|
||||
|
||||
|
||||
List<GCUBERunningInstance> resourceManagerList = null;
|
||||
try {
|
||||
resourceManagerList = this.getResourceManagerFromScope(scope);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ResourceAccessException("Cannot retrieve the managers for resource: " + this.getID());
|
||||
}
|
||||
List<ResourceBinderPortType> retval = new Vector<ResourceBinderPortType>();
|
||||
|
||||
if (resourceManagerList.isEmpty()) {
|
||||
System.out.println("\n\n\n\n\n****** Schianta qui size: " + resourceManagerList.size() + " scope: " + scope);
|
||||
throw new ResourceAccessException("Unable to find ResourceManagers for resource " + this.getType() + " in scope: " + scope.toString());
|
||||
}
|
||||
|
||||
EndpointReferenceType endpoint = null;
|
||||
ResourceBinderPortType pt = null;
|
||||
|
||||
for (GCUBERunningInstance resourceManager : resourceManagerList) {
|
||||
try {
|
||||
endpoint = resourceManager.getAccessPoint().getEndpoint("gcube/vremanagement/resourcemanager/binder");
|
||||
|
||||
pt = GCUBERemotePortTypeContext.getProxy(
|
||||
new ResourceBinderServiceAddressingLocator()
|
||||
.getResourceBinderPortTypePort(endpoint),
|
||||
scope,
|
||||
this.managerSec);
|
||||
if (pt != null) {
|
||||
retval.add(pt);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
// trying on next entry
|
||||
ServerConsole.error(LOG_PREFIX, e);
|
||||
}
|
||||
}
|
||||
if (retval != null && retval.size() > 0) {
|
||||
// Return a random manager from the available ones
|
||||
return retval;
|
||||
}
|
||||
// no managers found
|
||||
throw new ResourceAccessException("Unable to find ResourceManagers for resource " + this.getID() + "in scope: " + scope.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* The the list of resource report managers able to handle the resource in a given scope.
|
||||
* @param scope the scope in which to operate
|
||||
* @return all the available managers
|
||||
* @throws ResourceAccessException if no manager can be instantiated
|
||||
* @throws ResourceParameterException if the parameters are invalid
|
||||
*/
|
||||
public final List<ReportingPortType> getResourceReportManagers(final GCUBEScope scope) throws ResourceAccessException, ResourceParameterException {
|
||||
Assertion<ResourceParameterException> checker = new Assertion<ResourceParameterException>();
|
||||
checker.validate(scope != null, new ResourceParameterException("Invalid scope"));
|
||||
|
||||
List<GCUBERunningInstance> resourceManagerList = null;
|
||||
try {
|
||||
resourceManagerList = this.getResourceManagerFromScope(scope);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ResourceAccessException("Cannot retrieve the managers for resource: " + this.getID());
|
||||
}
|
||||
List<ReportingPortType> retval = new Vector<ReportingPortType>();
|
||||
|
||||
if (resourceManagerList.isEmpty()) {
|
||||
throw new ResourceAccessException("Unable to find ResourceManagers for resource " + this.getType() + " in scope: " + scope.toString());
|
||||
}
|
||||
|
||||
EndpointReferenceType endpoint = null;
|
||||
ReportingPortType pt = null;
|
||||
|
||||
for (GCUBERunningInstance resourceManager : resourceManagerList) {
|
||||
try {
|
||||
endpoint = resourceManager.getAccessPoint().getEndpoint("gcube/vremanagement/resourcemanager/reporting");
|
||||
|
||||
pt = GCUBERemotePortTypeContext.getProxy(
|
||||
new ReportingServiceAddressingLocator().getReportingPortTypePort(endpoint),
|
||||
scope,
|
||||
this.managerSec);
|
||||
if (pt != null) {
|
||||
retval.add(pt);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
// trying on next entry
|
||||
ServerConsole.error(LOG_PREFIX, e);
|
||||
}
|
||||
}
|
||||
if (retval != null && retval.size() > 0) {
|
||||
// Return a random report manager from the available ones
|
||||
return retval;
|
||||
}
|
||||
// no managers found
|
||||
throw new ResourceAccessException("Unable to find ReportResourceManagers for resource " + this.getID() + "in scope: " + scope.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* The resource manager needed to handle the resource in a given scope.
|
||||
* @param scope the scope in which to operate
|
||||
|
@ -361,19 +200,20 @@ public abstract class AbstractResourceManager {
|
|||
* @throws ResourceAccessException if no manager can be instantiated
|
||||
* @throws ResourceParameterException if the parameters are invalid
|
||||
*/
|
||||
public final ResourceBinderPortType getResourceManager(final GCUBEScope scope)
|
||||
throws AbstractResourceException {
|
||||
ServerConsole.info(LOG_PREFIX, "Getting Resource Manager in scope [" + scope.toString() + "]");
|
||||
|
||||
List<ResourceBinderPortType> retval = this.getResourceManagers(scope);
|
||||
if (retval != null && retval.size() > 0) {
|
||||
Random generator = new Random();
|
||||
// Return a random manager from the available ones
|
||||
ResourceBinderPortType manager = retval.get(generator.nextInt(retval.size()));
|
||||
return manager;
|
||||
public final RMBinderLibrary getResourceManager(String scope) throws AbstractResourceException {
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeBean bscope = new ScopeBean(scope);
|
||||
if (bscope.is(Type.VRE)) {
|
||||
scope = bscope.enclosingScope().toString();
|
||||
}
|
||||
// no managers found
|
||||
throw new ResourceAccessException("Unable to find ResourceManagers for resource " + this.getType() + " in scope: " + scope.toString());
|
||||
ScopeProvider.instance.set(scope);
|
||||
ServerConsole.info(LOG_PREFIX, "Getting Resource Manager in scope [" + scope.toString() + "]");
|
||||
RMBinderLibrary rml = Proxies.binderService().build();
|
||||
if (rml == null) { // no managers found
|
||||
throw new ResourceAccessException("Unable to find ResourceManagers for resource " + this.getType() + " in scope: " + scope.toString());
|
||||
}
|
||||
ScopeProvider.instance.set(currScope);
|
||||
return rml;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -383,19 +223,21 @@ public abstract class AbstractResourceManager {
|
|||
* @throws ResourceAccessException if no manager can be instantiated
|
||||
* @throws ResourceParameterException if the parameters are invalid
|
||||
*/
|
||||
public final ReportingPortType getReportResourceManager(final GCUBEScope scope)
|
||||
throws AbstractResourceException {
|
||||
ServerConsole.info(LOG_PREFIX, "Getting Resource Manager in scope [" + scope.toString() + "]");
|
||||
|
||||
List<ReportingPortType> retval = this.getResourceReportManagers(scope);
|
||||
if (retval != null && retval.size() > 0) {
|
||||
Random generator = new Random();
|
||||
// Return a random manager from the available ones
|
||||
ReportingPortType manager = retval.get(generator.nextInt(retval.size()));
|
||||
return manager;
|
||||
public final RMReportingLibrary getReportResourceManager(String scope) throws AbstractResourceException {
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeBean bscope = new ScopeBean(scope);
|
||||
if (bscope.is(Type.VRE)) {
|
||||
scope = bscope.enclosingScope().toString();
|
||||
}
|
||||
// no managers found
|
||||
throw new ResourceAccessException("Unable to find ResourceManagers for resource " + this.getType() + " in scope: " + scope.toString());
|
||||
ScopeProvider.instance.set(scope);
|
||||
|
||||
ServerConsole.info(LOG_PREFIX, "Getting Resource Manager in scope [" + scope.toString() + "]");
|
||||
RMReportingLibrary rml = Proxies.reportingService().build();
|
||||
if (rml == null) { // no managers found
|
||||
throw new ResourceAccessException("Unable to find ResourceManagers for resource " + this.getType() + " in scope: " + scope.toString());
|
||||
}
|
||||
ScopeProvider.instance.set(currScope);
|
||||
return rml;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -408,7 +250,7 @@ public abstract class AbstractResourceManager {
|
|||
* @return
|
||||
* @throws ResourceOperationException
|
||||
*/
|
||||
private String bindToScope(final GCUBEScope targetScope) throws AbstractResourceException {
|
||||
private String bindToScope(final String targetScope) throws AbstractResourceException {
|
||||
Assertion<AbstractResourceException> checker = new Assertion<AbstractResourceException>();
|
||||
checker.validate(targetScope != null, new ResourceParameterException("Invalid parameter targetScope. null not allowed."));
|
||||
checker.validate(this.getID() != null, new ResourceOperationException("Invalid resource ID. null not allowed."));
|
||||
|
@ -416,37 +258,47 @@ public abstract class AbstractResourceManager {
|
|||
ServerConsole.trace(
|
||||
LOG_PREFIX,
|
||||
"[BIND-SCOPE-ENTER] Adding " + this.getType() + " " + this.getID() + " to scope [" +
|
||||
targetScope.toString() + "]");
|
||||
targetScope.toString() + "]");
|
||||
|
||||
AddResourcesParameters addParam = new AddResourcesParameters();
|
||||
ResourceItem toAdd = new ResourceItem();
|
||||
toAdd.setID(this.getID());
|
||||
toAdd.setId(this.getID());
|
||||
toAdd.setType(this.getType().name());
|
||||
ResourceList r = new ResourceList();
|
||||
|
||||
|
||||
r.setResource(new ResourceItem[]{toAdd});
|
||||
ArrayList<ResourceItem> temp = new ArrayList<ResourceItem>();
|
||||
temp.add(toAdd);
|
||||
r.setResource(temp);
|
||||
addParam.setResources(r);
|
||||
addParam.setTargetScope(targetScope.toString());
|
||||
|
||||
ResourceBinderPortType manager = this.getResourceManager(targetScope);
|
||||
RMBinderLibrary manager = this.getResourceManager(targetScope);
|
||||
|
||||
try {
|
||||
String curr = ScopeProvider.instance.get();
|
||||
ScopeBean scope = new ScopeBean(targetScope);
|
||||
if (scope.is(Type.VRE)) {
|
||||
ScopeProvider.instance.set(scope.enclosingScope().toString());
|
||||
} else
|
||||
ScopeProvider.instance.set(targetScope);
|
||||
String reportID = manager.addResources(addParam);
|
||||
|
||||
ServerConsole.trace(
|
||||
LOG_PREFIX,
|
||||
"[BIND-SCOPE-EXIT] Applyed Adding " + this.getType() + " " + this.getID() + " to scope [" +
|
||||
targetScope.toString() + "]... reportID: " + reportID);
|
||||
targetScope.toString() + "]... reportID: " + reportID);
|
||||
|
||||
ReportingPortType pt = this.getReportResourceManager(targetScope);
|
||||
return pt.getReport(reportID);
|
||||
RMReportingLibrary pt = this.getReportResourceManager(scope.toString());
|
||||
|
||||
String toReturn = pt.getReport(reportID);
|
||||
ScopeProvider.instance.set(curr);
|
||||
return toReturn;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ServerConsole.trace(
|
||||
LOG_PREFIX,
|
||||
"[BIND-SCOPE-EXIT] [FAILURE]");
|
||||
throw new ResourceOperationException("During resource::addToScope: " + e.getMessage());
|
||||
"[BIND-SCOPE-EXIT] [FAILURE]");
|
||||
throw new ResourceOperationException("During resource::addToScope: "+ targetScope + " Message: \n" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -457,9 +309,7 @@ public abstract class AbstractResourceManager {
|
|||
* @param nestingPublication true for resources different from gHN and RI.
|
||||
* @return the reportID generated
|
||||
*/
|
||||
public final String addToExistingScope(
|
||||
final GCUBEScope sourceScope, final GCUBEScope targetScope)
|
||||
throws AbstractResourceException {
|
||||
public final String addToExistingScope(final ScopeBean sourceScope, final ScopeBean targetScope) throws AbstractResourceException {
|
||||
Assertion<AbstractResourceException> checker = new Assertion<AbstractResourceException>();
|
||||
checker.validate(sourceScope != null, new ResourceParameterException("Invalid parameter sourceScope. null not allowed."));
|
||||
checker.validate(targetScope != null, new ResourceParameterException("Invalid parameter targetScope. null not allowed."));
|
||||
|
@ -470,34 +320,36 @@ public abstract class AbstractResourceManager {
|
|||
ServerConsole.trace(
|
||||
LOG_PREFIX,
|
||||
"[ADD-ToExistingScope] Adding from scope [" +
|
||||
sourceScope.toString() +
|
||||
"] to existing scope [" +
|
||||
targetScope.toString() +
|
||||
"] " + this.getType() + " " + this.getID());
|
||||
sourceScope.toString() +
|
||||
"] to existing scope [" +
|
||||
targetScope.toString() +
|
||||
"] " + this.getType() + " " + this.getID());
|
||||
|
||||
// If not RI or GHN and the scopes are sibling and VO copyFromToVO
|
||||
if (!(this.getType() == AllowedResourceTypes.GHN) &&
|
||||
!(this.getType() == AllowedResourceTypes.RunningInstance) &&
|
||||
sourceScope.getType() == Type.VO && targetScope.getType() == Type.VO) {
|
||||
sourceScope.type() == Type.VO && targetScope.type() == Type.VO) {
|
||||
return copyFromToVO(sourceScope, targetScope);
|
||||
}
|
||||
|
||||
// Add a gCube Resource to
|
||||
// (i) a VRE scope from the parent VO or
|
||||
// (ii) a VO scope from the infrastructure scope
|
||||
if (!targetScope.isEnclosedIn(sourceScope)) {
|
||||
if (!targetScope.toString().contains(sourceScope.toString())) {
|
||||
throw new ResourceOperationException(
|
||||
"You are not allowed to apply to this scope. Target scope is not enclosed in the source one.");
|
||||
"You are not allowed to apply to this scope. Target scope is not enclosed in the source one.");
|
||||
}
|
||||
|
||||
report.addEntry(new ReportEntry(ReportOperation.AddToScope, this,
|
||||
"Added " + this.getType() + " " + this.getID() + " to parent scope " +
|
||||
targetScope.toString() + " the remote report ID is: " +
|
||||
this.bindToScope(targetScope), true));
|
||||
targetScope.toString() + " the remote report ID is: " +
|
||||
this.bindToScope(targetScope.toString()), true));
|
||||
|
||||
return report.getXML();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Similar to the {@link AbstractResourceManager#addToExistingScope} method but involves
|
||||
* two scopes of type VO.
|
||||
|
@ -510,17 +362,16 @@ public abstract class AbstractResourceManager {
|
|||
* @return
|
||||
* @throws AbstractResourceException
|
||||
*/
|
||||
public final String copyFromToVO(final GCUBEScope sourceScope, final GCUBEScope targetScope)
|
||||
throws AbstractResourceException {
|
||||
public final String copyFromToVO(final ScopeBean sourceScope, final ScopeBean targetScope) throws AbstractResourceException {
|
||||
Assertion<AbstractResourceException> checker = new Assertion<AbstractResourceException>();
|
||||
checker.validate(
|
||||
sourceScope != null && sourceScope.getType() == Type.VO,
|
||||
sourceScope != null && sourceScope.type() == Type.VO,
|
||||
new ResourceParameterException("The sourceScope is invalid or not of type VO."));
|
||||
checker.validate(
|
||||
targetScope != null && targetScope.getType() == Type.VO,
|
||||
targetScope != null && targetScope.type() == Type.VO,
|
||||
new ResourceParameterException("The targetScope is invalid or not of type VO."));
|
||||
checker.validate(
|
||||
sourceScope.getEnclosingScope() == targetScope.getEnclosingScope(),
|
||||
sourceScope.enclosingScope() == targetScope.enclosingScope(),
|
||||
new ResourceParameterException("The sourceScope and targetScope must be children of the same root VO."));
|
||||
checker.validate(this.getType() != AllowedResourceTypes.GHN && this.getType() != AllowedResourceTypes.RunningInstance,
|
||||
new ResourceAccessException("Operation not allowed for RI and GHNs."));
|
||||
|
@ -528,18 +379,24 @@ public abstract class AbstractResourceManager {
|
|||
new ResourceAccessException("Operation not allowed on resources with no ID."));
|
||||
|
||||
// Phase 1. retrieve the resource to copy
|
||||
GCUBEResource resStub = this.getGCUBEResource(sourceScope);
|
||||
Resource resStub = this.getResource(sourceScope);
|
||||
|
||||
// Phase 2. Before to register the resource, the scope must be
|
||||
// Phase 2. Before registering the resource, the scope must be
|
||||
// bound to the local GCUBEResource
|
||||
this.bindToScope(targetScope);
|
||||
this.bindToScope(targetScope.toString());
|
||||
|
||||
// Phase 3. Register to the new VO through the ISPublisher
|
||||
|
||||
String currentScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(targetScope.toString());
|
||||
Resource toReturn = null;
|
||||
try {
|
||||
return this.getISPublisher().registerGCUBEResource(resStub, targetScope, this.getSecurityManager());
|
||||
toReturn = this.getRegistryPublisher().create(resStub);
|
||||
} catch (Exception e) {
|
||||
throw new ResourceAccessException(e.getMessage());
|
||||
}
|
||||
ScopeProvider.instance.set(currentScope);
|
||||
return toReturn.id();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -550,7 +407,7 @@ public abstract class AbstractResourceManager {
|
|||
* @return
|
||||
* @throws AbstractResourceException
|
||||
*/
|
||||
protected abstract GCUBEResource buildGCUBEResource(final String xmlRepresentation) throws AbstractResourceException;
|
||||
protected abstract Resource buildResource(final String xmlRepresentation) throws AbstractResourceException;
|
||||
|
||||
/**
|
||||
* From a resource retrieves its GCUBEResource depending on the scope in which it is
|
||||
|
@ -559,8 +416,8 @@ public abstract class AbstractResourceManager {
|
|||
* @return
|
||||
* @throws AbstractResourceException
|
||||
*/
|
||||
public final GCUBEResource getGCUBEResource(final GCUBEScope scope) throws AbstractResourceException {
|
||||
return this.buildGCUBEResource(this.getXMLDescription(scope));
|
||||
public final Resource getResource(final ScopeBean scope) throws AbstractResourceException {
|
||||
return this.buildResource(this.getXMLDescription(scope));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -570,44 +427,39 @@ public abstract class AbstractResourceManager {
|
|||
* @return
|
||||
* @throws AbstractResourceException
|
||||
*/
|
||||
protected final String getXMLDescription(final GCUBEScope scope) throws AbstractResourceException {
|
||||
protected final String getXMLDescription(final ScopeBean scope) throws AbstractResourceException {
|
||||
Assertion<AbstractResourceException> checker = new Assertion<AbstractResourceException>();
|
||||
checker.validate(this.getID() != null, new ResourceAccessException("Cannot execute on resources with no ID."));
|
||||
|
||||
// Phase 1. retrieve the resource to copy
|
||||
GCUBEGenericQuery query = null;
|
||||
try {
|
||||
query = this.getISClient().getQuery(GCUBEGenericQuery.class);
|
||||
query.setExpression(
|
||||
"for $resource in collection('/db/Profiles/" + this.getType().name() + "')//Resource " +
|
||||
"where ( $resource/ID/string() eq '" +
|
||||
this.getID() +
|
||||
"') " +
|
||||
"return $resource"
|
||||
);
|
||||
} catch (Exception e) {
|
||||
throw new ResourceAccessException(e);
|
||||
}
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
|
||||
XMLResult resDescription = null;
|
||||
try {
|
||||
resDescription = this.getISClient().execute(query, scope).get(0);
|
||||
return resDescription.toString();
|
||||
} catch (Exception e) {
|
||||
// Phase 1. retrieve the resource to copy
|
||||
Query query = new QueryBox("for $resource in collection('/db/Profiles/" + this.getType().name() + "')//Resource " +
|
||||
"where ( $resource/ID/string() eq '" +
|
||||
this.getID() +
|
||||
"') " +
|
||||
"return $resource");
|
||||
|
||||
DiscoveryClient<String> client = client();
|
||||
|
||||
List<String> results = client.submit(query);
|
||||
if (results == null || results.isEmpty())
|
||||
throw new ResourceAccessException("Cannot retrieve the IS profile for resource: " + this.getID() +
|
||||
" in scope: " + scope.toString());
|
||||
}
|
||||
ScopeProvider.instance.set(currScope);
|
||||
|
||||
return results.get(0).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* The first phase of remove form scope.
|
||||
* The first phase of remove from scope.
|
||||
* This is common to all the resources (RI and GHNs).
|
||||
* @param scope
|
||||
* @return
|
||||
* @throws AbstractResourceException
|
||||
*/
|
||||
private String basicRemoveFromScope(final GCUBEScope scope)
|
||||
throws AbstractResourceException {
|
||||
private String basicRemoveFromScope(final ScopeBean scope) throws AbstractResourceException {
|
||||
Assertion<AbstractResourceException> checker = new Assertion<AbstractResourceException>();
|
||||
checker.validate(scope != null, new ResourceParameterException("Invalid parameter scope. null not allowed."));
|
||||
checker.validate(this.getID() != null, new ResourceOperationException("Invalid ID. null not allowed."));
|
||||
|
@ -618,17 +470,22 @@ public abstract class AbstractResourceManager {
|
|||
|
||||
RemoveResourcesParameters params = new RemoveResourcesParameters();
|
||||
ResourceItem toRemove = new ResourceItem();
|
||||
toRemove.setID(this.getID());
|
||||
toRemove.setId(this.getID());
|
||||
toRemove.setType(this.getType().name());
|
||||
|
||||
ResourceList resourcesToRemove = new ResourceList();
|
||||
resourcesToRemove.setResource(new ResourceItem[]{toRemove});
|
||||
params.setResources(resourcesToRemove);
|
||||
params.setTargetScope(scope.toString());
|
||||
ArrayList<ResourceItem> temp = new ArrayList<ResourceItem>();
|
||||
temp.add(toRemove);
|
||||
resourcesToRemove.setResource(temp);
|
||||
params.resources = resourcesToRemove;
|
||||
params.targetScope = scope.toString();
|
||||
ServerConsole.trace(LOG_PREFIX, "[REMOVE-FROM-SCOPE] Sending the Remove Resource request....");
|
||||
try {
|
||||
ResourceBinderPortType manager = this.getResourceManager(scope);
|
||||
RMBinderLibrary manager = this.getResourceManager(scope.toString());
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
retval = manager.removeResources(params);
|
||||
ScopeProvider.instance.set(currScope);
|
||||
} catch (Exception e) {
|
||||
throw new ResourceOperationException("During removeFrom scope of "
|
||||
+ this.getType()
|
||||
|
@ -641,59 +498,17 @@ public abstract class AbstractResourceManager {
|
|||
* Removes the current resource from the scope.
|
||||
* @param nestingRemoval true for resources different from gHN and RI
|
||||
*/
|
||||
public final String removeFromScope(final GCUBEScope scope)
|
||||
throws AbstractResourceException {
|
||||
public final String removeFromScope(final ScopeBean scope) throws AbstractResourceException {
|
||||
Assertion<AbstractResourceException> checker = new Assertion<AbstractResourceException>();
|
||||
checker.validate(scope != null, new ResourceParameterException("Invalid parameter scope. null not allowed."));
|
||||
checker.validate(this.getID() != null, new ResourceOperationException("Invalid ID. null not allowed."));
|
||||
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
|
||||
String retval = this.basicRemoveFromScope(scope);
|
||||
|
||||
// -- PHASE 2 - optional
|
||||
|
||||
// Builds the stub without the removed scope
|
||||
GCUBEResource resStub = this.getGCUBEResource(scope);
|
||||
// Refreshes the local profile
|
||||
resStub.removeScope(scope);
|
||||
|
||||
/*
|
||||
* These steps are for resources different from GHN and RI
|
||||
*/
|
||||
if (!this.getType().equals(AllowedResourceTypes.GHN.name()) &&
|
||||
!this.getType().equals(AllowedResourceTypes.RunningInstance.name())) {
|
||||
// Phase 1
|
||||
// if the resource joins only the current scope, after the removal it has also to be deleted
|
||||
try {
|
||||
List<GCUBEScope> boundedScopes = this.validateScopes(resStub.getScopes().values().toArray(new GCUBEScope[]{}));
|
||||
if (boundedScopes == null) {
|
||||
ServerConsole.warn(LOG_PREFIX, "[REMOVE-FROM-SCOPE] The resource " + this.getType() + " has no bound scopes");
|
||||
return retval;
|
||||
}
|
||||
|
||||
if (boundedScopes.size() == 0) {
|
||||
ServerConsole.trace(LOG_PREFIX, "[REMOVE-FROM-SCOPE] [DELETE-BRANCH] deleting resource since no more scopes remained");
|
||||
this.getISPublisher().removeGCUBEResource(
|
||||
this.getID(), this.getType().name(), scope, this.getSecurityManager());
|
||||
return retval;
|
||||
} else {
|
||||
// requires the update of the resources in all other scopes
|
||||
for (GCUBEScope _scope : boundedScopes) {
|
||||
if (!scope.equals(_scope)) {
|
||||
try {
|
||||
ServerConsole.trace(LOG_PREFIX, "[REMOVE-FROM-SCOPE] [UPDATE-BRANCH] Updating profile in scope [" + _scope.toString() + "]");
|
||||
this.getISPublisher().updateGCUBEResource(resStub, _scope, getSecurityManager());
|
||||
} catch (Exception e) {
|
||||
ServerConsole.error(LOG_PREFIX, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new ResourceOperationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
ScopeProvider.instance.set(currScope);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -704,14 +519,10 @@ public abstract class AbstractResourceManager {
|
|||
* @param scopes
|
||||
* @return
|
||||
*/
|
||||
protected List<GCUBEScope> validateScopes(final GCUBEScope[] scopes) {
|
||||
List<GCUBEScope> retval = new Vector<GCUBEScope>();
|
||||
for (GCUBEScope scope : scopes) {
|
||||
try {
|
||||
retval.add(ScopeManager.getScope(scope.toString()));
|
||||
} catch (Exception e) {
|
||||
ServerConsole.error(LOG_PREFIX, e);
|
||||
}
|
||||
protected List<ScopeBean> validateScopes(final String[] scopes) {
|
||||
List<ScopeBean> retval = new Vector<ScopeBean>();
|
||||
for (int i = 0; i < scopes.length; i++) {
|
||||
retval.add(new ScopeBean(scopes[i]));
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
@ -722,11 +533,11 @@ public abstract class AbstractResourceManager {
|
|||
* @param scope where the resource is bound
|
||||
* @throws AbstractResourceException
|
||||
*/
|
||||
public final void forceDelete(final GCUBEScope scope) throws AbstractResourceException {
|
||||
public final void forceDelete(final ScopeBean scope) throws AbstractResourceException {
|
||||
ServerConsole.trace(LOG_PREFIX, "[DELETE] [DELETE-BRANCH] deleting resource since no more scopes remained");
|
||||
Resource resStub = this.getResource(scope);
|
||||
try {
|
||||
this.getISPublisher().removeGCUBEResource(
|
||||
this.getID(), this.getType().name(), scope, this.getSecurityManager());
|
||||
this.getRegistryPublisher().remove(resStub);
|
||||
} catch (Exception e) {
|
||||
ServerConsole.error(LOG_PREFIX, e);
|
||||
}
|
||||
|
@ -737,64 +548,37 @@ public abstract class AbstractResourceManager {
|
|||
* According to the
|
||||
* <a href="https://gcube.wiki.gcube-system.org/gcube/index.php/Programmatic_Administration_Interface">
|
||||
* official wiki</a> the resource is deleted only if is not bound in other scopes. Otherwise this
|
||||
* operation simply corresponds to the in deep remove from scope.
|
||||
* operation simply corresponds to remove from scope.
|
||||
* @param scope
|
||||
* @throws ResourceOperationException
|
||||
*/
|
||||
public final void delete(final GCUBEScope scope) throws AbstractResourceException {
|
||||
public final void delete(final ScopeBean scope) throws AbstractResourceException {
|
||||
Assertion<AbstractResourceException> checker = new Assertion<AbstractResourceException>();
|
||||
checker.validate(scope != null, new ResourceParameterException("Invalid parameter scope. null not allowed."));
|
||||
checker.validate(this.getID() != null, new ResourceOperationException("Invalid ID. null not allowed."));
|
||||
|
||||
System.out.println("DELETING TYPE: "+ this.getType());
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
|
||||
GCUBEResource resStub = this.getGCUBEResource(scope);
|
||||
List<GCUBEScope> boundedScopes = this.validateScopes(resStub.getScopes().values().toArray(new GCUBEScope[]{}));
|
||||
Resource resStub = this.getResource(scope);
|
||||
|
||||
List<ScopeBean> boundedScopes = this.validateScopes(resStub.scopes().toArray(new String[0]));
|
||||
|
||||
ServerConsole.trace(LOG_PREFIX, "[DELETE] " + this.getType() + " " + this.getID() + " in scope [" + scope + "]");
|
||||
|
||||
ServerConsole.trace(LOG_PREFIX, "[DELETE] " + this.getType() + " " + this.getID() + " is bound to (" + boundedScopes.size() + ") scopes");
|
||||
|
||||
/*
|
||||
* Removefromscope accetta un boolean piu la resource gia ottenuta.
|
||||
* boolean per decidere se saltare fase due di update che la ripeto piu volte
|
||||
* rispetto a qui che lo faccio una volta sola.
|
||||
*/
|
||||
for (GCUBEScope _scope : boundedScopes) {
|
||||
// Removing from the children scopes
|
||||
if (_scope.isEnclosedIn(scope) || scope.equals(_scope)) {
|
||||
this.basicRemoveFromScope(_scope);
|
||||
resStub.removeScope(_scope);
|
||||
}
|
||||
}
|
||||
|
||||
// Phase 2
|
||||
// after the removal, the resource must be also updated in the other scopes it belongs to,
|
||||
// otherwise it will wrongly report there a scope where actually it is not registered anymore.
|
||||
// In order to do so, the just removed scope must be removed from the local
|
||||
// GCUBEResource object by invoking the method GCUBEResource.removeScope(<scope to remove>)
|
||||
// and then the resource must be updated in all the remaining scopes.
|
||||
|
||||
|
||||
if (resStub.getScopes().isEmpty()) {
|
||||
ServerConsole.trace(LOG_PREFIX, "[DELETE] [DELETE-BRANCH] deleting resource since no more scopes remained");
|
||||
try {
|
||||
this.getISPublisher().removeGCUBEResource(
|
||||
this.getID(), this.getType().name(), scope, this.getSecurityManager());
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
} else {
|
||||
boundedScopes = this.validateScopes(resStub.getScopes().values().toArray(new GCUBEScope[]{}));
|
||||
for (GCUBEScope _scope : boundedScopes) {
|
||||
try {
|
||||
ServerConsole.trace(LOG_PREFIX, "[DELETE] [UPDATE-BRANCH]" + this.getType() + " " + this.getID() + " in scope [" + _scope + "]");
|
||||
this.getISPublisher().updateGCUBEResource(resStub, _scope, getSecurityManager());
|
||||
} catch (Exception e) {
|
||||
ServerConsole.error(LOG_PREFIX, e);
|
||||
}
|
||||
}
|
||||
if (boundedScopes.size() > 1)
|
||||
ServerConsole.trace(LOG_PREFIX, "[DELETE] [DELETE-BRANCH] deleting resource is a remove from scope since more than 1 scope is present " + resStub.id());
|
||||
else if (boundedScopes.size() == 1)
|
||||
ServerConsole.trace(LOG_PREFIX, "[DELETE] [DELETE-BRANCH] deleting resource since is bound to 1 scope only " + resStub.id());
|
||||
try {
|
||||
this.getRegistryPublisher().remove(resStub);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
ScopeProvider.instance.set(currScope);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,9 +17,11 @@
|
|||
package org.gcube.resourcemanagement.support.server.managers.resources;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.resources.GCUBECollection;
|
||||
import org.gcube.common.core.resources.GCUBEResource;
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.AbstractResourceException;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.ResourceAccessException;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.ResourceParameterException;
|
||||
|
@ -66,19 +68,13 @@ public class CollectionManager extends AbstractResourceManager {
|
|||
super(id, name, AllowedResourceTypes.Collection, subtype);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
||||
|
||||
@Override
|
||||
protected final GCUBEResource buildGCUBEResource(final String xmlRepresentation)
|
||||
throws AbstractResourceException {
|
||||
try {
|
||||
GCUBECollection impl = GHNContext.getImplementation(GCUBECollection.class);
|
||||
impl.load(new StringReader(xmlRepresentation));
|
||||
return impl;
|
||||
} catch (Exception e) {
|
||||
throw new ResourceAccessException("Cannot load the stub for resource " + this.getType(), e);
|
||||
}
|
||||
protected Resource buildResource(String xmlRepresentation)
|
||||
throws AbstractResourceException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,17 +18,17 @@ package org.gcube.resourcemanagement.support.server.managers.resources;
|
|||
|
||||
import java.io.StringReader;
|
||||
|
||||
import org.apache.axis.message.addressing.Address;
|
||||
import org.apache.axis.message.addressing.EndpointReferenceType;
|
||||
import org.gcube.common.core.contexts.GCUBERemotePortTypeContext;
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.resources.GCUBEHostingNode;
|
||||
import org.gcube.common.core.resources.GCUBEResource;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.vremanagement.ghnmanager.stubs.AddScopeInputParams;
|
||||
import org.gcube.common.vremanagement.ghnmanager.stubs.GHNManagerPortType;
|
||||
import org.gcube.common.vremanagement.ghnmanager.stubs.ShutdownOptions;
|
||||
import org.gcube.common.vremanagement.ghnmanager.stubs.service.GHNManagerServiceAddressingLocator;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.gcube.common.resources.gcore.HostingNode;
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.common.vremanagement.ghnmanager.client.GHNManagerLibrary;
|
||||
import org.gcube.common.vremanagement.ghnmanager.client.fws.Types.AddScopeInputParams;
|
||||
import org.gcube.common.vremanagement.ghnmanager.client.fws.Types.ShutdownOptions;
|
||||
import org.gcube.common.vremanagement.ghnmanager.client.proxies.Proxies;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.AbstractResourceException;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.ResourceAccessException;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.ResourceOperationException;
|
||||
|
@ -100,10 +100,7 @@ public class GHNManager extends AbstractResourceManager {
|
|||
* @throws ResourceParameterException
|
||||
* @throws ResourceOperationException
|
||||
*/
|
||||
public final String addToNewScope(
|
||||
final GCUBEScope sourceScope,
|
||||
final GCUBEScope targetScope,
|
||||
final String scopeMap)
|
||||
public final String addToNewScope(final ScopeBean sourceScope, final ScopeBean targetScope, final String scopeMap)
|
||||
throws AbstractResourceException {
|
||||
Assertion<AbstractResourceException> checker = new Assertion<AbstractResourceException>();
|
||||
checker.validate(sourceScope != null, new ResourceParameterException("Parameter sourceScope null not allowed."));
|
||||
|
@ -111,7 +108,7 @@ public class GHNManager extends AbstractResourceManager {
|
|||
checker.validate(scopeMap != null && scopeMap.trim().length() > 0, new ResourceParameterException("Invalid scopeMap parameter."));
|
||||
checker.validate(this.getID() != null, new ResourceOperationException("This operation cannot be applied to resources with no ID."));
|
||||
|
||||
if (!targetScope.isEnclosedIn(sourceScope)) {
|
||||
if (!sourceScope.toString().contains(targetScope.toString())) {
|
||||
throw new ResourceOperationException(
|
||||
"You are not allowed to apply to this scope. Target scope is not enclosed in the source one.");
|
||||
}
|
||||
|
@ -144,22 +141,20 @@ public class GHNManager extends AbstractResourceManager {
|
|||
* @return
|
||||
* @throws AbstractResourceException
|
||||
*/
|
||||
public final GHNManagerPortType getGHNManager(final GCUBEScope scope)
|
||||
throws AbstractResourceException {
|
||||
public final GHNManagerLibrary getGHNManager(final ScopeBean scope) throws AbstractResourceException {
|
||||
Assertion<AbstractResourceException> checker = new Assertion<AbstractResourceException>();
|
||||
checker.validate(scope != null, new ResourceParameterException("Invalid scope"));
|
||||
checker.validate(this.getName() != null, new ResourceOperationException("This operation cannot be applied to resources with no name."));
|
||||
|
||||
EndpointReferenceType endpoint = new EndpointReferenceType();
|
||||
try {
|
||||
endpoint.setAddress(new Address("http://" + this.getName() + "/wsrf/services/gcube/common/vremanagement/GHNManager"));
|
||||
GHNManagerServiceAddressingLocator locator = new GHNManagerServiceAddressingLocator();
|
||||
GHNManagerPortType pt = locator.getGHNManagerPortTypePort(endpoint);
|
||||
pt = GCUBERemotePortTypeContext.getProxy(pt, scope, this.getSecurityManager());
|
||||
return pt;
|
||||
} catch (Exception e) {
|
||||
throw new ResourceAccessException(e.getMessage());
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
ServerConsole.info(LOG_PREFIX, "Getting Resource Manager in scope [" + scope.toString() + "]");
|
||||
GHNManagerLibrary ghnMan = Proxies.service().build();
|
||||
if (ghnMan == null) { // no managers found
|
||||
throw new ResourceAccessException("Unable to find GHNManagers for resource " + this.getType() + " in scope: " + scope.toString());
|
||||
}
|
||||
ScopeProvider.instance.set(currScope);
|
||||
return ghnMan;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -176,12 +171,12 @@ public class GHNManager extends AbstractResourceManager {
|
|||
* @throws ResourceAccessException
|
||||
* @throws ResourceParameterException
|
||||
*/
|
||||
public final void shutDown(final GCUBEScope scope, final boolean restart, final boolean clean)
|
||||
public final void shutDown(final ScopeBean scope, final boolean restart, final boolean clean)
|
||||
throws AbstractResourceException {
|
||||
Assertion<ResourceAccessException> checker = new Assertion<ResourceAccessException>();
|
||||
checker.validate(this.getID() != null, new ResourceAccessException("This operation cannot be applied to resources with no ID."));
|
||||
|
||||
GHNManagerPortType ghnManager = this.getGHNManager(scope);
|
||||
GHNManagerLibrary ghnManager = this.getGHNManager(scope);
|
||||
|
||||
ServerConsole.trace(LOG_PREFIX, "Shutting down " + scope.toString() + " " + this.getType() + " " + this.getID());
|
||||
|
||||
|
@ -196,12 +191,13 @@ public class GHNManager extends AbstractResourceManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected final GCUBEResource buildGCUBEResource(final String xmlRepresentation)
|
||||
throws AbstractResourceException {
|
||||
protected final Resource buildResource(final String xmlRepresentation) throws AbstractResourceException {
|
||||
try {
|
||||
GCUBEHostingNode impl = GHNContext.getImplementation(GCUBEHostingNode.class);
|
||||
impl.load(new StringReader(xmlRepresentation));
|
||||
return impl;
|
||||
JAXBContext ctx = JAXBContext.newInstance(HostingNode.class);
|
||||
Unmarshaller unmarshaller = ctx.createUnmarshaller();
|
||||
StringReader reader = new StringReader(xmlRepresentation);
|
||||
HostingNode deserialised = (HostingNode) unmarshaller.unmarshal(reader);
|
||||
return deserialised;
|
||||
} catch (Exception e) {
|
||||
throw new ResourceAccessException("Cannot load the stub for resource " + this.getType(), e);
|
||||
}
|
||||
|
|
|
@ -16,21 +16,36 @@
|
|||
|
||||
package org.gcube.resourcemanagement.support.server.managers.resources;
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.informationsystem.publisher.ISPublisher;
|
||||
import org.gcube.common.core.resources.GCUBEGenericResource;
|
||||
import org.gcube.common.core.resources.GCUBEResource;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.gcube.common.resources.gcore.GenericResource;
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.AbstractResourceException;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.ResourceAccessException;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.ResourceOperationException;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.ResourceParameterException;
|
||||
import org.gcube.resourcemanagement.support.server.managers.scope.ScopeManager;
|
||||
import org.gcube.resourcemanagement.support.server.types.AllowedResourceTypes;
|
||||
import org.gcube.resourcemanagement.support.server.utils.Assertion;
|
||||
import org.gcube.resourcemanagement.support.server.utils.ServerConsole;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -101,103 +116,123 @@ public class GenericResourceManager extends AbstractResourceManager {
|
|||
* @param subType (optional) if null it will not be changed
|
||||
* @param scope (optional) if null it will not be changed
|
||||
* @throws AbstractResourceException
|
||||
* @throws ParserConfigurationException
|
||||
* @throws SAXException
|
||||
* @throws IOException
|
||||
*/
|
||||
public final void update(
|
||||
final String name,
|
||||
final String description,
|
||||
final String body,
|
||||
final String subType,
|
||||
final GCUBEScope scope)
|
||||
throws AbstractResourceException {
|
||||
public final void update(final String name, final String description, final String body, final String subType, final ScopeBean scope) throws Exception {
|
||||
|
||||
Assertion<AbstractResourceException> checker = new Assertion<AbstractResourceException>();
|
||||
checker.validate(name != null && name.trim().length() != 0, new ResourceParameterException("Invalid field name. Null or empty value not allowed"));
|
||||
|
||||
ServerConsole.trace(LOG_PREFIX, "[RES-UPDATE] updating resource " + this.getType() + " " + this.getID());
|
||||
|
||||
GCUBEGenericResource res = (GCUBEGenericResource) this.getGCUBEResource(scope);
|
||||
res.setName(name.trim());
|
||||
GenericResource resource = getResourceToEditById(this.getID(), scope);
|
||||
resource.profile().name(name.trim());
|
||||
|
||||
if (description != null) {
|
||||
res.setDescription(description.trim());
|
||||
resource.profile().description(description.trim());
|
||||
}
|
||||
if (body != null) {
|
||||
res.setBody(body.trim());
|
||||
appendXmlFragment(resource.profile().newBody(), body);
|
||||
}
|
||||
if (subType != null) {
|
||||
res.setSecondaryType(subType.trim());
|
||||
}
|
||||
try {
|
||||
this.getISPublisher().updateGCUBEResource(res, scope, this.getSecurityManager());
|
||||
|
||||
/* FIXME old release
|
||||
* List<GCUBEScope> boundedScopes = this.validateScopes(res.getScopes().values().toArray(new GCUBEScope[]{}));
|
||||
|
||||
|
||||
for (GCUBEScope _scope : boundedScopes) {
|
||||
ServerConsole.trace(LOG_PREFIX, "[RES-UPDATE] ISPublisher updating resource " + this.getType() + " " + this.getID() + " in scope: [" + _scope + "]");
|
||||
this.getISPublisher().updateGCUBEResource(res, _scope, this.getSecurityManager());
|
||||
}
|
||||
*/
|
||||
} catch (Exception e) {
|
||||
throw new ResourceOperationException(e.getMessage());
|
||||
if (subType != null)
|
||||
resource.profile().type(subType.trim());
|
||||
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
RegistryPublisher publisher = getRegistryPublisher();
|
||||
String id = publisher.update(resource).id();
|
||||
|
||||
if (id == null || id.length() == 0) {
|
||||
throw new Exception("The GenericResource has not been updated");
|
||||
}
|
||||
ScopeProvider.instance.set(currScope);
|
||||
ServerConsole.info(LOG_PREFIX, "Resource Updated with ID: " + id);
|
||||
}
|
||||
|
||||
private GenericResource getResourceToEditById(String id, ScopeBean scope) throws Exception {
|
||||
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
|
||||
SimpleQuery query = queryFor(GenericResource.class);
|
||||
query.addCondition("$resource/ID/text() eq '"+ id +"'");
|
||||
|
||||
DiscoveryClient<GenericResource> client = clientFor(GenericResource.class);
|
||||
|
||||
List<GenericResource> r = client.submit(query);
|
||||
|
||||
ScopeProvider.instance.set(currScope);
|
||||
if (r == null || r.isEmpty())
|
||||
throw new Exception("Could not retrieve GenericResource profile with id " + id + " in scope + " +scope);
|
||||
else
|
||||
return r.get(0);
|
||||
}
|
||||
/**
|
||||
* Creates a Generic Resource and returns the ID given by the
|
||||
* resource manager at creation phase.
|
||||
* @return the id assigned to the newly created resource
|
||||
*/
|
||||
public static final synchronized String create(
|
||||
final String ID,
|
||||
final GCUBEScope scope,
|
||||
final String name,
|
||||
final String description,
|
||||
final String body,
|
||||
final String subType)
|
||||
public static final synchronized String create(final String ID, final ScopeBean scope, final String name, final String description, final String body, final String subType)
|
||||
throws Exception {
|
||||
Assertion<AbstractResourceException> checker = new Assertion<AbstractResourceException>();
|
||||
checker.validate(name != null && name.trim().length() != 0, new ResourceParameterException("Invalid field name. Null or empty value not allowed"));
|
||||
checker.validate(subType != null && subType.trim().length() != 0, new ResourceParameterException("Invalid field subType. Null or empty value not allowed"));
|
||||
|
||||
GCUBEGenericResource resource = GHNContext.getImplementation(GCUBEGenericResource.class);
|
||||
if (ID != null) {
|
||||
resource.setID(ID);
|
||||
}
|
||||
resource.setName(name.trim());
|
||||
GenericResource resource = new GenericResource();
|
||||
resource.newProfile().name(name.trim());
|
||||
|
||||
if (description != null) {
|
||||
resource.setDescription(description.trim());
|
||||
resource.profile().description(description.trim());
|
||||
}
|
||||
if (body != null) {
|
||||
resource.setBody(body.trim());
|
||||
appendXmlFragment(resource.profile().newBody(), body);
|
||||
}
|
||||
resource.setSecondaryType(subType.trim());
|
||||
resource.addScope(scope);
|
||||
resource.profile().type(subType.trim());
|
||||
|
||||
|
||||
GenericResourceManager gm = new GenericResourceManager();
|
||||
ISPublisher publisher = gm.getISPublisher();
|
||||
String retval = publisher.registerGCUBEResource(resource, scope, gm.getSecurityManager());
|
||||
|
||||
if (retval == null || retval.length() == 0) {
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
RegistryPublisher publisher = gm.getRegistryPublisher();
|
||||
String id = publisher.create(resource).id();
|
||||
|
||||
if (id == null || id.length() == 0) {
|
||||
throw new Exception("The GenericResource has not been created");
|
||||
}
|
||||
|
||||
Document doc = ScopeManager.getDocumentGivenXML(retval);
|
||||
String id = doc.getElementsByTagName("ID").item(0).getFirstChild().getNodeValue();
|
||||
|
||||
ScopeProvider.instance.set(currScope);
|
||||
ServerConsole.info(LOG_PREFIX, "Resource Created with ID: " + id);
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final GCUBEResource buildGCUBEResource(
|
||||
final String xmlRepresentation) throws AbstractResourceException {
|
||||
protected final Resource buildResource(final String xmlRepresentation) throws AbstractResourceException {
|
||||
try {
|
||||
GCUBEGenericResource impl = GHNContext.getImplementation(GCUBEGenericResource.class);
|
||||
impl.load(new StringReader(xmlRepresentation));
|
||||
return impl;
|
||||
JAXBContext ctx = JAXBContext.newInstance(GenericResource.class);
|
||||
Unmarshaller unmarshaller = ctx.createUnmarshaller();
|
||||
StringReader reader = new StringReader(xmlRepresentation);
|
||||
GenericResource deserialised = (GenericResource) unmarshaller.unmarshal(reader);
|
||||
return deserialised;
|
||||
} catch (Exception e) {
|
||||
throw new ResourceAccessException("Cannot load the stub for resource " + this.getType(), e);
|
||||
throw new ResourceAccessException("Cannot load the resource " + this.getType(), e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* append a well formed xml string to the body
|
||||
* @param parent
|
||||
* @param fragment
|
||||
* @throws IOException
|
||||
* @throws SAXException
|
||||
* @throws ParserConfigurationException
|
||||
*/
|
||||
public static void appendXmlFragment(Node parent, String fragment) throws IOException, SAXException, ParserConfigurationException {
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Document doc = parent.getOwnerDocument();
|
||||
Node fragmentNode = docBuilder.parse(new InputSource(new StringReader(fragment))).getDocumentElement();
|
||||
fragmentNode = doc.importNode(fragmentNode, true);
|
||||
parent.appendChild(fragmentNode);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,18 +16,21 @@
|
|||
|
||||
package org.gcube.resourcemanagement.support.server.managers.resources;
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||
|
||||
import java.io.File;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.gcube.common.core.faults.GCUBEFault;
|
||||
import org.gcube.common.core.informationsystem.client.AtomicCondition;
|
||||
import org.gcube.common.core.informationsystem.client.queries.GCUBEServiceQuery;
|
||||
import org.gcube.common.core.resources.GCUBEResource;
|
||||
import org.gcube.common.core.resources.GCUBEService;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.scope.GCUBEScope.Type;
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.common.resources.gcore.Software;
|
||||
import org.gcube.common.resources.gcore.Software.Profile.ServicePackage;
|
||||
import org.gcube.common.resources.gcore.Software.Profile.SoftwarePackage;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.AbstractResourceException;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.ResourceAccessException;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.ResourceOperationException;
|
||||
|
@ -36,12 +39,15 @@ import org.gcube.resourcemanagement.support.server.managers.scope.ScopeManager;
|
|||
import org.gcube.resourcemanagement.support.server.types.AllowedResourceTypes;
|
||||
import org.gcube.resourcemanagement.support.server.utils.Assertion;
|
||||
import org.gcube.resourcemanagement.support.server.utils.ServerConsole;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.AddResourcesParameters;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.PackageItem;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.ResourceBinderPortType;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.ResourceItem;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.ResourceList;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.SoftwareList;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.gcube.vremanagement.resourcemanager.client.RMBinderLibrary;
|
||||
import org.gcube.vremanagement.resourcemanager.client.fws.Types.AddResourcesParameters;
|
||||
import org.gcube.vremanagement.resourcemanager.client.fws.Types.PackageItem;
|
||||
import org.gcube.vremanagement.resourcemanager.client.fws.Types.ResourceItem;
|
||||
import org.gcube.vremanagement.resourcemanager.client.fws.Types.ResourceList;
|
||||
import org.gcube.vremanagement.resourcemanager.client.fws.Types.SoftwareList;
|
||||
|
||||
|
||||
/**
|
||||
* A support class containing operations to manage multiple resources.
|
||||
|
@ -63,8 +69,8 @@ public class ManagementUtils {
|
|||
public static final synchronized String addToExistingScope(
|
||||
final AllowedResourceTypes type,
|
||||
final String[] resourceIDs,
|
||||
final GCUBEScope sourceScope,
|
||||
final GCUBEScope targetScope)
|
||||
final ScopeBean sourceScope,
|
||||
final ScopeBean targetScope)
|
||||
throws Exception {
|
||||
ServerConsole.trace(
|
||||
LOG_PREFIX,
|
||||
|
@ -77,7 +83,7 @@ public class ManagementUtils {
|
|||
// 1 - If not RI or GHN and the scopes are sibling and VO copyFromToVO
|
||||
if (!(type == AllowedResourceTypes.GHN) &&
|
||||
!(type == AllowedResourceTypes.RunningInstance) &&
|
||||
sourceScope.getType() == Type.VO && targetScope.getType() == Type.VO) {
|
||||
sourceScope.type() == Type.VO && targetScope.type() == Type.VO) {
|
||||
// Phase 1. retrieve the resource to copy
|
||||
//GCUBEResource resStub = this.getGCUBEResource(sourceScope);
|
||||
|
||||
|
@ -90,8 +96,11 @@ public class ManagementUtils {
|
|||
try {
|
||||
for (String id : resourceIDs) {
|
||||
AbstractResourceManager res = ResourceFactory.createResourceManager(type, id);
|
||||
GCUBEResource resStub = res.getGCUBEResource(sourceScope);
|
||||
res.getISPublisher().registerGCUBEResource(resStub, targetScope, res.getSecurityManager());
|
||||
Resource resStub = res.getResource(sourceScope);
|
||||
String curr = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(targetScope.toString());
|
||||
res.getRegistryPublisher().update(resStub);
|
||||
ScopeProvider.instance.set(curr);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ResourceAccessException(e.getMessage());
|
||||
|
@ -102,7 +111,7 @@ public class ManagementUtils {
|
|||
// Add a gCube Resource to
|
||||
// (i) a VRE scope from the parent VO or
|
||||
// (ii) a VO scope from the infrastructure scope
|
||||
if (!targetScope.isEnclosedIn(sourceScope)) {
|
||||
if (sourceScope.toString().contains(targetScope.toString())) {
|
||||
throw new ResourceOperationException(
|
||||
"You are not allowed to apply to this scope. Target scope is not enclosed in the source one.");
|
||||
}
|
||||
|
@ -120,7 +129,7 @@ public class ManagementUtils {
|
|||
* @return the generated report ID
|
||||
*/
|
||||
public static final synchronized String removeFromExistingScope(final AllowedResourceTypes type, final String[] resourceIDs,
|
||||
final GCUBEScope sourceScope, final GCUBEScope targetScope) throws Exception {
|
||||
final ScopeBean sourceScope, final ScopeBean targetScope) throws Exception {
|
||||
|
||||
ServerConsole.trace(
|
||||
LOG_PREFIX,
|
||||
|
@ -154,23 +163,20 @@ public class ManagementUtils {
|
|||
* @return the ID of generated report
|
||||
* @throws AbstractResourceException
|
||||
*/
|
||||
private static synchronized String bindToScope(
|
||||
final AllowedResourceTypes type,
|
||||
final String[] resourceIDs,
|
||||
final GCUBEScope targetScope)
|
||||
throws AbstractResourceException {
|
||||
private static synchronized String bindToScope(final AllowedResourceTypes type, final String[] resourceIDs, final ScopeBean targetScope)throws AbstractResourceException {
|
||||
AddResourcesParameters addParam = new AddResourcesParameters();
|
||||
ResourceBinderPortType manager = ResourceFactory.createResourceManager(type).getResourceManager(targetScope);
|
||||
List<ResourceItem> resToBind = new Vector<ResourceItem>();
|
||||
RMBinderLibrary manager = ResourceFactory.createResourceManager(type).getResourceManager(targetScope.toString());
|
||||
ArrayList<ResourceItem> resToBind = new ArrayList<ResourceItem>();
|
||||
|
||||
for (String id : resourceIDs) {
|
||||
ResourceItem toAdd = new ResourceItem();
|
||||
toAdd.setID(id);
|
||||
toAdd.id = id;
|
||||
toAdd.setType(type.name());
|
||||
resToBind.add(toAdd);
|
||||
}
|
||||
ResourceList r = new ResourceList();
|
||||
r.setResource(resToBind.toArray(new ResourceItem[]{}));
|
||||
|
||||
r.setResource(resToBind);
|
||||
addParam.setResources(r);
|
||||
addParam.setTargetScope(targetScope.toString());
|
||||
|
||||
|
@ -191,11 +197,7 @@ public class ManagementUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static synchronized void delete(
|
||||
final AllowedResourceTypes type,
|
||||
final String[] resourceIDs,
|
||||
final GCUBEScope scope)
|
||||
throws AbstractResourceException {
|
||||
public static synchronized void delete(final AllowedResourceTypes type, final String[] resourceIDs, final ScopeBean scope) throws AbstractResourceException {
|
||||
AbstractResourceManager resource = ResourceFactory.createResourceManager(type);
|
||||
for (String id : resourceIDs) {
|
||||
try {
|
||||
|
@ -214,18 +216,14 @@ public class ManagementUtils {
|
|||
* @return the generated report ID
|
||||
* @throws Exception
|
||||
*/
|
||||
public static final synchronized String deploy(
|
||||
final GCUBEScope scope,
|
||||
final String[] ghnsID,
|
||||
final String[] servicesID)
|
||||
throws Exception {
|
||||
public static final synchronized String deploy(final ScopeBean scope, final String[] ghnsID, final String[] servicesID) throws Exception {
|
||||
Assertion<Exception> checker = new Assertion<Exception>();
|
||||
checker.validate(ghnsID != null && ghnsID.length != 0, new ResourceParameterException("Invalid ghnsID parameter. It cannot be null or empty."));
|
||||
checker.validate(servicesID != null && servicesID.length != 0, new ResourceParameterException("Invalid servicesID parameter. It cannot be null or empty."));
|
||||
checker.validate(scope != null, new Exception("Cannot retrieve the scope."));
|
||||
|
||||
AbstractResourceManager resource = ResourceFactory.createResourceManager(AllowedResourceTypes.Service);
|
||||
ResourceBinderPortType manager = ResourceFactory.createResourceManager(AllowedResourceTypes.Service).getResourceManager(scope);
|
||||
RMBinderLibrary manager = ResourceFactory.createResourceManager(AllowedResourceTypes.Service).getResourceManager(scope.toString());
|
||||
|
||||
System.out.println("\n\n**** These are the service ids to deploy on SCOPE " + scope);
|
||||
for (String sid : servicesID) {
|
||||
|
@ -236,21 +234,26 @@ public class ManagementUtils {
|
|||
System.out.println(ghn);
|
||||
}
|
||||
|
||||
List<PackageItem> serviceProfiles = new Vector<PackageItem>();
|
||||
ArrayList<PackageItem> serviceProfiles = new ArrayList<PackageItem>();
|
||||
|
||||
|
||||
// Retrieves the profiles of services
|
||||
final GCUBEServiceQuery query = resource.getISClient().getQuery(GCUBEServiceQuery.class);
|
||||
SimpleQuery query = null;
|
||||
DiscoveryClient<Software> client = clientFor(Software.class);
|
||||
|
||||
prepareServices: for (String serviceID : servicesID) {
|
||||
System.out.println("\n\n**** Query the IsClient to get the profile");
|
||||
query.clearConditions();
|
||||
query.addAtomicConditions(new AtomicCondition("/ID", serviceID));
|
||||
|
||||
System.out.println("**** Query : " + query.getExpression());
|
||||
|
||||
List<GCUBEService> results = resource.getISClient().execute(query, scope);
|
||||
System.out.println("\n\n**** Query the ICClient to get the profile");
|
||||
query = queryFor(Software.class);
|
||||
query.addCondition("$resource/Profile/ID/text() eq '" + serviceID + "'");
|
||||
|
||||
System.out.println("**** Query : " + query.toString());
|
||||
String curr = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
List<Software> results = client.submit(query);
|
||||
ScopeProvider.instance.set(curr);
|
||||
System.out.println("**** results received : " + results.size());
|
||||
|
||||
GCUBEService ret = null;
|
||||
Software ret = null;
|
||||
if (results != null && results.size() > 0) {
|
||||
ret = results.get(0);
|
||||
} else {
|
||||
|
@ -258,26 +261,26 @@ public class ManagementUtils {
|
|||
}
|
||||
|
||||
if (ret == null ||
|
||||
ret.getServiceClass() == null ||
|
||||
ret.getServiceName() == null ||
|
||||
ret.getVersion() == null) {
|
||||
ret.profile() == null ||
|
||||
ret.profile().softwareClass() == null ||
|
||||
ret.profile().softwareName() == null) {
|
||||
ServerConsole.error(LOG_PREFIX, "found an invalid service profile");
|
||||
continue;
|
||||
}
|
||||
|
||||
PackageItem toAdd = new PackageItem();
|
||||
|
||||
toAdd.setServiceClass(ret.getServiceClass());
|
||||
toAdd.setServiceName(ret.getServiceName());
|
||||
toAdd.setServiceVersion(ret.getVersion());
|
||||
if (ret.getPackages().size() == 1) {
|
||||
toAdd.setPackageName(ret.getPackages().get(0).getName());
|
||||
toAdd.setPackageVersion(ret.getPackages().get(0).getVersion());
|
||||
toAdd.serviceClass = ret.profile().softwareClass();
|
||||
toAdd.serviceName = ret.profile().softwareName();
|
||||
toAdd.serviceVersion ="1.0.0";
|
||||
if (ret.profile().packages().size() == 1) {
|
||||
toAdd.packageName = ret.profile().packages().iterator().next().name();
|
||||
toAdd.packageVersion = ret.profile().packages().iterator().next().version();
|
||||
} else {
|
||||
for (org.gcube.common.core.resources.service.Package p : ret.getPackages()) {
|
||||
if (p.getClass().isAssignableFrom(org.gcube.common.core.resources.service.MainPackage.class)) {
|
||||
toAdd.setPackageName(p.getName());
|
||||
toAdd.setPackageVersion(p.getVersion());
|
||||
for (SoftwarePackage p : ret.profile().packages()) {
|
||||
if (p.getClass().isAssignableFrom(ServicePackage.class)) {
|
||||
toAdd.packageName = p.name();
|
||||
toAdd.packageVersion = p.version();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -287,29 +290,25 @@ public class ManagementUtils {
|
|||
}
|
||||
|
||||
SoftwareList serviceList = new SoftwareList();
|
||||
serviceList.setSuggestedTargetGHNNames(ghnsID);
|
||||
serviceList.setSoftware(serviceProfiles.toArray(new PackageItem[0]));
|
||||
ArrayList<String> arrayGHNSids = new ArrayList<String>();
|
||||
for (int i = 0; i < ghnsID.length; i++) {
|
||||
arrayGHNSids.add(ghnsID[i]);
|
||||
}
|
||||
serviceList.suggestedTargetGHNNames = arrayGHNSids;
|
||||
serviceList.software = serviceProfiles;
|
||||
|
||||
AddResourcesParameters addResourcesParameters = new AddResourcesParameters();
|
||||
addResourcesParameters.setSoftware(serviceList);
|
||||
addResourcesParameters.softwareList = serviceList;
|
||||
addResourcesParameters.setTargetScope(scope.toString());
|
||||
|
||||
System.out.println("\n\n**** These is the ServiceList i pass to ResourceManagerPortType: ");
|
||||
for (int i = 0; i < serviceList.getSoftware().length; i++) {
|
||||
System.out.println(serviceList.getSoftware()[i]);
|
||||
for (int i = 0; i < serviceList.software.size(); i++) {
|
||||
System.out.println(serviceList.software.get(i));
|
||||
}
|
||||
|
||||
String id = "";
|
||||
try {
|
||||
id = manager.addResources(addResourcesParameters);
|
||||
ServerConsole.debug(LOG_PREFIX, "Report ID = " + id);
|
||||
} catch (GCUBEFault e) {
|
||||
ServerConsole.error(LOG_PREFIX, "during deployment.", e);
|
||||
throw e;
|
||||
} catch (RemoteException e) {
|
||||
ServerConsole.error(LOG_PREFIX, "during deployment.", e);
|
||||
throw e;
|
||||
}
|
||||
id = manager.addResources(addResourcesParameters);
|
||||
ServerConsole.debug(LOG_PREFIX, "Report ID = " + id);
|
||||
System.out.println("Returning.... no exceptions");
|
||||
return id;
|
||||
}
|
||||
|
@ -332,7 +331,7 @@ public class ManagementUtils {
|
|||
null,
|
||||
"test"
|
||||
},
|
||||
ScopeManager.getScope("/gcube/devsec/devVRE"));
|
||||
new ScopeBean("/gcube/devsec/devVRE"));
|
||||
} catch (Exception e) {
|
||||
ServerConsole.error(LOG_PREFIX, e);
|
||||
}
|
||||
|
|
|
@ -16,17 +16,23 @@
|
|||
|
||||
package org.gcube.resourcemanagement.support.server.managers.resources;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.informationsystem.client.AtomicCondition;
|
||||
import org.gcube.common.core.informationsystem.client.queries.GCUBEServiceQuery;
|
||||
import org.gcube.common.core.resources.GCUBEResource;
|
||||
import org.gcube.common.core.resources.GCUBERunningInstance;
|
||||
import org.gcube.common.core.resources.GCUBEService;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.common.resources.gcore.Software;
|
||||
import org.gcube.common.resources.gcore.Software.Profile.ServicePackage;
|
||||
import org.gcube.common.resources.gcore.Software.Profile.SoftwarePackage;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.AbstractResourceException;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.ResourceAccessException;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.ResourceOperationException;
|
||||
|
@ -34,15 +40,16 @@ import org.gcube.resourcemanagement.support.server.exceptions.ResourceParameterE
|
|||
import org.gcube.resourcemanagement.support.server.types.AllowedResourceTypes;
|
||||
import org.gcube.resourcemanagement.support.server.utils.Assertion;
|
||||
import org.gcube.resourcemanagement.support.server.utils.ServerConsole;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.AddResourcesParameters;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.PackageItem;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.RemoveResourcesParameters;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.ResourceBinderPortType;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.ResourceItem;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.ResourceList;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.SoftwareList;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.reporting.ReportingPortType;
|
||||
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.gcube.vremanagement.resourcemanager.client.RMBinderLibrary;
|
||||
import org.gcube.vremanagement.resourcemanager.client.RMReportingLibrary;
|
||||
import org.gcube.vremanagement.resourcemanager.client.fws.Types.AddResourcesParameters;
|
||||
import org.gcube.vremanagement.resourcemanager.client.fws.Types.PackageItem;
|
||||
import org.gcube.vremanagement.resourcemanager.client.fws.Types.RemoveResourcesParameters;
|
||||
import org.gcube.vremanagement.resourcemanager.client.fws.Types.ResourceItem;
|
||||
import org.gcube.vremanagement.resourcemanager.client.fws.Types.ResourceList;
|
||||
import org.gcube.vremanagement.resourcemanager.client.fws.Types.SoftwareList;
|
||||
|
||||
/**
|
||||
* @author Daniele Strollo (ISTI-CNR)
|
||||
|
@ -56,43 +63,57 @@ public class RunningInstanceManager extends AbstractResourceManager {
|
|||
* @deprecated discouraged use. With no ID some operations cannot be accessed.
|
||||
*/
|
||||
public RunningInstanceManager()
|
||||
throws ResourceParameterException, ResourceAccessException {
|
||||
throws ResourceParameterException, ResourceAccessException {
|
||||
super(AllowedResourceTypes.RunningInstance);
|
||||
}
|
||||
|
||||
public RunningInstanceManager(final String id)
|
||||
throws ResourceParameterException, ResourceAccessException {
|
||||
throws ResourceParameterException, ResourceAccessException {
|
||||
super(id, AllowedResourceTypes.RunningInstance);
|
||||
}
|
||||
|
||||
public RunningInstanceManager(final String id, final String name)
|
||||
throws ResourceParameterException, ResourceAccessException {
|
||||
throws ResourceParameterException, ResourceAccessException {
|
||||
super(id, name, AllowedResourceTypes.RunningInstance);
|
||||
}
|
||||
|
||||
public RunningInstanceManager(final String id, final String name, final String subType)
|
||||
throws ResourceParameterException, ResourceAccessException {
|
||||
throws ResourceParameterException, ResourceAccessException {
|
||||
super(id, name, AllowedResourceTypes.RunningInstance, subType);
|
||||
}
|
||||
|
||||
public final String deploy(
|
||||
final GCUBEScope scope, final String[] ghnsID, final String[] servicesID)
|
||||
throws ResourceParameterException, ResourceOperationException {
|
||||
/**
|
||||
*
|
||||
* @param scope
|
||||
* @param ghnsID
|
||||
* @param servicesID
|
||||
* @return
|
||||
* @throws ResourceParameterException
|
||||
* @throws ResourceOperationException
|
||||
*/
|
||||
public final String deploy(final ScopeBean scope, final String[] ghnsID, final String[] servicesID) throws ResourceParameterException, ResourceOperationException {
|
||||
Assertion<ResourceParameterException> checker = new Assertion<ResourceParameterException>();
|
||||
checker.validate(servicesID != null && servicesID.length != 0,
|
||||
new ResourceParameterException("Invalid servicesID parameter. It cannot be null or empty."));
|
||||
checker.validate(scope != null,
|
||||
new ResourceParameterException("Cannot retrieve the scope."));
|
||||
|
||||
List<PackageItem> serviceProfiles = new Vector<PackageItem>();
|
||||
ArrayList<PackageItem> serviceProfiles = new ArrayList<PackageItem>();
|
||||
|
||||
try {
|
||||
// Retrieves the profiles of services
|
||||
final GCUBEServiceQuery query = this.getISClient().getQuery(GCUBEServiceQuery.class);
|
||||
|
||||
SimpleQuery query = null;
|
||||
DiscoveryClient<Software> client = clientFor(Software.class);
|
||||
|
||||
prepareServices: for (String serviceID : servicesID) {
|
||||
query.addAtomicConditions(new AtomicCondition("/ID", serviceID));
|
||||
List<GCUBEService> results = this.getISClient().execute(query, scope);
|
||||
GCUBEService ret = null;
|
||||
query = queryFor(Software.class);
|
||||
query.addCondition("$resource/Profile/ID/text() eq '" + serviceID + "'");
|
||||
System.out.println("**** Query : " + query.toString());
|
||||
String curr = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
List<Software> results = client.submit(query);
|
||||
ScopeProvider.instance.set(curr);
|
||||
System.out.println("**** results received : " + results.size());
|
||||
Software ret = null;
|
||||
if (results != null && results.size() > 0) {
|
||||
ret = results.get(0);
|
||||
} else {
|
||||
|
@ -100,26 +121,25 @@ public class RunningInstanceManager extends AbstractResourceManager {
|
|||
}
|
||||
|
||||
if (ret == null ||
|
||||
ret.getServiceClass() == null ||
|
||||
ret.getServiceName() == null ||
|
||||
ret.getVersion() == null) {
|
||||
ret.profile() == null ||
|
||||
ret.profile().softwareClass() == null ||
|
||||
ret.profile().softwareName() == null) {
|
||||
ServerConsole.error(LOG_PREFIX, "found an invalid service profile");
|
||||
continue;
|
||||
}
|
||||
|
||||
PackageItem toAdd = new PackageItem();
|
||||
|
||||
toAdd.setServiceClass(ret.getServiceClass());
|
||||
toAdd.setServiceName(ret.getServiceName());
|
||||
toAdd.setServiceVersion(ret.getVersion());
|
||||
if (ret.getPackages().size() == 1) {
|
||||
toAdd.setPackageName(ret.getPackages().get(0).getName());
|
||||
toAdd.setPackageVersion(ret.getPackages().get(0).getVersion());
|
||||
toAdd.serviceClass = ret.profile().softwareClass();
|
||||
toAdd.serviceName = ret.profile().softwareName();
|
||||
toAdd.serviceVersion ="1.0.0";
|
||||
if (ret.profile().packages().size() == 1) {
|
||||
toAdd.packageName = ret.profile().packages().iterator().next().name();
|
||||
toAdd.packageVersion = ret.profile().packages().iterator().next().version();
|
||||
} else {
|
||||
for (org.gcube.common.core.resources.service.Package p : ret.getPackages()) {
|
||||
if (p.getClass().isAssignableFrom(org.gcube.common.core.resources.service.MainPackage.class)) {
|
||||
toAdd.setPackageName(p.getName());
|
||||
toAdd.setPackageVersion(p.getVersion());
|
||||
for (SoftwarePackage p : ret.profile().packages()) {
|
||||
if (p.getClass().isAssignableFrom(ServicePackage.class)) {
|
||||
toAdd.packageName = p.name();
|
||||
toAdd.packageVersion = p.version();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -130,29 +150,41 @@ public class RunningInstanceManager extends AbstractResourceManager {
|
|||
|
||||
SoftwareList serviceList = new SoftwareList();
|
||||
|
||||
// The GHNs are optional, suggested gHNs to use.
|
||||
if (ghnsID != null && ghnsID.length > 0) {
|
||||
serviceList.setSuggestedTargetGHNNames(ghnsID);
|
||||
ArrayList<String> arrayGHNSids = new ArrayList<String>();
|
||||
for (int i = 0; i < ghnsID.length; i++) {
|
||||
arrayGHNSids.add(ghnsID[i]);
|
||||
}
|
||||
|
||||
serviceList.setSoftware(serviceProfiles.toArray(new PackageItem[0]));
|
||||
serviceList.suggestedTargetGHNNames = arrayGHNSids;
|
||||
serviceList.software = serviceProfiles;
|
||||
|
||||
AddResourcesParameters addResourcesParameters = new AddResourcesParameters();
|
||||
addResourcesParameters.setSoftware(serviceList);
|
||||
addResourcesParameters.softwareList = serviceList;
|
||||
addResourcesParameters.setTargetScope(scope.toString());
|
||||
|
||||
String reportID = this.getResourceManager(scope).addResources(addResourcesParameters);
|
||||
ServerConsole.debug(LOG_PREFIX, "Report ID = " + reportID);
|
||||
return reportID;
|
||||
System.out.println("\n\n**** These is the ServiceList i pass to ResourceManagerPortType: ");
|
||||
for (int i = 0; i < serviceList.software.size(); i++) {
|
||||
System.out.println(serviceList.software.get(i));
|
||||
}
|
||||
|
||||
String id = "";
|
||||
RMBinderLibrary manager = ResourceFactory.createResourceManager(AllowedResourceTypes.Service).getResourceManager(scope.toString());
|
||||
String curr = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
id = manager.addResources(addResourcesParameters);
|
||||
ScopeProvider.instance.set(curr);
|
||||
return id;
|
||||
} catch (Exception e) {
|
||||
ServerConsole.error(LOG_PREFIX, "Error during deployment.", e);
|
||||
throw new ResourceOperationException("Software deployment failure: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public final String undeploy(
|
||||
final GCUBEScope scope)
|
||||
throws AbstractResourceException {
|
||||
/**
|
||||
*
|
||||
* @param scope
|
||||
* @return
|
||||
* @throws AbstractResourceException
|
||||
*/
|
||||
public final String undeploy(final ScopeBean scope) throws AbstractResourceException {
|
||||
Assertion<AbstractResourceException> checker = new Assertion<AbstractResourceException>();
|
||||
checker.validate(scope != null,
|
||||
new ResourceParameterException("Cannot retrieve the scope."));
|
||||
|
@ -160,17 +192,19 @@ public class RunningInstanceManager extends AbstractResourceManager {
|
|||
new ResourceOperationException("Invalid ID."));
|
||||
|
||||
try {
|
||||
ResourceBinderPortType rm = this.getResourceManager(scope);
|
||||
RMBinderLibrary rm = ResourceFactory.createResourceManager(AllowedResourceTypes.Service).getResourceManager(scope.toString());
|
||||
//prepare the parameters
|
||||
RemoveResourcesParameters params = new RemoveResourcesParameters();
|
||||
ResourceItem[] resourcelist = new ResourceItem[1];
|
||||
resourcelist[0] = new ResourceItem();
|
||||
resourcelist[0].setID(this.getID());
|
||||
resourcelist[0].setType(this.getType().name());
|
||||
resourcelist[0].id = this.getID();
|
||||
resourcelist[0].type = this.getType().name();
|
||||
ResourceList r = new ResourceList();
|
||||
r.setResource(resourcelist);
|
||||
params.setResources(r);
|
||||
params.setTargetScope(scope.toString());
|
||||
ArrayList<ResourceItem> temp =new ArrayList<ResourceItem>();
|
||||
temp.add(resourcelist[0]);
|
||||
r.setResource(temp);
|
||||
params.resources = r;
|
||||
params.targetScope = scope.toString();
|
||||
|
||||
//sending the request
|
||||
ServerConsole.info(LOG_PREFIX, "Sending the Remove Resource request....");
|
||||
|
@ -183,15 +217,15 @@ public class RunningInstanceManager extends AbstractResourceManager {
|
|||
}
|
||||
}
|
||||
|
||||
public final String checkDeployStatus(final GCUBEScope scope, final String deployID)
|
||||
throws AbstractResourceException {
|
||||
public final String checkDeployStatus(final ScopeBean scope, final String deployID)
|
||||
throws AbstractResourceException {
|
||||
Assertion<ResourceParameterException> checker = new Assertion<ResourceParameterException>();
|
||||
checker.validate(scope != null,
|
||||
new ResourceParameterException("Invalid scope passed"));
|
||||
checker.validate(deployID != null && deployID.trim().length() > 0,
|
||||
new ResourceParameterException("Invalid reportID passed"));
|
||||
|
||||
ReportingPortType vreManagerPortType = this.getReportResourceManager(scope);
|
||||
RMReportingLibrary vreManagerPortType = this.getReportResourceManager(scope.toString());
|
||||
|
||||
try {
|
||||
return vreManagerPortType.getReport(deployID);
|
||||
|
@ -202,14 +236,16 @@ public class RunningInstanceManager extends AbstractResourceManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected final GCUBEResource buildGCUBEResource(final String xmlRepresentation)
|
||||
throws AbstractResourceException {
|
||||
protected final Resource buildResource(final String xmlRepresentation) throws AbstractResourceException {
|
||||
try {
|
||||
GCUBERunningInstance impl = GHNContext.getImplementation(GCUBERunningInstance.class);
|
||||
impl.load(new StringReader(xmlRepresentation));
|
||||
return impl;
|
||||
JAXBContext ctx = JAXBContext.newInstance(GCoreEndpoint.class);
|
||||
Unmarshaller unmarshaller = ctx.createUnmarshaller();
|
||||
StringReader reader = new StringReader(xmlRepresentation);
|
||||
GCoreEndpoint deserialised = (GCoreEndpoint) unmarshaller.unmarshal(reader);
|
||||
return deserialised;
|
||||
} catch (Exception e) {
|
||||
throw new ResourceAccessException("Cannot load the stub for resource " + this.getType(), e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,10 +18,12 @@ package org.gcube.resourcemanagement.support.server.managers.resources;
|
|||
|
||||
import java.io.StringReader;
|
||||
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.resources.GCUBEResource;
|
||||
import org.gcube.common.core.resources.GCUBERuntimeResource;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.AbstractResourceException;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.ResourceAccessException;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.ResourceOperationException;
|
||||
|
@ -29,8 +31,7 @@ import org.gcube.resourcemanagement.support.server.exceptions.ResourceParameterE
|
|||
import org.gcube.resourcemanagement.support.server.types.AllowedResourceTypes;
|
||||
import org.gcube.resourcemanagement.support.server.utils.Assertion;
|
||||
import org.gcube.resourcemanagement.support.server.utils.ServerConsole;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.binder.ResourceBinderPortType;
|
||||
import org.gcube.vremanagement.resourcemanager.stubs.reporting.ReportingPortType;
|
||||
import org.gcube.vremanagement.resourcemanager.client.RMReportingLibrary;
|
||||
|
||||
|
||||
|
||||
|
@ -77,7 +78,7 @@ public class RuntimeResourceManager extends AbstractResourceManager {
|
|||
}
|
||||
|
||||
|
||||
public final String checkDeployStatus(final GCUBEScope scope, final String deployID)
|
||||
public final String checkDeployStatus(final ScopeBean scope, final String deployID)
|
||||
throws AbstractResourceException {
|
||||
Assertion<ResourceParameterException> checker = new Assertion<ResourceParameterException>();
|
||||
checker.validate(scope != null,
|
||||
|
@ -85,7 +86,7 @@ public class RuntimeResourceManager extends AbstractResourceManager {
|
|||
checker.validate(deployID != null && deployID.trim().length() > 0,
|
||||
new ResourceParameterException("Invalid reportID passed"));
|
||||
|
||||
ReportingPortType vreManagerPortType = this.getReportResourceManager(scope);
|
||||
RMReportingLibrary vreManagerPortType = this.getReportResourceManager(scope.name());
|
||||
|
||||
try {
|
||||
return vreManagerPortType.getReport(deployID);
|
||||
|
@ -96,14 +97,16 @@ public class RuntimeResourceManager extends AbstractResourceManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected final GCUBEResource buildGCUBEResource(final String xmlRepresentation)
|
||||
throws AbstractResourceException {
|
||||
protected final Resource buildResource(final String xmlRepresentation) throws AbstractResourceException {
|
||||
try {
|
||||
GCUBERuntimeResource impl = GHNContext.getImplementation(GCUBERuntimeResource.class);
|
||||
impl.load(new StringReader(xmlRepresentation));
|
||||
return impl;
|
||||
JAXBContext ctx = JAXBContext.newInstance(ServiceEndpoint.class);
|
||||
Unmarshaller unmarshaller = ctx.createUnmarshaller();
|
||||
StringReader reader = new StringReader(xmlRepresentation);
|
||||
ServiceEndpoint deserialised = (ServiceEndpoint) unmarshaller.unmarshal(reader);
|
||||
return deserialised;
|
||||
} catch (Exception e) {
|
||||
throw new ResourceAccessException("Cannot load the stub for resource " + this.getType(), e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,12 @@
|
|||
package org.gcube.resourcemanagement.support.server.managers.resources;
|
||||
|
||||
import java.io.StringReader;
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.resources.GCUBEResource;
|
||||
import org.gcube.common.core.resources.GCUBEService;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.common.resources.gcore.Software;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.AbstractResourceException;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.ResourceAccessException;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.ResourceParameterException;
|
||||
|
@ -70,14 +73,16 @@ public class ServiceManager extends AbstractResourceManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected final GCUBEResource buildGCUBEResource(final String xmlRepresentation)
|
||||
throws AbstractResourceException {
|
||||
protected final Resource buildResource(final String xmlRepresentation) throws AbstractResourceException {
|
||||
try {
|
||||
GCUBEService impl = GHNContext.getImplementation(GCUBEService.class);
|
||||
impl.load(new StringReader(xmlRepresentation));
|
||||
return impl;
|
||||
JAXBContext ctx = JAXBContext.newInstance(Software.class);
|
||||
Unmarshaller unmarshaller = ctx.createUnmarshaller();
|
||||
StringReader reader = new StringReader(xmlRepresentation);
|
||||
Software deserialised = (Software) unmarshaller.unmarshal(reader);
|
||||
return deserialised;
|
||||
} catch (Exception e) {
|
||||
throw new ResourceAccessException("Cannot load the stub for resource " + this.getType(), e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
/****************************************************************************
|
||||
* This software is part of the gCube System.
|
||||
* Site: http://www.gcube-system.org/
|
||||
****************************************************************************
|
||||
* The gCube/gCore software is licensed as Free Open Source software
|
||||
* conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
|
||||
* The software and documentation is provided by its authors/distributors
|
||||
* "as is" and no expressed or
|
||||
* implied warranty is given for its use, quality or fitness for a
|
||||
* particular case.
|
||||
****************************************************************************
|
||||
* Filename: MetadataCollectionManager.java
|
||||
****************************************************************************
|
||||
* @author <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
|
||||
***************************************************************************/
|
||||
|
||||
package org.gcube.resourcemanagement.support.server.managers.resources;
|
||||
|
||||
import java.io.StringReader;
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.resources.GCUBEMCollection;
|
||||
import org.gcube.common.core.resources.GCUBEResource;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.AbstractResourceException;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.ResourceAccessException;
|
||||
import org.gcube.resourcemanagement.support.server.exceptions.ResourceParameterException;
|
||||
import org.gcube.resourcemanagement.support.server.types.AllowedResourceTypes;
|
||||
|
||||
/**
|
||||
* @author Daniele Strollo (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
public class ViewManager extends AbstractResourceManager {
|
||||
|
||||
/**
|
||||
* @deprecated discouraged use. With no ID some operations cannot be accessed.
|
||||
*/
|
||||
public ViewManager()
|
||||
throws ResourceParameterException,
|
||||
ResourceAccessException {
|
||||
super(AllowedResourceTypes.VIEW);
|
||||
}
|
||||
|
||||
public ViewManager(final String id)
|
||||
throws ResourceParameterException,
|
||||
ResourceAccessException {
|
||||
super(id, AllowedResourceTypes.VIEW);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @param name
|
||||
* @param type
|
||||
* @throws ResourceParameterException
|
||||
* @throws ResourceAccessException
|
||||
*/
|
||||
public ViewManager(final String id, final String name)
|
||||
throws ResourceParameterException,
|
||||
ResourceAccessException {
|
||||
super(id, name, AllowedResourceTypes.VIEW);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @param name
|
||||
* @param type
|
||||
* @param subtype
|
||||
* @throws ResourceParameterException
|
||||
* @throws ResourceAccessException
|
||||
*/
|
||||
public ViewManager(final String id, final String name, final String subtype)
|
||||
throws ResourceParameterException, ResourceAccessException {
|
||||
super(id, name, AllowedResourceTypes.VIEW, subtype);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final GCUBEResource buildGCUBEResource(final String xmlRepresentation)
|
||||
throws AbstractResourceException {
|
||||
try {
|
||||
GCUBEMCollection impl = GHNContext.getImplementation(GCUBEMCollection.class);
|
||||
impl.load(new StringReader(xmlRepresentation));
|
||||
return impl;
|
||||
} catch (Exception e) {
|
||||
throw new ResourceAccessException("Cannot load the stub for resource " + this.getType(), e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,10 @@
|
|||
/****************************************************************************
|
||||
|
||||
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* This software is part of the gCube Project.
|
||||
* Site: http://www.gcube-system.org/
|
||||
****************************************************************************
|
||||
|
@ -16,19 +22,30 @@
|
|||
|
||||
package org.gcube.resourcemanagement.support.server.tests;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.core.contexts.GHNContext.Status;
|
||||
import org.gcube.common.core.resources.GCUBEHostingNode;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.scope.GCUBEScope.Type;
|
||||
import org.gcube.common.resources.gcore.HostingNode;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.resourcemanagement.support.client.utils.StatusHandler;
|
||||
import org.gcube.resourcemanagement.support.server.gcube.CacheManager;
|
||||
import org.gcube.resourcemanagement.support.server.gcube.ISClientRequester;
|
||||
import org.gcube.resourcemanagement.support.server.gcube.queries.QueryLoader;
|
||||
import org.gcube.resourcemanagement.support.server.gcube.queries.QueryLocation;
|
||||
import org.gcube.resourcemanagement.support.server.managers.resources.GHNManager;
|
||||
import org.gcube.resourcemanagement.support.server.managers.resources.GenericResourceManager;
|
||||
import org.gcube.resourcemanagement.support.server.managers.resources.ResourceFactory;
|
||||
import org.gcube.resourcemanagement.support.server.managers.scope.ScopeManager;
|
||||
import org.gcube.resourcemanagement.support.server.types.AllowedResourceTypes;
|
||||
import org.gcube.resourcemanagement.support.server.utils.ServerConsole;
|
||||
import org.gcube.resourcemanagement.support.shared.types.datamodel.ResourceDescriptor;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
||||
|
||||
/**
|
||||
* @author Daniele Strollo (ISTI-CNR)
|
||||
|
@ -37,37 +54,6 @@ import org.gcube.resourcemanagement.support.server.utils.ServerConsole;
|
|||
public class GenericTest {
|
||||
private static final String LOG_PREFIX = "[SW-SUPPORT-TEST]";
|
||||
|
||||
public static void testScope() {
|
||||
|
||||
try {
|
||||
Map<String, GCUBEScope> scopes = ScopeManager.getAvailableScopes();
|
||||
|
||||
System.out.println("\n\n\n******************** TEST SCOPE ***************\n");
|
||||
for (GCUBEScope scope : scopes.values()) {
|
||||
if ((scope.getType().compareTo(Type.INFRASTRUCTURE) == 0)
|
||||
|| (scope.getType().compareTo(Type.VO) == 0)) {
|
||||
if (scope.getServiceMap() != null) {
|
||||
ServerConsole.trace(null, "*** Map loaded for " + scope.getType() + " " + scope.toString() + " [OK]");
|
||||
} else {
|
||||
ServerConsole.trace(null, "*** Map loaded for " + scope.getType() + " " + scope.toString() + " [ERR]");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
if (scope.getEnclosingScope().getServiceMap() != null) {
|
||||
ServerConsole.trace(null, "*** Map loaded for " + scope.getType() + scope.toString() + " [OK]");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ServerConsole.trace(null, "*** Map loaded for " + scope.getType() + scope.toString() + " [ERR]");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
System.out.println("\n******************** TEST SCOPE END ***************\n");
|
||||
}
|
||||
}
|
||||
|
||||
public static String testCreation() {
|
||||
System.out.println("\n\n\n******************** TEST CREATION ***************");
|
||||
|
||||
|
@ -76,11 +62,11 @@ public class GenericTest {
|
|||
try {
|
||||
resID = GenericResourceManager.create(
|
||||
null,
|
||||
ScopeManager.getScope("/gcube/devsec"),
|
||||
"GR Test",
|
||||
"GR Test Description",
|
||||
new ScopeBean("/gcube/devsec"),
|
||||
"RMP Test",
|
||||
"RMP Test Description",
|
||||
"<TestBody>Hello</TestBody>",
|
||||
"XXX");
|
||||
"test");
|
||||
ServerConsole.trace(null, "Generic Resource Created with ID: " + resID);
|
||||
} catch (Exception e) {
|
||||
ServerConsole.error(LOG_PREFIX, e);
|
||||
|
@ -95,7 +81,7 @@ public class GenericTest {
|
|||
try {
|
||||
GenericResourceManager res = new GenericResourceManager(resID);
|
||||
ServerConsole.trace(null,
|
||||
res.addToExistingScope(ScopeManager.getScope(fromScope), ScopeManager.getScope(toScope))
|
||||
res.addToExistingScope(new ScopeBean(fromScope), new ScopeBean(toScope))
|
||||
);
|
||||
} catch (Exception e) {
|
||||
ServerConsole.error(LOG_PREFIX, e);
|
||||
|
@ -104,11 +90,11 @@ public class GenericTest {
|
|||
}
|
||||
}
|
||||
|
||||
public static void testResourceEdit(final String resID, final GCUBEScope scope) {
|
||||
public static void testResourceEdit(final String resID, final ScopeBean scope) {
|
||||
System.out.println("\n\n\n******************** TEST RESEDIT COPY ***************");
|
||||
try {
|
||||
GenericResourceManager res = new GenericResourceManager(resID);
|
||||
res.update("New Name", "updated description", null, null, scope);
|
||||
res.update(res.getName()+" Edited", "updated description", "<update>updated body</update>", "test2", scope);
|
||||
} catch (Exception e) {
|
||||
ServerConsole.error(LOG_PREFIX, e);
|
||||
} finally {
|
||||
|
@ -118,18 +104,19 @@ public class GenericTest {
|
|||
|
||||
public static void testModeGHN(final String resID, final String scope)
|
||||
throws Exception {
|
||||
GCUBEScope queryScope = ScopeManager.getScope(scope);
|
||||
ScopeBean queryScope = new ScopeBean(scope);
|
||||
GHNManager ghnManager = new GHNManager(resID);
|
||||
GCUBEHostingNode res = (GCUBEHostingNode) ghnManager.getGCUBEResource(queryScope);
|
||||
res.getNodeDescription().setStatus(Status.UNREACHABLE);
|
||||
ghnManager.getISPublisher().updateGCUBEResource(res, queryScope, ghnManager.getSecurityManager());
|
||||
HostingNode res = (HostingNode) ghnManager.getResource(queryScope);
|
||||
res.profile().description().status("CERTIFIED");
|
||||
ScopeProvider.instance.set(queryScope.name());
|
||||
ghnManager.getRegistryPublisher().update(res);
|
||||
}
|
||||
|
||||
public static void testGHN() {
|
||||
System.out.println("\n\n\n******************** TEST GHN ***************");
|
||||
try {
|
||||
GHNManager ghn1 = new GHNManager("20ddb210-b779-11df-96c9-a66904b26e27", "pc-strollo");
|
||||
ghn1.addToExistingScope(ScopeManager.getScope("/gcube"), ScopeManager.getScope("/gcube/devsec"));
|
||||
GHNManager ghn1 = new GHNManager("796f0680-3937-11e2-9d5f-ae6a92affb51", "pcd4science3.cern.ch");
|
||||
ghn1.addToExistingScope(new ScopeBean("/gcube"), new ScopeBean("/gcube/devsec"));
|
||||
} catch (Exception e) {
|
||||
ServerConsole.error(LOG_PREFIX, e);
|
||||
} finally {
|
||||
|
@ -137,7 +124,7 @@ public class GenericTest {
|
|||
}
|
||||
}
|
||||
|
||||
public static void testRemoveFromScope(final String resID, final GCUBEScope scope) {
|
||||
public static void testRemoveFromScope(final String resID, final ScopeBean scope) {
|
||||
System.out.println("\n\n\n******************** TEST RESOURCE REMOVEFROMSCOPE ***************");
|
||||
try {
|
||||
GenericResourceManager res = new GenericResourceManager(resID);
|
||||
|
@ -149,7 +136,8 @@ public class GenericTest {
|
|||
}
|
||||
}
|
||||
|
||||
public static void testDelete(final String resID, final GCUBEScope scope) {
|
||||
|
||||
public static void testDelete(final String resID, final ScopeBean scope) {
|
||||
System.out.println("\n\n\n******************** TEST RESOURCE DELETE ***************");
|
||||
try {
|
||||
GenericResourceManager res = new GenericResourceManager(resID);
|
||||
|
@ -161,27 +149,50 @@ public class GenericTest {
|
|||
}
|
||||
}
|
||||
|
||||
private static void testTree(ScopeBean scope) throws Exception {
|
||||
|
||||
CacheManager cm = new CacheManager();
|
||||
cm.setUseCache(false);
|
||||
HashMap<String, ArrayList<String>> results = ISClientRequester.getResourcesTree(cm, scope);
|
||||
for (String res : results.keySet()) {
|
||||
System.out.println(res);
|
||||
for (String sub : results.get(res)) {
|
||||
System.out.println(sub);
|
||||
}
|
||||
}
|
||||
|
||||
List<ResourceDescriptor> descs = ISClientRequester.getResourceModels(scope, "GenericResource", null, null);
|
||||
for (ResourceDescriptor resourceDescriptor : descs) {
|
||||
System.out.println(resourceDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void main(final String[] args) throws Exception {
|
||||
// The scopes must be initialized
|
||||
ScopeManager.setScopeConfigFile("test-suite" + File.separator + "scopes" + File.separator + "scopedata_admin.xml");
|
||||
|
||||
boolean deepTest = false;
|
||||
// testScope();
|
||||
// testGHN();
|
||||
if (deepTest) {
|
||||
ScopeProvider.instance.set("/gcube/devsec");
|
||||
|
||||
//testTree( new ScopeBean("/gcube"));
|
||||
|
||||
// boolean deepTest = true;
|
||||
//
|
||||
// // testGHN();
|
||||
// if (deepTest) {
|
||||
String resID = testCreation();
|
||||
testScopeCopy(resID, "/gcube/devsec", "/gcube/devsec/devVRE");
|
||||
|
||||
System.out.println("\n\nWaiting for resource refresh 60secs.\n\n\n");
|
||||
Thread.sleep(60000);
|
||||
|
||||
//testResourceEdit(resID, ScopeManager.getScope("/gcube/devsec"));
|
||||
testDelete(resID, ScopeManager.getScope("/gcube/devsec/devVRE"));
|
||||
|
||||
// testRemoveFromScope(resID, ScopeManager.getScope("/gcube/devsec"));
|
||||
} else {
|
||||
testModeGHN("f5cb0640-f1a7-11df-93d0-fc409084cf46", "/gcube/devsec/devVRE");
|
||||
}
|
||||
//////
|
||||
// System.out.println("\n\nWaiting for resource refresh 20secs.\n\n\n");
|
||||
// Thread.sleep(20000);
|
||||
//
|
||||
//
|
||||
// //testResourceEdit(resID, new ScopeBean("/gcube/devsec"));
|
||||
// //testDelete(resID, new ScopeBean("/gcube/devsec"));
|
||||
//
|
||||
// testRemoveFromScope(resID, new ScopeBean("/gcube/devsec/devVRE"));
|
||||
// } else {
|
||||
// testModeGHN("796f0680-3937-11e2-9d5f-ae6a92affb51", "/gcube/devsec/devVRE");
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import java.io.Serializable;
|
|||
|
||||
import org.gcube.resourcemanagement.support.client.views.ResourceTypeDecorator;
|
||||
|
||||
|
||||
import com.google.gwt.user.client.rpc.IsSerializable;
|
||||
|
||||
/**
|
||||
|
@ -30,8 +29,8 @@ import com.google.gwt.user.client.rpc.IsSerializable;
|
|||
* @author Daniele Strollo (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
public class CompleteResourceProfile implements Serializable, IsSerializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@SuppressWarnings("serial")
|
||||
public class CompleteResourceProfile implements Serializable {
|
||||
private String xmlRepresentation = null;
|
||||
private String htmlRepresentation = null;
|
||||
private ResourceTypeDecorator type = null;
|
||||
|
|
|
@ -23,16 +23,18 @@ import org.gcube.resourcemanagement.support.shared.util.Assertion;
|
|||
|
||||
|
||||
|
||||
|
||||
import com.extjs.gxt.ui.client.data.BaseModelData;
|
||||
import com.google.gwt.user.client.rpc.IsSerializable;
|
||||
|
||||
/**
|
||||
* All the resources that want to access resource management
|
||||
* operations must be described through this data type.
|
||||
* @author Daniele Strollo (ISTI-CNR)
|
||||
* @author Massimiliano Assante (ISTI-CNR)
|
||||
* @author Daniele Strollo
|
||||
*/
|
||||
public class ResourceDescriptor extends BaseModelData implements Serializable, IsSerializable {
|
||||
private static final long serialVersionUID = 6435512868470974421L;
|
||||
@SuppressWarnings("serial")
|
||||
public class ResourceDescriptor extends BaseModelData implements Serializable {
|
||||
|
||||
public ResourceDescriptor() {
|
||||
super();
|
||||
|
@ -46,11 +48,7 @@ public class ResourceDescriptor extends BaseModelData implements Serializable, I
|
|||
* @param name the short name assigned to the resource (mandatory).
|
||||
* @throws InvalidParameterException
|
||||
*/
|
||||
public ResourceDescriptor(
|
||||
final String type,
|
||||
final String subtype,
|
||||
final String id,
|
||||
final String name) throws InvalidParameterException {
|
||||
public ResourceDescriptor(String type, String subtype, String id, String name) throws InvalidParameterException {
|
||||
super();
|
||||
Assertion<InvalidParameterException> checker = new Assertion<InvalidParameterException>();
|
||||
checker.validate(name != null && name.length() > 0, new InvalidParameterException("The ghnName is null or empty"));
|
||||
|
@ -110,4 +108,13 @@ public class ResourceDescriptor extends BaseModelData implements Serializable, I
|
|||
public final Object getProperty(final String property) {
|
||||
return get(property);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ResourceDescriptor [getType()=" + getType() + ", getSubtype()="
|
||||
+ getSubtype() + ", getID()=" + getID() + ", getName()="
|
||||
+ getName() + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue