Пример #1
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);
        public CombinedKubernetesConfig GetCombinedConfig(IModule module, IRuntimeInfo runtimeInfo)
        {
            CombinedDockerConfig dockerConfig = this.dockerConfigProvider.GetCombinedConfig(module, runtimeInfo);

            // if the workload URI is a Unix domain socket then volume mount it into the container
            HostConfig hostConfig = this.AddSocketBinds(module, Option.Maybe(dockerConfig.CreateOptions.HostConfig));

            CreatePodParameters createOptions = new CreatePodParameters(
                dockerConfig.CreateOptions.Env,
                dockerConfig.CreateOptions.ExposedPorts,
                hostConfig,
                dockerConfig.CreateOptions.Image,
                dockerConfig.CreateOptions.Labels);

            if (this.enableKubernetesExtensions)
            {
                Option <KubernetesExperimentalCreatePodParameters> experimentalOptions = KubernetesExperimentalCreatePodParameters.Parse(dockerConfig.CreateOptions.OtherProperties);
                experimentalOptions.ForEach(parameters => createOptions.Volumes      = parameters.Volumes);
                experimentalOptions.ForEach(parameters => createOptions.NodeSelector = parameters.NodeSelector);
                experimentalOptions.ForEach(parameters => createOptions.Resources    = parameters.Resources);
            }

            Option <ImagePullSecret> imagePullSecret = dockerConfig.AuthConfig
                                                       .Map(auth => new ImagePullSecret(auth));

            return(new CombinedKubernetesConfig(dockerConfig.Image, createOptions, imagePullSecret));
        }
Пример #3
0
 public ProviderStatusServiceBase(IProviderStatusRepository <TModel> providerStatusRepository, IEventAggregator eventAggregator, IRuntimeInfo runtimeInfo, Logger logger)
 {
     _providerStatusRepository = providerStatusRepository;
     _eventAggregator          = eventAggregator;
     _runtimeInfo = runtimeInfo;
     _logger      = logger;
 }
Пример #4
0
 public SpinService(IRuntimeInfo runtimeInfo, IProcessProvider processProvider, IStartupContext startupContext, Logger logger)
 {
     _runtimeInfo = runtimeInfo;
     _processProvider = processProvider;
     _startupContext = startupContext;
     _logger = logger;
 }
Пример #5
0
 public SystemModule(IAppFolderInfo appFolderInfo,
                     IRuntimeInfo runtimeInfo,
                     IPlatformInfo platformInfo,
                     IOsInfo osInfo,
                     IRouteCacheProvider routeCacheProvider,
                     IConfigFileProvider configFileProvider,
                     IMainDatabase database,
                     ILifecycleService lifecycleService,
                     IDeploymentInfoProvider deploymentInfoProvider)
     : base("system")
 {
     _appFolderInfo          = appFolderInfo;
     _runtimeInfo            = runtimeInfo;
     _platformInfo           = platformInfo;
     _osInfo                 = osInfo;
     _routeCacheProvider     = routeCacheProvider;
     _configFileProvider     = configFileProvider;
     _database               = database;
     _lifecycleService       = lifecycleService;
     _deploymentInfoProvider = deploymentInfoProvider;
     Get("/status", x => GetStatus());
     Get("/routes", x => GetRoutes());
     Post("/shutdown", x => Shutdown());
     Post("/restart", x => Restart());
 }
Пример #6
0
        public async Task GetUnknownRuntimeInfoTest()
        {
            // Arrange
            var systemInfoResponse = new SystemInfoResponse
            {
                OSType       = OperatingSystemType,
                Architecture = Architecture
            };

            var runtimeInfoProvider  = Mock.Of <IRuntimeInfoProvider>();
            var moduleStateStore     = Mock.Of <IEntityStore <string, ModuleState> >();
            var restartPolicyManager = Mock.Of <IRestartPolicyManager>();

            var environment = new DockerEnvironment(runtimeInfoProvider, DeploymentConfig.Empty, moduleStateStore, restartPolicyManager, OperatingSystemType, Architecture);

            // act
            IRuntimeInfo reportedRuntimeInfo = await environment.GetRuntimeInfoAsync();

            // assert
            Assert.True(reportedRuntimeInfo is DockerReportedUnknownRuntimeInfo);
            var dockerReported = reportedRuntimeInfo as DockerReportedUnknownRuntimeInfo;

            Assert.Equal(OperatingSystemType, dockerReported.Platform.OperatingSystemType);
            Assert.Equal(Architecture, dockerReported.Platform.Architecture);
        }
