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 2010/12/23 03:44:31 UTC

svn commit: r1052143 [3/11] - in /oodt/branches/wengine-branch: ./ src/ src/main/ src/main/assembly/ src/main/bin/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/oodt/ src/main/java/org/apache/oodt/cas/ src/main/ja...

Added: oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/RunScriptInstance.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/RunScriptInstance.java?rev=1052143&view=auto
==============================================================================
--- oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/RunScriptInstance.java (added)
+++ oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/RunScriptInstance.java Thu Dec 23 02:44:23 2010
@@ -0,0 +1,43 @@
+/*
+ * 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.cas.workflow.instance;
+
+//OODT imports
+import org.apache.oodt.cas.workflow.metadata.ControlMetadata;
+import org.apache.oodt.cas.workflow.state.results.ResultsState;
+
+/**
+ * 
+ * @author bfoster
+ * @version $Revision$
+ *
+ *	TaskInstace for executing an external script
+ *
+ */
+public class RunScriptInstance extends TaskInstance {
+
+	private static String SCRIPT_PATH_KEY = "ScriptPath";
+
+	@Override
+	protected ResultsState performExecution(ControlMetadata crtlMetadata) {
+		String scriptPath = crtlMetadata.getMetadata(SCRIPT_PATH_KEY);
+		//TODO: fill in the guts!
+		return null;
+	}
+
+
+}

Added: oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/TaskInstance.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/TaskInstance.java?rev=1052143&view=auto
==============================================================================
--- oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/TaskInstance.java (added)
+++ oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/TaskInstance.java Thu Dec 23 02:44:23 2010
@@ -0,0 +1,208 @@
+/*
+ * 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.cas.workflow.instance;
+
+//JDK imports
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.Calendar;
+
+//OODT imports
+import org.apache.oodt.commons.date.DateUtils;
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.workflow.engine.WorkflowEngineClient;
+import org.apache.oodt.cas.workflow.exceptions.EngineException;
+import org.apache.oodt.cas.workflow.metadata.ControlMetadata;
+import org.apache.oodt.cas.workflow.metadata.WorkflowMetKeys;
+import org.apache.oodt.cas.workflow.processor.ProcessorInfo;
+import org.apache.oodt.cas.workflow.state.WorkflowState;
+import org.apache.oodt.cas.workflow.state.done.FailureState;
+import org.apache.oodt.cas.workflow.state.holding.UnknownState;
+import org.apache.oodt.cas.workflow.state.results.ResultsBailState;
+import org.apache.oodt.cas.workflow.state.results.ResultsFailureState;
+import org.apache.oodt.cas.workflow.state.results.ResultsState;
+import org.apache.oodt.cas.workflow.state.results.ResultsSuccessState;
+import org.apache.oodt.cas.workflow.state.running.ExecutingState;
+import org.apache.oodt.cas.workflow.state.transition.ExecutionCompleteState;
+import org.apache.oodt.cas.workflow.state.waiting.BlockedState;
+import org.apache.oodt.cas.workflow.util.WorkflowUtils;
+
+/**
+ * 
+ * @author bfoster
+ * @version $Revision$
+ *
+ *	Base TaskInstance which auto handles communicating metadata and state 
+ *	back to the WorkflowEngine from which it came.
+ *
+ */
+public abstract class TaskInstance {
+	
+	private static final Logger LOG = Logger.getLogger(TaskInstance.class.getName());
+	
+	private String jobId;
+	private String instanceId;
+	private String modelId;
+	private WorkflowEngineClient weClient;
+	private Metadata dynamicMetadata;
+	private Metadata staticMetadata;
+	private WorkflowState state;
+	
+	public void setJobId(String jobId) {
+		this.jobId = jobId;
+	}
+	
+	public String getJobId() {
+		return this.jobId;
+	}
+	
+	public void setInstanceId(String instanceId) {
+		this.instanceId = instanceId;
+	}
+	
+	public String getInstanceId() {
+		return this.instanceId;
+	}
+
+	public void setModelId(String modelId) {
+		this.modelId = modelId;
+	}
+	
+	public String getModelId() {
+		return this.modelId;
+	}
+	
+	public ProcessorInfo getProcessorInfo() throws EngineException {
+		return this.weClient.getProcessorInfo(this.instanceId, this.modelId);
+	}
+	
+	public WorkflowState getState() {
+		return this.state;
+	}
+	
+	public void setNotifyEngine(WorkflowEngineClient weClient) {
+		this.weClient = weClient;
+	}
+	
+	public void setDynamicMetadata(Metadata dynamicMetadata) {
+		this.dynamicMetadata = new Metadata(dynamicMetadata);
+	}
+	
+	public void setStaticMetadata(Metadata staticMetadata) {
+		this.staticMetadata = staticMetadata;
+	}
+	
+	public Metadata getMetadata() {
+		return new ControlMetadata(this.staticMetadata, this.dynamicMetadata).asMetadata();
+	}
+    
+    private void syncWorkflowMetadata(ControlMetadata ctrlMetadata) {
+    	try {
+			this.weClient.updateWorkflowMetadata(this.instanceId, this.modelId, ctrlMetadata.asMetadata(ControlMetadata.DYN));
+		}catch (Exception e) {
+			LOG.log(Level.SEVERE, "Failed to update workflow metadata for jobId = " + this.jobId + " ; modelId = " + this.modelId + " : " + e.getMessage(), e);
+		}
+    }
+	
+    private void syncInstanceMetadata(ControlMetadata ctrlMetadata) {
+    	try {
+    		this.weClient.updateInstanceMetadata(this.jobId, ctrlMetadata.asMetadata());
+    	}catch (Exception e) {
+    		LOG.log(Level.SEVERE, "Failed to update instance metadata for jobId = " + this.jobId + " ; modelId = " + this.modelId + " : " + e.getMessage(), e);
+    	}
+    }
+
+    private void syncWorkflowAndInstanceMetadata(Metadata metadata, Metadata instanceMetadata) {
+    	try {
+			this.weClient.updateWorkflowAndInstance(this.instanceId, this.modelId, this.state, metadata, this.jobId, instanceMetadata);
+		}catch (Exception e) {
+			LOG.log(Level.SEVERE, "Failed to update workflow and instance metadata for jobId = " + this.jobId + " ; modelId = " + this.modelId + " : " + e.getMessage(), e);
+		}
+    }
+    
+    private void syncState(WorkflowState workflowState) throws EngineException {
+		this.weClient.setWorkflowState(this.instanceId, this.modelId, workflowState);
+    }
+    
+    private void synchWithEngine(WorkflowState workflowState, ControlMetadata ctrlMetadata) {
+    	try {
+    		Metadata metadata = ctrlMetadata.asMetadata(ControlMetadata.DYN);
+	    	this.addStandardInstanceMetadata(workflowState, ctrlMetadata);
+	    	Metadata instanceMetadata = ctrlMetadata.asMetadata();
+	    	this.syncWorkflowAndInstanceMetadata(metadata, instanceMetadata);
+    	}catch (Exception e) {
+			LOG.log(Level.SEVERE, "Failed to updated instance state and metadata : " + e.getMessage(), e);
+		}
+    }
+    
+    private void addStandardInstanceMetadata(WorkflowState workflowState, ControlMetadata ctrlMetadata) throws Exception {
+    	ctrlMetadata.replaceLocalMetadata(WorkflowMetKeys.JOB_ID, this.jobId);
+    	ctrlMetadata.replaceLocalMetadata(WorkflowMetKeys.INSTANCE_ID, this.instanceId);
+    	ctrlMetadata.replaceLocalMetadata(WorkflowMetKeys.MODEL_ID, this.modelId);
+    	ctrlMetadata.replaceLocalMetadata(WorkflowMetKeys.STATE, workflowState.getName());
+    	ctrlMetadata.replaceLocalMetadata(WorkflowMetKeys.HOST, WorkflowUtils.getHostName());
+    	ProcessorInfo processorInfo = this.getProcessorInfo();
+    	Calendar calendar = Calendar.getInstance();
+    	calendar.setTime(processorInfo.getCreationDate());
+    	ctrlMetadata.replaceLocalMetadata(WorkflowMetKeys.CREATION_DATE, DateUtils.toString(DateUtils.toUtc(calendar)));
+    	calendar.setTime(processorInfo.getReadyDate());
+    	ctrlMetadata.replaceLocalMetadata(WorkflowMetKeys.READY_DATE, DateUtils.toString(DateUtils.toUtc(calendar)));
+    	if (processorInfo.getExecutionDate() != null) {
+        	calendar.setTime(processorInfo.getExecutionDate());
+        	ctrlMetadata.replaceLocalMetadata(WorkflowMetKeys.EXECUTION_DATE, DateUtils.toString(DateUtils.toUtc(calendar)));
+    	}
+    	if (processorInfo.getCompletionDate() != null) {
+    		calendar.setTime(processorInfo.getCompletionDate());
+    		ctrlMetadata.replaceLocalMetadata(WorkflowMetKeys.COMPLETION_DATE, DateUtils.toString(DateUtils.toUtc(calendar)));
+    	}
+    }
+    
+    protected void update(ExecutingState workflowState, ControlMetadata ctrlMetadata) {
+    	this.synchWithEngine(workflowState, ctrlMetadata);
+    }
+    
+    public void execute() {
+    	ControlMetadata ctrlMetadata = new ControlMetadata(this.staticMetadata, this.dynamicMetadata);
+    	this.state = new ExecutingState("");
+    	
+    	try {
+    		this.synchWithEngine(this.state, ctrlMetadata);
+        	ResultsState resultsState = this.performExecution(ctrlMetadata);
+        	if (resultsState instanceof ResultsSuccessState) {
+        		this.state = new ExecutionCompleteState("Successfully Executed Task [ModelId='" + this.modelId + "',JobId='" + this.jobId + "'] : " + resultsState.getMessage());
+        	}else if (resultsState instanceof ResultsFailureState) {
+        		this.state = new FailureState("Failed to Execute Task [ModelId='" + this.modelId + "',JobId='" + this.jobId + "'] : " + resultsState.getMessage());
+        	}else if (resultsState instanceof ResultsBailState) {
+        		this.state = new BlockedState("Task Bailed : " + resultsState.getMessage());
+        	}else {
+        		this.state = new UnknownState("Task [ModelId='" + this.modelId + "',JobId='" + this.jobId + "'] returned unsupported ResultState '" + resultsState + "' : " + resultsState.getMessage());
+        	}
+    	}catch (Exception e) {
+    		this.state = new FailureState("Execution of Task [ModelId='" + this.modelId + "',JobId='" + this.jobId + "'] failed : " + e.getMessage());
+    		LOG.log(Level.SEVERE, "Execution of Task [InstanceId='" + this.instanceId + "',ModelId='" + this.modelId + "',JobId='" + this.jobId + "'] failed : " + e.getMessage(), e);
+    	}catch (Error e) {
+    		this.state = new FailureState("Execution of Task (Fatal Error!!!) [ModelId='" + this.modelId + "',JobId='" + this.jobId + "'] failed : " + e.getMessage());
+    		LOG.log(Level.SEVERE, "Execution of Task (Fatal Error!!!) [InstanceId='" + this.instanceId + "',ModelId='" + this.modelId + "',JobId='" + this.jobId + "'] failed : " + e.getMessage(), e);
+    	}finally {
+    		ctrlMetadata.commitWorkflowMetadataKeys();
+    		this.synchWithEngine(this.state, ctrlMetadata);
+    	}
+    }
+    
+    protected abstract ResultsState performExecution(ControlMetadata crtlMetadata);
+
+}

