From: <an...@us...> - 2009-02-09 15:00:28
|
Revision: 7355 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=7355&view=rev Author: anfarr Date: 2009-02-09 15:00:24 +0000 (Mon, 09 Feb 2009) Log Message: ----------- SFOS-1100 Added Paths: ----------- trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/ trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/components.sf trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/desiredstate/ trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/desiredstate/DesiredEvent.java trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/desiredstate/DesiredEventHandler.java trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/desiredstate/DesiredEventRecord.java trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/desiredstate/DesiredEventRegistration.java trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/examples/ trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/examples/TestBench.java trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/examples/hm.sf trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/examples/junk.sf trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/examples/junk2 trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/model/ trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/model/OrchComponentModel.java trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/model/OrchConn.java trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/model/OrchConstants.java trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/model/OrchVM.java trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/model/OrchVol.java trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/policy/ trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/policy/IntegrityConstraintHandler.java Added: trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/components.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/components.sf (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/components.sf 2009-02-09 15:00:24 UTC (rev 7355) @@ -0,0 +1,35 @@ +/** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ + +#include "org/smartfrog/services/dependencies/statemodel/components.sf" + +OrchComponentModel extends Model { + sfClass "org.smartfrog.services.orchcomponent.model.OrchComponentModel"; +} + +ChangeStatusEffects extends PolicyEffects { + effectOnStatus extends Effect { + key "status"; + path LAZY ostate; + update LAZY PARENT:status; + } +} + + Added: trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/desiredstate/DesiredEvent.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/desiredstate/DesiredEvent.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/desiredstate/DesiredEvent.java 2009-02-09 15:00:24 UTC (rev 7355) @@ -0,0 +1,63 @@ +package org.smartfrog.services.orchcomponent.desiredstate; + +import java.util.Vector; + +public class DesiredEvent { + + private Vector<DesiredEventPart> parts = new Vector<DesiredEventPart>(); + + public DesiredEvent(String context){ + initDesiredEvent(context); + } + + private void initDesiredEvent(String context){ + while(true){ + + //Get next part... + String rem=null; + int idx = context.indexOf(":"); + + if (idx!=-1){ + rem = context.substring(idx+1); + context = context.substring(0,idx); + } + + DesiredEventPart dep = new DesiredEventPart(); + parts.add(dep); + + //Variable? + idx = context.indexOf("?"); + if (idx==0){ + context = context.substring(1); + dep.variable=true; + } + + //Prefix + idx = context.indexOf("*"); + if (idx!=-1){ + context = context.substring(0, idx); + dep.prefix=true; + } + + //Key is remainder of context part... + dep.key = context; + + //Any more? + if (rem!=null) context=rem; + else break; //from while... + } + + } + + public Vector<DesiredEventPart> getParts(){ return this.parts; } + + public static class DesiredEventPart { + private String key; + private boolean prefix=false; + private boolean variable=false; + + public String getKey(){return key;} + public boolean isPrefix(){return prefix;} + public boolean isVariable(){return variable;} + } +} Added: trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/desiredstate/DesiredEventHandler.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/desiredstate/DesiredEventHandler.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/desiredstate/DesiredEventHandler.java 2009-02-09 15:00:24 UTC (rev 7355) @@ -0,0 +1,8 @@ +package org.smartfrog.services.orchcomponent.desiredstate; + +import org.smartfrog.sfcore.componentdescription.ComponentDescription; + + +public interface DesiredEventHandler { + public void handleDesiredEvent(ComponentDescription base); +} Added: trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/desiredstate/DesiredEventRecord.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/desiredstate/DesiredEventRecord.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/desiredstate/DesiredEventRecord.java 2009-02-09 15:00:24 UTC (rev 7355) @@ -0,0 +1,22 @@ +package org.smartfrog.services.orchcomponent.desiredstate; + +import org.smartfrog.sfcore.componentdescription.ComponentDescription; + +public class DesiredEventRecord { + private DesiredEvent eventInfo; + private ComponentDescription base; + private DesiredEventHandler handler; + + public DesiredEventRecord(DesiredEvent eventInfo, ComponentDescription base, DesiredEventHandler handler){ + this.eventInfo=eventInfo; this.base=base; this.handler=handler; + } + public DesiredEvent getDesiredEvent(){ + return this.eventInfo; + } + public ComponentDescription getCD(){ + return this.base; + } + public DesiredEventHandler getHandler(){ + return this.handler; + } +} Added: trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/desiredstate/DesiredEventRegistration.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/desiredstate/DesiredEventRegistration.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/desiredstate/DesiredEventRegistration.java 2009-02-09 15:00:24 UTC (rev 7355) @@ -0,0 +1,10 @@ +package org.smartfrog.services.orchcomponent.desiredstate; + +import java.util.Vector; + +import org.smartfrog.sfcore.componentdescription.ComponentDescription; + +public interface DesiredEventRegistration { + public void registerForInsertionEvents(DesiredEventRecord record); + public void deRegisterForEvents(DesiredEventHandler handler); +} Added: trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/examples/TestBench.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/examples/TestBench.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/examples/TestBench.java 2009-02-09 15:00:24 UTC (rev 7355) @@ -0,0 +1,486 @@ +package org.smartfrog.services.orchcomponent.examples; + +import java.rmi.RemoteException; +import java.util.Enumeration; +import java.util.Vector; + +import org.smartfrog.services.orchcomponent.desiredstate.DesiredEvent; +import org.smartfrog.services.orchcomponent.desiredstate.DesiredEventHandler; +import org.smartfrog.services.orchcomponent.desiredstate.DesiredEventRecord; +import org.smartfrog.services.orchcomponent.desiredstate.DesiredEventRegistration; +import org.smartfrog.services.orchcomponent.desiredstate.DesiredEvent.DesiredEventPart; +import org.smartfrog.services.orchcomponent.model.OrchComponentModel; +import org.smartfrog.services.orchcomponent.model.OrchConstants; +import org.smartfrog.sfcore.common.Context; +import org.smartfrog.sfcore.common.ContextImpl; +import org.smartfrog.sfcore.common.SmartFrogException; +import org.smartfrog.sfcore.componentdescription.ComponentDescription; +import org.smartfrog.sfcore.componentdescription.ComponentDescriptionImpl; +import org.smartfrog.sfcore.languages.sf.sfcomponentdescription.SFComponentDescriptionImpl; +import org.smartfrog.sfcore.prim.Prim; +import org.smartfrog.sfcore.prim.PrimImpl; +import org.smartfrog.sfcore.reference.Reference; +import org.smartfrog.sfcore.reference.ReferencePart; + +public class TestBench extends PrimImpl implements Prim, DesiredEventRegistration { + + private Vector<DesiredEventRecord> ders = new Vector<DesiredEventRecord>(); + private OrchComponentModel model; + + public TestBench() throws RemoteException{} + + public synchronized void sfStart() throws RemoteException, SmartFrogException { + //System.out.println("&&&&& IN TEST BENCH START &&&&&"); + super.sfStart(); + + try { model = (OrchComponentModel) sfResolve(new Reference(ReferencePart.here(OrchConstants.ORCH_ROOT)));} + catch (Exception sfre){/*Elaborate*/ /*System.out.println("OOPS"+sfre);*/ return;} + + //System.out.println("&&&&& MODEL &&&&"+model.sfContext()); + + new Thread(new TestBenchThread()).start(); + } + + public void registerForInsertionEvents(DesiredEventRecord record){ + this.ders.add(record); + } + + public void deRegisterForEvents(DesiredEventHandler handler){} + + private void matchAndHandleEvent(DesiredEvent de, ComponentDescription cd){ + for (DesiredEventRecord der : ders){ + Context matching = matchEvent(de, der.getDesiredEvent()); + if (matching!=null){ + ComponentDescription base = der.getCD(); + Enumeration en = matching.keys(); + while (en.hasMoreElements()) { + Object mkey = en.nextElement(); + base.sfContext().put(mkey, matching.get(mkey)); + } + //System.out.println("***Handling event..."+base); + der.getHandler().handleDesiredEvent(base); + } + } + } + + private Context matchEvent(DesiredEvent in, DesiredEvent ref){ + Context match= new ContextImpl(); + + Vector<DesiredEventPart> inParts = in.getParts(); + Vector<DesiredEventPart> refParts = (Vector<DesiredEventPart>) ref.getParts().clone(); + + //This is not quite the right logic for the final integration. + //Here we assume that insertions are registered as being made *at* the point of interest, + //although as the VM insertion instance exemplifies they can happen higher... + + for (DesiredEventPart inPart : inParts){ + DesiredEventPart refPart = null; + try{refPart = refParts.remove(0);}catch(Exception e){} + if (refPart==null) return match; //got it! + String refKey = refPart.getKey(); + String inKey = inPart.getKey(); + + //System.out.println("matchEvent: refKey, inKey:"+refKey+":"+inKey); + + if (refPart.isVariable()){ + if (refPart.isPrefix()){ + if (inKey.startsWith(refPart.getKey())){ + match.put(refKey,inKey); + } else return null; //no match... + } else match.put(refKey,inKey); + } else if (!refKey.equals(inKey)) return null; //no match... + } + + if (refParts.size()>0) return null; //no match against reference... + + //System.out.println("matchEvent: we have a match"); + + return match; + } + + private void updateModel(){ + model.runPrims(); + model.runNotifier(); + } + + public class TestBenchThread implements Runnable { + public void run(){ + //Recall: the managed component is *only* interested in insertions... + //Any injection event however leads to model.runIdle()... + + //Narrative 1 + + //System.out.println("In TestBenchThread"); + + //1 -- Insertion of VM record with status "off" + String insertionPt = "desired:vms"; + + //The following would just happen in reality... + ComponentDescription vmcd = new SFComponentDescriptionImpl(); + ComponentDescription fcd = new SFComponentDescriptionImpl(); + vmcd.sfContext().put("status", "off"); + vmcd.sfContext().put("vm_id", "vm_0"); + vmcd.sfContext().put("fc_id", "fc_0"); + vmcd.setParent(fcd); + fcd.sfContext().put("vm_0", vmcd); + ComponentDescription vmscd = null; + try { vmscd = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); } + catch (Exception e){/*System.out.println("ERROR NOW"+e);*//**/} + fcd.setParent(vmscd); + vmscd.sfContext().put("fc_0", fcd); + insertionPt += ":fc_0:vm_0"; //see comment above in "matchEvent"... + + DesiredEvent de = new DesiredEvent(insertionPt); + matchAndHandleEvent(de, vmcd); + + //FC_0, VM_1 + insertionPt = "desired:vms:fc_0"; + + //The following would just happen in reality... + fcd = null; + try { fcd = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); } + catch (Exception e){/*System.out.println("ERROR NOW"+e);*//**/} + vmcd = new SFComponentDescriptionImpl(); + vmcd.sfContext().put("status", "on"); + vmcd.sfContext().put("vm_id", "vm_1"); + vmcd.sfContext().put("fc_id", "fc_0"); + vmcd.setParent(fcd); + fcd.sfContext().put("vm_1", vmcd); + + insertionPt += ":vm_1"; //see comment above in "matchEvent"... + + de = new DesiredEvent(insertionPt); + matchAndHandleEvent(de, vmcd); + + insertionPt = "desired:vms"; + + //FC_1, VM_2 + vmcd = new SFComponentDescriptionImpl(); + fcd = new SFComponentDescriptionImpl(); + vmcd.sfContext().put("status", "on"); + vmcd.sfContext().put("vm_id", "vm_2"); + vmcd.sfContext().put("fc_id", "fc_1"); + vmcd.setParent(fcd); + fcd.sfContext().put("vm_2", vmcd); + vmscd = null; + try { vmscd = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); } + catch (Exception e){/*System.out.println("ERROR NOW"+e);*//**/} + fcd.setParent(vmscd); + vmscd.sfContext().put("fc_1", fcd); + insertionPt += ":fc_1:vm_2"; //see comment above in "matchEvent"... + + de = new DesiredEvent(insertionPt); + matchAndHandleEvent(de, vmcd); + + updateModel(); + + + //check that there is a component deployed + /* + try { + Prim orch = (Prim) model.sfContext().get("orchestration"); + Prim vms = (Prim) orch.sfContext().get("vms"); + Prim fc = (Prim) vms.sfContext().get("fc_0"); + Prim ovm = (Prim) fc.sfContext().get("vm_0"); + Prim vm = (Prim) ovm.sfContext().get("vm"); + String vmid = (String) vm.sfContext().get("vm_id"); + + System.out.println("VM deployed with id:"+vmid); + } catch(Exception e){System.out.println(e);return;} + */ + + //2 -- Insertion of Conn record with vm_id and vol_id + insertionPt = "desired:connections"; + + //The following would just happen in reality... + ComponentDescription conncd = new SFComponentDescriptionImpl(); + fcd = new SFComponentDescriptionImpl(); + conncd.sfContext().put("vol_id", "vol_0"); + conncd.sfContext().put("vm_id", "vm_0"); + conncd.sfContext().put("conn_id", "conn_0"); + conncd.sfContext().put("sm_id", "smfoo"); + conncd.sfContext().put("fc_id", "fc_0"); + conncd.setParent(fcd); + fcd.sfContext().put("conn_0", conncd); + ComponentDescription connscd = null; + try { connscd = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); } + catch (Exception e){/*System.out.println("ERROR NOW"+e);*//**/} + fcd.setParent(connscd); + connscd.sfContext().put("fc_0", fcd); + insertionPt += ":fc_0:conn_0"; //see comment above in "matchEvent"... + + de = new DesiredEvent(insertionPt); + matchAndHandleEvent(de, conncd); + + insertionPt = "desired:connections:fc_0"; + + conncd = new SFComponentDescriptionImpl(); + fcd = null; + try { fcd = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); } + catch (Exception e){/*System.out.println("ERROR NOW"+e);*//**/} + + conncd.sfContext().put("vol_id", "vol_0"); + conncd.sfContext().put("vm_id", "vm_0"); + conncd.sfContext().put("conn_id", "conn_1"); + conncd.sfContext().put("sm_id", "smfoo"); + conncd.sfContext().put("fc_id", "fc_0"); + conncd.setParent(fcd); + fcd.sfContext().put("conn_1", conncd); + insertionPt += ":conn_1"; //see comment above in "matchEvent"... + + de = new DesiredEvent(insertionPt); + matchAndHandleEvent(de, conncd); + + //check + /* + try { + Prim orch = (Prim) model.sfContext().get("orchestration"); + Prim conns = (Prim) orch.sfContext().get("connections"); + Prim fc = (Prim) conns.sfContext().get("fc_0"); + Prim oconn = (Prim) fc.sfContext().get("conn_0"); + Prim conn = (Prim) oconn.sfContext().get("conn"); + String connid = (String) conn.sfContext().get("conn_id"); + + System.out.println("Connection deployed with id:"+connid); + } catch(Exception e){System.out.println(e);return;} + */ + + //3 -- The adaptive injection which is to be managed at within eventreg (ie the real version of this) + //will cause an event to fire on volume record insertion into desired... Here, we simulate it... + insertionPt = "desired:volumes"; + + //The following would just happen in reality... + ComponentDescription volcd = new SFComponentDescriptionImpl(); + volcd.sfContext().put("vol_id", "vol_0"); + + ComponentDescription volscd = null; + try { volscd = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); } + catch (Exception e){/*System.out.println("ERROR NOW"+e);*//**/} + volcd.setParent(volscd); + volscd.sfContext().put("vol_0", volcd); + insertionPt += ":vol_0"; //see comment above in "matchEvent"... + + de = new DesiredEvent(insertionPt); + matchAndHandleEvent(de, volcd); + + updateModel(); + + //check + /*try { + Prim orch = (Prim) model.sfContext().get("orchestration"); + Prim vols = (Prim) orch.sfContext().get("volumes"); + Prim ovol = (Prim) vols.sfContext().get("vol_0"); + Prim vol = (Prim) ovol.sfContext().get("vol"); + String volid = (String) vol.sfContext().get("vol_id"); + + System.out.println("Volume deployed with id:"+volid); + } catch(Exception e){System.out.println(e);return;} + */ + + insertionPt = "desired:connectionGrants"; + //The following would just happen in reality... + conncd = new SFComponentDescriptionImpl(); + fcd = new SFComponentDescriptionImpl(); + conncd.sfContext().put("status", "grant"); + conncd.sfContext().put("vr_id", "vrid123"); + conncd.setParent(fcd); + fcd.sfContext().put("conn_0", conncd); + connscd = null; + try { connscd = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); } + catch (Exception e){/*System.out.println("ERROR NOW"+e);*//**/} + fcd.setParent(connscd); + connscd.sfContext().put("fc_0", fcd); + + insertionPt += ":fc_0:conn_0:status"; //see comment above in "matchEvent"... + de = new DesiredEvent(insertionPt); + matchAndHandleEvent(de, conncd); + + insertionPt += ":fc_0:conn_1:status"; //see comment above in "matchEvent"... + conncd = new SFComponentDescriptionImpl(); + conncd.sfContext().put("status", "grant"); + conncd.sfContext().put("vr_id", "vrid123"); + conncd.setParent(fcd); + fcd.sfContext().put("conn_1", conncd); + + de = new DesiredEvent(insertionPt); + matchAndHandleEvent(de, conncd); + + updateModel(); + + insertionPt = "desired:volumeRealizations"; + //The following would just happen in reality... + ComponentDescription vrcd = new SFComponentDescriptionImpl(); + vrcd.sfContext().put("vol_id", "vol_0"); + ComponentDescription vrs = null; + try { vrs = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); } + catch (Exception e){/*System.out.println("ERROR NOW"+e);*//**/} + vrcd.setParent(vrs); + vrs.sfContext().put("vrid123", vrcd); + insertionPt += ":vrid123"; + + de = new DesiredEvent(insertionPt); + matchAndHandleEvent(de, vrcd); + updateModel(); + + insertionPt = "desired:localDev"; + //The following would just happen in reality... + vrcd = new SFComponentDescriptionImpl(); + vrcd.sfContext().put("vol_id", "vol_0"); + vrs = null; + try { vrs = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); } + catch (Exception e){/*System.out.println("ERROR NOW"+e);*//**/} + vrcd.setParent(vrs); + vrs.sfContext().put("vrid123", vrcd); + insertionPt += ":vrid123"; + + de = new DesiredEvent(insertionPt); + matchAndHandleEvent(de, vrcd); + + insertionPt = "desired:vms:fc_0:vm_0"; + //The following would just happen in reality... + ComponentDescription vmcdOn = null; + try { vmcdOn = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); } + catch (Exception e){/*System.out.println("ERROR NOW"+e);*//**/} + vmcdOn.sfContext().put("status", "on"); + updateModel(); + + ComponentDescription vmstate = null; + while (true){ + insertionPt = "orchestration:vms:fc_0:vm_0:vm:ostate"; + try { + vmstate = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); + if (vmstate.sfContext().get("status").equals("started")) break; //from while... + else Thread.sleep(3000); + + }catch (Exception e){} + } + + + //Narrative 2 + + /*insertionPt = "desired:vms:fc_0:vm_0"; + //The following would just happen in reality... + vmcdOn = null; + try { vmcdOn = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); } + catch (Exception e){} + vmcdOn.sfContext().put("status", "off"); + updateModel(); + + vmstate = null; + while (true){ + insertionPt = "orchestration:vms:fc_0:vm_0:vm:ostate"; + try { + vmstate = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); + if (vmstate.sfContext().get("status").equals("stopped")) break; //from while... + else Thread.sleep(3000); + + }catch (Exception e){} + } + + insertionPt = "desired:vms:fc_0:vm_0"; + //The following would just happen in reality... + vmcdOn = null; + try { vmcdOn = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); } + catch (Exception e){} + vmcdOn.sfContext().put("status", "on"); + updateModel(); + + vmstate = null; + while (true){ + insertionPt = "orchestration:vms:fc_0:vm_0:vm:ostate"; + try { + vmstate = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); + if (vmstate.sfContext().get("status").equals("started")) break; //from while... + else Thread.sleep(3000); + + }catch (Exception e){} + }*/ + + //Narrative 4 (switched) + /*insertionPt = "desired:connectionGrants:fc_0:conn_0"; + + ComponentDescription cgrant = null; + try { cgrant = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); } + catch (Exception e){} + cgrant.sfContext().put("status", "failed"); + de = new DesiredEvent(insertionPt); + matchAndHandleEvent(de, cgrant); + updateModel(); + + ComponentDescription connstate = null; + while (true){ + insertionPt = "orchestration:connections:fc_0:conn_0:conn:ostate"; + try { + connstate = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); + if (connstate.sfContext().get("status").equals("requested")) break; //from while... + else Thread.sleep(3000); + }catch (Exception e){} + } + + insertionPt = "desired:connectionGrants:fc_0:conn_0"; + + cgrant = null; + try { cgrant = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); } + catch (Exception e){} + cgrant.sfContext().put("status", "grant"); + de = new DesiredEvent(insertionPt); + matchAndHandleEvent(de, cgrant); + updateModel(); + + vmstate = null; + while (true){ + insertionPt = "orchestration:vms:fc_0:vm_0:vm:ostate"; + try { + vmstate = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); + if (vmstate.sfContext().get("status").equals("started")) break; //from while... + else Thread.sleep(3000); + + }catch (Exception e){} + }*/ + + //Narrative 3 + /*insertionPt = "desired:connections:fc_0"; + + fcd = null; + try { fcd = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); } + catch (Exception e){} + fcd.sfContext().remove("conn_0"); + updateModel();*/ + + //Narrative 5 + /*insertionPt = "observed:vmStatus:fc_0:vm_0"; + + vmcd = null; + try { vmcd = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); } + catch (Exception e){} + vmcd.sfContext().put("power", "failed"); + updateModel(); + + try { Thread.sleep(10000); }catch (Exception e){} + + vmcd.sfContext().remove("power"); + updateModel(); + */ + + //Narrative 5b + /*insertionPt = "desired:vms:fc_0"; + + fcd = null; + try { fcd = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); } + catch (Exception e){} + fcd.sfContext().remove("vm_0"); + updateModel(); + */ + + //Narrative 6 + /*insertionPt = "desired:volumes"; + + fcd = null; + try { fcd = (ComponentDescription) model.sfResolve(Reference.fromString(insertionPt)); } + catch (Exception e){} + fcd.sfContext().remove("vol_0"); + updateModel();*/ + } + } + +} Added: trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/examples/hm.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/examples/hm.sf (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/examples/hm.sf 2009-02-09 15:00:24 UTC (rev 7355) @@ -0,0 +1,642 @@ +#include "/org/smartfrog/components.sf" +#include "/org/smartfrog/services/dependencies/statemodel/components.sf" +#include "/org/smartfrog/services/dependencies/threadpool/components.sf" +#include "/org/smartfrog/services/orchcomponent/components.sf" + +sfConfig extends Compound { + hm extends hostmanager{} + tp extends SimpleThreadPool { + sfProcessComponentName "threadpool"; + } + eventreg extends Prim { + sfClass "org.smartfrog.services.orchcomponent.examples.TestBench"; + root LAZY PARENT:hm:orchModel; + } +} + +hostmanager extends Compound { + orchModel extends hostmanagerWkr{} +} + +hostmanagerWkr extends OrchComponentModel { + + desired extends DATA { + vms extends DATA {} + connectionGrants extends DATA {} + connections extends DATA {} + volumes extends DATA {} + templates extends DATA { + vrInj extends DATA { + foo "123"; + } + vol extends DATA {} + } + volumeRealizations extends DATA {} + localDev extends DATA {} + } + + injectors extends DATA { + bar "456"; + } + + observed extends DATA { + connectionRequests extends DATA {} + vmStatus extends DATA {} + connectionStatus extends DATA {} + } + + integrityConstraints extends DATA { + + VMCreate extends DATA { + context "desired:vms:?fc_id:?vm_id"; + policies extends DATA { + createFarmRecordInOrchestration extends DynamicPolicyEvaluation { + exists extends PolicyRef { reference ("orchestration:vms:" ++ fc_id); } + guard (LAZY exists==NULL); + effects extends PolicyEffects { + path LAZY orchestration:vms; + key LAZY fc_id; + deployComponent LAZY orchestration:templates:oFC; + } + } + createFarmRecordInObserved extends DynamicPolicyEvaluation { + exists extends PolicyRef { reference ("observed:vmStatus:" ++ fc_id); } + guard (LAZY exists==NULL); + effects extends PolicyEffects { + path LAZY observed:vmStatus; + key LAZY fc_id; + update extends DATA {} + } + } + createVMStatusRecordInObserved extends DynamicPolicyEvaluation { + effects extends PolicyEffects { + path extends PolicyRef { reference ("observed:vmStatus:" ++ fc_id); } + key LAZY vm_id; + update extends DATA {} + } + } + + createOrchComponent extends DynamicPolicyEvaluation { + exists extends PolicyRef { reference ("orchestration:vms:" ++ fc_id ++ ":" ++ vm_id); } + guard (LAZY exists==NULL); + + effects extends PolicyEffects { + copyAndDeployVMTemplate extends DATA { + path extends PolicyRef { reference ("orchestration:vms:" ++ fc_id); } + key LAZY vm_id; + deployComponent LAZY orchestration:templates:oVM; + } + copyFarmId extends DATA { + path extends PolicyRef { reference ("orchestration:vms:" ++ fc_id ++ ":" ++ vm_id ++ ":vm");} + key "fc_id"; + update LAZY fc_id; + } + copyVMId extends DATA { + path extends PolicyRef { reference ("orchestration:vms:" ++ fc_id ++ ":" ++ vm_id ++ ":vm");} + key "vm_id"; + update LAZY vm_id; + } + constructRefInObserved extends DATA { + path extends PolicyRef { reference ("observed:vmStatus:" ++ fc_id ++ ":" ++ vm_id); } + key "status"; + update extends RawRef { reference ("orchestration:vms:" ++ fc_id ++ ":" ++ vm_id ++ ":vm:ostate"); } + } + } + } + } + } + + ConnCreate extends DATA { + context "desired:connections:?fc_id:?conn_id"; + policies extends DATA { + createFarmRecordInOrchestration extends DynamicPolicyEvaluation { + exists extends PolicyRef { reference ("orchestration:connections:" ++ fc_id); } + guard (LAZY exists==NULL); + effects extends PolicyEffects { + path LAZY orchestration:connections; + key LAZY fc_id; + deployComponent LAZY orchestration:templates:oFC; + } + } + createFarmRecordInObserved extends DynamicPolicyEvaluation { + exists extends PolicyRef { reference ("observed:connectionStatus:" ++ fc_id); } + guard (LAZY exists==NULL); + effects extends PolicyEffects { + path LAZY observed:connectionStatus; + key LAZY fc_id; + update extends DATA {} + } + } + + createConnStatusRecordInObserved extends DynamicPolicyEvaluation { + effects extends PolicyEffects { + path extends PolicyRef { reference ("observed:connectionStatus:" ++ fc_id); } + key LAZY conn_id; + update extends DATA {} + } + } + + createOrchComponent extends DynamicPolicyEvaluation { + exists extends PolicyRef { reference ("orchestration:connections:" ++ fc_id ++ ":" ++ conn_id); } + guard (LAZY exists==NULL); + + effects extends PolicyEffects { + copyAndDeployConnTemplate extends DATA { + path extends PolicyRef { reference ("orchestration:connections:" ++ fc_id); } + key LAZY conn_id; + deployComponent LAZY orchestration:templates:oConn; + } + copyFarmId extends DATA { + path extends PolicyRef { reference ("orchestration:connections:" ++ fc_id ++ ":" ++ conn_id ++ ":conn");} + key "fc_id"; + update LAZY fc_id; + } + copyConnId extends DATA { + path extends PolicyRef { reference ("orchestration:connections:" ++ fc_id ++ ":" ++ conn_id ++ ":conn");} + key "conn_id"; + update LAZY conn_id; + } + constructRefInObserved extends DATA { + path extends PolicyRef { reference ("observed:connectionStatus:" ++ fc_id ++ ":" ++ conn_id); } + key "status"; + update extends RawRef { reference ("orchestration:connections:" ++ fc_id ++ ":" ++ conn_id ++ ":conn:ostate"); } + } + copyVMId extends DATA { + vm_id extends PolicyRef { reference ("desired:connections:" ++ fc_id ++ ":" ++ conn_id ++ ":vm_id"); } + path extends PolicyRef { reference ("orchestration:connections:" ++ fc_id ++ ":" ++ conn_id ++ ":conn");} + key "vm_id"; + update LAZY vm_id; + } + } + } + + ConnWithoutStorageManagerEntry extends DynamicPolicyEvaluation { + sm_id extends PolicyRef { reference ("desired:connections:" ++ fc_id ++ ":" ++ conn_id ++ ":sm_id"); } + exists extends PolicyRef { reference ("observed:connectionRequests:" ++ sm_id); } + guard (LAZY exists==NULL); + + effects extends PolicyEffects { + path LAZY observed:connectionRequests; + key LAZY sm_id; + update extends DATA {}; + } + } + + ConnWithoutVol extends DynamicPolicyEvaluation { + vol_id extends PolicyRef { reference ("desired:connections:" ++ fc_id ++ ":" ++ conn_id ++ ":vol_id"); } + exists extends PolicyRef { reference ("desired:volumes:" ++ vol_id); } + guard (LAZY exists==NULL); + + effects extends PolicyEffects { + path LAZY desired:volumes; + key LAZY vol_id; + update LAZY desired:volumes:templates:vol; + } + } + } + } + + HandleGrant extends DATA { + context "desired:connectionGrants:?fc_id:?conn_id:status"; + policies extends DATA { + ReflectInObserved extends DynamicPolicyEvaluation { + effects extends PolicyEffects { + path extends PolicyRef { reference ("observed:connectionStatus:" ++ fc_id ++ ":" ++ conn_id); } + key "grantStatus"; //check + update extends PolicyRef { reference ("desired:connectionGrants:" ++ fc_id ++ ":" ++ conn_id ++ ":status"); } + } + } + ReflectInjector extends DynamicPolicyEvaluation { + vr_id extends PolicyRef { reference ("desired:connectionGrants:" ++ fc_id ++ ":" ++ conn_id ++ ":vr_id"); } + status extends PolicyRef { reference ("desired:connectionGrants:" ++ fc_id ++ ":" ++ conn_id ++ ":status"); } + exists extends PolicyRef { reference ( "injectors:" ++vr_id );} + guard ((LAZY status=="ok") && (exists==NULL)); + effects extends PolicyEffects { + path LAZY injectors; + key LAZY vr_id; //check + update LAZY desired:templates:vrInj; + } + } + } + } + + VolCreate extends DATA { + context "desired:volumes:?vol_id"; + policy extends DynamicPolicyEvaluation { + exists extends PolicyRef { reference ("orchestration:volumes:" ++ vol_id); } + guard (LAZY exists==NULL); + + effects extends PolicyEffects { + copyAndDeployVolTemplate extends DATA { + path LAZY orchestration:volumes; + key LAZY vol_id; + deployComponent LAZY orchestration:templates:oVol; + } + copyVolId extends DATA { + path extends PolicyRef { reference ("orchestration:volumes:" ++ vol_id ++ ":vol");} + key "vol_id"; + update LAZY vol_id; + } + } + } + } + + VolumeRealizationLinkToVolume extends DATA { + context "desired:volumeRealizations:?vr_id"; + policy extends DynamicPolicyEvaluation { + vol_id extends PolicyRef { reference ("desired:volumeRealizations:" ++ vr_id ++ ":vol_id"); } + exists extends PolicyRef { reference ("orchestration:volumes:" ++ vol_id ++ ":vol:ostate:vr_id"); } + guard (LAZY exists==NULL); + + effects extends PolicyEffects { + path extends PolicyRef { reference ("orchestration:volumes:" ++ vol_id ++ ":vol:ostate"); } + key "vr_id"; + update LAZY vr_id; + } + } + } + } + + orchestration extends Composite { + + vms extends Composite{} + connections extends Composite{} + volumes extends Composite{} + + templates extends DATA { + + oFC extends Composite {} + + oVM extends CompositeWithSync { + vm extends StateComponent { + sfClass "org.smartfrog.services.orchcomponent.model.OrchVM"; + //sfClass "org.smartfrog.sfcore.prim.PrimImpl"; + dstate extends PolicyRef { reference ("desired:vms:" ++ fc_id ++ ":" ++ vm_id); } + + ostate extends DATA { + status "pending"; //"started", "stopping", "stopped" + } + + //Narrative 1 + pendingToStarted extends Transition { + guard (LAZY ostate:status=="pending"); + + //INVOKE RULES TABLES MODIFICATION + //CALL VMSTART() + + effects extends ChangeStatusEffects { //UPDATE STATUS TO STARTED + status "started"; + } + } + + //Narrative 2 + startedToStopping extends Transition { + guard (LAZY ostate:status=="started"); + effects extends ChangeStatusEffects { //UPDATE STATUS TO STOPPING + status "stopping"; + } + } + + stoppingToStopped extends Transition { + guard (LAZY ostate:status=="stopping"); + + //INVOKE VMSTOP(), if (!observed:vmStatus:?fc_id:?vm_id:power=="failed") + //Async. + + effects extends ChangeStatusEffects { //UPDATE STATUS TO STOPPED + status "stopped"; + /*movePowerToStopped extends Effect { + path extends PolicyRef { reference ("observed:vmStatus:" ++ fc_id ++ ":" ++ vm_id); } + key "power"; + update "stopped"; + }*/ + } + } + + //Narrative 4 + stoppedToPending extends Transition { + guard (LAZY ostate:status=="stopped"); + + effects extends ChangeStatusEffects { //UPDATE STATUS TO PENDING + status "pending"; + } + } + + //Narrative 5 + stoppedToTerminating extends Transition { + guard (LAZY ostate:status=="stopped"); + + effects extends ChangeStatusEffects { //UPDATE STATUS TO TERMINATING + status "terminating"; + } + } + + } + + //Narrative 1 + vmStartDesiredDependency extends Dependency { + by LAZY vm; + relevant (LAZY by:ostate:status=="pending"); + enabled (LAZY by:dstate:status=="on"); + } + + vmStartConnDependency extends Dependency { + on LAZY vmStartConnsAnd; + by LAZY vm; + relevant (LAZY by:ostate:status=="pending"); + enabled true; + } + + vmStartConnsAnd extends AndConnectorExists{} + + //Narrative 2 + vmStoppingDependency extends Dependency { + on LAZY vmStoppingOr; + by LAZY vm; + relevant (LAZY by:ostate:status=="started"); + enabled true; + } + + vmStoppingOr extends OrConnector; + + vmStoppingDesiredDependency extends Dependency { + by LAZY vmStoppingOr; + enabled (LAZY vm:dstate:status=="off"); + } + + vmStoppingPowerFailedDependency extends Dependency { + powerStatus extends PolicyRef { reference ("observed:vmStatus:" ++ vm:fc_id ++ ":" ++ vm:vm_id ++ ":power") }; + by LAZY vmStoppingOr; + enabled (LAZY powerStatus=="failed"); + } + + vmStoppingConnOr extends OrConnectorExists; + + vmStoppingConnOrDependency extends Dependency { + on LAZY vmStoppingConnOr; + by LAZY vmStoppingOr; + enabled true; + } + + vmStoppingRemovedDependency extends Dependency { + exists extends PolicyRef { reference ("desired:vms:" ++ vm:fc_id ++ ":" ++ vm:vm_id) }; + by LAZY vmStoppingOr; + relevant (LAZY by:ostate:status=="started"); + enabled (LAZY exists==NULL); + } + + //Narrative 4 + vmPendingDesiredDependency extends Dependency { + by LAZY vm; + transition "stoppedToPending"; + relevant (LAZY by:ostate:status=="stopped"); + enabled (LAZY by:dstate:status=="on"); + } + + vmPendingDependency extends Dependency { + on LAZY vmPendingConnsAnd; + by LAZY vm; + transition "stoppedToPending"; + relevant (LAZY by:ostate:status=="stopped"); + enabled true; + } + + vmPendingConnsAnd extends AndConnectorExists; + + //Narrative 5 + stoppedToTerminatingDependency extends Dependency { + exists extends PolicyRef { reference ("desired:vms:" ++ vm:fc_id ++ ":" ++ vm:vm_id); } + by LAZY vm; + transition "stoppedToTerminating"; + relevant (LAZY by:ostate:status=="stopped"); + enabled (LAZY exists==NULL); + } + + terminatingToTerminated extends CompositeTerminator { + terminateCond (LAZY vm:ostate:status=="terminating"); + } + + } + + oConn extends CompositeWithSync { + conn extends StateComponent { + sfClass "org.smartfrog.services.orchcomponent.model.OrchConn"; + //sfClass "org.smartfrog.sfcore.prim.PrimImpl"; + dstate extends PolicyRef { reference ("desired:connections:" ++ fc_id ++ ":" ++ conn_id); } + + ostate extends DATA { + status "pending"; //"requested", "ok", "removing", "failing", "terminating" + } + + //Narrative 1 + pendingToRequested extends Transition { + guard (LAZY ostate:status=="pending"); + effects extends ChangeStatusEffects { //UPDATE STATUS TO REQUESTED + status "requested"; + recordConnectionRequestId extends Effect { + path LAZY ostate; + key "connreq_id"; + update "insertgenerateConIdFuncCall"; + } + addConnectionRequest extends Effect { + path extends PolicyRef { reference ("observed:connectionRequests:" ++ dstate:sm_id); } + key LAZY ostate:connreq_id; + update extends DATA {}; + } + } + } + + requestedToOk extends Transition { + guard (LAZY ostate:status=="requested"); + + //INVOKE ADDDEVICE() + + effects extends ChangeStatusEffects { //UPDATE STATUS TO OK + status "ok"; + } + } + + //Narrative 3 + okToRemoving extends Transition { + guard (LAZY ostate:status=="ok"); + effects extends ChangeStatusEffects { //UPDATE STATUS TO REMOVING + status "removing"; + } + } + + removingToTerminating extends Transition { + guard (LAZY ostate:status=="removing"); + + //CALL REMOVE DEVICE + + effects extends ChangeStatusEffects { //UPDATE STATUS TO TERMINATING + status "terminating"; + removeConnectionRequest extends Effect { + path extends PolicyRef { reference ("observed:connectionRequests:" ++ dstate:sm_id); } + key LAZY ostate:connreq_id; + } + } + } + + //Narrative 4 + okToFailing extends Transition { + guard (LAZY ostate:status=="ok"); + effects extends ChangeStatusEffects { //UPDATE STATUS TO FAILING + status "failing"; + } + } + + failingToPending extends Transition { + guard (LAZY ostate:status=="failing"); + + //CALL REMOVE DEVICE + + effects extends ChangeStatusEffects { //UPDATE STATUS TO PENDING + status "pending"; + removeConnectionRequest extends Effect { + path extends PolicyRef { reference ("observed:connectionRequests:" ++ dstate:sm_id); } + key LAZY ostate:connreq_id; + } + } + } + } + + //Narrative 1 + connOnVolAvailableDependency extends Dependency { + by LAZY conn; + on extends PolicyRef { reference ("orchestration:volumes:" ++ conn:dstate:vol_id ++ ":vol"); } + relevant (LAZY by:ostate:status=="requested"); + enabled (LAZY on:ostate:status=="ok"); + } + + connOkDependency extends Dependency { + on extends PolicyRef { reference ("desired:connectionGrants:" ++ conn:fc_id ++ ":" ++ conn:conn_id); } + by LAZY conn; + relevant (LAZY by:ostate:status=="requested"); + enabled (LAZY on:status=="grant"); + } + + vmStartConnDependency extends Dependency { + on LAZY conn; + by extends PolicyRef { reference ("orchestration:vms:" ++ conn:fc_id ++ ":" ++ conn:dstate:vm_id ++ ":vmStartConnsAnd"); } + relevant (LAZY on:ostate:status!="ok"); + enabled false; + } + + //Narrative 2 + vmStoppingConnDependency extends Dependency { + on LAZY conn; + by extends PolicyRef { reference ("orchestration:vms:" ++ conn:fc_id ++ ":" ++ conn:dstate:vm_id ++ ":vmStoppingConnOr"); } + relevant (LAZY on:ostate:status=="ok"); + enabled false; + } + + //Narrative 3 + okToRemovingDependency extends Dependency { + exists extends PolicyRef { reference ("desired:connections:" ++ conn:fc_id ++ ":" ++ conn:conn_id); } + by LAZY conn; + transition "okToRemoving"; + relevant (LAZY by:ostate:status=="ok"); + enabled (LAZY exists==NULL); + } + + connOnVMStoppedDependency extends Dependency { + by LAZY conn; + on extends PolicyRef { reference ("orchestration:vms:" ++ conn:fc_id ++ ":" ++ conn:vm_id ++ ":vm"); } + relevant ((LAZY by:ostate:status=="removing") || (LAZY by:ostate:status=="failing")); + enabled (LAZY on:ostate:status=="stopped"); + } + + terminatingToTerminated extends CompositeTerminator { + terminateCond (LAZY conn:ostate:status=="terminating"); + } + + //Narrative 4 + okToFailingDependency extends Dependency { + on extends PolicyRef { reference ("desired:connectionGrants:" ++ conn:fc_id ++ ":" ++ conn:conn_id); } + by LAZY conn; + transition "okToFailing"; + relevant (LAZY by:ostate:status=="ok"); + enabled (LAZY on:status=="failed"); + } + + vmPendingConnDependency extends Dependency { + on LAZY conn; + by extends PolicyRef { reference ("orchestration:vms:" ++ conn:fc_id ++ ":" ++ conn:dstate:vm_id ++ ":vmPendingConnsAnd"); } + relevant ( (LAZY on:ostate:status!="ok") && (LAZY on:ostate:status!="pending" )); + enabled false; + } + + } + + oVol extends CompositeWithSync { + vol extends StateComponent { + sfClass "org.smartfrog.services.orchcomponent.model.OrchVol"; + //sfClass "org.smartfrog.sfcore.prim.PrimImpl"; + dstate extends PolicyRef { reference ("desired:volumes:" ++ vol_id); } + + ostate extends DATA { + status "pending"; //"realizing", "ok" + } + + //Narrative 1 + pendingToRealizing extends Transition { + guard (LAZY ostate:status=="pending"); + + //HARDCODED API CALL TO VOLUMEREALIZER + + effects extends ChangeStatusEffects { //UPDATE STATUS TO REALIZING + status "realizing"; + } + } + + realizingToOk extends Transition { + guard (LAZY ostate:status=="realizing"); + + effects extends ChangeStatusEffects { //UPDATE STATUS TO OK + status "ok"; + } + } + + //Narrative 6 + okToTerminating extends Transition { + guard (LAZY ostate:status=="ok"); + + effects extends ChangeStatusEffects { //UPDATE STATUS TO TERMINATING + status "terminating"; + } + } + + } + + //Narrative 1 + volRealizingDependency extends Dependency { + exists extends PolicyRef { reference ("desired:volumeRealizations:" ++ vol:ostate:vr_id); } + by LAZY vol; + relevant (LAZY by:ostate:status=="pending"); + enabled (LAZY exists!=NULL); + } + + volOkDependency extends Dependency { + exists extends PolicyRef { reference ("desired:localDev:" ++ vol:ostate:vr_id); } + by LAZY vol; + relevant (LAZY by:ostate:status=="realizing"); + enabled (LAZY exists!=NULL); + } + + //Narrative 6 + terminatingToTerminated extends CompositeTerminator { + terminateCond (LAZY vol:ostate:status=="terminating"); + } + + okToTerminatingDependency extends Dependency { + exists extends PolicyRef { reference ("desired:volumes:" ++ vol:vol_id); } + by LAZY vol; + relevant (LAZY by:ostate:status=="ok"); + enabled (LAZY exists==NULL); + } + } + } + } +} + Added: trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/examples/junk.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/examples/junk.sf (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/orchcomponent/examples/junk.sf 2009-02-09 15:00:24 UTC (rev 7355) @@ -0,0 +1,372 @@ + + + + + +/* + ReflectGrantInObserved extends DATA { + context "desired:connections:connectionGrants:?fc_id:?conn_id:status"; + grantstatus extends LazyRef { reference ("desired:connections:connectionGrants:" ++ fc_id ++ ":" + conn_id ++ ":status"); } + effects extends LazyApplyEffects { + reflectState extends DATA { + path -- extends LazyRef { reference ("observed:connectionStatus:" ++ fc_id ++ ":" ++ conn_id); } + key "grant"; + update LAZY grantstatus; + } + } + } + ConnWithoutVol extends DATA { + invariant extends DATA { + context "desired:connections:?fc_id:?conn_id"; + vol_id extends LazyRef { reference ("desired:connections:" ++ fc_id ++ ":" ++ conn_id ++ ":vol_id"); } + exists extends LazyRef { reference ("desired:volumes:" ++ vol_id); } + pred LAZY exists!=NULL; + } + enforcedBy extends DATA { + -- LAZY VolFromConn; + } + } + + GrantWithoutVRInj extends IntegrityConstraint { + invariant extends DATA { + context "desired:connections:connectionGrants:?fc_id:?conn_id"; + status extends LazyRef { reference ("desired:connections:connectionGrants:" ++ fc_id ++ ":" ++ conn_id ++ ":status"); } + vr_id extends LazyRef { reference ("desired:connections:connectionGrants:" ++ fc_id ++ :" ++ conn_id ++ ":vr_id"); } + exists extends LazyRef { reference ("vrInjectors:" ++ vr_id); } + pred (LAZY status=="ok" -> exists!=NULL); + } + enforcedBy extends DATA { + -- LAZY VRInjFromGrant; + } + } +*/ +/* + VolFromConn extends DATA { + context "desired:connections:?fc_id:?conn_id"; + vol_id extends LazyRef { reference ("desired:connections:"++ fc_id ++ ":" + conn_id ++ "vol_id"); } + effects extends LazyApplyEffects { + createVolEntry extends DATA { + path LAZY desired:volumes; + key LAZY vol_id; + update LAZY desired:volumes:templates:vol; + } + } + } + + VRInjFromGrant extends DATA { + context "desired:connections:connectionGrants:?fc_id:?conn_id:status"; + vr_id extends LazyRef { reference ("desired:connections:connectionGrants:" ++ fc_id ++ :" ++ conn_id ++ ":vr_id"); } + effects extends LazyApplyEffects { + createInjector extends DATA { + path LAZY vrInjectors; + key LAZY vr_id; + update LAZY desired:volumes:templates:vrInj; + } + } + } +*/ + + + /*connCreate extends DATA { + context "desired:connections:?fc_id:?conn_id"; + effects extends LazyApplyEffects { + copyAndDeployConnTemplate extends DATA { + path extends LazyRef { reference ("orchestration:connections:" ++ fc_id); } + key LAZY conn_id; + update LAZY templates:oConn; + } + copyFarmId extends DATA { + path extends LazyRef { reference ("orchestration:connections:" ++ fc_id ++ ":" ++ conn_id ++ "conn");} + key "fc_id"; + update LAZY fc_id; + } + copyConnId extends DATA { + path extends LazyRef { reference ("orchestration:vms:" ++ fc_id ++ ":" ++ conn_id ++ "conn");} + key "conn_id"; + update LAZY conn_id; + } + } + } + + volCreate extends DATA { + context -- "desired:volumes:?vol_id"; + effects extends LazyApplyEffects { + copyAndDeployVolTemplate extends DATA { + path LAZY orchestration:volumes"; + key LAZY vol_id; + update LAZY templates:oVol; + } + copyVolId extends DATA { + path extends LazyRef { reference ("orchestration:volumes:" ++ vol_id ++ "vol");} + key "vol_id"; + update LAZY vol_id; + } + } + }*/ + + +/* pendingToStarted extends Transition { + guard (LAZY ostate:status=="pending"); + + //INVOKE RULES TABLES MODIFICATION + //CALL VMSTART() + + effects extends ChangeStatusEffects { //UPDATE STATUS TO STARTING + update "starting"; + } + } + + startedToStopping extends Transition { + guard (LAZY ostate:status=="started"); + effects extends ChangeStatusEffects { //UPDATE STATUS TO STOPPING + update "stopping"; + } + } + + stoppingToStopped extends Transition { + guard (LAZY ostate:status=="stopping"); + + //INVOKE VMSTOP(), if (!observed:vmStatus:?fc_id:?vm_id:power=="failed") + //Async. + + effects extends ChangeStatusEffects { //UPDATE STATUS TO STOPPED + update "stopped"; + movePowerToStopped extends DATA { + path extends LazyRef { reference ("observed:vmStatus" ++ fc_id ++ ":" ++ vm_id); } + key "power"; + update LAZY PARENT:update; + } + } + } + + stoppedToPending extends Transition { + guard (LAZY ostate:status=="stopped"); + + effects extends ChangeStatusEffects { //UPDATE STATUS TO PENDING + update "pending"; + } + } + + } + + stoppedToTerminate extends CompositeTerminator { + terminateCond (LAZY vm:ostate:status=="stopped"); + } + + + + + vmPendingDesiredDependency extends Dependency { + by LAZY vm; + relevant (LAZY by:ostate:status=="stopped"); + enabled (LAZY by:dstate:status=="on"); + } + + vmPendingDependency extends Dependency { + on LAZY vmPendingConnsAnd; + by LAZY vm; + relevant (LAZY by:ostate:status=="stopped"); + enabled true; + } + + vmStartConnsAnd extends AndConnectorExists; + vmPendingConnsAnd extends AndConnectorExists; + + vmTerminateDependency extends Dependency { + on extends LazyRef { reference ("desired:vms:" ++ fc_id ++ ":" ++ vm_id) }; + by LAZY vm; + relevant (LAZY by:ostate:status=="stopped"); + enabled (LAZY on!=NULL); + } + } + + + + /* + oConn extends Composite{ + conn extends StateComponent { + sfClass "org.smartfrog.services.orchcomponent.examples.oConn"; + dstate extends LazyRef { reference ("desired:connections:" ++ fc_id ++ conn_id); } + + ostate extends DATA { + sfReflectState extends DATA { + path extends LazyRef { reference ("observed:connectionStatus" ++ fc_id); } + key LAZY conn_id; + toreflect extends LazyRef { reference ("orchestration:connections:" ++ fc_id + ":" +conn_id ++ ":conn:ostate"); } + } + status "pending"; //"requested", "ok", "removing", "failing", "terminating" + } + + pendingToRequested extends Transition { + guard (LAZY ostate:status=="pending"); + + effects extends ChangeStatusEffects { //UPDATE STATUS TO REQUESTED + update "requested"; + recordConnectionRequestId extends DATA { + path LAZY ostate; + key "connreq_id"; + update extends GenConId { //NOTE ATTRIBUTE NAME + -- LAZY dstate:conn_id; + } + } + addConnectionRequest extends DATA { + path extends LazyRef { reference ("observed:connectionRequests" ++ dstate:sm_id); } + key LAZY connreq_id; + update extends DATA {}; + } + } + } + + + + okToFailing extends Transition { + guard (LAZY ostate:status=="ok"); + effects extends ChangeStatusEffects { //UPDATE STATUS TO FAILING + update "failing"; + } + } + + failingToPending extends Transition { + guard (LAZY ostate:status=="failing"); + + //CALL REMOVE DEVICE + + effects extends ChangeStatusEffects { //UPDATE STATUS TO PENDING + update "pending"; + removeConnectionRequest extends DATA { + path extends LazyRef { reference ("observed:connectionRequests" ++ dstate:sm_id); } + key LAZY connreq_id; + } + } + + } + } + + terminatingToTerminate extends CompositeTerminator { + guard (conn:ostate:status=="terminating"); + } + + + connOnVMStoppedDependency extends Dependency { + by LAZY conn; + on extends LazyRef { reference ("vms:" ++ LAZY fc_id ++ ":" ++ dstate:vm_id ++ ":vm"); } + relevant (LAZY by:ostate:status=="removing" || by:ostate:status=="failing"); + enabled (LAZY on:... [truncated message content] |