public async Task GetWebServiceDefinition()
        {
            // This test will extract all the webservice definitions from AML priceplan
            // Only run when you need it

            var dataStore = await TestManager.GetDataStore();

            var azureToken    = dataStore.GetJson("AzureToken")["access_token"].ToString();
            var subscription  = "c6a33fd3-e442-48a4-b82d-bcc4ad8a71d7";
            var resourceGroup = "Api-Default-West-US";//dataStore.GetValue("SelectedResourceGroup");

            ServiceClientCredentials               creds            = new TokenCredentials(azureToken);
            AzureMLWebServicesManagementClient     client           = new AzureMLWebServicesManagementClient(creds);
            AzureMLCommitmentPlansManagementClient commitmentClient = new AzureMLCommitmentPlansManagementClient(creds);

            client.SubscriptionId           = subscription;
            commitmentClient.SubscriptionId = subscription;
            var webservices = await client.WebServices.ListByResourceGroupAsync(resourceGroup);

            foreach (var webserviceName in webservices)
            {
                var webservice = await client.WebServices.GetAsync(resourceGroup, webserviceName.Name);

                var str = ModelsSerializationUtil.GetAzureMLWebServiceDefinitionJsonFromObject(webservice);
                System.IO.File.WriteAllText(webserviceName.Name.Replace(".", "").Replace(":", "") + "FFTWebService.json", str);
            }
        }
Beispiel #2
0
        protected override void RunCmdlet()
        {
            string serializedDefinition =
                ModelsSerializationUtil.GetAzureMLWebServiceDefinitionJsonFromObject(this.WebService);

            if (!string.IsNullOrWhiteSpace(this.OutputFile))
            {
                var currentPath            = this.SessionState.Path.CurrentFileSystemLocation.Path;
                var definitionFileFullPath =
                    Path.IsPathRooted(this.OutputFile) ?
                    this.OutputFile :
                    Path.Combine(currentPath, this.OutputFile);

                bool fileExisting = File.Exists(definitionFileFullPath);
                this.ConfirmAction(
                    this.Force || !fileExisting,
                    "Want to overwriting the output file?",
                    "Overwriting the output file",
                    definitionFileFullPath,
                    () => File.WriteAllText(definitionFileFullPath, serializedDefinition));
            }
            else
            {
                this.WriteObject(serializedDefinition);
            }
        }
        public async Task GetWebServiceDefinition()
        {
            // This test will extract all the webservice definitions from AML priceplan
            // Only run when you need it

            var dataStore = await TestHarness.GetCommonDataStoreWithUserToken();

            var azureToken    = dataStore.GetJson("AzureToken")["access_token"].ToString();
            var subscription  = dataStore.GetJson("SelectedSubscription")["SubscriptionId"].ToString();
            var resourceGroup = "twitterAML";//dataStore.GetValue("SelectedResourceGroup");

            ServiceClientCredentials               creds            = new TokenCredentials(azureToken);
            AzureMLWebServicesManagementClient     client           = new AzureMLWebServicesManagementClient(creds);
            AzureMLCommitmentPlansManagementClient commitmentClient = new AzureMLCommitmentPlansManagementClient(creds);

            client.SubscriptionId           = subscription;
            commitmentClient.SubscriptionId = subscription;
            var webservices = await client.WebServices.ListAsync();

            foreach (var webserviceName in webservices)
            {
                var webservice = await client.WebServices.GetAsync(resourceGroup, webserviceName.Name);

                var str = ModelsSerializationUtil.GetAzureMLWebServiceDefinitionJsonFromObject(webservice);
                System.IO.File.WriteAllText(webserviceName.Name.Replace(".", "").Replace(":", "") + "WebServiceNew.json", str);
            }
        }
        protected override void RunCmdlet()
        {
            this.ConfirmAction(
                this.Force.IsPresent,
                Resources.NewServiceWarning.FormatInvariant(this.Name),
                "Creating the new web service",
                this.Name,
                () => {
                if (string.Equals(
                        this.ParameterSetName,
                        NewAzureMLWebService.CreateFromFileParameterSet,
                        StringComparison.OrdinalIgnoreCase))
                {
                    string jsonDefinition =
                        CmdletHelpers.GetWebServiceDefinitionFromFile(
                            this.SessionState.Path.CurrentFileSystemLocation.Path,
                            this.DefinitionFile);
                    this.NewWebServiceDefinition =
                        ModelsSerializationUtil.GetAzureMLWebServiceFromJsonDefinition(jsonDefinition);
                }

                WebService newWebService =
                    this.WebServicesClient.CreateAzureMlWebService(
                        this.ResourceGroupName,
                        this.Location,
                        this.Name,
                        this.NewWebServiceDefinition);
                this.WriteObject(newWebService);
            });
        }
