コード例 #1
0
        private JTokenWrapper GetEdgeHubDesiredProperties(JTokenWrapper deploymentJsonObject)
        {
            JTokenWrapper jtokenWrapper = new JTokenWrapper();

            jtokenWrapper.Value = deploymentJsonObject.Value[Constants.EdgeHub][Constants.DesiredProperties];
            return(jtokenWrapper);
        }
コード例 #2
0
        private void UpdateSystemModuleCreateOptions(JTokenWrapper createOptionsToken, EdgeConfiguration edgeConfiguration, EdgeGatewayConfiguration edgeGatewayConfiguration)
        {
            string[] communicationPort = edgeConfiguration.UpstreamCommunication.Split('/');
            IDictionary <string, Dictionary <string, string>[]> edgeHubPortBindingsConfig = new Dictionary <string, Dictionary <string, string>[]>();

            Dictionary <string, string>[] matrix = new Dictionary <string, string> [1];
            matrix[0] = new Dictionary <string, string>();
            matrix[0].Add(Constants.HostPort, communicationPort[0]);
            edgeHubPortBindingsConfig.Add(edgeConfiguration.UpstreamCommunication, matrix);

            var createOption = new
            {
                HostConfig = new
                {
                    PortBindings = JObject.FromObject(edgeHubPortBindingsConfig),
                    LogConfig    = new
                    {
                        Type   = "json-file",
                        Config = JObject.FromObject(GetModuleLogConfigurationType(edgeConfiguration.AdvanceConfiguration))
                    }
                }
            };

            createOptionsToken.Value.Replace(JObject.FromObject(createOption).ToString());
        }
コード例 #3
0
        private JTokenWrapper GetEdgeHubDesiredPropertiesMessageTTL(JTokenWrapper deploymentJsonObject)
        {
            JTokenWrapper jtokenWrapper           = new JTokenWrapper();
            var           edgeHubDesiredPropeties = GetEdgeHubDesiredProperties(deploymentJsonObject).Value;

            jtokenWrapper.Value = edgeHubDesiredPropeties[Constants.StoreForwardConfiguration][Constants.TimeToLiveSecs];
            return(jtokenWrapper);
        }
コード例 #4
0
        private JTokenWrapper GetEdgeAgentDesiredPropertiesRegistryCredentials(JTokenWrapper deploymentJsonObject)
        {
            JTokenWrapper jtokenWrapper             = new JTokenWrapper();
            var           edgeAgentDesiredPropeties = GetEdgeAgentDesiredProperties(deploymentJsonObject).Value;

            jtokenWrapper.Value = edgeAgentDesiredPropeties[Constants.Runtime][Constants.Settings][Constants.RegistryCredentials];
            return(jtokenWrapper);
        }
コード例 #5
0
        private JTokenWrapper GetEdgeAgentDesiredPropertiesEdgeHubModule(JTokenWrapper deploymentJsonObject)
        {
            JTokenWrapper jtokenWrapper             = new JTokenWrapper();
            var           edgeAgentDesiredPropeties = GetEdgeAgentDesiredPropertiesSystemModules(deploymentJsonObject).Value;

            jtokenWrapper.Value = edgeAgentDesiredPropeties[Constants.SystemModulesEdgeHub];
            return(jtokenWrapper);
        }
コード例 #6
0
        private JTokenWrapper GetEdgeAgentDesiredPropertiesEdgeAgentCreateOption(JTokenWrapper deploymentJsonObject)
        {
            JTokenWrapper jtokenWrapper             = new JTokenWrapper();
            var           edgeAgentDesiredPropeties = GetEdgeAgentDesiredProperties(deploymentJsonObject).Value;

            jtokenWrapper.Value = edgeAgentDesiredPropeties[Constants.SystemModules][Constants.SystemModulesEdgeAgent][Constants.Settings][Constants.CreateOptions];
            return(jtokenWrapper);
        }
コード例 #7
0
        private JTokenWrapper GetEdgeHubDesiredPropertiesRoutes(JTokenWrapper deploymentJsonObject)
        {
            JTokenWrapper jtokenWrapper           = new JTokenWrapper();
            var           edgeHubDesiredPropertie = GetEdgeHubDesiredProperties(deploymentJsonObject).Value;

            jtokenWrapper.Value = edgeHubDesiredPropertie[Constants.Routes];
            return(jtokenWrapper);
        }
コード例 #8
0
        public async Task <IToken> ParseAsync(Stream contentStream)
        {
            using (var textReader = new StreamReader(contentStream))
                using (var jsonReader = new JsonTextReader(textReader))
                {
                    var jObject = await JObject.LoadAsync(jsonReader);

                    return(JTokenWrapper.Wrap(jObject));
                }
        }
