예제 #1
0
 public async Task <ICommand> UpdateEdgeAgentAsync(IModuleWithIdentity module, IRuntimeInfo runtimeInfo)
 {
     using (this.factoryMetrics.MeasureTime("update"))
     {
         return(await this.underlying.UpdateEdgeAgentAsync(module, runtimeInfo));
     }
 }
예제 #2
0
 public Task <ICommand> CreateAsync(IModuleWithIdentity module, IRuntimeInfo runtimeInfo) =>
 Task.FromResult(CreateOrUpdateCommand.BuildCreate(
                     this.moduleManager,
                     module.Module,
                     module.ModuleIdentity,
                     this.configSource,
                     this.combinedConfigProvider.GetCombinedConfig(module.Module, runtimeInfo)) as ICommand);
예제 #3
0
 public Task <ICommand> CreateAsync(IModuleWithIdentity module, IRuntimeInfo runtimeInfo)
 {
     if (this.checkImagePullBeforeModuleCreate)
     {
         T config = this.combinedConfigProvider.GetCombinedConfig(module.Module, runtimeInfo);
         return(Task.FromResult(
                    new GroupCommand(
                        new PrepareUpdateCommand(this.moduleManager, module.Module, config),
                        CreateOrUpdateCommand.BuildCreate(
                            this.moduleManager,
                            module.Module,
                            module.ModuleIdentity,
                            this.configSource,
                            config,
                            this.edgeDeviceHostname,
                            this.parentEdgeHostname)
                        as ICommand) as ICommand));
     }
     else
     {
         return(Task.FromResult(
                    CreateOrUpdateCommand.BuildCreate(
                        this.moduleManager,
                        module.Module,
                        module.ModuleIdentity,
                        this.configSource,
                        this.combinedConfigProvider.GetCombinedConfig(module.Module, runtimeInfo),
                        this.edgeDeviceHostname,
                        this.parentEdgeHostname)
                    as ICommand));
     }
 }
예제 #4
0
 public async Task <ICommand> CreateAsync(IModuleWithIdentity module, IRuntimeInfo runtimeInfo)
 {
     this.factoryMetrics.AddMessage(module.Module, FactoryMetrics.ModuleCommandMetric.Start);
     using (this.factoryMetrics.MeasureTime("create"))
     {
         return(await this.underlying.CreateAsync(module, runtimeInfo));
     }
 }
예제 #5
0
 public async Task <ICommand> UpdateAsync(IModule current, IModuleWithIdentity next, IRuntimeInfo runtimeInfo)
 {
     this.factoryMetrics.AddMessage(current, FactoryMetrics.ModuleCommandMetric.Start);
     this.factoryMetrics.AddMessage(next.Module, FactoryMetrics.ModuleCommandMetric.Stop);
     using (this.factoryMetrics.MeasureTime("update"))
     {
         return(await this.underlying.UpdateAsync(current, next, runtimeInfo));
     }
 }
예제 #6
0
 public async Task <ICommand> UpdateAsync(IModule current, IModuleWithIdentity next, IRuntimeInfo runtimeInfo)
 {
     if (current is DockerModule currentDockerModule && next.Module is DockerModule)
     {
         return(new GroupCommand(
                    new RemoveCommand(this.client, currentDockerModule),
                    await this.CreateAsync(next, runtimeInfo)));
     }
     return(NullCommand.Instance);
 }
예제 #7
0
 public async Task <ICommand> CreateAsync(IModuleWithIdentity module, IRuntimeInfo runtimeInfo)
 {
     if (module.Module is DockerModule dockerModule)
     {
         CombinedDockerConfig combinedDockerConfig = this.combinedConfigProvider.GetCombinedConfig(dockerModule, runtimeInfo);
         return(new GroupCommand(
                    new PullCommand(this.client, combinedDockerConfig),
                    await CreateCommand.BuildAsync(this.client, dockerModule, module.ModuleIdentity, this.dockerLoggerConfig, this.configSource, module.Module is EdgeHubDockerModule)));
     }
     return(NullCommand.Instance);
 }
예제 #8
0
 public virtual bool Equals(IModuleWithIdentity other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(this.module.Equals(other.Module) && this.moduleIdentity.Equals(other.ModuleIdentity));
 }
