From 1028dee4dfcd89e914d66d4fe92aaa8fcfbfd494 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Mon, 28 Jul 2014 12:30:16 +0200 Subject: Support pre-compilation of scripts if supported by the engine. Also does this during testing to catch script syntax errors during build. Client shell detects these error and declares them pre-execution. Conflicts: src/main/java/com/c2kernel/scripting/Script.java src/test/java/MainTest.java --- .../java/com/c2kernel/process/ClientShell.java | 5 ++++- src/main/java/com/c2kernel/scripting/Script.java | 25 +++++++++++++++++----- src/test/java/MainTest.java | 16 ++++++++------ 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/c2kernel/process/ClientShell.java b/src/main/java/com/c2kernel/process/ClientShell.java index 9f1d3ab..eeeb07f 100644 --- a/src/main/java/com/c2kernel/process/ClientShell.java +++ b/src/main/java/com/c2kernel/process/ClientShell.java @@ -5,6 +5,7 @@ import java.util.Scanner; import com.c2kernel.entity.proxy.AgentProxy; import com.c2kernel.process.auth.ProxyLogin; import com.c2kernel.scripting.Script; +import com.c2kernel.scripting.ScriptParsingException; public class ClientShell extends StandardClient { @@ -21,13 +22,15 @@ public class ClientShell extends StandardClient { System.out.print("> "); while (scan.hasNextLine()) { String command = scan.nextLine(); - console.setScript(command); try { + console.setScript(command); Object response = console.execute(); if (response == null) System.out.println("Ok"); else System.out.println(response); + } catch (ScriptParsingException e) { + System.err.println("Syntax error: "+e.getMessage()); } catch (Throwable ex) { ex.printStackTrace(); } diff --git a/src/main/java/com/c2kernel/scripting/Script.java b/src/main/java/com/c2kernel/scripting/Script.java index 83849d9..d3b24ee 100644 --- a/src/main/java/com/c2kernel/scripting/Script.java +++ b/src/main/java/com/c2kernel/scripting/Script.java @@ -7,6 +7,8 @@ import java.util.ArrayList; import java.util.HashMap; import javax.script.Bindings; +import javax.script.Compilable; +import javax.script.CompiledScript; import javax.script.ScriptContext; import javax.script.ScriptEngine; import javax.script.ScriptEngineFactory; @@ -41,6 +43,7 @@ import com.c2kernel.utils.Logger; public class Script { String mScript = ""; + CompiledScript mCompScript = null; String mName; Integer mVersion; HashMap mInputParams = new HashMap(); @@ -55,7 +58,8 @@ public class Script * @throws ScriptParsingException * @throws ParameterException */ - public Script(String xml) throws ScriptParsingException, ParameterException { + public Script(String name, int version, String xml) throws ScriptParsingException, ParameterException { + mName = name; mVersion = version; parseScriptXML(xml); } /** @@ -93,7 +97,7 @@ public class Script setScriptEngine(lang); mVersion = null; addOutput(null, returnType); - mScript = expr; + setScript(expr); } /** @@ -292,7 +296,7 @@ public class Script if (scriptChildNodes.getLength() != 1) throw new ScriptParsingException("More than one child element found under script tag. Script characters may need escaping - suggest convert to CDATA section"); if (scriptChildNodes.item(0) instanceof Text) - mScript = ((Text) scriptChildNodes.item(0)).getData(); + setScript(((Text) scriptChildNodes.item(0)).getData()); else throw new ScriptParsingException("Child element of script tag was not text"); Logger.msg(6, "Script.parseScriptXML() - script:" + mScript); @@ -475,7 +479,10 @@ public class Script if (engine == null) throw new ScriptingEngineException("Script engine not set. Cannot execute scripts."); engine.put(ScriptEngine.FILENAME, mName); - returnValue = engine.eval(mScript); + if (mCompScript != null) + returnValue = mCompScript.eval(); + else + returnValue = engine.eval(mScript); Logger.msg(7, "Script.execute() - script returned \"" + returnValue + "\""); } catch (Throwable ex) @@ -516,8 +523,16 @@ public class Script return outputs; } - public void setScript(String script) { + public void setScript(String script) throws ScriptParsingException { mScript = script; + if (engine instanceof Compilable) { + try { + Logger.msg(1, "Compiling script "+mName); + mCompScript = ((Compilable)engine).compile(mScript); + } catch (ScriptException e) { + throw new ScriptParsingException(e.getMessage()); + } + } } static public void main(String[] args) { diff --git a/src/test/java/MainTest.java b/src/test/java/MainTest.java index 26898ac..431c4c0 100644 --- a/src/test/java/MainTest.java +++ b/src/test/java/MainTest.java @@ -12,6 +12,7 @@ import com.c2kernel.persistency.outcome.SchemaValidator; import com.c2kernel.process.Gateway; import com.c2kernel.scripting.Script; import com.c2kernel.utils.CastorXMLUtility; +import com.c2kernel.scripting.ScriptParsingException; import com.c2kernel.utils.FileStringUtility; import com.c2kernel.utils.Logger; @@ -58,7 +59,6 @@ public class MainTest { String bootItems = FileStringUtility.url2String(Gateway.getResource().getKernelResourceURL("boot/allbootitems.txt")); StringTokenizer str = new StringTokenizer(bootItems, "\n\r"); - long castorTime=0; while (str.hasMoreTokens()) { String thisItem = str.nextToken(); Logger.msg(1, "Validating "+thisItem); @@ -79,7 +79,6 @@ public class MainTest { String remarshalled = Gateway.getMarshaller().marshall(unmarshalled); long now = System.currentTimeMillis(); Logger.msg("Marshall/remarshall of "+thisItem+" took "+(now-then)+"ms"); - castorTime+=(now-then); errors = validator.validate(remarshalled); assert errors.length()==0 : "Remarshalled resource "+thisItem+" has errors :"+errors+"\nRemarshalled form:\n"+remarshalled; @@ -91,8 +90,12 @@ public class MainTest { // } // assert xmlDiff.identical(); } - } - Logger.msg("Total Castor marshall time: "+castorTime+"ms"); + + if (itemType.equals("SC")) { + Logger.msg(1, "Parsing script "+thisItem); + new Script(thisItem, 0, data); + } + } } private static Schema getSchema(String name, int version, String resPath) throws ObjectNotFoundException { @@ -104,11 +107,10 @@ public class MainTest { String testScriptString = FileStringUtility.url2String(MainTest.class.getResource("TestScript.xml")); String errors = valid.validate(testScriptString); assert errors.length()==0 : "Test script not valid to schema: "+errors; - - Script testScript = new Script(testScriptString); + + Script testScript = new Script("TestScript", 0, testScriptString); assert testScript.getInputParams().size()==1 : "Script input param count wrong"; assert testScript.getInputParams().get("test")!=null : "Could not retrieve script input param value"; - testScript.setInputParamValue("test", "Test"); assert testScript.getInputParams().get("test").getInitialised() : "Script is not initialized when it should be"; -- cgit v1.2.3 From 405a52f8f04b13f659c3bcdd232cb80317c09043 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Mon, 28 Jul 2014 12:47:13 +0200 Subject: Label script before compiling. --- src/main/java/com/c2kernel/scripting/Script.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/c2kernel/scripting/Script.java b/src/main/java/com/c2kernel/scripting/Script.java index d3b24ee..d8ccee2 100644 --- a/src/main/java/com/c2kernel/scripting/Script.java +++ b/src/main/java/com/c2kernel/scripting/Script.java @@ -528,6 +528,7 @@ public class Script if (engine instanceof Compilable) { try { Logger.msg(1, "Compiling script "+mName); + engine.put(ScriptEngine.FILENAME, mName); mCompScript = ((Compilable)engine).compile(mScript); } catch (ScriptException e) { throw new ScriptParsingException(e.getMessage()); -- cgit v1.2.3 From ac67b0ccef6b1235afba3f8bb5861c1333b6344e Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 29 Jul 2014 17:40:38 +0200 Subject: Reinstated URL parameter to CastorXMLUtility (other modules use their own instances of it) Renamed variables back to their original names --- src/main/java/com/c2kernel/process/Gateway.java | 6 +- .../java/com/c2kernel/utils/CastorXMLUtility.java | 74 +++++++++------------- src/test/java/MainTest.java | 11 +--- src/test/resources/server.conf | 3 +- 4 files changed, 39 insertions(+), 55 deletions(-) diff --git a/src/main/java/com/c2kernel/process/Gateway.java b/src/main/java/com/c2kernel/process/Gateway.java index cd76d0e..85262e8 100644 --- a/src/main/java/com/c2kernel/process/Gateway.java +++ b/src/main/java/com/c2kernel/process/Gateway.java @@ -108,7 +108,11 @@ public class Gateway // load kernel mapfiles giving the resourse loader and the properties of // the application to be able to configure castor - mMarshaller = new CastorXMLUtility(mResource, props, "mapFiles/"); + try { + mMarshaller = new CastorXMLUtility(mResource, props, mResource.getKernelResourceURL("mapFiles/")); + } catch (MalformedURLException e1) { + throw new InvalidDataException("Invalid Resource Location", ""); + } // init module manager diff --git a/src/main/java/com/c2kernel/utils/CastorXMLUtility.java b/src/main/java/com/c2kernel/utils/CastorXMLUtility.java index c7d37dd..c5c2499 100644 --- a/src/main/java/com/c2kernel/utils/CastorXMLUtility.java +++ b/src/main/java/com/c2kernel/utils/CastorXMLUtility.java @@ -29,11 +29,11 @@ import com.c2kernel.process.resource.ResourceLoader; * @author $Author: abranson $ $Date: 2004/10/20 14:10:21 $ * @version $Revision: 1.12 $ **************************************************************************/ -public class CastorXMLUtility{ +public class CastorXMLUtility +{ public static final String CASTOR_XML_SERIALIZER_FACTORY = "org.exolab.castor.xml.serializer.factory"; - - private XMLContext pCastorContext; + private XMLContext mappingContext; /** * Looks for a file called 'index.xml' at the given URL, and loads every @@ -42,89 +42,77 @@ public class CastorXMLUtility{ * @param aResourceLoader * the resource loader able to return the right class loader * @param aAppProperties - * the application properties containint optionnal castor + * the application properties containing optional castor * configuration - * @param aMapsSubPath - * the map root sub path (in the kernel path) + * @param mapURL + * the root URL for the mapfiles * @throws InvalidDataException */ public CastorXMLUtility(final ResourceLoader aResourceLoader, - final Properties aAppProperties, final String aMapsSubPath) + final Properties aAppProperties, final URL mapURL) throws InvalidDataException { - // build base url - URL wMapsURL ; - try { - wMapsURL = aResourceLoader.getKernelResourceURL(aMapsSubPath); - } catch (MalformedURLException e) { - throw new InvalidDataException(String.format( - "Invalid Resource Location [%s]. Cause:%s", aMapsSubPath, - e.getLocalizedMessage())); - } - + // load index - Logger.msg(3,String.format( "CastorXMLUtility. Loading maps from [%s]",wMapsURL)); + Logger.msg(3,String.format( "CastorXMLUtility. Loading maps from [%s]",mapURL)); String index; try { - index = FileStringUtility.url2String( new URL(wMapsURL, "index") ); + index = FileStringUtility.url2String( new URL(mapURL, "index") ); } catch (Exception e) { - throw new InvalidDataException(String.format("Could not load map index from [%s]",wMapsURL)); + throw new InvalidDataException(String.format("Could not load map index from [%s]",mapURL)); } // retrieve the class loader of the class "CastorXMLUtility" - ClassLoader wKernelClassLoader = aResourceLoader + ClassLoader defaultClassLoader = aResourceLoader .getClassLoader(CastorXMLUtility.class.getName()); Logger.msg(3, String.format( - "CastorXMLUtility.: iuse KernelClassLoader=[%s]", - wKernelClassLoader)); + "CastorXMLUtility.: defaultClassLoader=[%s]", + defaultClassLoader)); StringTokenizer sTokenizer = new StringTokenizer(index); int wNbMap = sTokenizer.countTokens(); // init the castor mapping using the classloader of the class "CastorXMLUtility" - Mapping wCastorMapping = new Mapping(wKernelClassLoader); + Mapping thisMapping = new Mapping(defaultClassLoader); HashSet loadedMapURLs = new HashSet(); try { int wMapIdx=0; while( sTokenizer.hasMoreTokens() ) { - String wCurrentMap = sTokenizer.nextToken(); - URL wCurrentMapURL = new URL(wMapsURL, wCurrentMap); + String thisMap = sTokenizer.nextToken(); + URL thisMapURL = new URL(mapURL, thisMap); wMapIdx++; - if( !loadedMapURLs.contains(wCurrentMapURL) ) { - Logger.msg( - 3, - String.format( - "CastorXMLUtility.: Adding mapping file (%d/%d):[%s]", - wMapIdx, wNbMap, wCurrentMapURL)); - wCastorMapping.loadMapping( wCurrentMapURL ); - loadedMapURLs.add( wCurrentMapURL ); + if( !loadedMapURLs.contains(thisMapURL) ) { + Logger.msg( 3, + String.format("CastorXMLUtility.: Adding mapping file (%d/%d):[%s]", wMapIdx, wNbMap, thisMapURL)); + thisMapping.loadMapping( thisMapURL ); + loadedMapURLs.add( thisMapURL ); } else { - Logger.msg(3,"Map file already loaded:"+wCurrentMapURL); + Logger.msg(3,"Map file already loaded:"+thisMapURL); } } - pCastorContext = new XMLContext(); + mappingContext = new XMLContext(); - pCastorContext.setClassLoader(wKernelClassLoader); + mappingContext.setClassLoader(defaultClassLoader); // if the aAppProperties contains castor properties then if (aAppProperties.contains(CASTOR_XML_SERIALIZER_FACTORY)) { - pCastorContext.setProperty(CASTOR_XML_SERIALIZER_FACTORY, + mappingContext.setProperty(CASTOR_XML_SERIALIZER_FACTORY, aAppProperties .getProperty(CASTOR_XML_SERIALIZER_FACTORY)); Logger.msg(3, String.format( "CastorXMLUtility.: castor prop: %s=[%s]", - CASTOR_XML_SERIALIZER_FACTORY, pCastorContext + CASTOR_XML_SERIALIZER_FACTORY, mappingContext .getProperty(CASTOR_XML_SERIALIZER_FACTORY))); } - pCastorContext.addMapping(wCastorMapping); + mappingContext.addMapping(thisMapping); } catch (MappingException ex) { Logger.error(ex); throw new InvalidDataException("XML Mapping files are not valid: "+ex.getMessage(), ""); @@ -136,7 +124,7 @@ public class CastorXMLUtility{ throw new InvalidDataException("Could not read XML mapping files: "+ex.getMessage(), ""); } - Logger.msg(1, String.format("Loaded [%d] maps from [%s]",loadedMapURLs.size(),wMapsURL)); + Logger.msg(1, String.format("Loaded [%d] maps from [%s]", loadedMapURLs.size(), mapURL)); } /************************************************************************** @@ -153,7 +141,7 @@ public class CastorXMLUtility{ if (obj instanceof Outcome) return ((Outcome)obj).getData(); StringWriter sWriter = new StringWriter(); - Marshaller marshaller = pCastorContext.createMarshaller(); + Marshaller marshaller = mappingContext.createMarshaller(); marshaller.setWriter(sWriter); marshaller.setMarshalAsDocument( false ); @@ -174,7 +162,7 @@ public class CastorXMLUtility{ { if (data.equals("")) return null; StringReader sReader = new StringReader( data ); - Unmarshaller unmarshaller = pCastorContext.createUnmarshaller(); + Unmarshaller unmarshaller = mappingContext.createUnmarshaller(); return unmarshaller.unmarshal( sReader ); } } diff --git a/src/test/java/MainTest.java b/src/test/java/MainTest.java index 431c4c0..ccef17a 100644 --- a/src/test/java/MainTest.java +++ b/src/test/java/MainTest.java @@ -12,7 +12,6 @@ import com.c2kernel.persistency.outcome.SchemaValidator; import com.c2kernel.process.Gateway; import com.c2kernel.scripting.Script; import com.c2kernel.utils.CastorXMLUtility; -import com.c2kernel.scripting.ScriptParsingException; import com.c2kernel.utils.FileStringUtility; import com.c2kernel.utils.Logger; @@ -37,16 +36,8 @@ public class MainTest { } } - /** - * @throws Exception - */ public void testMapFiles() throws Exception { - - Properties wAppProperties = new Properties(); - wAppProperties.put(CastorXMLUtility.CASTOR_XML_SERIALIZER_FACTORY, - "org.exolab.castor.xml.XercesXMLSerializerFactory"); - - new CastorXMLUtility(Gateway.getResource(), wAppProperties, "mapFiles/"); + new CastorXMLUtility(Gateway.getResource(), Gateway.getProperties(), Gateway.getResource().getKernelResourceURL("mapFiles/")); } public void testBootItems() throws Exception { diff --git a/src/test/resources/server.conf b/src/test/resources/server.conf index 476aeb0..c8a072a 100644 --- a/src/test/resources/server.conf +++ b/src/test/resources/server.conf @@ -1 +1,2 @@ -ClusterStorage=MemoryOnlyClusterStorage \ No newline at end of file +ClusterStorage=MemoryOnlyClusterStorage +org.exolab.castor.xml.serializer.factory=org.exolab.castor.xml.XercesXMLSerializerFactory \ No newline at end of file -- cgit v1.2.3 From acdc4f700666642e7efee841ceb6a635da9f88d4 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 29 Jul 2014 21:24:12 +0200 Subject: Help parameters no longer supported --- .../java/com/c2kernel/process/AbstractMain.java | 25 +++------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/c2kernel/process/AbstractMain.java b/src/main/java/com/c2kernel/process/AbstractMain.java index ad21b78..0baf9ce 100644 --- a/src/main/java/com/c2kernel/process/AbstractMain.java +++ b/src/main/java/com/c2kernel/process/AbstractMain.java @@ -36,25 +36,6 @@ abstract public class AbstractMain public static String MAIN_ARG_LOGLEVEL = "logLevel"; public static String MAIN_ARG_LOGFILE = "logFile"; public static String MAIN_ARG_CONNECT = "connect"; - public static String MAIN_ARG_HELP = "help"; - public static String MAIN_ARG_HELPSHORT = "h"; - - /** - * - * -noNewLogStream: if present no new Logstream is added to the logger ( - * considers that the Logger is already configured) - * - * @return help informations - */ - public static String usageHelp() { - - return "USAGE: com.c2kernel.process.AbstractMain \n" - + " -config \n" - + " [-connect ] (or LocalCentre in conf)\n" - + " [-h] [-help] \n" + " [-logLevel 0-19] \n" - + " [-logFile ]" - + " [-noNewLogStream ]"; - } @@ -122,12 +103,12 @@ abstract public class AbstractMain Logger.addLogStream(logStream, logLevel); } - Logger.msg(0, String.format( - "AbstractMain.readC2KArgs(): New logStream added = [%b]", - wMustAddNewLogStream)); + if (wMustAddNewLogStream) Logger.msg( + String.format("New logStream added at logLevel %d: %s", logLevel, logStream.getClass().getName())); // Dump params if log high enough + if (Logger.doLog(3)) for (Enumeration e = argProps.propertyNames(); e.hasMoreElements();) { String next = (String)e.nextElement(); System.out.println("AbstractMain: Param "+next+": "+argProps.getProperty(next)); -- cgit v1.2.3 From 42687932fd80afc120cbb0fd5e00954e7cdfceb4 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 29 Jul 2014 21:43:38 +0200 Subject: Validation of bootstrap outcomes from the kernel caused boot fail. Only validate non-kernel outcomes. --- src/main/java/com/c2kernel/process/Bootstrap.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java index bc93676..ed15234 100644 --- a/src/main/java/com/c2kernel/process/Bootstrap.java +++ b/src/main/java/com/c2kernel/process/Bootstrap.java @@ -195,13 +195,15 @@ public class Bootstrap } // data was missing or doesn't match - // validate it - OutcomeValidator validator = OutcomeValidator.getValidator(LocalObjectLoader.getSchema(newOutcome.getSchemaType(), newOutcome.getSchemaVersion())); - String error = validator.validate(newOutcome.getData()); - if (error.length() > 0) { - Logger.error("Outcome not valid: \n " + error); - throw new InvalidDataException(error, ""); - } + // validate it (but not for kernel objects because we need those to validate the rest) + if (ns!= null) { + OutcomeValidator validator = OutcomeValidator.getValidator(LocalObjectLoader.getSchema(newOutcome.getSchemaType(), newOutcome.getSchemaVersion())); + String error = validator.validate(newOutcome.getData()); + if (error.length() > 0) { + Logger.error("Outcome not valid: \n " + error); + throw new InvalidDataException(error, ""); + } + } // store Logger.msg("Bootstrap.verifyResource() - Writing new "+newOutcome.getSchemaType()+" v"+version+" to "+typeImpHandler.getName()+" "+itemName); -- cgit v1.2.3 From e6d1b8be6e0ad57d47c1f60fa5fcd9315d6b28fe Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 30 Jul 2014 15:01:53 +0200 Subject: Remove workflow override - bad hack for neuGrid that is no longer needed. --- .../predefined/item/CreateItemFromDescription.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java index f63c188..728631c 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java @@ -59,10 +59,6 @@ public class CreateItemFromDescription extends PredefinedStep String[] input = getDataList(requestData); String newName = input[0]; String domPath = input[1]; - String wfDefName = null; - int wfDefVer = -1; - if (input.length > 2) // override wf - wfDefName = input[2]; Logger.msg(1, "CreateItemFromDescription - Starting."); @@ -99,7 +95,7 @@ public class CreateItemFromDescription extends PredefinedStep newItem.initialise( agent.getSysKey(), Gateway.getMarshaller().marshall(getNewProperties(itemSysKey, newName, agent)), - Gateway.getMarshaller().marshall(getNewWorkflow(itemSysKey, wfDefName, wfDefVer)), + Gateway.getMarshaller().marshall(getNewWorkflow(itemSysKey)), Gateway.getMarshaller().marshall(getNewCollections(itemSysKey)) ); @@ -132,11 +128,12 @@ public class CreateItemFromDescription extends PredefinedStep return props; } - protected CompositeActivity getNewWorkflow(int itemSysKey, String wfDefName, int wfDefVer) throws ClusterStorageException, ObjectNotFoundException, InvalidDataException { + protected CompositeActivity getNewWorkflow(int itemSysKey) throws ClusterStorageException, ObjectNotFoundException, InvalidDataException { // loop through collections, collecting instantiated descriptions and finding the default workflow def String[] collNames = Gateway.getStorage().getClusterContents(itemSysKey, ClusterStorage.COLLECTION); + String wfDefName = null; Integer wfDefVer = null; for (String collName : collNames) { - if (collName.equalsIgnoreCase("workflow") && wfDefName == null) { + if (collName.equalsIgnoreCase("workflow")) { Collection thisCol = (Collection)Gateway.getStorage().get(itemSysKey, ClusterStorage.COLLECTION+"/"+collName, null); ArrayList members = thisCol.getMembers().list; // get the first member from the wf collection @@ -154,14 +151,14 @@ public class CreateItemFromDescription extends PredefinedStep // load workflow def if (wfDefName == null) throw new InvalidDataException("No workflow given or defined", ""); - if (wfDefVer == -1) + if (wfDefVer == null) throw new InvalidDataException("No workflow def version given",""); try { CompositeActivityDef wfDef = (CompositeActivityDef)LocalObjectLoader.getActDef(wfDefName, wfDefVer); return (CompositeActivity)wfDef.instantiate(); } catch (ObjectNotFoundException ex) { - throw new InvalidDataException("Workflow def '"+wfDefName+"' item not found", ""); + throw new InvalidDataException("Workflow def '"+wfDefName+"'v"+wfDefVer+" not found", ""); } catch (ClassCastException ex) { throw new InvalidDataException("Activity def '"+wfDefName+"' was not Composite", ""); } -- cgit v1.2.3 From 84c93e0d119f042b7eb903128441e23a4ed2ebd1 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Thu, 31 Jul 2014 10:28:05 +0200 Subject: CreateAgentFromDescription reverted to current Agent/Role mechanism --- .../agent/CreateAgentFromDescription.java | 45 ++++++++++++++-------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java index f311dc1..a7971f3 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java @@ -14,11 +14,12 @@ package com.c2kernel.lifecycle.instance.predefined.agent; import com.c2kernel.common.AccessRightsException; import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.ObjectAlreadyExistsException; +import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.CorbaServer; import com.c2kernel.entity.agent.ActiveEntity; import com.c2kernel.lifecycle.instance.predefined.item.CreateItemFromDescription; import com.c2kernel.lookup.AgentPath; -import com.c2kernel.lookup.DomainPath; +import com.c2kernel.lookup.RolePath; import com.c2kernel.process.Gateway; import com.c2kernel.utils.Logger; @@ -34,27 +35,36 @@ public class CreateAgentFromDescription extends CreateItemFromDescription super(); } - //requestdata is xmlstring + /** + * Params: + *
  1. 1: new Agent name
  2. + *
  3. 2...: Roles to assign to the agent. Must already exist. + * @see com.c2kernel.lifecycle.instance.predefined.item.CreateItemFromDescription#runActivityLogic(com.c2kernel.lookup.AgentPath, int, int, java.lang.String) + */ @Override protected String runActivityLogic(AgentPath agent, int itemSysKey, int transitionID, String requestData) throws InvalidDataException { String[] input = getDataList(requestData); String newName = input[0]; - String domPath = input[1]; - String wfDefName = null; - int wfDefVer = -1; - if (input.length > 2) // override wf - wfDefName = input[2]; Logger.msg(1, "CreateAgentFromDescription::request() - Starting."); try { + + if (input.length < 2) + throw new InvalidDataException("Agent should have at least one Role defined on creation"); + // check if given roles exist + for(int i=1; i Date: Tue, 26 Aug 2014 10:36:55 +0200 Subject: Proxy package javadoc --- .../com/c2kernel/entity/proxy/package-info.java | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/main/java/com/c2kernel/entity/proxy/package-info.java diff --git a/src/main/java/com/c2kernel/entity/proxy/package-info.java b/src/main/java/com/c2kernel/entity/proxy/package-info.java new file mode 100644 index 0000000..2fd6bfa --- /dev/null +++ b/src/main/java/com/c2kernel/entity/proxy/package-info.java @@ -0,0 +1,56 @@ +/** + * The Proxy API is a major part of the client-side functionality of the + * CRISTAL API, which provides client-side proxy objects that represent the + * Items and Agents on the server. It is the main entry point for many + * components, such as Scripts and Job execution. An AgentProxy is returned on + * login, and should be used as the root for all user-based CRISTAL interactions. + * + *

    The Proxy API provides the following functionality: + * + *

      + *
    • Transparent storage integration - Combines direct database access + * with remote calls to data retrieval methods on the Items. This allows client + * processes to load Item data directly from databases whenever possible + * without bothering the CRISTAL server. For example, the LDAP Lookup + * implementation allows client processes to load Item Properties directly from + * the LDAP server.
    • + * + *
    • Data object browsing and loading - The proxy objects allow client + * processes to browse through the storage cluster structure beneath the Item, + * and access the objects directly without having to unmarshall their XML forms. + * All object types have their own get methods, so there's no need to construct + * their paths nor cast. + * + *
    • Item object and directory change notification - When a proxy + * object is created, it notifies the CRISTAL server that its Item is located + * on, and it notified of all additions, deletions and modifications of objects + * within that Item so it can remain up-to-date. Client applications may use + * the {@link ProxyObserver} interface to be notified of changes, using + * {@link MemberSubscription} instances to set up push subscriptions to cluster + * contents. It also provides a mechanism for subscribing to directory paths, + * so that domain tree browsers can implement asynchronous loading and update + * themselves when the tree changes.
    • + * + *
    • Job querying - Job objects may be retrieved directly from an + * ItemProxy, and may also be filtered by Activity name.
    • + * + *
    • Job execution - The {@link AgentProxy} provides the main + * execution method for Jobs. This method performs outcome validation and + * executes required CRISTAL Scripts in the client process before the execution + * is requested on the server. Additional execution methods to call Predefined + * Steps are also available. + * + *
    • Utility methods for resolution and marshalling - The AgentProxy + * provides utility methods for finding Items in the directory by name, path, + * or system key, and gives access to the Castor XML marshalling system to + * transform CRISTAL objects to XML and back again. + * + * The core object of the Proxy API is the ProxyManager, which is initialized + * as a static member of the Gateway on initialization. This object can be used + * to create a Proxy object from a Path from the directory, and maintains a + * connection to the server called the Proxy Update Notification Channel, + * through which it subscribes to Items it holds proxies for so it can be + * informed of changes to Item data through {@link ProxyMessage} objects. + * + */ +package com.c2kernel.entity.proxy; \ No newline at end of file -- cgit v1.2.3 From d62e6fd732ab9223bc92b324d7cdcc9d2e28c109 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 26 Aug 2014 10:41:00 +0200 Subject: Formatting --- src/main/java/com/c2kernel/entity/proxy/package-info.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/c2kernel/entity/proxy/package-info.java b/src/main/java/com/c2kernel/entity/proxy/package-info.java index 2fd6bfa..404ca07 100644 --- a/src/main/java/com/c2kernel/entity/proxy/package-info.java +++ b/src/main/java/com/c2kernel/entity/proxy/package-info.java @@ -43,9 +43,9 @@ *
    • Utility methods for resolution and marshalling - The AgentProxy * provides utility methods for finding Items in the directory by name, path, * or system key, and gives access to the Castor XML marshalling system to - * transform CRISTAL objects to XML and back again. - * - * The core object of the Proxy API is the ProxyManager, which is initialized + * transform CRISTAL objects to XML and back again.
    • + *
    + *

    The core object of the Proxy API is the ProxyManager, which is initialized * as a static member of the Gateway on initialization. This object can be used * to create a Proxy object from a Path from the directory, and maintains a * connection to the server called the Proxy Update Notification Channel, -- cgit v1.2.3 From 2bf4284d2da271e4f40ef3ee680f1e845b01ca60 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 27 Aug 2014 09:09:27 +0200 Subject: Revert 'layer' from commit 8e8185210f5bd87cb5dcda3a458fe059f811aafc. This will be implemented as a diff overlay later. --- src/main/java/com/c2kernel/process/Bootstrap.java | 25 ++++---------------- .../java/com/c2kernel/process/module/Module.java | 3 +-- .../com/c2kernel/process/module/ModuleInfo.java | 1 - .../java/com/c2kernel/utils/LocalObjectLoader.java | 27 ++++++---------------- src/main/resources/boot/OD/Module.xsd | 1 - src/main/resources/boot/property/CAProp.xml | 1 - src/main/resources/boot/property/EAProp.xml | 1 - src/main/resources/boot/property/ODProp.xml | 1 - src/main/resources/boot/property/SCProp.xml | 1 - src/main/resources/boot/property/SMProp.xml | 1 - src/main/resources/mapFiles/ModuleMap.xml | 3 --- 11 files changed, 13 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java index ed15234..46e2cb6 100644 --- a/src/main/java/com/c2kernel/process/Bootstrap.java +++ b/src/main/java/com/c2kernel/process/Bootstrap.java @@ -106,7 +106,7 @@ public class Bootstrap String itemName = thisItem.substring(delim+1); try { String location = "boot/"+thisItem+(itemType.equals("OD")?".xsd":".xml"); - verifyResource(ns, itemName, 0, itemType, location, 0, reset); + verifyResource(ns, itemName, 0, itemType, location, reset); } catch (Exception e) { Logger.error(e); Logger.die("Error importing bootstrap items. Unsafe to continue."); @@ -115,7 +115,7 @@ public class Bootstrap } - public static DomainPath verifyResource(String ns, String itemName, Integer version, String itemType, String dataLocation, int layer, boolean reset) throws Exception { + public static DomainPath verifyResource(String ns, String itemName, Integer version, String itemType, String dataLocation, boolean reset) throws Exception { if (version == null) version = 0; LookupManager lookupManager = Gateway.getLookupManager(); ResourceImportHandler typeImpHandler = getHandler(itemType); @@ -127,7 +127,7 @@ public class Bootstrap Iterator en = Gateway.getLookup().search(typeImpHandler.getTypeRoot(), itemName); if (!en.hasNext()) { Logger.msg("Bootstrap.verifyResource() - "+typeImpHandler.getName()+" "+itemName+" not found. Creating new."); - thisProxy = createResourceItem(typeImpHandler, itemName, layer, ns); + thisProxy = createResourceItem(typeImpHandler, itemName, ns); } else { DomainPath path = (DomainPath)en.next(); @@ -151,15 +151,6 @@ public class Bootstrap Gateway.getStorage().put(thisProxy.getSystemKey(), new Property("Module", moduleName, false), thisProxy); } - // overwrite layer if different - int currentLayer = -1; - try { - String layerProp = thisProxy.getProperty("Layer"); - currentLayer = Integer.parseInt(layerProp); - } catch (Exception e) { } - if (currentLayer != layer) - Gateway.getStorage().put(thisProxy.getSystemKey(), new Property("Layer", String.valueOf(layer), false), thisProxy); - if (!modDomPath.equals(path)) { // move item to module subtree Logger.msg("Module item "+itemName+" found with path "+path.toString()+". Moving to "+modDomPath.toString()); modDomPath.setEntity(new ItemPath(thisProxy.getSystemKey())); @@ -248,10 +239,9 @@ public class Bootstrap /** * @param itemType * @param itemName - * @param layer * @param data */ - private static ItemProxy createResourceItem(ResourceImportHandler impHandler, String itemName, int layer, String ns) throws Exception { + private static ItemProxy createResourceItem(ResourceImportHandler impHandler, String itemName, String ns) throws Exception { // create props PropertyDescriptionList pdList = impHandler.getPropDesc(); PropertyArrayList props = new PropertyArrayList(); @@ -260,12 +250,7 @@ public class Bootstrap for (int i = 0; i < pdList.list.size(); i++) { PropertyDescription pd = pdList.list.get(i); String propName = pd.getName(); - String propVal; - if (propName.equals("Name")) - propVal = itemName; - else if (propName.equals("Layer")) - propVal = String.valueOf(layer); - else propVal = pd.getDefaultValue(); + String propVal = propName.equals("Name")?itemName:pd.getDefaultValue(); props.list.add(new Property(propName, propVal, pd.getIsMutable())); } diff --git a/src/main/java/com/c2kernel/process/module/Module.java b/src/main/java/com/c2kernel/process/module/Module.java index 195c883..1272026 100644 --- a/src/main/java/com/c2kernel/process/module/Module.java +++ b/src/main/java/com/c2kernel/process/module/Module.java @@ -57,7 +57,6 @@ public class Module { moduleItem.properties.add(new com.c2kernel.property.Property("Namespace", ns, false)); moduleItem.properties.add(new com.c2kernel.property.Property("Name", name, false)); moduleItem.properties.add(new com.c2kernel.property.Property("Type", "Module", false)); - moduleItem.properties.add(new com.c2kernel.property.Property("Layer", String.valueOf(info.layer), true)); moduleItem.properties.add(new com.c2kernel.property.Property("Version", info.version, true)); // Add dependency for all children ImportDependency children = new ImportDependency("Contents"); @@ -81,7 +80,7 @@ public class Module { for (ModuleResource thisRes : imports.getResources()) { try { thisRes.path = Bootstrap.verifyResource(ns, thisRes.name, thisRes.version, - thisRes.resourceType, thisRes.resourceLocation, info.layer, reset); + thisRes.resourceType, thisRes.resourceLocation, reset); } catch (Exception ex) { Logger.error(ex); Logger.die("Error importing module resources. Unsafe to continue."); diff --git a/src/main/java/com/c2kernel/process/module/ModuleInfo.java b/src/main/java/com/c2kernel/process/module/ModuleInfo.java index 646a915..55e02c9 100644 --- a/src/main/java/com/c2kernel/process/module/ModuleInfo.java +++ b/src/main/java/com/c2kernel/process/module/ModuleInfo.java @@ -6,7 +6,6 @@ public class ModuleInfo { public String desc; public String version; - public int layer = 0; public ArrayList dependency = new ArrayList(); public ModuleInfo() { diff --git a/src/main/java/com/c2kernel/utils/LocalObjectLoader.java b/src/main/java/com/c2kernel/utils/LocalObjectLoader.java index f0d8928..503e951 100644 --- a/src/main/java/com/c2kernel/utils/LocalObjectLoader.java +++ b/src/main/java/com/c2kernel/utils/LocalObjectLoader.java @@ -1,5 +1,5 @@ package com.c2kernel.utils; - + import java.util.Iterator; import com.c2kernel.common.InvalidDataException; @@ -24,28 +24,15 @@ public class LocalObjectLoader { { DomainPath defRoot = new DomainPath(root); Iterator e = Gateway.getLookup().search(defRoot, name); - ItemProxy defProxy = null; int currentLayer = -1; - while (e.hasNext()) { + if (e.hasNext()) { DomainPath defPath = (DomainPath)e.next(); - ItemProxy thisProxy = Gateway.getProxyManager().getProxy(defPath); - int thisLayer; - try { - String thisLayerProp = thisProxy.getProperty("Layer"); - thisLayer = Integer.parseInt(thisLayerProp); - } catch (Exception ex) { - thisLayer = 0; - } - if (thisLayer > currentLayer) { - currentLayer = thisLayer; - defProxy = thisProxy; - } - else if (thisLayer == currentLayer) { - throw new ObjectNotFoundException("Duplicate definition for "+name+" in "+root+" found in Layer "+thisLayer, ""); - } + if (e.hasNext()) throw new ObjectNotFoundException("Too many matches for "+name+" in "+root, ""); + return Gateway.getProxyManager().getProxy(defPath); } - if (defProxy == null) + else { throw new ObjectNotFoundException("No match for "+name+" in "+root, ""); - return defProxy; + } + } static public String getScript(String scriptName, int scriptVersion) throws ObjectNotFoundException { diff --git a/src/main/resources/boot/OD/Module.xsd b/src/main/resources/boot/OD/Module.xsd index c768e3f..d25352e 100644 --- a/src/main/resources/boot/OD/Module.xsd +++ b/src/main/resources/boot/OD/Module.xsd @@ -9,7 +9,6 @@ - diff --git a/src/main/resources/boot/property/CAProp.xml b/src/main/resources/boot/property/CAProp.xml index b29884a..ac37ae7 100644 --- a/src/main/resources/boot/property/CAProp.xml +++ b/src/main/resources/boot/property/CAProp.xml @@ -2,6 +2,5 @@ - diff --git a/src/main/resources/boot/property/EAProp.xml b/src/main/resources/boot/property/EAProp.xml index 2477c93..a345695 100644 --- a/src/main/resources/boot/property/EAProp.xml +++ b/src/main/resources/boot/property/EAProp.xml @@ -2,6 +2,5 @@ - diff --git a/src/main/resources/boot/property/ODProp.xml b/src/main/resources/boot/property/ODProp.xml index f4d7b15..894a6ee 100644 --- a/src/main/resources/boot/property/ODProp.xml +++ b/src/main/resources/boot/property/ODProp.xml @@ -1,6 +1,5 @@ - diff --git a/src/main/resources/boot/property/SCProp.xml b/src/main/resources/boot/property/SCProp.xml index 9ff0366..f5de23c 100644 --- a/src/main/resources/boot/property/SCProp.xml +++ b/src/main/resources/boot/property/SCProp.xml @@ -1,6 +1,5 @@ - diff --git a/src/main/resources/boot/property/SMProp.xml b/src/main/resources/boot/property/SMProp.xml index f43d0b5..8581e74 100644 --- a/src/main/resources/boot/property/SMProp.xml +++ b/src/main/resources/boot/property/SMProp.xml @@ -1,6 +1,5 @@ - diff --git a/src/main/resources/mapFiles/ModuleMap.xml b/src/main/resources/mapFiles/ModuleMap.xml index 440b852..45f6cbe 100644 --- a/src/main/resources/mapFiles/ModuleMap.xml +++ b/src/main/resources/mapFiles/ModuleMap.xml @@ -38,9 +38,6 @@ - - - -- cgit v1.2.3