diff options
Diffstat (limited to 'src/main/java/com/c2kernel/lifecycle/instance/predefined/agent')
4 files changed, 102 insertions, 98 deletions
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java index 0ce7c67..564c5db 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java @@ -20,10 +20,14 @@ */
package com.c2kernel.lifecycle.instance.predefined.agent;
-import com.c2kernel.common.AccessRightsException;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectAlreadyExistsException;
-import com.c2kernel.common.ObjectNotFoundException;
+import java.util.Arrays;
+
+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.common.PersistencyException;
import com.c2kernel.entity.CorbaServer;
import com.c2kernel.entity.agent.ActiveEntity;
import com.c2kernel.lifecycle.instance.predefined.item.CreateItemFromDescription;
@@ -53,71 +57,80 @@ public class CreateAgentFromDescription extends CreateItemFromDescription * <li>Comma-delimited Role names to assign to the agent. Must already exist.</li>
* <li>Initial properties to set in the new Agent</li>
* </ol>
+ * @throws ObjectNotFound
+ * @throws InvalidData The input parameters were incorrect
+ * @throws ObjectAlreadyExists The Agent already exists
+ * @throws CannotManage The Agent could not be created
+ * @throws ObjectCannotBeUpdated The addition of the new entries into the LookupManager failed
* @see com.c2kernel.lifecycle.instance.predefined.item.CreateItemFromDescription#runActivityLogic(com.c2kernel.lookup.AgentPath, int, int, java.lang.String)
*/
@Override
- protected String runActivityLogic(AgentPath agent, ItemPath itemPath,
- int transitionID, String requestData) throws InvalidDataException {
+ protected String runActivityLogic(AgentPath agent, ItemPath item,
+ int transitionID, String requestData) throws ObjectNotFound, InvalidData, ObjectAlreadyExists, CannotManage, ObjectCannotBeUpdated {
+
+ String[] params = getDataList(requestData);
+ if (Logger.doLog(3)) Logger.msg(3, "CreateAgentFromDescription: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params));
+ if (params.length < 3 || params.length > 4)
+ throw new InvalidData("CreateAgentFromDescription: Invalid parameters "+Arrays.toString(params));
- String[] input = getDataList(requestData);
- String newName = input[0];
- String descVer = input[1];
- String roles = input[2];
+ String newName = params[0];
+ String descVer = params[1];
+ String roles = params[2];
PropertyArrayList initProps =
- input.length > 3 ? getInitProperties(input[3]):new PropertyArrayList();
+ params.length > 3 ? getInitProperties(params[3]):new PropertyArrayList();
Logger.msg(1, "CreateAgentFromDescription::request() - Starting.");
- try {
-
- // check if given roles exist
- String[] roleArr = roles.split(",");
- for(int i=0; i<roleArr.length; i++) {
- RolePath thisRole = Gateway.getLookup().getRolePath(roleArr[i]);
- if (!thisRole.exists()) throw new InvalidDataException("Role "+roleArr[i]+" does not exist");
- }
-
- // check if the path is already taken
- try {
- Gateway.getLookup().getAgentPath(newName);
- throw new ObjectAlreadyExistsException("The agent name " +newName+ " exists already.", "");
- } catch (ObjectNotFoundException ex) { }
-
- // generate new entity key
- Logger.msg(6, "CreateItemFromDescription - Requesting new agent path");
- AgentPath newAgentPath = new AgentPath(new ItemPath(), newName);
+ // check if given roles exist
+ String[] roleArr = roles.split(",");
+ for(int i=0; i<roleArr.length; i++) {
+ RolePath thisRole = Gateway.getLookup().getRolePath(roleArr[i]);
+ }
+
+ // check if the path is already taken
+ try {
+ Gateway.getLookup().getAgentPath(newName);
+ throw new ObjectAlreadyExists("The agent name " +newName+ " exists already.");
+ } catch (ObjectNotFound ex) { }
- // resolve the item factory
- Logger.msg(6, "CreateItemFromDescription - Resolving item factory");
+ // generate new entity key
+ Logger.msg(6, "CreateItemFromDescription - Requesting new agent path");
+ AgentPath newAgentPath = new AgentPath(new ItemPath(), newName);
- // create the Item object
- Logger.msg(3, "CreateItemFromDescription - Creating Item");
- CorbaServer factory = Gateway.getCorbaServer();
- if (factory == null) throw new AccessRightsException("This process cannot create new Items", "");
- ActiveEntity newAgent = factory.createAgent(newAgentPath);
- Gateway.getLookupManager().add(newAgentPath);
+ // resolve the item factory
+ Logger.msg(6, "CreateItemFromDescription - Resolving item factory");
- // initialise it with its properties and workflow
+ // create the Item object
+ Logger.msg(3, "CreateItemFromDescription - Creating Item");
+ CorbaServer factory = Gateway.getCorbaServer();
+ if (factory == null) throw new CannotManage("This process cannot create new Items");
+ ActiveEntity newAgent = factory.createAgent(newAgentPath);
+ Gateway.getLookupManager().add(newAgentPath);
- Logger.msg(3, "CreateItemFromDescription - Initializing Item");
+ // initialise it with its properties and workflow
- newAgent.initialise(
- agent.getSystemKey(),
- Gateway.getMarshaller().marshall(getNewProperties(itemPath, descVer, initProps, newName, agent)),
- Gateway.getMarshaller().marshall(getNewWorkflow(itemPath, descVer)),
- Gateway.getMarshaller().marshall(getNewCollections(itemPath, descVer))
- );
-
- // add roles if given
-
- for(int i=1; i<input.length; i++) {
- newAgent.addRole(input[i]);
- }
+ Logger.msg(3, "CreateItemFromDescription - Initializing Item");
- return requestData;
- } catch (Exception e) {
- Logger.error(e);
- throw new InvalidDataException(e.getMessage(), "");
+ try {
+ newAgent.initialise(
+ agent.getSystemKey(),
+ Gateway.getMarshaller().marshall(getNewProperties(item, descVer, initProps, newName, agent)),
+ Gateway.getMarshaller().marshall(getNewWorkflow(item, descVer)),
+ Gateway.getMarshaller().marshall(getNewCollections(item, descVer))
+ );
+ } catch (PersistencyException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (Exception e) {
+ throw new InvalidData("CreateAgentFromDescription: Problem initializing new Agent. See log: "+e.getMessage());
+ }
+
+ // add roles if given
+
+ for(int i=1; i<roleArr.length; i++) {
+ newAgent.addRole(roleArr[i]);
}
+
+ return requestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java index ca1a8e4..65608c7 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java @@ -20,16 +20,16 @@ */
package com.c2kernel.lifecycle.instance.predefined.agent;
-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.common.PersistencyException;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.InvalidAgentPathException;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.lookup.RolePath;
-import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
@@ -41,7 +41,7 @@ public class RemoveAgent extends PredefinedStep { @Override
protected String runActivityLogic(AgentPath agent, ItemPath itemPath,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData {
Logger.msg(1, "RemoveAgent::request() - Starting.");
@@ -49,7 +49,7 @@ public class RemoveAgent extends PredefinedStep { try {
targetAgent = new AgentPath(itemPath);
} catch (InvalidAgentPathException ex) {
- throw new InvalidDataException("Could not resolve "+itemPath+" as an Agent.");
+ throw new InvalidData("Could not resolve "+itemPath+" as an Agent.");
}
String agentName = targetAgent.getAgentName();
@@ -59,28 +59,28 @@ public class RemoveAgent extends PredefinedStep { Gateway.getLookupManager().removeRole(targetAgent, role);
} catch (ObjectCannotBeUpdated e) {
Logger.error(e);
- throw new InvalidDataException("Error removing "+agentName+" from Role "+role.getName(), "");
- } catch (ObjectNotFoundException e) {
+ throw new InvalidData("Error removing "+agentName+" from Role "+role.getName());
+ } catch (ObjectNotFound e) {
Logger.error(e);
- throw new InvalidDataException("Tried to remove "+agentName+" from Role "+role.getName()+" that doesn't exist.", "");
- } catch (CannotManageException e) {
- throw new InvalidDataException("Tried to alter roles in a non-server process.", "");
+ throw new InvalidData("Tried to remove "+agentName+" from Role "+role.getName()+" that doesn't exist.");
+ } catch (CannotManage e) {
+ throw new InvalidData("Tried to alter roles in a non-server process.");
}
}
//clear out all storages
try {
Gateway.getStorage().removeCluster(targetAgent, "", null);
- } catch (ClusterStorageException e) {
+ } catch (PersistencyException e) {
Logger.error(e);
- throw new InvalidDataException("Error deleting storage for "+agentName, "");
+ throw new InvalidData("Error deleting storage for "+agentName);
}
//remove entity path
try {
Gateway.getLookupManager().delete(targetAgent);
} catch (Exception e) {
- throw new InvalidDataException("Error deleting AgentPath for "+agentName, "");
+ throw new InvalidData("Error deleting AgentPath for "+agentName);
}
return requestData;
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentPassword.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentPassword.java index 8a7062c..5285662 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentPassword.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentPassword.java @@ -21,11 +21,12 @@ package com.c2kernel.lifecycle.instance.predefined.agent;
import java.security.NoSuchAlgorithmException;
+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.InvalidItemPathException;
@@ -41,36 +42,26 @@ public class SetAgentPassword extends PredefinedStep { @Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
-
- Logger.msg(1, "SetAgentPassword::request() - Starting.");
+ int transitionID, String requestData) throws InvalidData, ObjectNotFound, ObjectCannotBeUpdated, CannotManage {
+
+ String[] params = getDataList(requestData);
+ if (Logger.doLog(3)) Logger.msg(3, "SetAgentPassword: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params));
+ if (params.length != 1) throw new InvalidData("SetAgentPassword: Invalid parameters "+Arrays.toString(params));
AgentPath targetAgent;
try {
targetAgent = new AgentPath(item);
} catch (InvalidItemPathException ex) {
- throw new InvalidDataException("Could not resolve syskey "+item+" as an Agent.");
+ throw new InvalidData("Can only set password on an Agent. "+item+" is an Item.");
}
String agentName = targetAgent.getAgentName();
- String[] params = getDataList(requestData);
- if (params.length!=1)
- throw new InvalidDataException("Requires 1 param: new password", "");
-
try {
Gateway.getLookupManager().setAgentPassword(targetAgent, params[0]);
- } catch (ObjectNotFoundException e) {
- Logger.error(e);
- throw new InvalidDataException("Agent "+agentName+" not found.", "");
- } catch (ObjectCannotBeUpdated e) {
- Logger.error(e);
- throw new InvalidDataException("Error updating LDAP entry.", "");
} catch (NoSuchAlgorithmException e) {
Logger.error(e);
- throw new InvalidDataException("Cryptographic libraries for password hashing not found.", "");
- } catch (CannotManageException e) {
- throw new InvalidDataException("Cannot set agent password in a non-server process.", "");
- }
+ throw new InvalidData("Cryptographic libraries for password hashing not found.");
+ }
params[1] = "REDACTED"; // censor user's password from outcome
return bundleData(params);
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java index 8c009e3..02cc49e 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java @@ -22,8 +22,8 @@ package com.c2kernel.lifecycle.instance.predefined.agent; import java.util.ArrayList;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.InvalidItemPathException;
@@ -40,7 +40,7 @@ public class SetAgentRoles extends PredefinedStep { @Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData {
Logger.msg(1, "SetAgentRoles::request() - Starting.");
@@ -49,7 +49,7 @@ public class SetAgentRoles extends PredefinedStep { try {
targetAgent = new AgentPath(item);
} catch (InvalidItemPathException ex) {
- throw new InvalidDataException("Could not resolve syskey "+item+" as an Agent.");
+ throw new InvalidData("Could not resolve syskey "+item+" as an Agent.");
}
RolePath[] currentRoles = targetAgent.getRoles();
@@ -57,8 +57,8 @@ public class SetAgentRoles extends PredefinedStep { for (int i=0; i<params.length; i++)
try {
requestedRoles.add(Gateway.getLookup().getRolePath(params[i]));
- } catch (ObjectNotFoundException e) {
- throw new InvalidDataException("Role "+params[i]+" not found", "");
+ } catch (ObjectNotFound e) {
+ throw new InvalidData("Role "+params[i]+" not found");
}
ArrayList<RolePath> rolesToRemove = new ArrayList<RolePath>();
@@ -75,7 +75,7 @@ public class SetAgentRoles extends PredefinedStep { Gateway.getLookupManager().removeRole(targetAgent, roleToRemove);
} catch (Exception e) {
Logger.error(e);
- throw new InvalidDataException("Error removing role "+roleToRemove.getName(), "");
+ throw new InvalidData("Error removing role "+roleToRemove.getName());
}
// add requested roles we don't already have
@@ -84,7 +84,7 @@ public class SetAgentRoles extends PredefinedStep { Gateway.getLookupManager().addRole(targetAgent, roleToAdd);
} catch (Exception e) {
Logger.error(e);
- throw new InvalidDataException("Error adding role "+roleToAdd.getName(), "");
+ throw new InvalidData("Error adding role "+roleToAdd.getName());
}
return requestData;
|
