Search in sources :

Example 1 with CompositeActivity

use of org.cristalise.kernel.lifecycle.instance.CompositeActivity in project kernel by cristal-ise.

the class ItemImplementation method initialise.

@Override
public void initialise(SystemKey agentId, String propString, String initWfString, String initCollsString) throws AccessRightsException, InvalidDataException, PersistencyException {
    Logger.msg(5, "Item::initialise(" + mItemPath + ") - agent:" + agentId);
    Object locker = new Object();
    AgentPath agentPath;
    try {
        agentPath = new AgentPath(agentId);
    } catch (InvalidItemPathException e) {
        throw new AccessRightsException("Invalid Agent Id:" + agentId);
    }
    // must supply properties
    if (propString == null || propString.length() == 0 || propString.equals("<NULL/>")) {
        throw new InvalidDataException("No properties supplied");
    }
    // store properties
    try {
        PropertyArrayList props = (PropertyArrayList) Gateway.getMarshaller().unmarshall(propString);
        for (Property thisProp : props.list) mStorage.put(mItemPath, thisProp, locker);
    } catch (Throwable ex) {
        Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Properties were invalid: " + propString);
        Logger.error(ex);
        mStorage.abort(locker);
        throw new InvalidDataException("Properties were invalid");
    }
    // Store an event and the initial properties
    try {
        Schema initSchema = LocalObjectLoader.getSchema("ItemInitialization", 0);
        Outcome initOutcome = new Outcome(0, propString, initSchema);
        History hist = new History(mItemPath, locker);
        Event newEvent = hist.addEvent(new AgentPath(agentId), null, "", "Initialize", "", "", initSchema, Bootstrap.getPredefSM(), PredefinedStep.DONE, "last");
        initOutcome.setID(newEvent.getID());
        Viewpoint newLastView = new Viewpoint(mItemPath, initSchema, "last", newEvent.getID());
        mStorage.put(mItemPath, initOutcome, locker);
        mStorage.put(mItemPath, newLastView, locker);
    } catch (Throwable ex) {
        Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Could not store event and outcome.");
        Logger.error(ex);
        mStorage.abort(locker);
        throw new PersistencyException("Error storing event and outcome");
    }
    // init collections
    if (initCollsString != null && initCollsString.length() > 0 && !initCollsString.equals("<NULL/>")) {
        try {
            CollectionArrayList colls = (CollectionArrayList) Gateway.getMarshaller().unmarshall(initCollsString);
            for (Collection<?> thisColl : colls.list) {
                mStorage.put(mItemPath, thisColl, locker);
            }
        } catch (Throwable ex) {
            Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Collections were invalid: " + initCollsString);
            Logger.error(ex);
            mStorage.abort(locker);
            throw new InvalidDataException("Collections were invalid");
        }
    }
    // create wf
    Workflow lc = null;
    try {
        if (initWfString == null || initWfString.length() == 0 || initWfString.equals("<NULL/>")) {
            lc = new Workflow(new CompositeActivity(), getNewPredefStepContainer());
        } else {
            lc = new Workflow((CompositeActivity) Gateway.getMarshaller().unmarshall(initWfString), getNewPredefStepContainer());
        }
        mStorage.put(mItemPath, lc, locker);
    } catch (Throwable ex) {
        Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Workflow was invalid: " + initWfString);
        Logger.error(ex);
        mStorage.abort(locker);
        throw new InvalidDataException("Workflow was invalid");
    }
    // All objects are in place, initialize the workflow to get the Item running
    lc.initialise(mItemPath, agentPath, locker);
    mStorage.put(mItemPath, lc, locker);
    mStorage.commit(locker);
    Logger.msg(3, "Initialisation of item " + mItemPath + " was successful");
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) AgentPath(org.cristalise.kernel.lookup.AgentPath) Schema(org.cristalise.kernel.persistency.outcome.Schema) Workflow(org.cristalise.kernel.lifecycle.instance.Workflow) History(org.cristalise.kernel.events.History) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) Event(org.cristalise.kernel.events.Event) PersistencyException(org.cristalise.kernel.common.PersistencyException) Property(org.cristalise.kernel.property.Property)

Example 2 with CompositeActivity

use of org.cristalise.kernel.lifecycle.instance.CompositeActivity in project kernel by cristal-ise.

the class Bootstrap method createResourceItem.

/**
 * @param impHandler
 * @param itemName
 * @param ns
 * @param itemPath
 * @return the ItemProxy representing the newly create Item
 * @throws Exception
 */
