Author: mattmann
Date: Sat Feb 19 03:51:57 2011
New Revision: 1072241
URL: http://svn.apache.org/viewvc?rev=1072241&view=rev
Log:
- OODT-139 WIP: commit initial draft of PedigreeResource
Added:
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PedigreeResource.java
Modified:
oodt/trunk/commons/src/test/org/apache/oodt/commons/util/XMLTest.java
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/HealthResource.java
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PCSService.java
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PCSServiceConfMetKeys.java
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PCSServiceConfig.java
oodt/trunk/pcs/services/src/main/webapp/META-INF/context.xml
oodt/trunk/pcs/services/src/main/webapp/WEB-INF/web.xml
Modified: oodt/trunk/commons/src/test/org/apache/oodt/commons/util/XMLTest.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/commons/src/test/org/apache/oodt/commons/util/XMLTest.java?rev=1072241&r1=1072240&r2=1072241&view=diff
==============================================================================
--- oodt/trunk/commons/src/test/org/apache/oodt/commons/util/XMLTest.java
(original)
+++ oodt/trunk/commons/src/test/org/apache/oodt/commons/util/XMLTest.java Sat
Feb 19 03:51:57 2011
@@ -57,7 +57,6 @@ public class XMLTest extends TestCase {
assertEquals("log", doc.getDocumentElement().getTagName());
java.util.zip.CRC32 crc = new java.util.zip.CRC32();
String result = XML.serialize(doc);
- System.err.println("FUCK YOU: " + result);
crc.update(result.getBytes());
long value = crc.getValue();
assertTrue("Stringified DOM document CRC mismatch, got value =
" + value, 3880488030L == value || 2435419114L == value || /* added by Chris
Mattmann: pretty print fix */3688328384L == value || /* other newline treatment
*/ 750262163L == value || 3738296466L == value /* Apache incubator warmed up
the file, so it suffered thermal expansion */);
Modified:
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/HealthResource.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/HealthResource.java?rev=1072241&r1=1072240&r2=1072241&view=diff
==============================================================================
---
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/HealthResource.java
(original)
+++
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/HealthResource.java
Sat Feb 19 03:51:57 2011
@@ -31,10 +31,6 @@ import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
//JSON imports
import net.sf.json.JSONObject;
@@ -389,17 +385,4 @@ public class HealthResource extends PCSS
output.put("status", status.getStatus());
return output;
}
-
- private class ResourceNotFoundException extends WebApplicationException {
-
- public ResourceNotFoundException() {
- super(Response.status(Status.NOT_FOUND).type(MediaType.TEXT_PLAIN)
- .build());
- }
-
- public ResourceNotFoundException(String msg) {
- super(Response.status(Status.NOT_FOUND).entity(msg).type(
- MediaType.TEXT_PLAIN).build());
- }
- }
}
Modified:
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PCSService.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PCSService.java?rev=1072241&r1=1072240&r2=1072241&view=diff
==============================================================================
---
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PCSService.java
(original)
+++
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PCSService.java
Sat Feb 19 03:51:57 2011
@@ -17,10 +17,17 @@
package org.apache.oodt.pcs.services;
+//JDK imports
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
+//JAX-RS imports
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
/**
*
* Base class for PCS JAX-RS services. Loads up
@@ -46,5 +53,19 @@ public class PCSService extends HttpServ
super.init(config);
conf = new PCSServiceConfig(config);
}
+
+
+ protected class ResourceNotFoundException extends WebApplicationException {
+
+ public ResourceNotFoundException() {
+ super(Response.status(Status.NOT_FOUND).type(MediaType.TEXT_PLAIN)
+ .build());
+ }
+
+ public ResourceNotFoundException(String msg) {
+ super(Response.status(Status.NOT_FOUND).entity(msg).type(
+ MediaType.TEXT_PLAIN).build());
+ }
+ }
}
Modified:
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PCSServiceConfMetKeys.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PCSServiceConfMetKeys.java?rev=1072241&r1=1072240&r2=1072241&view=diff
==============================================================================
---
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PCSServiceConfMetKeys.java
(original)
+++
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PCSServiceConfMetKeys.java
Sat Feb 19 03:51:57 2011
@@ -40,5 +40,7 @@ public interface PCSServiceConfMetKeys {
public static final String PCS_HEALTH_WORKFLOW_STATUS_PATH =
"org.apache.oodt.pcs.health.workflow.statuses.filePath";
public static final String PCS_TRACE_ENABLE_NON_CAT =
"org.apache.oodt.pcs.trace.enableNonCat";
+
+ public static final String PCS_TRACE_PTYPE_EXCLUDE_LIST =
"org.apache.oodt.pcs.trace.productTypeExcludeList";
}
Modified:
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PCSServiceConfig.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PCSServiceConfig.java?rev=1072241&r1=1072240&r2=1072241&view=diff
==============================================================================
---
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PCSServiceConfig.java
(original)
+++
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PCSServiceConfig.java
Sat Feb 19 03:51:57 2011
@@ -104,6 +104,14 @@ public class PCSServiceConfig implements
public boolean isTraceNotCatalogedFiles() {
return Boolean.valueOf(this.parameters.get(PCS_TRACE_ENABLE_NON_CAT));
}
+
+ /**
+ * @return The comma-separated list of product types to exclude from
+ * pedigree tracking.
+ */
+ public String getTraceProductTypeExcludeList(){
+ return
PathUtils.replaceEnvVariables(this.parameters.get(PCS_TRACE_PTYPE_EXCLUDE_LIST));
+ }
@SuppressWarnings("unchecked")
private void readContextParams(ServletConfig config) {
Added:
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PedigreeResource.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PedigreeResource.java?rev=1072241&view=auto
==============================================================================
---
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PedigreeResource.java
(added)
+++
oodt/trunk/pcs/services/src/main/java/org/apache/oodt/pcs/services/PedigreeResource.java
Sat Feb 19 03:51:57 2011
@@ -0,0 +1,125 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.oodt.pcs.services;
+
+//JDK imports
+import java.net.MalformedURLException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+//JAX-RS imports
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+
+//JSON imports
+import net.sf.json.JSONObject;
+
+//OODT imports
+import org.apache.oodt.pcs.pedigree.Pedigree;
+import org.apache.oodt.pcs.pedigree.PedigreeTree;
+import org.apache.oodt.pcs.pedigree.PedigreeTreeNode;
+import org.apache.oodt.pcs.util.FileManagerUtils;
+
+/**
+ *
+ * Exposes the {@link Pedigree} API of the PCS to provide an upstream and
+ * downstream lineage of a particular OODT {@link Product} using JAX-RS.
+ *
+ * @author mattmann
+ * @version $Revision$
+ *
+ */
+@Path("pedigree")
+public class PedigreeResource extends PCSService {
+
+ private static final long serialVersionUID = 4851623546718112205L;
+
+ private Pedigree trace;
+
+ private FileManagerUtils fm;
+
+ public PedigreeResource() throws MalformedURLException {
+ this.fm = new FileManagerUtils(PCSService.conf.getFmUrl());
+ this.trace = new Pedigree(this.fm, PCSService.conf
+ .isTraceNotCatalogedFiles(), Arrays.asList(PCSService.conf
+ .getTraceProductTypeExcludeList().split(",")));
+ }
+
+ @GET
+ @Path("report/{filename}")
+ @Produces("text/plain")
+ public String generatePedigree(@PathParam("filename") String filename) {
+ PedigreeTree upstreamTree = this.trace.doPedigree(this.fm
+ .safeGetProductByName(filename), true);
+ PedigreeTree downstreamTree = this.trace.doPedigree(this.fm
+ .safeGetProductByName(filename), false);
+ upstreamTree.printPedigreeTree();
+ downstreamTree.printPedigreeTree();
+ return this.encodePedigreeAsJson(upstreamTree, downstreamTree);
+ }
+
+ @GET
+ @Path("report/{filename}/upstream")
+ @Produces("text/plain")
+ public String generateUpstreamPedigree(@PathParam("filename") String
filename) {
+ PedigreeTree upstreamTree = this.trace.doPedigree(this.fm
+ .safeGetProductByName(filename), true);
+ return this.encodePedigreeAsJson(upstreamTree, null);
+ }
+
+ @GET
+ @Path("report/{filename}/downstream")
+ @Produces("text/plain")
+ public String generateDownstreamPedigree(
+ @PathParam("filename") String filename) {
+ PedigreeTree downstreamTree = this.trace.doPedigree(this.fm
+ .safeGetProductByName(filename), false);
+ return this.encodePedigreeAsJson(null, downstreamTree);
+ }
+
+ private String encodePedigreeAsJson(PedigreeTree up, PedigreeTree down) {
+ Map<String, Object> output = new HashMap<String, Object>();
+ if (up != null)
+ output.put("upstream", this.encodePedigreeTreeAsJson(up.getRoot()));
+ if (down != null)
+ output.put("downstream", this.encodePedigreeTreeAsJson(down.getRoot()));
+ JSONObject json = new JSONObject();
+ json.put("pedigree", output);
+ return json.toString();
+ }
+
+ private Object encodePedigreeTreeAsJson(PedigreeTreeNode node) {
+ if (node.getNumChildren() > 0) {
+ Map<String, Object> map = new HashMap<String, Object>();
+ List<Object> list = new Vector<Object>();
+ for (int i = 0; i < node.getNumChildren(); i++) {
+ list.add(this
+ .encodePedigreeTreeAsJson(node.getChildAt(i)));
+ }
+ map.put(node.getNodeProduct().getProductName(), list);
+ return map;
+ } else {
+ return node.getNodeProduct().getProductName();
+ }
+ }
+}
Modified: oodt/trunk/pcs/services/src/main/webapp/META-INF/context.xml
URL:
http://svn.apache.org/viewvc/oodt/trunk/pcs/services/src/main/webapp/META-INF/context.xml?rev=1072241&r1=1072240&r2=1072241&view=diff
==============================================================================
--- oodt/trunk/pcs/services/src/main/webapp/META-INF/context.xml (original)
+++ oodt/trunk/pcs/services/src/main/webapp/META-INF/context.xml Sat Feb 19
03:51:57 2011
@@ -37,5 +37,8 @@ the License.
<Parameter name="org.apache.oodt.pcs.trace.enableNonCat"
value="true"/>
+
+ <Parameter name="org.apache.oodt.pcs.trace.productTypeExcludeList"
+ value="TypeName1,TypeName2"/>
</Context>
Modified: oodt/trunk/pcs/services/src/main/webapp/WEB-INF/web.xml
URL:
http://svn.apache.org/viewvc/oodt/trunk/pcs/services/src/main/webapp/WEB-INF/web.xml?rev=1072241&r1=1072240&r2=1072241&view=diff
==============================================================================
--- oodt/trunk/pcs/services/src/main/webapp/WEB-INF/web.xml (original)
+++ oodt/trunk/pcs/services/src/main/webapp/WEB-INF/web.xml Sat Feb 19 03:51:57
2011
@@ -28,6 +28,7 @@ the License.
<param-name>jaxrs.serviceClasses</param-name>
<param-value>
org.apache.oodt.pcs.services.HealthResource
+ org.apache.oodt.pcs.services.PedigreeResource
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>