use of org.cristalise.kernel.lookup.AgentPath in project kernel by cristal-ise.
the class Job method setAgentUUID.
/**
* Used by castor to unmarshall from XML
*
* @param uuid the string representation of UUID
* @throws InvalidItemPathException Cannot set UUID of agent and delegate from parameter
*/
public void setAgentUUID(String uuid) throws InvalidItemPathException {
if (StringUtils.isBlank(uuid)) {
agentPath = null;
delegatePath = null;
} else if (uuid.contains(":")) {
String[] agentStr = uuid.split(":");
if (agentStr.length != 2)
throw new InvalidItemPathException("Cannot set UUID of agent and delegate from string:" + uuid);
setAgentPath(new AgentPath(agentStr[0]));
setDelegatePath(new AgentPath(agentStr[1]));
} else
setAgentPath(new AgentPath(uuid));
}
use of org.cristalise.kernel.lookup.AgentPath in project kernel by cristal-ise.
the class ImportAgent method create.
@Override
public Path create(AgentPath agentPath, boolean reset) throws ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, ObjectAlreadyExistsException {
if (roles.isEmpty())
throw new ObjectNotFoundException("Agent '" + name + "' must declare at least one Role ");
AgentPath newAgent = new AgentPath(getItemPath(), name);
ActiveEntity newAgentEnt = Gateway.getCorbaServer().createAgent(newAgent);
Gateway.getLookupManager().add(newAgent);
// assemble properties
properties.add(new Property(NAME, name, true));
properties.add(new Property(TYPE, "Agent", false));
try {
if (StringUtils.isNotBlank(password))
Gateway.getLookupManager().setAgentPassword(newAgent, password);
newAgentEnt.initialise(agentPath.getSystemKey(), Gateway.getMarshaller().marshall(new PropertyArrayList(properties)), null, null);
} catch (Exception ex) {
Logger.error(ex);
throw new CannotManageException("Error initialising new agent name:" + name);
}
for (ImportRole role : roles) {
RolePath thisRole = (RolePath) role.create(agentPath, reset);
Gateway.getLookupManager().addRole(newAgent, thisRole);
}
return newAgent;
}
use of org.cristalise.kernel.lookup.AgentPath in project kernel by cristal-ise.
the class CreateAgentFromDescription method runActivityLogic.
/**
* Params:
* <ol>
* <li>Agent name</li>
* <li>Domain context</li>
* <li>Comma-delimited Role names to assign to the Agent</li>
* <li>Password (optional)</li>
* <li>Initial properties to set in the new Agent (optional)</li>
* <li>Description version to use(optional)</li>
* </ol>
* @throws ObjectNotFoundException
* @throws InvalidDataException The input parameters were incorrect
* @throws ObjectAlreadyExistsException The Agent already exists
* @throws CannotManageException The Agent could not be created
* @throws ObjectCannotBeUpdated The addition of the new entries into the LookupManager failed
* @throws PersistencyException
* @see org.cristalise.kernel.lifecycle.instance.predefined.item.CreateItemFromDescription#runActivityLogic(AgentPath, ItemPath, int, String, Object)
*/
@Override
protected String runActivityLogic(AgentPath agentPath, ItemPath descItemPath, int transitionID, String requestData, Object locker) throws ObjectNotFoundException, InvalidDataException, ObjectAlreadyExistsException, CannotManageException, ObjectCannotBeUpdated, PersistencyException {
String[] input = getDataList(requestData);
String newName = input[0];
String contextS = input[1];
String[] roles = input[2].split(",");
String pwd = input.length > 3 ? input[3] : "";
String descVer = input.length > 4 ? input[4] : "last";
PropertyArrayList initProps = input.length > 5 ? unmarshallInitProperties(input[5]) : new PropertyArrayList();
// generate new agent path with new UUID
Logger.msg(1, "CreateAgentFromDescription - Requesting new agent path name:" + newName);
AgentPath newAgentPath = new AgentPath(new ItemPath(), newName);
// check if the agent's name is already taken
if (Gateway.getLookup().exists(newAgentPath))
throw new ObjectAlreadyExistsException("The agent name " + newName + " exists already.");
DomainPath context = new DomainPath(new DomainPath(contextS), newName);
if (context.exists())
throw new ObjectAlreadyExistsException("The path " + context + " exists already.");
ActiveEntity newAgent = createAgentAddRoles(newAgentPath, roles, pwd);
initialiseItem(newAgent, agentPath, descItemPath, initProps, newName, descVer, context, newAgentPath, locker);
// censor password from outcome
if (input.length > 3)
input[3] = "REDACTED";
return bundleData(input);
}
use of org.cristalise.kernel.lookup.AgentPath in project kernel by cristal-ise.
the class RemoveAgent method runActivityLogic.
@Override
protected String runActivityLogic(AgentPath agent, ItemPath itemPath, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, PersistencyException {
Logger.msg(1, "RemoveAgent::request() - Starting.");
AgentPath targetAgent;
try {
targetAgent = new AgentPath(itemPath);
} catch (InvalidAgentPathException ex) {
throw new InvalidDataException("Could not resolve " + itemPath + " as an Agent.");
}
String agentName = targetAgent.getAgentName();
// remove from roles
for (RolePath role : targetAgent.getRoles()) {
try {
Gateway.getLookupManager().removeRole(targetAgent, role);
} catch (ObjectCannotBeUpdated | ObjectNotFoundException | CannotManageException e) {
Logger.error(e);
throw new InvalidDataException("Error removing " + agentName + " from Role " + role.getName() + " exceptoin message:" + e.getMessage());
}
}
return super.runActivityLogic(agent, itemPath, transitionID, requestData, locker);
}
use of org.cristalise.kernel.lookup.AgentPath in project kernel by cristal-ise.
the class SetAgentRoles method runActivityLogic.
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException {
String[] params = getDataList(requestData);
Logger.msg(3, "SetAgentRoles: called by " + agent + " on " + item + " with 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.");
}
RolePath[] currentRoles = targetAgent.getRoles();
ArrayList<RolePath> requestedRoles = new ArrayList<RolePath>();
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");
}
}
ArrayList<RolePath> rolesToRemove = new ArrayList<RolePath>();
for (RolePath existingRole : currentRoles) {
//
if (// if we have it, and it's requested, then it will be kept
requestedRoles.contains(existingRole))
// so remove it from request - this will be left with roles to be added
requestedRoles.remove(existingRole);
else
// else this role will be removed
rolesToRemove.add(existingRole);
}
// remove roles not in new list
for (RolePath roleToRemove : rolesToRemove) try {
Gateway.getLookupManager().removeRole(targetAgent, roleToRemove);
} catch (Exception e) {
Logger.error(e);
throw new InvalidDataException("Error removing role " + roleToRemove.getName());
}
// add requested roles we don't already have
for (RolePath roleToAdd : requestedRoles) {
try {
Gateway.getLookupManager().addRole(targetAgent, roleToAdd);
} catch (Exception e) {
Logger.error(e);
throw new InvalidDataException("Error adding role " + roleToAdd.getName());
}
}
return requestData;
}
Aggregations