private static ItemProxy createResourceItem(ResourceImportHandler impHandler, String itemName, String ns, ItemPath itemPath) throws Exception {
    // create props
    PropertyDescriptionList pdList = impHandler.getPropDesc();
    PropertyArrayList props = new PropertyArrayList();
    LookupManager lookupManager = Gateway.getLookupManager();
    for (int i = 0; i < pdList.list.size(); i++) {
        PropertyDescription pd = pdList.list.get(i);
        String propName = pd.getName();
        String propVal = pd.getDefaultValue();
        if (propName.equals(NAME.toString()))
            propVal = itemName;
        else if (propName.equals(MODULE.toString()))
            propVal = (ns == null) ? "kernel" : ns;
        props.list.add(new Property(propName, propVal, pd.getIsMutable()));
    }
    CompositeActivity ca = new CompositeActivity();
    try {
        ca = (CompositeActivity) ((CompositeActivityDef) LocalObjectLoader.getActDef(impHandler.getWorkflowName(), 0)).instantiate();
    } catch (ObjectNotFoundException ex) {
        Logger.error(ex);
        Logger.error("Module resource workflow " + impHandler.getWorkflowName() + " not found. Using empty.");
    }
    Gateway.getCorbaServer().createItem(itemPath);
    lookupManager.add(itemPath);
    DomainPath newDomPath = impHandler.getPath(itemName, ns);
    newDomPath.setItemPath(itemPath);
    lookupManager.add(newDomPath);
    ItemProxy newItemProxy = Gateway.getProxyManager().getProxy(itemPath);
    newItemProxy.initialise(systemAgents.get("system").getPath(), props, ca, null);
    return newItemProxy;
}
Also used : PropertyDescription(org.cristalise.kernel.property.PropertyDescription) DomainPath(org.cristalise.kernel.lookup.DomainPath) ItemProxy(org.cristalise.kernel.entity.proxy.ItemProxy) CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) LookupManager(org.cristalise.kernel.lookup.LookupManager) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) CompositeActivityDef(org.cristalise.kernel.lifecycle.CompositeActivityDef) PropertyDescriptionList(org.cristalise.kernel.property.PropertyDescriptionList) Property(org.cristalise.kernel.property.Property) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint)

Example 3 with CompositeActivity

use of org.cristalise.kernel.lifecycle.instance.CompositeActivity in project kernel by cristal-ise.

the class CompositeActivityDef method instantiate.

@Override
public WfVertex instantiate(String name) throws ObjectNotFoundException, InvalidDataException {
    CompositeActivity caInstance = new CompositeActivity();
    Logger.msg(1, "CompositeActivityDef.instantiate(name:" + name + ") - Starting.");
    caInstance.setName(name);
    configureInstance(caInstance);
    if (getItemPath() != null)
        caInstance.setType(getItemID());
    caInstance.getChildrenGraphModel().setStartVertexId(getChildrenGraphModel().getStartVertexId());
    caInstance.getChildrenGraphModel().setVertices(intantiateVertices(caInstance));
    caInstance.getChildrenGraphModel().setEdges(instantiateEdges(caInstance));
    caInstance.getChildrenGraphModel().setNextId(getChildrenGraphModel().getNextId());
    caInstance.getChildrenGraphModel().resetVertexOutlines();
    propagateCollectionProperties(caInstance);
    return caInstance;
}
Also used : CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity)

Example 4 with CompositeActivity

use of org.cristalise.kernel.lifecycle.instance.CompositeActivity 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 5 with CompositeActivity

use of org.cristalise.kernel.lifecycle.instance.CompositeActivity in project kernel by cristal-ise.

the class ReplaceDomainWorkflow method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, PersistencyException {
    Workflow lifeCycle = getWf();
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "ReplaceDomainWorkflow: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    if (params.length != 1)
        throw new InvalidDataException("ReplaceDomainWorkflow: Invalid parameters " + Arrays.toString(params));
    lifeCycle.getChildrenGraphModel().removeVertex(lifeCycle.search("workflow/domain"));
    CompositeActivity domain;
    try {
        domain = (CompositeActivity) Gateway.getMarshaller().unmarshall(params[0]);
    } catch (Exception e) {
        Logger.error(e);
        throw new InvalidDataException("ReplaceDomainWorkflow: Could not unmarshall new workflow: " + e.getMessage());
    }
    domain.setName("domain");
    lifeCycle.initChild(domain, true, new GraphPoint(150, 100));
    // if new workflow, activate it, otherwise refresh the jobs
    if (!domain.active)
        lifeCycle.run(agent, item, locker);
    else
        lifeCycle.refreshJobs(item);
    // store new wf
    try {
        Gateway.getStorage().put(item, lifeCycle, locker);
    } catch (PersistencyException e) {
        throw new PersistencyException("ReplaceDomainWorkflow: Could not write new workflow to storage: " + e.getMessage());
    }
    return requestData;
}
Also used : GraphPoint(org.cristalise.kernel.graph.model.GraphPoint) CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Workflow(org.cristalise.kernel.lifecycle.instance.Workflow) PersistencyException(org.cristalise.kernel.common.PersistencyException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Aggregations

CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)7 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)5 PersistencyException (org.cristalise.kernel.common.PersistencyException)4 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)3 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)3 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)3 PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)3 IOException (java.io.IOException)2 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)2 CompositeActivityDef (org.cristalise.kernel.lifecycle.CompositeActivityDef)2 AgentPath (org.cristalise.kernel.lookup.AgentPath)2 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)2 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)2 Property (org.cristalise.kernel.property.Property)2 MappingException (org.exolab.castor.mapping.MappingException)2 MarshalException (org.exolab.castor.xml.MarshalException)2 ValidationException (org.exolab.castor.xml.ValidationException)2 Collection (org.cristalise.kernel.collection.Collection)1 CollectionMember (org.cristalise.kernel.collection.CollectionMember)1 CannotManageException (org.cristalise.kernel.common.CannotManageException)1