Esempio n. 1
0
        /*
         * XML é visto como um array de bytes, chamado data.
         * esse array é salvo em "path" e lido por AppLoader gerando um objeto Component Type,
         * passado ao DGAC
         */
        public string deployHashComponent(byte[] data, string userName, string password, string curDir, bool flag_compile)
        {
            try
            {
                string filename = Path.GetTempFileName();
                File.WriteAllBytes(filename, data);

                if (data != null)
                {
                    ComponentType c = LoaderApp.DeserializeObject(filename);
                    int           res;
                    if (c.header.baseType != null && c.header.baseType.extensionType.ItemElementName == ItemChoiceType.implements)
                    {
                        res = BackEnd.registerConcreteComponentTransaction(c, userName, password, curDir, flag_compile);
                    }
                    else
                    {
                        res = BackEnd.registerAbstractComponentTransaction(c, userName, password, curDir, flag_compile);
                    }

                    if (res >= 0)
                    {
                        string component_reference = c.header.packagePath + "." + c.header.name;
                        File.Copy(filename, Constants.PATH_TEMP_WORKER + component_reference + ".hpe", true);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                return("-- Message -- \n " + e.Message + "\n\n -- Stack Trace --\n" + e.StackTrace + "\n\n -- Inner Exception -- \n" + e.InnerException);
            }

            return(null);
        }
Esempio n. 2
0
        public string deploy(string config_contents)
        {
            int res = -1;

            try
            {
                string filename = Path.GetTempFileName();
                File.WriteAllText(filename, config_contents);

                ComponentType c = LoaderApp.DeserializeObject(filename);
                if (c.header.baseType != null && c.header.baseType.extensionType.ItemElementName == ItemChoiceType.implements)
                {
                    res = BackEnd.registerConcreteComponentTransaction(c, null, null, "");
                }
                else
                {
                    res = BackEnd.registerAbstractComponentTransaction(c, null, null, "");
                }

                if (res >= 0)
                {
                    string component_reference = c.header.packagePath + "." + c.header.name;
                    File.Copy(filename, Constants.PATH_TEMP_WORKER + component_reference + ".hpe", true);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                return("-- Message -- \n " + e.Message + "\n\n -- Stack Trace --\n" + e.StackTrace + "\n\n -- Inner Exception -- \n" + e.InnerException);
            }

            return("deployed " + res);
        }
Esempio n. 3
0
        public string readCatalog()
        {
            Console.WriteLine("Reading Component Catalog");

            CatalogType env = br.ufc.pargo.hpe.backend.DGAC.BackEnd.readCatalog();

            string xmlEnv = LoaderApp.SerializeCatalog(Constants.PATH_TEMP_WORKER + "catalog.xml", env);

            return(xmlEnv);
        }
Esempio n. 4
0
        public byte[] readEnvironment()
        {
            Console.WriteLine("Reading Environment");

            EnvironmentType env = br.ufc.pargo.hpe.backend.DGAC.BackEnd.readEnvironment();

            byte[] xmlEnv = LoaderApp.SerializeEnvironment(Constants.PATH_TEMP_WORKER + "environment.xml", env);

            return(xmlEnv);
        }
        public static void invokeDeploySystem(SAFeSWL_Architecture arch_desc,
                                              string arch_ref,
                                              object platform_address,
                                              ComponentType c_appplication_abstract,
                                              ComponentType c_application_concrete,
                                              ComponentType c_workflow_abstract,
                                              ComponentType c_workflow_concrete,
                                              ComponentType c_system_abstract,
                                              ComponentType c_system_concrete)
        {
            try
            {
                IPlatformServices platform_access = null;
                if (platform_address is string)
                {
                    // Deploy the components of the system.
                    ServiceUtils.PlatformServices.PlatformServices platform_access_ = new ServiceUtils.PlatformServices.PlatformServices((string)platform_address);
                    platform_access_.Timeout = int.MaxValue;
                    platform_access          = (IPlatformServices)platform_access_;
                }
                else if (platform_address is IPlatformServices)
                {
                    platform_access = (IPlatformServices)platform_address;
                }

                string application_abstract = LoaderApp.serialize <ComponentType>(c_appplication_abstract);
                string application_concrete = LoaderApp.serialize <ComponentType>(c_application_concrete);
                string workflow_abstract    = LoaderApp.serialize <ComponentType>(c_workflow_abstract);
                string workflow_concrete    = LoaderApp.serialize <ComponentType>(c_workflow_concrete);
                string system_abstract      = LoaderApp.serialize <ComponentType>(c_system_abstract);
                string system_concrete      = LoaderApp.serialize <ComponentType>(c_system_concrete);

                Console.Error.WriteLine(platform_access.deploy(application_abstract));
                Console.Error.WriteLine(platform_access.deploy(workflow_abstract));
                Console.Error.WriteLine(platform_access.deploy(system_abstract));

                Console.Error.WriteLine(platform_access.deploy(application_concrete));
                Console.Error.WriteLine(platform_access.deploy(workflow_concrete));
                Console.Error.WriteLine(platform_access.deploy(system_concrete));
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine(e.StackTrace);
                if (e.InnerException != null)
                {
                    Console.Error.WriteLine(e.InnerException.Message);
                    Console.Error.WriteLine(e.InnerException.StackTrace);
                }
            }

            //return 0;
        }
Esempio n. 6
0
        public static String deployHashComponent(byte[] data)
        {
            string filename = "newConfig";
            string path     = Constants.PATH_TEMP_WORKER + filename + ".xml";

            if (data != null)
            {
                FileUtil.saveByteArrayIntoFile(data, path);
                ComponentType c = LoaderApp.DeserializeObject(path);
                dgac.registerConcreteComponent(c, null, null, null);
            }

            return("ok");
        }
        private CodeTypeReference buildCodeTypeReference(InterfaceSignature isig,
                                                         IList <string> dependency_list,
                                                         IList <string> usings_list)
        {
            string[] parts      = isig.the_interface.Class_name.Split('.');
            string   class_name = parts[parts.Length - 1];


            CodeTypeReference slice_accessor_type = new CodeTypeReference(class_name + (isig.the_interface.Class_nargs == 0 ? "" : "`" + isig.the_interface.Class_nargs));

            dependency_list.Add(LoaderApp.buildDllName(isig.package_path, isig.the_interface.Assembly_string) + ".dll");

            if (!usings_list.Contains(isig.package_path))
            {
                usings_list.Add(isig.package_path);
            }

            slice_accessor_type.Options &= CodeTypeReferenceOptions.GenericTypeParameter;

            IList <InterfaceParameter> ip_list = BackEnd.ipdao.list(isig.the_interface.Id_abstract, isig.the_interface.Id_interface);

            IDictionary <String, CodeTypeReference> type_argument_list = new Dictionary <String, CodeTypeReference>();

            foreach (KeyValuePair <string, InterfaceSignature> isig_ in isig.parameters)
            {
                CodeTypeReference slice_accessor_arg_type;
                string            par_id = isig_.Key;
                if (isig.varId.ContainsKey(par_id))
                {
                    string var_id = isig.varId[isig_.Key];
                    slice_accessor_arg_type = new CodeTypeReference(var_id);
                }
                else
                {
                    slice_accessor_arg_type = buildCodeTypeReference(isig_.Value, dependency_list, usings_list);
                }
                // slice_accessor_type.TypeArguments.Add(slice_accessor_arg_type);
                type_argument_list.Add(par_id, slice_accessor_arg_type);
            }

            foreach (InterfaceParameter ip in ip_list)
            {
                slice_accessor_type.TypeArguments.Add(type_argument_list[ip.ParId]);
            }

            return(slice_accessor_type);
        }
Esempio n. 8
0
        /*
         * XML é visto como um array de bytes, chamado data.
         * esse array é salvo em "path" e lido por AppLoader gerando um objeto Component Type,
         * passado ao DGAC
         */
        public string deployHashConfiguration(byte[] data, byte[] hcl_data, string userName, string password, string curDir)
        {
            Console.WriteLine("deployHashConfiguration");
            Console.WriteLine("hcl_data is null ? {0} ! {1}", hcl_data == null, data == null);

            try
            {
                string filename = "newConfig";
                string path     = Constants.PATH_TEMP_WORKER + filename + ".xml";
                if (data != null)
                {
                    FileUtil.saveByteArrayIntoFile(data, path);
                    ComponentType c           = LoaderApp.DeserializeObject(path);
                    int           id_abstract = BackEnd.registerAbstractComponent(c, userName, password, curDir);
                    BackEnd.updateConfiguration(id_abstract, hcl_data);
                }
            } catch (Exception e) {
                Console.Error.WriteLine(e.Message);
                return("-- Message -- \n " + e.Message + "\n\n -- Stack Trace --\n" + e.StackTrace + "\n\n -- Inner Exception -- \n" + e.InnerException);
            }

            return(null);
        }
Esempio n. 9
0
        public ComponentID createInstance(string instanceName, string class_name, TypeMap properties)
        {
            Console.WriteLine("CREATE INSTANCE");
            Connector.openConnection();

            ComponentID cid = new WorkerComponentIDImpl(instanceName);

            try {
                Console.WriteLine("createInstanceBaseForAllKinds - 1 " + instanceName);
                unitProperties.Add(cid, properties);

                Console.WriteLine("createInstanceBaseForAllKinds - 2");
                string   id_unit          = properties.getString(Constants.UNIT_KEY, "");
                string   library_path     = properties.getString(Constants.COMPONENT_KEY, "");
                string   assembly_string  = properties.getString(Constants.ASSEMBLY_STRING_KEY, "");
                string[] portNames        = properties.getStringArray(Constants.PORT_NAMES_KEY, new string[0]);
                int      kind             = Constants.kindMapping[properties.getString(Constants.KIND_KEY, "")];
                string   unit_mapping_xml = properties.getString(Constants.NODES_KEY, "");
                Instantiator.UnitMappingType[] unit_mapping = LoaderApp.deserialize <Instantiator.UnitMappingType[]>(unit_mapping_xml);

                Console.WriteLine("createInstanceBaseForAllKinds - 3 ; assembly_string = " + assembly_string + "; class name = " + class_name);

                ObjectHandle    obj        = Activator.CreateInstance(assembly_string, class_name);
                hpe.basic.IUnit unit_slice = (hpe.basic.IUnit)obj.Unwrap();
                unit_slice.Id_unit   = id_unit;
                unit_slice.PortNames = portNames;
                unit_slice.Kind      = kind;
                unit_slice.ClassName = class_name;
                unit_slice.QualifiedComponentTypeName = library_path;

                unit_registry.Add(instanceName, unit_slice);

                Console.WriteLine("createInstanceBaseForAllKinds - 4");

                Services services = new WorkerServicesImpl(this, cid, unit_slice);
                unit_slice.setServices(services);

                Console.WriteLine("createInstanceBaseForAllKinds - 6");

                if (properties.hasKey(Constants.KEY_KEY))
                {
                    int[] facet_topology      = properties.getIntArray(Constants.FACET_TOPOLOGY, new int[0]);
                    int   this_facet_instance = properties.getInt(Constants.FACET_INSTANCE, 0);
                    int   this_facet          = properties.getInt(Constants.FACET, 0);
                    unit_slice.ThisFacetInstance = this_facet_instance;
                    unit_slice.ThisFacet         = facet_topology[this_facet_instance];

                    Console.WriteLine("createInstanceBaseForAllKinds - 7 - PASSOU DIRETO");

                    unit_slice.configure_facet_topology(facet_topology, unit_mapping);

                    if (kind == Constants.KIND_BINDING)
                    {
                        Console.WriteLine("createInstanceBaseForAllKinds - 8");

                        IBindingKind unit_slice_binding_root = (IBindingKind)unit_slice;
                        string[]     ip_address_facets       = properties.getStringArray(Constants.FACET_IP_ADDRESS, new string[0]);
                        int[]        port_facets             = properties.getIntArray(Constants.FACET_PORT, new int[0]);
                        Console.WriteLine("createInstanceBaseForAllKinds - 9" + ip_address_facets.Length + "," + port_facets.Length);
                        configure_facet_address(unit_slice_binding_root, ip_address_facets, port_facets);
                        Console.WriteLine("createInstanceBaseForAllKinds - 10");

                        Console.WriteLine("createInstanceBaseForAllKinds - 11 ");
                    }
                }
                else
                {
                    Console.WriteLine("createInstanceBaseForAllKinds - NO SPLIT");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("createInstanceBaseForAllKinds - EXCEPTION");
                Console.WriteLine("EXCEPTION MESSAGE -" + e.Message);
                Console.WriteLine("INNER EXCEPTION MESSAGE -" + e.InnerException.Message);
                throw e;
            }

            Connector.closeConnection();

            return(cid);
        }
        private CodeCompileUnit createCompileUnit(string package_path, string unit_class_name, out string[] dependencies)
        {
            IList <string> dependency_list = new List <string>();
            IList <string> usings_list     = new List <string>();

            CodeCompileUnit compileUnit = new CodeCompileUnit();

            #region namespace

            AbstractComponentFunctor acf = BackEnd.acfdao.retrieve(id_abstract);
            Interface i = BackEnd.idao.retrieve(id_abstract, id_interface);

            CodeNamespace globalNamespace = new CodeNamespace();
            compileUnit.Namespaces.Add(globalNamespace);

            CodeNamespace ns = new CodeNamespace(package_path);
            compileUnit.Namespaces.Add(ns);

            #endregion

            #region class

            IDictionary <string, int> par_order;
            InterfaceSignature        interface_type_descriptor = createSliceAccessorType(i, out par_order);
            CodeTypeReference         type_ref = buildCodeTypeReference(interface_type_descriptor, dependency_list, usings_list);

            string[] ss = i.Class_name.Split(new char[] { '.' });

            string unit_interface_name = ss[ss.Length - 1];
            //string unit_class_name = unit_interface_name + wrapper_source_name_suffix;
            CodeTypeDeclaration unit_class = new CodeTypeDeclaration(unit_class_name);
            ns.Types.Add(unit_class);

            #region class / inheritance

            unit_class.BaseTypes.Add("br.ufc.pargo.hpe.ConnectorImpl.IConnectorImpl");
            unit_class.BaseTypes.Add(type_ref);

            dependency_list.Add(LoaderApp.buildDllName(acf.Library_path, i.Assembly_string) + ".dll");
            dependency_list.Add("DGAC.dll");

            #endregion


            #region class / type parameters

            unit_class.TypeParameters.AddRange(createContextParameters(interface_type_descriptor, par_order, dependency_list, usings_list));

            #endregion

            #region class / public slice accessors

            IList <Slice> slice_list = BackEnd.sdao.listByInterface(id_abstract, id_interface);

            foreach (Slice s in slice_list)
            {
                if (s.isPublic())
                {
                    string slice_accessor_name = s.PortName;

                    InterfaceSignature isig_slice          = interface_type_descriptor.slice_types[slice_accessor_name];
                    CodeTypeReference  slice_accessor_type = buildCodeTypeReference(isig_slice, dependency_list, usings_list);

                    CodeMemberField slice_accessor_field = createSliceAccessorField(slice_accessor_name.ToLower(), slice_accessor_type);
                    unit_class.Members.Add(slice_accessor_field);

                    CodeMemberProperty slice_accessor_property = createSliceAccessorProperty(slice_accessor_name, slice_accessor_type);
                    unit_class.Members.Add(slice_accessor_property);
                }
            }

            #endregion

            #region class / actions and condition

            IList <InterfaceAction> action_list = BackEnd.iadao.list(id_abstract, id_interface);

            foreach (InterfaceAction ia in action_list)
            {
                if (ia.IsCondition)
                {
                    unit_class.Members.Add(createConditionMethod(ia.Id_action));
                }
                else
                {
                    if (!ia.Id_action.Equals("main"))
                    {
                        unit_class.Members.Add(createActionMethod(ia.Id_action));
                    }
                    else
                    {
                        // The default method "main" is pre-defined in the IConnectorImpl super class.
                    }
                }
            }
            #endregion


            #region using dependencies


            foreach (string using_reference in usings_list)
            {
                CodeNamespaceImport import = new CodeNamespaceImport();
                import.Namespace = using_reference;
                globalNamespace.Imports.Add(import);
            }

            #endregion

            #endregion

            dependencies = new string[dependency_list.Count];
            dependency_list.CopyTo(dependencies, 0);

            return(compileUnit);
        }
Esempio n. 11
0
        private string buildInstantiatorStringOfSystem(string component_ref, int facet_instance, Tuple <int, string>[] facet_address_list, int[] nodes)
        {
            IList <AbstractComponentFunctor> acf_list = BackEnd.acfdao.listByKind(Constants.KIND_APPLICATION_NAME);
            AbstractComponentFunctor         acf      = acf_list [0];

            Instantiator.InstanceType instantiator = new Instantiator.InstanceType();
            Instantiator.ComponentFunctorApplicationType contract = new Instantiator.ComponentFunctorApplicationType();
            contract.component_ref = component_ref;
            contract.argument      = new Instantiator.ContextArgumentType[0];

            instantiator.contextual_type         = contract;
            instantiator.facet_instanceSpecified = true;
            instantiator.facet_instance          = facet_instance;

            IList <Interface> units = BackEnd.idao.list(acf.Id_abstract);

            instantiator.unit_mapping = new Instantiator.UnitMappingType[units.Count];

            Console.WriteLine("buildInstantiatorStringOfSystem 0 " + units.Count);

            int iu = 0;

            foreach (Interface u in units)
            {
                instantiator.unit_mapping [iu] = new Instantiator.UnitMappingType();

                instantiator.unit_mapping [iu].unit_id    = u.Id_interface;
                instantiator.unit_mapping [iu].unit_index = 0;

                instantiator.unit_mapping [iu].facet_instanceSpecified = true;
                instantiator.unit_mapping [iu].facet_instance          = instantiator.unit_mapping [iu].facet = u.Facet;

                int number_of_nodes = nodes[instantiator.unit_mapping [iu].facet_instance];
                instantiator.unit_mapping [iu].node = new int[number_of_nodes];
                for (int n = 0; n < number_of_nodes; n++)
                {
                    instantiator.unit_mapping [iu].node [n] = n;
                }

                iu++;
            }

            Console.WriteLine("buildInstantiatorStringOfSystem 1");

            instantiator.facet_address = new Instantiator.FacetAddressType[facet_address_list.Length];
            for (int i = 0; i < facet_address_list.Length; i++)
            {
                instantiator.facet_address [i] = new Instantiator.FacetAddressType();
                instantiator.facet_address [i].facet_instanceSpecified = true;
                instantiator.facet_address [i].facet_instance          = instantiator.facet_address [i].facet = facet_address_list[i].Item1;
                instantiator.facet_address [i].facetSpecified          = true;
                instantiator.facet_address [i].facet = instantiator.facet_address [i].facet_instance;

                string platform_address = facet_address_list[i].Item2 != null ? facet_address_list[i].Item2 : "http://127.0.0.1:100";

                Uri uri = new Uri(platform_address);

                instantiator.facet_address [i].address       = uri.Host;
                instantiator.facet_address [i].portSpecified = true;
                instantiator.facet_address [i].port          = uri.Port;
            }

            Console.WriteLine("buildInstantiatorStringOfSystem 2");

            string instantiator_string = LoaderApp.serializeInstantiator(instantiator);

            return(instantiator_string);
        }