コード例 #1
0
 public string serialize()
 {
     var kf = new DefaultKevoreeFactory();
     return kf.createJSONSerializer().serialize(this.valueMarshalled);
 }
コード例 #2
0
        private void RegisterHandler(Register register)
        {
            var client = Context.WebSocket;
            _clients.Add(register.GetNodeName(), client);
            var currentModel = WSGroupServices.GetModelService().getCurrentModel().getModel();

            var kf = new DefaultKevoreeFactory();
            // we clone the marshalled instance into a proper one
            var modelToApply = (ContainerRoot)kf.createJSONLoader().loadModelFromString(currentModel.serialize()).get(0);

            // We merge received model with current one
            ContainerRoot recModel = (ContainerRoot)WSGroupServices.GetJsonModelLoader()
                        .loadModelFromString(register.GetModel()).get(0);

            TraceSequence tseq = WSGroupServices.GetModelCompare().merge(modelToApply, recModel);
            tseq.applyOn(modelToApply);

            Dictionary<string, string> context = new Dictionary<string, string>();
            context.Add("nodeName", register.GetNodeName());
            context.Add("groupName", WSGroupServices.GetContext().getInstanceName());
            if (DoesFilterMatchIncomingNodeName(register.GetNodeName(), WSGroupServices.GetFilter()))
            {
                ApplyOnConnect(context, modelToApply);
            }
            else
            {
                var push = new Push(new ContainerRootMarshalled(modelToApply).serialize());
                _clients[register.GetNodeName()].Send(push.Serialize());
            }
        }
コード例 #3
0
        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;
            }
        }
コード例 #4
0
        /*private static void debug(ContainerRoot result)
        {
            var fact = new DefaultKevoreeFactory();
            var serializer = fact.createJSONSerializer();
            var modelStr = serializer.serialize(result);

            Console.WriteLine(modelStr);
        }*/
        private ContainerRoot Analyse(string typeDefName, string typeDefVersion, string typeDefPackage, string packageName, string packageVersion)
        {
            KevoreeFactory kevoreeFactory = new DefaultKevoreeFactory();
            ContainerRoot containerRoot = null;

            var filteredAssemblyTypes = new HashSet<DeployUnit>(_exports).Where(x => _annotationHelper.FilterByAttribute(x.GetType(), EXPECTED_TYPES)).ToList();
            if (!filteredAssemblyTypes.Any())
            {
                log.Error("None of the expected types have been found (Component, Channel, Node, Group)");
            }
            else if (filteredAssemblyTypes.Count > 0)
            {
                containerRoot = kevoreeFactory.createContainerRoot();
                kevoreeFactory.root(containerRoot);
                // A type found (nominal)
                /*
                 * Initialisation a type definition (container root) with information common to all the components types.
                 */
                var typedefinedObject = filteredAssemblyTypes[0];
                TypeDefinition typeDefinitionType = GenericComponentDefinition(typeDefName, typeDefVersion, typeDefPackage, packageName, packageVersion, kevoreeFactory, containerRoot, typedefinedObject);

                /* each of those types inherits from TypeDefinition.
                 Only ChannelType and ComponentType are specialized.
                 NodeType and GroupType inherits from TypeDefinition without any specificity */
                if (typeDefinitionType is ComponentTypeImpl)
                {
                    log.Debug("Component type");
                    CompleteComponentTypeDefinition(typedefinedObject, (ComponentTypeImpl)typeDefinitionType, kevoreeFactory);
                }
                else if (typeDefinitionType is ChannelTypeImpl)
                {
                    log.Debug("Channel type");
                    CompleteChannelTypeDefinition(typedefinedObject, (ChannelTypeImpl)typeDefinitionType, kevoreeFactory);
                }
                else if (typeDefinitionType is NodeTypeImpl)
                {
                    // nothing to do
                    log.Debug("Node type");
                    CompleteNodeTypeDefinition(typedefinedObject, (NodeTypeImpl)typeDefinitionType, kevoreeFactory);
                }
                else if (typeDefinitionType is GroupTypeImpl)
                {
                    // nothing to do
                    log.Debug("Group type");
                    CompleteGroupTypeDefinition(typedefinedObject, (GroupTypeImpl)typeDefinitionType, kevoreeFactory);
                }

                if (typeDefinitionType.getDictionaryType() == null)
                {
                    typeDefinitionType.setDictionaryType(kevoreeFactory.createDictionaryType());
                }

                if (typeDefinitionType.getDictionaryType().getAttributes() == null)
                {
                    typeDefinitionType.getDictionaryType().setAttributes(new ArrayList());
                }
            }

            return containerRoot;
        }
コード例 #5
0
 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);
 }