diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2014-10-03 17:30:41 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2014-10-03 17:30:41 +0200 |
| commit | 275d0bbf555c8917be82ce4cc21eb4cabb00f4c5 (patch) | |
| tree | ddcc6b14077d90d1b970b67829f07120547dbb62 /src/main/java/com/c2kernel/lifecycle/instance/predefined/server | |
| parent | a139f95bfeca603333b8c0310ae09c6805e58584 (diff) | |
Huge exception overhaul: Merged ClusterStorageException with
PersistencyException. Replaced MembershipException with
InvalidCollectionModification CORBA Exception. Made all predef steps
throw more accurate exceptions when they go wrong, and let more
exceptions bubble through from underneath.
Diffstat (limited to 'src/main/java/com/c2kernel/lifecycle/instance/predefined/server')
6 files changed, 98 insertions, 95 deletions
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/AddDomainContext.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/AddDomainContext.java index 3cb2182..57de2a1 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/AddDomainContext.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/AddDomainContext.java @@ -20,11 +20,12 @@ */
package com.c2kernel.lifecycle.instance.predefined.server;
+import java.util.Arrays;
import java.util.Stack;
-import com.c2kernel.common.CannotManageException;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectAlreadyExistsException;
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectAlreadyExists;
import com.c2kernel.common.ObjectCannotBeUpdated;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
@@ -41,13 +42,15 @@ public class AddDomainContext extends PredefinedStep { @Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectCannotBeUpdated, ObjectAlreadyExists, CannotManage {
- Logger.msg(1, "AddDomainContext::request() - Starting.");
+ String[] params = getDataList(requestData);
+ if (Logger.doLog(3)) Logger.msg(3, "AddDomainContext: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params));
+ if (params.length != 1) throw new InvalidData("AddDomainContext: Invalid parameters "+Arrays.toString(params));
- DomainPath pathToAdd = new DomainPath(getDataList(requestData)[0]);
+ DomainPath pathToAdd = new DomainPath(params);
if (pathToAdd.exists())
- throw new InvalidDataException("Context "+pathToAdd+" already exists", "");
+ throw new ObjectAlreadyExists("Context "+pathToAdd+" already exists");
// collect parent paths if they don't exist
Stack<DomainPath> pathsToAdd = new Stack<DomainPath>();
while(pathToAdd!= null && !pathToAdd.exists()) {
@@ -56,16 +59,7 @@ public class AddDomainContext extends PredefinedStep { }
while(!pathsToAdd.empty()) {
pathToAdd = pathsToAdd.pop();
- try {
- Gateway.getLookupManager().add(pathToAdd);
- } catch (ObjectAlreadyExistsException e) {
- Logger.error("Context "+pathToAdd+" inconsistently exists.");
- } catch (ObjectCannotBeUpdated e) {
- Logger.error(e);
- throw new InvalidDataException("Exception adding path "+pathToAdd+": "+e.getMessage(), "");
- } catch (CannotManageException e) {
- throw new InvalidDataException("Cannot alter directory in a non-server process", "");
- }
+ Gateway.getLookupManager().add(pathToAdd);
}
return requestData;
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewAgent.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewAgent.java index 6caf25e..ffe8950 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewAgent.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewAgent.java @@ -20,7 +20,11 @@ */
package com.c2kernel.lifecycle.instance.predefined.server;
-import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.entity.imports.ImportAgent;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
@@ -39,19 +43,25 @@ public class CreateNewAgent extends PredefinedStep //requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectNotFound, ObjectCannotBeUpdated, CannotManage, ObjectAlreadyExists {
String redactedRequestData;
- try {
- ImportAgent newAgent = (ImportAgent)Gateway.getMarshaller().unmarshall(requestData);
- newAgent.create(agent, true);
- newAgent.setPassword("REDACTED");
- redactedRequestData = Gateway.getMarshaller().marshall(newAgent);
- return redactedRequestData;
- } catch (Exception ex) {
- Logger.error(ex);
- throw new InvalidDataException("Error creating agent", "");
- }
+ ImportAgent newAgent;
+ try {
+ newAgent = (ImportAgent)Gateway.getMarshaller().unmarshall(requestData);
+ } catch (Exception e1) {
+ Logger.error(e1);
+ throw new InvalidData("CreateNewAgent: Couldn't unmarshall new Agent: "+requestData);
+ }
+ newAgent.create(agent, true);
+ newAgent.setPassword("REDACTED");
+ try {
+ redactedRequestData = Gateway.getMarshaller().marshall(newAgent);
+ } catch (Exception e) {
+ Logger.error(e);
+ throw new InvalidData("CreateNewAgent: Couldn't marshall new Agent for outcome: "+newAgent);
+ }
+ return redactedRequestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewItem.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewItem.java index 139bc55..5e0505e 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewItem.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewItem.java @@ -23,7 +23,12 @@ package com.c2kernel.lifecycle.instance.predefined.server; -import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidCollectionModification;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.entity.imports.ImportItem;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
@@ -42,15 +47,16 @@ public class CreateNewItem extends PredefinedStep //requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectCannotBeUpdated, ObjectNotFound, CannotManage, ObjectAlreadyExists, InvalidCollectionModification {
- try {
- ImportItem newItem = (ImportItem)Gateway.getMarshaller().unmarshall(requestData);
- newItem.create(agent, false);
- return requestData;
- } catch (Exception ex) {
- Logger.error(ex);
- throw new InvalidDataException("Error creating item", "");
- }
+ ImportItem newItem;
+ try {
+ newItem = (ImportItem)Gateway.getMarshaller().unmarshall(requestData);
+ } catch (Exception e) {
+ Logger.error(e);
+ throw new InvalidData("CreateNewAgent: Couldn't unmarshall new Agent: "+requestData);
+ }
+ newItem.create(agent, false);
+ return requestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewRole.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewRole.java index 49231ea..de05dec 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewRole.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewRole.java @@ -20,7 +20,11 @@ */
package com.c2kernel.lifecycle.instance.predefined.server;
-import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.entity.imports.ImportRole;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
@@ -39,16 +43,17 @@ public class CreateNewRole extends PredefinedStep //requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectAlreadyExists, ObjectCannotBeUpdated, CannotManage, ObjectNotFound {
- try {
- ImportRole newRole = (ImportRole)Gateway.getMarshaller().unmarshall(requestData);
- newRole.create(agent, true);
- return requestData;
- } catch (Exception ex) {
- Logger.error(ex);
- throw new InvalidDataException("Error creating role", "");
- }
+ ImportRole newRole;
+ try {
+ newRole = (ImportRole)Gateway.getMarshaller().unmarshall(requestData);
+ } catch (Exception e) {
+ Logger.error(e);
+ throw new InvalidData("CreateNewAgent: Couldn't unmarshall new Agent: "+requestData);
+ }
+ newRole.create(agent, true);
+ return requestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java index d90f163..2d78e69 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java @@ -20,10 +20,12 @@ */
package com.c2kernel.lifecycle.instance.predefined.server;
-import com.c2kernel.common.CannotManageException;
-import com.c2kernel.common.InvalidDataException;
+import java.util.Arrays;
+
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidData;
import com.c2kernel.common.ObjectCannotBeUpdated;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
@@ -38,28 +40,25 @@ public class RemoveDomainContext extends PredefinedStep { @Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectNotFound, ObjectCannotBeUpdated, CannotManage {
- Logger.msg(1, "RemoveDomainContext::request() - Starting.");
-
- DomainPath pathToDelete = new DomainPath(getDataList(requestData)[0]);
+ String[] params = getDataList(requestData);
+ if (Logger.doLog(3)) Logger.msg(3, "RemoveDomainContext: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params));
+ if (params.length != 1) throw new InvalidData("RemoveDomainContext: Invalid parameters "+Arrays.toString(params));
+
+ DomainPath pathToDelete = new DomainPath(params[0]);
if (!pathToDelete.exists())
- throw new InvalidDataException("Context "+pathToDelete+" does not exist", "");
+ throw new ObjectNotFound("Context "+pathToDelete+" does not exist");
+
try {
pathToDelete.getItemPath();
- throw new InvalidDataException("Path "+pathToDelete+" is an Entity. Use its own Erase step instead, or RemoveAgent.", "");
- } catch (ObjectNotFoundException ex) { }
+ throw new InvalidData("Path "+pathToDelete+" is an Entity. Use its own Erase step instead, or RemoveAgent.");
+ } catch (ObjectNotFound ex) { }
+
if (Gateway.getLookup().getChildren(pathToDelete).hasNext())
- throw new InvalidDataException("Context "+pathToDelete+" is not empty. Cannot delete.", "");
+ throw new ObjectCannotBeUpdated("Context "+pathToDelete+" is not empty. Cannot delete.");
- try {
- Gateway.getLookupManager().delete(pathToDelete);
- } catch (ObjectCannotBeUpdated e) {
- Logger.error(e);
- throw new InvalidDataException("Exception deleting path"+pathToDelete+": "+e.getMessage(), "");
- } catch (CannotManageException e) {
- throw new InvalidDataException("Cannot alter directory in a non-server process", "");
- }
+ Gateway.getLookupManager().delete(pathToDelete);
return requestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveRole.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveRole.java index a467ee0..7aeda55 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveRole.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveRole.java @@ -22,10 +22,10 @@ package com.c2kernel.lifecycle.instance.predefined.server; import java.util.Arrays;
-import com.c2kernel.common.CannotManageException;
-import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidData;
import com.c2kernel.common.ObjectCannotBeUpdated;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
@@ -44,33 +44,22 @@ public class RemoveRole extends PredefinedStep //requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, CannotManage, ObjectNotFound, ObjectCannotBeUpdated {
- String[] params = getDataList(requestData);
- if (Logger.doLog(3)) Logger.msg(3, "AddC2KObject: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params));
- LookupManager lookup;
- try {
- lookup = Gateway.getLookupManager();
- } catch (CannotManageException e) {
- throw new InvalidDataException(e.getMessage(), "");
- }
-
- RolePath thisRole; AgentPath[] agents;
- try {
- thisRole = lookup.getRolePath(params[0]);
- agents = Gateway.getLookup().getAgents(thisRole);
- } catch (ObjectNotFoundException e) {
- throw new InvalidDataException("Role "+params[0]+" not found.", "");
- }
+ String[] params = getDataList(requestData);
+ if (Logger.doLog(3)) Logger.msg(3, "RemoveRole: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params));
+ if (params.length != 1) throw new InvalidData("RemoveRole: Invalid parameters "+Arrays.toString(params));
+
+ LookupManager lookup = Gateway.getLookupManager();
+
+ RolePath thisRole; AgentPath[] agents;
+ thisRole = lookup.getRolePath(params[0]);
+ agents = Gateway.getLookup().getAgents(thisRole);
if (agents.length > 0)
- throw new InvalidDataException("Cannot remove role. "+agents.length+" agents still hold it.", "");
- try {
- lookup.delete(thisRole);
- } catch (ObjectCannotBeUpdated e) {
- Logger.error(e);
- throw new InvalidDataException("Role "+params[0]+" could not be removed.", "");
- }
+ throw new ObjectCannotBeUpdated("Cannot remove role. "+agents.length+" agents still hold it.");
+
+ lookup.delete(thisRole);
return requestData;
|
