diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2014-10-02 09:42:59 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2014-10-02 09:42:59 +0200 |
| commit | 71a3b23bce68b73c88ea478a0a46683876d0111e (patch) | |
| tree | 5d0b3700cb81ae73db61b1cb53792cfe8bca0834 | |
| parent | a4af569e384baf0dcff0198016a309ed66b9910a (diff) | |
Check the schema type of the predefined step before bundling the params
into a PredefinedStepOutcome.
Added single parameter execution method for scripts that can't handle
the ... method params.
3 files changed, 90 insertions, 40 deletions
diff --git a/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java b/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java index 1f24229..188c393 100644 --- a/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java +++ b/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java @@ -82,21 +82,28 @@ public class AgentProxy extends ItemProxy }
/**
- * Executes a job on the given item using this agent.
+ * Standard execution of jobs. Note that this method should always be the one used from clients - all execution
+ * parameters are taken from the job where they're probably going to be correct.
*
- * @param item - item holding this job
- * @param job - the job to execute
+ * @param job
+ * @throws AccessRightsException
+ * @throws InvalidDataException
+ * @throws InvalidTransitionException
+ * @throws ObjectNotFoundException
+ * @throws PersistencyException
+ * @throws ObjectAlreadyExistsException
* @throws ScriptErrorException
*/
- protected String execute(ItemProxy item, Job job)
+ public String execute(Job job)
throws AccessRightsException,
- InvalidTransitionException,
- ObjectNotFoundException,
- InvalidDataException,
- PersistencyException,
- ObjectAlreadyExistsException,
- ScriptErrorException
+ InvalidDataException,
+ InvalidTransitionException,
+ ObjectNotFoundException,
+ PersistencyException,
+ ObjectAlreadyExistsException,
+ ScriptErrorException
{
+ ItemProxy item = Gateway.getProxyManager().getProxy(job.getItemPath());
OutcomeValidator validator = null;
Date startTime = new Date();
Logger.msg(3, "AgentProxy - executing "+job.getStepPath()+" for "+mAgentPath.getAgentName());
@@ -173,32 +180,6 @@ public class AgentProxy extends ItemProxy return script.execute();
}
- /**
- * Standard execution of jobs. Note that this method should always be the one used from clients - all execution
- * parameters are taken from the job where they're probably going to be correct.
- *
- * @param job
- * @throws AccessRightsException
- * @throws InvalidDataException
- * @throws InvalidTransitionException
- * @throws ObjectNotFoundException
- * @throws PersistencyException
- * @throws ObjectAlreadyExistsException
- * @throws ScriptErrorException
- */
- public String execute(Job job)
- throws AccessRightsException,
- InvalidDataException,
- InvalidTransitionException,
- ObjectNotFoundException,
- PersistencyException,
- ObjectAlreadyExistsException,
- ScriptErrorException
- {
- ItemProxy targetItem = Gateway.getProxyManager().getProxy(job.getItemPath());
- return execute(targetItem, job);
- }
-
public String execute(ItemProxy item, String predefStep, C2KLocalObject obj)
throws AccessRightsException,
InvalidDataException,
@@ -217,7 +198,25 @@ public class AgentProxy extends ItemProxy return execute(item, predefStep, param);
}
- public String execute(ItemProxy item, String predefStep, String... params)
+ /**
+ * Multi-parameter execution. Wraps parameters up in a PredefinedStepOutcome
+ * if the schema of the requested step is such.
+ *
+ * @param item The item on which to execute the step
+ * @param predefStep The step name to run
+ * @param params An array of parameters to pass to the step. See each step's
+ * documentation for its required parameters
+ *
+ * @return The outcome after processing. May have been altered by the step.
+ *
+ * @throws AccessRightsException The agent was not allowed to execute this step
+ * @throws InvalidDataException The parameters supplied were incorrect
+ * @throws InvalidTransitionException The step wasn't available
+ * @throws ObjectNotFoundException Thrown by some steps that try to locate additional objects
+ * @throws PersistencyException Problem writing or reading the database
+ * @throws ObjectAlreadyExistsException Thrown by steps that create additional object
+ */
+ public String execute(ItemProxy item, String predefStep, String[] params)
throws AccessRightsException,
InvalidDataException,
InvalidTransitionException,
@@ -225,7 +224,42 @@ public class AgentProxy extends ItemProxy PersistencyException,
ObjectAlreadyExistsException
{
- return item.getItem().requestAction(mAgentPath.getSystemKey(), "workflow/predefined/"+predefStep, PredefinedStep.DONE, PredefinedStep.bundleData(params));
+ String schemaName = PredefinedStep.getPredefStepSchemaName(predefStep);
+ String param;
+ if (schemaName.equals("PredefinedStepOutcome"))
+ param = PredefinedStep.bundleData(params);
+ else
+ param = params[0];
+
+ return item.getItem().requestAction(mAgentPath.getSystemKey(), "workflow/predefined/"+predefStep, PredefinedStep.DONE, param);
+ }
+
+ /**
+ * Single parameter execution
+ *
+ * @see #execute(ItemProxy, String, String[])
+ *
+ * @param item
+ * @param predefStep
+ * @param param
+ * @return
+ * @throws AccessRightsException
+ * @throws InvalidDataException
+ * @throws InvalidTransitionException
+ * @throws ObjectNotFoundException
+ * @throws PersistencyException
+ * @throws ObjectAlreadyExistsException
+ */
+
+ public String execute(ItemProxy item, String predefStep, String param)
+ throws AccessRightsException,
+ InvalidDataException,
+ InvalidTransitionException,
+ ObjectNotFoundException,
+ PersistencyException,
+ ObjectAlreadyExistsException
+ {
+ return execute(item, predefStep, new String[] {param });
}
/** Wrappers for scripts */
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStep.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStep.java index 7a318ba..d68f22e 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStep.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStep.java @@ -14,6 +14,9 @@ import org.xml.sax.InputSource; import com.c2kernel.common.InvalidDataException;
import com.c2kernel.lifecycle.instance.Activity;
+import com.c2kernel.lifecycle.instance.predefined.agent.AgentPredefinedStepContainer;
+import com.c2kernel.lifecycle.instance.predefined.item.ItemPredefinedStepContainer;
+import com.c2kernel.lifecycle.instance.predefined.server.ServerPredefinedStepContainer;
import com.c2kernel.persistency.outcome.Outcome;
import com.c2kernel.utils.Logger;
/***********************************************************************************************************************************************************************************************************************************************************************************************************
@@ -92,6 +95,19 @@ public abstract class PredefinedStep extends Activity {
return getName();
}
+
+ static public String getPredefStepSchemaName(String stepName) {
+ PredefinedStepContainer[] allSteps = { new ItemPredefinedStepContainer(), new AgentPredefinedStepContainer(), new ServerPredefinedStepContainer() };
+ for (PredefinedStepContainer thisContainer : allSteps) {
+ String stepPath = thisContainer.getName()+"/"+stepName;
+ Activity step = (Activity)thisContainer.search(stepPath);
+ if (step != null) {
+ return (String)step.getProperties().get("SchemaType");
+ }
+ }
+ return "PredefinedStepOutcome"; // default to standard if not found - server may be a newer version
+ }
+
// generic bundling of parameters
static public String bundleData(String[] data)
{
@@ -132,7 +148,7 @@ public abstract class PredefinedStep extends Activity // generic bundling of single parameter
static public String bundleData(String data)
{
- return "<PredefinedStepOutcome><param><![CDATA[" + data + "]]></param></PredefinedStepOutcome>";
+ return bundleData(new String[]{ data });
}
public static String[] getDataList(String xmlData)
diff --git a/src/main/resources/boot/SC/ServerNewEntity.xml b/src/main/resources/boot/SC/ServerNewEntity.xml index 8520d0d..b2f72fb 100644 --- a/src/main/resources/boot/SC/ServerNewEntity.xml +++ b/src/main/resources/boot/SC/ServerNewEntity.xml @@ -5,7 +5,7 @@ var schema = job.getActPropString("SchemaType");
var predef = schema.equals("Item")?"CreateNewItem":"CreateNewAgent";
- item.requestAction(agent.getSystemKey(), "workflow/predefined/"+predef, Packages.com.c2kernel.lifecycle.instance.predefined.PredefinedStep.DONE, job.getOutcomeString());
+ agent.execute(item, predef, job.getOutcomeString());
]]></script>
</cristalscript>
|
