Search in sources :

Example 1 with CannotManageException

use of org.cristalise.kernel.common.CannotManageException in project kernel by cristal-ise.

the class ItemImplementation method delegatedAction.

@Override
public String delegatedAction(SystemKey agentId, SystemKey delegateId, String stepPath, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, ObjectNotFoundException, InvalidDataException, PersistencyException, ObjectAlreadyExistsException, InvalidCollectionModification {
    Workflow lifeCycle = null;
    try {
        AgentPath agent = new AgentPath(agentId);
        AgentPath delegate = delegateId == null ? null : new AgentPath(delegateId);
        Logger.msg(1, "ItemImplementation::request(" + mItemPath + ") - Transition " + transitionID + " on " + stepPath + " by " + (delegate == null ? "" : delegate + " on behalf of ") + agent);
        // TODO: check if delegate is allowed valid for agent
        lifeCycle = (Workflow) mStorage.get(mItemPath, ClusterType.LIFECYCLE + "/workflow", null);
        String finalOutcome = lifeCycle.requestAction(agent, delegate, stepPath, mItemPath, transitionID, requestData);
        // store the workflow if we've changed the state of the domain wf
        if (!(stepPath.startsWith("workflow/predefined")))
            mStorage.put(mItemPath, lifeCycle, lifeCycle);
        // remove entity path if transaction was successful
        if (stepPath.equals("workflow/predefined/Erase")) {
            Logger.msg("Erasing item path " + mItemPath.toString());
            Gateway.getLookupManager().delete(mItemPath);
        }
        mStorage.commit(lifeCycle);
        return finalOutcome;
    } catch (AccessRightsException | InvalidTransitionException | ObjectNotFoundException | PersistencyException | InvalidDataException | ObjectAlreadyExistsException | InvalidCollectionModification ex) {
        if (Logger.doLog(8))
            Logger.error(ex);
        String errorOutcome = handleError(agentId, delegateId, stepPath, lifeCycle, ex);
        if (StringUtils.isBlank(errorOutcome)) {
            mStorage.abort(lifeCycle);
            throw ex;
        } else {
            mStorage.commit(lifeCycle);
            return errorOutcome;
        }
    } catch (InvalidAgentPathException | ObjectCannotBeUpdated | CannotManageException ex) {
        if (Logger.doLog(8))
            Logger.error(ex);
        String errorOutcome = handleError(agentId, delegateId, stepPath, lifeCycle, ex);
        if (StringUtils.isBlank(errorOutcome)) {
            mStorage.abort(lifeCycle);
            throw new InvalidDataException(ex.getClass().getName() + " - " + ex.getMessage());
        } else {
            mStorage.commit(lifeCycle);
            return errorOutcome;
        }
    } catch (Exception ex) {
        // non-CORBA exception hasn't been caught!
        Logger.error("Unknown Error: requestAction on " + mItemPath + " by " + agentId + " executing " + stepPath);
        Logger.error(ex);
        String errorOutcome = handleError(agentId, delegateId, stepPath, lifeCycle, ex);
        if (StringUtils.isBlank(errorOutcome)) {
            mStorage.abort(lifeCycle);
            throw new InvalidDataException("Extraordinary Exception during execution:" + ex.getClass().getName() + " - " + ex.getMessage());
        } else {
            mStorage.commit(lifeCycle);
            return errorOutcome;
        }
    }
}
Also used : InvalidTransitionException(org.cristalise.kernel.common.InvalidTransitionException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) Workflow(org.cristalise.kernel.lifecycle.instance.Workflow) InvalidCollectionModification(org.cristalise.kernel.common.InvalidCollectionModification) 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) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException)

Example 2 with CannotManageException

use of org.cristalise.kernel.common.CannotManageException in project kernel by cristal-ise.

the class ItemImplementation method handleError.

/**
 * @param agentId
 * @param delegateId
 * @param stepPath
 * @param ex
 * @return
 * @throws PersistencyException
 * @throws ObjectNotFoundException
 * @throws AccessRightsException
 * @throws InvalidTransitionException
 * @throws InvalidDataException
 * @throws ObjectAlreadyExistsException
 * @throws InvalidCollectionModification
 */
