summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java
diff options
context:
space:
mode:
authorogattaz <olivier@gattaz.com>2014-06-05 16:51:07 +0200
committerogattaz <olivier@gattaz.com>2014-06-05 16:51:07 +0200
commit2fd193d7936084de91eae46e8c2763914d87ab71 (patch)
treeb136ed97e535f11d4b3433d16c26570c89430ce4 /src/main/java/com/c2kernel/entity/proxy/AgentProxy.java
parent1225792532f77e6e8f4a9addfc0c0a6cf56e89b8 (diff)
parente73468fd08cc27aa31f76a27c916e45d5987c628 (diff)
Merge branch 'master' of ssh://dev.cccs.uwe.ac.uk:22/var/git/cristal-kernel
Diffstat (limited to 'src/main/java/com/c2kernel/entity/proxy/AgentProxy.java')
-rw-r--r--src/main/java/com/c2kernel/entity/proxy/AgentProxy.java101
1 files changed, 50 insertions, 51 deletions
diff --git a/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java b/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java
index f76af10..e5a52f0 100644
--- a/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java
+++ b/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java
@@ -11,7 +11,7 @@
package com.c2kernel.entity.proxy;
import java.util.Date;
-import java.util.Enumeration;
+import java.util.Iterator;
import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
@@ -22,17 +22,17 @@ import com.c2kernel.common.PersistencyException;
import com.c2kernel.entity.Agent;
import com.c2kernel.entity.AgentHelper;
import com.c2kernel.entity.C2KLocalObject;
-import com.c2kernel.entity.ManageableEntity;
import com.c2kernel.entity.agent.Job;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
-import com.c2kernel.lookup.EntityPath;
-import com.c2kernel.lookup.InvalidEntityPathException;
+import com.c2kernel.lookup.InvalidItemPathException;
+import com.c2kernel.lookup.ItemPath;
import com.c2kernel.lookup.Path;
import com.c2kernel.persistency.outcome.OutcomeValidator;
import com.c2kernel.persistency.outcome.Schema;
import com.c2kernel.process.Gateway;
+import com.c2kernel.process.auth.Authenticator;
import com.c2kernel.scripting.ErrorInfo;
import com.c2kernel.scripting.Script;
import com.c2kernel.scripting.ScriptErrorException;
@@ -47,51 +47,43 @@ import com.c2kernel.utils.Logger;
* @version $Revision: 1.37 $ $Date: 2005/10/05 07:39:36 $
* @author $Author: abranson $
******************************************************************************/
-public class AgentProxy extends EntityProxy
+public class AgentProxy extends ItemProxy
{
- AgentPath path;
+ AgentPath agentPath;
+ Authenticator auth;
/**************************************************************************
* Creates an AgentProxy without cache and change notification
**************************************************************************/
- public AgentProxy( org.omg.CORBA.Object ior,
+ protected AgentProxy( org.omg.CORBA.Object ior,
int systemKey)
throws ObjectNotFoundException
{
- super(ior, systemKey);
- try {
- path = new AgentPath(systemKey);
- } catch (InvalidEntityPathException e) {
+ super(ior, systemKey);
+ try {
+ agentPath = new AgentPath(systemKey);
+ mPath = agentPath;
+ } catch (InvalidItemPathException e) {
throw new ObjectNotFoundException();
}
}
- @Override
- public ManageableEntity narrow() throws ObjectNotFoundException
+ public Authenticator getAuthObj() {
+ return auth;
+ }
+
+ public void setAuthObj(Authenticator auth) {
+ this.auth = auth;
+ }
+
+ @Override
+ public Agent narrow() throws ObjectNotFoundException
{
try {
return AgentHelper.narrow(mIOR);
} catch (org.omg.CORBA.BAD_PARAM ex) { }
throw new ObjectNotFoundException("CORBA Object was not an Agent, or the server is down.");
}
- /**************************************************************************
- *
- *
- **************************************************************************/
- public void initialise( String agentProps, String collector )
- throws AccessRightsException,
- InvalidDataException,
- PersistencyException,
- ObjectNotFoundException
- {
- Logger.msg(7, "AgentProxy::initialise - started");
-
- ((Agent)getEntity()).initialise( agentProps );
- }
-
- public AgentPath getPath() {
- return path;
- }
/**
* Executes a job on the given item using this agent.
@@ -100,7 +92,7 @@ public class AgentProxy extends EntityProxy
* @param job - the job to execute
* @throws ScriptErrorException
*/
- public void execute(ItemProxy item, Job job)
+ public String execute(ItemProxy item, Job job)
throws AccessRightsException,
InvalidTransitionException,
ObjectNotFoundException,
@@ -111,7 +103,7 @@ public class AgentProxy extends EntityProxy
{
OutcomeValidator validator = null;
Date startTime = new Date();
- Logger.msg(3, "AgentProxy - executing "+job.getStepPath()+" for "+path.getAgentName());
+ Logger.msg(3, "AgentProxy - executing "+job.getStepPath()+" for "+agentPath.getAgentName());
// get the outcome validator if present
if (job.hasOutcome())
{
@@ -170,12 +162,14 @@ public class AgentProxy extends EntityProxy
job.setAgentId(getSystemKey());
Logger.msg(3, "AgentProxy - submitting job to item proxy");
- item.requestAction(job);
+ String result = item.requestAction(job);
if (Logger.doLog(3)) {
Date timeNow = new Date();
long secsNow = (timeNow.getTime()-startTime.getTime())/1000;
Logger.msg(3, "Execution took "+secsNow+" seconds");
}
+
+ return result;
}
private Object callScript(ItemProxy item, Job job) throws ScriptingEngineException {
@@ -196,7 +190,7 @@ public class AgentProxy extends EntityProxy
* @throws ObjectAlreadyExistsException
* @throws ScriptErrorException
*/
- public void execute(Job job)
+ public String execute(Job job)
throws AccessRightsException,
InvalidDataException,
InvalidTransitionException,
@@ -206,14 +200,14 @@ public class AgentProxy extends EntityProxy
ScriptErrorException
{
try {
- ItemProxy targetItem = (ItemProxy)Gateway.getProxyManager().getProxy(new EntityPath(job.getItemSysKey()));
- execute(targetItem, job);
- } catch (InvalidEntityPathException e) {
+ ItemProxy targetItem = Gateway.getProxyManager().getProxy(new ItemPath(job.getItemSysKey()));
+ return execute(targetItem, job);
+ } catch (InvalidItemPathException e) {
throw new ObjectNotFoundException("Job contained invalid item sysKey: "+job.getItemSysKey(), "");
}
}
- public void execute(ItemProxy item, String predefStep, C2KLocalObject obj)
+ public String execute(ItemProxy item, String predefStep, C2KLocalObject obj)
throws AccessRightsException,
InvalidDataException,
InvalidTransitionException,
@@ -228,10 +222,10 @@ public class AgentProxy extends EntityProxy
Logger.error(ex);
throw new InvalidDataException("Error on marshall", "");
}
- execute(item, predefStep, param);
+ return execute(item, predefStep, param);
}
- public void execute(ItemProxy item, String predefStep, String... params)
+ public String execute(ItemProxy item, String predefStep, String... params)
throws AccessRightsException,
InvalidDataException,
InvalidTransitionException,
@@ -239,7 +233,7 @@ public class AgentProxy extends EntityProxy
PersistencyException,
ObjectAlreadyExistsException
{
- item.requestAction(getSystemKey(), "workflow/predefined/"+predefStep, PredefinedStep.DONE, PredefinedStep.bundleData(params));
+ return item.getItem().requestAction(getSystemKey(), "workflow/predefined/"+predefStep, PredefinedStep.DONE, PredefinedStep.bundleData(params));
}
/** Wrappers for scripts */
@@ -253,31 +247,36 @@ public class AgentProxy extends EntityProxy
/** Let scripts resolve items */
public ItemProxy searchItem(String name) throws ObjectNotFoundException {
- Enumeration<Path> results = Gateway.getLDAPLookup().search(new DomainPath(""),name);
+ Iterator<Path> results = Gateway.getLookup().search(new DomainPath(""),name);
Path returnPath = null;
- if (!results.hasMoreElements())
+ if (!results.hasNext())
throw new ObjectNotFoundException(name, "");
- while(results.hasMoreElements()) {
- Path nextMatch = results.nextElement();
+ while(results.hasNext()) {
+ Path nextMatch = results.next();
if (returnPath != null && nextMatch.getSysKey() != -1 && returnPath.getSysKey() != nextMatch.getSysKey())
throw new ObjectNotFoundException("Too many items with that name");
returnPath = nextMatch;
}
- return (ItemProxy)Gateway.getProxyManager().getProxy(returnPath);
+ return Gateway.getProxyManager().getProxy(returnPath);
}
public ItemProxy getItem(String itemPath) throws ObjectNotFoundException {
return (getItem(new DomainPath(itemPath)));
}
- public ItemProxy getItem(Path itemPath) throws ObjectNotFoundException {
- return (ItemProxy)Gateway.getProxyManager().getProxy(itemPath);
+ @Override
+ public AgentPath getPath() {
+ return agentPath;
+ }
+
+ public ItemProxy getItem(Path itemPath) throws ObjectNotFoundException {
+ return Gateway.getProxyManager().getProxy(itemPath);
}
- public ItemProxy getItemBySysKey(int sysKey) throws ObjectNotFoundException, InvalidEntityPathException {
- return (ItemProxy)Gateway.getProxyManager().getProxy(new EntityPath(sysKey));
+ public ItemProxy getItemBySysKey(int sysKey) throws ObjectNotFoundException, InvalidItemPathException {
+ return Gateway.getProxyManager().getProxy(new ItemPath(sysKey));
}
}