Search in sources :

Example 1 with ActiveEntity

use of org.cristalise.kernel.entity.agent.ActiveEntity in project kernel by cristal-ise.

the class CorbaServer method createAgent.

public ActiveEntity createAgent(AgentPath agentPath) throws CannotManageException, ObjectAlreadyExistsException {
    if (agentPath.exists())
        throw new ObjectAlreadyExistsException();
    agentPath.setIOR(getAgentIOR(agentPath));
    ActiveEntity agent = new ActiveEntity(agentPath, mAgentPOA);
    synchronized (mItemCache) {
        mItemCache.put(agentPath, agent);
    }
    return agent;
}
Also used : ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) ActiveEntity(org.cristalise.kernel.entity.agent.ActiveEntity)

Example 2 with ActiveEntity

use of org.cristalise.kernel.entity.agent.ActiveEntity 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 3 with ActiveEntity

use of org.cristalise.kernel.entity.agent.ActiveEntity in project kernel by cristal-ise.

the class CorbaServer method getAgent.

/**
 * Returns a CORBA servant for a pre-existing entity
 *
 * @param agentPath the AgentPath representing the Agent
 * @return the servant
 * @throws InvalidAgentPathException agentPath was not Agent
 * @throws ObjectNotFoundException agentPath was not found
 */
public ActiveEntity getAgent(AgentPath agentPath) throws InvalidAgentPathException, ObjectNotFoundException {
    Servant agent = null;
    if (!agentPath.exists())
        throw new ObjectNotFoundException(agentPath + " does not exist");
    synchronized (mItemCache) {
        agent = mItemCache.get(agentPath);
        if (agent == null) {
            Logger.msg(7, "Creating new servant for " + agentPath);
            agent = new ActiveEntity(agentPath, mAgentPOA);
            mItemCache.put(agentPath, agent);
        } else if (!(agent instanceof ActiveEntity))
            throw new InvalidAgentPathException("Item " + agentPath + " was not an agent");
    }
    return (ActiveEntity) agent;
}
Also used : ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) Servant(org.omg.PortableServer.Servant) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException) ActiveEntity(org.cristalise.kernel.entity.agent.ActiveEntity)

Example 4 with ActiveEntity

use of org.cristalise.kernel.entity.agent.ActiveEntity in project kernel by cristal-ise.

the class CreateAgentFromDescription method createAgentAddRoles.

/**
 * @param newAgentPath
 * @param roles
 * @return
 * @throws CannotManageException
 * @throws ObjectCannotBeUpdated
 * @throws ObjectAlreadyExistsException
 */
protected ActiveEntity createAgentAddRoles(AgentPath newAgentPath, String[] roles, String pwd) throws CannotManageException, ObjectCannotBeUpdated, ObjectAlreadyExistsException {
    // create the Agent object
    Logger.msg(3, "CreateAgentFromDescription.createAgentAddRoles() - Creating Agent");
    CorbaServer factory = Gateway.getCorbaServer();
    if (factory == null)
        throw new CannotManageException("This process cannot create new Items");
    ActiveEntity newAgent = factory.createAgent(newAgentPath);
    Gateway.getLookupManager().add(newAgentPath);
    try {
        if (StringUtils.isNotBlank(pwd))
            Gateway.getLookupManager().setAgentPassword(newAgentPath, pwd);
        for (String roleName : roles) {
            RolePath role = Gateway.getLookupManager().getRolePath(roleName);
            Gateway.getLookupManager().addRole(newAgentPath, role);
        }
    } catch (ObjectNotFoundException | NoSuchAlgorithmException e) {
        Logger.error(e);
        Gateway.getLookupManager().delete(newAgentPath);
    }
    return newAgent;
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) CorbaServer(org.cristalise.kernel.entity.CorbaServer) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ActiveEntity(org.cristalise.kernel.entity.agent.ActiveEntity) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 5 with ActiveEntity

use of org.cristalise.kernel.entity.agent.ActiveEntity 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)

Aggregations

ActiveEntity (org.cristalise.kernel.entity.agent.ActiveEntity)5 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)3 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)3 CannotManageException (org.cristalise.kernel.common.CannotManageException)2 AgentPath (org.cristalise.kernel.lookup.AgentPath)2 RolePath (org.cristalise.kernel.lookup.RolePath)2 PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CorbaServer (org.cristalise.kernel.entity.CorbaServer)1 DomainPath (org.cristalise.kernel.lookup.DomainPath)1 InvalidAgentPathException (org.cristalise.kernel.lookup.InvalidAgentPathException)1 ItemPath (org.cristalise.kernel.lookup.ItemPath)1 Property (org.cristalise.kernel.property.Property)1 Servant (org.omg.PortableServer.Servant)1