From da731d2bb81666b9c697d9099da632e7dfcdc0f7 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 9 Sep 2014 12:13:21 +0200 Subject: Replaced int sysKey Item identifier with UUID, which is now portable. ItemPath objects are now used to identify Items throughout the kernel, replacing ints and Integers. --- .../java/com/c2kernel/process/AbstractMain.java | 30 +---- src/main/java/com/c2kernel/process/Bootstrap.java | 96 ++++++++------- src/main/java/com/c2kernel/process/Gateway.java | 15 --- .../java/com/c2kernel/process/ItemHTTPBridge.java | 33 +++-- .../java/com/c2kernel/process/UserCodeProcess.java | 6 +- .../java/com/c2kernel/process/module/Module.java | 135 ++++++++++++++------- .../com/c2kernel/process/module/ModuleImport.java | 60 ++++++++- .../com/c2kernel/process/module/ModuleManager.java | 14 +-- .../c2kernel/process/module/ModuleResource.java | 46 +++++++ 9 files changed, 282 insertions(+), 153 deletions(-) (limited to 'src/main/java/com/c2kernel/process') diff --git a/src/main/java/com/c2kernel/process/AbstractMain.java b/src/main/java/com/c2kernel/process/AbstractMain.java index 0ecfd01..0baf9ce 100644 --- a/src/main/java/com/c2kernel/process/AbstractMain.java +++ b/src/main/java/com/c2kernel/process/AbstractMain.java @@ -21,12 +21,11 @@ import com.c2kernel.process.resource.BadArgumentsException; import com.c2kernel.utils.FileStringUtility; import com.c2kernel.utils.Logger; - -/** - * @author abranson - * @author ogattaz +/************************************************************************** * - */ + * @author $Author: abranson $ $Date: 2004/10/25 15:27:35 $ + * @version $Revision: 1.67 $ + **************************************************************************/ abstract public class AbstractMain { public static boolean isServer = false; @@ -37,22 +36,8 @@ 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"; - /** - * - * @return a help text - */ - public static String getUsageHelpText() { - return "USAGE: com.c2kernel.process.AbstractMain \n" - + " -config \n" - + " [-connect ] (or LocalCentre in conf)\n" - + " [-help] \n" - + " [-noNewLogStream] (for embedded mode: the logger is already configured ) \n" - + " [-logLevel 0-19] \n" - + " [-logFile ]"; - } /************************************************************************** * reading and setting input paramaters @@ -98,13 +83,6 @@ abstract public class AbstractMain } - // print the help and die - if (argProps.containsKey(MAIN_ARG_HELP)){ - System.out.println(); - System.out.println(getUsageHelpText()); - Logger.die("Stop kernel"); - } - if (argProps.containsKey("logFile")) try { logStream = new PrintStream(new FileOutputStream(argProps.getProperty("logFile"), true)); diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java index 46e2cb6..23582bb 100644 --- a/src/main/java/com/c2kernel/process/Bootstrap.java +++ b/src/main/java/com/c2kernel/process/Bootstrap.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Set; import java.util.StringTokenizer; +import java.util.UUID; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.XMLUnit; @@ -101,12 +102,16 @@ public class Bootstrap StringTokenizer str = new StringTokenizer(bootList, "\n\r"); while (str.hasMoreTokens()) { String thisItem = str.nextToken(); - int delim = thisItem.indexOf('/'); - String itemType = thisItem.substring(0,delim); - String itemName = thisItem.substring(delim+1); + ItemPath itemPath = null; + String[] itemParts = thisItem.split("/"); + if (itemParts.length == 3) { // includes UUID + itemPath = new ItemPath(UUID.fromString(itemParts[2])); + } + String itemType = itemParts[0]; + String itemName = itemParts[1]; try { String location = "boot/"+thisItem+(itemType.equals("OD")?".xsd":".xml"); - verifyResource(ns, itemName, 0, itemType, location, reset); + verifyResource(ns, itemName, 0, itemType, itemPath, location, reset); } catch (Exception e) { Logger.error(e); Logger.die("Error importing bootstrap items. Unsafe to continue."); @@ -114,8 +119,7 @@ public class Bootstrap } } - - public static DomainPath verifyResource(String ns, String itemName, Integer version, String itemType, String dataLocation, boolean reset) throws Exception { + public static DomainPath verifyResource(String ns, String itemName, Integer version, String itemType, ItemPath itemPath, String dataLocation, boolean reset) throws Exception { if (version == null) version = 0; LookupManager lookupManager = Gateway.getLookupManager(); ResourceImportHandler typeImpHandler = getHandler(itemType); @@ -126,13 +130,18 @@ public class Bootstrap ItemProxy thisProxy; Iterator en = Gateway.getLookup().search(typeImpHandler.getTypeRoot(), itemName); if (!en.hasNext()) { + if (itemPath == null) itemPath = new ItemPath(); Logger.msg("Bootstrap.verifyResource() - "+typeImpHandler.getName()+" "+itemName+" not found. Creating new."); - thisProxy = createResourceItem(typeImpHandler, itemName, ns); + thisProxy = createResourceItem(typeImpHandler, itemName, ns, itemPath); } else { DomainPath path = (DomainPath)en.next(); thisProxy = Gateway.getProxyManager().getProxy(path); - + if (itemPath != null && !path.getItemPath().equals(itemPath)) { + Logger.warning("Resource "+itemType+"/"+itemName+" should have path "+itemPath+" but was found with path "+path.getItemPath()); + itemPath = path.getItemPath(); + } + if (itemPath == null) itemPath = path.getItemPath(); // Verify module property and location String moduleName = (ns==null?"kernel":ns); @@ -148,12 +157,12 @@ public class Bootstrap } if (!moduleName.equals(itemModule)) { // write module property - Gateway.getStorage().put(thisProxy.getSystemKey(), new Property("Module", moduleName, false), thisProxy); + Gateway.getStorage().put(itemPath, new Property("Module", moduleName, 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())); + modDomPath.setEntity(itemPath); if (!modDomPath.exists()) lookupManager.add(modDomPath); lookupManager.delete(path); @@ -198,15 +207,15 @@ public class Bootstrap // store Logger.msg("Bootstrap.verifyResource() - Writing new "+newOutcome.getSchemaType()+" v"+version+" to "+typeImpHandler.getName()+" "+itemName); - History hist = new History(thisProxy.getSystemKey(), thisProxy); + History hist = new History(itemPath, 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)); + Event newEvent = hist.addEvent(systemAgents.get("system").getPath(), "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); + Viewpoint newLastView = new Viewpoint(itemPath, newOutcome.getSchemaType(), "last", 0, newEvent.getID()); + Viewpoint newNumberView = new Viewpoint(itemPath, newOutcome.getSchemaType(), String.valueOf(version), 0, newEvent.getID()); + Gateway.getStorage().put(itemPath, newOutcome, thisProxy); + Gateway.getStorage().put(itemPath, newLastView, thisProxy); + Gateway.getStorage().put(itemPath, newNumberView, thisProxy); } Gateway.getStorage().commit(thisProxy); return modDomPath; @@ -241,7 +250,7 @@ public class Bootstrap * @param itemName * @param data */ - private static ItemProxy createResourceItem(ResourceImportHandler impHandler, String itemName, String ns) throws Exception { + private static ItemProxy createResourceItem(ResourceImportHandler impHandler, String itemName, String ns, ItemPath itemPath) throws Exception { // create props PropertyDescriptionList pdList = impHandler.getPropDesc(); PropertyArrayList props = new PropertyArrayList(); @@ -263,21 +272,20 @@ public class Bootstrap } - ItemPath entityPath = Gateway.getNextKeyManager().generateNextEntityKey(); - Gateway.getCorbaServer().createEntity(entityPath); - lookupManager.add(entityPath); + Gateway.getCorbaServer().createItem(itemPath); + lookupManager.add(itemPath); DomainPath newDomPath = impHandler.getPath(itemName, ns); - newDomPath.setEntity(entityPath); + newDomPath.setEntity(itemPath); lookupManager.add(newDomPath); - ItemProxy newItemProxy = Gateway.getProxyManager().getProxy(entityPath); - newItemProxy.initialise( 1, props, ca, null); + ItemProxy newItemProxy = Gateway.getProxyManager().getProxy(itemPath); + newItemProxy.initialise( systemAgents.get("system").getPath(), props, ca, null); return newItemProxy; } /************************************************************************** * Checks for the existence of the admin users so you can use Cristal **************************************************************************/ - private static void checkAgent(String name, String pass, String role, boolean joblist) throws Exception { + private static void checkAgent(String name, String pass, String role, UUID uuid, boolean joblist) throws Exception { Logger.msg(1, "Bootstrap.checkAgent() - Checking for existence of '"+name+"' user."); LookupManager lookup = Gateway.getLookupManager(); @@ -297,19 +305,17 @@ public class Bootstrap } try { - ItemPath entityPath = Gateway.getNextKeyManager().generateNextEntityKey(); - AgentPath agentPath = new AgentPath(entityPath.getSysKey(), name); + AgentPath agentPath = new AgentPath(new ItemPath(uuid), name); agentPath.setPassword(pass); - Gateway.getCorbaServer().createEntity(agentPath); + Gateway.getCorbaServer().createAgent(agentPath); lookup.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); + Gateway.getStorage().put(agentPath, new Property("Name", name, true), null); + Gateway.getStorage().put(agentPath, 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."); throw ex; @@ -323,13 +329,13 @@ public class Bootstrap // check for administrative user String adminPassword = Gateway.getProperties().getProperty("AdminPassword", "admin12345"); - checkAgent("admin", adminPassword, "Admin", false); - // check for import user - checkAgent("system", adminPassword, "Admin", false); + checkAgent("system", adminPassword, "Admin", new UUID(0, 0), false); + + checkAgent("admin", adminPassword, "Admin", new UUID(0, 1), false); // check for local usercode user - checkAgent(InetAddress.getLocalHost().getHostName(), "uc", "UserCode", true); + checkAgent(InetAddress.getLocalHost().getHostName(), "uc", "UserCode", UUID.randomUUID(), true); } public static void createServerItem() throws Exception { @@ -338,22 +344,22 @@ public class Bootstrap thisServerPath = new DomainPath("/servers/"+serverName); ItemPath serverEntity; try { - serverEntity = thisServerPath.getEntity(); + serverEntity = thisServerPath.getItemPath(); } catch (ObjectNotFoundException ex) { Logger.msg("Creating server item "+thisServerPath); - serverEntity = Gateway.getNextKeyManager().generateNextEntityKey(); - Gateway.getCorbaServer().createEntity(serverEntity); + serverEntity = new ItemPath(); + Gateway.getCorbaServer().createItem(serverEntity); lookupManager.add(serverEntity); thisServerPath.setEntity(serverEntity); lookupManager.add(thisServerPath); } - Gateway.getStorage().put(serverEntity.getSysKey(), new Property("Name", serverName, false), null); - Gateway.getStorage().put(serverEntity.getSysKey(), new Property("Type", "Server", false), null); - Gateway.getStorage().put(serverEntity.getSysKey(), new Property("KernelVersion", Gateway.getKernelVersion(), true), null); + Gateway.getStorage().put(serverEntity, new Property("Name", serverName, false), null); + Gateway.getStorage().put(serverEntity, new Property("Type", "Server", false), null); + Gateway.getStorage().put(serverEntity, new Property("KernelVersion", Gateway.getKernelVersion(), true), null); if (Gateway.getProperties().getProperty("ItemServer.Proxy.port") != null) - Gateway.getStorage().put(serverEntity.getSysKey(), + Gateway.getStorage().put(serverEntity, new Property("ProxyPort", Gateway.getProperties().getProperty("ItemServer.Proxy.port"), false), null); - Gateway.getStorage().put(serverEntity.getSysKey(), + Gateway.getStorage().put(serverEntity, new Property("ConsolePort", String.valueOf(Logger.getConsolePort()), true), null); Gateway.getProxyManager().connectToProxyServer(Gateway.getProperties().getProperty("ItemServer.name"), Gateway.getProperties().getInt("ItemServer.Proxy.port")); @@ -362,7 +368,7 @@ public class Bootstrap public static void initServerItemWf() throws Exception { CompositeActivityDef serverWfCa = (CompositeActivityDef)LocalObjectLoader.getActDef("ServerItemWorkflow", 0); Workflow wf = new Workflow((CompositeActivity)serverWfCa.instantiate(), new ServerPredefinedStepContainer()); - wf.initialise(thisServerPath.getSysKey(), systemAgents.get("system").getPath()); - Gateway.getStorage().put(thisServerPath.getSysKey(), wf, null); + wf.initialise(thisServerPath.getItemPath(), systemAgents.get("system").getPath()); + Gateway.getStorage().put(thisServerPath.getItemPath(), wf, null); } } diff --git a/src/main/java/com/c2kernel/process/Gateway.java b/src/main/java/com/c2kernel/process/Gateway.java index 85262e8..c2dd646 100644 --- a/src/main/java/com/c2kernel/process/Gateway.java +++ b/src/main/java/com/c2kernel/process/Gateway.java @@ -20,7 +20,6 @@ import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.Lookup; import com.c2kernel.lookup.LookupManager; 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; @@ -61,7 +60,6 @@ public class Gateway static private boolean orbDestroyed = false; static private Lookup mLookup; static private LookupManager mLookupManager = null; - static private NextKeyManager mNextKeyManager; static private TransactionManager mStorage; static private ProxyManager mProxyManager; static private ProxyServer mProxyServer; @@ -161,10 +159,6 @@ public class Gateway else { throw new CannotManageException("Lookup implementation is not a LookupManager. Cannot write to directory"); } - - // init next key manager - mNextKeyManager = (NextKeyManager)mC2KProps.getInstance("NextKeyManager"); - mNextKeyManager.open(auth); // start entity proxy server mProxyServer = new ProxyServer(mC2KProps.getProperty("ItemServer.name")); @@ -290,11 +284,6 @@ public class Gateway if (mCorbaServer != null) mCorbaServer.close(); mCorbaServer = null; - - // close next key manager - if (mNextKeyManager != null) - mNextKeyManager.close(); - mNextKeyManager = null; // disconnect from storages if (mStorage != null) @@ -428,9 +417,5 @@ public class Gateway } } - - public static NextKeyManager getNextKeyManager() { - return mNextKeyManager; - } } diff --git a/src/main/java/com/c2kernel/process/ItemHTTPBridge.java b/src/main/java/com/c2kernel/process/ItemHTTPBridge.java index 6ad8e01..86e3659 100644 --- a/src/main/java/com/c2kernel/process/ItemHTTPBridge.java +++ b/src/main/java/com/c2kernel/process/ItemHTTPBridge.java @@ -1,8 +1,12 @@ package com.c2kernel.process; import java.util.StringTokenizer; +import java.util.UUID; +import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.C2KLocalObject; +import com.c2kernel.lookup.DomainPath; +import com.c2kernel.lookup.ItemPath; import com.c2kernel.utils.server.HTTPRequestHandler; /* QueryData over HTTP Socket Handler @@ -25,21 +29,26 @@ public class ItemHTTPBridge extends HTTPRequestHandler { public String processRequest() { System.out.println("ItemHTTPBridge::ProcessRequest()"); StringTokenizer tok = new StringTokenizer(resource, "?"); - //String itemPath = tok.nextToken(); + String path = tok.nextToken(); String query = tok.nextToken(); - int sysKey = -1; - //Path path = Gateway.getLDAPLookup().; + ItemPath itemPath; + try { + itemPath = new ItemPath(UUID.fromString(path)); + } catch (IllegalArgumentException ex) { + DomainPath domPath = new DomainPath(path); + if (!domPath.exists()) + return error("404 Not Found", "The path "+path+" you requested was not found."); + try { + itemPath = domPath.getItemPath(); + } catch (ObjectNotFoundException e) { + return error("404 Not Found", "The path "+path+" you requested was not found."); + } + } + if (method.equals("GET")) { try { - //DomainPath domPath = new DomainPath(itemPath); - //EntityPath entityPath = domPath.getEntity(); - - if (sysKey > -1) { - C2KLocalObject response = Gateway.getStorage().get(sysKey, query, null); - return Gateway.getMarshaller().marshall(response); - } - else - return error("404 Not Found", "The entity "+sysKey+" you requested was not found."); + C2KLocalObject response = Gateway.getStorage().get(itemPath, query, null); + return Gateway.getMarshaller().marshall(response); } catch (Exception e) { return error("400 Bad Request", "Usage: GET <path to item>?<path to kernel object>
"+e.getClass().getName()); diff --git a/src/main/java/com/c2kernel/process/UserCodeProcess.java b/src/main/java/com/c2kernel/process/UserCodeProcess.java index 0d35025..6b34bf5 100644 --- a/src/main/java/com/c2kernel/process/UserCodeProcess.java +++ b/src/main/java/com/c2kernel/process/UserCodeProcess.java @@ -84,7 +84,7 @@ public class UserCodeProcess extends StandardClient implements ProxyObserver config = new ArrayList(); - public ArrayList scripts = new ArrayList(); - public ImportItem moduleItem; + private ModuleInfo info; + private String resURL; + private ModuleImports imports = new ModuleImports(); + private ArrayList config = new ArrayList(); + private ArrayList scripts = new ArrayList(); public Module() { super(); + // Module properties + properties.add(new com.c2kernel.property.Property("Type", "Module", false)); + setInitialPath("/desc/modules/"); + setWorkflow("NoWorkflow"); + setWorkflowVer(0); + imports.list.add(this); } public void runScript(String event, AgentProxy user, boolean isServer) throws ScriptingEngineException { @@ -51,36 +55,41 @@ public class Module { } } - public void addModuleItem(String moduleXML) { - 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("Version", info.version, true)); - // Add dependency for all children - ImportDependency children = new ImportDependency("Contents"); - for (ModuleImport thisImport : imports.list) { - DomainPath path = thisImport.path; - if (path != null) - children.dependencyMemberList.add(new ImportDependencyMember(path.toString())); - } - moduleItem.dependencyList.add(children); - // Add moduleXML + public void setModuleXML(String moduleXML) { ImportOutcome moduleOutcome = new ImportOutcome("Module", 0, "last", null); moduleOutcome.data = moduleXML; - moduleItem.outcomes.add(moduleOutcome); - imports.list.add(moduleItem); + outcomes.add(moduleOutcome); } + @Override + public void setNamespace(String ns) { + super.setNamespace(ns); + replaceProp(new Property("Namespace", ns, false)); + } + + @Override + public void setName(String name) { + super.setName(name); + replaceProp(new Property("Name", name, false)); + } + + private void replaceProp(Property newProp) { + for (Property prop : properties) { + if (prop.getName().equals("Namespace")) { + prop.setMutable(newProp.isMutable()); + prop.setValue(newProp.getValue()); + return; + } + } + properties.add(newProp); + } public void importAll(ItemProxy serverEntity, AgentProxy systemAgent, String moduleXML, boolean reset) throws Exception { - int systemAgentId = systemAgent.getSystemKey(); - addModuleItem(moduleXML); + setModuleXML(moduleXML); for (ModuleResource thisRes : imports.getResources()) { try { - thisRes.path = Bootstrap.verifyResource(ns, thisRes.name, thisRes.version, - thisRes.resourceType, thisRes.resourceLocation, reset); + thisRes.setNamespace(ns); + thisRes.create(systemAgent.getPath(), reset); } catch (Exception ex) { Logger.error(ex); Logger.die("Error importing module resources. Unsafe to continue."); @@ -91,13 +100,13 @@ public class Module { RolePath rolePath; try { rolePath = Gateway.getLookup().getRolePath(thisRole.name); - if (rolePath.hasJobList() != thisRole.jobList) { + if (rolePath.hasJobList() != thisRole.hasJobList()) { Logger.msg("Module.importAll() - Role '"+thisRole.name+"' has incorrect joblist settings. Correcting."); - rolePath.setHasJobList(thisRole.jobList); + rolePath.setHasJobList(thisRole.hasJobList()); } } catch (ObjectNotFoundException ex) { Logger.msg("Module.importAll() - Role '"+thisRole.name+"' not found. Creating."); - thisRole.create(systemAgentId); + thisRole.create(systemAgent.getPath(), reset); } } @@ -108,12 +117,12 @@ public class Module { continue; } catch (ObjectNotFoundException ex) { } Logger.msg("Module.importAll() - User '"+thisAgent.name+"' not found. Creating."); - thisAgent.create(systemAgentId); + thisAgent.create(systemAgent.getPath(), reset); } for (ImportItem thisItem : imports.getItems()) { thisItem.setNamespace(ns); - thisItem.create(systemAgentId, reset); + thisItem.create(systemAgent.getPath(), reset); } } @@ -126,12 +135,13 @@ public class Module { } return props; } - - public String getNs() { - return ns; + + public ArrayList getScripts() { + return scripts; } - public String getName() { - return name; + + public void setResURL(String resURL) { + this.resURL = resURL; } public String getDesc() { return info.desc; @@ -148,4 +158,43 @@ public class Module { public boolean hasDependency(String dep) { return info.dependency.contains(dep); } + + public ModuleInfo getInfo() { + return info; + } + + public void setInfo(ModuleInfo info) { + this.info = info; + replaceProp(new Property("Version", info.version, true)); + } + + public ModuleImports getImports() { + return imports; + } + + public void setImports(ModuleImports imp) { + // Add dependency for all children + imports = imp; + ImportDependency children = new ImportDependency("Contents"); + for (ModuleImport thisImport : imports.list) { + DomainPath path = thisImport.domainPath; + if (path != null) + children.dependencyMemberList.add(new ImportDependencyMember(path.toString())); + } + dependencyList.add(children); + } + + public void setConfig(ArrayList config) { + this.config = config; + } + + public void setScripts(ArrayList scripts) { + this.scripts = scripts; + } + + public ArrayList getConfig() { + return config; + } + + } diff --git a/src/main/java/com/c2kernel/process/module/ModuleImport.java b/src/main/java/com/c2kernel/process/module/ModuleImport.java index 1f5b16d..f54b47d 100644 --- a/src/main/java/com/c2kernel/process/module/ModuleImport.java +++ b/src/main/java/com/c2kernel/process/module/ModuleImport.java @@ -1,10 +1,66 @@ package com.c2kernel.process.module; +import java.util.UUID; + +import com.c2kernel.common.CannotManageException; +import com.c2kernel.common.ObjectAlreadyExistsException; +import com.c2kernel.common.ObjectCannotBeUpdated; +import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.DomainPath; +import com.c2kernel.lookup.ItemPath; public abstract class ModuleImport { - public String name; - public DomainPath path; + protected String ns; + protected String name; + protected DomainPath domainPath; + protected ItemPath itemPath; + + public ModuleImport() { + } + + public abstract void create(AgentPath agentPath, boolean reset) throws ObjectNotFoundException, + ObjectCannotBeUpdated, CannotManageException, ObjectAlreadyExistsException; + + public void setID( String uuid ) + { + if (uuid != null) itemPath = new ItemPath(UUID.fromString(uuid)); + } + + public String getID() { + return itemPath==null?null:itemPath.getUUID().toString(); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public void setNamespace(String ns) { + this.ns = ns; + } + public String getNamespace() { + return ns; + } + + public DomainPath getDomainPath() { + return domainPath; + } + + public void setDomainPath(DomainPath domainPath) { + this.domainPath = domainPath; + } + + public ItemPath getItemPath() { + return itemPath; + } + + public void setItemPath(ItemPath itemPath) { + this.itemPath = itemPath; + } } \ No newline at end of file diff --git a/src/main/java/com/c2kernel/process/module/ModuleManager.java b/src/main/java/com/c2kernel/process/module/ModuleManager.java index 6a69ff8..4fde044 100644 --- a/src/main/java/com/c2kernel/process/module/ModuleManager.java +++ b/src/main/java/com/c2kernel/process/module/ModuleManager.java @@ -49,13 +49,13 @@ public class ModuleManager { if (errors.length() > 0) throw new ModuleException("Module XML found at "+newModuleURL+" was not valid: "+errors); Module newModule = (Module)Gateway.getMarshaller().unmarshall(moduleXML); - if (newModule.resURL != null && newModule.resURL.length()>0) Gateway.getResource().addModuleBaseURL(newModule.ns, newModule.resURL); + if (newModule.getResURL() != null && newModule.getResURL().length()>0) Gateway.getResource().addModuleBaseURL(newModule.getNamespace(), newModule.getResURL()); modules.add(newModule); - modulesXML.put(newModule.ns, moduleXML); + modulesXML.put(newModule.getNamespace(), moduleXML); if (loadedModules.contains(newModule.getName())) throw new ModuleException("Module name clash: "+newModule.getName()); - 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()); + if (moduleNs.contains(newModule.getNamespace())) throw new ModuleException("Module namespace clash: "+newModule.getNamespace()); + Logger.debug(4, "Module found: "+newModule.getNamespace()+" - "+newModule.getName()); + loadedModules.add(newModule.getName()); moduleNs.add(newModule.getNamespace()); } catch (ModuleException e) { Logger.error("Could not load module description from "+newModuleURL); throw e; @@ -156,9 +156,9 @@ public class ModuleManager { Logger.msg("Registering module "+thisMod.getName()); try { - String nsReset = Gateway.getProperties().getProperty("Module."+thisMod.ns+".reset"); + String nsReset = Gateway.getProperties().getProperty("Module."+thisMod.getNamespace()+".reset"); boolean thisReset = nsReset == null?reset:nsReset.equals("true"); - thisMod.importAll(serverEntity, user, modulesXML.get(thisMod.ns), thisReset); + thisMod.importAll(serverEntity, user, modulesXML.get(thisMod.getNamespace()), thisReset); } catch (Exception e) { Logger.error(e); throw new ModuleException("Error importing items 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 b36623f..874c7cc 100644 --- a/src/main/java/com/c2kernel/process/module/ModuleResource.java +++ b/src/main/java/com/c2kernel/process/module/ModuleResource.java @@ -1,5 +1,13 @@ package com.c2kernel.process.module; +import com.c2kernel.common.CannotManageException; +import com.c2kernel.common.ObjectAlreadyExistsException; +import com.c2kernel.common.ObjectCannotBeUpdated; +import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.lookup.AgentPath; +import com.c2kernel.process.Bootstrap; +import com.c2kernel.utils.Logger; + public class ModuleResource extends ModuleImport { public Integer version; @@ -8,4 +16,42 @@ public class ModuleResource extends ModuleImport { public ModuleResource() { } + + @Override + public void create(AgentPath agentPath, boolean reset) + throws ObjectNotFoundException, ObjectCannotBeUpdated, + CannotManageException, ObjectAlreadyExistsException { + try { + domainPath = Bootstrap.verifyResource(ns, name, version, resourceType, itemPath, resourceLocation, reset); + } catch (Exception e) { + Logger.error(e); + throw new CannotManageException("Exception verifying module resource "+ns+"/"+name); + } + } + + public int getVersion() { + return version; + } + + public void setVersion(int version) { + this.version = version; + } + + public String getResourceType() { + return resourceType; + } + + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + + public String getResourceLocation() { + return resourceLocation; + } + + public void setResourceLocation(String resourceLocation) { + this.resourceLocation = resourceLocation; + } + + } \ No newline at end of file -- cgit v1.2.3