private String handleError(SystemKey agentId, SystemKey delegateId, String stepPath, Workflow lifeCycle, Exception ex) throws PersistencyException, ObjectNotFoundException, AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException, InvalidCollectionModification {
    if (!Gateway.getProperties().getBoolean("StateMachine.enableErrorHandling", false))
        return null;
    int errorTransId = ((Activity) lifeCycle.search(stepPath)).getErrorTransitionId();
    if (errorTransId == -1)
        return null;
    try {
        AgentPath agent = new AgentPath(agentId);
        AgentPath delegate = delegateId == null ? null : new AgentPath(delegateId);
        String errorOutcome = Gateway.getMarshaller().marshall(new ErrorInfo(ex));
        lifeCycle.requestAction(agent, delegate, stepPath, mItemPath, errorTransId, errorOutcome);
        if (!(stepPath.startsWith("workflow/predefined")))
            mStorage.put(mItemPath, lifeCycle, lifeCycle);
        return errorOutcome;
    } catch (InvalidAgentPathException | ObjectCannotBeUpdated | CannotManageException | MarshalException | ValidationException | IOException | MappingException e) {
        Logger.error(e);
        return "";
    }
}
Also used : MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ErrorInfo(org.cristalise.kernel.scripting.ErrorInfo) Activity(org.cristalise.kernel.lifecycle.instance.Activity) CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) IOException(java.io.IOException) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) MappingException(org.exolab.castor.mapping.MappingException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException)

Example 3 with CannotManageException

use of org.cristalise.kernel.common.CannotManageException in project kernel by cristal-ise.

the class Gateway method startServer.

/**
 * Makes this process capable of creating and managing server entities. Runs the
 * Creates the LookupManager, ProxyServer, initialises the ORB and CORBAServer
 */
public static void startServer() throws InvalidDataException, CannotManageException {
    try {
        // check top level directory contexts
        if (mLookup instanceof LookupManager) {
            mLookupManager = (LookupManager) mLookup;
            mLookupManager.initializeDirectory();
        } else {
            throw new CannotManageException("Lookup implementation is not a LookupManager. Cannot write to directory");
        }
        // start entity proxy server
        mProxyServer = new ProxyServer(mC2KProps.getProperty("ItemServer.name"));
        // Init ORB - set various config
        String serverName = mC2KProps.getProperty("ItemServer.name");
        // TODO: externalize this (or replace corba completely)
        if (serverName != null)
            mC2KProps.put("com.sun.CORBA.ORBServerHost", serverName);
        String serverPort = mC2KProps.getProperty("ItemServer.iiop", "1500");
        mC2KProps.put("com.sun.CORBA.ORBServerPort", serverPort);
        mC2KProps.put("com.sun.CORBA.POA.ORBServerId", "1");
        mC2KProps.put("com.sun.CORBA.POA.ORBPersistentServerPort", serverPort);
        // need to force UTF-8 in the Sun ORB
        mC2KProps.put("com.sun.CORBA.codeset.charsets", "0x05010001, 0x00010109");
        mC2KProps.put("com.sun.CORBA.codeset.wcharsets", "0x00010109, 0x05010001");
        // Standard initialisation of the ORB
        orbDestroyed = false;
        mORB = org.omg.CORBA.ORB.init(new String[0], mC2KProps);
        Logger.msg("Gateway.startServer() - ORB initialised. ORB class:'" + mORB.getClass().getName() + "'");
        // start corba server components
        mCorbaServer = new CorbaServer();
        Logger.msg("Gateway.startServer() - Server '" + serverName + "' STARTED.");
    } catch (Exception ex) {
        Logger.error(ex);
        Logger.die("Exception starting server components. Shutting down.");
    }
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) LookupManager(org.cristalise.kernel.lookup.LookupManager) CorbaServer(org.cristalise.kernel.entity.CorbaServer) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) MalformedURLException(java.net.MalformedURLException) PersistencyException(org.cristalise.kernel.common.PersistencyException) CannotManageException(org.cristalise.kernel.common.CannotManageException) ProxyServer(org.cristalise.kernel.entity.proxy.ProxyServer)

Example 4 with CannotManageException

use of org.cristalise.kernel.common.CannotManageException in project kernel by cristal-ise.

the class ModuleWorkflow method populateActivityDef.

