|
|
|
@ -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
|
|
|
|
@ -149,6 +185,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
|
|
|
|
@ -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();
|
|
|
|
|