Beispiel #5
0
        private static WebService GetServiceDefinitionFromTestData(string testDataFile, string commitmentPlanId, StorageAccount storageAccount)
        {
            string serviceAsJson     = File.ReadAllText(testDataFile);
            var    serviceDefinition = ModelsSerializationUtil.GetAzureMLWebServiceFromJsonDefinition(serviceAsJson);

            serviceDefinition.Location = WebServiceTests.DefaultLocation;
            serviceDefinition.Properties.CommitmentPlan.Id = commitmentPlanId;
            serviceDefinition.Properties.StorageAccount    = storageAccount;
            return(serviceDefinition);
        }
        protected override void RunCmdlet()
        {
            string jsonDefinition = this.JsonString;

            if (string.Equals(
                    this.ParameterSetName,
                    ImportWebServiceDefinition.ImportFromFileParamSet,
                    StringComparison.OrdinalIgnoreCase))
            {
                jsonDefinition = CmdletHelpers.GetWebServiceDefinitionFromFile(
                    this.SessionState.Path.CurrentFileSystemLocation.Path,
                    this.InputFile);
            }

            WebService serviceDefinition = ModelsSerializationUtil.GetAzureMLWebServiceFromJsonDefinition(jsonDefinition);

            this.WriteObject(serviceDefinition);
        }
Beispiel #7
0
        public override void ExecuteCmdlet()
        {
            string serializedDefinition =
                ModelsSerializationUtil.GetAzureMLWebServiceDefinitionJsonFromObject(this.WebService);

            if (!string.IsNullOrWhiteSpace(this.OutputFile))
            {
                bool fileExisting = File.Exists(this.OutputFile);
                this.ConfirmAction(
                    this.Force || !fileExisting,
                    "Want to overwriting the output file?",
                    "Overwriting the output file",
                    this.OutputFile,
                    () => File.WriteAllText(this.OutputFile, serializedDefinition));
            }
            else
            {
                this.WriteObject(serializedDefinition);
            }
        }
Beispiel #8
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 webserviceFile     = request.DataStore.GetValue("WebServiceFile");
            string webserviceName     = request.DataStore.GetValue("WebServiceName");
            string commitmentPlanName = request.DataStore.GetValue("CommitmentPlan");
            string resourceGroup      = request.DataStore.GetValue("SelectedResourceGroup");
            string storageAccountName = request.DataStore.GetValue("StorageAccountName");
            string storageAccountKey  = request.DataStore.GetValue("StorageAccountKey");

            string responseType      = request.DataStore.GetValue("IsRequestResponse");
            bool   isRequestResponse = false;

            if (responseType != null)
            {
                isRequestResponse = bool.Parse(responseType);
            }

            ServiceClientCredentials               creds            = new TokenCredentials(azureToken);
            AzureMLWebServicesManagementClient     client           = new AzureMLWebServicesManagementClient(creds);
            AzureMLCommitmentPlansManagementClient commitmentClient = new AzureMLCommitmentPlansManagementClient(creds);

            client.SubscriptionId           = subscription;
            commitmentClient.SubscriptionId = subscription;

            // Create commitment plan
            var commitmentPlan = new Azure.Management.MachineLearning.CommitmentPlans.Models.CommitmentPlan();

            commitmentPlan.Sku = new ResourceSku()
            {
                Capacity = 1,
                Name     = "S1",
                Tier     = "Standard"
            };

            commitmentPlan.Location = "South Central US";
            var createdCommitmentPlan = await commitmentClient.CommitmentPlans.CreateOrUpdateAsync(commitmentPlan, resourceGroup, commitmentPlanName);

            request.Logger.LogResource(request.DataStore, createdCommitmentPlan.Name,
                                       DeployedResourceType.MlWebServicePlan, CreatedBy.BPST, DateTime.UtcNow.ToString("o"), createdCommitmentPlan.Id, commitmentPlan.Sku.Tier);

            // Get webservicedefinition
            string         sqlConnectionString = request.DataStore.GetValueAtIndex("SqlConnectionString", "SqlServerIndex");
            SqlCredentials sqlCredentials;

            string jsonDefinition = File.ReadAllText(request.Info.App.AppFilePath + "/" + webserviceFile);

            if (!string.IsNullOrWhiteSpace(sqlConnectionString))
            {
                sqlCredentials = SqlUtility.GetSqlCredentialsFromConnectionString(sqlConnectionString);
                jsonDefinition = ReplaceSqlPasswords(sqlCredentials, jsonDefinition);
            }

            // Create WebService - fixed to southcentralus
            WebService webService = ModelsSerializationUtil.GetAzureMLWebServiceFromJsonDefinition(jsonDefinition);

            webService.Properties.StorageAccount = new StorageAccount
            {
                Key  = storageAccountKey,
                Name = storageAccountName
            };

            webService.Properties.CommitmentPlan = new CommitmentPlan(createdCommitmentPlan.Id);
            // A little bit of juggling to change the name
            webService = new WebService(webService.Location, webService.Properties, null, webserviceName, webService.Type, webService.Tags);

            WebService result = null;

            try
            {
                result = client.WebServices.CreateOrUpdate(resourceGroup, webserviceName, webService);


                var    keys            = client.WebServices.ListKeys(resourceGroup, webserviceName);
                var    swaggerLocation = result.Properties.SwaggerLocation;
                string url             = swaggerLocation.Replace("swagger.json", "jobs?api-version=2.0");

                if (isRequestResponse)
                {
                    url = swaggerLocation.Replace("swagger.json", "execute?api-version=2.0&format=swagger");
                }

                string serviceKey = keys.Primary;

                request.DataStore.AddToDataStore("AzureMLUrl", url);
                request.DataStore.AddToDataStore("AzureMLKey", serviceKey);
            }
            catch (CloudException e)
            {
                return(new ActionResponse(ActionStatus.Failure, JsonUtility.GetJObjectFromStringValue(e.Message), e, "DefaultError", ((CloudException)e).Response.Content));
            }
            request.Logger.LogResource(request.DataStore, result.Name,
                                       DeployedResourceType.MlWebService, CreatedBy.BPST, DateTime.UtcNow.ToString("o"), result.Id);

            return(new ActionResponse(ActionStatus.Success));
        }