예제 #9
0
        public async Task <ICommand> UpdateAsync(IModule current, IModuleWithIdentity next, IRuntimeInfo runtimeInfo)
        {
            if (current is DockerModule currentDockerModule && next.Module is DockerModule nextDockerModule)
            {
                CombinedDockerConfig combinedDockerConfig = this.combinedConfigProvider.GetCombinedConfig(nextDockerModule, runtimeInfo);
                return(new GroupCommand(
                           new PullCommand(this.client, combinedDockerConfig),
                           new StopCommand(this.client, currentDockerModule),
                           new RemoveCommand(this.client, currentDockerModule),
                           await CreateCommand.BuildAsync(this.client, nextDockerModule, next.ModuleIdentity, this.dockerLoggerConfig, this.configSource, next.Module is EdgeHubDockerModule)));
            }

            return(NullCommand.Instance);
        }
예제 #10
0
        async Task <ICommand> UpdateAsync(Option <IModule> current, IModuleWithIdentity next, IRuntimeInfo runtimeInfo, bool start)
        {
            T config = this.combinedConfigProvider.GetCombinedConfig(next.Module, runtimeInfo);

            return(new GroupCommand(
                       new PrepareUpdateCommand(this.moduleManager, next.Module, config),
                       await current.Match(c => this.StopAsync(c), () => Task.FromResult <ICommand>(NullCommand.Instance)),
                       CreateOrUpdateCommand.BuildUpdate(
                           this.moduleManager,
                           next.Module,
                           next.ModuleIdentity,
                           this.configSource,
                           config,
                           start) as ICommand));
        }
예제 #11
0
        public async Task <ICommand> CreateAsync(IModuleWithIdentity module, IRuntimeInfo runtimeInfo)
        {
            if (module.Module is DockerModule dockerModule)
            {
                CombinedDockerConfig combinedDockerConfig = this.combinedConfigProvider.GetCombinedConfig(dockerModule, runtimeInfo);

                var commands = new List <ICommand>();
                if (module.Module.ImagePullPolicy != ImagePullPolicy.Never)
                {
                    commands.Add(new PullCommand(this.client, combinedDockerConfig));
                }

                commands.Add(await CreateCommand.BuildAsync(this.client, dockerModule, module.ModuleIdentity, this.dockerLoggerConfig, this.configSource, module.Module is EdgeHubDockerModule));
                return(new GroupCommand(commands.ToArray()));
            }

            return(NullCommand.Instance);
        }
예제 #12
0
        public async Task <ICommand> UpdateAsync(IModule current, IModuleWithIdentity next, IRuntimeInfo runtimeInfo)
        {
            if (current is DockerModule currentDockerModule && next.Module is DockerModule nextDockerModule)
            {
                CombinedDockerConfig combinedDockerConfig = this.combinedConfigProvider.GetCombinedConfig(nextDockerModule, runtimeInfo);
                var commands = new List <ICommand>();
                if (next.Module.ImagePullPolicy != ImagePullPolicy.Never)
                {
                    commands.Add(new PullCommand(this.client, combinedDockerConfig));
                }

                commands.AddRange(
                    new ICommand[]
                {
                    new StopCommand(this.client, currentDockerModule),
                    new RemoveCommand(this.client, currentDockerModule),
                    await CreateCommand.BuildAsync(this.client, nextDockerModule, next.ModuleIdentity, this.dockerLoggerConfig, this.configSource, next.Module is EdgeHubDockerModule)
                });
                return(new GroupCommand(commands.ToArray()));
            }

            return(NullCommand.Instance);
        }
