public void update(IContainerRootMarshalled model, UpdateCallback callback)
 {
     _service.update(model, callback, _caller);
 }
 public UUIDModelImpl(Guid guid, IContainerRootMarshalled cc)
 {
     this.guid = guid;
     this.cc = cc;
 }
 public void compareAndSwap(IContainerRootMarshalled model, Guid uuid, UpdateCallback callback)
 {
     _service.compareAndSwap(model, uuid, callback, _caller);
 }
Esempio n. 4
0
 public AdaptationModel plan(IContainerRootMarshalled current, IContainerRootMarshalled target,
                             ITracesSequence sequence)
 {
     return((_node as NodeType).plan(current, target, sequence));
 }
 public UpdateContext(IContainerRootMarshalled currentModel, IContainerRootMarshalled proposedModel, String callerPath)
 {
     this.currentModel = currentModel;
     this.proposedModel = proposedModel;
     this.callerPath = callerPath;
 }
Esempio n. 6
0
 public void update(IContainerRootMarshalled model, UpdateCallback callback)
 {
     _service.update(model, callback, _caller);
 }
 public AdaptationModel plan(IContainerRootMarshalled current, IContainerRootMarshalled target,
     ITracesSequence sequence )
 {
     return (_node as NodeType).plan(current, target, sequence);
 }
 public void compareAndSwap(IContainerRootMarshalled model, Guid uuid, UpdateCallback callback, String callerPath)
 {
     scheduler.Add(() => UpdateModelRunnable(model, uuid, callback, callerPath));
 }