Beispiel #9
0
        public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request)
        {
            var azureToken   = request.DataStore.GetJson("AzureToken")["access_token"].ToString();
            var subscription = request.DataStore.GetJson("SelectedSubscription")["SubscriptionId"].ToString();

            var webserviceFile     = request.DataStore.GetValue("WebServiceFile");
            var webserviceName     = request.DataStore.GetValue("WebServiceName");
            var commitmentPlanName = request.DataStore.GetValue("CommitmentPlan");
            var resourceGroup      = request.DataStore.GetValue("SelectedResourceGroup");
            var storageAccountName = request.DataStore.GetValue("StorageAccountName");

            string         sqlConnectionString = request.DataStore.GetValueAtIndex("SqlConnectionString", "SqlServerIndex");
            SqlCredentials sqlCredentials      = SqlUtility.GetSqlCredentialsFromConnectionString(sqlConnectionString);

            ServiceClientCredentials               creds            = new TokenCredentials(azureToken);
            AzureMLWebServicesManagementClient     client           = new AzureMLWebServicesManagementClient(creds);
            AzureMLCommitmentPlansManagementClient commitmentClient = new AzureMLCommitmentPlansManagementClient(creds);

            client.SubscriptionId           = subscription;
            commitmentClient.SubscriptionId = subscription;

            // Create commitment plan
            var commitmentPlan = new Azure.Management.MachineLearning.CommitmentPlans.Models.CommitmentPlan();

            commitmentPlan.Sku = new ResourceSku()
            {
                Capacity = 1,
                Name     = "S1",
                Tier     = "Standard"
            };

            commitmentPlan.Location = "South Central US";
            var createdsCommitmentPlan = await commitmentClient.CommitmentPlans.CreateOrUpdateAsync(commitmentPlan, resourceGroup, commitmentPlanName);

            // Get key from storage account
            var response = await RequestUtility.CallAction(request, "Microsoft-GetStorageAccountKey");

            var    responseObject = JsonUtility.GetJObjectFromObject(response.Body);
            string key            = responseObject["StorageAccountKey"].ToString();

            // Get webservicedefinition
            string jsonDefinition = File.ReadAllText(request.Info.App.AppFilePath + "/" + webserviceFile);
            string jsonFinal      = ReplaceSqlPasswords(sqlCredentials, jsonDefinition);

            // Create WebService - fixed to southcentralus
            WebService webService = ModelsSerializationUtil.GetAzureMLWebServiceFromJsonDefinition(jsonFinal);

            webService.Properties.StorageAccount = new StorageAccount
            {
                Key  = key,
                Name = storageAccountName
            };

            webService.Properties.CommitmentPlan = new CommitmentPlan(createdsCommitmentPlan.Id);
            webService.Name = webserviceName;

            var result = await client.WebServices.CreateOrUpdateAsync(resourceGroup, webserviceName, webService);

            var keys = await client.WebServices.ListKeysAsync(resourceGroup, webserviceName);

            var swaggerLocation = result.Properties.SwaggerLocation;

            string url        = swaggerLocation.Replace("swagger.json", "jobs?api-version=2.0");
            string serviceKey = keys.Primary;

            request.DataStore.AddToDataStore("AzureMLUrl", url);
            request.DataStore.AddToDataStore("AzureMLKey", serviceKey);

            return(new ActionResponse(ActionStatus.Success));
        }