Fixing some backward compatibility problems with profiles registered via AF

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Collector@30238 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Manuele Simi 2010-10-29 02:25:51 +00:00
parent f182095fef
commit 7ca1e0dfc4
4 changed files with 95 additions and 39 deletions

View File

@ -8,7 +8,9 @@ import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.collector.impl.state.AggregatorRegisteredResource; import org.gcube.informationsystem.collector.impl.state.AggregatorRegisteredResource;
import org.gcube.informationsystem.collector.impl.utils.*; import org.gcube.informationsystem.collector.impl.utils.*;
import org.gcube.informationsystem.collector.impl.xmlstorage.exist.State; import org.gcube.informationsystem.collector.impl.xmlstorage.exist.State;
import org.gcube.informationsystem.collector.impl.resources.BaseDAIXResource;
import org.gcube.informationsystem.collector.impl.resources.GCUBEInstanceStateResource; import org.gcube.informationsystem.collector.impl.resources.GCUBEInstanceStateResource;
import org.gcube.informationsystem.collector.impl.resources.GCUBEProfileResource;
import org.gcube.informationsystem.collector.impl.resources.GCUBEXMLResource; import org.gcube.informationsystem.collector.impl.resources.GCUBEXMLResource;
import org.globus.mds.aggregator.impl.AggregatorServiceGroupResource; import org.globus.mds.aggregator.impl.AggregatorServiceGroupResource;
import org.globus.mds.aggregator.impl.AggregatorServiceGroupEntryResource; import org.globus.mds.aggregator.impl.AggregatorServiceGroupEntryResource;
@ -177,14 +179,24 @@ public class AggregatorRegisteredResource extends AggregatorServiceGroupResource
logger.debug("Aggregator Sink " + entryparser.getSink()); logger.debug("Aggregator Sink " + entryparser.getSink());
// Build the new resource to store // Build the new resource to store
logger.debug("Storing the new delivered resource"); logger.debug("Storing the new delivered resource");
BaseDAIXResource resource;
//TODO: check if it's a profile or an RP, by relying on the publisher (registry or not) if (entryparser.getType().compareToIgnoreCase(GCUBEProfileResource.TYPE) == 0) {
//TODO: this will be removed after all the gHNs have the ISPublisher 2.0 installed
GCUBEInstanceStateResource instanceState = new GCUBEInstanceStateResource(); // and all the profiles arrive via the XMLCollectionAccess PT
instanceState.setResourceName(Identifier.buildInstanceStateID(entryparser)); resource = new GCUBEProfileResource();
instanceState.setContent(aentry.getEntryAsString()); String profile = aentry.getProfile();
GCUBEXMLResource res = new GCUBEXMLResource(instanceState); //logger.debug("Received profile: " + profile);
resource.setResourceName(Identifier.buildProfileID(profile));
resource.setContent(profile);
} else {
resource = new GCUBEInstanceStateResource();
resource.setResourceName(Identifier.buildInstanceStateID(entryparser));
resource.setContent(aentry.getEntryAsString());
}
GCUBEXMLResource res = new GCUBEXMLResource(resource);
res.setEntryKey(sinkparser.getEntryKey()); res.setEntryKey(sinkparser.getEntryKey());
res.setGroupKey(sinkparser.getGroupKey()); res.setGroupKey(sinkparser.getGroupKey());
res.setTerminationTime(entry.getTerminationTime()); res.setTerminationTime(entry.getTerminationTime());

View File