Пример #7
0
 public NetworkingService(IFileSystem fileSystem, IRuntimeInfo runtime, IConsole console)
 {
     _fileSystem         = fileSystem;
     _runtime            = runtime;
     _console            = console;
     _ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
 }
Пример #8
0
        AgentState BuildCurrentState(ModuleSet moduleSet, IRuntimeInfo runtimeInfo, long version, DeploymentStatus status)
        {
            IEdgeAgentModule edgeAgentModule;
            IEdgeHubModule   edgeHubModule;
            ImmutableDictionary <string, IModule>  userModules;
            IImmutableDictionary <string, IModule> currentModules = moduleSet?.Modules;

            if (currentModules == null)
            {
                edgeAgentModule = UnknownEdgeAgentModule.Instance;
                edgeHubModule   = UnknownEdgeHubModule.Instance;
                userModules     = ImmutableDictionary <string, IModule> .Empty;
            }
            else
            {
                edgeAgentModule = currentModules.ContainsKey(Constants.EdgeAgentModuleName) ? moduleSet.Modules[Constants.EdgeAgentModuleName] as IEdgeAgentModule : UnknownEdgeAgentModule.Instance;
                edgeHubModule   = currentModules.ContainsKey(Constants.EdgeHubModuleName) ? moduleSet.Modules[Constants.EdgeHubModuleName] as IEdgeHubModule : UnknownEdgeHubModule.Instance;
                userModules     = currentModules.RemoveRange(new[] { Constants.EdgeAgentModuleName, Constants.EdgeHubModuleName }).ToImmutableDictionary();
            }

            var currentState = new AgentState(
                version,
                status,
                runtimeInfo,
                new SystemModules(edgeAgentModule, edgeHubModule),
                userModules,
                CurrentReportedPropertiesSchemaVersion,
                this.versionInfo);

            return(currentState);
        }
Пример #9
0
 public SpinService(IRuntimeInfo runtimeInfo, IProcessProvider processProvider, IStartupContext startupContext, Logger logger)
 {
     _runtimeInfo     = runtimeInfo;
     _processProvider = processProvider;
     _startupContext  = startupContext;
     _logger          = logger;
 }
Пример #10
0
        public virtual CombinedDockerConfig GetCombinedConfig(IModule module, IRuntimeInfo runtimeInfo)
        {
            if (!(module is IModule <DockerConfig> moduleWithDockerConfig))
            {
                throw new InvalidOperationException("Module does not contain DockerConfig");
            }

            if (!(runtimeInfo is IRuntimeInfo <DockerRuntimeConfig> dockerRuntimeConfig))
            {
                throw new InvalidOperationException("RuntimeInfo does not contain DockerRuntimeConfig");
            }

            // Convert registry credentials from config to AuthConfig objects
            List <AuthConfig> deploymentAuthConfigs = dockerRuntimeConfig.Config.RegistryCredentials
                                                      .Select(c =>
            {
                string address = this.parser.ParseURI(c.Value.Address).GetOrElse(c.Value.Address);
                return(new AuthConfig {
                    ServerAddress = address, Username = c.Value.Username, Password = c.Value.Password
                });
            })
                                                      .ToList();

            // First try to get matching auth config from the runtime info. If no match is found,
            // then try the auth configs from the environment
            Option <AuthConfig> authConfig = deploymentAuthConfigs.FirstAuthConfig(moduleWithDockerConfig.Config.Image)
                                             .Else(() => this.authConfigs.FirstAuthConfig(moduleWithDockerConfig.Config.Image));

            return(new CombinedDockerConfig(moduleWithDockerConfig.Config.Image, moduleWithDockerConfig.Config.CreateOptions, moduleWithDockerConfig.Config.Digest, authConfig));
        }
Пример #11
0
 public BrowserService(IProcessProvider processProvider, IConfigFileProvider configFileProvider, IRuntimeInfo runtimeInfo, Logger logger)
 {
     _processProvider = processProvider;
     _configFileProvider = configFileProvider;
     _runtimeInfo = runtimeInfo;
     _logger = logger;
 }