@Override
public void populateActivityDef() throws ObjectNotFoundException, CannotManageException {
    super.populateActivityDef();
    CompositeActivityDef compActDef = (CompositeActivityDef) actDef;
    ArrayList<ActivityDef> graphActDefs = compActDef.getRefChildActDef();
    if (activities.size() != graphActDefs.size())
        throw new CannotManageException("There were " + activities.size() + " declared activities, but the graph uses " + graphActDefs.size());
    for (ModuleDescRef moduleDescRef : activities) {
        boolean found = false;
        for (ActivityDef childActDef : graphActDefs) {
            if (childActDef.getName().equals(moduleDescRef.getName()) && childActDef.getVersion().equals(moduleDescRef.getVersion())) {
                found = true;
                break;
            }
        }
        if (!found)
            throw new CannotManageException("Graphed child activity " + moduleDescRef.getName() + " v" + moduleDescRef.getVersion() + " not referenced in module for " + getName());
    }
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) CompositeActivityDef(org.cristalise.kernel.lifecycle.CompositeActivityDef) ActivityDef(org.cristalise.kernel.lifecycle.ActivityDef) CompositeActivityDef(org.cristalise.kernel.lifecycle.CompositeActivityDef)

Example 5 with CannotManageException

use of org.cristalise.kernel.common.CannotManageException in project kernel by cristal-ise.

the class CreateItemFromDescription method runActivityLogic.

/**
 * Params:
 * <ol>
 * <li>Item name</li>
 * <li>Domain context</li>
 * <li>Description version to use(optional)</li>
 * <li>Initial properties to set in the new Agent (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
 */
@Override
protected String runActivityLogic(AgentPath agent, ItemPath descItemPath, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectAlreadyExistsException, CannotManageException, ObjectCannotBeUpdated, PersistencyException {
    String[] input = getDataList(requestData);
    String newName = input[0];
    String domPath = input[1];
    String descVer = input.length > 2 ? input[2] : "last";
    PropertyArrayList initProps = input.length > 3 ? unmarshallInitProperties(input[3]) : new PropertyArrayList();
    Logger.msg(1, "CreateItemFromDescription - name:" + newName);
    // check if the path is already taken
    DomainPath context = new DomainPath(new DomainPath(domPath), newName);
    if (context.exists())
        throw new ObjectAlreadyExistsException("The path " + context + " exists already.");
    // generate new item path with random uuid
    Logger.msg(6, "CreateItemFromDescription - Requesting new item path");
    ItemPath newItemPath = new ItemPath();
    // create the Item object
    Logger.msg(3, "CreateItemFromDescription - Creating Item");
    CorbaServer factory = Gateway.getCorbaServer();
    if (factory == null)
        throw new CannotManageException("This process cannot create new Items");
    TraceableEntity newItem = factory.createItem(newItemPath);
    Gateway.getLookupManager().add(newItemPath);
    initialiseItem(newItem, agent, descItemPath, initProps, newName, descVer, context, newItemPath, locker);
    return requestData;
}
Also used : TraceableEntity(org.cristalise.kernel.entity.TraceableEntity) DomainPath(org.cristalise.kernel.lookup.DomainPath) CannotManageException(org.cristalise.kernel.common.CannotManageException) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) CorbaServer(org.cristalise.kernel.entity.CorbaServer) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Aggregations

CannotManageException (org.cristalise.kernel.common.CannotManageException)12 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)8 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)7 PersistencyException (org.cristalise.kernel.common.PersistencyException)6 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)5 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)5 AgentPath (org.cristalise.kernel.lookup.AgentPath)5 CorbaServer (org.cristalise.kernel.entity.CorbaServer)3 InvalidAgentPathException (org.cristalise.kernel.lookup.InvalidAgentPathException)3 ItemPath (org.cristalise.kernel.lookup.ItemPath)3 RolePath (org.cristalise.kernel.lookup.RolePath)3 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 TraceableEntity (org.cristalise.kernel.entity.TraceableEntity)2 ActiveEntity (org.cristalise.kernel.entity.agent.ActiveEntity)2 DomainPath (org.cristalise.kernel.lookup.DomainPath)2 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)2 PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)2 MappingException (org.exolab.castor.mapping.MappingException)2 MarshalException (org.exolab.castor.xml.MarshalException)2