ISerde <DeploymentConfigInfo> GetSerde() { var moduleDeserializerTypes = new Dictionary <string, Type> { [TestType] = typeof(TestModule) }; var edgeAgentDeserializerTypes = new Dictionary <string, Type> { [TestType] = typeof(TestAgentModule) }; var edgeHubDeserializerTypes = new Dictionary <string, Type> { [TestType] = typeof(TestHubModule) }; var runtimeInfoDeserializerTypes = new Dictionary <string, Type> { [TestType] = typeof(TestRuntimeInfo) }; var deserializerTypesMap = new Dictionary <Type, IDictionary <string, Type> > { [typeof(IModule)] = moduleDeserializerTypes, [typeof(IEdgeAgentModule)] = edgeAgentDeserializerTypes, [typeof(IEdgeHubModule)] = edgeHubDeserializerTypes, [typeof(IRuntimeInfo)] = runtimeInfoDeserializerTypes, }; ISerde <DeploymentConfigInfo> serde = new TypeSpecificSerDe <DeploymentConfigInfo>(deserializerTypesMap); return(serde); }
public CrdWatchOperator( string iotHubHostname, string deviceId, string edgeHostname, string proxyImage, string proxyConfigPath, string proxyConfigVolumeName, string serviceAccountName, string k8sNamespace, string workloadApiVersion, Uri workloadUri, Uri managementUri, PortMapServiceType defaultMapServiceType, IKubernetes client, IModuleIdentityLifecycleManager moduleIdentityLifecycleManager) { this.iotHubHostname = Preconditions.CheckNonWhiteSpace(iotHubHostname, nameof(iotHubHostname)); this.deviceId = Preconditions.CheckNonWhiteSpace(deviceId, nameof(deviceId)); this.edgeHostname = Preconditions.CheckNonWhiteSpace(edgeHostname, nameof(edgeHostname)); this.proxyImage = Preconditions.CheckNonWhiteSpace(proxyImage, nameof(proxyImage)); this.proxyConfigPath = Preconditions.CheckNonWhiteSpace(proxyConfigPath, nameof(proxyConfigPath)); this.proxyConfigVolumeName = Preconditions.CheckNonWhiteSpace(proxyConfigVolumeName, nameof(proxyConfigVolumeName)); this.serviceAccountName = Preconditions.CheckNonWhiteSpace(serviceAccountName, nameof(serviceAccountName)); this.k8sNamespace = Preconditions.CheckNonWhiteSpace(k8sNamespace, nameof(k8sNamespace)); this.workloadApiVersion = Preconditions.CheckNonWhiteSpace(workloadApiVersion, nameof(workloadApiVersion)); this.workloadUri = Preconditions.CheckNotNull(workloadUri, nameof(workloadUri)); this.managementUri = Preconditions.CheckNotNull(managementUri, nameof(managementUri)); this.defaultMapServiceType = Preconditions.CheckNotNull(defaultMapServiceType, nameof(defaultMapServiceType)).ToString(); this.client = Preconditions.CheckNotNull(client, nameof(client)); this.podWatch = Option.None <Watcher <V1Pod> >(); this.resourceName = KubeUtils.SanitizeK8sValue(this.iotHubHostname) + Constants.K8sNameDivider + KubeUtils.SanitizeK8sValue(this.deviceId); this.deploymentSelector = Constants.K8sEdgeDeviceLabel + " = " + KubeUtils.SanitizeK8sValue(this.deviceId) + "," + Constants.K8sEdgeHubNameLabel + "=" + KubeUtils.SanitizeK8sValue(this.iotHubHostname); var deserializerTypesMap = new Dictionary <Type, IDictionary <string, Type> > { [typeof(IModule)] = new Dictionary <string, Type> { ["docker"] = typeof(CombinedDockerModule) } }; this.deploymentSerde = new TypeSpecificSerDe <EdgeDeploymentDefinition <TConfig> >(deserializerTypesMap, new CamelCasePropertyNamesContractResolver()); this.moduleIdentityLifecycleManager = moduleIdentityLifecycleManager; }
public KubernetesCrdCommand(string deviceNamespace, string iotHubHostname, string deviceId, IKubernetes client, KubernetesModule <DockerConfig>[] modules, Option <IRuntimeInfo> runtimeInfo, ICombinedConfigProvider <T> combinedConfigProvider) { this.deviceNamespace = KubeUtils.SanitizeK8sValue(Preconditions.CheckNonWhiteSpace(deviceNamespace, nameof(deviceNamespace))); this.iotHubHostname = KubeUtils.SanitizeK8sValue(Preconditions.CheckNonWhiteSpace(iotHubHostname, nameof(iotHubHostname))); this.deviceId = KubeUtils.SanitizeK8sValue(Preconditions.CheckNonWhiteSpace(deviceId, nameof(deviceId))); this.client = Preconditions.CheckNotNull(client, nameof(client)); this.modules = Preconditions.CheckNotNull(modules, nameof(modules)); this.runtimeInfo = Preconditions.CheckNotNull(runtimeInfo, nameof(runtimeInfo)); this.combinedConfigProvider = Preconditions.CheckNotNull(combinedConfigProvider, nameof(combinedConfigProvider)); this.id = new Lazy <string>(() => this.modules.Aggregate(string.Empty, (prev, module) => module.Name + prev)); var deserializerTypesMap = new Dictionary <Type, IDictionary <string, Type> > { [typeof(IModule)] = new Dictionary <string, Type> { ["docker"] = typeof(CombinedDockerConfig) } }; this.deploymentSerde = new TypeSpecificSerDe <EdgeDeploymentDefinition <DockerConfig> >(deserializerTypesMap); }
public CrdWatcher( string iotHubHostname, string deviceId, string edgeHostname, string proxyImage, string proxyConfigPath, string proxyConfigVolumeName, string serviceAccountName, string resourceName, string deploymentSelector, string defaultMapServiceType, string k8sNamespace, string workloadApiVersion, Uri workloadUri, Uri managementUri, TypeSpecificSerDe <EdgeDeploymentDefinition <TConfig> > deploymentSerde, IModuleIdentityLifecycleManager moduleIdentityLifecycleManager, IKubernetes client) { this.iotHubHostname = iotHubHostname; this.deviceId = deviceId; this.edgeHostname = edgeHostname; this.proxyImage = proxyImage; this.proxyConfigPath = proxyConfigPath; this.proxyConfigVolumeName = proxyConfigVolumeName; this.serviceAccountName = serviceAccountName; this.resourceName = resourceName; this.deploymentSelector = deploymentSelector; this.defaultMapServiceType = defaultMapServiceType; this.k8sNamespace = k8sNamespace; this.workloadApiVersion = workloadApiVersion; this.workloadUri = workloadUri; this.managementUri = managementUri; this.deploymentSerde = deploymentSerde; this.moduleIdentityLifecycleManager = moduleIdentityLifecycleManager; this.client = client; }
protected override void Load(ContainerBuilder builder) { // ISerde<ModuleSet> builder.Register( c => new ModuleSetSerde( new Dictionary <string, Type> { { DockerType, typeof(DockerModule) } })) .As <ISerde <ModuleSet> >() .SingleInstance(); // ISerde<DeploymentConfig> builder.Register( c => { ISerde <DeploymentConfig> serde = new TypeSpecificSerDe <DeploymentConfig>(DeploymentConfigTypeMapping); return(serde); }) .As <ISerde <DeploymentConfig> >() .SingleInstance(); // ISerde<DeploymentConfigInfo> builder.Register( c => { ISerde <DeploymentConfigInfo> serde = new TypeSpecificSerDe <DeploymentConfigInfo>(DeploymentConfigTypeMapping); return(serde); }) .As <ISerde <DeploymentConfigInfo> >() .SingleInstance(); // Detect system environment builder.Register(c => new SystemEnvironment()) .As <ISystemEnvironment>() .SingleInstance(); // IRocksDbOptionsProvider // For EdgeAgent, we don't need high performance from RocksDb, so always turn off optimizeForPerformance builder.Register(c => new RocksDbOptionsProvider(c.Resolve <ISystemEnvironment>(), false)) .As <IRocksDbOptionsProvider>() .SingleInstance(); if (!this.usePersistentStorage && this.useBackupAndRestore) { // Backup and restore serialization builder.Register(c => new ProtoBufDataBackupRestore()) .As <IDataBackupRestore>() .SingleInstance(); } // IDbStoreProvider builder.Register( async c => { var loggerFactory = c.Resolve <ILoggerFactory>(); ILogger logger = loggerFactory.CreateLogger(typeof(AgentModule)); if (this.usePersistentStorage) { // Create partition for mma var partitionsList = new List <string> { "moduleState", "deploymentConfig" }; try { IDbStoreProvider dbStoreprovider = DbStoreProvider.Create( c.Resolve <IRocksDbOptionsProvider>(), this.storagePath, partitionsList); logger.LogInformation($"Created persistent store at {this.storagePath}"); return(dbStoreprovider); } catch (Exception ex) when(!ExceptionEx.IsFatal(ex)) { logger.LogError(ex, "Error creating RocksDB store. Falling back to in-memory store."); IDbStoreProvider dbStoreProvider = await this.BuildInMemoryDbStoreProvider(c); return(dbStoreProvider); } } else { logger.LogInformation($"Using in-memory store"); IDbStoreProvider dbStoreProvider = await this.BuildInMemoryDbStoreProvider(c); return(dbStoreProvider); } }) .As <Task <IDbStoreProvider> >() .SingleInstance(); // Task<IStoreProvider> builder.Register(async c => { var dbStoreProvider = await c.Resolve <Task <IDbStoreProvider> >(); IStoreProvider storeProvider = new StoreProvider(dbStoreProvider); return(storeProvider); }) .As <Task <IStoreProvider> >() .SingleInstance(); // IEntityStore<string, ModuleState> builder.Register(async c => { IStoreProvider storeProvider = await c.Resolve <Task <IStoreProvider> >(); return(storeProvider.GetEntityStore <string, ModuleState>("moduleState")); }) .As <Task <IEntityStore <string, ModuleState> > >() .SingleInstance(); // IEntityStore<string, DeploymentConfigInfo> builder.Register(async c => { IStoreProvider storeProvider = await c.Resolve <Task <IStoreProvider> >(); return(storeProvider.GetEntityStore <string, string>("deploymentConfig")); }) .As <Task <IEntityStore <string, string> > >() .SingleInstance(); // IRestartManager builder.Register(c => new RestartPolicyManager(this.maxRestartCount, this.coolOffTimeUnitInSeconds)) .As <IRestartPolicyManager>() .SingleInstance(); // IPlanner builder.Register( async c => new HealthRestartPlanner( await c.Resolve <Task <ICommandFactory> >(), await c.Resolve <Task <IEntityStore <string, ModuleState> > >(), this.intensiveCareTime, c.Resolve <IRestartPolicyManager>()) as IPlanner) .As <Task <IPlanner> >() .SingleInstance(); // IPlanRunner builder.Register(c => new OrderedRetryPlanRunner(this.maxRestartCount, this.coolOffTimeUnitInSeconds, SystemTime.Instance)) .As <IPlanRunner>() .SingleInstance(); // IEncryptionDecryptionProvider builder.Register( async c => { IEncryptionProvider provider = await this.workloadUri.Map( async uri => { IEncryptionProvider encryptionProvider = await EncryptionProvider.CreateAsync( this.storagePath, uri, this.workloadApiVersion.Expect(() => new InvalidOperationException("Missing workload API version")), Constants.EdgeletClientApiVersion, this.moduleId, this.moduleGenerationId.Expect(() => new InvalidOperationException("Missing generation ID")), Constants.EdgeletInitializationVectorFileName); return(encryptionProvider); }).GetOrElse(() => Task.FromResult <IEncryptionProvider>(NullEncryptionProvider.Instance)); return(provider); }) .As <Task <IEncryptionProvider> >() .SingleInstance(); // IAvailabilityMetric builder.Register(c => new AvailabilityMetrics(c.Resolve <IMetricsProvider>(), this.storagePath)) .As <IAvailabilityMetric>() .SingleInstance(); // Task<Agent> builder.Register( async c => { var configSource = c.Resolve <Task <IConfigSource> >(); var environmentProvider = c.Resolve <Task <IEnvironmentProvider> >(); var planner = c.Resolve <Task <IPlanner> >(); var planRunner = c.Resolve <IPlanRunner>(); var reporter = c.Resolve <IReporter>(); var moduleIdentityLifecycleManager = c.Resolve <IModuleIdentityLifecycleManager>(); var deploymentConfigInfoSerde = c.Resolve <ISerde <DeploymentConfigInfo> >(); var deploymentConfigInfoStore = await c.Resolve <Task <IEntityStore <string, string> > >(); var encryptionProvider = c.Resolve <Task <IEncryptionProvider> >(); var availabilityMetric = c.Resolve <IAvailabilityMetric>(); return(await Agent.Create( await configSource, await planner, planRunner, reporter, moduleIdentityLifecycleManager, await environmentProvider, deploymentConfigInfoStore, deploymentConfigInfoSerde, await encryptionProvider, availabilityMetric)); }) .As <Task <Agent> >() .SingleInstance(); base.Load(builder); }