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. --- src/main/java/com/c2kernel/process/Bootstrap.java | 96 ++++++++++++----------- 1 file changed, 51 insertions(+), 45 deletions(-) (limited to 'src/main/java/com/c2kernel/process/Bootstrap.java') 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); } } -- cgit v1.2.3