diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2014-05-15 15:10:13 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2014-05-15 15:10:13 +0200 |
| commit | 8e8185210f5bd87cb5dcda3a458fe059f811aafc (patch) | |
| tree | 6c6e8783c20800df261d7e0e79aa276ead84d368 | |
| parent | 2ee6d3c6e816214892fdd541a9aae535686be788 (diff) | |
Introduced 'Layer' attribute to allow overriding of descriptions. Desc
with the same name in the same description tree will be ranked by
LocalObjectLoader according to this number, and the highest one chosen
for instantiation. Fixes #188
| -rw-r--r-- | src/main/java/com/c2kernel/process/Bootstrap.java | 25 | ||||
| -rw-r--r-- | src/main/java/com/c2kernel/process/module/Module.java | 3 | ||||
| -rw-r--r-- | src/main/java/com/c2kernel/process/module/ModuleInfo.java | 1 | ||||
| -rw-r--r-- | src/main/java/com/c2kernel/utils/LocalObjectLoader.java | 28 | ||||
| -rw-r--r-- | src/main/resources/boot/OD/Module.xsd | 1 | ||||
| -rw-r--r-- | src/main/resources/boot/property/CAProp.xml | 1 | ||||
| -rw-r--r-- | src/main/resources/boot/property/EAProp.xml | 1 | ||||
| -rw-r--r-- | src/main/resources/boot/property/ODProp.xml | 1 | ||||
| -rw-r--r-- | src/main/resources/boot/property/SCProp.xml | 1 | ||||
| -rw-r--r-- | src/main/resources/boot/property/SMProp.xml | 1 | ||||
| -rw-r--r-- | src/main/resources/mapFiles/ModuleMap.xml | 3 |
11 files changed, 58 insertions, 8 deletions
diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java index e2ad24e..f273c5d 100644 --- a/src/main/java/com/c2kernel/process/Bootstrap.java +++ b/src/main/java/com/c2kernel/process/Bootstrap.java @@ -103,7 +103,7 @@ public class Bootstrap String itemName = thisItem.substring(delim+1);
try {
String location = "boot/"+thisItem+(itemType.equals("OD")?".xsd":".xml");
- verifyResource(ns, itemName, 0, itemType, location, reset);
+ verifyResource(ns, itemName, 0, itemType, location, 0, reset);
} catch (Exception e) {
Logger.error(e);
Logger.die("Error importing bootstrap items. Unsafe to continue.");
@@ -112,7 +112,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, String dataLocation, int layer, boolean reset) throws Exception {
if (version == null) version = 0;
ResourceImportHandler typeImpHandler = getHandler(itemType);
Logger.msg(1, "Bootstrap.verifyResource() - Verifying version "+version+" of "+typeImpHandler.getName()+" "+itemName);
@@ -123,7 +123,7 @@ public class Bootstrap Enumeration<Path> en = Gateway.getLDAPLookup().search(typeImpHandler.getTypeRoot(), itemName);
if (!en.hasMoreElements()) {
Logger.msg("Bootstrap.verifyResource() - "+typeImpHandler.getName()+" "+itemName+" not found. Creating new.");
- thisProxy = createResourceItem(typeImpHandler, itemName, ns);
+ thisProxy = createResourceItem(typeImpHandler, itemName, layer, ns);
}
else {
DomainPath path = (DomainPath)en.nextElement();
@@ -147,6 +147,15 @@ public class Bootstrap 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()));
@@ -224,16 +233,22 @@ public class Bootstrap /**
* @param itemType
* @param itemName
+ * @param layer
* @param data
*/
- private static ItemProxy createResourceItem(ResourceImportHandler impHandler, String itemName, String ns) throws Exception {
+ private static ItemProxy createResourceItem(ResourceImportHandler impHandler, String itemName, int layer, String ns) throws Exception {
// create props
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()));
}
diff --git a/src/main/java/com/c2kernel/process/module/Module.java b/src/main/java/com/c2kernel/process/module/Module.java index 32a5997..2c182ea 100644 --- a/src/main/java/com/c2kernel/process/module/Module.java +++ b/src/main/java/com/c2kernel/process/module/Module.java @@ -56,6 +56,7 @@ public class Module { 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");
@@ -79,7 +80,7 @@ public class Module { for (ModuleResource thisRes : imports.getResources()) {
try {
thisRes.path = Bootstrap.verifyResource(ns, thisRes.name, thisRes.version,
- thisRes.resourceType, thisRes.resourceLocation, reset);
+ thisRes.resourceType, thisRes.resourceLocation, info.layer, reset);
} catch (Exception ex) {
Logger.error(ex);
}
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/utils/LocalObjectLoader.java b/src/main/java/com/c2kernel/utils/LocalObjectLoader.java index 05f8aba..307cd97 100644 --- a/src/main/java/com/c2kernel/utils/LocalObjectLoader.java +++ b/src/main/java/com/c2kernel/utils/LocalObjectLoader.java @@ -1,11 +1,14 @@ package com.c2kernel.utils;
+import java.util.Enumeration;
+
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.lifecycle.ActivityDef;
import com.c2kernel.lifecycle.instance.stateMachine.StateMachine;
import com.c2kernel.lookup.DomainPath;
+import com.c2kernel.lookup.Path;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.persistency.outcome.Schema;
@@ -20,8 +23,29 @@ public class LocalObjectLoader { throws ObjectNotFoundException
{
DomainPath defRoot = new DomainPath(root);
- DomainPath defPath = (DomainPath)defRoot.find(name);
- return Gateway.getProxyManager().getProxy(defPath);
+ Enumeration<Path> e = Gateway.getLDAPLookup().search(defRoot, name);
+ ItemProxy defProxy = null; int currentLayer = -1;
+ while (e.hasMoreElements()) {
+ DomainPath defPath = (DomainPath)e.nextElement();
+ ItemProxy thisProxy = Gateway.getProxyManager().getProxy(defPath);
+ int thisLayer;
+ try {
+ String thisLayerProp = thisProxy.getProperty("Layer");
+ thisLayer = Integer.parseInt(thisLayerProp);
+ } catch (Exception ex) {
+ thisLayer = 0;
+ }
+ if (thisLayer > currentLayer) {
+ currentLayer = thisLayer;
+ defProxy = thisProxy;
+ }
+ else if (thisLayer == currentLayer) {
+ throw new ObjectNotFoundException("Duplicate definition for "+name+" in "+root+" found in Layer "+thisLayer, "");
+ }
+ }
+ if (defProxy == null)
+ throw new ObjectNotFoundException("No match for "+name+" in "+root, "");
+ return defProxy;
}
static public String getScript(String scriptName, int scriptVersion) throws ObjectNotFoundException {
diff --git a/src/main/resources/boot/OD/Module.xsd b/src/main/resources/boot/OD/Module.xsd index d25352e..c768e3f 100644 --- a/src/main/resources/boot/OD/Module.xsd +++ b/src/main/resources/boot/OD/Module.xsd @@ -9,6 +9,7 @@ <xs:sequence>
<xs:element name="Description" type="xs:string" />
<xs:element name="Version" type="xs:string" />
+ <xs:element name="Layer" type="xs:integer" minOccurs="0" default="0"/>
<xs:element name="Dependency" type="xs:string"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
diff --git a/src/main/resources/boot/property/CAProp.xml b/src/main/resources/boot/property/CAProp.xml index ac37ae7..b29884a 100644 --- a/src/main/resources/boot/property/CAProp.xml +++ b/src/main/resources/boot/property/CAProp.xml @@ -2,5 +2,6 @@ <PropertyDescription Name="Name" IsClassIdentifier="false" DefaultValue="" IsMutable="false"/>
<PropertyDescription Name="Complexity" IsClassIdentifier="true" DefaultValue="Composite" IsMutable="false"/>
<PropertyDescription Name="Type" IsClassIdentifier="true" DefaultValue="ActivityDesc" IsMutable="false"/>
+ <PropertyDescription Name="Layer" IsClassIdentifier="false" DefaultValue="0" IsMutable="true"/>
<PropertyDescription Name="Module" IsClassIdentifier="false" DefaultValue="" IsMutable="false"/>
</AllProperties>
diff --git a/src/main/resources/boot/property/EAProp.xml b/src/main/resources/boot/property/EAProp.xml index a345695..2477c93 100644 --- a/src/main/resources/boot/property/EAProp.xml +++ b/src/main/resources/boot/property/EAProp.xml @@ -2,5 +2,6 @@ <PropertyDescription Name="Name" IsClassIdentifier="false" DefaultValue="" IsMutable="false"/>
<PropertyDescription Name="Complexity" IsClassIdentifier="true" DefaultValue="Elementary" IsMutable="false"/>
<PropertyDescription Name="Type" IsClassIdentifier="true" DefaultValue="ActivityDesc" IsMutable="false"/>
+ <PropertyDescription Name="Layer" IsClassIdentifier="false" DefaultValue="0" IsMutable="true"/>
<PropertyDescription Name="Module" IsClassIdentifier="false" DefaultValue="" IsMutable="false"/>
</AllProperties>
diff --git a/src/main/resources/boot/property/ODProp.xml b/src/main/resources/boot/property/ODProp.xml index 894a6ee..f4d7b15 100644 --- a/src/main/resources/boot/property/ODProp.xml +++ b/src/main/resources/boot/property/ODProp.xml @@ -1,5 +1,6 @@ <AllProperties>
<PropertyDescription Name="Name" IsClassIdentifier="false" DefaultValue="" IsMutable="false"/>
<PropertyDescription Name="Type" IsClassIdentifier="true" DefaultValue="OutcomeDesc" IsMutable="false"/>
+ <PropertyDescription Name="Layer" IsClassIdentifier="false" DefaultValue="0" IsMutable="true"/>
<PropertyDescription Name="Module" IsClassIdentifier="false" DefaultValue="" IsMutable="false"/>
</AllProperties>
diff --git a/src/main/resources/boot/property/SCProp.xml b/src/main/resources/boot/property/SCProp.xml index f5de23c..9ff0366 100644 --- a/src/main/resources/boot/property/SCProp.xml +++ b/src/main/resources/boot/property/SCProp.xml @@ -1,5 +1,6 @@ <AllProperties>
<PropertyDescription Name="Name" IsClassIdentifier="false" DefaultValue="" IsMutable="false"/>
<PropertyDescription Name="Type" IsClassIdentifier="true" DefaultValue="Script" IsMutable="false"/>
+ <PropertyDescription Name="Layer" IsClassIdentifier="false" DefaultValue="0" IsMutable="true"/>
<PropertyDescription Name="Module" IsClassIdentifier="false" DefaultValue="" IsMutable="false"/>
</AllProperties>
diff --git a/src/main/resources/boot/property/SMProp.xml b/src/main/resources/boot/property/SMProp.xml index 8581e74..f43d0b5 100644 --- a/src/main/resources/boot/property/SMProp.xml +++ b/src/main/resources/boot/property/SMProp.xml @@ -1,5 +1,6 @@ <AllProperties>
<PropertyDescription Name="Name" IsClassIdentifier="false" DefaultValue="" IsMutable="false"/>
<PropertyDescription Name="Type" IsClassIdentifier="true" DefaultValue="StateMachine" IsMutable="false"/>
+ <PropertyDescription Name="Layer" IsClassIdentifier="false" DefaultValue="0" IsMutable="true"/>
<PropertyDescription Name="Module" IsClassIdentifier="false" DefaultValue="" IsMutable="false"/>
</AllProperties>
diff --git a/src/main/resources/mapFiles/ModuleMap.xml b/src/main/resources/mapFiles/ModuleMap.xml index 45f6cbe..440b852 100644 --- a/src/main/resources/mapFiles/ModuleMap.xml +++ b/src/main/resources/mapFiles/ModuleMap.xml @@ -38,6 +38,9 @@ <field name="version" direct="true" type="string">
<bind-xml name="Version" node="element" />
</field>
+ <field name="layer" direct="true" type="integer">
+ <bind-xml name="Layer" node="element" />
+ </field>
<field name="dependency" collection="arraylist" direct="true"
type="string">
<bind-xml name="Dependency" node="element" />
|