@ -15,6 +15,12 @@ import org.globus.mds.aggregator.impl.AggregatorServiceGroupEntryResource;
public class EntryParser { public class EntryParser {
private AggregatorServiceGroupEntryResource entry = null; private AggregatorServiceGroupEntryResource entry = null;
private static final String registryNS = "gcube/informationsystem/registry/Registry";
public enum RESOURCETYPE {
Profile, Properties
}
public EntryParser(AggregatorServiceGroupEntryResource entry) { public EntryParser(AggregatorServiceGroupEntryResource entry) {
this.entry = entry; this.entry = entry;
@ -83,17 +89,17 @@ public class EntryParser {
/** /**
* *
* @return the {@link RESOURCETYPE} * @return the type of the resource (Profile or Properties)
*/ */
/* public RESOURCETYPE getType() { public String getType() {
EndpointReferenceType memberEpr = entry.getMemberEPR(); EndpointReferenceType memberEpr = entry.getMemberEPR();
if (memberEpr.getAddress().toString().endsWith(registryNS)) { if (memberEpr.getAddress().toString().endsWith(registryNS)) {
return RESOURCETYPE.Profile; return "Profile";
} else { } else {
return RESOURCETYPE.Properties; return "Properties";
} }
} }
*/
public void getRPSet() { public void getRPSet() {
// get RP set from entry // get RP set from entry
// ResourcePropertySet rpSet = entry.getResourcePropertySet(); // ResourcePropertySet rpSet = entry.getResourcePropertySet();

View File

@ -1,5 +1,15 @@
package org.gcube.informationsystem.collector.impl.utils; package org.gcube.informationsystem.collector.impl.utils;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
/** /**
* *
* Build instance state identifiers * Build instance state identifiers
@ -27,4 +37,28 @@ public class Identifier {
public static String buildInstanceStateID(String source, String id) { public static String buildInstanceStateID(String source, String id) {
return source.replace("http://", "").replace(":", "").replace("/", "-") + "-" + id.replace("http://", "").replace(":", "").replace("/", "-"); return source.replace("http://", "").replace(":", "").replace("/", "-") + "-" + id.replace("http://", "").replace(":", "").replace("/", "-");
} }
/**
* Builds a profile ID starting from the message (a string serialization of the profile)
* @param message the message
* @return the ID of the profile
* @throws Exception if the profile is not well-formed
*/
public static String buildProfileID(String message) throws Exception {
Document internalDOM;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
StringReader reader = new StringReader(message);
InputSource source = new InputSource(reader);
internalDOM = builder.parse(source);
XPath path = XPathFactory.newInstance().newXPath();
// uses the GCUBEResource ID as local resource ID
return path.evaluate("/Resource/ID", internalDOM);
} catch (Exception e) {
throw new Exception("Unable to extract the ID from the resource " + e.getMessage());
} finally {
internalDOM = null;
}
}
} }

View File

@ -15,7 +15,10 @@ import javax.xml.parsers.*;
import javax.xml.xpath.*; import javax.xml.xpath.*;
import javax.xml.transform.dom.DOMSource; import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer; import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactory;
import java.io.StringWriter; import java.io.StringWriter;
@ -84,33 +87,17 @@ public class MsgParser {
public String getEntryType() { public String getEntryType() {
return this.type; return this.type;
} }
/** /**
* Returns the entry type if the entry is a profile * Returns the Scope Name included in the entry
* *
* @throws Exception * @throws Exception
* *
* @return the entry type * @return the Scope name
*/ */
public String getResourceType() throws Exception { public String getScopeName() throws Exception {
if (this.type.equalsIgnoreCase("Profile")) { return this.getGCUBEProperty("Scope");
logger.warn("The entry does not have a ResourceType");
throw new Exception("Invalid resource (type = Properties)");
}
return this.getGCUBEProperty("DILIGENTResourceType");
}
/**
* Returns the VO Name included in the entry
*
* @throws Exception
*
* @return the VO name
*/
public String getVOName() throws Exception {
return this.getGCUBEProperty("VO");
} }
/** /**
@ -168,11 +155,31 @@ public class MsgParser {
* *
* @return the DHN ID * @return the DHN ID
*/ */
public String getDHNID() throws Exception { public String getGHNID() throws Exception {
return this.getGCUBEProperty("GHN"); return this.getGCUBEProperty("GHN");
} }
/**
*
* @return the profile, it any
* @throws Exception
*/
public String getProfile() throws Exception {
try {
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
StringWriter buffer = new StringWriter();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(new DOMSource(this.internalDOM.getElementsByTagName("Resource").item(0)), new StreamResult(buffer));
return buffer.toString();
} catch (Exception e) {
throw new Exception("Unable to deserialise content data");
}
}
/** /**
* Reads a GCUBE Property * Reads a GCUBE Property
* *
@ -182,17 +189,14 @@ public class MsgParser {
*/ */
private String getGCUBEProperty(String propName) throws Exception { private String getGCUBEProperty(String propName) throws Exception {
String value = null;
try { try {
value = path.evaluate("//" + rootElement return path.evaluate("//" + rootElement
+ "/child::*[local-name() = '" + propName + "']", + "/child::*[local-name() = '" + propName + "']",
internalDOM); internalDOM);
} catch (XPathExpressionException xpee) { } catch (XPathExpressionException xpee) {
logger.error("", xpee); logger.error("", xpee);
throw new Exception("XPath evaluation error"); throw new Exception("XPath evaluation error");
} }
return value;
} }
/** /**