Пример #1
0
 public ModuleManager(IServiceProvider serviceProvider,
                      IModuleConfigBuilder builder,
                      ApplicationPartManager appPartManager,
                      ICacheManager <object> cacheManager,
                      IModulesUnitOfWork unitOfWork)
 {
     this._logger         = serviceProvider.GetService <ILoggerFactory>().CreateLogger <ModuleManager>();
     this._builder        = builder;
     this._cacheManager   = cacheManager;
     this._appPartManager = appPartManager;
     this._unitOfWork     = unitOfWork;
 }
Пример #2
0
        ModuleConfiguration BuildEdgeAgent(IEnumerable <ModuleConfiguration> configs)
        {
            // caller guarantees that $edgeAgent exists in moduleBuilders
            IModuleConfigBuilder agentBuilder = this.moduleBuilders[ModuleName.EdgeAgent];

            // Settings boilerplate
            var settings = new Dictionary <string, object>()
            {
                ["minDockerVersion"] = "v1.25"
            };

            // Registry credentials under settings
            if (this.registries.Count != 0)
            {
                var credentials = new Dictionary <string, object>();
                for (int i = 0; i < this.registries.Count; ++i)
                {
                    Registry registry = this.registries[i];
                    credentials.Add(
                        $"reg{i}",
                        new
                    {
                        registry.Username,
                        registry.Password,
                        registry.Address
                    });
                }

                settings["registryCredentials"] = credentials;
            }

            // Deployment info for edge agent
            var systemModules = new Dictionary <string, object>()
            {
                // We need to call agentBuilder.Build() *early* here because we
                // need the agent's own deployment information (e.g. image, env
                // vars). Even though we aren't finished building the agent
                // config yet, the agent builder has enough info at this
                // point to provide what we need. We'll call Build() again
                // later to get an updated module configuration that includes
                // deployment info for other modules, plus desired properties
                // for all modules.
                [ParseModuleName(agentBuilder.Name).name] = agentBuilder.Build().Deployment
            };

            // Deployment info for all other modules
            var modules = new Dictionary <string, object>();

            foreach (ModuleConfiguration config in configs)
            {
                (string name, bool system) = ParseModuleName(config.Name);
                IDictionary <string, object> coll = system ? systemModules : modules;
                coll[name] = config.Deployment;
            }

            // Compose edge agent's desired properties
            var desiredProperties = new Dictionary <string, object>
            {
                ["schemaVersion"] = "1.0",
                ["runtime"]       = new Dictionary <string, object>
                {
                    ["type"]     = "docker",
                    ["settings"] = settings
                },
                ["systemModules"] = systemModules
            };

            if (modules.Count != 0)
            {
                desiredProperties["modules"] = modules;
            }

            agentBuilder.WithDesiredProperties(desiredProperties);

            return(agentBuilder.Build());
        }