Feature #12037, Please provide a way to get the Context UUID in ContextManager implemented
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/admin/rmp-common-library@178533 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
7c0a1b31e2
commit
f28a358eee
2
pom.xml
2
pom.xml
|
@ -11,7 +11,7 @@
|
|||
|
||||
<groupId>org.gcube.portlets.admin</groupId>
|
||||
<artifactId>rmp-common-library</artifactId>
|
||||
<version>2.8.1-SNAPSHOT</version>
|
||||
<version>2.8.2-SNAPSHOT</version>
|
||||
<name>Resource Management Library</name>
|
||||
<description>
|
||||
gCube Resource Management Library is a common library containing shared code for Information System Operations
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.gcube.common.resources.gcore.GenericResource;
|
|||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.resourcemanagement.support.server.utils.ServerConsole;
|
||||
import org.gcube.resourcemanagement.support.shared.types.datamodel.D4SEnvironment;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.w3c.dom.Document;
|
||||
|
@ -103,10 +104,10 @@ public class ContextManager {
|
|||
public static LinkedHashMap<String, ScopeBean> readContexts() throws Exception {
|
||||
LinkedHashMap<String, ScopeBean> toReturn = new LinkedHashMap<String, ScopeBean>();
|
||||
String scopeXML = readInfraVoFromIS();
|
||||
|
||||
System.out.println("**** readContexts()");
|
||||
Document scopeDocument = getDocumentGivenXML(scopeXML);
|
||||
NodeList voElements = scopeDocument.getElementsByTagName("vo");
|
||||
System.out.println("voElements="+ voElements.getLength());
|
||||
ServerConsole.debug("voElements="+ voElements.getLength());
|
||||
for (int i = 0; i < voElements.getLength(); i++) {
|
||||
NodeList voDetails = voElements.item(i).getChildNodes();
|
||||
String voString = voDetails.item(2).getFirstChild().getNodeValue();
|
||||
|
@ -124,6 +125,41 @@ public class ContextManager {
|
|||
}
|
||||
return toReturn;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param confFile
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static LinkedHashMap<String, D4SEnvironment> readContextsWithUUIDs() throws Exception {
|
||||
LinkedHashMap<String, D4SEnvironment> toReturn = new LinkedHashMap<String, D4SEnvironment>();
|
||||
String scopeXML = readInfraVoFromIS();
|
||||
System.out.println("**** readContexts()");
|
||||
Document scopeDocument = getDocumentGivenXML(scopeXML);
|
||||
NodeList voElements = scopeDocument.getElementsByTagName("vo");
|
||||
ServerConsole.debug("voElements="+ voElements.getLength());
|
||||
for (int i = 0; i < voElements.getLength(); i++) {
|
||||
NodeList voDetails = voElements.item(i).getChildNodes();
|
||||
String voString = voDetails.item(2).getFirstChild().getNodeValue();
|
||||
ScopeBean vo = new ScopeBean(voString);
|
||||
D4SEnvironment voWrapper = new D4SEnvironment(vo, "uuid-not-exisiting-for-vos");
|
||||
toReturn.put(vo.toString(), voWrapper);
|
||||
try {
|
||||
for (GenericResource resVRE : getVREResourcesFromVO(vo)) {
|
||||
String name = resVRE.profile().name();
|
||||
String uuid = resVRE.id();
|
||||
D4SEnvironment vreWrapper = new D4SEnvironment(new ScopeBean(vo.toString()+"/"+name), uuid);
|
||||
// This operation overrides the vo map
|
||||
toReturn.put(name, vreWrapper);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ServerConsole.error("Exception raised while loading VREs for VO : " + vo, e);
|
||||
}
|
||||
}
|
||||
return toReturn;
|
||||
|
||||
}
|
||||
/**
|
||||
* query the IS to get the VRE list given a VO
|
||||
|
@ -150,6 +186,28 @@ public class ContextManager {
|
|||
return toReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* query the IS to get the VRE list given a VO
|
||||
* @param vo
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
protected static List<GenericResource> getVREResourcesFromVO(final ScopeBean vo) throws Exception {
|
||||
ServerConsole.info(LOG_PREFIX, "Starting Retrieving VREs for VO : " + vo);
|
||||
|
||||
ScopeProvider.instance.set(vo.toString());
|
||||
SimpleQuery query = queryFor(GenericResource.class);
|
||||
query.addCondition("$resource/Profile/SecondaryType/text() eq 'VRE'");
|
||||
|
||||
DiscoveryClient<GenericResource> client = clientFor(GenericResource.class);
|
||||
|
||||
List<GenericResource> gRes = client.submit(query);
|
||||
for (GenericResource res : gRes) {
|
||||
ServerConsole.info(LOG_PREFIX, "Found: " + res.profile().name());
|
||||
}
|
||||
return gRes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a context, if it is a VO or an infrastructure, the corresponding
|
||||
* map file is retrieved from the globus location and the contained xml
|
||||
|
@ -181,14 +239,6 @@ public class ContextManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
// private static ServiceMap loadServiceMap(final VO vo, final String fileName) throws Exception {
|
||||
// ServiceMap map = new ServiceMap();
|
||||
// String filePath = System.getenv("GLOBUS_LOCATION") + File.separator + "config" + File.separator + fileName;
|
||||
// ServerConsole.info(LOG_PREFIX, "--- Loading " + vo.getName() + " from: " + filePath);
|
||||
// map.load(new FileReader(filePath));
|
||||
// return map;
|
||||
// }
|
||||
|
||||
private static String readInfraVoFromIS() throws Exception {
|
||||
String context = "";
|
||||
String token = SecurityTokenProvider.instance.get();
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package org.gcube.resourcemanagement.support.shared.types.datamodel;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class D4SEnvironment implements Serializable{
|
||||
private ScopeBean context;
|
||||
private String uuid;
|
||||
|
||||
public D4SEnvironment() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
public D4SEnvironment(ScopeBean context, String uuid) {
|
||||
super();
|
||||
this.context = context;
|
||||
this.uuid = uuid;
|
||||
}
|
||||
public ScopeBean getContext() {
|
||||
return context;
|
||||
}
|
||||
public void setContext(ScopeBean context) {
|
||||
this.context = context;
|
||||
}
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("D4SEnvironment [context=");
|
||||
builder.append(context);
|
||||
builder.append(", uuid=");
|
||||
builder.append(uuid);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue