Search in sources :

Example 11 with AgentPath

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));
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) AgentPath(org.cristalise.kernel.lookup.AgentPath)

Example 12 with AgentPath

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;
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) Property(org.cristalise.kernel.property.Property) ActiveEntity(org.cristalise.kernel.entity.agent.ActiveEntity) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) CannotManageException(org.cristalise.kernel.common.CannotManageException) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 13 with AgentPath

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);
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) AgentPath(org.cristalise.kernel.lookup.AgentPath) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) ActiveEntity(org.cristalise.kernel.entity.agent.ActiveEntity) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 14 with AgentPath

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);
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 15 with AgentPath

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;
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ArrayList(java.util.ArrayList) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) RolePath(org.cristalise.kernel.lookup.RolePath)

Aggregations

AgentPath (org.cristalise.kernel.lookup.AgentPath)23 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)10 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)10 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)8 CannotManageException (org.cristalise.kernel.common.CannotManageException)6 PersistencyException (org.cristalise.kernel.common.PersistencyException)6 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)5 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)5 RolePath (org.cristalise.kernel.lookup.RolePath)5 InvalidAgentPathException (org.cristalise.kernel.lookup.InvalidAgentPathException)4 IOException (java.io.IOException)3 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)3 AgentProxy (org.cristalise.kernel.entity.proxy.AgentProxy)3 CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)3 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)3 DomainPath (org.cristalise.kernel.lookup.DomainPath)3 ItemPath (org.cristalise.kernel.lookup.ItemPath)3 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)3 Property (org.cristalise.kernel.property.Property)3 PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)3