Search in sources :

Example 6 with AgentPath

use of org.cristalise.kernel.lookup.AgentPath in project kernel by cristal-ise.

the class SetAgentPassword method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException {
    String[] params = getDataList(requestData);
    Logger.msg(3, "SetAgentPassword: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    if (params.length != 1)
        throw new InvalidDataException("SetAgentPassword: Invalid parameters " + Arrays.toString(params));
    try {
        AgentPath targetAgent = new AgentPath(item);
        if (!targetAgent.equals(agent) && !agent.hasRole("Admin")) {
            throw new InvalidDataException("Agent passwords may only be set by those Agents or by an Administrator");
        }
        Gateway.getLookupManager().setAgentPassword(targetAgent, params[0]);
        // censor password from outcome
        params[0] = "REDACTED";
        return bundleData(params);
    } catch (InvalidItemPathException ex) {
        Logger.error(ex);
        throw new InvalidDataException("Can only set password on an Agent. " + item + " is an Item.");
    } catch (NoSuchAlgorithmException e) {
        Logger.error(e);
        throw new InvalidDataException("Cryptographic libraries for password hashing not found.");
    }
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) AgentPath(org.cristalise.kernel.lookup.AgentPath) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 7 with AgentPath

use of org.cristalise.kernel.lookup.AgentPath in project kernel by cristal-ise.

the class RemoveRole method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, CannotManageException, ObjectNotFoundException, ObjectCannotBeUpdated {
    String[] params = getDataList(requestData);
    Logger.msg(3, "RemoveRole: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    if (params.length != 1)
        throw new InvalidDataException("RemoveRole must have one paramater:" + Arrays.toString(params));
    LookupManager lookup = Gateway.getLookupManager();
    RolePath thisRole = lookup.getRolePath(params[0]);
    AgentPath[] agents = Gateway.getLookup().getAgents(thisRole);
    if (agents.length > 0)
        throw new ObjectCannotBeUpdated("Cannot remove role as " + agents.length + " other agents still hold it.");
    lookup.delete(thisRole);
    return requestData;
}
Also used : AgentPath(org.cristalise.kernel.lookup.AgentPath) LookupManager(org.cristalise.kernel.lookup.LookupManager) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 8 with AgentPath

use of org.cristalise.kernel.lookup.AgentPath in project kernel by cristal-ise.

the class Erase method runActivityLogic.

// requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, PersistencyException {
    Logger.msg(1, "Erase::request() - Starting item:" + item.getUUID());
    Iterator<Path> domPaths = Gateway.getLookup().searchAliases(item);
    while (domPaths.hasNext()) {
        DomainPath path = (DomainPath) domPaths.next();
        // delete them
        if (path.getItemPath().equals(item))
            Gateway.getLookupManager().delete(path);
    }
    // clear out all storages
    Gateway.getStorage().removeCluster(item, "", locker);
    Logger.msg(1, "Erase::request() - DONE item:" + item.getUUID());
    return requestData;
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) AgentPath(org.cristalise.kernel.lookup.AgentPath) ItemPath(org.cristalise.kernel.lookup.ItemPath) Path(org.cristalise.kernel.lookup.Path) DomainPath(org.cristalise.kernel.lookup.DomainPath)

Example 9 with AgentPath

use of org.cristalise.kernel.lookup.AgentPath in project kernel by cristal-ise.

the class ItemImplementation method queryLifeCycle.

/**
 */
@Override
public String queryLifeCycle(SystemKey agentId, boolean filter) throws AccessRightsException, ObjectNotFoundException, PersistencyException {
    Logger.msg(1, "ItemImplementation::queryLifeCycle(" + mItemPath + ") - agent: " + agentId);
    try {
        AgentPath agent;
        try {
            agent = new AgentPath(agentId);
        } catch (InvalidItemPathException e) {
            throw new AccessRightsException("Agent " + agentId + " doesn't exist");
        }
        Workflow wf = (Workflow) mStorage.get(mItemPath, ClusterType.LIFECYCLE + "/workflow", null);
        JobArrayList jobBag = new JobArrayList();
        CompositeActivity domainWf = (CompositeActivity) wf.search("workflow/domain");
        jobBag.list = filter ? domainWf.calculateJobs(agent, mItemPath, true) : domainWf.calculateAllJobs(agent, mItemPath, true);
        Logger.msg(1, "ItemImplementation::queryLifeCycle(" + mItemPath + ") - Returning " + jobBag.list.size() + " jobs.");
        try {
            return Gateway.getMarshaller().marshall(jobBag);
        } catch (Exception e) {
            Logger.error(e);
            throw new PersistencyException("Error marshalling job bag");
        }
    } catch (AccessRightsException | ObjectNotFoundException | PersistencyException e) {
        Logger.error(e);
        throw e;
    } catch (Throwable ex) {
        Logger.error("ItemImplementation::queryLifeCycle(" + mItemPath + ") - Unknown error");
        Logger.error(ex);
        throw new PersistencyException("Unknown error querying jobs. Please see server log.");
    }
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) AgentPath(org.cristalise.kernel.lookup.AgentPath) CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) Workflow(org.cristalise.kernel.lifecycle.instance.Workflow) PersistencyException(org.cristalise.kernel.common.PersistencyException) JobArrayList(org.cristalise.kernel.entity.agent.JobArrayList) MappingException(org.exolab.castor.mapping.MappingException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ValidationException(org.exolab.castor.xml.ValidationException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) MarshalException(org.exolab.castor.xml.MarshalException) InvalidTransitionException(org.cristalise.kernel.common.InvalidTransitionException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) IOException(java.io.IOException) PersistencyException(org.cristalise.kernel.common.PersistencyException) CannotManageException(org.cristalise.kernel.common.CannotManageException) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException)

Example 10 with AgentPath

use of org.cristalise.kernel.lookup.AgentPath in project kernel by cristal-ise.

the class ActiveLocator method preinvoke.

/**
 ************************************************************************
 *
 *************************************************************************
 */
@Override
public org.omg.PortableServer.Servant preinvoke(byte[] oid, org.omg.PortableServer.POA poa, String operation, org.omg.PortableServer.ServantLocatorPackage.CookieHolder cookie) {
    try {
        ByteBuffer bb = ByteBuffer.wrap(oid);
        long msb = bb.getLong();
        long lsb = bb.getLong();
        AgentPath syskey = new AgentPath(new SystemKey(msb, lsb));
        Logger.msg(1, "===========================================================");
        Logger.msg(1, "Agent called at " + new Timestamp(System.currentTimeMillis()) + ": " + operation + "(" + syskey + ").");
        return Gateway.getCorbaServer().getAgent(syskey);
    } catch (ObjectNotFoundException ex) {
        Logger.error("ObjectNotFoundException::ActiveLocator::preinvoke() " + ex.toString());
        throw new org.omg.CORBA.OBJECT_NOT_EXIST();
    } catch (InvalidItemPathException ex) {
        Logger.error("InvalidItemPathException::ActiveLocator::preinvoke() " + ex.toString());
        throw new org.omg.CORBA.INV_OBJREF();
    }
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ByteBuffer(java.nio.ByteBuffer) Timestamp(java.sql.Timestamp) SystemKey(org.cristalise.kernel.common.SystemKey)

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