Пример #12
0
 public EdgeDeploymentCommand(
     string deviceNamespace,
     ResourceName resourceName,
     IKubernetes client,
     IEnumerable <IModule> modules,
     IRuntimeInfo runtimeInfo,
     ICombinedConfigProvider <CombinedKubernetesConfig> configProvider)
 {
     this.deviceNamespace = KubeUtils.SanitizeK8sValue(Preconditions.CheckNonWhiteSpace(deviceNamespace, nameof(deviceNamespace)));
     this.resourceName    = Preconditions.CheckNotNull(resourceName, nameof(resourceName));
     this.client          = Preconditions.CheckNotNull(client, nameof(client));
     this.modules         = Preconditions.CheckNotNull(modules, nameof(modules)).ToList();
     this.runtimeInfo     = Preconditions.CheckNotNull(runtimeInfo, nameof(runtimeInfo));
     this.configProvider  = Preconditions.CheckNotNull(configProvider, nameof(configProvider));
     this.id = new Lazy <string>(() => this.modules.Aggregate(string.Empty, (prev, module) => module.Name + prev));
     this.serializerSettings = new JsonSerializerSettings
     {
         ContractResolver = new OverrideJsonIgnoreOfBaseClassContractResolver(
             new Dictionary <Type, string[]>
         {
             [typeof(KubernetesModule)] = new[] { nameof(KubernetesModule.Name) }
         })
         {
             // Environment variable (env) property JSON casing should be left alone
             NamingStrategy = new CamelCaseNamingStrategy
             {
                 ProcessDictionaryKeys = false
             }
         }
     };
 }
Пример #13
0
 public WaitForExit(IRuntimeInfo runtimeInfo, IProcessProvider processProvider, IStartupContext startupContext, ILogger logger)
 {
     _runtimeInfo     = runtimeInfo;
     _processProvider = processProvider;
     _startupContext  = startupContext;
     _logger          = logger;
 }
Пример #14
0
        public async Task GetRuntimeInfoTest()
        {
            // Arrange
            var systemInfo = new SystemInfo(OperatingSystemType, Architecture, Version);

            var store = Mock.Of <IEntityStore <string, ModuleState> >();
            var restartPolicyManager = Mock.Of <IRestartPolicyManager>();

            var    runtimeInfoProvider  = Mock.Of <IRuntimeInfoProvider>(r => r.GetSystemInfo(CancellationToken.None) == Task.FromResult(systemInfo));
            var    moduleStateStore     = Mock.Of <IEntityStore <string, ModuleState> >();
            string minDockerVersion     = "20";
            string dockerLoggingOptions = "dummy logging options";

            var deploymentConfig = new DeploymentConfig(
                "1.0",
                new DockerRuntimeInfo("docker", new DockerRuntimeConfig(minDockerVersion, dockerLoggingOptions)),
                new SystemModules(Option.None <IEdgeAgentModule>(), Option.None <IEdgeHubModule>()),
                new Dictionary <string, IModule>());

            var environment = new DockerEnvironment(runtimeInfoProvider, deploymentConfig, moduleStateStore, restartPolicyManager, systemInfo.OperatingSystemType, systemInfo.Architecture, systemInfo.Version);

            // act
            IRuntimeInfo reportedRuntimeInfo = await environment.GetRuntimeInfoAsync();

            // assert
            Assert.True(reportedRuntimeInfo is DockerReportedRuntimeInfo);
            var dockerReported = reportedRuntimeInfo as DockerReportedRuntimeInfo;

            Assert.Equal(OperatingSystemType, dockerReported.Platform.OperatingSystemType);
            Assert.Equal(Architecture, dockerReported.Platform.Architecture);
            Assert.Equal(Version, dockerReported.Platform.Version);
            Assert.Equal(minDockerVersion, dockerReported.Config.MinDockerVersion);
            Assert.Equal(dockerLoggingOptions, dockerReported.Config.LoggingOptions);
        }
Пример #15
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));
     }
 }
Пример #16
0
 public InstallUpdateService(ICheckUpdateService checkUpdateService, IAppFolderInfo appFolderInfo,
                             IDiskProvider diskProvider, IHttpClient httpClient,
                             IArchiveService archiveService, IProcessProvider processProvider,
                             IVerifyUpdates updateVerifier,
                             IConfigFileProvider configFileProvider,
                             IRuntimeInfo runtimeInfo,
                             IBackupService backupService,
                             Logger logger)
 {
     if (configFileProvider == null)
     {
         throw new ArgumentNullException("configFileProvider");
     }
     _checkUpdateService = checkUpdateService;
     _appFolderInfo      = appFolderInfo;
     _diskProvider       = diskProvider;
     _httpClient         = httpClient;
     _archiveService     = archiveService;
     _processProvider    = processProvider;
     _updateVerifier     = updateVerifier;
     _configFileProvider = configFileProvider;
     _runtimeInfo        = runtimeInfo;
     _backupService      = backupService;
     _logger             = logger;
 }