Added: oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/ValidateMetadataInstance.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/ValidateMetadataInstance.java?rev=1052143&view=auto
==============================================================================
--- oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/ValidateMetadataInstance.java (added)
+++ oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/ValidateMetadataInstance.java Thu Dec 23 02:44:23 2010
@@ -0,0 +1,55 @@
+/*
+ * 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.cas.workflow.instance;
+
+//OODT imports
+import org.apache.oodt.cas.workflow.metadata.ControlMetadata;
+import org.apache.oodt.cas.workflow.state.results.ResultsFailureState;
+import org.apache.oodt.cas.workflow.state.results.ResultsState;
+import org.apache.oodt.cas.workflow.state.results.ResultsSuccessState;
+
+/**
+ * 
+ * @author bfoster
+ * @version $Revision$
+ * 
+ * Test TaskInstance which checks to insure proper metadata flow is happening
+ * between workflow processors
+ *
+ */
+public class ValidateMetadataInstance extends TaskInstance {
+
+	private static final String VALIDATE_KEY = "validateKey";
+	
+	@Override
+	protected ResultsState performExecution(ControlMetadata crtlMetadata) {
+		crtlMetadata.replaceLocalMetadata(this.getModelId() + "_key", this.getInstanceId());
+		crtlMetadata.setAsWorkflowMetadataKey(this.getModelId() + "_key");
+		
+		String keyNames = crtlMetadata.getMetadata(VALIDATE_KEY);
+		if (keyNames == null)
+			return new ResultsSuccessState("No key name requested to look for");
+		
+		String[] splitKeyNames = keyNames.split(",");
+		for (String keyName : splitKeyNames) {
+			if (crtlMetadata.getMetadata(keyName) == null) 
+				return new ResultsFailureState(keyName + " not found in metadata");
+		}
+		return new ResultsSuccessState("All keys '" + keyNames + "' where found in metadata");
+	}
+
+}

Added: oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowInstanceRepository.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowInstanceRepository.java?rev=1052143&view=auto
==============================================================================
--- oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowInstanceRepository.java (added)
+++ oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowInstanceRepository.java Thu Dec 23 02:44:23 2010
@@ -0,0 +1,116 @@
+/*
+ * 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.cas.workflow.instance.repo;
+
+//OODT imports
+import org.apache.oodt.cas.catalog.metadata.TransactionalMetadata;
+import org.apache.oodt.cas.catalog.page.PageInfo;
+import org.apache.oodt.cas.catalog.page.QueryPager;
+import org.apache.oodt.cas.catalog.page.TransactionReceipt;
+import org.apache.oodt.cas.catalog.query.ComparisonQueryExpression;
+import org.apache.oodt.cas.catalog.query.QueryExpression;
+import org.apache.oodt.cas.catalog.struct.TransactionId;
+import org.apache.oodt.cas.catalog.system.CatalogService;
+import org.apache.oodt.cas.catalog.term.Term;
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.workflow.page.QueryPage;
+import static org.apache.oodt.cas.workflow.metadata.WorkflowMetKeys.*;
+
+//JDK imports
+import java.util.Collections;
+import java.util.List;
+import java.util.Vector;
+
+/**
+ * @author mattmann
+ * @author bfoster
+ * @version $Revision$
+ * 
+ * <p>
+ * TaskInstance Metadata Repository which utilizes CAS-Catalog
+ * </p>.
+ */
+public class WorkflowInstanceRepository {
+
+	private CatalogService catalogService;
+	
+	public WorkflowInstanceRepository(CatalogService catalogService) {
+		this.catalogService = catalogService;
+	}
+	
+    public void storeInstanceMetadata(String jobId, Metadata metadata) throws Exception {
+    	metadata.replaceMetadata(CatalogService.CATALOG_SERVICE_TRANSACTION_ID_MET_KEY, jobId);
+    	metadata.replaceMetadata(CatalogService.ENABLE_UPDATE_MET_KEY, "true");
+    	this.catalogService.ingest(metadata);
+    }
+
+    public void removeInstanceMetadatas(String instanceId) throws Exception {
+    	for (TransactionId<?> transId : this.getTransactionIdsByInstanceId(instanceId)) {
+    		Metadata m = new Metadata();
+    		m.replaceMetadata(CatalogService.CATALOG_SERVICE_TRANSACTION_ID_MET_KEY, transId.toString());
+    		this.catalogService.delete(m);
+    	}
+    }
+    
+    public void removeInstanceMetadata(String jobId) throws Exception {
+		Metadata m = new Metadata();
+		m.addMetadata(CatalogService.CATALOG_SERVICE_TRANSACTION_ID_MET_KEY, jobId);
+		this.catalogService.delete(m);
+    }
+    
+    public List<String> getJobIds(String instanceId) throws Exception {
+    	List<String> jobIds = new Vector<String>();
+    	for (TransactionId<?> transId : this.getTransactionIdsByInstanceId(instanceId))
+    		jobIds.add(transId.toString());
+    	return jobIds;
+    }
+
+    public Metadata getInstanceMetadata(String jobId) throws Exception {
+		List<TransactionalMetadata> metadatas = this.catalogService.getMetadataFromTransactionIdStrings(Collections.singletonList(jobId));
+		if (metadatas.size() > 0)
+			return metadatas.get(0).getMetadata();
+		else
+			return new Metadata();
+    }
+    
+	public QueryPage getNextPage(QueryPage page) throws Exception {
+		return new QueryPage(this.catalogService.getNextPage(page));
+	}
+	
+	public QueryPage getPage(PageInfo pageInfo, QueryExpression queryExpression) throws Exception {
+    	return new QueryPage(this.catalogService.getPage(pageInfo, queryExpression));
+	}
+	
+	public List<Metadata> getMetadata(QueryPage page) throws Exception {
+    	List<Metadata> metadatas = new Vector<Metadata>();
+    	for(TransactionalMetadata m : this.catalogService.getMetadata(page))
+    		metadatas.add(m.getMetadata());
+    	return metadatas;
+	}
+    
+    protected List<TransactionId<?>> getTransactionIdsByInstanceId(String instanceId) throws Exception {
+    	ComparisonQueryExpression query = new ComparisonQueryExpression();
+    	query.setOperator(ComparisonQueryExpression.Operator.EQUAL_TO);
+    	query.setTerm(new Term(INSTANCE_ID, Collections.singletonList(instanceId)));
+    	QueryPager queryPager = this.catalogService.query(query);
+    	Vector<TransactionId<?>> transIds = new Vector<TransactionId<?>>();
+    	for (TransactionReceipt receipt: queryPager.getTransactionReceipts())
+    		transIds.add(receipt.getTransactionId());
+    	return transIds;
+    }
+
+}

