From: <sf...@us...> - 2016-07-28 16:37:08
|
Revision: 8888 http://sourceforge.net/p/smartfrog/svn/8888 Author: sfpcg Date: 2016-07-28 16:37:04 +0000 (Thu, 28 Jul 2016) Log Message: ----------- Added Paths: ----------- trunk/core/smartfrog/src/org/smartfrog/services/automation/ trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/ trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/Image.java trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/VM.java trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/app.sf trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/array.sf trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/arrayConnector.sf trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/image.sf trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/messages.sf trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/pair.sf trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/pairFailure.sf trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/pairOrdered.sf trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/pairVersioning.sf trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/sequence.sf trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/vm.sf trunk/core/smartfrog/src/org/smartfrog/services/automation/rabbitmq/ trunk/core/smartfrog/src/org/smartfrog/services/automation/rabbitmq/Receiver.java trunk/core/smartfrog/src/org/smartfrog/services/automation/rabbitmq/Sender.java trunk/core/smartfrog/src/org/smartfrog/services/automation/rabbitmq/components.sf trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/ trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/components.sf trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/connector/ trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/connector/AndConnector.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/connector/NandConnector.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/connector/NorConnector.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/connector/OrConnector.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/dependency/ trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/dependency/Relation.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/dependency/RelationValidation.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/exceptions/ trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/exceptions/SmartFrogStateException.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/exceptions/SmartFrogStateLifecycleException.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/modeltermination/ trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/modeltermination/ModelTermination.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/state/ trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/state/Composite.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/state/Model.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/state/NWayComposite.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/state/NotificationLock.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/state/State.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/state/StateChangeNotification.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/state/StateDependencies.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/state/StateHolder.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/state/StateSaving.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/state/StateSetting.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/state/ThreadedState.java trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/utils/ trunk/core/smartfrog/src/org/smartfrog/services/automation/statemodel/utils/CDUtil.java trunk/core/smartfrog/src/org/smartfrog/services/automation/threadpool/ trunk/core/smartfrog/src/org/smartfrog/services/automation/threadpool/ThreadPool.java trunk/core/smartfrog/src/org/smartfrog/services/automation/threadpool/ThreadPoolImpl.java trunk/core/smartfrog/src/org/smartfrog/services/automation/threadpool/ThreadPoolTester.java trunk/core/smartfrog/src/org/smartfrog/services/automation/threadpool/components.sf trunk/core/smartfrog/src/org/smartfrog/services/automation/threadpool/threadpool.sf Added: trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/Image.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/Image.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/Image.java 2016-07-28 16:37:04 UTC (rev 8888) @@ -0,0 +1,151 @@ +/** (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 + +*/ +package org.smartfrog.services.automation.examples; + +import java.rmi.RemoteException; +import java.util.HashMap; +import java.util.Random; +import java.util.Vector; + +import org.smartfrog.services.automation.statemodel.state.State; +import org.smartfrog.services.automation.threadpool.ThreadPool; +import org.smartfrog.sfcore.common.Context; +import org.smartfrog.sfcore.common.SmartFrogException; +import org.smartfrog.sfcore.prim.Prim; +import org.smartfrog.sfcore.prim.TerminationRecord; + +public class Image extends State implements Prim { + + String name = ""; + String image = ""; + String status = "deleted"; + int threadDelay = 5000; + + Thread deleteThread = null; + Thread createThread = null; + + Object threadlock = new Object(); + + public Image() throws RemoteException {super();} + + public synchronized void sfDeploy() throws RemoteException, SmartFrogException { + super.sfDeploy(); + name = sfCompleteNameSafe().toString(); + image = (String) sfResolve("image", image, false); + status = (String) sfResolve("status", status, false); + threadDelay = ((Integer) sfResolve("threadDelay", threadDelay, false)).intValue(); + } + + public void sfTerminateWith (TerminationRecord tr) { + if (deleteThread != null) { + deleteThread.interrupt(); + } + if (createThread != null) { + createThread.interrupt(); + } + super.sfTerminateWith(tr); + } + + public void setState(HashMap data){ + String desiredStatus = (String) data.get("desiredStatus"); + String desiredImage = (String) data.get("desiredImage"); + String status = (String) data.get("status"); + + if ( status.equals("deleted") && desiredStatus.equals("created") && !desiredImage.equals("")) { + create(desiredImage); + return; + } + + if ((!status.equals("deleted")) && (!status.equals("deleting")) && desiredStatus.equals("deleted")) { + delete(); + return; + } + + //System.out.println(name + ": no changes"); + return; //no changes + } + + + private void delete() { + HashMap save = new HashMap(); + System.out.println(name + ": deleting image"); + if (createThread != null) { + createThread.interrupt(); + createThread = null; + } + deleteThread = new Thread() { + public void run() { + HashMap save = new HashMap(); + try {Thread.sleep(threadDelay);} catch (Exception e) { return; } + + synchronized (threadlock) { + System.out.println(name + ": image deleted"); + save.put("status", "deleted"); + save.put("baseImage", ""); + save.put("image", ""); + saveState(save); + + deleteThread = null; + } + } + }; + deleteThread.start(); + + save.put("status", "deleting"); + saveState(save); + } + + + private void create(String baseImage) { + HashMap save = new HashMap(); + String imagename = baseImage + "." + imageId(); + System.out.println(name + ": creating image " + imagename); + if (deleteThread != null) { + deleteThread.interrupt(); + deleteThread = null; + } + + createThread = new Thread() { + public void run() { + HashMap save = new HashMap(); + try {Thread.sleep(threadDelay);} catch (Exception e) { return; } + + synchronized (threadlock) { + System.out.println(name + ": created image " + image); + save.put("status", "created"); + saveState(save); + + createThread = null; + } + } + }; + createThread.start(); + + save.put("image", imagename); + save.put("baseImage", baseImage); + save.put("status", "creating"); + saveState(save); + } + + Random rn = new Random(); + private int imageId() { + return rn.nextInt(100000000); + } +} Added: trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/VM.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/VM.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/VM.java 2016-07-28 16:37:04 UTC (rev 8888) @@ -0,0 +1,215 @@ +/** (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 + +*/ +package org.smartfrog.services.automation.examples; + +import java.rmi.RemoteException; +import java.util.HashMap; +import java.util.Random; +import java.util.Vector; + +import org.smartfrog.services.automation.statemodel.state.State; +import org.smartfrog.services.automation.threadpool.ThreadPool; +import org.smartfrog.sfcore.common.Context; +import org.smartfrog.sfcore.common.SmartFrogException; +import org.smartfrog.sfcore.prim.Prim; +import org.smartfrog.sfcore.prim.TerminationRecord; + +public class VM extends State implements Prim { + + String name = ""; + String status = "deleted"; + int threadDelay = 5000; + int failureFrequency = 0; + int checkFrequency = 1; + + Random rn = new Random(); + + Thread failureThread = null; + Thread deleteThread = null; + Thread createThread = null; + Object threadlock = new Object(); + + public VM() throws RemoteException {super();} + + public synchronized void sfDeploy() throws RemoteException, SmartFrogException { + super.sfDeploy(); + name = sfCompleteNameSafe().toString(); + status = (String) sfResolve("status", status, false); + threadDelay = ((Integer) sfResolve("threadDelay", threadDelay, false)).intValue(); + failureFrequency = ((Integer) sfResolve("failureFrequency", failureFrequency, false)).intValue(); + checkFrequency = ((Integer) sfResolve("checkFrequency", checkFrequency, false)).intValue(); + } + + public void sfTerminateWith (TerminationRecord tr) { + stopThreads(); + super.sfTerminateWith(tr); + } + + public void setState(HashMap data){ + //System.out.println(name + " " + data); + String desiredStatus = (String) data.get("desiredStatus"); + String status = (String) data.get("status"); + + if (status.equals("failed") && desiredStatus.equals("deleted")) { + reset(); + return; + } + + if (status.equals("deleted") && desiredStatus.equals("created")) { + create(); + return; + } + + if ((!status.equals("deleted")) && desiredStatus.equals("deleted")) { + delete(); + return; + } + + return; //no changes + + } + + + private void delete() { + stopThreads(); + HashMap save = new HashMap(); + System.out.println(name + ": deleting vm"); + + deleteThread = new Thread() { + public void run() { + HashMap save = new HashMap(); + + try {Thread.sleep(threadDelay);} catch (Exception e) { return; } + synchronized(threadlock) { + try { + status = (String) sfResolve("status", status, false); + if (status.equals("failed")) return; + } catch (Exception e) {} + + System.out.println(name + ": deleted vm"); + save = new HashMap(); + save.put("status", "deleted"); + saveState(save); + deleteThread = null; + } + } + }; + deleteThread.start(); + + save.put("status", "deleting"); + saveState(save); + + } + + + private void create() { + stopThreads(); + HashMap save = new HashMap(); + System.out.println(name + ": creating vm"); + + String image = ""; + try { image = (String) sfResolve("image", "", false); } catch (Exception e) {} + if (image.equals("")) { + System.out.println(name + ": failed to create VM as image is non-existent"); + save.put("status", "failed"); + saveState(save); + return; + } + + createThread = new Thread() { + public void run() { + startFailureThread(); + try {Thread.sleep(threadDelay);} catch (Exception e) { return;} + synchronized(threadlock) { + try { + status = (String) sfResolve("status", status, false); + } catch (Exception e) {} + if (status.equals("creating")) { + HashMap save = new HashMap(); + System.out.println(name + ": created vm"); + save.put("status", "created"); + saveState(save); + } + createThread = null; + } + } + }; + createThread.start(); + + status = "creating"; + save.put("status", status); + saveState(save); + } + + private void reset() { + HashMap save = new HashMap(); + System.out.println(name + " reset"); + save.put("status", "deleted"); + saveState(save); + } + + + private void startFailureThread() { + if (failureThread != null) { + failureThread.interrupt(); + failureThread = null; + }; + //System.out.println("starting failure thread " + checkFrequency + " " + failureFrequency); + if ((failureFrequency > 0) && (checkFrequency > 0)) { + failureThread = new Thread() { + public void run() { + boolean failed = false; + while (!failed) { + try {Thread.sleep(1000 * checkFrequency);} catch (Exception e) { failureThread = null; return; } + int r = (rn.nextInt(99) + 1); + //System.out.println(name + " failure check " + r + " " + failureFrequency); + if ( r <= failureFrequency) failed = true; + } + synchronized (threadlock) { + failureThread = null; + if (!status.equals("deleted")) { + HashMap save = new HashMap(); + System.out.println(name + " has failed"); + save.put("status", "failed"); + saveState(save); + } + } + } + }; + failureThread.start(); + } + } + + private void stopThreads() { + if (failureThread != null) { + failureThread.interrupt(); + failureThread = null; + } + if (deleteThread != null) { + deleteThread.interrupt(); + deleteThread = null; + } + if (createThread != null) { + createThread.interrupt(); + createThread = null; + } + } +} + Added: trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/app.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/app.sf (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/app.sf 2016-07-28 16:37:04 UTC (rev 8888) @@ -0,0 +1,37 @@ +/** (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 +/** (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/components.sf" +#include "org/smartfrog/services/automation/statemodel/components.sf" + +sfConfig extends Composite { + app extends StateHolder { + [stateNotify] active true; + } + inUse extends Dependency { + on LAZY app; by LAZY mayDelete; + enabled (!on:active); + } +} \ No newline at end of file Added: trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/array.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/array.sf (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/array.sf 2016-07-28 16:37:04 UTC (rev 8888) @@ -0,0 +1,125 @@ +/** (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 +/** (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/components.sf" +#include "org/smartfrog/services/automation/statemodel/components.sf" +#include "org/smartfrog/services/automation/threadpool/components.sf" + +// //////////////////////////////////////////////////////////////////// + +Image extends State { + sfClass "org.smartfrog.services.automation.examples.Image"; + threadDelay 10000; + + [stateData, stateListen] desiredStatus TBD; + [stateData, stateListen] desiredImage TBD; + + [stateData, stateNotify] status "deleted"; + [stateData, stateNotify] baseImage ""; + [stateData, stateNotify] image ""; + + deleteRequired ((LAZY desiredImage != LAZY baseImage) && (LAZY status != "deleted")); +} + +// //////////////////////////////////////////////////////////////////// + +VM extends State { + sfClass "org.smartfrog.services.automation.examples.VM"; + threadDelay 10000; + failureFrequency 2; + image TBD; + + [stateData, stateListen] desiredStatus TBD; + [stateData, stateNotify] status "deleted"; + + deleteRequired (LAZY status == "failed"); +} + +// //////////////////////////////////////////////////////////////////// + +PairState extends StateHolder { + [stateNotify] desiredStatus "deleted"; + [stateNotify] desiredImage "foo.v1"; + + targetStatus LAZY desiredStatus; +} + +// //////////////////////////////////////////////////////////////////// + +Pair extends Composite { + state extends PairState { + targetStatus IF ((LAZY theVm:deleteRequired) || (LAZY theImage:deleteRequired)) THEN "deleted" ELSE LAZY desiredStatus FI; + } + theVm extends VM { + image LAZY theImage:image; + desiredStatus LAZY state:targetStatus; + } + theImage extends Image { + desiredStatus LAZY state:targetStatus; + desiredImage LAZY state:desiredImage; + } + VMWaitForImage extends Dependency { + on LAZY theImage; by LAZY theVm; + relevant (by:desiredStatus == "created"); + enabled (on:status == "created"); + } + ImageWaitForVM extends Dependency { + on LAZY theVm; by LAZY theImage; + relevant (by:desiredStatus == "deleted"); + enabled ((on:status == "deleted") || (on:status == "failed")); + } + delayVMResetForImage extends Dependency { + on LAZY theImage; by LAZY theVm; + relevant (by:status == "failed"); + enabled (on:status == "deleted"); + } + delayImageCreateForReset extends Dependency { + on LAZY theVm; by LAZY theImage; + relevant (by:status == "deleted"); + enabled (on:status != "failed"); + } +} + +// //////////////////////////////////////////////////////////////////// + +sfConfig extends Compound { + threadpool extends ThreadPool { + sfProcessComponentName "threadpool"; + maxThreads 100; + } + model extends Model { + systemState extends StateHolder { + [stateNotify] desiredStatus "deleted"; + } + array extends NWayComposite { + template extends DATA Pair { + state:desiredStatus LAZY systemState:desiredStatus; + } + instances 20; + } + } +} + + Added: trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/arrayConnector.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/arrayConnector.sf (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/arrayConnector.sf 2016-07-28 16:37:04 UTC (rev 8888) @@ -0,0 +1,129 @@ +/** (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 +/** (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/components.sf" +#include "org/smartfrog/services/automation/statemodel/components.sf" +#include "org/smartfrog/services/automation/threadpool/components.sf" + +// //////////////////////////////////////////////////////////////////// + +Image extends State { + sfClass "org.smartfrog.services.automation.examples.Image"; + threadDelay 10000; + + [stateData, stateListen] desiredStatus TBD; + [stateData, stateListen] desiredImage TBD; + + [stateData, stateNotify] status "deleted"; + [stateData, stateNotify] baseImage ""; + [stateData, stateNotify] image ""; + + deleteRequired ((LAZY desiredImage != LAZY baseImage) && (LAZY status != "deleted")); +} + +// //////////////////////////////////////////////////////////////////// + +VM extends State { + sfClass "org.smartfrog.services.automation.examples.VM"; + threadDelay 10000; + failureFrequency 0; + image TBD; + + [stateData, stateListen] desiredStatus TBD; + [stateData, stateNotify] status "deleted"; + + deleteRequired (LAZY status == "failed"); +} + +// //////////////////////////////////////////////////////////////////// + +PairState extends StateHolder { + [stateNotify] desiredStatus "deleted"; + [stateNotify] desiredImage "foo.v1"; + + targetStatus LAZY desiredStatus; +} + +// //////////////////////////////////////////////////////////////////// + +Pair extends Composite { + state extends PairState { + targetStatus IF ((LAZY theVm:deleteRequired) || (LAZY theImage:deleteRequired)) THEN "deleted" ELSE LAZY desiredStatus FI; + } + theVm extends VM { + image LAZY theImage:image; + desiredStatus LAZY state:targetStatus; + } + theImage extends Image { + desiredStatus LAZY state:targetStatus; + desiredImage LAZY state:desiredImage; + } + VMWaitForImage extends Dependency { + on LAZY theImage; by LAZY theVm; + relevant (by:desiredStatus == "created"); + enabled (on:status == "created"); + } + ImageWaitForVM extends Dependency { + on LAZY theVm; by LAZY theImage; + relevant (by:desiredStatus == "deleted"); + enabled ((on:status == "deleted") || (on:status == "failed")); + } + delayVMResetForImage extends Dependency { + on LAZY theImage; by LAZY theVm; + relevant (by:status == "failed"); + enabled (on:status == "deleted"); + } + delayImageCreateForReset extends Dependency { + on LAZY theVm; by LAZY theImage; + relevant (by:status == "deleted"); + enabled (on:status != "failed"); + } +} + +// //////////////////////////////////////////////////////////////////// + +sfConfig extends Compound { + threadpool extends ThreadPool { + sfProcessComponentName "threadpool"; + maxThreads 100; + } + model extends Model { + systemState extends StateHolder { + [stateNotify] desiredStatus "deleted"; + } + mayDelete AndConnector; + array extends NWayComposite { + template extends DATA Pair { + state:desiredStatus LAZY systemState:desiredStatus; + preventDelete extends Dependency { + on LAZY mayDelete; + by LAZY theVm; + relevant (LAZY by:desiredStatus == "deleted"); + } + } + instances 20; + } + } +} Added: trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/image.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/image.sf (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/image.sf 2016-07-28 16:37:04 UTC (rev 8888) @@ -0,0 +1,60 @@ +/** (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 +/** (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/components.sf" +#include "org/smartfrog/services/automation/statemodel/components.sf" +#include "org/smartfrog/services/automation/threadpool/components.sf" + +// //////////////////////////////////////////////////////////////////// + +Image extends State { + sfClass "org.smartfrog.services.automation.examples.Image"; + threadDelay 10000; + + [stateData, stateListen] desiredStatus TBD; + [stateData, stateListen] desiredImage TBD; + + [stateData, stateNotify] status "deleted"; + [stateData, stateNotify] baseImage ""; + [stateData, stateNotify] image ""; +} + +// //////////////////////////////////////////////////////////////////// + +sfConfig extends Compound { + threadpool extends ThreadPool { + sfProcessComponentName "threadpool"; + } + model extends Model { + state extends StateHolder { + [stateNotify] desiredStatus "deleted"; + [stateNotify] desiredImage "foo.v1"; + } + image extends Image { + desiredImage LAZY state:desiredImage; + desiredStatus LAZY state:desiredStatus; + } + } +} Added: trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/messages.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/messages.sf (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/messages.sf 2016-07-28 16:37:04 UTC (rev 8888) @@ -0,0 +1,87 @@ +/** (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 +/** (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/components.sf" +#include "org/smartfrog/services/automation/statemodel/components.sf" +#include "org/smartfrog/services/automation/threadpool/components.sf" +#include "org/smartfrog/services/automation/rabbitmq/components.sf" + +// //////////////////////////////////////////////////////////////////// + +ScreenplaySender extends Sender { + // Message bus connection info + hostname "screenplay19.labs.hpecorp.net"; + username "scDemo"; + password "scDemo"; + topic "stateSync"; + // amqp://scDemo:sc...@sc...:5672 + + // add here all the [stateData] attributes which are sent, plus [stateListen] for those to trigger sending + [stateData, stateListen] desiredStatus "deleted"; + [stateData, stateListen] desiredImage ""; +} + +// //////////////////////////////////////////////////////////////////// + +ScreenplayReceiver extends Receiver { + // Message bus connection info + hostname "screenplay19.labs.hpecorp.net"; + username "scDemo"; + password "scDemo"; + topic "stateSync"; + queue "default"; + // amqp://scDemo:sc...@sc...:5672 + + // add here all the [stateData] attributes which are sent, plus [stateListen] for those to trigger sending + [stateData, stateNotify] desiredStatus; + [stateData, stateNotify] desiredImage; +} + +// //////////////////////////////////////////////////////////////////// + +sfConfig extends Compound { + threadpool extends ThreadPool { + sfProcessComponentName "threadpool"; + } + model1 extends Model { + state extends StateHolder { + [stateNotify] desiredStatus "deleted"; + [stateNotify] desiredImage "foo.v1"; + } + sender extends ScreenplaySender { + desiredImage LAZY state:desiredImage; + desiredStatus LAZY state:desiredStatus; + } + } + model2 extends Model { + receiver extends ScreenplayReceiver {queue "one";}; + } + model3 extends Model { + receiver extends ScreenplayReceiver {queue "two";}; + } + model4 extends Model { + receiver extends ScreenplayReceiver {queue "three";}; + } +} Added: trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/pair.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/pair.sf (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/pair.sf 2016-07-28 16:37:04 UTC (rev 8888) @@ -0,0 +1,89 @@ +/** (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 +/** (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/components.sf" +#include "org/smartfrog/services/automation/statemodel/components.sf" +#include "org/smartfrog/services/automation/threadpool/components.sf" + +// //////////////////////////////////////////////////////////////////// + +Image extends State { + sfClass "org.smartfrog.services.automation.examples.Image"; + threadDelay 10000; + + [stateData, stateListen] desiredStatus TBD; + [stateData, stateListen] desiredImage TBD; + + [stateData, stateNotify] status "deleted"; + [stateData, stateNotify] baseImage ""; + [stateData, stateNotify] image ""; +} + +// //////////////////////////////////////////////////////////////////// + +VM extends State { + sfClass "org.smartfrog.services.automation.examples.VM"; + threadDelay 10000; + failureFrequency 0; + image TBD; + + [stateData, stateListen] desiredStatus TBD; + [stateData, stateNotify] status "deleted"; +} + +// //////////////////////////////////////////////////////////////////// + +PairState extends StateHolder { + [stateNotify] desiredStatus "deleted"; + [stateNotify] desiredImage "foo.v1"; + + targetStatus LAZY desiredStatus; +} + +// //////////////////////////////////////////////////////////////////// + +Pair extends Composite { + state extends PairState; + theVm extends VM { + image LAZY theImage:image; + desiredStatus LAZY state:targetStatus; + } + theImage extends Image { + desiredStatus LAZY state:targetStatus; + desiredImage LAZY state:desiredImage; + } +} + +// //////////////////////////////////////////////////////////////////// + +sfConfig extends Compound { + threadpool extends ThreadPool { + sfProcessComponentName "threadpool"; + } + model extends Model { + pair extends Pair; + [stateInvariant] pair:state:imageCreatedForVM ((LAZY theImage:status != "deleted") -> ((LAZY theVm:status == "deleted") || (LAZY theVm:status == "failed"))); + } +} Added: trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/pairFailure.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/pairFailure.sf (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/pairFailure.sf 2016-07-28 16:37:04 UTC (rev 8888) @@ -0,0 +1,112 @@ +/** (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 +/** (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/components.sf" +#include "org/smartfrog/services/automation/statemodel/components.sf" +#include "org/smartfrog/services/automation/threadpool/components.sf" + +// //////////////////////////////////////////////////////////////////// + +Image extends State { + sfClass "org.smartfrog.services.automation.examples.Image"; + threadDelay 10000; + + [stateData, stateListen] desiredStatus TBD; + [stateData, stateListen] desiredImage TBD; + + [stateData, stateNotify] status "deleted"; + [stateData, stateNotify] baseImage ""; + [stateData, stateNotify] image ""; +} + +// //////////////////////////////////////////////////////////////////// + +VM extends State { + sfClass "org.smartfrog.services.automation.examples.VM"; + threadDelay 10000; + failureFrequency 2; + image TBD; + + [stateData, stateListen] desiredStatus TBD; + [stateData, stateNotify] status "deleted"; + + deleteRequired (LAZY status == "failed"); +} + +// //////////////////////////////////////////////////////////////////// + +PairState extends StateHolder { + [stateNotify] desiredStatus "deleted"; + [stateNotify] desiredImage "foo.v1"; + + targetStatus LAZY desiredStatus; +} + +// //////////////////////////////////////////////////////////////////// + +Pair extends Composite { + state extends PairState { + targetStatus IF (LAZY theVm:deleteRequired) THEN "deleted" ELSE LAZY desiredStatus FI; + } + theVm extends VM { + image LAZY theImage:image; + desiredStatus LAZY state:targetStatus; + } + theImage extends Image { + desiredStatus LAZY state:targetStatus; + desiredImage LAZY state:desiredImage; + } + VMWaitForImage extends Dependency { + on LAZY theImage; by LAZY theVm; + relevant (by:desiredStatus == "created"); + enabled (on:status == "created"); + } + ImageWaitForVM extends Dependency { + on LAZY theVm; by LAZY theImage; + relevant (by:desiredStatus == "deleted"); + enabled ((on:status == "deleted") || (on:status == "failed")); + } + delayVMResetForImage extends Dependency { + on LAZY theImage; by LAZY theVm; + relevant (by:status == "failed"); + enabled (on:status == "deleted"); + } + delayImageCreateForReset extends Dependency { + on LAZY theVm; by LAZY theImage; + relevant (by:status == "deleted"); + enabled (on:status != "failed"); + } +} + +// //////////////////////////////////////////////////////////////////// + +sfConfig extends Compound { + threadpool extends ThreadPool { + sfProcessComponentName "threadpool"; + } + model extends Model { + pair extends Pair + } +} Added: trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/pairOrdered.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/pairOrdered.sf (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/pairOrdered.sf 2016-07-28 16:37:04 UTC (rev 8888) @@ -0,0 +1,98 @@ +/** (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 +/** (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/components.sf" +#include "org/smartfrog/services/automation/statemodel/components.sf" +#include "org/smartfrog/services/automation/threadpool/components.sf" + +// //////////////////////////////////////////////////////////////////// + +Image extends State { + sfClass "org.smartfrog.services.automation.examples.Image"; + threadDelay 10000; + + [stateData, stateListen] desiredStatus TBD; + [stateData, stateListen] desiredImage TBD; + + [stateData, stateNotify] status "deleted"; + [stateData, stateNotify] baseImage ""; + [stateData, stateNotify] image ""; +} + +// //////////////////////////////////////////////////////////////////// + +VM extends State { + sfClass "org.smartfrog.services.automation.examples.VM"; + threadDelay 10000; + failureFrequency 0; + image TBD; + + [stateData, stateListen] desiredStatus TBD; + [stateData, stateNotify] status "deleted"; +} + +// //////////////////////////////////////////////////////////////////// + +PairState extends StateHolder { + [stateNotify] desiredStatus "deleted"; + [stateNotify] desiredImage "foo.v1"; + + targetStatus LAZY desiredStatus; +} + +// //////////////////////////////////////////////////////////////////// + +Pair extends Composite { + state extends PairState; + theVm extends VM { + image LAZY theImage:image; + desiredStatus LAZY state:targetStatus; + } + theImage extends Image { + desiredStatus LAZY state:targetStatus; + desiredImage LAZY state:desiredImage; + } + VMWaitForImage extends Dependency { + on LAZY theImage; by LAZY theVm; + relevant (by:desiredStatus == "created"); + enabled (on:status == "created"); + } + ImageWaitForVM extends Dependency { + on LAZY theVm; by LAZY theImage; + relevant (by:desiredStatus == "deleted"); + enabled ((on:status == "deleted") || (on:status == "failed")); + } +} + +// //////////////////////////////////////////////////////////////////// + +sfConfig extends Compound { + threadpool extends ThreadPool { + sfProcessComponentName "threadpool"; + } + model extends Model { + pair extends Pair + } +} Added: trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/pairVersioning.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/pairVersioning.sf (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/pairVersioning.sf 2016-07-28 16:37:04 UTC (rev 8888) @@ -0,0 +1,114 @@ +/** (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 +/** (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/components.sf" +#include "org/smartfrog/services/automation/statemodel/components.sf" +#include "org/smartfrog/services/automation/threadpool/components.sf" + +// //////////////////////////////////////////////////////////////////// + +Image extends State { + sfClass "org.smartfrog.services.automation.examples.Image"; + threadDelay 10000; + + [stateData, stateListen] desiredStatus TBD; + [stateData, stateListen] desiredImage TBD; + + [stateData, stateNotify] status "deleted"; + [stateData, stateNotify] baseImage ""; + [stateData, stateNotify] image ""; + + deleteRequired ((LAZY desiredImage != LAZY baseImage) && (LAZY status != "deleted")); +} + +// //////////////////////////////////////////////////////////////////// + +VM extends State { + sfClass "org.smartfrog.services.automation.examples.VM"; + threadDelay 10000; + failureFrequency 0; + image TBD; + + [stateData, stateListen] desiredStatus TBD; + [stateData, stateNotify] status "deleted"; + + deleteRequired (LAZY status == "failed"); +} + +// //////////////////////////////////////////////////////////////////// + +PairState extends StateHolder { + [stateNotify] desiredStatus "deleted"; + [stateNotify] desiredImage "foo.v1"; + + targetStatus LAZY desiredStatus; +} + +// //////////////////////////////////////////////////////////////////// + +Pair extends Composite { + state extends PairState { + targetStatus IF ((LAZY theVm:deleteRequired) || (LAZY theImage:deleteRequired)) THEN "deleted" ELSE LAZY desiredStatus FI; + } + theVm extends VM { + image LAZY theImage:image; + desiredStatus LAZY state:targetStatus; + } + theImage extends Image { + desiredStatus LAZY state:targetStatus; + desiredImage LAZY state:desiredImage; + } + VMWaitForImage extends Dependency { + on LAZY theImage; by LAZY theVm; + relevant (by:desiredStatus == "created"); + enabled (on:status == "created"); + } + ImageWaitForVM extends Dependency { + on LAZY theVm; by LAZY theImage; + relevant (by:desiredStatus == "deleted"); + enabled ((on:status == "deleted") || (on:status == "failed")); + } + delayVMResetForImage extends Dependency { + on LAZY theImage; by LAZY theVm; + relevant (by:status == "failed"); + enabled (on:status == "deleted"); + } + delayImageCreateForReset extends Dependency { + on LAZY theVm; by LAZY theImage; + relevant (by:status == "deleted"); + enabled (on:status != "failed"); + } +} + +// //////////////////////////////////////////////////////////////////// + +sfConfig extends Compound { + threadpool extends ThreadPool { + sfProcessComponentName "threadpool"; + } + model extends Model { + pair extends Pair + } +} Added: trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/sequence.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/sequence.sf (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/sequence.sf 2016-07-28 16:37:04 UTC (rev 8888) @@ -0,0 +1,148 @@ +/** (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 +/** (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/components.sf" +#include "org/smartfrog/services/automation/statemodel/components.sf" +#include "org/smartfrog/services/automation/threadpool/components.sf" + +// //////////////////////////////////////////////////////////////////// + +Image extends State { + sfClass "org.smartfrog.services.automation.examples.Image"; + threadDelay 10000; + + [stateData, stateListen] desiredStatus TBD; + [stateData, stateListen] desiredImage TBD; + + [stateData, stateNotify] status "deleted"; + [stateData, stateNotify] baseImage ""; + [stateData, stateNotify] image ""; + + deleteRequired ((LAZY desiredImage != LAZY baseImage) && (LAZY status != "deleted")); +} + +// //////////////////////////////////////////////////////////////////// + +VM extends State { + sfClass "org.smartfrog.services.automation.examples.VM"; + threadDelay 10000; + failureFrequency 0; + image TBD; + + [stateData, stateListen] desiredStatus TBD; + [stateData, stateNotify] status "deleted"; + + deleteRequired (LAZY status == "failed"); +} + +// //////////////////////////////////////////////////////////////////// + +PairState extends StateHolder { + [stateNotify] desiredStatus "deleted"; + [stateNotify] desiredImage "foo.v1"; + + targetStatus LAZY desiredStatus; +} + +// //////////////////////////////////////////////////////////////////// + +Pair extends Composite { + state extends PairState { + targetStatus IF ((LAZY theVm:deleteRequired) || (LAZY theImage:deleteRequired)) THEN "deleted" ELSE LAZY desiredStatus FI; + } + theVm extends VM { + image LAZY theImage:image; + desiredStatus LAZY state:targetStatus; + } + theImage extends Image { + desiredStatus LAZY state:targetStatus; + desiredImage LAZY state:desiredImage; + } + VMWaitForImage extends Dependency { + on LAZY theImage; by LAZY theVm; + relevant (by:desiredStatus == "created"); + enabled (on:status == "created"); + } + ImageWaitForVM extends Dependency { + on LAZY theVm; by LAZY theImage; + relevant (by:desiredStatus == "deleted"); + enabled ((on:status == "deleted") || (on:status == "failed")); + } + delayVMResetForImage extends Dependency { + on LAZY theImage; by LAZY theVm; + relevant (by:status == "failed"); + enabled (on:status == "deleted"); + } + delayImageCreateForReset extends Dependency { + on LAZY theVm; by LAZY theImage; + relevant (by:status == "deleted"); + enabled (on:status != "failed"); + } +} + +// //////////////////////////////////////////////////////////////////// + +sfConfig extends Compound { + threadpool extends ThreadPool { + sfProcessComponentName "threadpool"; + maxThreads 100; + } + model extends Model { + systemState extends StateHolder { + [stateNotify] desiredStatus "deleted"; + } + array extends Composite { + p1 extends Pair { + state:desiredStatus LAZY systemState:desiredStatus; + } + p2 extends Pair { + state:desiredStatus LAZY systemState:desiredStatus; + } + p2WaitForP1 extends Dependency { + on LAZY p1:theVm by LAZY p2:theVm; + relevent (by:desiredStatus == "created"); + enabled (on:status == "created"); + } + p3 extends Pair { + state:desiredStatus LAZY systemState:desiredStatus; + } + p3WaitForP2 extends Dependency { + on LAZY p2:theVm by LAZY p3:theVm; + relevent (by:desiredStatus == "created"); + enabled (on:status == "created"); + } + p4 extends Pair { + state:desiredStatus LAZY systemState:desiredStatus; + } + p4WaitForP3 extends Dependency { + on LAZY p3:theVm by LAZY p4:theVm; + relevent (by:desiredStatus == "created"); + enabled (on:status == "created"); + } + } + } +} + + Added: trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/vm.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/vm.sf (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/automation/examples/vm.sf 2016-07-28 16:37:04 UTC (rev 8888) @@ -0,0 +1,58 @@ +/** (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 +/** (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/components.sf" +#include "org/smartfrog/services/automation/statemodel/components.sf" +#include "org/smartfrog/services/automation/threadpool/components.sf" + +// //////////////////////////////////////////////////////////////////// + +VM extends State { + sfClass "org.smartfrog.services.automation.examples.VM"; + threadDelay 10000; + failureFrequency 10; + image TBD; + + [stateData, stateListen] desiredStatus TBD; + [stateData, stateNotify] status "deleted"; +} + +// //////////////////////////////////////////////////////////////////// + +sfConfig extends Compound { + threadpool extends ThreadPool { + sfProcessComponentName "threadpool"; + } + model extends Model { + state extends StateHolder { + [stateNotify] desiredStatus "deleted"; + [stateNotify] desiredImage "foo.v1"; + } + theVm extends VM { + image LAZY state:desiredImage; + desiredStatus LAZY state:desiredStatus; + } + } +} Added: trunk/core/smartfrog/src/org/smartfrog/services/automation/rabbitmq/Receiver.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/automation/rabbitmq/Receiver.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/automation/rabbitmq/Receiver.java 2016-07-28 16:37:04 UTC (rev 8888) @@ -0,0 +1,144 @@ +package org.smartfrog.services.automation.rabbitmq; + +import java.rmi.RemoteException; +import java.util.HashMap; +import java.util.concurrent.TimeoutException; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.ObjectInputStream; + + +import com.rabbitmq.client.ConnectionFactory; +import com.rabbitmq.client.Connection; +import com.rabbitmq.client.AMQP; +import com.rabbitmq.client.Channel; +import com.rabbitmq.client.DefaultConsumer; +import com.rabbitmq.client.Envelope; + +import org.smartfrog.services.automation.statemodel.state.State; +import org.smartfrog.sfcore.common.SmartFrogException; +import org.smartfrog.sfcore.prim.TerminationRecord; + +public class Receiver extends State { + String topic = ""; + String hostname = "localhost"; + int port = 0; + String username = ""; + String password = ""; + String virtualhost = ""; + String queue = "default"; + + int epoch = -1; + + Connection connection = null;; + Channel channel= null;; + ConnectionFactory factory = null; + + public Receiver() throws RemoteException { + super(); + } + + @Override + public void sfDeploy() throws RemoteException, SmartFrogException { + super.sfDeploy(); + topic = (String) sfResolve("topic", topic, false); + queue = (String) sfResolve("queue", queue, false); + hostname = (String) sfResolve("hostname", hostname, false); + port = ((Integer) sfResolve("port", port, false)).intValue(); + username = (String) sfResolve("username", username, false); + password = (String) sfResolve("password", password, false); + virtualhost = (String) sfResolve("virtualhost", virtualhost, false); + ConnectionFactory factory = new ConnectionFactory(); + + if (hostname != "") factory.setHost(hostname); + if (port != 0) factory.setPort(port); + if (username != "") factory.setUsername(username); + if (password != "") factory.setPassword(password); + + System.out.println(sfCompleteNameSafe() + "settings " + factory.getHost() + ":" + factory.getPort() + ":" + factory.getUsername() + ":" + factory.getPassword() + ":" + factory.getVirtualHost()); + try { + connection = factory.newConnection(); + channel = connection.createChannel(); + channel.exchangeDeclare(topic, "fanout"); + channel.queueDeclare(queue, true, false, false, null); + channel.queueBind(queue, topic, ""); + } catch (Exception e) { + System.out.println(sfCompleteNameSafe() + "error in setting up message bus access" + e); + e.printStackTrace(); + } + System.out.println(sfCompleteNameSafe() + " channel set up"); + + boolean autoAck = false; + try { + channel.basicConsume(queue, autoAck, sfCompleteNameSafe().toString(), + new DefaultConsumer(channel) { + @Override + public void handleDelivery(String consumerTag, + Envelope envelope, + AMQP.BasicProperties properties, + byte[] body) + throws IOException + { + + try { + ... [truncated message content] |