You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by bf...@apache.org on 2012/03/16 00:31:45 UTC
svn commit: r1301267 - in /oodt/trunk/pge/src:
main/java/org/apache/oodt/cas/pge/ main/java/org/apache/oodt/cas/pge/config/
main/java/org/apache/oodt/cas/pge/metadata/ test/org/apache/oodt/cas/pge/
test/org/apache/oodt/cas/pge/metadata/
Author: bfoster
Date: Thu Mar 15 23:31:45 2012
New Revision: 1301267
URL: http://svn.apache.org/viewvc?rev=1301267&view=rev
Log:
Port CAS-PGE's PcsMetadataKeys to PgeTaskMetKeys
-------------
OODT-411
Removed:
oodt/trunk/pge/src/main/java/org/apache/oodt/cas/pge/metadata/PcsMetadataKeys.java
Modified:
oodt/trunk/pge/src/main/java/org/apache/oodt/cas/pge/PGETaskInstance.java
oodt/trunk/pge/src/main/java/org/apache/oodt/cas/pge/config/XmlFilePgeConfigBuilder.java
oodt/trunk/pge/src/main/java/org/apache/oodt/cas/pge/metadata/PgeTaskMetKeys.java
oodt/trunk/pge/src/test/org/apache/oodt/cas/pge/TestPGETaskInstance.java
oodt/trunk/pge/src/test/org/apache/oodt/cas/pge/metadata/TestPgeTaskMetKeys.java
Modified: oodt/trunk/pge/src/main/java/org/apache/oodt/cas/pge/PGETaskInstance.java
URL: http://svn.apache.org/viewvc/oodt/trunk/pge/src/main/java/org/apache/oodt/cas/pge/PGETaskInstance.java?rev=1301267&r1=1301266&r2=1301267&view=diff
==============================================================================
--- oodt/trunk/pge/src/main/java/org/apache/oodt/cas/pge/PGETaskInstance.java (original)
+++ oodt/trunk/pge/src/main/java/org/apache/oodt/cas/pge/PGETaskInstance.java Thu Mar 15 23:31:45 2012
@@ -14,10 +14,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.oodt.cas.pge;
+//OODT static imports
+import static org.apache.oodt.cas.pge.metadata.PgeTaskMetKeys.ACTION_IDS;
+import static org.apache.oodt.cas.pge.metadata.PgeTaskMetKeys.ACTION_REPO_FILE;
+import static org.apache.oodt.cas.pge.metadata.PgeTaskMetKeys.ATTEMPT_INGEST_ALL;
+import static org.apache.oodt.cas.pge.metadata.PgeTaskMetKeys.CRAWLER_CRAWL_FOR_DIRS;
+import static org.apache.oodt.cas.pge.metadata.PgeTaskMetKeys.CRAWLER_RECUR;
+import static org.apache.oodt.cas.pge.metadata.PgeTaskMetKeys.INGEST_CLIENT_TRANSFER_SERVICE_FACTORY;
+import static org.apache.oodt.cas.pge.metadata.PgeTaskMetKeys.INGEST_FILE_MANAGER_URL;
+import static org.apache.oodt.cas.pge.metadata.PgeTaskMetKeys.LOG_FILE_PATTERN;
+import static org.apache.oodt.cas.pge.metadata.PgeTaskMetKeys.MET_FILE_EXT;
+import static org.apache.oodt.cas.pge.metadata.PgeTaskMetKeys.NAME;
+import static org.apache.oodt.cas.pge.metadata.PgeTaskMetKeys.PGE_RUNTIME;
+import static org.apache.oodt.cas.pge.metadata.PgeTaskMetKeys.PROPERTY_ADDERS;
+import static org.apache.oodt.cas.pge.metadata.PgeTaskMetKeys.REQUIRED_METADATA;
+import static org.apache.oodt.cas.pge.metadata.PgeTaskMetKeys.WORKFLOW_MANAGER_URL;
+import static org.apache.oodt.cas.pge.metadata.PgeTaskStatus.CONF_FILE_BUILD;
+import static org.apache.oodt.cas.pge.metadata.PgeTaskStatus.CRAWLING;
+import static org.apache.oodt.cas.pge.metadata.PgeTaskStatus.RUNNING_PGE;
+
//JDK imports
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.FileHandler;
@@ -26,42 +49,37 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.util.regex.Pattern;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.net.URL;
//OODT imports
-import org.apache.oodt.cas.workflow.metadata.CoreMetKeys;
-import org.apache.oodt.cas.workflow.structs.WorkflowTaskConfiguration;
-import org.apache.oodt.cas.workflow.structs.WorkflowTaskInstance;
-import org.apache.oodt.cas.workflow.structs.exceptions.WorkflowTaskInstanceException;
-import org.apache.oodt.cas.workflow.system.XmlRpcWorkflowManagerClient;
-import org.apache.oodt.cas.workflow.util.ScriptFile;
import org.apache.oodt.cas.crawl.ProductCrawler;
import org.apache.oodt.cas.crawl.StdProductCrawler;
import org.apache.oodt.cas.crawl.status.IngestStatus;
import org.apache.oodt.cas.metadata.Metadata;
import org.apache.oodt.cas.metadata.SerializableMetadata;
import org.apache.oodt.cas.metadata.util.PathUtils;
-import org.apache.oodt.commons.exec.ExecUtils;
import org.apache.oodt.cas.pge.config.DynamicConfigFile;
import org.apache.oodt.cas.pge.config.OutputDir;
import org.apache.oodt.cas.pge.config.PgeConfig;
import org.apache.oodt.cas.pge.config.RegExprOutputFiles;
import org.apache.oodt.cas.pge.config.RenamingConv;
import org.apache.oodt.cas.pge.config.XmlFilePgeConfigBuilder;
-import org.apache.oodt.cas.pge.metadata.PcsMetadataKeys;
import org.apache.oodt.cas.pge.metadata.PgeMetadata;
import org.apache.oodt.cas.pge.metadata.PgeTaskMetKeys;
-import org.apache.oodt.cas.pge.metadata.PgeTaskStatus;
import org.apache.oodt.cas.pge.writers.PcsMetFileWriter;
import org.apache.oodt.cas.pge.writers.SciPgeConfigFileWriter;
+import org.apache.oodt.cas.workflow.metadata.CoreMetKeys;
+import org.apache.oodt.cas.workflow.structs.WorkflowTaskConfiguration;
+import org.apache.oodt.cas.workflow.structs.WorkflowTaskInstance;
+import org.apache.oodt.cas.workflow.structs.exceptions.WorkflowTaskInstanceException;
+import org.apache.oodt.cas.workflow.system.XmlRpcWorkflowManagerClient;
+import org.apache.oodt.cas.workflow.util.ScriptFile;
+import org.apache.oodt.commons.exec.ExecUtils;
//Spring imports
import org.springframework.context.support.FileSystemXmlApplicationContext;
+//Google imports
+import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
/**
@@ -102,7 +120,7 @@ public class PGETaskInstance implements
// configure workflow manager
wm = new XmlRpcWorkflowManagerClient(new URL(
this.pgeMetadata
- .getMetadata(PcsMetadataKeys.WORKFLOW_MANAGER_URL)));
+ .getMetadata(WORKFLOW_MANAGER_URL.getName())));
workflowInstId = this.pgeMetadata
.getMetadata(CoreMetKeys.WORKFLOW_INST_ID);
@@ -117,9 +135,13 @@ public class PGETaskInstance implements
WorkflowTaskConfiguration config) {
Metadata staticMetadata = new Metadata();
for (Object key : config.getProperties().keySet()) {
- if (PgeTaskMetKeys.PROPERTY_ADDERS.getName().equals((String) key)) {
- staticMetadata.addMetadata((String) key,
- Lists.newArrayList(config.getProperty((String) key).split(",")));
+ PgeTaskMetKeys metKey = PgeTaskMetKeys.getByName((String) key);
+ if (metKey != null && metKey.isVector()) {
+ staticMetadata.addMetadata(
+ (String) key,
+ Lists.newArrayList(Splitter.on(",").trimResults()
+ .omitEmptyStrings()
+ .split(config.getProperty((String) key))));
} else {
staticMetadata.addMetadata((String) key,
config.getProperty((String) key));
@@ -131,7 +153,7 @@ public class PGETaskInstance implements
protected void runPropertyAdders() throws Exception {
try {
List<String> propertyAdders = pgeMetadata
- .getAllMetadata(PgeTaskMetKeys.PROPERTY_ADDERS.getName());
+ .getAllMetadata(PROPERTY_ADDERS.getName());
if (propertyAdders != null) {
for (String propertyAdder : propertyAdders) {
runPropertyAdder(loadPropertyAdder(propertyAdder));
@@ -191,7 +213,7 @@ public class PGETaskInstance implements
}
protected void createSciPgeConfigFiles() throws IOException {
- this.updateStatus(PgeTaskStatus.CONF_FILE_BUILD.getWorkflowStatusName());
+ this.updateStatus(CONF_FILE_BUILD.getWorkflowStatusName());
for (DynamicConfigFile dynamicConfigFile : pgeConfig
.getDynamicConfigFiles()) {
try {
@@ -249,7 +271,7 @@ public class PGETaskInstance implements
createdFile.getAbsolutePath()
+ "."
+ this.pgeMetadata
- .getMetadata(PcsMetadataKeys.MET_FILE_EXT));
+ .getMetadata(MET_FILE_EXT.getName()));
}
}
}
@@ -293,14 +315,14 @@ public class PGETaskInstance implements
protected String getPgeScriptName() {
return "sciPgeExeScript_"
- + this.pgeMetadata.getMetadata(PgeTaskMetKeys.NAME.getName());
+ + this.pgeMetadata.getMetadata(NAME.getName());
}
protected Handler initializePgeLogHandler() throws SecurityException,
IOException {
FileHandler handler = null;
String logFilePattern = this.pgeMetadata
- .getMetadata(PgeTaskMetKeys.LOG_FILE_PATTERN.getName());
+ .getMetadata(LOG_FILE_PATTERN.getName());
if (logFilePattern != null) {
LOG.log(Level.INFO,
"Creating Log Handler to capture pge output to file '"
@@ -316,7 +338,7 @@ public class PGETaskInstance implements
protected Logger initializePgeLogger(Handler handler) {
if (handler != null) {
Logger pgeLogger = Logger.getLogger(this.pgeMetadata
- .getMetadata(PgeTaskMetKeys.NAME.getName())
+ .getMetadata(NAME.getName())
+ System.currentTimeMillis());
pgeLogger.addHandler(handler);
return pgeLogger;
@@ -346,7 +368,7 @@ public class PGETaskInstance implements
// run script and evaluate whether success or failure
handler = this.initializePgeLogHandler();
pgeLogger = this.initializePgeLogger(handler);
- this.updateStatus(PgeTaskStatus.RUNNING_PGE.getWorkflowStatusName());
+ this.updateStatus(RUNNING_PGE.getWorkflowStatusName());
if (!this.wasPgeSuccessful(ExecUtils.callProgram(
this.pgeConfig.getShellType() + " " + this.getScriptPath(),
pgeLogger,
@@ -357,7 +379,7 @@ public class PGETaskInstance implements
"Successfully completed running: '" + sf.getCommands() + "'");
long endTime = System.currentTimeMillis();
- this.pgeMetadata.replaceMetadata(PgeTaskMetKeys.PGE_RUNTIME.getName(),
+ this.pgeMetadata.replaceMetadata(PGE_RUNTIME.getName(),
(endTime - startTime) + "");
} catch (Exception e) {
@@ -390,30 +412,30 @@ public class PGETaskInstance implements
protected void setCrawlerConfigurations(StdProductCrawler crawler)
throws Exception {
crawler.setMetFileExtension(this.pgeMetadata
- .getMetadata(PcsMetadataKeys.MET_FILE_EXT));
+ .getMetadata(MET_FILE_EXT.getName()));
crawler.setClientTransferer(this.pgeMetadata
- .getMetadata(PcsMetadataKeys.CLIENT_TRANSFER_SERVICE_FACTORY));
+ .getMetadata(INGEST_CLIENT_TRANSFER_SERVICE_FACTORY.getName()));
crawler.setFilemgrUrl(this.pgeMetadata
- .getMetadata(PcsMetadataKeys.FILE_MANAGER_URL));
+ .getMetadata(INGEST_FILE_MANAGER_URL.getName()));
String actionRepoFile = this.pgeMetadata
- .getMetadata(PcsMetadataKeys.ACTION_REPO_FILE);
+ .getMetadata(ACTION_REPO_FILE.getName());
if (actionRepoFile != null && !actionRepoFile.equals("")) {
crawler.setApplicationContext(new FileSystemXmlApplicationContext(
actionRepoFile));
List<String> actionIds = pgeMetadata
- .getAllMetadata(PcsMetadataKeys.ACTION_IDS);
+ .getAllMetadata(ACTION_IDS.getName());
if (actionIds != null) {
crawler.setActionIds(actionIds);
}
}
crawler.setRequiredMetadata(this.pgeMetadata
- .getAllMetadata(PcsMetadataKeys.REQUIRED_METADATA));
+ .getAllMetadata(REQUIRED_METADATA.getName()));
String crawlForDirsString = this.pgeMetadata
- .getMetadata(PcsMetadataKeys.CRAWLER_CRAWL_FOR_DIRS);
+ .getMetadata(CRAWLER_CRAWL_FOR_DIRS.getName());
boolean crawlForDirs = (crawlForDirsString != null) ? crawlForDirsString
.toLowerCase().equals("true") : false;
String recurString = this.pgeMetadata
- .getMetadata(PcsMetadataKeys.CRAWLER_RECUR);
+ .getMetadata(CRAWLER_RECUR.getName());
boolean recur = (recurString != null) ? recurString.toLowerCase().equals(
"true") : true;
crawler.setCrawlForDirs(crawlForDirs);
@@ -428,9 +450,9 @@ public class PGETaskInstance implements
List<File> crawlDirs) {
File currentDir = null;
try {
- this.updateStatus(PgeTaskStatus.CRAWLING.getWorkflowStatusName());
+ this.updateStatus(CRAWLING.getWorkflowStatusName());
boolean attemptIngestAll = Boolean.parseBoolean(this.pgeMetadata
- .getMetadata(PgeTaskMetKeys.ATTEMPT_INGEST_ALL.getName()));
+ .getMetadata(ATTEMPT_INGEST_ALL.getName()));
for (File crawlDir : crawlDirs) {
currentDir = crawlDir;
LOG.log(Level.INFO, "Executing StdProductCrawler in productPath: ["
Modified: oodt/trunk/pge/src/main/java/org/apache/oodt/cas/pge/config/XmlFilePgeConfigBuilder.java
URL: http://svn.apache.org/viewvc/oodt/trunk/pge/src/main/java/org/apache/oodt/cas/pge/config/XmlFilePgeConfigBuilder.java?rev=1301267&r1=1301266&r2=1301267&view=diff
==============================================================================
--- oodt/trunk/pge/src/main/java/org/apache/oodt/cas/pge/config/XmlFilePgeConfigBuilder.java (original)
+++ oodt/trunk/pge/src/main/java/org/apache/oodt/cas/pge/config/XmlFilePgeConfigBuilder.java Thu Mar 15 23:31:45 2012
@@ -48,6 +48,8 @@ import static org.apache.oodt.cas.pge.co
import static org.apache.oodt.cas.pge.config.PgeConfigMetKeys.VAL_ATTR;
import static org.apache.oodt.cas.pge.config.PgeConfigMetKeys.WORKFLOW_MET_ATTR;
import static org.apache.oodt.cas.pge.config.PgeConfigMetKeys.WRITER_CLASS_ATTR;
+import static org.apache.oodt.cas.pge.metadata.PgeTaskMetKeys.CONFIG_FILE_PATH;
+import static org.apache.oodt.cas.pge.metadata.PgeTaskMetKeys.QUERY_FILE_MANAGER_URL;
//JDK imports
import java.io.File;
@@ -69,9 +71,7 @@ import org.apache.oodt.cas.filemgr.util.
import org.apache.oodt.cas.filemgr.util.SqlParser;
import org.apache.oodt.cas.metadata.Metadata;
import org.apache.oodt.cas.metadata.util.PathUtils;
-import org.apache.oodt.cas.pge.metadata.PcsMetadataKeys;
import org.apache.oodt.cas.pge.metadata.PgeMetadata;
-import org.apache.oodt.cas.pge.metadata.PgeTaskMetKeys;
import org.apache.oodt.commons.xml.XMLUtils;
//W3C imports
@@ -93,7 +93,7 @@ public class XmlFilePgeConfigBuilder imp
try {
PgeConfig pgeConfig = new PgeConfig();
this.buildImports(this.fillIn(pgeMetadata
- .getMetadata(PgeTaskMetKeys.CONFIG_FILE_PATH.getName()),
+ .getMetadata(CONFIG_FILE_PATH.getName()),
pgeMetadata.asMetadata()), null, pgeConfig, pgeMetadata);
return pgeConfig;
} catch (Exception e) {
@@ -347,7 +347,7 @@ public class XmlFilePgeConfigBuilder imp
if (value.toUpperCase()
.matches("^\\s*SQL\\s*\\(.*\\)\\s*\\{.*\\}\\s*$"))
value = QueryUtils.getQueryResultsAsString(new XmlRpcFileManagerClient(new URL(inputMetadata
- .getMetadata(PcsMetadataKeys.FILE_MANAGER_URL))).complexQuery(SqlParser.parseSqlQueryMethod(value)));
+ .getMetadata(QUERY_FILE_MANAGER_URL.getName()))).complexQuery(SqlParser.parseSqlQueryMethod(value)));
return value;
}catch (Exception e) {
throw new Exception("Failed to parse value: " + value, e);
Modified: oodt/trunk/pge/src/main/java/org/apache/oodt/cas/pge/metadata/PgeTaskMetKeys.java
URL: http://svn.apache.org/viewvc/oodt/trunk/pge/src/main/java/org/apache/oodt/cas/pge/metadata/PgeTaskMetKeys.java?rev=1301267&r1=1301266&r2=1301267&view=diff
==============================================================================
--- oodt/trunk/pge/src/main/java/org/apache/oodt/cas/pge/metadata/PgeTaskMetKeys.java (original)
+++ oodt/trunk/pge/src/main/java/org/apache/oodt/cas/pge/metadata/PgeTaskMetKeys.java Thu Mar 15 23:31:45 2012
@@ -21,29 +21,149 @@ import com.google.common.annotations.Vis
/**
* PGETaskInstance Reserved Metadata keys.
- *
+ *
* @author bfoster (Brian Foster)
*/
public enum PgeTaskMetKeys {
- NAME("PGETask/Name", "PGETask_Name"),
- CONFIG_FILE_PATH("PGETask/ConfigFilePath", "PGETask_ConfigFilePath"),
- LOG_FILE_PATTERN("PGETask/LogFilePattern", "PGETask_LogFilePattern"),
- PROPERTY_ADDERS("PGETask/PropertyAdders", "PGETask_PropertyAdderClasspath"),
- PGE_RUNTIME("PGETask/Runtime", "PGETask_Runtime"),
- ATTEMPT_INGEST_ALL("PGETask/AttemptIngestAll", "PGETask_AttemptIngestAll");
+ /**
+ * PGE Name used to create the execution script file name and name the Java Logger.
+ */
+ NAME(
+ "PGETask/Name",
+ "PGETask_Name"),
+ /**
+ * Path to CAS-PGE's configuration file.
+ */
+ CONFIG_FILE_PATH(
+ "PGETask/ConfigFilePath",
+ "PGETask_ConfigFilePath"),
+ /**
+ * Java logger pattern used to create log files for CAS-PGE.
+ */
+ LOG_FILE_PATTERN(
+ "PGETask/LogFilePattern",
+ "PGETask_LogFilePattern"),
+ /**
+ * List of {@link ConfigFilePropertyAdder}s classpaths to be run.
+ */
+ PROPERTY_ADDERS(
+ "PGETask/PropertyAdders",
+ "PGETask_PropertyAdderClasspath",
+ true),
+ /**
+ * Set by CAS-PGE to the number of milliseconds it took CAS-PGE to run.
+ */
+ PGE_RUNTIME(
+ "PGETask/Runtime",
+ "PGETask_Runtime"),
+ /**
+ * CAS Workflow Manager URL to which CAS-PGE should update it's status
+ * and metadata.
+ */
+ WORKFLOW_MANAGER_URL(
+ "PGETask/WorkflowManagerUrl",
+ "PCS_WorkflowManagerUrl"),
+ /**
+ * CAS File Manager URL used for queries.
+ */
+ QUERY_FILE_MANAGER_URL(
+ "PGETask/Query/FileManagerUrl",
+ "PCS_FileManagerUrl"),
+ /**
+ * CAS File Manager URL used for product ingestion.
+ */
+ INGEST_FILE_MANAGER_URL(
+ "PGETask/Ingest/FileManagerUrl",
+ "PCS_FileManagerUrl"),
+ /**
+ * The {@link DataTransferFactory} used for product staging.
+ */
+ QUERY_CLIENT_TRANSFER_SERVICE_FACTORY(
+ "PGETask/Query/ClientTransferServiceFactory",
+ "PCS_ClientTransferServiceFactory"),
+ /**
+ * The {@link DataTransferFactory} used for product ingestion.
+ */
+ INGEST_CLIENT_TRANSFER_SERVICE_FACTORY(
+ "PGETask/Ingest/ClientTransferServiceFactory",
+ "PCS_ClientTransferServiceFactory"),
+ /**
+ * Path to Spring XML file which contains CAS {@link CrawlerAction}s.
+ */
+ ACTION_REPO_FILE(
+ "PGETask/Ingest/ActionRepoFile",
+ "PCS_ActionRepoFile"),
+ /**
+ * The IDs of the {@link CrawlerAction}s in the {@link #ACTION_REPO_FILE} to run.
+ */
+ ACTION_IDS(
+ "PGETask/Ingest/ActionsIds",
+ "PCS_ActionsIds",
+ true),
+ /**
+ * If set to true the crawler will crawl for directories instead of files.
+ */
+ CRAWLER_CRAWL_FOR_DIRS(
+ "PGETask/Ingest/CrawlerCrawlForDirs",
+ "PCS_CrawlerCrawlForDirs"),
+ /**
+ * If set to true the crawler will perform a deep crawl for files.
+ */
+ CRAWLER_RECUR(
+ "PGETask/Ingest/CrawlerRecur",
+ "PCS_CrawlerRecur"),
+ /**
+ * File extension given to each Product's metadata file.
+ */
+ MET_FILE_EXT(
+ "PGETask/Ingest/MetFileExtension",
+ "PCS_MetFileExtension"),
+ /**
+ * List of metadata keys required for Product ingest.
+ */
+ REQUIRED_METADATA(
+ "PGETask/Ingest/RequiredMetadata",
+ "PCS_RequiredMetadata",
+ true),
+ /**
+ * If set to true then will attempt to ingest all Product's even if one
+ * fails. If false, will bail ingest after first failed Product ingest.
+ */
+ ATTEMPT_INGEST_ALL(
+ "PGETask/Ingest/AttemptIngestAll",
+ "PGETask_AttemptIngestAll");
public static final String USE_LEGACY_PROPERTY = "org.apache.oodt.cas.pge.legacyMode";
@VisibleForTesting String name;
@VisibleForTesting String legacyName;
+ private boolean isVector;
PgeTaskMetKeys(String name, String legacyName) {
+ this(name, legacyName, false);
+ }
+
+ PgeTaskMetKeys(String name, String legacyName, boolean isVector) {
this.name = name;
this.legacyName = legacyName;
+ this.isVector = isVector;
}
public String getName() {
return Boolean.getBoolean(USE_LEGACY_PROPERTY) ? legacyName : name;
}
+
+ public boolean isVector() {
+ return isVector;
+ }
+
+ public static PgeTaskMetKeys getByName(String name) {
+ for (PgeTaskMetKeys key : values()) {
+ if (key.getName().equals(name)) {
+ return key;
+ }
+ }
+ return null;
+ }
}
Modified: oodt/trunk/pge/src/test/org/apache/oodt/cas/pge/TestPGETaskInstance.java
URL: http://svn.apache.org/viewvc/oodt/trunk/pge/src/test/org/apache/oodt/cas/pge/TestPGETaskInstance.java?rev=1301267&r1=1301266&r2=1301267&view=diff
==============================================================================
--- oodt/trunk/pge/src/test/org/apache/oodt/cas/pge/TestPGETaskInstance.java (original)
+++ oodt/trunk/pge/src/test/org/apache/oodt/cas/pge/TestPGETaskInstance.java Thu Mar 15 23:31:45 2012
@@ -25,6 +25,7 @@ import org.apache.oodt.cas.pge.PGETaskIn
import org.apache.oodt.cas.pge.config.PgeConfig;
import org.apache.oodt.cas.pge.metadata.PgeMetadata;
import org.apache.oodt.cas.pge.metadata.PgeTaskMetKeys;
+import org.apache.oodt.cas.workflow.structs.WorkflowTaskConfiguration;
//Google imports
import com.google.common.collect.Lists;
@@ -34,14 +35,16 @@ import junit.framework.TestCase;
/**
* Test class for {@link PGETaskInstance}.
- *
+ *
* @author bfoster (Brian Foster)
*/
public class TestPGETaskInstance extends TestCase {
public void testLoadPropertyAdders() throws Exception {
PGETaskInstance pgeTask = new PGETaskInstance();
- ConfigFilePropertyAdder propAdder = pgeTask.loadPropertyAdder(MockConfigFilePropertyAdder.class.getCanonicalName());
+ ConfigFilePropertyAdder propAdder = pgeTask
+ .loadPropertyAdder(MockConfigFilePropertyAdder.class
+ .getCanonicalName());
assertNotNull(propAdder);
assertTrue(propAdder instanceof MockConfigFilePropertyAdder);
}
@@ -49,33 +52,95 @@ public class TestPGETaskInstance extends
public void testRunPropertyAdders() throws Exception {
PGETaskInstance pgeTask = new PGETaskInstance();
Metadata staticMet = new Metadata();
- staticMet.addMetadata(PROPERTY_ADDERS.getName(), MockConfigFilePropertyAdder.class.getCanonicalName());
+ staticMet.addMetadata(PROPERTY_ADDERS.getName(),
+ MockConfigFilePropertyAdder.class.getCanonicalName());
Metadata dynMet = new Metadata();
pgeTask.pgeMetadata = new PgeMetadata(staticMet, dynMet);
pgeTask.pgeConfig = new PgeConfig();
- pgeTask.pgeConfig.setPropertyAdderCustomArgs(new Object[] { "key", "value" });
+ pgeTask.pgeConfig.setPropertyAdderCustomArgs(new Object[] { "key",
+ "value" });
pgeTask.runPropertyAdders();
assertEquals("value", pgeTask.pgeMetadata.getMetadata("key"));
staticMet = new Metadata();
dynMet = new Metadata();
- dynMet.addMetadata(PROPERTY_ADDERS.getName(), Lists.newArrayList(MockConfigFilePropertyAdder.class.getCanonicalName(), MockConfigFilePropertyAdder.class.getCanonicalName()));
+ dynMet.addMetadata(PROPERTY_ADDERS.getName(), Lists.newArrayList(
+ MockConfigFilePropertyAdder.class.getCanonicalName(),
+ MockConfigFilePropertyAdder.class.getCanonicalName()));
pgeTask.pgeMetadata = new PgeMetadata(staticMet, dynMet);
pgeTask.pgeConfig = new PgeConfig();
- pgeTask.pgeConfig.setPropertyAdderCustomArgs(new Object[] { "key", "value" });
+ pgeTask.pgeConfig.setPropertyAdderCustomArgs(new Object[] { "key",
+ "value" });
pgeTask.runPropertyAdders();
assertEquals("value", pgeTask.pgeMetadata.getMetadata("key"));
- assertEquals("2", pgeTask.pgeMetadata.getMetadata(MockConfigFilePropertyAdder.RUN_COUNTER));
+ assertEquals("2",
+ pgeTask.pgeMetadata
+ .getMetadata(MockConfigFilePropertyAdder.RUN_COUNTER));
System.setProperty(PgeTaskMetKeys.USE_LEGACY_PROPERTY, "true");
staticMet = new Metadata();
dynMet = new Metadata();
- dynMet.addMetadata(PROPERTY_ADDERS.getName(), MockConfigFilePropertyAdder.class.getCanonicalName());
+ dynMet.addMetadata(PROPERTY_ADDERS.getName(),
+ MockConfigFilePropertyAdder.class.getCanonicalName());
pgeTask.pgeMetadata = new PgeMetadata(staticMet, dynMet);
pgeTask.pgeConfig = new PgeConfig();
- pgeTask.pgeConfig.setPropertyAdderCustomArgs(new Object[] { "key", "value" });
+ pgeTask.pgeConfig.setPropertyAdderCustomArgs(new Object[] { "key",
+ "value" });
pgeTask.runPropertyAdders();
assertEquals("value", pgeTask.pgeMetadata.getMetadata("key"));
- assertEquals("1", pgeTask.pgeMetadata.getMetadata(MockConfigFilePropertyAdder.RUN_COUNTER));
+ assertEquals("1",
+ pgeTask.pgeMetadata
+ .getMetadata(MockConfigFilePropertyAdder.RUN_COUNTER));
+ }
+
+ public void testCreatePgeMetadata() {
+ final String PGE_NAME = "PGE_Test";
+ final String PGE_REQUIRED_METADATA = "Filename, FileLocation ";
+ final String PROP_ADDERS = "some.prop.adder.classpath,some.other.classpath";
+ PGETaskInstance pgeTask = new PGETaskInstance();
+ Metadata dynMet = new Metadata();
+ WorkflowTaskConfiguration config = new WorkflowTaskConfiguration();
+ config.addConfigProperty(PgeTaskMetKeys.NAME.getName(), PGE_NAME);
+ config.addConfigProperty(PgeTaskMetKeys.REQUIRED_METADATA.getName(),
+ PGE_REQUIRED_METADATA);
+ config.addConfigProperty(PgeTaskMetKeys.PROPERTY_ADDERS.getName(),
+ PROP_ADDERS);
+
+ PgeMetadata pgeMet = pgeTask.createPgeMetadata(dynMet, config);
+ assertEquals(1, pgeMet.getAllMetadata(PgeTaskMetKeys.NAME.getName())
+ .size());
+ assertEquals(PGE_NAME,
+ pgeMet.getAllMetadata(PgeTaskMetKeys.NAME.getName()).get(0));
+ assertEquals(2,
+ pgeMet.getAllMetadata(PgeTaskMetKeys.REQUIRED_METADATA.getName())
+ .size());
+ assertTrue(pgeMet.getAllMetadata(
+ PgeTaskMetKeys.REQUIRED_METADATA.getName()).contains("Filename"));
+ assertTrue(pgeMet.getAllMetadata(
+ PgeTaskMetKeys.REQUIRED_METADATA.getName())
+ .contains("FileLocation"));
+ assertEquals(2,
+ pgeMet.getAllMetadata(PgeTaskMetKeys.PROPERTY_ADDERS.getName())
+ .size());
+ assertTrue(pgeMet
+ .getAllMetadata(PgeTaskMetKeys.PROPERTY_ADDERS.getName()).contains(
+ "some.prop.adder.classpath"));
+ assertTrue(pgeMet
+ .getAllMetadata(PgeTaskMetKeys.PROPERTY_ADDERS.getName()).contains(
+ "some.other.classpath"));
+
+ // Verify still works when only one property adder is specified.
+ pgeTask = new PGETaskInstance();
+ config = new WorkflowTaskConfiguration();
+ config.addConfigProperty(PgeTaskMetKeys.PROPERTY_ADDERS.getName(),
+ "one.prop.adder.only");
+
+ pgeMet = pgeTask.createPgeMetadata(dynMet, config);
+ assertEquals(1,
+ pgeMet.getAllMetadata(PgeTaskMetKeys.PROPERTY_ADDERS.getName())
+ .size());
+ assertEquals("one.prop.adder.only",
+ pgeMet.getAllMetadata(PgeTaskMetKeys.PROPERTY_ADDERS.getName())
+ .get(0));
}
}
Modified: oodt/trunk/pge/src/test/org/apache/oodt/cas/pge/metadata/TestPgeTaskMetKeys.java
URL: http://svn.apache.org/viewvc/oodt/trunk/pge/src/test/org/apache/oodt/cas/pge/metadata/TestPgeTaskMetKeys.java?rev=1301267&r1=1301266&r2=1301267&view=diff
==============================================================================
--- oodt/trunk/pge/src/test/org/apache/oodt/cas/pge/metadata/TestPgeTaskMetKeys.java (original)
+++ oodt/trunk/pge/src/test/org/apache/oodt/cas/pge/metadata/TestPgeTaskMetKeys.java Thu Mar 15 23:31:45 2012
@@ -31,4 +31,14 @@ public class TestPgeTaskMetKeys extends
System.setProperty(PgeTaskMetKeys.USE_LEGACY_PROPERTY, "true");
assertEquals(PgeTaskMetKeys.NAME.getName(), PgeTaskMetKeys.NAME.legacyName);
}
+
+ public void testIsVector() {
+ assertFalse(PgeTaskMetKeys.NAME.isVector());
+ assertFalse(PgeTaskMetKeys.getByName(
+ PgeTaskMetKeys.NAME.getName()).isVector());
+ assertTrue(PgeTaskMetKeys.PROPERTY_ADDERS.isVector());
+ assertTrue(PgeTaskMetKeys.getByName(
+ PgeTaskMetKeys.PROPERTY_ADDERS.getName()).isVector());
+ assertNull(PgeTaskMetKeys.getByName("BOGUS/BOGUS/BOGUS"));
+ }
}