summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/process/Bootstrap.java
diff options
context:
space:
mode:
authorabranson <andrew.branson@cern.ch>2011-08-04 00:42:34 +0200
committerabranson <andrew.branson@cern.ch>2011-08-04 00:42:34 +0200
commit0ec8481c10cd8277d84c7c1a785483a0a739e5a0 (patch)
tree5f6e5d9ae75193e67e6f3b3dfa488960c5cde1d5 /source/com/c2kernel/process/Bootstrap.java
parent036cbdba66f804743c4c838ed598d6972c4b3e17 (diff)
More code cleanup:
Refactored Entity Proxy Subscription to handle generics better Rewrote RemoteMap to use TreeMap instead of the internal array for order. It now sorts its keys by number if they parse, else as strings. Removed a no-longer-in-progress outcome form class
Diffstat (limited to 'source/com/c2kernel/process/Bootstrap.java')
-rw-r--r--source/com/c2kernel/process/Bootstrap.java86
1 files changed, 42 insertions, 44 deletions
diff --git a/source/com/c2kernel/process/Bootstrap.java b/source/com/c2kernel/process/Bootstrap.java
index 777568c..6ffdd01 100644
--- a/source/com/c2kernel/process/Bootstrap.java
+++ b/source/com/c2kernel/process/Bootstrap.java
@@ -3,12 +3,10 @@ package com.c2kernel.process;
import java.net.InetAddress;
import java.util.Enumeration;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.StringTokenizer;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.TraceableEntity;
-import com.c2kernel.entity.agent.ActiveEntity;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.events.Event;
import com.c2kernel.events.History;
@@ -56,18 +54,19 @@ public class Bootstrap
checkAdminAgents();
// create the server's mother item
- createServerItem();
+ createServerItem();
new Thread(new Runnable() {
+ @Override
public void run() {
try {
Thread.currentThread().setName("Bootstrapper");
-
+
// make sure all of the boot items are up-to-date
verifyBootDataItems();
-
+
// verify the server item's wf
initServerItemWf();
-
+
// create the factories etc.
createBootstrapFactoryItems();
Logger.msg("Bootstrap.run() - Bootstrapping complete");
@@ -78,7 +77,7 @@ public class Bootstrap
}
}).start();
}
-
+
/**************************************************************************
* Checks all kernel descriptions, stored in resources
**************************************************************************/
@@ -87,7 +86,7 @@ public class Bootstrap
Logger.msg(1, "Verifying kernel boot items");
bootItems = FileStringUtility.url2String(Resource.getKernelResourceURL("boot/allbootitems.txt"));
verifyBootDataItems(bootItems, true);
- if (Resource.getDomainBaseURL() == null)
+ if (Resource.getDomainBaseURL() == null)
Logger.msg(1, "No Domain base URL. Skipping domain boot check.");
else {
try {
@@ -100,7 +99,7 @@ public class Bootstrap
return;
}
Logger.msg(1, "Verifying domain agents");
-
+
try {
bootItems = FileStringUtility.url2String(Resource.getDomainResourceURL("boot/domainagents.txt"));
verifyDomainAgents(bootItems);
@@ -110,11 +109,11 @@ public class Bootstrap
return;
}
}
-
+
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()) {
@@ -123,7 +122,7 @@ public class Bootstrap
checkAgent(agent.nextToken(), agent.nextToken(), agent.nextToken(), agent.nextToken().equalsIgnoreCase("true"));
}
}
-
+
private static void verifyBootDataItems(String bootList, boolean isKernel) {
StringTokenizer str = new StringTokenizer(bootList, "\n\r");
while (str.hasMoreTokens()) {
@@ -139,9 +138,9 @@ public class Bootstrap
bootstrapFactoryItems.put(itemName, data);
continue;
}
-
+
Logger.msg(1, "Bootstrap.verifyBootItems() - Verifying data of "+getDataType(itemType)+" "+itemName);
- Enumeration en = Gateway.getLDAPLookup().search(getTypeRoot(itemType), itemName);
+ Enumeration<?> en = Gateway.getLDAPLookup().search(getTypeRoot(itemType), itemName);
ItemProxy thisProxy;
if (!en.hasMoreElements()) {
@@ -156,7 +155,7 @@ public class Bootstrap
String oldData = currentData.getOutcome().getData();
if (data.equals(oldData)) {
Logger.msg(5, "Bootstrap.verifyBootItems() - Data identical, no update required");
-
+
continue;
}
} catch (ObjectNotFoundException ex) {
@@ -191,12 +190,12 @@ public class Bootstrap
PropertyDescriptionList pdList = (PropertyDescriptionList)CastorXMLUtility.unmarshall(Resource.getTextResource("boot/property/"+itemType+"Prop.xml"));
PropertyArrayList props = new PropertyArrayList();
for (int i = 0; i < pdList.list.size(); i++) {
- PropertyDescription pd = (PropertyDescription) pdList.list.get(i);
+ PropertyDescription pd = pdList.list.get(i);
String propName = pd.getName();
String propVal = propName.equals("Name")?itemName:pd.getDefaultValue();
- props.list.add(new Property(propName, propVal));
+ props.list.add(new Property(propName, propVal));
}
-
+
EntityPath entityPath = Gateway.getLDAPLookup().getNextKeyManager().generateNextEntityKey();
TraceableEntity newItem = (TraceableEntity)Gateway.getCorbaServer().createEntity(entityPath);
Gateway.getLDAPLookup().add(entityPath);
@@ -219,7 +218,7 @@ public class Bootstrap
return new DomainPath("/desc/OutcomeDesc/");
throw new Exception("Unknown bootstrap item type: "+type);
}
-
+
private static String getDataType(String type) throws Exception {
if (type.equals("CA"))
return "CompositeActivityDef";
@@ -230,36 +229,36 @@ public class Bootstrap
if (type.equals("SC"))
return "Script";
throw new Exception("Unknown bootstrap item type: "+type);
-
+
}
-
+
/**************************************************************************
* 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, boolean joblist) throws Exception {
Logger.msg(1, "Bootstrap.checkAgent() - Checking for existence of '"+name+"' user.");
LDAPLookup lookup = Gateway.getLDAPLookup();
try {
- AgentPath agentPath = lookup.getRoleManager().getAgentPath(name);
+ lookup.getRoleManager().getAgentPath(name);
Logger.msg(3, "Bootstrap.checkAgent() - User '"+name+"' found.");
return;
} catch (ObjectNotFoundException ex) { }
Logger.msg("Bootstrap.checkAgent() - User '"+name+"' not found. Creating.");
-
+
RolePath rolePath;
try {
rolePath = lookup.getRoleManager().getRolePath(role);
} catch (ObjectNotFoundException ex) {
rolePath = lookup.getRoleManager().createRole(role, joblist);
}
-
+
try {
EntityPath entityPath = lookup.getNextKeyManager().generateNextEntityKey();
AgentPath agentPath = new AgentPath(entityPath.getSysKey(), name);
agentPath.setPassword(pass);
- ActiveEntity adminAgent = (ActiveEntity)Gateway.getCorbaServer().createEntity(agentPath);
+ Gateway.getCorbaServer().createEntity(agentPath);
Gateway.getLDAPLookup().add(agentPath);
-
+
// assign admin role
Logger.msg("Bootstrap.checkAgent() - Assigning role '"+role+"'");
rolePath.addAgent(agentPath);
@@ -273,21 +272,21 @@ public class Bootstrap
}
/**
- *
+ *
*/
public static void checkAdminAgents() throws Exception {
// check for administrative user
String adminPassword = Gateway.getProperty("AdminPassword", "admin12345");
-
+
checkAgent("admin", adminPassword, "Admin", false);
-
+
// check for import user
checkAgent("system", adminPassword, "Admin", false);
-
+
// check for local usercode user
checkAgent(InetAddress.getLocalHost().getHostName(), "uc", "UserCode", true);
- }
-
+ }
+
public static void createServerItem() throws Exception {
String serverName = Gateway.getProperty("ItemServer.name");
thisServerPath = new DomainPath("/servers/"+serverName);
@@ -297,7 +296,7 @@ public class Bootstrap
} catch (ObjectNotFoundException ex) {
Logger.msg("Creating server item "+thisServerPath);
serverEntity = Gateway.getLDAPLookup().getNextKeyManager().generateNextEntityKey();
- TraceableEntity newItem = (TraceableEntity)Gateway.getCorbaServer().createEntity(serverEntity);
+ Gateway.getCorbaServer().createEntity(serverEntity);
Gateway.getLDAPLookup().add(serverEntity);
thisServerPath.setEntity(serverEntity);
Gateway.getLDAPLookup().add(thisServerPath);
@@ -306,15 +305,15 @@ public class Bootstrap
Gateway.getStorage().put(serverEntity.getSysKey(), new Property("Type", "Server"), null);
Gateway.getStorage().put(serverEntity.getSysKey(), new Property("KernelVersion", Resource.getKernelVersion()), null);
if (Gateway.getProperty("ItemServer.Proxy.port") != null)
- Gateway.getStorage().put(serverEntity.getSysKey(),
+ Gateway.getStorage().put(serverEntity.getSysKey(),
new Property("ProxyPort", Gateway.getProperty("ItemServer.Proxy.port")), null);
if (Gateway.getProperty("ItemServer.Console.port") != null)
- Gateway.getStorage().put(serverEntity.getSysKey(),
+ Gateway.getStorage().put(serverEntity.getSysKey(),
new Property("ConsolePort", Gateway.getProperty("ItemServer.Console.port")), null);
Gateway.getProxyManager().connectToProxyServer(Gateway.getProperty("ItemServer.name"), Integer.parseInt(Gateway.getProperty("ItemServer.Proxy.port")));
}
-
+
public static void initServerItemWf() throws Exception {
CompositeActivityDef serverWfCa = (CompositeActivityDef)LocalObjectLoader.getActDef("ServerItemWorkflow", "last");
Workflow wf = new Workflow((CompositeActivity)serverWfCa.instantiate());
@@ -325,21 +324,20 @@ 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 (Iterator iter = bootstrapFactoryItems.keySet().iterator(); iter.hasNext();) {
- String itemName = (String) iter.next();
- String itemXML = (String)bootstrapFactoryItems.get(itemName);
+ 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(),
+ Gateway.getLDAPLookup().getRoleManager().getAgentPath("system").getSysKey(),
"workflow/predefined/CreateNewItem",
- Transitions.DONE,
+ Transitions.DONE,
itemXML);
Logger.msg("Bootstrap.createBootstrapFactoryItems() - Created factory item: "+itemName);
ItemProxy factProxy = (ItemProxy)Gateway.getProxyManager().getProxy(factPath);