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/ItemImplementation.java | |
| 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/ItemImplementation.java')
| -rw-r--r-- | src/main/java/com/c2kernel/entity/ItemImplementation.java | 86 |
1 files changed, 46 insertions, 40 deletions
diff --git a/src/main/java/com/c2kernel/entity/ItemImplementation.java b/src/main/java/com/c2kernel/entity/ItemImplementation.java index 9aa4f9b..79b2c89 100644 --- a/src/main/java/com/c2kernel/entity/ItemImplementation.java +++ b/src/main/java/com/c2kernel/entity/ItemImplementation.java @@ -1,5 +1,7 @@ package com.c2kernel.entity;
+import java.util.UUID;
+
import com.c2kernel.collection.Collection;
import com.c2kernel.collection.CollectionArrayList;
import com.c2kernel.common.AccessRightsException;
@@ -8,6 +10,7 @@ import com.c2kernel.common.InvalidTransitionException; import com.c2kernel.common.ObjectAlreadyExistsException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.common.PersistencyException;
+import com.c2kernel.common.SystemKey;
import com.c2kernel.entity.agent.JobArrayList;
import com.c2kernel.lifecycle.instance.CompositeActivity;
import com.c2kernel.lifecycle.instance.Workflow;
@@ -15,6 +18,7 @@ import com.c2kernel.lifecycle.instance.predefined.PredefinedStepContainer; import com.c2kernel.lifecycle.instance.predefined.item.ItemPredefinedStepContainer;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.InvalidItemPathException;
+import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.persistency.TransactionManager;
@@ -26,27 +30,30 @@ import com.c2kernel.utils.Logger; public class ItemImplementation implements ItemOperations {
protected final TransactionManager mStorage;
- protected final int mSystemKey;
+ protected final ItemPath mItemPath;
- protected ItemImplementation(int systemKey) {
+ protected ItemImplementation(ItemPath key) {
this.mStorage = Gateway.getStorage();
- this.mSystemKey = systemKey;
+ this.mItemPath = key;
}
@Override
- public int getSystemKey() {
- // TODO Auto-generated method stub
- return 0;
+ public SystemKey getSystemKey() {
+ return mItemPath.getSystemKey();
+ }
+
+ public UUID getUUID() {
+ return mItemPath.getUUID();
}
@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
{
- Logger.msg(5, "Item::initialise("+mSystemKey+") - agent:"+agentId);
+ Logger.msg(5, "Item::initialise("+mItemPath+") - agent:"+agentId);
Object locker = new Object();
-
+
AgentPath agentPath;
try {
agentPath = new AgentPath(agentId);
@@ -64,9 +71,9 @@ public class ItemImplementation implements ItemOperations { PropertyArrayList props = (PropertyArrayList) Gateway
.getMarshaller().unmarshall(propString);
for (Property thisProp : props.list)
- mStorage.put(mSystemKey, thisProp, locker);
+ mStorage.put(mItemPath, thisProp, locker);
} catch (Throwable ex) {
- Logger.msg(8, "TraceableEntity::initialise(" + mSystemKey
+ Logger.msg(8, "TraceableEntity::initialise(" + mItemPath
+ ") - Properties were invalid: " + propString);
Logger.error(ex);
mStorage.abort(locker);
@@ -81,10 +88,10 @@ public class ItemImplementation implements ItemOperations { else
lc = new Workflow((CompositeActivity) Gateway
.getMarshaller().unmarshall(initWfString), getNewPredefStepContainer());
- lc.initialise(mSystemKey, agentPath);
- mStorage.put(mSystemKey, lc, locker);
+ lc.initialise(mItemPath, agentPath);
+ mStorage.put(mItemPath, lc, locker);
} catch (Throwable ex) {
- Logger.msg(8, "TraceableEntity::initialise(" + mSystemKey
+ Logger.msg(8, "TraceableEntity::initialise(" + mItemPath
+ ") - Workflow was invalid: " + initWfString);
Logger.error(ex);
mStorage.abort(locker);
@@ -97,10 +104,10 @@ public class ItemImplementation implements ItemOperations { CollectionArrayList colls = (CollectionArrayList) Gateway
.getMarshaller().unmarshall(initCollsString);
for (Collection<?> thisColl : colls.list) {
- mStorage.put(mSystemKey, thisColl, locker);
+ mStorage.put(mItemPath, thisColl, locker);
}
} catch (Throwable ex) {
- Logger.msg(8, "TraceableEntity::initialise(" + mSystemKey
+ Logger.msg(8, "TraceableEntity::initialise(" + mItemPath
+ ") - Collections were invalid: "
+ initCollsString);
Logger.error(ex);
@@ -109,7 +116,7 @@ public class ItemImplementation implements ItemOperations { }
}
mStorage.commit(locker);
- Logger.msg(3, "Initialisation of item " + mSystemKey
+ Logger.msg(3, "Initialisation of item " + mItemPath
+ " was successful");
}
@@ -120,7 +127,7 @@ public class ItemImplementation implements ItemOperations { }
@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,
@@ -128,20 +135,20 @@ public class ItemImplementation implements ItemOperations { try {
- Logger.msg(1, "TraceableEntity::request(" + mSystemKey + ") - "
+ Logger.msg(1, "TraceableEntity::request(" + mItemPath + ") - "
+ transitionID + " " + stepPath + " by " + agentId);
AgentPath agent = new AgentPath(agentId);
- Workflow lifeCycle = (Workflow) mStorage.get(mSystemKey,
+ Workflow lifeCycle = (Workflow) mStorage.get(mItemPath,
ClusterStorage.LIFECYCLE + "/workflow", null);
- String finalOutcome = lifeCycle.requestAction(agent, stepPath, mSystemKey,
+ String finalOutcome = lifeCycle.requestAction(agent, stepPath, mItemPath,
transitionID, requestData);
// store the workflow if we've changed the state of the domain
// wf
if (!(stepPath.startsWith("workflow/predefined")))
- mStorage.put(mSystemKey, lifeCycle, null);
+ mStorage.put(mItemPath, lifeCycle, null);
return finalOutcome;
// Normal operation exceptions
@@ -173,7 +180,7 @@ public class ItemImplementation implements ItemOperations { throw ex;
// non-CORBA exception hasn't been caught!
} catch (Throwable ex) {
- Logger.error("Unknown Error: requestAction on " + mSystemKey
+ Logger.error("Unknown Error: requestAction on " + mItemPath
+ " by " + agentId + " executing " + stepPath);
Logger.error(ex);
throw new InvalidDataException(
@@ -184,10 +191,10 @@ public class ItemImplementation implements ItemOperations { }
@Override
- public String queryLifeCycle(int agentId, boolean filter)
+ public String queryLifeCycle(SystemKey agentId, boolean filter)
throws AccessRightsException, ObjectNotFoundException,
PersistencyException {
- Logger.msg(1, "TraceableEntity::queryLifeCycle(" + mSystemKey
+ Logger.msg(1, "TraceableEntity::queryLifeCycle(" + mItemPath
+ ") - agent: " + agentId);
try {
AgentPath agent;
@@ -199,21 +206,21 @@ public class ItemImplementation implements ItemOperations { }
Workflow wf;
try {
- wf = (Workflow) mStorage.get(mSystemKey,
+ wf = (Workflow) mStorage.get(mItemPath,
ClusterStorage.LIFECYCLE + "/workflow", null);
} catch (ClusterStorageException e) {
Logger.error("TraceableEntity::queryLifeCycle("
- + mSystemKey + ") - Error loading workflow");
+ + mItemPath + ") - Error loading workflow");
Logger.error(e);
throw new PersistencyException("Error loading workflow");
}
JobArrayList jobBag = new JobArrayList();
CompositeActivity domainWf = (CompositeActivity) wf
.search("workflow/domain");
- jobBag.list = filter ? domainWf.calculateJobs(agent,
- mSystemKey, true) : domainWf.calculateAllJobs(agent,
- mSystemKey, true);
- Logger.msg(1, "TraceableEntity::queryLifeCycle(" + mSystemKey
+ jobBag.list = filter ?
+ domainWf.calculateJobs(agent, mItemPath, true) :
+ domainWf.calculateAllJobs(agent, mItemPath, true);
+ Logger.msg(1, "TraceableEntity::queryLifeCycle(" + mItemPath
+ ") - Returning " + jobBag.list.size() + " jobs.");
try {
return Gateway.getMarshaller().marshall(jobBag);
@@ -222,7 +229,7 @@ public class ItemImplementation implements ItemOperations { throw new PersistencyException("Error marshalling job bag");
}
} catch (Throwable ex) {
- Logger.error("TraceableEntity::queryLifeCycle(" + mSystemKey
+ Logger.error("TraceableEntity::queryLifeCycle(" + mItemPath
+ ") - Unknown error");
Logger.error(ex);
throw new PersistencyException(
@@ -236,7 +243,7 @@ public class ItemImplementation implements ItemOperations { String result = "";
- Logger.msg(1, "TraceableEntity::queryData(" + mSystemKey + ") - "
+ Logger.msg(1, "TraceableEntity::queryData(" + mItemPath + ") - "
+ path);
try { // check for cluster contents query
@@ -244,8 +251,7 @@ public class ItemImplementation implements ItemOperations { if (path.endsWith("/all")) {
int allPos = path.lastIndexOf("all");
String query = path.substring(0, allPos);
- String[] ids = mStorage.getClusterContents(mSystemKey,
- query);
+ String[] ids = mStorage.getClusterContents(mItemPath, query);
for (int i = 0; i < ids.length; i++) {
result += ids[i];
@@ -256,7 +262,7 @@ public class ItemImplementation implements ItemOperations { }
// ****************************************************************
else { // retrieve the object instead
- C2KLocalObject obj = mStorage.get(mSystemKey, path, null);
+ C2KLocalObject obj = mStorage.get(mItemPath, path, null);
// marshall it, or in the case of an outcome get the data.
result = Gateway.getMarshaller().marshall(obj);
@@ -264,14 +270,14 @@ public class ItemImplementation implements ItemOperations { } catch (ObjectNotFoundException ex) {
throw ex;
} catch (Throwable ex) {
- Logger.warning("TraceableEntity::queryData(" + mSystemKey
+ Logger.warning("TraceableEntity::queryData(" + mItemPath
+ ") - " + path + " Failed: " + ex.getClass().getName());
throw new PersistencyException("Server exception: "
+ ex.getClass().getName(), "");
}
if (Logger.doLog(9))
- Logger.msg(9, "TraceableEntity::queryData(" + mSystemKey
+ Logger.msg(9, "TraceableEntity::queryData(" + mItemPath
+ ") - result:" + result);
return result;
@@ -282,8 +288,8 @@ public class ItemImplementation implements ItemOperations { */
@Override
protected void finalize() throws Throwable {
- Logger.msg(7, "Item "+mSystemKey+" reaped");
- Gateway.getStorage().clearCache(mSystemKey, null);
+ Logger.msg(7, "Item "+mItemPath+" reaped");
+ Gateway.getStorage().clearCache(mItemPath, null);
super.finalize();
}
}
|