Пример #17
0
 public BrowserService(IProcessProvider processProvider, IConfigFileProvider configFileProvider, IRuntimeInfo runtimeInfo, Logger logger)
 {
     _processProvider    = processProvider;
     _configFileProvider = configFileProvider;
     _runtimeInfo        = runtimeInfo;
     _logger             = logger;
 }
Пример #18
0
        async Task <IEnumerable <ICommand> > ProcessDesiredAndCurrentSets(
            ModuleSet desired, ModuleSet current, IRuntimeInfo runtimeInfo, IImmutableDictionary <string, IModuleIdentity> moduleIdentities)
        {
            Diff diff = desired.Diff(current);
            IEnumerable <Task <ICommand> > stopTasks = current.Modules.Select(m => this.commandFactory.StopAsync(m.Value));
            IEnumerable <ICommand>         stop      = await Task.WhenAll(stopTasks);

            IEnumerable <Task <ICommand> > removeTasks = diff.Removed.Select(name => this.commandFactory.RemoveAsync(current.Modules[name]));
            IEnumerable <ICommand>         remove      = await Task.WhenAll(removeTasks);

            // Only update changed modules
            IList <Task <ICommand> > updateTasks = diff.AddedOrUpdated
                                                   .Select(m => this.CreateOrUpdate(current, m, runtimeInfo, moduleIdentities))
                                                   .ToList();
            IEnumerable <ICommand> update = await Task.WhenAll(updateTasks);

            IEnumerable <Task <ICommand> > startTasks = desired.Modules.Values
                                                        .Where(m => m.DesiredStatus == ModuleStatus.Running)
                                                        .Select(m => this.commandFactory.StartAsync(m));
            IEnumerable <ICommand> start = await Task.WhenAll(startTasks);

            return(stop
                   .Concat(remove)
                   .Concat(update)
                   .Concat(start));
        }
Пример #19
0
        public async Task <Plan> PlanAsync(
            ModuleSet desired,
            ModuleSet current,
            IRuntimeInfo runtimeInfo,
            IImmutableDictionary <string, IModuleIdentity> moduleIdentities)
        {
            Events.LogDesired(desired);
            Events.LogCurrent(current);
            Events.LogIdentities(moduleIdentities);

            // Check that module names sanitize and remain unique.
            var groupedModules = desired.Modules.ToLookup(pair => KubeUtils.SanitizeK8sValue(pair.Key));

            if (groupedModules.Any(c => c.Count() > 1))
            {
                string nameList = groupedModules
                                  .Where(c => c.Count() > 1)
                                  .SelectMany(g => g, (pairs, pair) => pair.Key)
                                  .Join(",");
                throw new InvalidIdentityException($"Deployment will cause a name collision in Kubernetes namespace, modules: [{nameList}]");
            }

            // TODO: improve this so it is generic for all potential module types.
            if (!desired.Modules.Values.All(p => p is IModule <DockerConfig>))
            {
                throw new InvalidModuleException($"Kubernetes deployment currently only handles type={typeof(DockerConfig).FullName}");
            }

            // This is a workaround for K8s Public Preview Refresh
            // TODO: remove this workaround when merging to the main release
            desired = new ModuleSet(desired.Modules.Remove(Constants.EdgeAgentModuleName));
            current = new ModuleSet(current.Modules.Remove(Constants.EdgeAgentModuleName));

            Diff moduleDifference = desired.Diff(current);

            Plan plan;

            if (!moduleDifference.IsEmpty)
            {
                // The "Plan" here is very simple - if we have any change, publish all desired modules to a EdgeDeployment CRD.
                // The CRD allows us to give the customer a Kubernetes-centric way to see the deployment
                // and the status of that deployment through the "edgedeployments" API.
                var crdCommand  = new EdgeDeploymentCommand(this.deviceNamespace, this.resourceName, this.client, desired.Modules.Values, runtimeInfo, this.configProvider);
                var planCommand = await this.commandFactory.WrapAsync(crdCommand);

                var planList = new List <ICommand>
                {
                    planCommand
                };
                Events.PlanCreated(planList);
                plan = new Plan(planList);
            }
            else
            {
                plan = Plan.Empty;
            }

            return(plan);
        }
