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); }); }
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); }
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)); }
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)); }