diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2014-09-09 12:13:21 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2014-09-09 12:13:21 +0200 |
| commit | da731d2bb81666b9c697d9099da632e7dfcdc0f7 (patch) | |
| tree | 567693c3c48f3d15ecbb2dac4f9db03bb6e58c72 /src/main/java/com/c2kernel/entity/agent | |
| parent | ae1e79e33fd30e3d8bcedbef8891a14a048276d7 (diff) | |
Replaced int sysKey Item identifier with UUID, which is now portable.
ItemPath objects are now used to identify Items throughout the kernel,
replacing ints and Integers.
Diffstat (limited to 'src/main/java/com/c2kernel/entity/agent')
5 files changed, 168 insertions, 41 deletions
diff --git a/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java b/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java index a799b62..ca7431c 100644 --- a/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java +++ b/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java @@ -17,8 +17,9 @@ import com.c2kernel.common.InvalidTransitionException; import com.c2kernel.common.ObjectAlreadyExistsException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.common.PersistencyException;
-import com.c2kernel.entity.AgentImplementation;
+import com.c2kernel.common.SystemKey;
import com.c2kernel.entity.AgentPOA;
+import com.c2kernel.lookup.AgentPath;
import com.c2kernel.utils.Logger;
/**************************************************************************
@@ -33,8 +34,8 @@ public class ActiveEntity extends AgentPOA private final org.omg.PortableServer.POA mPoa;
private final AgentImplementation mAgentImpl;
- public ActiveEntity( int key,
- org.omg.PortableServer.POA poa )
+ public ActiveEntity( AgentPath key,
+ org.omg.PortableServer.POA poa )
{
Logger.msg(5, "ActiveEntity::constructor() - SystemKey:" + key );
mPoa = poa;
@@ -61,7 +62,7 @@ public class ActiveEntity extends AgentPOA *
**************************************************************************/
@Override
- public int getSystemKey()
+ public SystemKey getSystemKey()
{
return mAgentImpl.getSystemKey();
}
@@ -89,7 +90,7 @@ public class ActiveEntity extends AgentPOA */
@Override
- public void refreshJobList(int sysKey, String stepPath, String newJobs) {
+ public void refreshJobList(SystemKey sysKey, String stepPath, String newJobs) {
synchronized (this) {
mAgentImpl.refreshJobList(sysKey, stepPath, newJobs);
}
@@ -110,7 +111,7 @@ public class ActiveEntity extends AgentPOA }
@Override
- public void initialise(int agentId, String propString, String initWfString,
+ public void initialise(SystemKey agentId, String propString, String initWfString,
String initCollsString) throws AccessRightsException,
InvalidDataException, PersistencyException, ObjectNotFoundException {
synchronized (this) {
@@ -120,7 +121,7 @@ public class ActiveEntity extends AgentPOA }
@Override
- public String requestAction(int agentID, String stepPath, int transitionID,
+ public String requestAction(SystemKey agentID, String stepPath, int transitionID,
String requestData) throws AccessRightsException,
InvalidTransitionException, ObjectNotFoundException,
InvalidDataException, PersistencyException,
@@ -133,7 +134,7 @@ public class ActiveEntity extends AgentPOA }
@Override
- public String queryLifeCycle(int agentId, boolean filter)
+ public String queryLifeCycle(SystemKey agentId, boolean filter)
throws AccessRightsException, ObjectNotFoundException,
PersistencyException {
synchronized (this) {
diff --git a/src/main/java/com/c2kernel/entity/agent/ActiveLocator.java b/src/main/java/com/c2kernel/entity/agent/ActiveLocator.java index f3d4fb0..966b265 100644 --- a/src/main/java/com/c2kernel/entity/agent/ActiveLocator.java +++ b/src/main/java/com/c2kernel/entity/agent/ActiveLocator.java @@ -12,9 +12,13 @@ package com.c2kernel.entity.agent;
+import java.nio.ByteBuffer;
import java.sql.Timestamp;
+import java.util.UUID;
import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.lookup.InvalidAgentPathException;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
@@ -48,7 +52,10 @@ public class ActiveLocator extends org.omg.PortableServer.ServantLocatorPOA try
{
- int syskey = Integer.parseInt(new String(oid));
+ ByteBuffer bb = ByteBuffer.wrap(oid);
+ long msb = bb.getLong();
+ long lsb = bb.getLong();
+ AgentPath syskey = new AgentPath(new UUID(msb, lsb));
Logger.msg(1,"===========================================================");
Logger.msg(1,"Agent called at "+new Timestamp( System.currentTimeMillis()) +": " + operation +
@@ -61,7 +68,10 @@ public class ActiveLocator extends org.omg.PortableServer.ServantLocatorPOA {
Logger.error("ObjectNotFoundException::ActiveLocator::preinvoke() "+ex.toString());
throw new org.omg.CORBA.OBJECT_NOT_EXIST();
- }
+ } catch (InvalidAgentPathException ex) {
+ Logger.error("InvalidAgentPathException::ActiveLocator::preinvoke() "+ex.toString());
+ throw new org.omg.CORBA.INV_OBJREF();
+ }
}
diff --git a/src/main/java/com/c2kernel/entity/agent/AgentImplementation.java b/src/main/java/com/c2kernel/entity/agent/AgentImplementation.java new file mode 100644 index 0000000..0406387 --- /dev/null +++ b/src/main/java/com/c2kernel/entity/agent/AgentImplementation.java @@ -0,0 +1,83 @@ +package com.c2kernel.entity.agent;
+
+import com.c2kernel.common.CannotManageException;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.SystemKey;
+import com.c2kernel.entity.AgentOperations;
+import com.c2kernel.entity.ItemImplementation;
+import com.c2kernel.lifecycle.instance.predefined.PredefinedStepContainer;
+import com.c2kernel.lifecycle.instance.predefined.agent.AgentPredefinedStepContainer;
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.lookup.ItemPath;
+import com.c2kernel.lookup.RolePath;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.utils.Logger;
+
+public class AgentImplementation extends ItemImplementation implements
+ AgentOperations {
+
+ private JobList currentJobs;
+ private final AgentPath mAgentPath;
+
+ public AgentImplementation(AgentPath path) {
+ super(path);
+ mAgentPath = path;
+ }
+
+ /**
+ * Called by an activity when it reckons we need to update our joblist for it
+ */
+
+ @Override
+ public synchronized void refreshJobList(SystemKey sysKey, String stepPath, String newJobs) {
+ try {
+ ItemPath itemPath = new ItemPath(sysKey);
+ JobArrayList newJobList = (JobArrayList)Gateway.getMarshaller().unmarshall(newJobs);
+
+ // get our joblist
+ if (currentJobs == null)
+ currentJobs = new JobList( itemPath, null);
+
+ // remove old jobs for this item
+ currentJobs.removeJobsForStep( itemPath, stepPath );
+
+ // merge new jobs in
+ for (Object name : newJobList.list) {
+ Job newJob = (Job)name;
+ Logger.msg(6, "Adding job for "+newJob.getItemPath()+"/"+newJob.getStepPath()+":"+newJob.getTransition().getId());
+ currentJobs.addJob(newJob);
+ }
+
+ } catch (Throwable ex) {
+ Logger.error("Could not refresh job list.");
+ Logger.error(ex);
+ }
+
+ }
+
+ @Override
+ public void addRole(String roleName) throws CannotManageException, ObjectNotFoundException {
+ RolePath newRole = Gateway.getLookup().getRolePath(roleName);
+ try {
+ newRole.addAgent(mAgentPath);
+ } catch (ObjectCannotBeUpdated ex) {
+ throw new CannotManageException("Could not update role");
+ }
+ }
+
+ @Override
+ public void removeRole(String roleName) throws CannotManageException, ObjectNotFoundException {
+ RolePath rolePath = Gateway.getLookup().getRolePath(roleName);
+ try {
+ rolePath.removeAgent(mAgentPath);
+ } catch (ObjectCannotBeUpdated ex) {
+ throw new CannotManageException("Could not update role");
+ }
+ }
+
+ @Override
+ protected PredefinedStepContainer getNewPredefStepContainer() {
+ return new AgentPredefinedStepContainer();
+ }
+}
diff --git a/src/main/java/com/c2kernel/entity/agent/Job.java b/src/main/java/com/c2kernel/entity/agent/Job.java index cef35ef..fe2084d 100644 --- a/src/main/java/com/c2kernel/entity/agent/Job.java +++ b/src/main/java/com/c2kernel/entity/agent/Job.java @@ -1,6 +1,7 @@ package com.c2kernel.entity.agent;
import java.util.HashMap;
+import java.util.UUID;
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
@@ -9,6 +10,7 @@ import com.c2kernel.entity.proxy.ItemProxy; import com.c2kernel.lifecycle.instance.Activity;
import com.c2kernel.lifecycle.instance.stateMachine.Transition;
import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.lookup.InvalidAgentPathException;
import com.c2kernel.lookup.InvalidItemPathException;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.ClusterStorage;
@@ -34,7 +36,7 @@ public class Job implements C2KLocalObject private int id;
- private int itemSysKey;
+ private ItemPath itemPath;
private String stepName;
@@ -48,8 +50,6 @@ public class Job implements C2KLocalObject private String targetStateName;
- private int agentId = -1;
-
private String agentRole;
private CastorHashMap actProps = new CastorHashMap();
@@ -58,6 +58,8 @@ public class Job implements C2KLocalObject private String name;
+ private AgentPath agentPath;
+
private String agentName;
private String outcomeData;
@@ -79,9 +81,9 @@ public class Job implements C2KLocalObject {
}
- public Job(Activity act, int itemSysKey, Transition transition, AgentPath agent, String role) throws InvalidDataException, ObjectNotFoundException {
+ public Job(Activity act, ItemPath itemPath, Transition transition, AgentPath agent, String role) throws InvalidDataException, ObjectNotFoundException, InvalidAgentPathException {
- setItemSysKey(itemSysKey);
+ setItemPath(itemPath);
setStepPath(act.getPath());
setTransition(transition);
setOriginStateName(act.getStateMachine().getState(transition.getOriginStateId()).getName());
@@ -89,7 +91,7 @@ public class Job implements C2KLocalObject setStepName(act.getName());
setActProps(act.getProperties());
setStepType(act.getType());
- setAgentName(agent.getAgentName());
+ if (agent != null) setAgentName(agent.getAgentName());
setAgentRole(role);
}
@@ -121,15 +123,24 @@ public class Job implements C2KLocalObject name = String.valueOf(id);
}
- public int getItemSysKey() {
- return itemSysKey;
+ public ItemPath getItemPath() {
+ return itemPath;
}
- public void setItemSysKey(int sysKey) {
- itemSysKey = sysKey;
+ public void setItemPath(ItemPath path) {
+ itemPath = path;
item = null;
}
+ public void setItemUUID( String uuid )
+ {
+ setItemPath(new ItemPath(UUID.fromString(uuid)));
+ }
+
+ public String getItemUUID() {
+ return getItemPath().getUUID().toString();
+ }
+
public String getStepName() {
return stepName;
}
@@ -162,14 +173,34 @@ public class Job implements C2KLocalObject this.transition = transition;
}
- public int getAgentId() throws ObjectNotFoundException {
- if (agentId == -1)
- agentId = Gateway.getLookup().getAgentPath(getAgentName()).getSysKey();
- return agentId;
+ public AgentPath getAgentPath() throws ObjectNotFoundException {
+ if (agentPath == null && getAgentName() != null) {
+ agentPath = Gateway.getLookup().getAgentPath(getAgentName());
+ }
+ return agentPath;
}
- public void setAgentId(int id) {
- agentId = id;
+ public void setAgentPath(AgentPath agentPath) {
+ this.agentPath = agentPath;
+ agentName = agentPath.getAgentName();
+ }
+
+ public void setAgentUUID( String uuid )
+ {
+ if (uuid != null)
+ try {
+ setAgentPath(new AgentPath(UUID.fromString(uuid)));
+ } catch (InvalidAgentPathException e) {
+ Logger.error("Invalid agent path in Job: "+uuid);
+ }
+ }
+
+ public String getAgentUUID() {
+ try {
+ if (getAgentPath() != null)
+ return getAgentPath().getUUID().toString();
+ } catch (ObjectNotFoundException e) { }
+ return null;
}
public String getAgentName()
@@ -179,9 +210,10 @@ public class Job implements C2KLocalObject return agentName;
}
- public void setAgentName(String agentName)
+ public void setAgentName(String agentName) throws ObjectNotFoundException
{
this.agentName = agentName;
+ agentPath = Gateway.getLookup().getAgentPath(agentName);
}
public String getAgentRole() {
@@ -254,7 +286,7 @@ public class Job implements C2KLocalObject public ItemProxy getItemProxy() throws ObjectNotFoundException, InvalidItemPathException {
if (item == null)
- item = Gateway.getProxyManager().getProxy(new ItemPath(itemSysKey));
+ item = Gateway.getProxyManager().getProxy(itemPath);
return item;
}
@@ -294,7 +326,7 @@ public class Job implements C2KLocalObject }
try {
- Viewpoint view = (Viewpoint) Gateway.getStorage().get(getItemSysKey(),
+ Viewpoint view = (Viewpoint) Gateway.getStorage().get(itemPath,
ClusterStorage.VIEWPOINT + "/" + schemaName + "/" + viewName, null);
return view.getOutcome().getData();
} catch (ObjectNotFoundException ex) { // viewpoint doesn't exist yet
@@ -302,7 +334,7 @@ public class Job implements C2KLocalObject } catch (ClusterStorageException e) {
Logger.error(e);
throw new InvalidDataException("ViewpointOutcomeInitiator: ClusterStorageException loading viewpoint "
- + ClusterStorage.VIEWPOINT + "/" + schemaName + "/" + viewName+" in syskey "+getItemSysKey());
+ + ClusterStorage.VIEWPOINT + "/" + schemaName + "/" + viewName+" in item "+itemPath.getUUID());
}
}
else
@@ -375,7 +407,7 @@ public class Job implements C2KLocalObject public boolean equals(Job job)
{
- return (getItemSysKey() == job.getItemSysKey()) && this.stepPath.equals(job.stepPath) && transition.getId() == job.getTransition().getId();
+ return (itemPath.equals(job.getItemPath()) && this.stepPath.equals(job.stepPath) && transition.getId() == job.getTransition().getId());
}
private void setActProps(CastorHashMap actProps) {
diff --git a/src/main/java/com/c2kernel/entity/agent/JobList.java b/src/main/java/com/c2kernel/entity/agent/JobList.java index 271decb..ac3b421 100644 --- a/src/main/java/com/c2kernel/entity/agent/JobList.java +++ b/src/main/java/com/c2kernel/entity/agent/JobList.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Iterator;
import java.util.Vector;
+import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.RemoteMap;
import com.c2kernel.utils.Logger;
@@ -20,9 +21,9 @@ public class JobList extends RemoteMap<Job> /**************************************************************************
* Empty constructor for Castor
**************************************************************************/
- public JobList(int sysKey, Object locker)
+ public JobList(ItemPath itemPath, Object locker)
{
- super(sysKey, ClusterStorage.JOB, locker);
+ super(itemPath, ClusterStorage.JOB, locker);
}
@@ -55,7 +56,7 @@ public class JobList extends RemoteMap<Job> /**
* @param job
*/
- public void removeJobsWithSysKey( int sysKey )
+ public void removeJobsForItem( ItemPath itemPath )
{
Iterator<Job> currentMembers = values().iterator();
Job j = null;
@@ -64,14 +65,14 @@ public class JobList extends RemoteMap<Job> {
j = currentMembers.next();
- if( j.getItemSysKey() == sysKey )
+ if( j.getItemPath().equals(itemPath) )
remove( String.valueOf(j.getId()) );
}
- Logger.msg(5, "JobList::removeJobsWithSysKey() - " + sysKey + " DONE." );
+ Logger.msg(5, "JobList::removeJobsWithSysKey() - " + itemPath + " DONE." );
}
- public void removeJobsForStep( int sysKey, String stepPath )
+ public void removeJobsForStep( ItemPath itemPath, String stepPath )
{
ArrayList<String> staleJobs = new ArrayList<String>();
Iterator<String> jobIter = keySet().iterator();
@@ -79,7 +80,7 @@ public class JobList extends RemoteMap<Job> {
String jid = jobIter.next();
Job j = get(jid);
- if( j.getItemSysKey() == sysKey && j.getStepPath().equals(stepPath))
+ if( j.getItemPath().equals(itemPath) && j.getStepPath().equals(stepPath))
staleJobs.add(jid);
}
@@ -88,14 +89,14 @@ public class JobList extends RemoteMap<Job> for (String jid : staleJobs) {
remove(jid);
}
- Logger.msg(5, "JobList::removeJobsForStep() - " + sysKey + " DONE." );
+ Logger.msg(5, "JobList::removeJobsForStep() - " + itemPath + " DONE." );
}
/**
* @param itemKey
* @param string
* @return
*/
- public Vector<Job> getJobsOfSysKey(int sysKey)
+ public Vector<Job> getJobsOfItem( ItemPath itemPath )
{
Iterator<Job> currentMembers = values().iterator();
Job j = null;
@@ -105,7 +106,7 @@ public class JobList extends RemoteMap<Job> {
j = currentMembers.next();
- if( j.getItemSysKey() == sysKey )
+ if( j.getItemPath().equals(itemPath) )
jobs.add(j);
}
|