Esempio n. 9
0
 public void compareAndSwap(IContainerRootMarshalled model, Guid uuid, UpdateCallback callback)
 {
     _service.compareAndSwap(model, uuid, callback, _caller);
 }
 private void switchToNewModel(IContainerRootMarshalled c)
 {
     ContainerRoot cc = CloneContainerRoot(c);
     if (!c.isReadOnly())
     {
         cc = (ContainerRoot)kevoreeFactory.createModelCloner().clone(cc, true);
     }
     // current model is backed-up
     UUIDModel previousModel = model;
     if (previousModel != null)
     {
         models.AddLast(previousModel);
     }
     // TODO : MAGIC NUMBER ;-) , ONLY KEEP 10 PREVIOUS MODEL
     if (models.Count > 15)
     {
         models.RemoveFirst();
     }
     // Changes the current model by the new model
     if (cc != null)
     {
         UUIDModel uuidModel = new UUIDModelImpl(Guid.NewGuid(), new ContainerRootMarshalled(cc));
         this.model = uuidModel;
         // Fires the update to listeners
         modelListeners.notifyAllListener();
     }
 }
        private void UpdateModelRunnable(IContainerRootMarshalled targetModel, Guid? uuid, UpdateCallback callback,
                string callerPath)
        {
            bool res = false;
            if (this.getCurrentLock() != null)
            {

                if (uuid.Equals(this.getCurrentLock().getGuid()))
                {
                    res = this.internalUpdateModel(targetModel, callerPath);
                }
                else
                {
                    //Log.debug("Core Locked , bad UUID {}", uuid);
                    res = false; // LOCK REFUSED !
                }
            }
            else
            {
                // COMMON CHECK
                if (uuid != null)
                {
                    if (this.model != null && uuid.Equals(this.model.getUUID()))
                    {
                        res = this.internalUpdateModel(targetModel, callerPath);
                    }
                    else
                    {
                        res = false;
                    }
                }
                else
                {
                    res = this.internalUpdateModel(targetModel, callerPath);
                }
            }
            bool finalRes = res;
            new Thread(new ThreadStart(() =>
            {
                if (callback != null)
                {
                    callback(finalRes);
                }
            })).Start();
        }
        private bool internalUpdateModel(IContainerRootMarshalled proposedNewModel, string callerPath)
        {
            if (proposedNewModel.findNodesByID(this.nodeName) == null)
            {
                return false;
            }
            try
            {
                var readOnlyNewModel = CloneContainerRoot(proposedNewModel);
                if (readOnlyNewModel.isReadOnly())
                {
                    readOnlyNewModel = (ContainerRoot)kevoreeFactory.createModelCloner().clone(readOnlyNewModel, false);
                    readOnlyNewModel.setGenerated_KMF_ID(nodeName + "@" + callerPath + "#" + java.lang.System.nanoTime());
                    readOnlyNewModel = (ContainerRoot)kevoreeFactory.createModelCloner().clone(readOnlyNewModel, true);
                }
                else
                {
                    readOnlyNewModel.setGenerated_KMF_ID(nodeName + "@" + callerPath + "#" + java.lang.System.nanoTime());
                }
                pending = proposedNewModel;
                // Model check is OK.
                ContainerRoot currentModel;
                if (this.model != null)
                {

                    var serialized = this.model.getModel().serialize();
                    var kf = new org.kevoree.factory.DefaultKevoreeFactory();
                    currentModel = (ContainerRoot)kf.createJSONLoader().loadModelFromString(serialized).get(0);
                }
                else
                {
                    currentModel = null;
                }
                UpdateContext updateContext = new UpdateContext(new ContainerRootMarshalled(currentModel), new ContainerRootMarshalled(readOnlyNewModel), callerPath);
                bool preCheckResult = modelListeners.preUpdate(updateContext);
                bool initUpdateResult = modelListeners.initUpdate(updateContext);
                if (preCheckResult && initUpdateResult)
                {
                    IContainerRootMarshalled newmodel = new ContainerRootMarshalled(readOnlyNewModel);
                    // CHECK FOR HARA KIRI
                    IContainerRootMarshalled previousHaraKiriModel = null;
                    // Checks and bootstrap the node
                    checkBootstrapNode(newmodel);
                    if (this.model != null)
                    {
                        var serialized = this.model.getModel().serialize();
                        var kf = new org.kevoree.factory.DefaultKevoreeFactory();
                        currentModel = (ContainerRoot)kf.createJSONLoader().loadModelFromString(serialized).get(0);
                    }
                    else
                    {
                        currentModel = null;
                    }
                    long milli = java.lang.System.currentTimeMillis();

                    bool deployResult;
                    try
                    {
                        if (nodeInstance != null)
                        {
                            // Compare the two models and plan the adaptation
                            // Log.info("Comparing models and planning
                            // adaptation.")

                            var dkf = new DefaultKevoreeFactory();
                            var modelCompare = dkf.createModelCompare();

                            // TODO : clean up -> cloned
                            var newmodel2 = CloneContainerRoot(newmodel);

                            var traces = modelCompare.diff(currentModel, newmodel2);
                            AdaptationModel adaptationModel = nodeInstance.plan(new ContainerRootMarshalled(currentModel), newmodel, new TracesMarshalled(traces));
                            // Execution of the adaptation
                            updateContext = new UpdateContext(new ContainerRootMarshalled(currentModel), new ContainerRootMarshalled(newmodel2), callerPath);

                            UpdateContext final_updateContext = updateContext;
                            Func<bool> afterUpdateTest = () => { return modelListeners.afterUpdate(final_updateContext); };
                            Func<bool> postRollbackTest = () =>
                            {
                                modelListeners.postRollback(final_updateContext);
                                return true;
                            };

                            Func<bool> preCmdPreRollbackTest = getPreCmdPreRollbackTest(updateContext, modelListeners);

                            IContainerNodeMarshalled rootNode = newmodel.findNodesByID(getNodeName());
                            deployResult = PrimitiveCommandExecutionHelper.execute(this, rootNode,
                                    adaptationModel, nodeInstance, afterUpdateTest, preCmdPreRollbackTest,
                                    postRollbackTest);

                            if (deployResult)
                            {
                                this.model = new UUIDModelImpl(Guid.NewGuid(), newmodel);
                            }
                        }
                        else
                        {
                            deployResult = false;
                        }
                    }
                    catch (Exception e)
                    {
                        loggerMaster.Error(e.StackTrace);
                        deployResult = false;
                    }
                    if (deployResult)
                    {
                        switchToNewModel(newmodel);
                    }
                    else
                    {
                        // KEEP FAIL MODEL, TODO
                        // IF HARAKIRI
                        if (previousHaraKiriModel != null)
                        {
                            internalUpdateModel(previousHaraKiriModel, callerPath);
                            previousHaraKiriModel = null; // CLEAR
                        }
                    }
                    long milliEnd = java.lang.System.currentTimeMillis() - milli;
                    //pending = null;
                    return deployResult;

                }
                else
                {
                    return false;
                }

            }
            catch (java.lang.Throwable)
            {
                return false;
            }
        }
 private ContainerRoot CloneContainerRoot(IContainerRootMarshalled newmodel)
 {
     var kf = new DefaultKevoreeFactory();
     JSONModelLoader loader = new JSONModelLoader(kf);
     var serialized = newmodel.serialize();
     return (ContainerRoot)loader.loadModelFromString(serialized).get(0);
 }
        private void checkBootstrapNode(IContainerRootMarshalled currentModel)
        {
            try
            {
                if (nodeInstance == null)
                {
                    IContainerNodeMarshalled foundNode = currentModel.findNodesByID(getNodeName());
                    if (foundNode != null)
                    {
                        nodeInstance = bootstrapNodeType(currentModel, getNodeName());
                        if (nodeInstance != null)
                        {
                            nodeInstance.Start();

                            UUIDModelImpl uuidModel = new UUIDModelImpl(Guid.NewGuid(), new ContainerRootMarshalled(kevoreeFactory.createContainerRoot()));

                            // TODO : check for concurrency problems here.
                            this.model = uuidModel;
                        }
                    }
                }
            }
            catch (java.lang.Throwable)
            {
                // TODO is it possible to display the following log ?
                try
                {
                    if (nodeInstance != null)
                    {
                        // TODO : Mieux gérer les erreurs
                        /*Method met = resolver.resolve(org.kevoree.annotation.Stop.class);
                        met.invoke(nodeInstance);
                         */
                    }
                }
                catch (java.lang.Throwable)
                {
                }
                finally
                {
                }
                nodeInstance = null;
               // resolver = null;
            }
        }
        private INodeRunner bootstrapNodeType(IContainerRootMarshalled model, String nodeName)
        {
            var containerNode = model.findNodesByID(nodeName);

            if (containerNode != null)
            {
                return bootstrapService.createInstance(containerNode);
            }
            else
            {
                return null;
            }
        }
 public void update(IContainerRootMarshalled model, UpdateCallback callback, string callerPath)
 {
     scheduler.Add(() => UpdateModelRunnable(model, null, callback, callerPath));
 }