diff options
| author | ogattaz <olivier@gattaz.com> | 2014-06-05 16:51:07 +0200 |
|---|---|---|
| committer | ogattaz <olivier@gattaz.com> | 2014-06-05 16:51:07 +0200 |
| commit | 2fd193d7936084de91eae46e8c2763914d87ab71 (patch) | |
| tree | b136ed97e535f11d4b3433d16c26570c89430ce4 /src/main/java/com/c2kernel/process | |
| parent | 1225792532f77e6e8f4a9addfc0c0a6cf56e89b8 (diff) | |
| parent | e73468fd08cc27aa31f76a27c916e45d5987c628 (diff) | |
Merge branch 'master' of ssh://dev.cccs.uwe.ac.uk:22/var/git/cristal-kernel
Diffstat (limited to 'src/main/java/com/c2kernel/process')
21 files changed, 507 insertions, 380 deletions
diff --git a/src/main/java/com/c2kernel/process/AbstractMain.java b/src/main/java/com/c2kernel/process/AbstractMain.java index 03807f0..e241ee2 100644 --- a/src/main/java/com/c2kernel/process/AbstractMain.java +++ b/src/main/java/com/c2kernel/process/AbstractMain.java @@ -17,6 +17,7 @@ import java.io.PrintStream; import java.util.Enumeration;
import java.util.Properties;
+import com.c2kernel.process.resource.BadArgumentsException;
import com.c2kernel.utils.FileStringUtility;
import com.c2kernel.utils.Logger;
@@ -29,54 +30,31 @@ abstract public class AbstractMain {
public static boolean runningAsWrapper = false;
- /**************************************************************************
- *
- **************************************************************************/
- static protected void usage()
- {
- System.out.println();
- System.out.println("USAGE: com.c2kernel.process.AbstractMain \n" +
- " -config <server/client config file> \n" +
- " [-connect <LC connect file> ] (or LocalCentre in conf)\n" +
- " [-h] [-help] \n" +
- " [-logLevel 0-19] \n" +
- " [-logFile <path to log file>]");
- Logger.die("Initialisation error");
- }
/**************************************************************************
* reading and setting input paramaters
**************************************************************************/
- public static Properties readC2KArgs( String[] args ) {
+ public static Properties readC2KArgs( String[] args ) throws BadArgumentsException {
Properties c2kProps;
Properties argProps = new Properties();
int logLevel = 0;
PrintStream logStream = System.out;
- if (args == null) return argProps;
-
int i = 0;
while( i < args.length ) {
if (args[i].startsWith("-") && args[i].length()>1) {
String key = args[i].substring(1);
- if (argProps.containsKey(key)) {
- System.err.println("Argument "+args[i]+" given twice");
- usage();
- }
+ if (argProps.containsKey(key))
+ throw new BadArgumentsException("Argument "+args[i]+" given twice");
String value = "";
if (!args[i+1].startsWith("-"))
value = args[++i];
argProps.put(key, value);
i++;
}
- else {
- System.err.println("Bad argument: "+args[i]);
- usage();
- }
- }
-
- if( argProps.containsKey("h") || argProps.containsKey("help")) {
- usage();
+ else
+ throw new BadArgumentsException("Bad argument: "+args[i]);
+
}
if (argProps.containsKey("logFile"))
@@ -84,7 +62,7 @@ abstract public class AbstractMain logStream = new PrintStream(new FileOutputStream(argProps.getProperty("logFile"), true));
} catch (FileNotFoundException e) {
e.printStackTrace();
- System.err.println("Logfile "+argProps.getProperty("logFile")+" cannot be created");
+ throw new BadArgumentsException("Logfile "+argProps.getProperty("logFile")+" cannot be created");
}
// Set up log stream
@@ -100,9 +78,11 @@ abstract public class AbstractMain }
String configPath = argProps.getProperty("config");
- if (configPath == null || !new File(configPath).exists()) {
- System.err.println("Config file "+configPath+" not found");
- }
+ if (configPath == null)
+ throw new BadArgumentsException("Config file not specified");
+
+ if (!new File(configPath).exists())
+ throw new BadArgumentsException("Config file "+configPath+" not found");
else
Logger.msg(0, "Config file: "+configPath);
@@ -110,17 +90,22 @@ abstract public class AbstractMain c2kProps = FileStringUtility.loadConfigFile(argProps.getProperty("config") );
c2kProps.putAll(argProps); // args overlap config
- if (c2kProps.containsKey("connect")) {
- String connectFile = c2kProps.getProperty("connect");
+ String connectFile = c2kProps.getProperty("connect");
+ if (connectFile == null)
+ throw new BadArgumentsException("Connect file not specified");
+
+ if (!new File(connectFile).exists())
+ throw new BadArgumentsException("Connect file "+connectFile+" not found");
+ else
Logger.msg(0, "Connect file: "+connectFile);
- FileStringUtility.appendConfigFile( c2kProps, connectFile);
-
- if (!c2kProps.containsKey("LocalCentre")) {
- String connectFileName = new File(connectFile).getName();
- String centreId = connectFileName.substring(0, connectFileName.lastIndexOf(".clc"));
- c2kProps.setProperty("LocalCentre", centreId);
- }
- }
+
+ FileStringUtility.appendConfigFile( c2kProps, connectFile);
+
+ if (!c2kProps.containsKey("LocalCentre")) {
+ String connectFileName = new File(connectFile).getName();
+ String centreId = connectFileName.substring(0, connectFileName.lastIndexOf(".clc"));
+ c2kProps.setProperty("LocalCentre", centreId);
+ }
c2kProps.putAll(argProps); // args override connect file too
Logger.msg(7, "AbstractMain::standardSetUp() - readC2KArgs() DONE.");
diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java index 4f64adf..bcc5e68 100644 --- a/src/main/java/com/c2kernel/process/Bootstrap.java +++ b/src/main/java/com/c2kernel/process/Bootstrap.java @@ -1,14 +1,16 @@ package com.c2kernel.process;
import java.net.InetAddress;
-import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
import java.util.StringTokenizer;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;
import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.entity.TraceableEntity;
+import com.c2kernel.entity.proxy.AgentProxy;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.events.Event;
import com.c2kernel.events.History;
@@ -20,13 +22,15 @@ import com.c2kernel.lifecycle.instance.predefined.ServerPredefinedStepContainer; import com.c2kernel.lifecycle.instance.stateMachine.Transition;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
-import com.c2kernel.lookup.EntityPath;
-import com.c2kernel.lookup.LDAPLookup;
+import com.c2kernel.lookup.ItemPath;
+import com.c2kernel.lookup.Lookup;
import com.c2kernel.lookup.Path;
import com.c2kernel.lookup.RolePath;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.outcome.Outcome;
import com.c2kernel.persistency.outcome.Viewpoint;
+import com.c2kernel.process.resource.DefaultResourceImportHandler;
+import com.c2kernel.process.resource.ResourceImportHandler;
import com.c2kernel.property.Property;
import com.c2kernel.property.PropertyArrayList;
import com.c2kernel.property.PropertyDescription;
@@ -43,6 +47,8 @@ import com.c2kernel.utils.Logger; public class Bootstrap
{
static DomainPath thisServerPath;
+ static HashMap<String, ResourceImportHandler> resHandlerCache = new HashMap<String, ResourceImportHandler>();
+ static HashMap<String, AgentProxy> systemAgents = new HashMap<String, AgentProxy>();
/**
* Run everything without timing-out the service wrapper
@@ -67,7 +73,7 @@ public class Bootstrap Logger.msg("Bootstrap.run() - Initialising Server Item Workflow");
initServerItemWf();
- // register modules
+ Gateway.getModuleManager().setUser(systemAgents.get("system"));
Gateway.getModuleManager().registerModules();
Logger.msg("Bootstrap.run() - Bootstrapping complete");
@@ -98,10 +104,8 @@ public class Bootstrap String itemType = thisItem.substring(0,delim);
String itemName = thisItem.substring(delim+1);
try {
- String data = Gateway.getResource().getTextResource(ns, "boot/"+thisItem+(itemType.equals("OD")?".xsd":".xml"));
- if (data == null)
- Logger.die("No data found for "+getDataType(itemType)+" "+itemName);
- verifyResource(ns, itemName, 0, itemType, data, reset);
+ String location = "boot/"+thisItem+(itemType.equals("OD")?".xsd":".xml");
+ verifyResource(ns, itemName, 0, itemType, location, 0, reset);
} catch (Exception e) {
Logger.error(e);
Logger.die("Error importing bootstrap items. Unsafe to continue.");
@@ -110,122 +114,164 @@ public class Bootstrap }
- public static void verifyResource(String ns, String itemName, Integer version, String itemType, String data, boolean reset) throws Exception {
+ public static DomainPath verifyResource(String ns, String itemName, Integer version, String itemType, String dataLocation, int layer, boolean reset) throws Exception {
if (version == null) version = 0;
- Logger.msg(1, "Bootstrap.verifyResource() - Verifying version "+version+" of "+getDataType(itemType)+" "+itemName);
+ ResourceImportHandler typeImpHandler = getHandler(itemType);
+ Logger.msg(1, "Bootstrap.verifyResource() - Verifying version "+version+" of "+typeImpHandler.getName()+" "+itemName);
- Enumeration<Path> en = Gateway.getLDAPLookup().search(getTypeRoot(itemType), itemName);
+ // Find or create Item for Resource
+ DomainPath modDomPath = typeImpHandler.getPath(itemName, ns);
ItemProxy thisProxy;
- Outcome newOutcome = new Outcome(0, data, getDataType(itemType), 0);
-
- if (!en.hasMoreElements()) {
- Logger.msg("Bootstrap.verifyResource() - "+getDataType(itemType)+" "+itemName+" not found. Creating new.");
- thisProxy = createResourceItem(itemType, itemName, ns);
+ Iterator<Path> 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);
}
else {
- DomainPath path = (DomainPath)en.nextElement();
- thisProxy = (ItemProxy)Gateway.getProxyManager().getProxy(path);
- try {
- Viewpoint currentData = (Viewpoint)thisProxy.getObject(ClusterStorage.VIEWPOINT+"/"+getDataType(itemType)+"/"+version);
+ DomainPath path = (DomainPath)en.next();
+ thisProxy = Gateway.getProxyManager().getProxy(path);
+
+ // Verify module property and location
+
+ String moduleName = (ns==null?"kernel":ns);
+ String itemModule;
+ try{
+ itemModule = thisProxy.getProperty("Module");
+ if (!itemModule.equals("") && !itemModule.equals("null") && !moduleName.equals(itemModule)) {
+ Logger.error("Bootstrap.verifyResource() - Module clash! Resource '"+itemName+"' included in module "+moduleName+" but is assigned to '"+itemModule+"'. Not overwriting.");
+ return path;
+ }
+ } catch (ObjectNotFoundException ex) {
+ itemModule = "";
+ }
+
+ if (!moduleName.equals(itemModule)) { // write module property
+ 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()));
+ if (!modDomPath.exists())
+ Gateway.getLookup().add(modDomPath);
+ Gateway.getLookup().delete(path);
+ }
+ }
+
+ // Verify/Import Outcomes, creating events and views as necessary
+ Set<Outcome> impList = typeImpHandler.getResourceOutcomes(itemName, ns, dataLocation, version);
+ for (Outcome newOutcome : impList) {
+ try {
+ Viewpoint currentData = (Viewpoint)thisProxy.getObject(ClusterStorage.VIEWPOINT+"/"+newOutcome.getSchemaType()+"/"+version);
Outcome oldData = currentData.getOutcome();
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreComments(true);
Diff xmlDiff = new Diff(newOutcome.getDOM(), oldData.getDOM());
if (xmlDiff.identical()) {
Logger.msg(5, "Bootstrap.verifyResource() - Data identical, no update required");
- return;
+ continue;
}
else {
Logger.msg("Difference found in "+itemName+": "+xmlDiff.toString());
if (!reset && !currentData.getEvent().getStepPath().equals("Bootstrap")) {
Logger.msg("Version "+version+" was not set by Bootstrap, and reset not requested. Not overwriting.");
- return;
+ continue;
}
}
} catch (ObjectNotFoundException ex) {
- Logger.error("Bootstrap.verifyResource() - Item "+itemName+" exists but version "+version+" not found! Attempting to insert new.");
+ Logger.msg("Bootstrap.verifyResource() - Item "+itemName+" exists but version "+version+" not found! Attempting to insert new.");
}
+
+ // data was missing or doesn't match
+ Logger.msg("Bootstrap.verifyResource() - Writing new "+newOutcome.getSchemaType()+" v"+version+" to "+typeImpHandler.getName()+" "+itemName);
+ History hist = new History(thisProxy.getSystemKey(), thisProxy);
+ Transition predefDone = new Transition(0, "Done", 0, 0);
+ Event newEvent = hist.addEvent("system", "Admin", "Bootstrap", "Bootstrap", "Bootstrap", newOutcome.getSchemaType(), 0, "PredefinedStep", 0, predefDone, String.valueOf(version));
+ newOutcome.setID(newEvent.getID());
+ Viewpoint newLastView = new Viewpoint(thisProxy.getSystemKey(), newOutcome.getSchemaType(), "last", 0, newEvent.getID());
+ Viewpoint newNumberView = new Viewpoint(thisProxy.getSystemKey(), newOutcome.getSchemaType(), String.valueOf(version), 0, newEvent.getID());
+ Gateway.getStorage().put(thisProxy.getSystemKey(), newOutcome, thisProxy);
+ Gateway.getStorage().put(thisProxy.getSystemKey(), newLastView, thisProxy);
+ Gateway.getStorage().put(thisProxy.getSystemKey(), newNumberView, thisProxy);
}
- // data was missing or doesn't match
- Logger.msg("Bootstrap.verifyResource() - Writing new version "+version+" to "+getDataType(itemType)+" "+itemName);
- History hist = new History(thisProxy.getSystemKey(), thisProxy);
- Transition predefDone = new Transition(0, "Done", 0, 0);
- Event newEvent = hist.addEvent("system", "Admin", "Bootstrap", "Bootstrap", "Bootstrap", getDataType(itemType), 0, "PredefinedStep", 0, predefDone, String.valueOf(version));
- newOutcome.setID(newEvent.getID());
- Viewpoint newLastView = new Viewpoint(thisProxy.getSystemKey(), getDataType(itemType), "last", 0, newEvent.getID());
- Viewpoint newZeroView = new Viewpoint(thisProxy.getSystemKey(), getDataType(itemType), String.valueOf(version), 0, newEvent.getID());
- Gateway.getStorage().put(thisProxy.getSystemKey(), newOutcome, thisProxy);
- Gateway.getStorage().put(thisProxy.getSystemKey(), newLastView, thisProxy);
- Gateway.getStorage().put(thisProxy.getSystemKey(), newZeroView, thisProxy);
- Gateway.getStorage().commit(thisProxy);
+ Gateway.getStorage().commit(thisProxy);
+ return modDomPath;
+ }
+
+ private static ResourceImportHandler getHandler(String resType) throws Exception {
+ if (resHandlerCache.containsKey(resType))
+ return resHandlerCache.get(resType);
+ ResourceImportHandler handler;
+ Object handlerProp = Gateway.getProperties().get("ResourceImportHandler."+resType);
+ if (handlerProp instanceof ResourceImportHandler)
+ handler = (ResourceImportHandler)handlerProp;
+ else if (handlerProp instanceof String) { //class name
+ try {
+ Class<?> handlerClass = Class.forName((String)handlerProp);
+ handler = (ResourceImportHandler) handlerClass.newInstance();
+ } catch (ClassNotFoundException e) {
+ throw new Exception("Handler class "+handlerProp+" for importing "+resType+" resources not found");
+ } catch (ClassCastException e) {
+ throw new Exception(handlerProp+" for importing "+resType+" was not a ResourceImportHandler");
+ }
+ }
+ else
+ handler = new DefaultResourceImportHandler(resType);
+
+ resHandlerCache.put(resType, handler);
+ return handler;
}
- /**
+ /**
* @param itemType
* @param itemName
+ * @param layer
* @param data
*/
- private static ItemProxy createResourceItem(String itemType, String itemName, String ns) throws Exception {
+ private static ItemProxy createResourceItem(ResourceImportHandler impHandler, String itemName, int layer, String ns) throws Exception {
// create props
- PropertyDescriptionList pdList = (PropertyDescriptionList)Gateway.getMarshaller().unmarshall(Gateway.getResource().getTextResource(null, "boot/property/"+itemType+"Prop.xml"));
+ PropertyDescriptionList pdList = impHandler.getPropDesc();
PropertyArrayList props = new PropertyArrayList();
for (int i = 0; i < pdList.list.size(); i++) {
PropertyDescription pd = pdList.list.get(i);
String propName = pd.getName();
- String propVal = propName.equals("Name")?itemName:pd.getDefaultValue();
+ String propVal;
+ if (propName.equals("Name"))
+ propVal = itemName;
+ else if (propName.equals("Layer"))
+ propVal = String.valueOf(layer);
+ else propVal = pd.getDefaultValue();
props.list.add(new Property(propName, propVal, pd.getIsMutable()));
}
CompositeActivity ca = new CompositeActivity();
- if (ns!=null && Gateway.getProperties().getBoolean("Module.debug", false)) {
- String wf;
- if (itemType.equals("CA")) wf = "ManageCompositeActDef";
- else if (itemType.equals("EA")) wf = "ManageElementaryActDef";
- else if (itemType.equals("OD")) wf = "ManageSchema";
- else if (itemType.equals("SC")) wf = "ManageScript";
- else throw new Exception("Unknown bootstrap item type: "+itemType);
- ca = (CompositeActivity) ((CompositeActivityDef)LocalObjectLoader.getActDef(wf, 0)).instantiate();
- }
-
- EntityPath entityPath = Gateway.getLDAPLookup().getNextKeyManager().generateNextEntityKey();
- TraceableEntity newItem = (TraceableEntity)Gateway.getCorbaServer().createEntity(entityPath);
- Gateway.getLDAPLookup().add(entityPath);
- newItem.initialise(
- 1,
- Gateway.getMarshaller().marshall(props),
- Gateway.getMarshaller().marshall(ca));
- DomainPath newDomPath = new DomainPath(getTypeRoot(itemType).toString()+"/system/"+(ns==null?"kernel":ns)+"/"+itemName);
- newDomPath.setEntity(entityPath);
- Gateway.getLDAPLookup().add(newDomPath);
- return (ItemProxy)Gateway.getProxyManager().getProxy(entityPath);
- }
-
- public static DomainPath getTypeRoot(String type) throws Exception {
- if (type.equals("CA") || type.equals("EA"))
- return new DomainPath("/desc/ActivityDesc/");
- if (type.equals("SC"))
- return new DomainPath("/desc/Script/");
- if (type.equals("OD"))
- return new DomainPath("/desc/OutcomeDesc/");
- if (type.equals("SM"))
- return new DomainPath("/desc/StateMachine");
- throw new Exception("Unknown bootstrap item type: "+type);
- }
+ if (ns!=null && Gateway.getProperties().getBoolean("Module.debug", false))
+ try {
+ ca = (CompositeActivity) ((CompositeActivityDef)LocalObjectLoader.getActDef(impHandler.getWorkflowName(), 0)).instantiate();
+ } catch (ObjectNotFoundException ex) {
+ Logger.error("Module resource workflow "+impHandler.getWorkflowName()+" not found. Using empty.");
+ }
- private static String getDataType(String type) throws Exception {
- if (type.equals("CA"))
- return "CompositeActivityDef";
- if (type.equals("EA"))
- return "ElementaryActivityDef";
- if (type.equals("OD"))
- return "Schema";
- if (type.equals("SC"))
- return "Script";
- if (type.equals("SM"))
- return "StateMachine";
- throw new Exception("Unknown bootstrap item type: "+type);
+ ItemPath entityPath = Gateway.getNextKeyManager().generateNextEntityKey();
+ Gateway.getCorbaServer().createEntity(entityPath);
+ Gateway.getLookup().add(entityPath);
+ DomainPath newDomPath = impHandler.getPath(itemName, ns);
+ newDomPath.setEntity(entityPath);
+ Gateway.getLookup().add(newDomPath);
+ ItemProxy newItemProxy = Gateway.getProxyManager().getProxy(entityPath);
+ newItemProxy.initialise( 1, props, ca, null);
+ return newItemProxy;
}
/**************************************************************************
@@ -233,9 +279,9 @@ public class Bootstrap **************************************************************************/
private static void checkAgent(String name, String pass, String role, boolean joblist) throws Exception {
Logger.msg(1, "Bootstrap.checkAgent() - Checking for existence of '"+name+"' user.");
- LDAPLookup lookup = Gateway.getLDAPLookup();
+ Lookup lookup = Gateway.getLookup();
try {
- lookup.getRoleManager().getAgentPath(name);
+ systemAgents.put(name, Gateway.getProxyManager().getAgentProxy(lookup.getAgentPath(name)));
Logger.msg(3, "Bootstrap.checkAgent() - User '"+name+"' found.");
return;
} catch (ObjectNotFoundException ex) { }
@@ -243,23 +289,24 @@ public class Bootstrap RolePath rolePath;
try {
- rolePath = lookup.getRoleManager().getRolePath(role);
+ rolePath = lookup.getRolePath(role);
} catch (ObjectNotFoundException ex) {
- rolePath = lookup.getRoleManager().createRole(role, joblist);
+ rolePath = lookup.createRole(role, joblist);
}
try {
- EntityPath entityPath = lookup.getNextKeyManager().generateNextEntityKey();
+ ItemPath entityPath = Gateway.getNextKeyManager().generateNextEntityKey();
AgentPath agentPath = new AgentPath(entityPath.getSysKey(), name);
agentPath.setPassword(pass);
Gateway.getCorbaServer().createEntity(agentPath);
- Gateway.getLDAPLookup().add(agentPath);
+ Gateway.getLookup().add(agentPath);
// assign admin role
Logger.msg("Bootstrap.checkAgent() - Assigning role '"+role+"'");
rolePath.addAgent(agentPath);
Gateway.getStorage().put(agentPath.getSysKey(), new Property("Name", name, true), null);
Gateway.getStorage().put(agentPath.getSysKey(), new Property("Type", "Agent", false), null);
+ systemAgents.put(name, Gateway.getProxyManager().getAgentProxy(agentPath));
Logger.msg("Bootstrap.checkAgent() - Done");
} catch (Exception ex) {
Logger.error("Unable to create "+name+" user.");
@@ -286,16 +333,16 @@ public class Bootstrap public static void createServerItem() throws Exception {
String serverName = Gateway.getProperties().getProperty("ItemServer.name");
thisServerPath = new DomainPath("/servers/"+serverName);
- EntityPath serverEntity;
+ ItemPath serverEntity;
try {
serverEntity = thisServerPath.getEntity();
} catch (ObjectNotFoundException ex) {
Logger.msg("Creating server item "+thisServerPath);
- serverEntity = Gateway.getLDAPLookup().getNextKeyManager().generateNextEntityKey();
+ serverEntity = Gateway.getNextKeyManager().generateNextEntityKey();
Gateway.getCorbaServer().createEntity(serverEntity);
- Gateway.getLDAPLookup().add(serverEntity);
+ Gateway.getLookup().add(serverEntity);
thisServerPath.setEntity(serverEntity);
- Gateway.getLDAPLookup().add(thisServerPath);
+ Gateway.getLookup().add(thisServerPath);
}
Gateway.getStorage().put(serverEntity.getSysKey(), new Property("Name", serverName, false), null);
Gateway.getStorage().put(serverEntity.getSysKey(), new Property("Type", "Server", false), null);
@@ -315,7 +362,7 @@ public class Bootstrap PredefinedStepContainer predef = (PredefinedStepContainer)wf.search("workflow/predefined");
wf.getChildGraphModel().removeVertex(predef);
wf.addChild(new ServerPredefinedStepContainer(), predef.getCentrePoint());
- wf.initialise(thisServerPath.getSysKey(), Gateway.getLDAPLookup().getRoleManager().getAgentPath("system"));
+ wf.initialise(thisServerPath.getSysKey(), systemAgents.get("system").getPath());
Gateway.getStorage().put(thisServerPath.getSysKey(), wf, null);
}
}
diff --git a/src/main/java/com/c2kernel/process/ClientShell.java b/src/main/java/com/c2kernel/process/ClientShell.java index 6a620d8..b6afb2c 100644 --- a/src/main/java/com/c2kernel/process/ClientShell.java +++ b/src/main/java/com/c2kernel/process/ClientShell.java @@ -3,7 +3,7 @@ package com.c2kernel.process; import java.util.Scanner;
import com.c2kernel.entity.proxy.AgentProxy;
-import com.c2kernel.process.auth.Authenticator;
+import com.c2kernel.process.auth.ProxyLogin;
import com.c2kernel.scripting.Script;
public class ClientShell extends StandardClient {
@@ -40,7 +40,7 @@ public class ClientShell extends StandardClient { Gateway.init(readC2KArgs(args));
String authClassName = Gateway.getProperties().getProperty("cli.auth");
Class<?> authClass = Gateway.getResource().getClassForName(authClassName);
- Authenticator auth = (Authenticator)authClass.newInstance();
+ ProxyLogin auth = (ProxyLogin)authClass.newInstance();
AgentProxy user = auth.authenticate(Gateway.getProperties().getProperty("Name"));
ClientShell shell = new ClientShell(user);
shell.run();
diff --git a/src/main/java/com/c2kernel/process/Gateway.java b/src/main/java/com/c2kernel/process/Gateway.java index 0d9dbe6..2db7aa1 100644 --- a/src/main/java/com/c2kernel/process/Gateway.java +++ b/src/main/java/com/c2kernel/process/Gateway.java @@ -13,12 +13,14 @@ import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.CorbaServer;
import com.c2kernel.entity.proxy.AgentProxy;
-import com.c2kernel.entity.proxy.EntityProxyManager;
+import com.c2kernel.entity.proxy.ProxyManager;
+import com.c2kernel.entity.proxy.ProxyServer;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.LDAPLookup;
-import com.c2kernel.lookup.LDAPProperties;
+import com.c2kernel.lookup.Lookup;
import com.c2kernel.persistency.ClusterStorageException;
+import com.c2kernel.persistency.NextKeyManager;
import com.c2kernel.persistency.TransactionManager;
+import com.c2kernel.process.auth.Authenticator;
import com.c2kernel.process.module.ModuleManager;
import com.c2kernel.process.resource.Resource;
import com.c2kernel.process.resource.ResourceLoader;
@@ -36,7 +38,7 @@ import com.c2kernel.utils.ObjectProperties; *
* Child objects:
* <ul>
- * <li>LDAPLookup - Provides access to the CRISTAL directory. Find or
+ * <li>Lookup - Provides access to the CRISTAL directory. Find or
* search for Items or Agents.
* <li>EntityProxyManager - Gives a local proxy object for Entities found
* in LDAP. Execute activities in Items, query or subscribe to Entity data.
@@ -55,12 +57,13 @@ public class Gateway static private ModuleManager mModules;
static private org.omg.CORBA.ORB mORB;
static private boolean orbDestroyed = false;
- static private LDAPLookup mLDAPLookup;
+ static private Lookup mLookup;
+ static private NextKeyManager mNextKeyManager;
static private TransactionManager mStorage;
- static private EntityProxyManager mProxyManager;
+ static private ProxyManager mProxyManager;
+ static private ProxyServer mProxyServer;
static private CorbaServer mCorbaServer;
static private CastorXMLUtility mMarshaller;
- static private AgentProxy mCurrentUser = null;
static private ResourceLoader mResource;
@@ -69,7 +72,7 @@ public class Gateway /**
* Initialises the Gateway and all of the client objects it holds, with
- * the exception of the LDAPLookup, which is initialised during connect()
+ * the exception of the Lookup, which is initialised during connect()
*
* @param props - java.util.Properties containing all application properties.
* If null, the java system properties are used
@@ -81,7 +84,7 @@ public class Gateway /**
* Initialises the Gateway and all of the client objects it holds, with
- * the exception of the LDAPLookup, which is initialised during connect()
+ * the exception of the Lookup, which is initialised during connect()
*
* @param props - java.util.Properties containing all application properties.
* If null, the java system properties are used
@@ -108,7 +111,7 @@ public class Gateway // init module manager
try {
- mModules = new ModuleManager(ClassLoader.getSystemResources("META-INF/cristal/module.xml"), AbstractMain.runningAsWrapper);
+ mModules = new ModuleManager(mResource.getModuleDefURLs(), AbstractMain.runningAsWrapper);
} catch (Exception e) {
Logger.error(e);
throw new InvalidDataException("Could not load module definitions.", "");
@@ -133,9 +136,6 @@ public class Gateway Language.isTranlated=true;
Language.mTableOfTranslation = FileStringUtility.loadLanguageFile(languageFile);
}
-
- // if client, run module startup scripts. Otherwise bootstrap will do it after all imports
- if (!AbstractMain.runningAsWrapper) mModules.runScripts("startup");
}
/**
@@ -147,17 +147,20 @@ public class Gateway */
static public void startServer() throws InvalidDataException {
try {
- // check top level LDAP contexts
- mLDAPLookup.install();
+ // check top level directory contexts
+ mLookup.initializeDirectory();
+ // init next key manager
+ mNextKeyManager = (NextKeyManager)mC2KProps.getInstance("NextKeyManager");
+
// start entity proxy server
- EntityProxyManager.initServer();
+ mProxyServer = new ProxyServer(mC2KProps.getProperty("ItemServer.name"));
// Init ORB - set various config
- String serverName = getProperty("ItemServer.name");
+ String serverName = mC2KProps.getProperty("ItemServer.name");
if (serverName != null)
mC2KProps.put("com.sun.CORBA.ORBServerHost", serverName);
- String serverPort = getProperty("ItemServer.iiop", "1500");
+ String serverPort = mC2KProps.getProperty("ItemServer.iiop", "1500");
mC2KProps.put("com.sun.CORBA.ORBServerPort", serverPort);
//TODO: externalize this (or replace corba completely)
mC2KProps.put("com.sun.CORBA.POA.ORBServerId", "1");
@@ -197,140 +200,59 @@ public class Gateway throws InvalidDataException,
ClusterStorageException
{
- LDAPProperties ldapProps = new LDAPProperties();
-
- if( ldapProps.mHost != null && ldapProps.mPort != null &&
- ldapProps.mUser != null && ldapProps.mPassword != null )
- {
- try
- {
- mLDAPLookup = new LDAPLookup(ldapProps);
- }
- catch (Exception ex)
- {
- Logger.error(ex);
- throw new InvalidDataException("Cannot authenticate. Name and/or password invalid.", "");
- }
- }
- else
- {
- Logger.error("LDAP properties not set for server login.");
- throw new InvalidDataException("Cannot authenticate with LDAP.", "");
- }
-
- setup();
- }
-
- /**
- * Authenticates a user and returns and AgentProxy on them without overriding the system LDAP context.
- * Useful for handling multiple users in one context e.g. on a web server
- *
- * @param agentName - username
- * @param agentPassword - password
- * @return AgentProxy on that user
- * @throws InvalidDataException
- * @throws ObjectNotFoundException
- */
- static public AgentProxy login(String agentName, String agentPassword) throws InvalidDataException, ObjectNotFoundException {
- LDAPProperties ldapProps = new LDAPProperties();
- AgentPath agentPath;
- try {
- agentPath = mLDAPLookup.getRoleManager().getAgentPath(agentName);
- } catch (Exception ex) {
+ try {
+ Authenticator auth = (Authenticator)mC2KProps.getInstance("Authenticator");
+ auth.authenticate("System");
+
+ mLookup = (Lookup)mC2KProps.getInstance("Lookup");
+ mLookup.open(auth);
+
+ mStorage = new TransactionManager(auth);
+ mProxyManager = new ProxyManager();
+
+ } catch (Exception ex) {
Logger.error(ex);
- throw new ObjectNotFoundException("Could not resolve agent", "");
+ throw new InvalidDataException("Cannot connect server process. Please check config.", "");
}
- String agentDN = agentPath.getFullDN();
- ldapProps.mUser = agentDN;
- ldapProps.mPassword = agentPassword;
- try {
- LDAPLookup.createConnection(ldapProps);
- return (AgentProxy)getProxyManager().getProxy(mLDAPLookup.getRoleManager().getAgentPath(agentName));
- } catch (Exception ex) {
- Logger.error(ex);
- throw new InvalidDataException("Could not log in", "");
- }
- }
+ }
/**
- * Logs into the LDAP server with the given username and password, and initialises the lookup.
+ * Logs in with the given username and password, and initialises the lookup, storage and proxy manager.
*
* @param agentName - username
* @param agentPassword - password
* @return an AgentProxy on the requested user
* @throws InvalidDataException
+ * @throws ClusterStorageException
+ * @throws ClassNotFoundException
+ * @throws IllegalAccessException
+ * @throws InstantiationException
*/
- static public AgentProxy connect(String agentName, String agentPassword)
- throws InvalidDataException, ObjectNotFoundException
- {
-
- LDAPProperties ldapProps = new LDAPProperties();
- if (ldapProps.mHost!=null && ldapProps.mPort!= null && ldapProps.mLocalPath!=null )
- {
- try {
- ldapProps.mUser = "";
- ldapProps.mPassword = "";
- mLDAPLookup = new LDAPLookup(ldapProps);
- String agentDN = mLDAPLookup.getRoleManager().getAgentPath(agentName).getFullDN();
-
- //found agentDN, try to log in with it
- ldapProps.mUser = agentDN;
- ldapProps.mPassword = agentPassword;
- mLDAPLookup = new LDAPLookup(ldapProps);
-
- // find agent proxy
- AgentPath agentPath = mLDAPLookup.getRoleManager().getAgentPath(agentName);
-
- if (agentPath!=null)
- {
- setup();
- mCurrentUser = (AgentProxy) mProxyManager.getProxy(agentPath);
- return mCurrentUser;
- }
- else
- {
- throw new InvalidDataException("The agentDN " +agentDN+ " is invalid.", "");
- }
- } catch (ClusterStorageException e) {
- throw new InvalidDataException(Language.translate("Error initialising storage")+Language.translate(". See log."), "");
- } catch (ObjectNotFoundException e) {
- throw new ObjectNotFoundException(Language.translate("Invalid username/password"), "");
- } catch (Exception e) {
- throw new InvalidDataException(Language.translate("Could not log in")+": "+Language.translate(e.getMessage()), "");
- }
-
- }
- else
- {
- throw new InvalidDataException("Cannot log in. Some connection properties are not set.", "");
- }
-
- }
-
- /**
- * @return the mCurrentUser
- */
- public static AgentProxy getCurrentUser() {
- return mCurrentUser;
- }
-
- /**
- * Initializes the storage and proxy manager, called during connect.
- *
- * @throws InvalidDataException
- * @throws ClusterStorageException
- */
- static private void setup()
- throws InvalidDataException,
- ClusterStorageException
+ static public AgentProxy connect(String agentName, String agentPassword, String resource)
+ throws InvalidDataException, ObjectNotFoundException, ClusterStorageException, InstantiationException, IllegalAccessException, ClassNotFoundException
{
+ Authenticator auth = (Authenticator)mC2KProps.getInstance("Authenticator");
+ if (!auth.authenticate(agentName, agentPassword, resource))
+ throw new InvalidDataException("Login failed", "");
+
+ mLookup = (Lookup)mC2KProps.getInstance("Lookup");
+ mLookup.open(auth);
- // Init storages
- mStorage = new TransactionManager();
- mProxyManager = new EntityProxyManager();
+ mStorage = new TransactionManager(auth);
+ mProxyManager = new ProxyManager();
+ // find agent proxy
+ AgentPath agentPath = mLookup.getAgentPath(agentName);
+ AgentProxy userProxy = (AgentProxy) mProxyManager.getProxy(agentPath);
+ userProxy.setAuthObj(auth);
+
+ // Run module startup scripts. Server does this during bootstrap
+ mModules.setUser(userProxy);
+ mModules.runScripts("startup");
+
+ return userProxy;
}
/**
@@ -352,15 +274,17 @@ public class Gateway mStorage = null;
// disconnect from ldap
- if (mLDAPLookup != null)
- mLDAPLookup.disconnect();
- mLDAPLookup = null;
+ if (mLookup != null)
+ mLookup.close();
+ mLookup = null;
- // shut down proxy manager
+ // shut down proxy manager & server
+ if (mProxyServer != null)
+ mProxyServer.shutdownServer();
if (mProxyManager != null)
mProxyManager.shutdown();
mProxyManager = null;
- EntityProxyManager.shutdownServer();
+
// close log consoles
Logger.closeConsole();
@@ -380,9 +304,9 @@ public class Gateway return mORB;
}
- static public LDAPLookup getLDAPLookup()
+ static public Lookup getLookup()
{
- return mLDAPLookup;
+ return mLookup;
}
static public CorbaServer getCorbaServer()
@@ -405,11 +329,16 @@ public class Gateway return mResource;
}
- static public EntityProxyManager getProxyManager()
+ static public ProxyManager getProxyManager()
{
return mProxyManager;
}
+
+ public static ProxyServer getProxyServer() {
+ return mProxyServer;
+ }
+
static public String getCentreId() {
return getProperty("LocalCentre");
}
@@ -437,11 +366,7 @@ public class Gateway static public void dumpC2KProps(int logLevel) {
if (!Logger.doLog(logLevel)) return;
- Logger.msg(logLevel, "C2K Properties:");
- for (Enumeration<?> e = propertyNames(); e.hasMoreElements();) {
- String name = (String) e.nextElement();
- Logger.msg(" "+name+": "+getProperty(name));
- }
+ mC2KProps.dumpProps(logLevel);
}
static public ObjectProperties getProperties() {
@@ -456,5 +381,9 @@ public class Gateway }
}
+
+ public static NextKeyManager getNextKeyManager() {
+ return mNextKeyManager;
+ }
}
diff --git a/src/main/java/com/c2kernel/process/StandardServer.java b/src/main/java/com/c2kernel/process/StandardServer.java index 546aaa5..e283cb6 100644 --- a/src/main/java/com/c2kernel/process/StandardServer.java +++ b/src/main/java/com/c2kernel/process/StandardServer.java @@ -72,7 +72,7 @@ public class StandardServer extends AbstractMain implements WrapperListener }
catch( Exception ex )
{
- Logger.error(ex);
+ ex.printStackTrace();
Logger.die("Startup failed");
}
return null;
diff --git a/src/main/java/com/c2kernel/process/UserCodeProcess.java b/src/main/java/com/c2kernel/process/UserCodeProcess.java index f7bbe74..0d35025 100644 --- a/src/main/java/com/c2kernel/process/UserCodeProcess.java +++ b/src/main/java/com/c2kernel/process/UserCodeProcess.java @@ -9,8 +9,8 @@ import com.c2kernel.common.InvalidTransitionException; import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.entity.agent.Job;
import com.c2kernel.entity.proxy.AgentProxy;
-import com.c2kernel.entity.proxy.EntityProxyObserver;
import com.c2kernel.entity.proxy.MemberSubscription;
+import com.c2kernel.entity.proxy.ProxyObserver;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.scripting.ErrorInfo;
import com.c2kernel.scripting.ScriptErrorException;
@@ -24,7 +24,7 @@ import com.c2kernel.utils.Logger; * Copyright (C) 2003 CERN - European Organization for Nuclear Research
* All rights reserved.
**************************************************************************/
-public class UserCodeProcess extends StandardClient implements EntityProxyObserver<Job>, Runnable {
+public class UserCodeProcess extends StandardClient implements ProxyObserver<Job>, Runnable {
// Default state machine transitions
private static final int START = 1;
@@ -38,12 +38,12 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv HashMap<String, ErrorInfo> errors = new HashMap<String, ErrorInfo>();
HashMap<String, C2KLocalObject> jobs;
- public UserCodeProcess(String agentName, String agentPass) {
+ public UserCodeProcess(String agentName, String agentPass, String resource) {
// login - try for a while in case server hasn't imported our user yet
for (int i=1;i<6;i++) {
try {
Logger.msg("Login attempt "+i+" of 5");
- agent = Gateway.connect(agentName, agentPass);
+ agent = Gateway.connect(agentName, agentPass, resource);
break;
} catch (Exception ex) {
Logger.error("Could not log in.");
@@ -209,7 +209,7 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv }
public static UserCodeProcess getInstance() throws UnknownHostException {
- return new UserCodeProcess(InetAddress.getLocalHost().getHostName(), "uc");
+ return new UserCodeProcess(InetAddress.getLocalHost().getHostName(), "uc", Gateway.getProperties().getProperty("AuthResource", "Cristal"));
}
static public void main(String[] args)
diff --git a/src/main/java/com/c2kernel/process/auth/Authenticator.java b/src/main/java/com/c2kernel/process/auth/Authenticator.java index ae18474..40defc4 100644 --- a/src/main/java/com/c2kernel/process/auth/Authenticator.java +++ b/src/main/java/com/c2kernel/process/auth/Authenticator.java @@ -1,12 +1,16 @@ package com.c2kernel.process.auth;
-import java.util.Properties;
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.entity.proxy.AgentProxy;
public interface Authenticator {
-
- public void initialize(Properties props) throws Exception;
- public AgentProxy authenticate(String resource) throws Exception;
+ public boolean authenticate(String agentName, String password, String resource) throws InvalidDataException, ObjectNotFoundException;
+
+ public boolean authenticate(String resource) throws InvalidDataException, ObjectNotFoundException;
+
+ public Object getAuthObject();
+
+ public void disconnect();
}
diff --git a/src/main/java/com/c2kernel/process/auth/ConsoleAuth.java b/src/main/java/com/c2kernel/process/auth/ConsoleAuth.java index a6af253..531540d 100644 --- a/src/main/java/com/c2kernel/process/auth/ConsoleAuth.java +++ b/src/main/java/com/c2kernel/process/auth/ConsoleAuth.java @@ -6,7 +6,7 @@ import java.util.Scanner; import com.c2kernel.entity.proxy.AgentProxy;
import com.c2kernel.process.Gateway;
-public class ConsoleAuth implements Authenticator {
+public class ConsoleAuth implements ProxyLogin {
public ConsoleAuth() {
}
@@ -27,7 +27,7 @@ public class ConsoleAuth implements Authenticator { System.out.print("Password:");
String pass = scan.nextLine();
try {
- user = Gateway.connect(username, pass);
+ user = Gateway.connect(username, pass, resource);
} catch (Exception ex) {
System.err.println(ex.getMessage());
}
diff --git a/src/main/java/com/c2kernel/process/auth/ProxyLogin.java b/src/main/java/com/c2kernel/process/auth/ProxyLogin.java new file mode 100644 index 0000000..94416cf --- /dev/null +++ b/src/main/java/com/c2kernel/process/auth/ProxyLogin.java @@ -0,0 +1,12 @@ +package com.c2kernel.process.auth;
+
+import java.util.Properties;
+
+import com.c2kernel.entity.proxy.AgentProxy;
+
+public interface ProxyLogin {
+
+ public void initialize(Properties props) throws Exception;
+ public AgentProxy authenticate(String resource) throws Exception;
+
+}
diff --git a/src/main/java/com/c2kernel/process/module/Module.java b/src/main/java/com/c2kernel/process/module/Module.java index fda4b1b..873754f 100644 --- a/src/main/java/com/c2kernel/process/module/Module.java +++ b/src/main/java/com/c2kernel/process/module/Module.java @@ -4,13 +4,15 @@ import java.util.ArrayList; import java.util.Properties;
import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.entity.imports.ImportDependency;
+import com.c2kernel.entity.imports.ImportDependencyMember;
+import com.c2kernel.entity.imports.ImportAgent;
+import com.c2kernel.entity.imports.ImportItem;
+import com.c2kernel.entity.imports.ImportRole;
+import com.c2kernel.entity.imports.ImportOutcome;
+import com.c2kernel.entity.proxy.AgentProxy;
import com.c2kernel.entity.proxy.ItemProxy;
-import com.c2kernel.lifecycle.instance.predefined.entitycreation.Dependency;
-import com.c2kernel.lifecycle.instance.predefined.entitycreation.DependencyMember;
-import com.c2kernel.lifecycle.instance.predefined.entitycreation.NewAgent;
-import com.c2kernel.lifecycle.instance.predefined.entitycreation.NewItem;
-import com.c2kernel.lifecycle.instance.predefined.entitycreation.NewRole;
-import com.c2kernel.lifecycle.instance.predefined.entitycreation.Outcome;
+import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.RolePath;
import com.c2kernel.process.Bootstrap;
import com.c2kernel.process.Gateway;
@@ -26,17 +28,17 @@ public class Module { public ModuleImports imports = new ModuleImports();
public ArrayList<ModuleConfig> config = new ArrayList<ModuleConfig>();
public ArrayList<ModuleScript> scripts = new ArrayList<ModuleScript>();
- public NewItem moduleItem;
+ public ImportItem moduleItem;
public Module() {
super();
}
- public void runScript(String event, boolean isServer) throws ScriptingEngineException {
+ public void runScript(String event, AgentProxy user, boolean isServer) throws ScriptingEngineException {
for (ModuleScript script : scripts) {
if (script.shouldRun(event, isServer)) {
Logger.msg("Running "+script.event+" "+script.target+" script from "+name);
- Object result = script.getScript(ns).execute();
+ Object result = script.getScript(ns, user).execute();
if (result instanceof ErrorInfo) {
ErrorInfo error = (ErrorInfo) result;
Logger.error(error.toString());
@@ -50,44 +52,45 @@ public class Module { }
public void addModuleItem(String moduleXML) {
- NewItem moduleItem = new NewItem(name, "/desc/modules/", "ModuleWorkflow");
+ ImportItem moduleItem = new ImportItem(name, "/desc/modules/", "NoWorkflow", 0);
// Module properties
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
- Dependency children = new Dependency("Contents");
+ ImportDependency children = new ImportDependency("Contents");
for (ModuleImport thisImport : imports.list) {
- String path = thisImport.getPath(ns);
+ DomainPath path = thisImport.path;
if (path != null)
- children.dependencyMemberList.add(
- new DependencyMember(path+"/"+thisImport.name));
+ children.dependencyMemberList.add(new ImportDependencyMember(path.toString()));
}
moduleItem.dependencyList.add(children);
// Add moduleXML
- Outcome moduleOutcome = new Outcome("Module", 0, "last", null);
+ ImportOutcome moduleOutcome = new ImportOutcome("Module", 0, "last", null);
moduleOutcome.data = moduleXML;
moduleItem.outcomes.add(moduleOutcome);
imports.list.add(moduleItem);
}
- public void importAll(ItemProxy serverEntity, String moduleXML, boolean reset) throws Exception {
+ public void importAll(ItemProxy serverEntity, AgentProxy systemAgent, String moduleXML, boolean reset) throws Exception {
+ int systemAgentId = systemAgent.getSystemKey();
addModuleItem(moduleXML);
- int systemAgentId = Gateway.getLDAPLookup().getRoleManager().getAgentPath("system").getSysKey();
for (ModuleResource thisRes : imports.getResources()) {
try {
- Bootstrap.verifyResource(ns, thisRes.name, thisRes.version, thisRes.resourceType, Gateway.getResource().getTextResource(ns, thisRes.resourceLocation), reset);
+ thisRes.path = Bootstrap.verifyResource(ns, thisRes.name, thisRes.version,
+ thisRes.resourceType, thisRes.resourceLocation, info.layer, reset);
} catch (Exception ex) {
Logger.error(ex);
}
}
- for (NewRole thisRole : imports.getRoles()) {
+ for (ImportRole thisRole : imports.getRoles()) {
RolePath rolePath;
try {
- rolePath = Gateway.getLDAPLookup().getRoleManager().getRolePath(thisRole.name);
+ rolePath = Gateway.getLookup().getRolePath(thisRole.name);
if (rolePath.hasJobList() != thisRole.jobList) {
Logger.msg("Module.importAll() - Role '"+thisRole.name+"' has incorrect joblist settings. Correcting.");
rolePath.setHasJobList(thisRole.jobList);
@@ -98,9 +101,9 @@ public class Module { }
}
- for (NewAgent thisAgent : imports.getAgents()) {
+ for (ImportAgent thisAgent : imports.getAgents()) {
try {
- Gateway.getLDAPLookup().getRoleManager().getAgentPath(thisAgent.name);
+ Gateway.getLookup().getAgentPath(thisAgent.name);
Logger.msg(3, "Module.importAll() - User '"+thisAgent.name+"' found.");
continue;
} catch (ObjectNotFoundException ex) { }
@@ -108,7 +111,7 @@ public class Module { thisAgent.create(systemAgentId);
}
- for (NewItem thisItem : imports.getItems()) {
+ for (ImportItem thisItem : imports.getItems()) {
thisItem.setNamespace(ns);
thisItem.create(systemAgentId, reset);
}
diff --git a/src/main/java/com/c2kernel/process/module/ModuleImport.java b/src/main/java/com/c2kernel/process/module/ModuleImport.java index 77bf3f6..1f5b16d 100644 --- a/src/main/java/com/c2kernel/process/module/ModuleImport.java +++ b/src/main/java/com/c2kernel/process/module/ModuleImport.java @@ -1,9 +1,10 @@ package com.c2kernel.process.module;
+import com.c2kernel.lookup.DomainPath;
+
public abstract class ModuleImport {
public String name;
+ public DomainPath path;
- public abstract String getPath(String ns);
-
}
\ No newline at end of file diff --git a/src/main/java/com/c2kernel/process/module/ModuleImports.java b/src/main/java/com/c2kernel/process/module/ModuleImports.java index 5dfde42..e0ddd90 100644 --- a/src/main/java/com/c2kernel/process/module/ModuleImports.java +++ b/src/main/java/com/c2kernel/process/module/ModuleImports.java @@ -2,9 +2,9 @@ package com.c2kernel.process.module; import java.util.ArrayList;
-import com.c2kernel.lifecycle.instance.predefined.entitycreation.NewAgent;
-import com.c2kernel.lifecycle.instance.predefined.entitycreation.NewItem;
-import com.c2kernel.lifecycle.instance.predefined.entitycreation.NewRole;
+import com.c2kernel.entity.imports.ImportAgent;
+import com.c2kernel.entity.imports.ImportItem;
+import com.c2kernel.entity.imports.ImportRole;
import com.c2kernel.utils.CastorArrayList;
public class ModuleImports extends CastorArrayList<ModuleImport> {
@@ -28,29 +28,29 @@ public class ModuleImports extends CastorArrayList<ModuleImport> { return subset;
}
- public ArrayList<NewItem> getItems() {
- ArrayList<NewItem> subset = new ArrayList<NewItem>();
+ public ArrayList<ImportItem> getItems() {
+ ArrayList<ImportItem> subset = new ArrayList<ImportItem>();
for (ModuleImport imp : list) {
- if (imp instanceof NewItem)
- subset.add((NewItem)imp);
+ if (imp instanceof ImportItem)
+ subset.add((ImportItem)imp);
}
return subset;
}
- public ArrayList<NewAgent> getAgents() {
- ArrayList<NewAgent> subset = new ArrayList<NewAgent>();
+ public ArrayList<ImportAgent> getAgents() {
+ ArrayList<ImportAgent> subset = new ArrayList<ImportAgent>();
for (ModuleImport imp : list) {
- if (imp instanceof NewAgent)
- subset.add((NewAgent)imp);
+ if (imp instanceof ImportAgent)
+ subset.add((ImportAgent)imp);
}
return subset;
}
- public ArrayList<NewRole> getRoles() {
- ArrayList<NewRole> subset = new ArrayList<NewRole>();
+ public ArrayList<ImportRole> getRoles() {
+ ArrayList<ImportRole> subset = new ArrayList<ImportRole>();
for (ModuleImport imp : list) {
- if (imp instanceof NewRole)
- subset.add((NewRole)imp);
+ if (imp instanceof ImportRole)
+ subset.add((ImportRole)imp);
}
return subset;
}
diff --git a/src/main/java/com/c2kernel/process/module/ModuleInfo.java b/src/main/java/com/c2kernel/process/module/ModuleInfo.java index 55e02c9..646a915 100644 --- a/src/main/java/com/c2kernel/process/module/ModuleInfo.java +++ b/src/main/java/com/c2kernel/process/module/ModuleInfo.java @@ -6,6 +6,7 @@ public class ModuleInfo { public String desc;
public String version;
+ public int layer = 0;
public ArrayList<String> dependency = new ArrayList<String>();
public ModuleInfo() {
diff --git a/src/main/java/com/c2kernel/process/module/ModuleManager.java b/src/main/java/com/c2kernel/process/module/ModuleManager.java index 3cb4904..6a69ff8 100644 --- a/src/main/java/com/c2kernel/process/module/ModuleManager.java +++ b/src/main/java/com/c2kernel/process/module/ModuleManager.java @@ -9,6 +9,7 @@ import java.util.Properties; import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.entity.proxy.AgentProxy;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.persistency.outcome.OutcomeValidator;
@@ -22,6 +23,7 @@ public class ModuleManager { ArrayList<Module> modules = new ArrayList<Module>();
HashMap<String, String> modulesXML = new HashMap<String, String>();
Properties props = new Properties();
+ AgentProxy user;
boolean isServer;
OutcomeValidator moduleValidator;
@@ -54,11 +56,6 @@ public class ModuleManager { if (moduleNs.contains(newModule.getNs())) throw new ModuleException("Module namespace clash: "+newModule.getNs());
Logger.debug(4, "Module found: "+newModule.getNs()+" - "+newModule.getName());
loadedModules.add(newModule.getName()); moduleNs.add(newModule.getNs());
- Properties modProp = newModule.getProperties(isServer);
- for (Enumeration<?> e = modProp.propertyNames(); e.hasMoreElements();) {
- String propName = (String)e.nextElement();
- props.put(propName, modProp.get(propName));
- }
} catch (ModuleException e) {
Logger.error("Could not load module description from "+newModuleURL);
throw e;
@@ -69,7 +66,7 @@ public class ModuleManager { }
Logger.debug(5, "Checking dependencies");
- boolean allDepsPresent = false;
+ boolean allDepsPresent = true;
ArrayList<String> prevModules = new ArrayList<String>();
for (int i=0; i<modules.size();i++) {
@@ -84,7 +81,7 @@ public class ModuleManager { Logger.msg(6, thisMod.getName()+" depends on "+dep);
if (!loadedModules.contains(dep)) {
Logger.error("UNMET MODULE DEPENDENCY: "+thisMod.getName()+" requires "+dep);
- allDepsPresent = true;
+ allDepsPresent = false;
}
else if (!prevModules.contains(dep)) {
Logger.msg(1, "ModuleManager: Shuffling "+thisMod.getName()+" to the end to fulfil dependency on "+dep);
@@ -104,9 +101,19 @@ public class ModuleManager { Logger.die("Circular module dependencies involving: "+badMod);
}
}
+ // Current module is 'next', this is the correct order to load the properties
+ Properties modProp = thisMod.getProperties(isServer);
+ for (Enumeration<?> e = modProp.propertyNames(); e.hasMoreElements();) {
+ String propName = (String)e.nextElement();
+ props.put(propName, modProp.get(propName));
+ }
prevModules.add(thisMod.getName());
}
- if (allDepsPresent) Logger.die("Unmet module dependencies. Cannot continue");
+ if (!allDepsPresent) Logger.die("Unmet module dependencies. Cannot continue");
+ }
+
+ public void setUser(AgentProxy user) {
+ this.user = user;
}
public String getModuleVersions() {
@@ -126,7 +133,7 @@ public class ModuleManager { public void runScripts(String event) {
for (Module thisMod : modules) {
try {
- thisMod.runScript(event, isServer);
+ thisMod.runScript(event, user, isServer);
} catch (ScriptingEngineException e) {
Logger.error(e);
Logger.die(e.getMessage());
@@ -137,7 +144,7 @@ public class ModuleManager { public void registerModules() throws ModuleException {
ItemProxy serverEntity;
try {
- serverEntity = (ItemProxy)Gateway.getProxyManager().getProxy(new DomainPath("/servers/"+Gateway.getProperties().getProperty("ItemServer.name")));
+ serverEntity = Gateway.getProxyManager().getProxy(new DomainPath("/servers/"+Gateway.getProperties().getProperty("ItemServer.name")));
} catch (ObjectNotFoundException e) {
throw new ModuleException("Cannot find local server name.");
}
@@ -151,7 +158,7 @@ public class ModuleManager { try {
String nsReset = Gateway.getProperties().getProperty("Module."+thisMod.ns+".reset");
boolean thisReset = nsReset == null?reset:nsReset.equals("true");
- thisMod.importAll(serverEntity, modulesXML.get(thisMod.ns), thisReset);
+ thisMod.importAll(serverEntity, user, modulesXML.get(thisMod.ns), thisReset);
} catch (Exception e) {
Logger.error(e);
throw new ModuleException("Error importing items for module "+thisMod.getName());
@@ -159,7 +166,7 @@ public class ModuleManager { Logger.msg("Module "+thisMod.getName()+" registered");
try {
- thisMod.runScript("startup", true);
+ thisMod.runScript("startup", user, true);
} catch (ScriptingEngineException e) {
Logger.error(e);
throw new ModuleException("Error in startup script for module "+thisMod.getName());
diff --git a/src/main/java/com/c2kernel/process/module/ModuleResource.java b/src/main/java/com/c2kernel/process/module/ModuleResource.java index 2f7b638..b36623f 100644 --- a/src/main/java/com/c2kernel/process/module/ModuleResource.java +++ b/src/main/java/com/c2kernel/process/module/ModuleResource.java @@ -8,17 +8,4 @@ public class ModuleResource extends ModuleImport { public ModuleResource() {
}
-
- @Override
- public String getPath(String ns) {
- StringBuffer path = new StringBuffer();
- if (resourceType.equals("CA") || resourceType.equals("EA"))
- path.append("/desc/ActivityDesc/");
- if (resourceType.equals("SC"))
- path.append("/desc/Script/");
- if (resourceType.equals("OD"))
- path.append("/desc/OutcomeDesc/");
- path.append("system/").append(ns==null?"kernel":ns);
- return path.toString();
- }
}
\ No newline at end of file diff --git a/src/main/java/com/c2kernel/process/module/ModuleScript.java b/src/main/java/com/c2kernel/process/module/ModuleScript.java index beed6f9..f16f390 100644 --- a/src/main/java/com/c2kernel/process/module/ModuleScript.java +++ b/src/main/java/com/c2kernel/process/module/ModuleScript.java @@ -1,7 +1,6 @@ package com.c2kernel.process.module;
import com.c2kernel.entity.proxy.AgentProxy;
-import com.c2kernel.process.Gateway;
import com.c2kernel.scripting.Script;
import com.c2kernel.scripting.ScriptingEngineException;
@@ -23,16 +22,8 @@ public class ModuleScript { this.script = script;
}
- public Script getScript(String ns) throws ScriptingEngineException {
- AgentProxy user = Gateway.getCurrentUser();
- try {
- if (user == null) user = (AgentProxy)Gateway.getProxyManager().getProxy(
- Gateway.getLDAPLookup().getRoleManager().getAgentPath("system"));
- } catch (Exception ex) {
- throw new ScriptingEngineException("System agent unavailable");
- }
+ public Script getScript(String ns, AgentProxy user) throws ScriptingEngineException {
return new Script(lang, ns+" "+target+" "+event, script, user);
-
}
public boolean shouldRun(String event, boolean isServer) {
diff --git a/src/main/java/com/c2kernel/process/resource/BadArgumentsException.java b/src/main/java/com/c2kernel/process/resource/BadArgumentsException.java new file mode 100644 index 0000000..c7fe7cf --- /dev/null +++ b/src/main/java/com/c2kernel/process/resource/BadArgumentsException.java @@ -0,0 +1,17 @@ +package com.c2kernel.process.resource;
+
+public class BadArgumentsException extends Exception {
+
+ public BadArgumentsException() {
+ super();
+ }
+
+ public BadArgumentsException(String message) {
+ super(message);
+ }
+
+ public BadArgumentsException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/process/resource/DefaultResourceImportHandler.java b/src/main/java/com/c2kernel/process/resource/DefaultResourceImportHandler.java new file mode 100644 index 0000000..afcf021 --- /dev/null +++ b/src/main/java/com/c2kernel/process/resource/DefaultResourceImportHandler.java @@ -0,0 +1,87 @@ +package com.c2kernel.process.resource;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import com.c2kernel.lookup.DomainPath;
+import com.c2kernel.persistency.outcome.Outcome;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.property.PropertyDescriptionList;
+
+public class DefaultResourceImportHandler implements ResourceImportHandler {
+
+ String resType;
+ String schemaName;
+ String typeRoot;
+ DomainPath typeRootPath;
+ String wfDef;
+ PropertyDescriptionList props;
+
+ public DefaultResourceImportHandler(String resType) throws Exception {
+ this.resType = resType;
+ if (resType.equals("CA")) {
+ wfDef = "ManageCompositeActDef";
+ schemaName = "CompositeActivityDef";
+ typeRoot = "/desc/ActivityDesc";
+ }
+ else if (resType.equals("EA")) {
+ wfDef = "ManageElementaryActDef";
+ schemaName = "ElementaryActivityDef";
+ typeRoot = "/desc/ActivityDesc";
+ }
+ else if (resType.equals("OD")) {
+ wfDef = "ManageSchema";
+ schemaName = "Schema";
+ typeRoot = "/desc/OutcomeDesc";
+ }
+ else if (resType.equals("SC")) {
+ wfDef = "ManageScript";
+ schemaName = "Script";
+ typeRoot = "/desc/Script";
+ }
+ else if (resType.equals("SM")) {
+ wfDef = "ManageStateMachine";
+ schemaName = "StateMachine";
+ typeRoot = "/desc/StateMachine";
+ }
+ else throw new Exception("Unknown bootstrap item type: "+resType);
+ typeRootPath = new DomainPath(typeRoot);
+ props = (PropertyDescriptionList)Gateway.getMarshaller().unmarshall(Gateway.getResource().getTextResource(null, "boot/property/"+resType+"Prop.xml"));
+ }
+
+ @Override
+ public DomainPath getTypeRoot() {
+ return typeRootPath;
+ }
+
+ @Override
+ public String getName() {
+ return schemaName;
+ }
+
+ @Override
+ public DomainPath getPath(String name, String ns) throws Exception {
+ return new DomainPath(typeRoot+"/system/"+(ns==null?"kernel":ns)+'/'+name);
+ }
+
+ @Override
+ public Set<Outcome> getResourceOutcomes(String name, String ns, String location, int version) throws Exception {
+ HashSet<Outcome> retArr = new HashSet<Outcome>();
+ String data = Gateway.getResource().getTextResource(ns, location);
+ if (data == null)
+ throw new Exception("No data found for "+schemaName+" "+name);
+ Outcome resOutcome = new Outcome(0, data, schemaName, 0);
+ retArr.add(resOutcome);
+ return retArr;
+ }
+
+ @Override
+ public PropertyDescriptionList getPropDesc() throws Exception {
+ return props;
+ }
+
+ @Override
+ public String getWorkflowName() throws Exception {
+ return wfDef;
+ }
+}
diff --git a/src/main/java/com/c2kernel/process/resource/Resource.java b/src/main/java/com/c2kernel/process/resource/Resource.java index 4d07f35..2ee95c5 100644 --- a/src/main/java/com/c2kernel/process/resource/Resource.java +++ b/src/main/java/com/c2kernel/process/resource/Resource.java @@ -3,6 +3,7 @@ package com.c2kernel.process.resource; //Java
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
@@ -160,4 +161,9 @@ public class Resource implements ResourceLoader { throw new ObjectNotFoundException(e.getMessage(),null);
}
}
+
+ @Override
+ public Enumeration<URL> getModuleDefURLs() throws Exception {
+ return ClassLoader.getSystemResources("META-INF/cristal/module.xml");
+ }
}
diff --git a/src/main/java/com/c2kernel/process/resource/ResourceImportHandler.java b/src/main/java/com/c2kernel/process/resource/ResourceImportHandler.java new file mode 100644 index 0000000..8f825b5 --- /dev/null +++ b/src/main/java/com/c2kernel/process/resource/ResourceImportHandler.java @@ -0,0 +1,47 @@ +package com.c2kernel.process.resource;
+
+import java.util.Set;
+
+import com.c2kernel.lookup.DomainPath;
+import com.c2kernel.persistency.outcome.Outcome;
+import com.c2kernel.property.PropertyDescriptionList;
+
+public interface ResourceImportHandler {
+
+
+ /** Returns the DomainPath for a specific resource
+ * @param ns - module namespace
+ * @param name - resource name
+ * @return
+ */
+ public DomainPath getPath(String name, String ns) throws Exception;
+
+ /** Generates the outcomes that the resource should contain.
+ * @param res - the module resource definition
+ * @return a set of outcomes to be synced with the resource item.
+ * @throws Exception - if the supplied resources are not valid
+ */
+ public Set<Outcome> getResourceOutcomes(String name, String ns, String location, int version) throws Exception;
+
+ /** Gives the CompActDef name to instantiate to provide the workflow for this type of resource.
+ * Should be found in the CA typeroot (/desc/ActivityDesc/)
+ * @return String workflow name
+ * @throws Exception
+ */
+ public String getWorkflowName() throws Exception;
+
+ /** Should return all of the Properties the resource Item
+ * will have on creation. The Property 'Name' will be created and populated automatically, even if not declared.
+ * @return a PropertyDescriptionList - an arraylist of PropertyDescriptions
+ * @throws Exception
+ */
+ public PropertyDescriptionList getPropDesc() throws Exception;
+
+ /** The directory context to search for existing resources. The name of the resource must be unique below this point.
+ * @return Root path
+ */
+ public DomainPath getTypeRoot();
+
+ public String getName();
+
+}
diff --git a/src/main/java/com/c2kernel/process/resource/ResourceLoader.java b/src/main/java/com/c2kernel/process/resource/ResourceLoader.java index fdf2508..2bbc4d1 100644 --- a/src/main/java/com/c2kernel/process/resource/ResourceLoader.java +++ b/src/main/java/com/c2kernel/process/resource/ResourceLoader.java @@ -2,6 +2,7 @@ package com.c2kernel.process.resource; import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Enumeration;
import java.util.HashMap;
import com.c2kernel.common.InvalidDataException;
@@ -38,4 +39,6 @@ public interface ResourceLoader { public Class<?> getClassForName(String name)
throws ClassNotFoundException;
+ public Enumeration<URL> getModuleDefURLs() throws Exception;
+
}
\ No newline at end of file |