Пример #20
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));
     }
 }
Пример #21
0
        public async Task <Plan> PlanAsync(ModuleSet desired, ModuleSet current, IRuntimeInfo runtimeInfo, IImmutableDictionary <string, IModuleIdentity> moduleIdentities)
        {
            Diff diff = desired.Diff(current);
            Plan plan = diff.IsEmpty
                ? Plan.Empty
                : await this.CreatePlan(desired, current, runtimeInfo, moduleIdentities);

            return(plan);
        }
Пример #22
0
 public Router(INzbDroneServiceFactory nzbDroneServiceFactory, IServiceProvider serviceProvider,
               IConsoleService consoleService, IRuntimeInfo runtimeInfo, Logger logger)
 {
     _nzbDroneServiceFactory = nzbDroneServiceFactory;
     _serviceProvider        = serviceProvider;
     _consoleService         = consoleService;
     _runtimeInfo            = runtimeInfo;
     _logger = logger;
 }
 public PlexPathReplacementService(
     IMediaSourceRepository mediaSourceRepository,
     IRuntimeInfo runtimeInfo,
     ILogger <PlexPathReplacementService> logger)
 {
     _mediaSourceRepository = mediaSourceRepository;
     _runtimeInfo           = runtimeInfo;
     _logger = logger;
 }
Пример #24
0
 public SystemModule(IAppFolderInfo appFolderInfo, IRuntimeInfo runtimeInfo, IRouteCacheProvider routeCacheProvider, IConfigFileProvider configFileProvider)
     : base("system")
 {
     _appFolderInfo = appFolderInfo;
     _runtimeInfo = runtimeInfo;
     _routeCacheProvider = routeCacheProvider;
     _configFileProvider = configFileProvider;
     Get["/status"] = x => GetStatus();
     Get["/routes"] = x => GetRoutes();
 }
Пример #25
0
 public Router(INzbDroneServiceFactory nzbDroneServiceFactory, IServiceProvider serviceProvider, IStartupArguments startupArguments,
                 IConsoleService consoleService, IRuntimeInfo runtimeInfo, Logger logger)
 {
     _nzbDroneServiceFactory = nzbDroneServiceFactory;
     _serviceProvider = serviceProvider;
     _startupArguments = startupArguments;
     _consoleService = consoleService;
     _runtimeInfo = runtimeInfo;
     _logger = logger;
 }
Пример #26
0
 public LifecycleService(IEventAggregator eventAggregator,
                         IRuntimeInfo runtimeInfo,
                         IServiceProvider serviceProvider,
                         Logger logger)
 {
     _eventAggregator = eventAggregator;
     _runtimeInfo     = runtimeInfo;
     _serviceProvider = serviceProvider;
     _logger          = logger;
 }
Пример #27
0
 public RemoteAccessAdapter(IRuntimeInfo runtimeInfo,
                            IUrlAclAdapter urlAclAdapter,
                            IFirewallAdapter firewallAdapter,
                            ISslAdapter sslAdapter)
 {
     _runtimeInfo     = runtimeInfo;
     _urlAclAdapter   = urlAclAdapter;
     _firewallAdapter = firewallAdapter;
     _sslAdapter      = sslAdapter;
 }
Пример #28
0
 public SystemModule(IAppFolderInfo appFolderInfo, IRuntimeInfo runtimeInfo, IRouteCacheProvider routeCacheProvider, IConfigFileProvider configFileProvider)
     : base("system")
 {
     _appFolderInfo      = appFolderInfo;
     _runtimeInfo        = runtimeInfo;
     _routeCacheProvider = routeCacheProvider;
     _configFileProvider = configFileProvider;
     Get["/status"]      = x => GetStatus();
     Get["/routes"]      = x => GetRoutes();
 }
Пример #29
0
 public NzbDroneServiceFactory(IConfigFileProvider configFileProvider, IHostController hostController, IRuntimeInfo runtimeInfo,
                    IProcessProvider processProvider, PriorityMonitor priorityMonitor, IStartupArguments startupArguments, Logger logger)
 {
     _configFileProvider = configFileProvider;
     _hostController = hostController;
     _runtimeInfo = runtimeInfo;
     _processProvider = processProvider;
     _priorityMonitor = priorityMonitor;
     _startupArguments = startupArguments;
     _logger = logger;
 }