コード例 #9
0
        private void UpdateEdgeAgent(JTokenWrapper deploymentJsonObject, EdgeConfiguration edgeConfiguration, EdgeGatewayConfiguration edgeGatewayConfiguration)
        {
            var createOptionsToken = GetEdgeAgentDesiredPropertiesEdgeAgentCreateOption(deploymentJsonObject);

            UpdateSystemModuleCreateOptions(createOptionsToken, edgeConfiguration, edgeGatewayConfiguration);

            var edgeAgent = GetEdgeAgentDesiredPropertiesEdgeAgentModule(deploymentJsonObject);

            SetHttpProxyWithUpstreamProtocolDetails(edgeAgent, edgeGatewayConfiguration);
        }
コード例 #10
0
        public async Task <EdgeAgentDeploymentPayload> PrepareDeploymentTemplateForInternalAgentIdAsync(string plantId, string internalAgentId)
        {
            using (ILoggerTransaction logger = _loggerTransaction.LogTransaction(GetType().Name))
            {
                try
                {
                    EdgeAgentDeploymentPayload agentPayload = new EdgeAgentDeploymentPayload();
                    JTokenWrapper deploymentJsonObject      = new JTokenWrapper();
                    var           deploymentTemplate        = await _edgeAgentDeploymentRepository.GetDeploymentTemplateAsync();

                    deploymentJsonObject.Value = JObject.Parse(deploymentTemplate.DeploymentTemplate);

                    var edgeAgent = await _edgeAgentRepository.GetEdgeAgentByIdAsync(plantId, internalAgentId);

                    var edgeConfiguration = await _edgeConfigurationRepository.GetEdgeConfigurationByInternalAgentIdAsync(plantId, internalAgentId);

                    var edgeGatewayConfiguration = await _edgeGatewayConfigurationRepository.GetEdgeGatewayConfigurationByInternalAgentIdAsync(plantId, internalAgentId);

                    var modulesOfAgent = await _edgeMessagePipelineRepository.GetEdgeModuleConfigurationsByAgentIdAsync(plantId, internalAgentId);

                    var defaultModulesOfAgent = await GetDefaultModulesOfAgentAsync(plantId, internalAgentId);

                    var finalModulesOfAgent = GetFinalModulesOfAgent(defaultModulesOfAgent, modulesOfAgent);

                    var routesForTemplate = await GetRoutesForTemplateAsync(plantId, internalAgentId, defaultModulesOfAgent, finalModulesOfAgent);

                    var modulesForTemplate = GetModulesForTemplate(defaultModulesOfAgent, modulesOfAgent, edgeConfiguration);

                    JObject modules = JObject.FromObject(modulesForTemplate);
                    var     edgeAgentDesiredPropertiesModules = GetEdgeAgentDesiredPropertiesModules(deploymentJsonObject).Value;
                    edgeAgentDesiredPropertiesModules.Replace(modules);

                    JObject routes = JObject.FromObject(routesForTemplate);
                    var     edgeHubDesiresPropertiesRoutes = GetEdgeHubDesiredPropertiesRoutes(deploymentJsonObject).Value;
                    edgeHubDesiresPropertiesRoutes.Replace(routes);

                    SetModuleDesiredProperties(finalModulesOfAgent, deploymentJsonObject, edgeAgent, edgeConfiguration);
                    UpdateEdgeHub(deploymentJsonObject, edgeConfiguration, edgeGatewayConfiguration);
                    UpdateEdgeAgent(deploymentJsonObject, edgeConfiguration, edgeGatewayConfiguration);
                    SetRegistryCredentials(deploymentJsonObject);
                    agentPayload.DeploymentTemplate      = deploymentJsonObject.Value;
                    agentPayload.AgentConfigurationName  = string.Format(AgentonfigurationNameTemplate, edgeAgent.AgentName, DateTime.UtcNow.ToString());
                    agentPayload.DeploymentConfiguration = await PrepareDeploymentConfigurationForInternalAgentIdAsync(plantId, internalAgentId);

                    return(agentPayload);
                }
                catch (Exception ex)
                {
                    logger.LogException(ex);
                    throw;
                }
            }
        }
