Esempio n. 1
0
        public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request)
        {
            string azureToken    = request.DataStore.GetJson("AzureToken", "access_token");
            string subscription  = request.DataStore.GetJson("SelectedSubscription", "SubscriptionId");
            string resourceGroup = request.DataStore.GetValue("SelectedResourceGroup");

            string serverName = request.DataStore.GetValue("ASServerName") ?? "analysisserver-" + RandomGenerator.GetRandomLowerCaseCharacters(5);
            string location   = request.DataStore.GetValue("ASLocation") ?? "westus";
            string sku        = request.DataStore.GetValue("ASSku") ?? "D1";
            string admin      = AzureUtility.GetEmailFromToken(request.DataStore.GetJson("AzureToken"));

            SubscriptionCloudCredentials creds = new TokenCloudCredentials(subscription, azureToken);
            AzureArmParameterGenerator   param = new AzureArmParameterGenerator();

            param.AddStringParam("name", serverName);
            param.AddStringParam("location", location);
            param.AddStringParam("sku", sku);
            param.AddStringParam("admin", admin);

            string armTemplatefilePath = File.ReadAllText(request.ControllerModel.SiteCommonFilePath + "/service/arm/NewAzureAS.json");
            string template            = AzureUtility.GetAzureArmParameters(armTemplatefilePath, param);
            await AzureUtility.ValidateAndDeployArm(creds, resourceGroup, "ASDeployment", template);

            await AzureUtility.WaitForArmDeployment(creds, resourceGroup, "ASDeployment");

            AzureHttpClient client   = new AzureHttpClient(azureToken, subscription, resourceGroup);
            var             response = await client.ExecuteWithSubscriptionAndResourceGroupAsync(HttpMethod.Get
                                                                                                 , $"/providers/Microsoft.AnalysisServices/servers/{serverName}/"
                                                                                                 , "2016-05-16"
                                                                                                 , string.Empty
                                                                                                 , new Dictionary <string, string>());

            string responseBody = await response.Content.ReadAsStringAsync();

            if (!response.IsSuccessStatusCode)
            {
                return(new ActionResponse(ActionStatus.Failure));
            }

            JObject responseObj = JsonUtility.GetJObjectFromJsonString(responseBody);

            request.DataStore.AddToDataStore("ASServerUrl", responseObj["properties"]["serverFullName"], DataStoreType.Public);

            request.Logger.LogResource(request.DataStore, responseObj["properties"]["serverFullName"].ToString(),
                                       DeployedResourceType.AzureAnalysisServices, CreatedBy.BPST, DateTime.UtcNow.ToString("o"), string.Empty, sku);

            return(new ActionResponse(ActionStatus.Success, responseObj));
        }
Esempio n. 2
0
        public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request)
        {
            var azureToken     = request.DataStore.GetJson("AzureToken", "access_token");
            var subscription   = request.DataStore.GetJson("SelectedSubscription", "SubscriptionId");
            var resourceGroup  = request.DataStore.GetValue("SelectedResourceGroup");
            var deploymentName = request.DataStore.GetValue("DeploymentName") ?? "AzureMLDeployment";

            var workspaceName      = request.DataStore.GetValue("WorkspaceName");
            var storageAccountName = request.DataStore.GetValue("StorageAccountName");
            var planName           = request.DataStore.GetValue("PlanName") ?? "azuremlplan";
            var skuName            = request.DataStore.GetValue("SkuName") ?? "S1";
            var skuTier            = request.DataStore.GetValue("SkuTier") ?? "Standard";
            var skuCapacity        = request.DataStore.GetValue("SkuCapacity") ?? "1";

            // Get email address

            var param = new AzureArmParameterGenerator();

            param.AddStringParam("name", workspaceName);
            param.AddStringParam("resourcegroup", resourceGroup);
            param.AddStringParam("subscription", subscription);
            param.AddStringParam("newStorageAccountName", storageAccountName);
            param.AddStringParam("planName", planName);
            param.AddStringParam("skuName", skuName);
            param.AddStringParam("skuTier", skuTier);
            param.AddStringParam("skuCapacity", skuCapacity);
            param.AddStringParam("ownerEmail", AzureUtility.GetEmailFromToken(request.DataStore.GetJson("AzureToken")));

            SubscriptionCloudCredentials creds = new TokenCloudCredentials(subscription, azureToken);

            Microsoft.Azure.Management.Resources.ResourceManagementClient client = new ResourceManagementClient(creds);

            var armTemplate      = JsonUtility.GetJObjectFromJsonString(System.IO.File.ReadAllText(Path.Combine(request.ControllerModel.SiteCommonFilePath, "Service/Arm/azureml.json")));
            var armParamTemplate = JsonUtility.GetJObjectFromObject(param.GetDynamicObject());

            armTemplate.Remove("parameters");
            armTemplate.Add("parameters", armParamTemplate["parameters"]);


            var deployment = new Microsoft.Azure.Management.Resources.Models.Deployment()
            {
                Properties = new DeploymentPropertiesExtended()
                {
                    Template   = armTemplate.ToString(),
                    Parameters = JsonUtility.GetEmptyJObject().ToString()
                }
            };

            var validate = client.Deployments.ValidateAsync(resourceGroup, deploymentName, deployment, new CancellationToken()).Result;

            if (!validate.IsValid)
            {
                return(new ActionResponse(ActionStatus.Failure, JsonUtility.GetJObjectFromObject(validate), null,
                                          DefaultErrorCodes.DefaultErrorCode, $"Azure:{validate.Error.Message} Details:{validate.Error.Details}"));
            }

            var deploymentItem = client.Deployments.CreateOrUpdateAsync(resourceGroup, deploymentName, deployment, new CancellationToken()).Result;

            var status = await AzureUtility.WaitForArmDeployment(creds, resourceGroup, deploymentName);

            return(status);
        }