Пример #30
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);
 }
Пример #31
0
 public NzbDroneServiceFactory(IConfigFileProvider configFileProvider, IHostController hostController, IRuntimeInfo runtimeInfo,
                               IProcessProvider processProvider, PriorityMonitor priorityMonitor, IStartupArguments startupArguments, Logger logger)
 {
     _configFileProvider = configFileProvider;
     _hostController     = hostController;
     _runtimeInfo        = runtimeInfo;
     _processProvider    = processProvider;
     _priorityMonitor    = priorityMonitor;
     _startupArguments   = startupArguments;
     _logger             = logger;
 }
Пример #32
0
        public UrlAclAdapter(INetshProvider netshProvider,
                             IConfigFileProvider configFileProvider,
                             IRuntimeInfo runtimeInfo,
                             Logger logger)
        {
            _netshProvider = netshProvider;
            _configFileProvider = configFileProvider;
            _runtimeInfo = runtimeInfo;
            _logger = logger;

            Urls = new List<String>();
        }
Пример #33
0
 public DeploymentConfig(
     string schemaVersion,
     IRuntimeInfo runtime,
     SystemModules systemModules,
     IDictionary <string, IModule> modules)
 {
     this.SchemaVersion = Preconditions.CheckNotNull(schemaVersion, nameof(schemaVersion));
     this.SystemModules = Preconditions.CheckNotNull(systemModules, nameof(this.SystemModules));
     this.Runtime       = Preconditions.CheckNotNull(runtime, nameof(runtime));
     this.Modules       = modules?.ToImmutableDictionary() ?? ImmutableDictionary <string, IModule> .Empty;
     this.UpdateModuleNames();
 }
Пример #34
0
        public async Task <Plan> PlanAsync(
            ModuleSet desired,
            ModuleSet current,
            IRuntimeInfo runtimeInfo,
            IImmutableDictionary <string, IModuleIdentity> moduleIdentities)
        {
            Events.LogDesired(desired);
            Events.LogCurrent(current);
            Events.LogIdentities(moduleIdentities);

            // Check that module names sanitize and remain unique.
            var groupedModules = desired.Modules.GroupBy(pair => KubeUtils.SanitizeK8sValue(pair.Key)).ToArray();

            if (groupedModules.Any(c => c.Count() > 1))
            {
                string nameList = groupedModules.Where(c => c.Count() > 1).SelectMany(g => g, (pairs, pair) => pair.Key).Join(",");
                throw new InvalidIdentityException($"Deployment will cause a name collision in Kubernetes namespace, modules: [{nameList}]");
            }

            // TODO: improve this so it is generic for all potential module types.
            if (!desired.Modules.Values.All(p => p is IModule <DockerConfig>))
            {
                throw new InvalidModuleException($"Kubernetes deployment currently only handles type={typeof(T).FullName}");
            }

            Diff moduleDifference = desired.Diff(current);

            Plan plan;

            if (!moduleDifference.IsEmpty)
            {
                // The "Plan" here is very simple - if we have any change, publish all desired modules to a CRD.
                // The CRD allows us to give the customer a Kubernetes-centric way to see the deployment
                // and the status of that deployment through the "edgedeployments" API.
                var k8sModules = desired.Modules.Select(m => new KubernetesModule <DockerConfig>(m.Value as IModule <DockerConfig>));

                var crdCommand  = new KubernetesCrdCommand <CombinedDockerConfig>(this.deviceNamespace, this.iotHubHostname, this.deviceId, this.client, k8sModules.ToArray(), Option.Some(runtimeInfo), this.combinedConfigProvider as ICombinedConfigProvider <CombinedDockerConfig>);
                var planCommand = await this.commandFactory.WrapAsync(crdCommand);

                var planList = new List <ICommand>
                {
                    planCommand
                };
                Events.PlanCreated(planList);
                plan = new Plan(planList);
            }
            else
            {
                plan = Plan.Empty;
            }

            return(plan);
        }