コード例 #11
0
        private void UpdateEdgeHub(JTokenWrapper deploymentJsonObject, EdgeConfiguration edgeConfiguration, EdgeGatewayConfiguration edgeGatewayConfiguration)
        {
            var createOptionsToken = GetEdgeAgentDesiredPropertiesEdgeHubCreateOption(deploymentJsonObject);

            UpdateSystemModuleCreateOptions(createOptionsToken, edgeConfiguration, edgeGatewayConfiguration);

            var messageTTLToken = GetEdgeHubDesiredPropertiesMessageTTL(deploymentJsonObject).Value;

            messageTTLToken.Replace(Convert.ToInt32(edgeConfiguration.MessageTTL));
            var edgeHub = GetEdgeAgentDesiredPropertiesEdgeHubModule(deploymentJsonObject);

            SetHttpProxyWithUpstreamProtocolDetails(edgeHub, edgeGatewayConfiguration);
        }
コード例 #12
0
        private void SetRegistryCredentials(JTokenWrapper deploymentJsonObject)
        {
            IDictionary <string, Dictionary <string, string> > registryCredentials = new Dictionary <string, Dictionary <string, string> >();
            Dictionary <string, string> userDetails = new Dictionary <string, string>();

            userDetails.Add(_configuration.AcrUserNameTemplate, _configuration.AcrUserName);
            userDetails.Add(_configuration.AcrUserPasswordTemplate, _configuration.AcrPassword);
            userDetails.Add(Constants.UserAddress, _configuration.AcrRepositoryEndpoint);
            registryCredentials.Add(_configuration.AcrUserName, userDetails);
            var registryCredentialsToken = GetEdgeAgentDesiredPropertiesRegistryCredentials(deploymentJsonObject).Value;

            registryCredentialsToken.Replace(JObject.FromObject(registryCredentials));
        }
コード例 #13
0
 private void SetHttpProxyWithUpstreamProtocolDetails(JTokenWrapper module, EdgeGatewayConfiguration edgeGatewayConfiguration)
 {
     if (edgeGatewayConfiguration.ProxyUser != null && edgeGatewayConfiguration.ProxyHost != null && edgeGatewayConfiguration.ProxyPassword != null)
     {
         IDictionary <string, ModuleEnvironmentValue> envData = new Dictionary <string, ModuleEnvironmentValue>();
         var hostProxyDetails = string.Format(Constants.ProxyTemplate, edgeGatewayConfiguration.ProxyUser, edgeGatewayConfiguration.ProxyPassword, edgeGatewayConfiguration.ProxyHost);
         envData.Add(Constants.HttpsProxy, new ModuleEnvironmentValue {
             Value = hostProxyDetails
         });
         envData.Add(Constants.UpstreamProtocl, new ModuleEnvironmentValue {
             Value = Constants.UpstreamProtocolValue
         });
         module.Value[Constants.ModuleEnv] = JObject.FromObject(envData);
     }
 }
コード例 #14
0
        private JTokenWrapper GetCreateOptions()
        {
            JTokenWrapper jtokenWrapper = new JTokenWrapper();
            var           createOptions = new
            {
                HostConfig = new
                {
                    LogConfig = new
                    {
                        Type   = "json-file",
                        Config = new JObject()
                    }
                }
            };

            jtokenWrapper.Value = JObject.FromObject(createOptions);
            return(jtokenWrapper);
        }
コード例 #15
0
        public IToken Parse(string contentString)
        {
            var jObject = JObject.Parse(contentString);

            return(JTokenWrapper.Wrap(jObject));
        }
コード例 #16
0
        private void SetModuleDesiredProperties(IEnumerable <EdgeMessagePipelineModule> moduleList, JTokenWrapper deploymentJsonObject, EdgeAgentDto edgeAgent, EdgeConfiguration edgeConfiguration)
        {
            foreach (var edgeModule in moduleList)
            {
                var moduleDesiredProperty = new JObject();
                switch (edgeModule.ModuleImageName)
                {
                case DefaultUpstreamModule:
                {
                    var desiredProperties = new
                    {
                        configuration = new
                        { }
                    };

                    moduleDesiredProperty[Constants.DesiredProperties]       = JObject.FromObject(desiredProperties);
                    deploymentJsonObject.Value[edgeModule.ConfigurationName] = moduleDesiredProperty;
                    break;
                }

                default:
                {
                    var desiredProperties = new
                    {
                        configuration = new
                        {
                            timeStamp = DateTime.UtcNow.ToString("o"),
                            blobSas   = string.IsNullOrEmpty(edgeModule.ModuleConfigurationBlobFileURI) ? string.Empty : edgeModule.ModuleConfigurationBlobFileURI
                        }
                    };

                    moduleDesiredProperty[Constants.DesiredProperties]       = JObject.FromObject(desiredProperties);
                    deploymentJsonObject.Value[edgeModule.ConfigurationName] = moduleDesiredProperty;
                    break;
                }
                }
            }
        }