Beispiel #1
0
        public static string GetStreamAnalyticsTemplateParameterJson(StreamAnalyticsDeploymentRequest depReq)
        {
            // generates parameter json string from the request object
            TemplateStreamAnalyticsParameterRequest template = new TemplateStreamAnalyticsParameterRequest()
            {
                Parameters = new ParameterStreamAnalyticsModel()
                {
                    IotHubName = new ParameterStreamAnalyticsValue()
                    {
                        Value = depReq.IoTHubName
                    },
                    CosmosDbAccountName = new ParameterStreamAnalyticsValue()
                    {
                        Value = depReq.CosmosDBAccountName
                    },
                    CosmosDbName = new ParameterStreamAnalyticsValue()
                    {
                        Value = depReq.CosmosDBName
                    },
                    CosmosDBMessageCollectionName = new ParameterStreamAnalyticsValue()
                    {
                        Value = depReq.CosmosDBMessageCollectionName
                    },
                }
            };

            return(JsonConvert.SerializeObject(template));
        }
    public async Task validate_streamAnalytics_azureRM_template_Exception()
    {
        var repo          = CreateRepository();
        var subscriptions = await repo.GetSubscriptions();

        Assert.NotNull(subscriptions);

        await Assert.ThrowsAsync <CloudException>(async() => await repo.CreateResoureGroup(subscriptions[0]
                                                                                           .SubscriptionId,
                                                                                           "e4455astus",
                                                                                           "msiotunittest"));

        var deployReq = new StreamAnalyticsDeploymentRequest
        {
            IoTHubName                    = "iothubtestms4x4",
            CosmosDBAccountName           = "cosmostestms4x4",
            CosmosDBName                  = "cosmostestdb",
            CosmosDBMessageCollectionName = "testcollection",
            SubscriptionId                = subscriptions[0]
                                            .SubscriptionId,
            ResourceGroupName = "msiotunittest",
            Location          = "eastus"
        };

        var deployment = await repo.Validate4x4StreamAnalyticsUsingAzureRMTemplate(deployReq);

        Assert.Null(deployment.Error);
        Assert.Equal("Succeeded", deployment.Properties.ProvisioningState);
    }
        public async Task Deploy4x4IoTStreamAnalytics([FromBody] StreamAnalyticsDeploymentModel depMod)
        {
            try
            {
                logger.LogInformation("Deploying Stream Analytics : {iothub}", depMod.IoTHubName);
                StreamAnalyticsDeploymentRequest deployReq = new StreamAnalyticsDeploymentRequest()
                {
                    IoTHubName                    = depMod.IoTHubName,
                    CosmosDBAccountName           = depMod.CosmosDBAccountName,
                    CosmosDBName                  = depMod.CosmosDBName,
                    CosmosDBMessageCollectionName = depMod.CosmosDBMessageCollectionName,
                    SubscriptionId                = depMod.SubscriptionId,
                    ResourceGroupName             = depMod.ResourceGroupName,
                    Location = depMod.Location
                };

                var deployment = await _resourceManagerRepo.Deploy4x4StreamAnalyticsUsingAzureRMTemplate(deployReq);
            }
            catch (Exception e)
            {
                logger.LogError(e, "Deploy application - Exception {message}", e.Message);
            }
        }
Beispiel #4
0
        public async Task <DeploymentValidateResult> Validate4x4StreamAnalyticsUsingAzureRMTemplate(StreamAnalyticsDeploymentRequest depReq, string token)
        {
            try
            {
                var credential = new TokenCredentials(token);
                var resourceManagementClient = new ResourceManagementClient(credential)
                {
                    SubscriptionId = depReq.SubscriptionId
                };

                // generates a parameter json required for ARM template deployment
                var parameterTemplateJson = GetStreamAnalyticsTemplateParameterJson(depReq);

                var deployment = new Deployment();
                deployment.Properties = new DeploymentProperties
                {
                    Mode         = DeploymentMode.Incremental,
                    TemplateLink = new TemplateLink(_armTemplateStreamAnalyticsUrl),
                    Parameters   = parameterTemplateJson
                };

                // This is for unit testing and validating the ARM template to be deployed
                return(await resourceManagementClient.Deployments.ValidateAsync(depReq.ResourceGroupName,
                                                                                depReq.ResourceGroupName, deployment));
            }
            catch (Exception e)
            {
                Log.Error("Validate Stream Analytics error {@error}", e.Message);
                throw e;
            }
        }
        public async Task <DeploymentValidateResult> Validate4x4StreamAnalyticsUsingAzureRMTemplate(StreamAnalyticsDeploymentRequest depReq)
        {
            try
            {
                var resourceManagementClient = await clientFactory.GetResourceMangementClientAsync(depReq.SubscriptionId);

                // generates a parameter json required for ARM template deployment
                var parameterTemplateJson = GetStreamAnalyticsTemplateParameterJson(depReq);

                var deployment = new Deployment();
                deployment.Properties = new DeploymentProperties
                {
                    Mode         = DeploymentMode.Incremental,
                    TemplateLink = new TemplateLink(armOptions.TemplateStreamAnalyticsUrl),
                    Parameters   = parameterTemplateJson
                };

                // This is for unit testing and validating the ARM template to be deployed
                return(await resourceManagementClient.Deployments.ValidateAsync(depReq.ResourceGroupName,
                                                                                depReq.ResourceGroupName, deployment));
            }
            catch (Exception e)
            {
                logger.LogError(e, "Validate Stream Analytics error {error}", e.Message);
                throw;
            }
        }