Пример #35
0
 public WebHostController(IRuntimeInfo runtimeInfo,
                          IConfigFileProvider configFileProvider,
                          IFirewallAdapter firewallAdapter,
                          IEnumerable <IAspNetCoreMiddleware> middlewares,
                          Logger logger)
 {
     _runtimeInfo        = runtimeInfo;
     _configFileProvider = configFileProvider;
     _firewallAdapter    = firewallAdapter;
     _middlewares        = middlewares;
     _logger             = logger;
 }
        public override CombinedDockerConfig GetCombinedConfig(IModule module, IRuntimeInfo runtimeInfo)
        {
            CombinedDockerConfig combinedConfig = base.GetCombinedConfig(module, runtimeInfo);

            // if the workload URI is a Unix domain socket then volume mount it into the container
            CreateContainerParameters createOptions = CloneOrCreateParams(combinedConfig.CreateOptions);

            this.MountSockets(module, createOptions);
            this.InjectNetworkAliases(module, createOptions);

            return(new CombinedDockerConfig(combinedConfig.Image, createOptions, combinedConfig.NotaryContentTrust, combinedConfig.AuthConfig));
        }
Пример #37
0
        public UrlAclAdapter(INetshProvider netshProvider,
                             IConfigFileProvider configFileProvider,
                             IRuntimeInfo runtimeInfo,
                             Logger logger)
        {
            _netshProvider = netshProvider;
            _configFileProvider = configFileProvider;
            _runtimeInfo = runtimeInfo;
            _logger = logger;

            InternalUrls = new List<UrlAcl>();
            RegisteredUrls = GetRegisteredUrls();
        }
Пример #38
0
 public OwinHostController(
                           IOwinAppFactory owinAppFactory,
                           IRuntimeInfo runtimeInfo,
                           IUrlAclAdapter urlAclAdapter,
                           IFirewallAdapter firewallAdapter,
                           ISslAdapter sslAdapter,
                           Logger logger)
 {
     _owinAppFactory = owinAppFactory;
     _runtimeInfo = runtimeInfo;
     _urlAclAdapter = urlAclAdapter;
     _firewallAdapter = firewallAdapter;
     _sslAdapter = sslAdapter;
     _logger = logger;
 }
Пример #39
0
 public OwinHostController(IConfigFileProvider configFileProvider,
                           IEnumerable<IOwinMiddleWare> owinMiddleWares,
                           IRuntimeInfo runtimeInfo,
                           IUrlAclAdapter urlAclAdapter,
                           IFirewallAdapter firewallAdapter,
                           ISslAdapter sslAdapter,
                           Logger logger)
 {
     _configFileProvider = configFileProvider;
     _owinMiddleWares = owinMiddleWares;
     _runtimeInfo = runtimeInfo;
     _urlAclAdapter = urlAclAdapter;
     _firewallAdapter = firewallAdapter;
     _sslAdapter = sslAdapter;
     _logger = logger;
 }
Пример #40
0
 public SystemModule(IAppFolderInfo appFolderInfo,
                     IRuntimeInfo runtimeInfo,
                     IRouteCacheProvider routeCacheProvider,
                     IConfigFileProvider configFileProvider,
                     IMainDatabase database,
                     ILifecycleService lifecycleService)
     : base("system")
 {
     _appFolderInfo = appFolderInfo;
     _runtimeInfo = runtimeInfo;
     _routeCacheProvider = routeCacheProvider;
     _configFileProvider = configFileProvider;
     _database = database;
     _lifecycleService = lifecycleService;
     Get["/status"] = x => GetStatus();
     Get["/routes"] = x => GetRoutes();
     Post["/shutdown"] = x => Shutdown();
     Post["/restart"] = x => Restart();
 }
Пример #41
0
 public SystemTrayApp(IBrowserService browserService, IRuntimeInfo runtimeInfo, IProcessProvider processProvider)
 {
     _browserService = browserService;
     _runtimeInfo = runtimeInfo;
     _processProvider = processProvider;
 }
Пример #42
0
 public MappedNetworkDriveValidator(IRuntimeInfo runtimeInfo, IDiskProvider diskProvider)
     : base("Mapped Network Drive and Windows Service")
 {
     _runtimeInfo = runtimeInfo;
     _diskProvider = diskProvider;
 }
Пример #43
0
 public MonoVersionCheck(IRuntimeInfo runtimeInfo, Logger logger)
 {
     _runtimeInfo = runtimeInfo;
     _logger = logger;
 }
Пример #44
0
 public SpinService(IRuntimeInfo runtimeInfo, IProcessProvider processProvider, Logger logger)
 {
     _runtimeInfo = runtimeInfo;
     _processProvider = processProvider;
     _logger = logger;
 }