예제 #13
0
        internal override InitializationResult _Init(IConfigurationRoot configuration, IContainer container)
        {
            _dockerClient = new DockerClientConfiguration(new Uri(configuration.GetValue <string>("DockerUri")))
                            .CreateClient();

            var configSource = new EmulatorConfigSource(configuration);

            var dockerLoggingOptions = new Dictionary <string, string>
            {
                { "max-size", "1m" },
                { "max-file", "1" }
            };
            var loggingConfig = new DockerLoggingConfig("json-file", dockerLoggingOptions);

            var dockerAuthConfig = configuration.GetSection("DockerRegistryAuth").Get <List <AuthConfig> >() ??
                                   new List <AuthConfig>();
            var combinedDockerConfigProvider = new CombinedDockerConfigProvider(dockerAuthConfig);
            //var runtimeInfoProvider = RuntimeInfoProvider.CreateAsync(_dockerClient);

            var dockerModule = new Devices.Edge.Agent.Docker.DockerModule(
                Name,
                DockerHostingSettings.Version,
                DockerHostingSettings.DesiredStatus.Value,
                DockerHostingSettings.RestartPolicy.Value,
                DockerHostingSettings.Config,
                null,
                null
                );

            var connectionString =
                configuration.GetValue <string>(Devices.Edge.Agent.Core.Constants.EdgeHubConnectionStringKey);
            var connectionStringBuilder = IotHubConnectionStringBuilder.Create(connectionString);

            var moduleIdentity = new ModuleIdentity(connectionStringBuilder.IotHubName,
                                                    Environment.MachineName,
                                                    connectionStringBuilder.DeviceId,
                                                    connectionStringBuilder.ModuleId,
                                                    new ConnectionStringCredentials(connectionString));

            _moduleWithIdentity = new ModuleWithIdentity(dockerModule, moduleIdentity);
            //var combinedDockerConfig = combinedDockerConfigProvider.GetCombinedConfig(dockerModule, runtimeInfo);

            _dockerFactory = new LoggingCommandFactory(new DockerCommandFactory(_dockerClient,
                                                                                loggingConfig,
                                                                                configSource,
                                                                                combinedDockerConfigProvider),
                                                       Devices.Edge.Util.Logger.Factory);

            //var updateCommand = new GroupCommand(
            //      new RemoveCommand(_dockerClient, dockerModule),
            //        new GroupCommand(
            //            new PullCommand(_dockerClient, combinedDockerConfig),
            //            CreateCommand.BuildAsync(_dockerClient,
            //            dockerModule,
            //            dockerModuleWithIdentity.ModuleIdentity,
            //            loggingConfig,
            //            configSource,
            //            false).Result));

            //_createCommand = new GroupCommand(
            //   new PullCommand(_dockerClient, combinedDockerConfig),
            //   CreateCommand.BuildAsync(_dockerClient,
            //   dockerModule,
            //   dockerModuleWithIdentity.ModuleIdentity,
            //   loggingConfig,
            //   configSource,
            //   false).Result);

            //_startCommand = dockerFactory.StartAsync(dockerModule).Result;
            return(base._Init(configuration, container));
        }
예제 #14
0
 public Task <ICommand> UpdateEdgeAgentAsync(IModuleWithIdentity module, IRuntimeInfo runtimeInfo) =>
 this.UpdateAsync(Option.None <IModule>(), module, runtimeInfo, true);
예제 #15
0
 public Task <ICommand> UpdateAsync(IModule current, IModuleWithIdentity next, IRuntimeInfo runtimeInfo) =>
 this.UpdateAsync(Option.Some(current), next, runtimeInfo, false);
예제 #16
0
 public async Task <ICommand> CreateAsync(IModuleWithIdentity module, IRuntimeInfo runtimeInfo) => new LoggingCommand(await this.underlying.CreateAsync(module, runtimeInfo), "create", this.logger);
예제 #17
0
 public async Task <ICommand> UpdateAsync(IModule current, IModuleWithIdentity next, IRuntimeInfo runtimeInfo) => new LoggingCommand(await this.underlying.UpdateAsync(current, next, runtimeInfo), "update", this.logger);
예제 #18
0
 public Task <ICommand> UpdateEdgeAgentAsync(IModuleWithIdentity module, IRuntimeInfo runtimeInfo) => Task.FromResult(NullCommand.Instance as ICommand);
예제 #19
0
 public Task <ICommand> UpdateEdgeAgentAsync(IModuleWithIdentity module, IRuntimeInfo runtimeInfo)
 {
     Assert.True(module.Module is TestModule);
     return(Task.FromResult <ICommand>(new TestCommand(TestCommandType.TestUpdateEdgeAgent, module.Module, this.Recorder)));
 }
예제 #20
0
 public Task <ICommand> UpdateAsync(IModule current, IModuleWithIdentity next, IRuntimeInfo runtimeInfo)
 {
     Assert.True(current is TestModule);
     Assert.True(next.Module is TestModule);
     return(Task.FromResult <ICommand>(new TestCommand(TestCommandType.TestUpdate, next.Module, this.Recorder)));
 }
예제 #21
0
 public Task <ICommand> CreateAsync(IModuleWithIdentity module, IRuntimeInfo runtimeInfo)
 {
     Assert.True(module.Module is TestModule);
     return(Task.FromResult <ICommand>(new TestCommand(TestCommandType.TestCreate, module.Module, this.Recorder, true)));
 }
예제 #22
0
 public async Task <ICommand> UpdateEdgeAgentAsync(IModuleWithIdentity module, IRuntimeInfo runtimeInfo) => new LoggingCommand(await this.underlying.UpdateEdgeAgentAsync(module, runtimeInfo), "update Edge Agent", this.logger);
예제 #23
0
 public Task <ICommand> CreateAsync(IModuleWithIdentity module, IRuntimeInfo runtimeInfo) =>
 Task.FromResult((ICommand)NullCommand.Instance);
예제 #24
0
 public Task <ICommand> UpdateAsync(IModule current, IModuleWithIdentity next, IRuntimeInfo runtimeInfo) =>
 Task.FromResult((ICommand)NullCommand.Instance);