Added: oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowInstanceRepositoryFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowInstanceRepositoryFactory.java?rev=1052143&view=auto
==============================================================================
--- oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowInstanceRepositoryFactory.java (added)
+++ oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowInstanceRepositoryFactory.java Thu Dec 23 02:44:23 2010
@@ -0,0 +1,50 @@
+/*
+ * 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.cas.workflow.instance.repo;
+
+//OODT imports
+import org.apache.oodt.cas.catalog.system.CatalogServiceFactory;
+
+/**
+ * @author bfoster
+ * @version $Revision$
+ * 
+ * Factory which creates a cas-catalog workflow instance metadata repository
+ *
+ */
+public class WorkflowInstanceRepositoryFactory {
+
+	private CatalogServiceFactory csFactory;
+	
+	public WorkflowInstanceRepository createRepo() {
+		try {
+			return new WorkflowInstanceRepository(this.csFactory.createCatalogService());
+		}catch (Exception e) {
+			e.printStackTrace();
+			return null;
+		}
+	}
+
+	public CatalogServiceFactory getCatalogServiceFactory() {
+		return csFactory;
+	}
+
+	public void setCatalogServiceFactory(CatalogServiceFactory csFactory) {
+		this.csFactory = csFactory;
+	}
+	
+}

Added: oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowManagerDataSourceIndex.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowManagerDataSourceIndex.java?rev=1052143&view=auto
==============================================================================
--- oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowManagerDataSourceIndex.java (added)
+++ oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowManagerDataSourceIndex.java Thu Dec 23 02:44:23 2010
@@ -0,0 +1,539 @@
+/*
+ * 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.cas.workflow.instance.repo;
+
+//JDK imports
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Vector;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+//SQL imports
+import javax.sql.DataSource;
+
+//OODT imports
+import org.apache.oodt.cas.catalog.exception.CatalogIndexException;
+import org.apache.oodt.cas.catalog.exception.IngestServiceException;
+import org.apache.oodt.cas.catalog.exception.QueryServiceException;
+import org.apache.oodt.cas.catalog.page.IndexPager;
+import org.apache.oodt.cas.catalog.page.IngestReceipt;
+import org.apache.oodt.cas.catalog.query.ComparisonQueryExpression;
+import org.apache.oodt.cas.catalog.query.NotQueryExpression;
+import org.apache.oodt.cas.catalog.query.QueryExpression;
+import org.apache.oodt.cas.catalog.query.QueryLogicalGroup;
+import org.apache.oodt.cas.catalog.query.StdQueryExpression;
+import org.apache.oodt.cas.catalog.struct.Index;
+import org.apache.oodt.cas.catalog.struct.IngestService;
+import org.apache.oodt.cas.catalog.struct.QueryService;
+import org.apache.oodt.cas.catalog.struct.TransactionId;
+import org.apache.oodt.cas.catalog.struct.TransactionIdFactory;
+import org.apache.oodt.cas.catalog.struct.impl.transaction.UuidTransactionIdFactory;
+import org.apache.oodt.cas.catalog.term.Term;
+import org.apache.oodt.cas.catalog.term.TermBucket;
+import org.apache.oodt.commons.date.DateUtils;
+import static org.apache.oodt.cas.workflow.metadata.WorkflowMetKeys.*;
+
+/**
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>
+ * A queriable index for querying for cas-workflow instance metadata
+ * <p>
+ */
+public class WorkflowManagerDataSourceIndex implements Index, QueryService, IngestService {
+
+	private static final Logger LOG = Logger.getLogger(WorkflowManagerDataSourceIndex.class.getName());
+	
+	protected DataSource dataSource;
+	
+	public WorkflowManagerDataSourceIndex(DataSource dataSource) throws InstantiationException {
+		this.dataSource = dataSource;
+	}
+	
+	public List<TransactionId<?>> getPage(IndexPager indexPage)
+			throws CatalogIndexException {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public Properties getProperties() throws CatalogIndexException {
+		return new Properties();
+	}
+
+	public String getProperty(String key) throws CatalogIndexException {
+		return null;
+	}
+
+	public TransactionIdFactory getTransactionIdFactory() throws CatalogIndexException {
+		return new UuidTransactionIdFactory();
+	}
+
+	public boolean hasTransactionId(TransactionId<?> transactionId)
+			throws CatalogIndexException {
+		Connection conn = null;
+		Statement stmt = null;
+		ResultSet rs = null;
+		try {
+			conn = this.dataSource.getConnection();
+			stmt = conn.createStatement();
+			rs = stmt.executeQuery("SELECT DISTINCT workflow_instance_id FROM workflow_instance_metadata WHERE workflow_instance_id = '" + transactionId + "'");	
+			return rs.next();
+		}catch (Exception e) {
+			throw new CatalogIndexException("Failed to check for workflow id '" + transactionId + "' : " + e.getMessage(), e);
+		}finally {
+			try {
+				conn.close();
+			}catch(Exception e) {}
+			try {
+				stmt.close();
+			}catch(Exception e) {}
+			try {
+				rs.close();
+			}catch(Exception e) {}
+		}
+	}
+
+	public List<TermBucket> getBuckets(TransactionId<?> transactionId)
+			throws QueryServiceException {
+		Connection conn = null;
+		Statement stmt = null;
+		ResultSet rs = null;
+		try {
+			conn = this.dataSource.getConnection();
+			stmt = conn.createStatement();
+			rs = stmt.executeQuery("SELECT * FROM workflow_instance_metadata WHERE workflow_instance_id = '" + transactionId + "'");	
+			
+			TermBucket tb = new TermBucket("Workflows");
+			while (rs.next()) {
+                String key = URLDecoder.decode(rs.getString("workflow_met_key"), "UTF-8");
+                String value = URLDecoder.decode(rs.getString("workflow_met_val"), "UTF-8");
+                tb.addTerm(new Term(key, Collections.singletonList(value)));
+            }
+			return Collections.singletonList(tb);
+		}catch (Exception e) {
+			throw new QueryServiceException("Failed to get Workflow Instance Metadata for workflow id '" + transactionId + "' : " + e.getMessage(), e);
+		}finally {
+			try {
+				conn.close();
+			}catch(Exception e) {}
+			try {
+				stmt.close();
+			}catch(Exception e) {}
+			try {
+				rs.close();
+			}catch(Exception e) {}
+		}
+	}
+
+	public Map<TransactionId<?>, List<TermBucket>> getBuckets(
+			List<TransactionId<?>> transactionIds) throws QueryServiceException {
+		Map<TransactionId<?>, List<TermBucket>> returnMap = new HashMap<TransactionId<?>, List<TermBucket>>();
+		for (TransactionId<?> transactionId : transactionIds) 
+			returnMap.put(transactionId, this.getBuckets(transactionId));
+		return returnMap;
+	}
+
+	public List<IngestReceipt> query(QueryExpression queryExpression)
+			throws QueryServiceException {
+		Connection conn = null;
+		Statement stmt = null;
+		ResultSet rs = null;
+		try {
+			conn = this.dataSource.getConnection();
+			stmt = conn.createStatement();
+			String sqlQuery = this.getSqlQuery(queryExpression);
+	        LOG.log(Level.INFO, "Performing Query: " + sqlQuery);
+			rs = stmt.executeQuery(sqlQuery);	
+
+			Vector<String> workflowInstanceIds = new Vector<String>();
+			while (rs.next()) 
+				workflowInstanceIds.add(rs.getString("workflow_instance_id"));
+			
+			try {
+				rs.close();
+			}catch(Exception e) {}
+			
+			List<IngestReceipt> receipts = new Vector<IngestReceipt>();
+			for (String workflowInstanceId : workflowInstanceIds) {
+                String creationDate = null;
+                try {
+                	sqlQuery = "SELECT workflow_met_val FROM workflow_instance_metadata WHERE workflow_instance_id = '" + workflowInstanceId + "' AND workflow_met_key = '" + URLEncoder.encode(CREATION_DATE, "UTF-8") + "'";
+        	        LOG.log(Level.INFO, "Performing Query: " + sqlQuery);
+        	        rs = stmt.executeQuery(sqlQuery);
+        	        if (rs.next()) {
+        	        	creationDate = URLDecoder.decode(rs.getString("workflow_met_val"), "UTF-8");
+        	        }else {
+        	        	creationDate = DateUtils.toString(DateUtils.toUtc(Calendar.getInstance()));
+        	        	LOG.log(Level.WARNING, "CreationDate not found for '" + workflowInstanceId + "' . . . db might be out of sync . . . fixing CreationDate to '" + creationDate + "'");
+        	        }
+                }catch (Exception e) {
+                	throw new QueryServiceException("Failed to get CreationDate for InstanceId '" + workflowInstanceId + "' : " + e.getMessage(), e);
+                }
+                receipts.add(new IngestReceipt(new UuidTransactionIdFactory().createTransactionId(workflowInstanceId), DateUtils.toCalendar(creationDate, DateUtils.FormatType.UTC_FORMAT).getTime()));
+            }
+			return receipts;
+		}catch (Exception e) {
+			throw new QueryServiceException("Failed to query Workflow Instances Database : " + e.getMessage(), e);
+		}finally {
+			try {
+				conn.close();
+			}catch(Exception e) {}
+			try {
+				stmt.close();
+			}catch(Exception e) {}
+			try {
+				rs.close();
+			}catch(Exception e) {}
+		}
+	}
+	
+	public List<IngestReceipt> query(QueryExpression queryExpression,
+			int startIndex, int endIndex) throws QueryServiceException {
+		Connection conn = null;
+		Statement stmt = null;
+		ResultSet rs = null;
+		try {
+			conn = this.dataSource.getConnection();
+			stmt = conn.createStatement();
+			String sqlQuery = this.getSqlQuery(queryExpression);
+	        LOG.log(Level.INFO, "Performing Query: " + sqlQuery);
+			rs = stmt.executeQuery(sqlQuery);	
+
+			Vector<String> workflowInstanceIds = new Vector<String>();
+			while (rs.next()) 
+				workflowInstanceIds.add(rs.getString("workflow_instance_id"));
+			
+			try {
+				rs.close();
+			}catch(Exception e) {}
+			
+			List<IngestReceipt> receipts = new Vector<IngestReceipt>();
+			for (int i = startIndex; i < endIndex; i++) {
+				String workflowInstanceId = workflowInstanceIds.get(i);
+                String creationDate = null;
+                try {
+                	sqlQuery = "SELECT workflow_met_val FROM workflow_instance_metadata WHERE workflow_instance_id = '" + workflowInstanceId + "' AND workflow_met_key = '" + URLEncoder.encode(CREATION_DATE, "UTF-8") + "'";
+        	        LOG.log(Level.INFO, "Performing Query: " + sqlQuery);
+        	        rs = stmt.executeQuery(sqlQuery);
+        	        if (rs.next()) {
+        	        	creationDate = URLDecoder.decode(rs.getString("workflow_met_val"), "UTF-8");
+        	        }else {
+        	        	creationDate = DateUtils.toString(DateUtils.toUtc(Calendar.getInstance()));
+        	        	LOG.log(Level.WARNING, "CreationDate not found for '" + workflowInstanceId + "' . . . db might be out of sync . . . fixing CreationDate to '" + creationDate + "'");
+        	        }
+                }catch (Exception e) {
+                	throw new QueryServiceException("Failed to get CreationDate for InstanceId '" + workflowInstanceId + "' : " + e.getMessage(), e);
+                }
+                receipts.add(new IngestReceipt(new UuidTransactionIdFactory().createTransactionId(workflowInstanceId), DateUtils.toCalendar(creationDate, DateUtils.FormatType.UTC_FORMAT).getTime()));
+            }
+			return receipts;
+		}catch (Exception e) {
+			throw new QueryServiceException("Failed to query Workflow Instances Database : " + e.getMessage(), e);
+		}finally {
+			try {
+				conn.close();
+			}catch(Exception e) {}
+			try {
+				stmt.close();
+			}catch(Exception e) {}
+			try {
+				rs.close();
+			}catch(Exception e) {}
+		}
+	}
+
+	public int sizeOf(QueryExpression queryExpression)
+			throws QueryServiceException {
+		Connection conn = null;
+		Statement stmt = null;
+		ResultSet rs = null;
+		try {
+			conn = this.dataSource.getConnection();
+			stmt = conn.createStatement();
+			String sqlQuery = this.getSqlQuery(queryExpression);
+	        LOG.log(Level.INFO, "Performing Query: " + sqlQuery);
+			rs = stmt.executeQuery(sqlQuery);	
+
+			int numWorkflowInstances = 0;
+            while (rs.next())
+            	numWorkflowInstances = rs.getInt("workflow_instance_id");
+			
+            return numWorkflowInstances;
+		}catch (Exception e) {
+			throw new QueryServiceException("Failed to query Workflow Instances Database : " + e.getMessage(), e);
+		}finally {
+			try {
+				conn.close();
+			}catch(Exception e) {}
+			try {
+				stmt.close();
+			}catch(Exception e) {}
+			try {
+				rs.close();
+			}catch(Exception e) {}
+		}
+	}
+
+    private String getSqlQuery(QueryExpression queryExpression) throws QueryServiceException, UnsupportedEncodingException {
+        String sqlQuery = null;
+        if (queryExpression instanceof QueryLogicalGroup) {
+        	QueryLogicalGroup qlg = (QueryLogicalGroup) queryExpression;
+            sqlQuery = "(" + this.getSqlQuery(qlg.getExpressions().get(0));
+            String op = qlg.getOperator() == QueryLogicalGroup.Operator.AND ? "INTERSECT" : "UNION";
+            for (int i = 1; i < qlg.getExpressions().size(); i++) 
+                sqlQuery += ") " + op + " (" + this.getSqlQuery(qlg.getExpressions().get(i));
+            sqlQuery += ")";
+        }else if (queryExpression instanceof ComparisonQueryExpression){
+        	ComparisonQueryExpression cqe = (ComparisonQueryExpression) queryExpression;
+        	String operator = null;
+            if (cqe.getOperator().equals(ComparisonQueryExpression.Operator.EQUAL_TO)) {
+            	operator = "=";
+            } else if (cqe.getOperator().equals(ComparisonQueryExpression.Operator.GREATER_THAN)) {
+            	operator = ">";
+            } else if (cqe.getOperator().equals(ComparisonQueryExpression.Operator.GREATER_THAN_EQUAL_TO)) {
+            	operator = ">=";
+            } else if (cqe.getOperator().equals(ComparisonQueryExpression.Operator.LESS_THAN)) {
+            	operator = "<";
+            } else if (cqe.getOperator().equals(ComparisonQueryExpression.Operator.LESS_THAN_EQUAL_TO)) {
+            	operator = "<=";
+            } else {
+                throw new QueryServiceException("Invalid ComparisonQueryExpression Operator '" + cqe.getOperator() + "'");
+            }
+            
+            sqlQuery = "SELECT DISTINCT workflow_instance_id FROM workflow_instance_metadata WHERE workflow_met_key = '" + URLEncoder.encode(cqe.getTerm().getName(), "UTF-8") + "' AND (";
+        	for (int i = 0; i < cqe.getTerm().getValues().size(); i++) {
+        		String value = cqe.getTerm().getValues().get(i);
+                sqlQuery += "workflow_met_val " + operator + " '" + URLEncoder.encode(value, "UTF-8") + "'";
+	            if ((i + 1) < cqe.getTerm().getValues().size())
+	            	sqlQuery += "OR";
+        	}
+        	sqlQuery += ")";
+        }else if (queryExpression instanceof NotQueryExpression) {
+        	NotQueryExpression nqe = (NotQueryExpression) queryExpression;
+            sqlQuery = "SELECT DISTINCT workflow_instance_id FROM workflow_instance_metadata WHERE NOT (" + this.getSqlQuery(nqe.getQueryExpression()) + ")";
+        }else if (queryExpression instanceof StdQueryExpression) {
+            sqlQuery = "SELECT DISTINCT workflow_instance_id FROM workflow_instance_metadata";
+        }else {
+            throw new QueryServiceException("Invalid QueryExpression '" + queryExpression.getClass().getCanonicalName() + "'");
+        }
+        return sqlQuery;
+    }
+
+	public boolean delete(TransactionId<?> transactionId)
+			throws IngestServiceException {
+	    Connection conn = null;
+		Statement statement = null;
+
+		try {
+			conn = dataSource.getConnection();
+			conn.setAutoCommit(false);
+			statement = conn.createStatement();
+
+			String deleteSql = "DELETE FROM workflow_instance_metadata "
+					+ "WHERE workflow_instance_id = '" + transactionId + "'";
+
+			LOG.log(Level.FINE, "sql: Executing: " + deleteSql);
+			statement.execute(deleteSql);
+			conn.commit();
+			return true;
+		} catch (Exception e) {
+			LOG.log(Level.WARNING,
+					"Exception removing workflow instance metadata. Message: "
+							+ e.getMessage());
+			try {
+				conn.rollback();
+			} catch (SQLException e2) {
+				LOG.log(Level.SEVERE,
+						"Unable to rollback removeWorkflowInstanceMetadata "
+								+ "transaction. Message: " + e2.getMessage());
+			}
+			throw new IngestServiceException(e.getMessage(), e);
+		} finally {
+			if (statement != null) {
+				try {
+					statement.close();
+				} catch (SQLException ignore) {
+				}
+
+				statement = null;
+			}
+
+			if (conn != null) {
+				try {
+					conn.close();
+
+				} catch (SQLException ignore) {
+				}
+
+				conn = null;
+			}
+		}
+	}
+
+	public IngestReceipt ingest(List<TermBucket> termBuckets) throws IngestServiceException {
+        try {
+        	String creationDate = null;
+			TransactionId<?> transactionId = this.getTransactionIdFactory().createNewTransactionId(); 
+	        for (TermBucket termBucket : termBuckets) {
+				for (Term term : termBucket.getTerms()) {
+					if (term.getName().equals(CREATION_DATE))
+						creationDate = term.getFirstValue();
+					for (String val : term.getValues()) {
+						Connection conn = null;
+						Statement statement = null;
+	
+						try {
+							conn = dataSource.getConnection();
+							conn.setAutoCommit(false);
+							statement = conn.createStatement();
+							String addMetSql = "INSERT INTO workflow_instance_metadata"
+									+ " (workflow_instance_id,workflow_met_key,workflow_met_val) VALUES ('"
+									+ transactionId
+									+ "','"
+									+ URLEncoder.encode(term.getName(), "UTF-8")
+									+ "','"
+									+ URLEncoder.encode(val, "UTF-8") + "')";
+	
+							LOG.log(Level.FINE, "sql: Executing: " + addMetSql);
+							statement.execute(addMetSql);
+	
+							conn.commit();
+						} catch (Exception e) {
+							LOG.log(Level.WARNING, "Exception adding metadata ["
+									+ term.getName() + "=>" + val
+									+ "] to workflow inst: [" + transactionId
+									+ "]. Message: " + e.getMessage(), e);
+							try {
+								conn.rollback();
+							} catch (SQLException e2) {
+								LOG.log(Level.SEVERE,
+										"Unable to rollback addMetadataValue transaction. Message: "
+												+ e2.getMessage(), e);
+							}
+						} finally {
+	
+							if (statement != null) {
+								try {
+									statement.close();
+								} catch (SQLException ignore) {
+								}
+	
+								statement = null;
+							}
+	
+							if (conn != null) {
+								try {
+									conn.close();
+	
+								} catch (SQLException ignore) {
+								}
+	
+								conn = null;
+							}
+						}
+					}
+				}
+			}
+			return new IngestReceipt(transactionId, DateUtils.toCalendar(creationDate, DateUtils.FormatType.UTC_FORMAT).getTime());
+		} catch (Exception e) {
+			throw new IngestServiceException("Failed to ingest : " + e.getMessage(), e);
+		}
+	}
+
+	public boolean reduce(TransactionId<?> transactionId,
+			List<TermBucket> termBuckets) throws IngestServiceException {
+	    Connection conn = null;
+	    Statement statement = null;
+
+		try {
+			for (TermBucket bucket: termBuckets) {
+				for (Term term: bucket.getTerms()) {
+					for (String val: term.getValues()) {
+						conn = dataSource.getConnection();
+						conn.setAutoCommit(false);
+						statement = conn.createStatement();
+	
+						String deleteSql = "DELETE FROM workflow_instance_metadata "
+								+ "WHERE workflow_instance_id = '"
+								+ transactionId
+								+ "' AND workflow_met_key = '"
+								+ URLEncoder.encode(term.getName(), "UTF-8")
+								+ "' AND workflow_met_val = '"
+								+ URLEncoder.encode(val, "UTF-8") + "'";
+	
+						LOG.log(Level.FINE, "sql: Executing: " + deleteSql);
+						statement.execute(deleteSql);
+						conn.commit();	
+					}
+				}
+			}
+			return true;
+		} catch (Exception e) {
+			e.printStackTrace();
+			LOG.log(Level.WARNING,
+					"Exception removing workflow instance metadata. Message: "
+							+ e.getMessage());
+			try {
+				conn.rollback();
+			} catch (SQLException e2) {
+				LOG.log(Level.SEVERE,
+						"Unable to rollback removeWorkflowInstanceMetadata "
+								+ "transaction. Message: " + e2.getMessage());
+			}
+			throw new IngestServiceException(e.getMessage());
+		} finally {
+			if (statement != null) {
+				try {
+					statement.close();
+				} catch (SQLException ignore) {
+				}
+
+				statement = null;
+			}
+
+			if (conn != null) {
+				try {
+					conn.close();
+
+				} catch (SQLException ignore) {
+				}
+
+				conn = null;
+			}
+		}
+	}
+
+	public IngestReceipt update(TransactionId<?> transactionId,
+			List<TermBucket> termBuckets) throws IngestServiceException {
+		this.delete(transactionId);
+		return this.ingest(termBuckets);
+	}
+
+}

Added: oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowManagerDataSourceIndexFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowManagerDataSourceIndexFactory.java?rev=1052143&view=auto
==============================================================================
--- oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowManagerDataSourceIndexFactory.java (added)
+++ oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowManagerDataSourceIndexFactory.java Thu Dec 23 02:44:23 2010
@@ -0,0 +1,63 @@
+/*
+ * 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.cas.workflow.instance.repo;
+
+//OODT imports
+import org.apache.oodt.cas.catalog.struct.IndexFactory;
+import org.apache.oodt.commons.database.DatabaseConnectionBuilder;
+
+/**
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>
+ * Factory for creating a cas-catalog workflow data source index
+ * <p>
+ */
+public class WorkflowManagerDataSourceIndexFactory implements IndexFactory {
+
+    protected String jdbcUrl;
+    protected String user;
+    protected String pass;
+    protected String driver;
+	
+	public WorkflowManagerDataSourceIndex createIndex() {
+		try {
+			return new WorkflowManagerDataSourceIndex(DatabaseConnectionBuilder.buildDataSource(this.user, this.pass, this.driver, this.jdbcUrl));
+		}catch (Exception e) {
+			//log
+			return null;
+		}
+	}
+
+	public void setJdbcUrl(String jdbcUrl) {
+		this.jdbcUrl = jdbcUrl;
+	}
+
+	public void setUser(String user) {
+		this.user = user;
+	}
+
+	public void setPass(String pass) {
+		this.pass = pass;
+	}
+
+	public void setDriver(String driver) {
+		this.driver = driver;
+	}
+	
+}

Added: oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowManagerDictionary.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowManagerDictionary.java?rev=1052143&view=auto
==============================================================================
--- oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowManagerDictionary.java (added)
+++ oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowManagerDictionary.java Thu Dec 23 02:44:23 2010
@@ -0,0 +1,82 @@
+/*
+ * 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.cas.workflow.instance.repo;
+
+//JDK imports
+import java.util.Set;
+
+//OODT imports
+import org.apache.oodt.cas.catalog.exception.CatalogDictionaryException;
+import org.apache.oodt.cas.catalog.query.ComparisonQueryExpression;
+import org.apache.oodt.cas.catalog.query.NotQueryExpression;
+import org.apache.oodt.cas.catalog.query.QueryExpression;
+import org.apache.oodt.cas.catalog.query.QueryLogicalGroup;
+import org.apache.oodt.cas.catalog.query.StdQueryExpression;
+import org.apache.oodt.cas.catalog.struct.Dictionary;
+import org.apache.oodt.cas.catalog.term.Term;
+import org.apache.oodt.cas.catalog.term.TermBucket;
+import org.apache.oodt.cas.metadata.Metadata;
+import static org.apache.oodt.cas.workflow.metadata.WorkflowMetKeys.*;
+
+/**
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>
+ * CAS-Catalog Dictiony for WorkflowManager
+ * <p>
+ */
+public class WorkflowManagerDictionary implements Dictionary {
+
+	public TermBucket lookup(Metadata metadata)
+			throws CatalogDictionaryException {
+		if (metadata.containsKey(JOB_ID) && metadata.containsKey(INSTANCE_ID) && metadata.containsKey(MODEL_ID)) {
+			TermBucket workflowBucket = new TermBucket("Workflows");
+			for (String key : metadata.getAllKeys()) 
+				workflowBucket.addTerm(new Term(key, metadata.getAllMetadata((String) key)));
+			return workflowBucket;
+		}else {
+			return null;
+		}
+	}
+
+	public Metadata reverseLookup(TermBucket termBucket)
+			throws CatalogDictionaryException {
+		Metadata metadata = new Metadata();
+		if (termBucket.getName().equals("Workflows")) {
+			for (Term term : termBucket.getTerms())
+				metadata.addMetadata(term.getName(), term.getValues());
+		}
+		return metadata;
+	}
+
+	public boolean understands(QueryExpression queryExpression)
+			throws CatalogDictionaryException {
+		Set<String> bucketNames = queryExpression.getBucketNames();
+		if (bucketNames == null || bucketNames.contains("Workflows")) {
+			if (queryExpression instanceof NotQueryExpression 
+					|| queryExpression instanceof ComparisonQueryExpression 
+					|| queryExpression instanceof StdQueryExpression 
+					|| queryExpression instanceof QueryLogicalGroup) {
+				return true;
+			} else
+				return false;	
+		}
+		return false;
+	}
+
+}

Added: oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowManagerDictionaryFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowManagerDictionaryFactory.java?rev=1052143&view=auto
==============================================================================
--- oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowManagerDictionaryFactory.java (added)
+++ oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/instance/repo/WorkflowManagerDictionaryFactory.java Thu Dec 23 02:44:23 2010
@@ -0,0 +1,36 @@
+/*
+ * 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.cas.workflow.instance.repo;
+
+//OODT imports
+import org.apache.oodt.cas.catalog.struct.DictionaryFactory;
+
+/**
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>
+ * Factory for creating a cas-catalog workflow dictionary
+ * <p>
+ */
+public class WorkflowManagerDictionaryFactory implements DictionaryFactory {
+
+	public WorkflowManagerDictionary createDictionary() {
+		return new WorkflowManagerDictionary();
+	}
+
+}

Added: oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/listener/ChangeType.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/listener/ChangeType.java?rev=1052143&view=auto
==============================================================================
--- oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/listener/ChangeType.java (added)
+++ oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/listener/ChangeType.java Thu Dec 23 02:44:23 2010
@@ -0,0 +1,58 @@
+/*
+ * 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.cas.workflow.listener;
+
+/**
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>
+ * Different Listener Message Categories
+ * <p>
+ */
+public class ChangeType {
+
+	public static final ChangeType STATE = new ChangeType("State");
+	public static final ChangeType DYN_MET = new ChangeType("DynamicMetadata");
+	public static final ChangeType STATIC_MET = new ChangeType("StaticMetadata");
+	public static final ChangeType LISTENERS = new ChangeType("Listeners");
+	public static final ChangeType PRIORITY = new ChangeType("Priority");
+	public static final ChangeType EXCUSED_WPS = new ChangeType("ExcusedWorkflowProcessors");
+
+	private String name;
+	
+	public ChangeType(String name) {
+		this.name = name;
+	}
+	
+	public String getName() {
+		return this.name;
+	}
+	
+	public boolean equals(Object obj) {
+		if (obj instanceof ChangeType) {
+			return this.name.equals(((ChangeType) obj).name);
+		}else {
+			return false;
+		}
+	}
+	
+	public int hashCode() {
+		return this.getName().hashCode();
+	}
+	
+}

Added: oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/listener/WorkflowProcessorListener.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/listener/WorkflowProcessorListener.java?rev=1052143&view=auto
==============================================================================
--- oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/listener/WorkflowProcessorListener.java (added)
+++ oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/listener/WorkflowProcessorListener.java Thu Dec 23 02:44:23 2010
@@ -0,0 +1,34 @@
+/*
+ * 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.cas.workflow.listener;
+
+//OODT imports
+import org.apache.oodt.cas.workflow.processor.WorkflowProcessor;
+
+/**
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>
+ * Notification Interface for WorkflowProcessors
+ * <p>
+ */
+public interface WorkflowProcessorListener {
+
+	public void notifyChange(WorkflowProcessor processor, ChangeType changeType);
+	
+}

Added: oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/metadata/ControlMetadata.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/metadata/ControlMetadata.java?rev=1052143&view=auto
==============================================================================
--- oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/metadata/ControlMetadata.java (added)
+++ oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/metadata/ControlMetadata.java Thu Dec 23 02:44:23 2010
@@ -0,0 +1,231 @@
+/*
+ * 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.cas.workflow.metadata;
+
+//JDK imports
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
+//OODT imports
+import org.apache.oodt.cas.metadata.Metadata;
+
+/**
+ * 
+ * @author bfoster
+ * @version $Revision$
+ * 
+ * <p>
+ * A wrapper class to act as a facade interface to all the different
+ * {@link Metadata} sources given to a PGE
+ * </p>.
+ */
+public class ControlMetadata {
+
+    private Metadata dynamicMetadata, localMetadata;
+    private Metadata staticMetadata;
+    
+    public static final int DYN = 1;
+
+    public static final int STATIC = 2;
+
+    public static final int LOCAL = 3;
+
+    private static int[] defaultMetadataQueryOrder = new int[] {
+    	ControlMetadata.DYN, ControlMetadata.LOCAL, ControlMetadata.STATIC };
+
+    private static int[] defaultMetadataCombineOrder = new int[] {
+    	ControlMetadata.STATIC, ControlMetadata.LOCAL, ControlMetadata.DYN };
+
+    private HashMap<String, String> keyLinkMap;
+    
+    private Set<String> workflowMetKeys;
+    
+    public static void main(String[] args) {
+    	ControlMetadata m = new ControlMetadata();
+		m.replaceLocalMetadata("test/IASI", "iasi");
+		m.replaceLocalMetadata("test/MHS", "mhs");
+		m.replaceLocalMetadata("test/AMSUA", "amsua");
+		m.linkKey("test", "test/MHS");
+		Metadata m1 = m.asMetadata();
+		System.out.println(m1.getAllKeys());
+    }
+    
+    
+    public ControlMetadata() {
+    	this(null, null);
+    }
+    
+    public ControlMetadata(ControlMetadata ctrlMetadata) {
+    	this(null, null);
+    	this.replaceControlMetadata(ctrlMetadata);
+    }
+    
+    public ControlMetadata(Metadata staticMetadata, Metadata dynamicMetadata) {
+        this.keyLinkMap = new HashMap<String, String>();
+        this.workflowMetKeys = new HashSet<String>();
+		this.staticMetadata = staticMetadata != null ? new Metadata(staticMetadata) : new Metadata();
+        this.dynamicMetadata = dynamicMetadata != null ? new Metadata(dynamicMetadata) : new Metadata();
+        this.localMetadata = new Metadata();
+	}
+    
+    public void replaceControlMetadata(ControlMetadata ctrlMetadata) {
+    	this.replaceControlMetadata(ctrlMetadata, null);
+    }
+    
+    //Namespaces custom metadata, keyLinkMap keys (if key-ref exists in custom metadata or keyLinkMap) and, workflowMetKeys (if they exist in custom metadata or keyLinkMap)
+    public void replaceControlMetadata(ControlMetadata ctrlMetadata, String group) {
+    	this.staticMetadata.replaceMetadata(group, ctrlMetadata.staticMetadata);
+    	this.dynamicMetadata.replaceMetadata(group, ctrlMetadata.dynamicMetadata);
+    	this.localMetadata.replaceMetadata(group, ctrlMetadata.localMetadata);
+    	for (String key : ctrlMetadata.keyLinkMap.keySet()) {
+    		String keyLink = ctrlMetadata.keyLinkMap.get(key);
+    		if (group != null && (ctrlMetadata.localMetadata.containsKey(keyLink) || ctrlMetadata.keyLinkMap.containsKey(keyLink)))
+    			keyLink = group + "/" + keyLink;
+    		this.linkKey(group != null ? group + "/" + key : key, keyLink);
+    	}
+    	for (String key : ctrlMetadata.workflowMetKeys)
+    		this.setAsWorkflowMetadataKey((group != null && (ctrlMetadata.localMetadata.containsKey(key) || ctrlMetadata.keyLinkMap.containsKey(key))) ? group + "/" + key : key);
+    }
+    
+    public void setAsWorkflowMetadataKey(String... keys) {
+        this.workflowMetKeys.addAll(Arrays.asList(keys));
+    }
+    
+    /**
+     * If no args, all keys are committed, otherwise only keys given are committed
+     */
+    public void commitWorkflowMetadataKeys(String... keys) {
+    	Set<String> commitKeys = keys.length > 0 ? new HashSet<String>(Arrays.asList(keys)) : new HashSet<String>(this.workflowMetKeys);
+        for (String key : commitKeys) {
+        	this.dynamicMetadata.replaceMetadata(key, this.localMetadata.getAllMetadata(this.resolveKey(key)));
+        	this.localMetadata.removeMetadata(key);
+        	this.workflowMetKeys.remove(key);
+        }
+    }
+    
+    public void linkKey(String keyName, String linkToKeyName) {
+    	this.localMetadata.removeMetadata(keyName);
+        this.keyLinkMap.put(keyName, linkToKeyName);
+    }
+    
+    public void unlinkKey(String key) {
+    	this.keyLinkMap.remove(key);
+    }
+    
+    public boolean isLink(String key) {
+    	return this.keyLinkMap.containsKey(key);
+    }
+    
+    public String getReferenceKey(String key) {
+    	return this.resolveKey(key);
+    }
+    
+    public List<String> getReferenceKeyPath(String key) {
+    	Vector<String> keyPath = new Vector<String>();
+        String useKeyName = key;
+        while(this.keyLinkMap.containsKey(useKeyName))
+        	keyPath.add(useKeyName = this.keyLinkMap.get(useKeyName));
+        return keyPath;
+    }
+
+    public void replaceLocalMetadata(String name, String value) {
+    	String resolveKey = this.resolveKey(name);
+    	if (this.keyLinkMap.containsKey(name) && this.dynamicMetadata.containsKey(resolveKey))
+    		this.dynamicMetadata.replaceMetadata(resolveKey, value);
+    	else
+    		this.localMetadata.replaceMetadata(resolveKey, value);
+    }
+
+    public void replaceLocalMetadata(Metadata metadata) {
+    	for (String key : metadata.getAllKeys())
+    		this.replaceLocalMetadata(key, metadata.getAllMetadata(key));
+    }
+    
+    public void replaceLocalMetadata(String name, List<String> values) {
+    	String resolveKey = this.resolveKey(name);
+    	if (this.keyLinkMap.containsKey(name) && this.dynamicMetadata.containsKey(resolveKey))
+    		this.dynamicMetadata.replaceMetadata(resolveKey, values);
+    	else
+    		this.localMetadata.replaceMetadata(resolveKey, values);
+    }
+
+    // add in order which you want metadata added (will return a copy)
+    public Metadata asMetadata(int... types) {
+        if (types.length < 1)
+            types = defaultMetadataCombineOrder;
+        Metadata combinedMetadata = new Metadata();
+        for (int type : types) {
+            switch (type) {
+            case DYN:
+                combinedMetadata.replaceMetadata(this.dynamicMetadata);
+                break;
+            case STATIC:
+                combinedMetadata.replaceMetadata(this.staticMetadata);
+                break;
+            case LOCAL:
+                combinedMetadata.replaceMetadata(this.localMetadata);
+                for (String key : this.keyLinkMap.keySet())
+                    combinedMetadata.replaceMetadata(key, this.getAllMetadata(key));
+                break;
+            }
+        }
+        return combinedMetadata;
+    }
+
+    public List<String> getAllMetadata(String name, int... types) {
+        if (types.length < 1)
+            types = defaultMetadataQueryOrder;
+        String useKeyName = this.resolveKey(name);
+        for (int type : types) {
+            switch (type) {
+            case DYN:
+                if (this.dynamicMetadata.containsKey(useKeyName))
+                    return this.dynamicMetadata.getAllMetadata(useKeyName);
+                break;
+            case STATIC:
+                if (this.staticMetadata.containsKey(useKeyName))
+                    return this.staticMetadata.getAllMetadata(useKeyName);
+                break;
+            case LOCAL:
+                if (this.localMetadata.containsKey(useKeyName))
+                    return this.localMetadata.getAllMetadata(useKeyName);
+                break;
+            }
+        }
+        return new Vector<String>();
+    }
+
+    public String getMetadata(String name, int... types) {
+        List<String> values = this.getAllMetadata(name, types);
+        if (values.size() > 0)
+            return values.get(0);
+        else
+            return null;
+    }
+    
+    public String resolveKey(String keyName) {
+        String useKeyName = keyName;
+        while(this.keyLinkMap.containsKey(useKeyName))
+            useKeyName = this.keyLinkMap.get(useKeyName);
+        return useKeyName;
+    }
+
+}

Added: oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/metadata/ResourceMetKeys.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/metadata/ResourceMetKeys.java?rev=1052143&view=auto
==============================================================================
--- oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/metadata/ResourceMetKeys.java (added)
+++ oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/metadata/ResourceMetKeys.java Thu Dec 23 02:44:23 2010
@@ -0,0 +1,34 @@
+/*
+ * 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.cas.workflow.metadata;
+
+/**
+ * 
+ * @author bfoster
+ * @version $Revision$
+ * 
+ * <p>
+ * Resource Manager reserved Workflow Metadata keys
+ * </p>.
+ */
+public interface ResourceMetKeys {
+	
+	public static final String QUEUE_NAME = "QueueName";
+	
+	public static final String LOAD = "Load";
+
+}

Added: oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/metadata/WorkflowMetKeys.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/metadata/WorkflowMetKeys.java?rev=1052143&view=auto
==============================================================================
--- oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/metadata/WorkflowMetKeys.java (added)
+++ oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/metadata/WorkflowMetKeys.java Thu Dec 23 02:44:23 2010
@@ -0,0 +1,49 @@
+/*
+ * 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.cas.workflow.metadata;
+
+/**
+ * 
+ * @author bfoster
+ * @version $Revision$
+ * 
+ * Workflow reserved Metadata keys
+ * 
+ */
+public interface WorkflowMetKeys {
+	
+	public static final String JOB_ID = "JobId";
+	
+	public static final String INSTANCE_ID = "InstanceId";
+	
+	public static final String MODEL_ID = "ModelId";
+
+	public static final String STATE = "State";
+
+	public static final String PRIORITY = "Priority";
+
+	public static final String HOST = "Host";
+	
+	public static final String CREATION_DATE = "CreationDate";
+
+	public static final String READY_DATE = "ReadyDate";
+
+	public static final String EXECUTION_DATE = "ExecutionDate";
+
+	public static final String COMPLETION_DATE = "CompletionDate";
+
+}

Added: oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/WorkflowGraph.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/WorkflowGraph.java?rev=1052143&view=auto
==============================================================================
--- oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/WorkflowGraph.java (added)
+++ oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/WorkflowGraph.java Thu Dec 23 02:44:23 2010
@@ -0,0 +1,108 @@
+/*
+ * 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.cas.workflow.model;
+
+//JDK imports
+import java.util.List;
+import java.util.Vector;
+
+//OODT imports
+import org.apache.oodt.cas.workflow.util.WorkflowUtils;
+
+/**
+ * 
+ * @author bfoster
+ * @version $Revision$
+ * 
+ * <p>
+ * Workflow Graph of Models which make up the mapping of workflows to one another
+ * </p>.
+ */
+public class WorkflowGraph {
+
+	private WorkflowGraph parent;
+	private WorkflowModel model;
+	private WorkflowGraph preConditions;
+	private Vector<WorkflowGraph> children;
+	private WorkflowGraph postConditions;
+	private boolean isCondition;
+	
+	public WorkflowGraph(WorkflowModel model) {
+		this.model = model;
+		this.children = new Vector<WorkflowGraph>();
+		this.isCondition = false;
+	}
+
+	public void setParent(WorkflowGraph parent) {
+		this.parent = parent;
+	}
+	
+	public void setModel(WorkflowModel model) {
+		this.model = model;
+	}
+	
+	public void setPreConditions(WorkflowGraph preConditions) {
+		this.preConditions = preConditions;
+		WorkflowUtils.markAsCondition(this.preConditions);
+	}
+	
+	public void setPostConditions(WorkflowGraph postConditions) {
+		this.postConditions = postConditions;
+		WorkflowUtils.markAsCondition(this.postConditions);
+	}
+	
+	public void setIsCondition(boolean isCondition) {
+		this.isCondition = isCondition;
+	}
+	
+	public void addChild(WorkflowGraph child) {
+		this.children.add(child);
+	}
+	
+	public void addChildren(List<WorkflowGraph> children) {
+		this.children.addAll(children);
+	}
+	
+	public WorkflowModel getModel() {
+		return this.model;
+	}
+	
+	public WorkflowGraph getParent() {
+		return this.parent;
+	}
+	
+	public List<WorkflowGraph> getChildren() {
+		return this.children;
+	}
+	
+	public WorkflowGraph getPreConditions() {
+		return preConditions;
+	}
+
+	public WorkflowGraph getPostConditions() {
+		return postConditions;
+	}
+
+	public boolean isCondition() {
+		return this.isCondition;
+	}
+	
+	public String getId() {
+		return this.model.getId();
+	}
+
+}

Added: oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/WorkflowModel.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/WorkflowModel.java?rev=1052143&view=auto
==============================================================================
--- oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/WorkflowModel.java (added)
+++ oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/WorkflowModel.java Thu Dec 23 02:44:23 2010
@@ -0,0 +1,85 @@
+/*
+ * 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.cas.workflow.model;
+
+//OODT imports
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.workflow.priority.Priority;
+
+//JDK imports
+import java.util.List;
+
+/**
+ * @author mattmann
+ * @version $Revision$
+ * 
+ */
+public class WorkflowModel {
+
+	private String id;
+	private String name;
+	private String executionType;
+	private String instanceClass;
+	private Priority priority;
+	private int minReqSuccessfulSubProcessors;
+	private List<String> excusedSubProcessorIds;    
+	private Metadata staticMetadata;
+    
+    public WorkflowModel(String id, String name, String executionType, String instanceClass, Priority priority, int minReqSuccessfulSubProcessors, List<String> excusedSubProcessorIds, Metadata staticMetadata) {
+    	this.id = id;
+    	this.name = name;
+    	this.executionType = executionType;
+    	this.instanceClass = instanceClass;
+    	this.priority = priority;
+    	this.minReqSuccessfulSubProcessors = minReqSuccessfulSubProcessors;
+    	this.excusedSubProcessorIds = excusedSubProcessorIds;
+        this.staticMetadata = staticMetadata;
+    }
+
+	public String getId() {
+		return this.id;
+	}
+
+	public String getName() {
+		return this.name;
+	}
+
+	public String getExecutionType() {
+		return this.executionType;
+	}
+
+	public String getInstanceClass() {
+		return this.instanceClass;
+	}
+	
+	public Priority getPriority() {
+		return this.priority;
+	}
+	
+	public int getMinReqSuccessfulSubProcessors() {
+		return this.minReqSuccessfulSubProcessors;
+	}
+
+	public List<String> getExcusedSubProcessorIds() {
+		return this.excusedSubProcessorIds;
+	}
+
+	public Metadata getStaticMetadata() {
+    	return this.staticMetadata;
+    }
+    
+}

Added: oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/WorkflowModelFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/WorkflowModelFactory.java?rev=1052143&view=auto
==============================================================================
--- oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/WorkflowModelFactory.java (added)
+++ oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/WorkflowModelFactory.java Thu Dec 23 02:44:23 2010
@@ -0,0 +1,100 @@
+/*
+ * 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.cas.workflow.model;
+
+//OODT imports
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.workflow.priority.Priority;
+
+//JDK imports
+import java.util.List;
+import java.util.Vector;
+import java.util.UUID;
+
+/**
+ * 
+ * @author bfoster
+ * @version $Revision$
+ * 
+ * <p>
+ * Factory for creating WorkflowModels
+ * </p>.
+ */
+public class WorkflowModelFactory {
+
+    protected String modelId;
+    protected String modelName;
+    protected String executionType;
+    protected Priority priority;
+    protected int minReqSuccessfulSubProcessors;
+    protected String instanceClass;
+    protected List<String> excusedSubProcessorIds;
+    protected Metadata staticMetadata;
+	
+    public WorkflowModelFactory() {
+    	this.priority = Priority.getDefault();
+    	this.minReqSuccessfulSubProcessors = -1;
+    }
+    
+    public WorkflowModelFactory(WorkflowModel model) {
+    	this.modelId = model.getId();
+    	this.modelName = model.getName();
+    	this.executionType = model.getExecutionType();
+    	this.priority = model.getPriority();
+    	this.minReqSuccessfulSubProcessors = model.getMinReqSuccessfulSubProcessors();
+    	this.instanceClass = model.getInstanceClass();
+    	this.excusedSubProcessorIds = model.getExcusedSubProcessorIds();
+    	this.staticMetadata = model.getStaticMetadata();
+    }
+    
+	public WorkflowModel createModel() {
+		return new WorkflowModel(this.modelId == null ? this.modelId = UUID.randomUUID().toString() : this.modelId, this.modelName == null ? this.modelId : this.modelName, this.executionType, this.instanceClass, this.priority, this.minReqSuccessfulSubProcessors, this.excusedSubProcessorIds == null ? new Vector<String>() : this.excusedSubProcessorIds, this.staticMetadata == null ? new Metadata() : this.staticMetadata);
+	}
+
+	public void setModelId(String modelId) {
+		this.modelId = modelId;
+	}
+	
+	public void setModelName(String modelName) {
+		this.modelName = modelName;
+	}
+
+	public void setExecutionType(String executionType) {
+		this.executionType = executionType;
+	}
+	
+	public void setInstanceClass(String instanceClass) {
+		this.instanceClass = instanceClass;
+	}
+
+	public void setStaticMetadata(Metadata staticMetadata) {
+		this.staticMetadata = staticMetadata;
+	}
+	
+	public void setPriority(Priority priority) {
+		this.priority = priority;
+	}
+	
+	public void setMinReqSuccessfulSubProcessors(int minReqSuccessfulSubProcessors) {
+		this.minReqSuccessfulSubProcessors = minReqSuccessfulSubProcessors;
+	}
+	
+	public void setExcusedSubProcessorIds(List<String> excusedSubProcessorIds) {
+		this.excusedSubProcessorIds = excusedSubProcessorIds;
+	}
+	
+}

Added: oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/repo/WorkflowModelRepository.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/repo/WorkflowModelRepository.java?rev=1052143&view=auto
==============================================================================
--- oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/repo/WorkflowModelRepository.java (added)
+++ oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/repo/WorkflowModelRepository.java Thu Dec 23 02:44:23 2010
@@ -0,0 +1,39 @@
+/*
+ * 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.cas.workflow.model.repo;
+
+//JDK imports
+import java.util.Map;
+import java.util.Set;
+
+//OODT imports
+import org.apache.oodt.cas.workflow.model.WorkflowGraph;
+
+/**
+ * 
+ * @author bfoster
+ * @version $Revision$
+ * 
+ * <p>
+ * Repository for storing workflow models
+ * </p>.
+ */
+public interface WorkflowModelRepository {
+		
+	public Map<String, WorkflowGraph> loadGraphs(Set<String> supportedProcessorIds) throws Exception;
+	
+}

Added: oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/repo/WorkflowModelRepositoryFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/repo/WorkflowModelRepositoryFactory.java?rev=1052143&view=auto
==============================================================================
--- oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/repo/WorkflowModelRepositoryFactory.java (added)
+++ oodt/branches/wengine-branch/src/main/java/org/apache/oodt/cas/workflow/model/repo/WorkflowModelRepositoryFactory.java Thu Dec 23 02:44:23 2010
@@ -0,0 +1,32 @@
+/*
+ * 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.cas.workflow.model.repo;
+
+/**
+ * 
+ * @author bfoster
+ * @version $Revision$
+ * 
+ * <p>
+ * Factory for creating workflow model repositories
+ * </p>.
+ */
+public interface WorkflowModelRepositoryFactory {
+
+	public WorkflowModelRepository createModelRepository();
+	
+}