From 684e01bb190c7d0b95347b732aeb3cdeda4740d7 Mon Sep 17 00:00:00 2001 From: abranson Date: Tue, 18 Oct 2011 17:00:33 +0200 Subject: Module support --- source/com/c2kernel/process/Bootstrap.java | 156 ++++++++--------------------- 1 file changed, 44 insertions(+), 112 deletions(-) (limited to 'source/com/c2kernel/process/Bootstrap.java') diff --git a/source/com/c2kernel/process/Bootstrap.java b/source/com/c2kernel/process/Bootstrap.java index 5011b7f..5b83d89 100644 --- a/source/com/c2kernel/process/Bootstrap.java +++ b/source/com/c2kernel/process/Bootstrap.java @@ -2,7 +2,6 @@ package com.c2kernel.process; import java.net.InetAddress; import java.util.Enumeration; -import java.util.HashMap; import java.util.StringTokenizer; import com.c2kernel.common.ObjectNotFoundException; @@ -15,7 +14,6 @@ import com.c2kernel.lifecycle.instance.CompositeActivity; import com.c2kernel.lifecycle.instance.Workflow; import com.c2kernel.lifecycle.instance.predefined.PredefinedStepContainer; import com.c2kernel.lifecycle.instance.predefined.ServerPredefinedStepContainer; -import com.c2kernel.lifecycle.instance.predefined.entitycreation.NewItem; import com.c2kernel.lifecycle.instance.stateMachine.States; import com.c2kernel.lifecycle.instance.stateMachine.Transitions; import com.c2kernel.lookup.AgentPath; @@ -44,7 +42,6 @@ import com.c2kernel.utils.Resource; public class Bootstrap { - static HashMap bootstrapFactoryItems = new HashMap(); static DomainPath thisServerPath; /** @@ -68,8 +65,6 @@ public class Bootstrap // verify the server item's wf initServerItemWf(); - // create the factories etc. - createBootstrapFactoryItems(); Logger.msg("Bootstrap.run() - Bootstrapping complete"); } catch (Exception e) { Logger.error(e); @@ -86,45 +81,11 @@ public class Bootstrap String bootItems; Logger.msg(1, "Verifying kernel boot items"); bootItems = FileStringUtility.url2String(Resource.getKernelResourceURL("boot/allbootitems.txt")); - verifyBootDataItems(bootItems, true); - if (Resource.getDomainBaseURL() == null) - Logger.msg(1, "No Domain base URL. Skipping domain boot check."); - else { - try { - Logger.msg(1, "Verifying domain boot items"); - bootItems = FileStringUtility.url2String(Resource.getDomainResourceURL("boot/allbootitems.txt")); - verifyBootDataItems(bootItems, false); - } catch (Exception ex) { - Logger.error(ex); - Logger.msg("No domain boot items found."); - return; - } - Logger.msg(1, "Verifying domain agents"); - - try { - bootItems = FileStringUtility.url2String(Resource.getDomainResourceURL("boot/domainagents.txt")); - verifyDomainAgents(bootItems); - } catch (Exception ex) { - Logger.error(ex); - Logger.msg("No domain agents found."); - return; - } - } - + verifyBootDataItems(bootItems, null); Logger.msg(1, "Boot data items complete"); - - } - - private static void verifyDomainAgents(String agentFile) throws Exception { - StringTokenizer str = new StringTokenizer(agentFile, "\n\r"); - while (str.hasMoreTokens()) { - String thisItem = str.nextToken(); - StringTokenizer agent = new StringTokenizer(thisItem, ","); - checkAgent(agent.nextToken(), agent.nextToken(), agent.nextToken(), agent.nextToken().equalsIgnoreCase("true")); - } } - private static void verifyBootDataItems(String bootList, boolean isKernel) { + private static void verifyBootDataItems(String bootList, String ns) { StringTokenizer str = new StringTokenizer(bootList, "\n\r"); while (str.hasMoreTokens()) { String thisItem = str.nextToken(); @@ -132,63 +93,62 @@ public class Bootstrap String itemType = thisItem.substring(0,delim); String itemName = thisItem.substring(delim+1); try { - String data = Resource.getTextResource("boot/"+thisItem+".xml"); + String data = Resource.getTextResource(ns, "boot/"+thisItem+(itemType.equals("OD")?".xsd":".xml")); if (data == null) Logger.die("No data found for "+getDataType(itemType)+" "+itemName); - if (itemType.equals("factory")) { - bootstrapFactoryItems.put(itemName, data); - continue; - } - - Logger.msg(1, "Bootstrap.verifyBootItems() - Verifying data of "+getDataType(itemType)+" "+itemName); - Enumeration en = Gateway.getLDAPLookup().search(getTypeRoot(itemType), itemName); - ItemProxy thisProxy; - - if (!en.hasMoreElements()) { - Logger.msg("Bootstrap.verifyBootItems() - "+getDataType(itemType)+" "+itemName+" not found. Creating new."); - thisProxy = createBootstrapDataItem(itemType, itemName, isKernel); - } - else { - DomainPath path = (DomainPath)en.nextElement(); - thisProxy = (ItemProxy)Gateway.getProxyManager().getProxy(path); - try { - Viewpoint currentData = (Viewpoint)thisProxy.getObject(ClusterStorage.VIEWPOINT+"/"+getDataType(itemType)+"/last"); - String oldData = currentData.getOutcome().getData(); - if (data.equals(oldData)) { - Logger.msg(5, "Bootstrap.verifyBootItems() - Data identical, no update required"); - - continue; - } - } catch (ObjectNotFoundException ex) { - Logger.error("Bootstrap.verifyBootItems() - Item exists but no data found! Attempting to insert new."); - } - } - // data was missing or doesn't match - Logger.msg("Bootstrap.verifyBootItems() - Writing new data to "+getDataType(itemType)+" "+itemName); - History hist = (History)thisProxy.getObject(ClusterStorage.HISTORY); - Event newEvent = hist.addEvent("system", "Admin", Transitions.DONE, "Import", "Import", "Import", States.FINISHED); - Outcome newOutcome = new Outcome(newEvent.getID(), data, getDataType(itemType), 0); - Viewpoint newLastView = new Viewpoint(thisProxy.getSystemKey(), getDataType(itemType), "last", 0, newEvent.getID()); - Viewpoint newZeroView = new Viewpoint(thisProxy.getSystemKey(), getDataType(itemType), "0", 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); + verifyResource(ns, itemName, itemType, data); } catch (Exception e) { Logger.error(e); Logger.die("Error importing bootstrap items. Unsafe to continue."); } } } + + + public static void verifyResource(String ns, String itemName, String itemType, String data) throws Exception { + Logger.msg(1, "Bootstrap.verifyResource() - Verifying data of "+getDataType(itemType)+" "+itemName); + Enumeration en = Gateway.getLDAPLookup().search(getTypeRoot(itemType), itemName); + ItemProxy thisProxy; + + if (!en.hasMoreElements()) { + Logger.msg("Bootstrap.verifyResource() - "+getDataType(itemType)+" "+itemName+" not found. Creating new."); + thisProxy = createResourceItem(itemType, itemName, ns); + } + else { + DomainPath path = (DomainPath)en.nextElement(); + thisProxy = (ItemProxy)Gateway.getProxyManager().getProxy(path); + try { + Viewpoint currentData = (Viewpoint)thisProxy.getObject(ClusterStorage.VIEWPOINT+"/"+getDataType(itemType)+"/last"); + String oldData = currentData.getOutcome().getData(); + if (data.equals(oldData)) { + Logger.msg(5, "Bootstrap.verifyResource() - Data identical, no update required"); + return; + } + } catch (ObjectNotFoundException ex) { + Logger.error("Bootstrap.verifyResource() - Item exists but no data found! Attempting to insert new."); + } + } + // data was missing or doesn't match + Logger.msg("Bootstrap.verifyResource() - Writing new data to "+getDataType(itemType)+" "+itemName); + History hist = (History)thisProxy.getObject(ClusterStorage.HISTORY); + Event newEvent = hist.addEvent("system", "Admin", Transitions.DONE, "Import", "Import", "Import", States.FINISHED); + Outcome newOutcome = new Outcome(newEvent.getID(), data, getDataType(itemType), 0); + Viewpoint newLastView = new Viewpoint(thisProxy.getSystemKey(), getDataType(itemType), "last", 0, newEvent.getID()); + Viewpoint newZeroView = new Viewpoint(thisProxy.getSystemKey(), getDataType(itemType), "0", 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); + } /** * @param itemType * @param itemName * @param data */ - private static ItemProxy createBootstrapDataItem(String itemType, String itemName, boolean isKernel) throws Exception { + private static ItemProxy createResourceItem(String itemType, String itemName, String ns) throws Exception { // create props - PropertyDescriptionList pdList = (PropertyDescriptionList)CastorXMLUtility.unmarshall(Resource.getTextResource("boot/property/"+itemType+"Prop.xml")); + PropertyDescriptionList pdList = (PropertyDescriptionList)CastorXMLUtility.unmarshall(Resource.getTextResource(null, "boot/property/"+itemType+"Prop.xml")); PropertyArrayList props = new PropertyArrayList(); for (int i = 0; i < pdList.list.size(); i++) { PropertyDescription pd = pdList.list.get(i); @@ -204,7 +164,7 @@ public class Bootstrap 1, CastorXMLUtility.marshall(props), CastorXMLUtility.marshall(new CompositeActivity())); - DomainPath newDomPath = new DomainPath(getTypeRoot(itemType).toString()+"/system/"+(isKernel?"kernel":"domain")+"/"+itemName); + 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); @@ -325,32 +285,4 @@ public class Bootstrap Gateway.getStorage().put(thisServerPath.getSysKey(), wf, null); // add this proxy server in case it was just registered, or the port has changed } - - public static void createBootstrapFactoryItems() throws Exception { - Logger.msg(1, "Verifying local object factories"); - for (String itemName : bootstrapFactoryItems.keySet()) { - String itemXML = bootstrapFactoryItems.get(itemName); - Logger.msg(2, "Verifying "+itemName); - NewItem item = (NewItem)CastorXMLUtility.unmarshall(itemXML); - DomainPath factPath = new DomainPath(new DomainPath(item.initialPath), item.name); - if (factPath.exists()) continue; - ItemProxy serverEntity = (ItemProxy)Gateway.getProxyManager().getProxy(thisServerPath); - serverEntity.requestAction( - Gateway.getLDAPLookup().getRoleManager().getAgentPath("system").getSysKey(), - "workflow/predefined/CreateNewItem", - Transitions.DONE, - itemXML); - Logger.msg("Bootstrap.createBootstrapFactoryItems() - Created factory item: "+itemName); - ItemProxy factProxy = (ItemProxy)Gateway.getProxyManager().getProxy(factPath); - String propDesc = Resource.getTextResource("boot/property/"+itemName+"Prop.xml"); - History hist = (History)factProxy.getObject(ClusterStorage.HISTORY); - Event newEvent = hist.addEvent("system", "Admin", Transitions.DONE, "Import", "Import", "Import", States.FINISHED); - Outcome newOutcome = new Outcome(newEvent.getID(), propDesc, "PropertyDescription", 0); - Viewpoint newLastView = new Viewpoint(factProxy.getSystemKey(), "PropertyDescription", "last", 0, newEvent.getID()); - Gateway.getStorage().put(factProxy.getSystemKey(), newOutcome, factProxy); - Gateway.getStorage().put(factProxy.getSystemKey(), newLastView, factProxy); - Gateway.getStorage().commit(factProxy); - } - } - } -- cgit v1.2.3