/************************************************************************** * TraceableEntity * * $Workfile$ * $Revision: 1.108 $ * $Date: 2005/10/06 14:46:22 $ * * Copyright (C) 2001 CERN - European Organization for Nuclear Research * All rights reserved. **************************************************************************/ package com.c2kernel.entity; import com.c2kernel.common.AccessRightsException; import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.InvalidTransitionException; import com.c2kernel.common.ObjectAlreadyExistsException; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.common.PersistencyException; import com.c2kernel.entity.agent.JobArrayList; import com.c2kernel.lifecycle.instance.CompositeActivity; import com.c2kernel.lifecycle.instance.Workflow; import com.c2kernel.lifecycle.instance.stateMachine.Transitions; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.InvalidEntityPathException; import com.c2kernel.persistency.ClusterStorage; import com.c2kernel.persistency.ClusterStorageException; import com.c2kernel.persistency.TransactionManager; import com.c2kernel.process.Gateway; import com.c2kernel.property.Property; import com.c2kernel.property.PropertyArrayList; import com.c2kernel.utils.Logger; /************************************************************************** * * @author $Author: abranson $ $Date: 2005/10/06 14:46:22 $ * @version $Revision: 1.108 $ *
* ,. '\'\ ,---. * . | \\ l\\l_ // | * _ _ | \\/ `/ `.| | * /~\\ \ //~\ | Y | | || Y | * | \\ \ // | | \| | |\ / | * [ || || ] \ | o|o | > / * ] Y || || Y [ \___\_--_ /_/__/ * | \_|l,------.l|_/ | /.-\(____) /--.\ * | >' `< | `--(______)----' * \ (/~`--____--'~\) / u// u / \ * `-_>-__________-<_-' / \ / /| * /(_#(__)#_)\ ( .) / / ] * \___/__\___/ `.`' / [ * /__`--'__\ |`-' | * /\(__,>-~~ __) | |_ * /\//\\( `--~~ ) _l |-:. * '\/ <^\ /^> | ` ( < \\ * _\ >-__-< /_ ,-\ ,-~~->. \ `:._,/ * (___\ /___) (____/ (____) `-' * Kovax and, paradoxically, Kovax ****************************************************************************/ public class TraceableEntity extends ItemPOA { private final int mSystemKey; private final org.omg.PortableServer.POA mPoa; private final TransactionManager mStorage; /************************************************************************** * Constructor used by the Locator only **************************************************************************/ public TraceableEntity( int key, org.omg.PortableServer.POA poa ) { Logger.msg(5,"TraceableEntity::constructor() - SystemKey:" + key ); mSystemKey = key; mPoa = poa; mStorage = Gateway.getStorage(); } /************************************************************************** * **************************************************************************/ @Override public org.omg.PortableServer.POA _default_POA() { if(mPoa != null) return mPoa; else return super._default_POA(); } /************************************************************************** * **************************************************************************/ @Override public int getSystemKey() { Logger.msg(8, "TraceableEntity::getSystemKey() - " + mSystemKey); return mSystemKey; } /************************************************************************** * **************************************************************************/ @Override public void initialise( int agentId, String propString, String initWfString ) throws AccessRightsException, InvalidDataException, PersistencyException { Logger.msg(1, "TraceableEntity::initialise("+mSystemKey+") - agent:"+agentId); synchronized (this) { Workflow lc = null; PropertyArrayList props = null; AgentPath agentPath; try { agentPath = new AgentPath(agentId); } catch (InvalidEntityPathException e) { throw new AccessRightsException("Invalid Agent Id:" + agentId); } //unmarshalling checks the validity of the received strings // create properties if (!propString.equals("")) { try { props = (PropertyArrayList)Gateway.getMarshaller().unmarshall(propString); for (Object name : props.list) { Property thisProp = (Property)name; mStorage.put(mSystemKey, thisProp, props); } } catch (Throwable ex) { Logger.msg(8, "TraceableEntity::initialise("+mSystemKey+ ") - Properties were invalid: "+propString); Logger.error(ex); mStorage.abort(props); } mStorage.commit(props); } // create wf try { if (initWfString == null || initWfString.equals("")) lc = new Workflow(new CompositeActivity()); else lc = new Workflow((CompositeActivity)Gateway.getMarshaller().unmarshall(initWfString)); lc.initialise(mSystemKey, agentPath); mStorage.put(mSystemKey, lc, null); } catch (Throwable ex) { Logger.msg(8, "TraceableEntity::initialise("+mSystemKey+") - Workflow was invalid: "+initWfString); Logger.error(ex); } } } /************************************************************************** * **************************************************************************/ //requestdata is xmlstring @Override public void requestAction( int agentId, String stepPath, int transitionID, String requestData ) throws AccessRightsException, InvalidTransitionException, ObjectNotFoundException, InvalidDataException, PersistencyException, ObjectAlreadyExistsException { synchronized (this) { try { Logger.msg(1, "TraceableEntity::request("+mSystemKey+") - " + Transitions.getTransitionName(transitionID) + " "+stepPath + " by " +agentId ); AgentPath agent = new AgentPath(agentId); Workflow lifeCycle = (Workflow)mStorage.get(mSystemKey, ClusterStorage.LIFECYCLE+"/workflow", null); lifeCycle.requestAction( agent, stepPath, transitionID, requestData ); // store the workflow if we've changed the state of the domain wf if (!(stepPath.startsWith("workflow/predefined"))) mStorage.put(mSystemKey, lifeCycle, null); // Normal operation exceptions } catch (AccessRightsException ex) { Logger.msg("Propagating AccessRightsException back to the calling agent"); throw ex; } catch (InvalidTransitionException ex) { Logger.msg("Propagating InvalidTransitionException back to the calling agent"); throw ex; } catch (ObjectNotFoundException ex) { Logger.msg("Propagating ObjectNotFoundException back to the calling agent"); throw ex; // errors } catch (ClusterStorageException ex) { Logger.error(ex); throw new PersistencyException("Error on storage: "+ex.getMessage(), ""); } catch (InvalidEntityPathException ex) { Logger.error(ex); throw new AccessRightsException("Invalid Agent Id: "+agentId, ""); } catch (InvalidDataException ex) { Logger.error(ex); Logger.msg("Propagating InvalidDataException back to the calling agent"); throw ex; } catch (ObjectAlreadyExistsException ex) { Logger.error(ex); Logger.msg("Propagating ObjectAlreadyExistsException back to the calling agent"); throw ex; // non-CORBA exception hasn't been caught! } catch (Throwable ex) { Logger.error("Unknown Error: requestAction on "+mSystemKey+" by "+agentId+" executing "+stepPath); Logger.error(ex); throw new InvalidDataException("Extraordinary Exception during execution:"+ex.getClass().getName()+" - "+ex.getMessage(), ""); } } } /************************************************************************** * **************************************************************************/ @Override public String queryLifeCycle( int agentId, boolean filter ) throws AccessRightsException, ObjectNotFoundException, PersistencyException { synchronized (this) { Logger.msg(1, "TraceableEntity::queryLifeCycle("+mSystemKey+") - agent: " + agentId); try { AgentPath agent = new AgentPath(agentId); Workflow wf = (Workflow)mStorage.get(mSystemKey, ClusterStorage.LIFECYCLE+"/workflow", null); JobArrayList jobBag = new JobArrayList(); CompositeActivity domainWf = (CompositeActivity)wf.search("workflow/domain"); jobBag.list = filter?domainWf.calculateJobs(agent, true):domainWf.calculateAllJobs(agent, true); Logger.msg(1, "TraceableEntity::queryLifeCycle("+mSystemKey+") - Returning "+jobBag.list.size()+" jobs."); return Gateway.getMarshaller().marshall( jobBag ); } catch( Throwable ex ) { Logger.error(ex); return "