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 2011/02/23 23:19:54 UTC

svn commit: r1073967 - in /oodt/branches/wengine-branch/wengine/src/main/java/org/apache/oodt/cas/workflow: event/DeleteWorkflowsByFilter.java event/FilteredEvent.java metadata/WorkflowMetKeys.java

Author: bfoster
Date: Wed Feb 23 22:19:54 2011
New Revision: 1073967

URL: http://svn.apache.org/viewvc?rev=1073967&view=rev
Log:

- added delete workflows by filter event

---------------

Added:
    oodt/branches/wengine-branch/wengine/src/main/java/org/apache/oodt/cas/workflow/event/DeleteWorkflowsByFilter.java   (with props)
    oodt/branches/wengine-branch/wengine/src/main/java/org/apache/oodt/cas/workflow/event/FilteredEvent.java   (with props)
Modified:
    oodt/branches/wengine-branch/wengine/src/main/java/org/apache/oodt/cas/workflow/metadata/WorkflowMetKeys.java

Added: oodt/branches/wengine-branch/wengine/src/main/java/org/apache/oodt/cas/workflow/event/DeleteWorkflowsByFilter.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/wengine/src/main/java/org/apache/oodt/cas/workflow/event/DeleteWorkflowsByFilter.java?rev=1073967&view=auto
==============================================================================
--- oodt/branches/wengine-branch/wengine/src/main/java/org/apache/oodt/cas/workflow/event/DeleteWorkflowsByFilter.java (added)
+++ oodt/branches/wengine-branch/wengine/src/main/java/org/apache/oodt/cas/workflow/event/DeleteWorkflowsByFilter.java Wed Feb 23 22:19:54 2011
@@ -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.event;
+
+//OODT imports
+import org.apache.oodt.cas.catalog.page.PageInfo;
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.workflow.engine.WorkflowEngineLocal;
+import org.apache.oodt.cas.workflow.page.QueuePage;
+import org.apache.oodt.cas.workflow.processor.ProcessorStub;
+
+/**
+ * @author bfoster
+ * @version $Revision$
+ * 
+ * Event for delete all workflows given by filter
+ *
+ */
+public class DeleteWorkflowsByFilter extends FilteredEvent {
+	
+	@Override
+	public void performAction(WorkflowEngineLocal engine, Metadata inputMetadata)
+			throws Exception {
+		try {
+			QueuePage page = null;
+			do {
+				page = engine.getPage(new PageInfo(50, PageInfo.FIRST_PAGE), this.createFilter(engine, inputMetadata));
+				for (ProcessorStub stub : page.getStubs())
+					engine.deleteWorkflow(stub.getInstanceId());
+			}while (!page.getPageInfo().isLastPage());
+		}catch (Exception e) {
+			throw new Exception("Failed to delete workflows by filter : " + e.getMessage(), e);
+		}
+	}
+
+}

Propchange: oodt/branches/wengine-branch/wengine/src/main/java/org/apache/oodt/cas/workflow/event/DeleteWorkflowsByFilter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/branches/wengine-branch/wengine/src/main/java/org/apache/oodt/cas/workflow/event/FilteredEvent.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/wengine/src/main/java/org/apache/oodt/cas/workflow/event/FilteredEvent.java?rev=1073967&view=auto
==============================================================================
--- oodt/branches/wengine-branch/wengine/src/main/java/org/apache/oodt/cas/workflow/event/FilteredEvent.java (added)
+++ oodt/branches/wengine-branch/wengine/src/main/java/org/apache/oodt/cas/workflow/event/FilteredEvent.java Wed Feb 23 22:19:54 2011
@@ -0,0 +1,78 @@
+/*
+ * 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.event;
+
+//JDK imports
+import java.util.Collections;
+import java.util.List;
+
+//OODT imports
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.workflow.engine.WorkflowEngineLocal;
+import org.apache.oodt.cas.workflow.exceptions.EngineException;
+import org.apache.oodt.cas.workflow.metadata.WorkflowMetKeys;
+import org.apache.oodt.cas.workflow.page.PageFilter;
+import org.apache.oodt.cas.workflow.processor.ProcessorStub;
+import org.apache.oodt.cas.workflow.state.StateUtils;
+import org.apache.oodt.cas.workflow.state.WorkflowState;
+
+/**
+ * @author bfoster
+ * @version $Revision$
+ * 
+ * Abstract Event for delete workflows given by filter
+ *
+ */
+public abstract class FilteredEvent extends WorkflowEngineEvent {
+	
+	public PageFilter createFilter(WorkflowEngineLocal engine, final Metadata eventMetadata) throws EngineException {
+		final List<WorkflowState> supportedStates = engine.getSupportedStates();
+		final Metadata filterMetadata = new Metadata(eventMetadata);
+		filterMetadata.removeMetadata(WorkflowMetKeys.MODEL_ID);
+		filterMetadata.removeMetadata(WorkflowMetKeys.STATE);
+		filterMetadata.removeMetadata(WorkflowMetKeys.CATEGORY);
+		return new PageFilter() {
+			
+			private String modelId = eventMetadata.getMetadata(WorkflowMetKeys.MODEL_ID);
+			private WorkflowState state = eventMetadata.getMetadata(WorkflowMetKeys.STATE) != null ? StateUtils.getStateByName(supportedStates, eventMetadata.getMetadata(WorkflowMetKeys.STATE)) : null;
+			private WorkflowState.Category category = eventMetadata.getMetadata(WorkflowMetKeys.CATEGORY) != null ? StateUtils.getCategoryByName(supportedStates, eventMetadata.getMetadata(WorkflowMetKeys.CATEGORY)) : null;
+			private Metadata metadata = filterMetadata;
+			
+			public boolean accept(ProcessorStub stub,
+					Metadata cachedMetadata) {
+				if (modelId != null) 
+					if (!stub.getModelId().equals(modelId))
+						return false;
+				if (state != null) 
+					if (!stub.getState().equals(state))
+						return false;
+				if (category != null) 
+					if (!stub.getState().getCategory().equals(category))
+						return false;
+				if (metadata != null) {
+					for (String key : metadata.getAllKeys()) {
+						List<String> values = cachedMetadata.getAllMetadata(key);
+						if (values == null || Collections.disjoint(metadata.getAllMetadata(key), values))
+							return false;
+					}
+				}
+				return true;
+			}
+		};
+	}
+	
+}

Propchange: oodt/branches/wengine-branch/wengine/src/main/java/org/apache/oodt/cas/workflow/event/FilteredEvent.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: oodt/branches/wengine-branch/wengine/src/main/java/org/apache/oodt/cas/workflow/metadata/WorkflowMetKeys.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/wengine/src/main/java/org/apache/oodt/cas/workflow/metadata/WorkflowMetKeys.java?rev=1073967&r1=1073966&r2=1073967&view=diff
==============================================================================
--- oodt/branches/wengine-branch/wengine/src/main/java/org/apache/oodt/cas/workflow/metadata/WorkflowMetKeys.java (original)
+++ oodt/branches/wengine-branch/wengine/src/main/java/org/apache/oodt/cas/workflow/metadata/WorkflowMetKeys.java Wed Feb 23 22:19:54 2011
@@ -36,6 +36,8 @@ public interface WorkflowMetKeys {
 
 	public static final String STATE = "State";
 
+	public static final String CATEGORY = "Category";
+
 	public static final String PRIORITY = "Priority";
 
 	public static final String HOST = "Host";