public void AddWebServiceEndpoint(WorkspaceSetting setting, AddWebServiceEndpointRequest req) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string queryUrl = WebServiceApi + string.Format("workspaces/{0}/webservices/{1}/endpoints/{2}", setting.WorkspaceId, req.WebServiceId, req.EndpointName); string body = jss.Serialize(req); HttpResult hr = Util.HttpPut(queryUrl, body).Result; if (!hr.IsSuccess) { throw new AmlRestApiException(hr); } }
public async Task <string> UploadResourceAsnyc(WorkspaceSetting setting, string fileFormat, string fileName) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string query = StudioApi + string.Format("resourceuploads/workspaces/{0}/?userStorage=true&dataTypeId={1}", setting.WorkspaceId, fileFormat); HttpResult hr = await Util.HttpPostFile(query, fileName); if (!hr.IsSuccess) { throw new AmlRestApiException(hr); } return(hr.Payload); }
public string ExportAmlWebServiceDefinitionFromExperiment(WorkspaceSetting setting, string experimentId) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string queryUrl = StudioApi + string.Format("workspaces/{0}/experiments/{1}/webservicedefinition", setting.WorkspaceId, experimentId); HttpResult hr = Util.HttpGet(queryUrl).Result; if (hr.IsSuccess) { return(hr.Payload); } throw new AmlRestApiException(hr); }
private void SubmitExperiment(WorkspaceSetting setting, Experiment exp, string rawJson, string newName, bool createNewCopy, bool run) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string body = CreateSubmitExperimentRequest(exp, rawJson, run, newName, createNewCopy); string queryUrl = StudioApi + string.Format("workspaces/{0}/experiments/{1}", setting.WorkspaceId, createNewCopy ? string.Empty : exp.ExperimentId); HttpResult hr = Util.HttpPost(queryUrl, body).Result; if (!hr.IsSuccess) { throw new AmlRestApiException(hr); } }
public string UploadResource(WorkspaceSetting setting, string fileFormat) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string query = StudioApi + string.Format("resourceuploads/workspaces/{0}/?userStorage=true&dataTypeId={1}", setting.WorkspaceId, fileFormat); HttpResult hr = Util.HttpPost(query, string.Empty).Result; if (!hr.IsSuccess) { throw new AmlRestApiException(hr); } return(hr.Payload); }
public void PatchWebServiceEndpoint(WorkspaceSetting setting, string webServiceId, string endpointName, dynamic patchReq) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string body = jss.Serialize(patchReq); string url = WebServiceApi + string.Format("workspaces/{0}/webservices/{1}/endpoints/{2}", setting.WorkspaceId, webServiceId, endpointName); HttpResult hr = Util.HttpPatch(url, body).Result; if (!hr.IsSuccess) { throw new AmlRestApiException(hr); } }
public Module[] GetModules(WorkspaceSetting setting) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string query = StudioApi + string.Format("workspaces/{0}/modules", setting.WorkspaceId); HttpResult hr = Util.HttpGet(query).Result; if (!hr.IsSuccess) { throw new AmlRestApiException(hr); } Module[] modules = jss.Deserialize <Module[]>(hr.Payload); return(modules); }
public UserAsset[] GetTransforms(WorkspaceSetting setting) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string queryUrl = StudioApi + string.Format("workspaces/{0}/transformmodules", setting.WorkspaceId); HttpResult hr = Util.HttpGet(queryUrl).Result; if (hr.IsSuccess) { UserAsset[] tms = jss.Deserialize <UserAsset[]>(hr.Payload); return(tms); } throw new AmlRestApiException(hr); }
public async Task <string> UploadResourceInChunksAsnyc(WorkspaceSetting setting, int numOfBlocks, int blockId, string uploadId, string fileName, string fileFormat) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string query = StudioApi + string.Format("blobuploads/workspaces/{0}/?numberOfBlocks={1}&blockId={2}&uploadId={3}&dataTypeId={4}", setting.WorkspaceId, numOfBlocks, blockId, uploadId, fileFormat); HttpResult hr = await Util.HttpPostFile(query, fileName); if (!hr.IsSuccess) { throw new AmlRestApiException(hr); } return(hr.Payload); }
public string GetCustomModuleBuildJobStatus(WorkspaceSetting setting, string activityGroupId) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string query = StudioApi + string.Format("workspaces/{0}/modules/custom?activityGroupId={1}", setting.WorkspaceId, activityGroupId); HttpResult hr = Util.HttpGet(query).Result; if (!hr.IsSuccess) { throw new AmlRestApiException(hr); } string jobStatus = hr.Payload; return(jobStatus); }
public PackingServiceActivity UnpackExperiment(WorkspaceSetting setting, string packedLocation, string sourceRegion) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string queryUrl = StudioApi + string.Format("workspaces/{0}/packages?api-version=2.0&packageUri={1}{2}", setting.WorkspaceId, HttpUtility.UrlEncode(packedLocation), "®ion=" + sourceRegion.Replace(" ", string.Empty)); //Console.WriteLine("Unpacking: PUT " + queryUrl); HttpResult hr = Util.HttpPut(queryUrl, string.Empty).Result; if (hr.IsSuccess) { PackingServiceActivity activity = jss.Deserialize <PackingServiceActivity>(hr.Payload); return(activity); } throw new AmlRestApiException(hr); }
// Note this API is NOT officially supported. It might break in the future and we won't support it if/when it happens. public PackingServiceActivity UnpackExperimentFromGallery(WorkspaceSetting setting, string packageUri, string galleryUrl, string entityId) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string queryUrl = StudioApi + string.Format("workspaces/{0}/packages?api-version=2.0&packageUri={1}&communityUri={2}&entityId={3}", setting.WorkspaceId, HttpUtility.UrlEncode(packageUri), HttpUtility.UrlEncode(galleryUrl), entityId); //Console.WriteLine("Upacking from Gallery: PUT " + queryUrl); HttpResult hr = Util.HttpPut(setting.AuthorizationToken, queryUrl, string.Empty).Result; if (hr.IsSuccess) { PackingServiceActivity activity = jss.Deserialize <PackingServiceActivity>(hr.Payload); return(activity); } throw new AmlRestApiException(hr); }
public PackingServiceActivity PackExperiment(WorkspaceSetting setting, string experimentId) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string queryUrl = StudioApi + string.Format("workspaces/{0}/packages?api-version=2.0&experimentid={1}/&clearCredentials=true&includeAuthorId=false", setting.WorkspaceId, experimentId); //Console.WriteLine("Packing: POST " + queryUrl); HttpResult hr = Util.HttpPost(queryUrl, string.Empty).Result; if (hr.IsSuccess) { PackingServiceActivity activity = jss.Deserialize <PackingServiceActivity>(hr.Payload); return(activity); } throw new AmlRestApiException(hr); }
public string BeginParseCustomModuleJob(WorkspaceSetting setting, string moduleUploadMetadata) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string query = StudioApi + string.Format("workspaces/{0}/modules/custom", setting.WorkspaceId); HttpResult hr = Util.HttpPost(query, moduleUploadMetadata).Result; if (!hr.IsSuccess) { throw new AmlRestApiException(hr); } string activityId = hr.Payload.Replace("\"", ""); return(activityId); }
public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request) { var azureToken = request.DataStore.GetJson("AzureToken", "access_token"); var subscription = request.DataStore.GetJson("SelectedSubscription", "SubscriptionId"); var workspaceName = request.DataStore.GetValue("WorkspaceName"); var experimentJsonPath = request.DataStore.GetValue("ExperimentJsonPath"); var experimentName = request.DataStore.GetValue("ExperimentName"); string json = System.IO.File.ReadAllText(Path.Combine(request.Info.App.AppFilePath, experimentJsonPath)); ManagementSDK azuremlClient = new ManagementSDK(); var workspaces = azuremlClient.GetWorkspacesFromRdfe(azureToken, subscription); var workspace = workspaces.SingleOrDefault(p => p.Name.ToLowerInvariant() == workspaceName.ToLowerInvariant()); if (workspace == null) { return(new ActionResponse(ActionStatus.Failure, null, null, string.Empty, "Workspace not found")); } var workspaceSettings = new WorkspaceSetting() { AuthorizationToken = workspace.AuthorizationToken.PrimaryToken, Location = workspace.Region, WorkspaceId = workspace.Id }; var experiments = azuremlClient.GetExperiments(workspaceSettings); var experiment = experiments.LastOrDefault(p => p.Description.ToLowerInvariant() == experimentName.ToLowerInvariant()); if (experiment != null) { azuremlClient.SaveExperiment(workspaceSettings, experiment, json); } else { experiment = new Experiment() { ExperimentId = Guid.NewGuid().ToString(), Description = experimentName, Summary = "Solution Template", Creator = "Solution Template" }; } azuremlClient.SaveExperimentAs(workspaceSettings, experiment, json, experimentName); return(new ActionResponse(ActionStatus.Success)); }
public async Task DownloadDatasetAsync(WorkspaceSetting setting, string datasetId, string filename) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string url = StudioApi + string.Format("workspaces/{0}/datasources/{1}", setting.WorkspaceId, datasetId); HttpResult hr = Util.HttpGet(url).Result; if (!hr.IsSuccess) { throw new AmlRestApiException(hr); } Dataset ds = jss.Deserialize <Dataset>(hr.Payload); string downloadUrl = ds.DownloadLocation.BaseUri + ds.DownloadLocation.Location + ds.DownloadLocation.AccessCredential; await DownloadFileAsync(downloadUrl, filename); }
private void ValidateWorkspaceSetting(WorkspaceSetting setting) { if (setting.Location == null || setting.Location == string.Empty) { throw new ArgumentException("No Location specified."); } if (setting.WorkspaceId == null || setting.WorkspaceId == string.Empty) { throw new ArgumentException("No Workspace Id specified."); } if (setting.AuthorizationToken == null || setting.AuthorizationToken == string.Empty) { throw new ArgumentException("No Authorization Token specified."); } SetApiUrl(setting.Location); }
public string GetDatasetSchemaGenStatus(WorkspaceSetting setting, string dataSourceId) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string query = StudioApi + string.Format("workspaces/{0}/datasources/{1}", setting.WorkspaceId, dataSourceId); HttpResult hr = Util.HttpGet(query).Result; if (!hr.IsSuccess) { throw new AmlRestApiException(hr); } dynamic parsed = jss.Deserialize <object>(hr.Payload); string schemaJobStatus = parsed["SchemaStatus"]; return(schemaJobStatus); }
public WebService GetWebServicesById(WorkspaceSetting setting, string webServiceId) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string queryUrl = WebServiceApi + string.Format("workspaces/{0}/webservices/{1}", setting.WorkspaceId, webServiceId); HttpResult hr = Util.HttpGet(queryUrl).Result; if (hr.IsSuccess) { WebService ws = jss.Deserialize <WebService>(hr.Payload); return(ws); } else { throw new AmlRestApiException(hr); } }
public Workspace GetWorkspaceFromAmlRP(WorkspaceSetting setting) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string queryUrl = StudioApi + string.Format("workspaces/{0}", setting.WorkspaceId); HttpResult hr = Util.HttpGet(queryUrl).Result; if (hr.IsSuccess) { Workspace ws = jss.Deserialize <Workspace>(hr.Payload); return(ws); } else { throw new AmlRestApiException(hr); } }
public WebServiceCreationStatus GetWebServiceCreationStatus(WorkspaceSetting setting, string activityId) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string queryUrl = StudioApi + string.Format("workspaces/{0}/experiments/{1}/webservice", setting.WorkspaceId, activityId); HttpResult hr = Util.HttpGet(queryUrl).Result; if (hr.IsSuccess) { WebServiceCreationStatus status = jss.Deserialize <WebServiceCreationStatus>(hr.Payload); return(status); } else { throw new AmlRestApiException(hr); } }
public WebServiceEndPoint GetWebServiceEndpointByName(WorkspaceSetting setting, string webServiceId, string epName) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string queryUrl = WebServiceApi + string.Format("workspaces/{0}/webservices/{1}/endpoints/{2}", setting.WorkspaceId, webServiceId, epName); HttpResult hr = Util.HttpGet(queryUrl).Result; if (hr.IsSuccess) { WebServiceEndPoint ep = jss.Deserialize <WebServiceEndPoint>(hr.Payload); return(ep); } else { throw new AmlRestApiException(hr); } }
public WebServiceCreationStatus DeployWebServiceFromPredictiveExperiment(WorkspaceSetting setting, string predictiveExperimentId, bool updateExistingWebServiceDefaultEndpoint) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string queryUrl = StudioApi + string.Format("workspaces/{0}/experiments/{1}/webservice?generateNewPortNames=false{2}", setting.WorkspaceId, predictiveExperimentId, updateExistingWebServiceDefaultEndpoint ? "&updateExistingWebService=true" : ""); HttpResult hr = Util.HttpPost(queryUrl, string.Empty).Result; if (hr.IsSuccess) { WebServiceCreationStatus status = jss.Deserialize <WebServiceCreationStatus>(hr.Payload); return(status); } else { throw new AmlRestApiException(hr); } }
public bool RefreshWebServiceEndPoint(WorkspaceSetting setting, string webServiceId, string endpointName, bool overwriteResources) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string query = WebServiceApi + string.Format("workspaces/{0}/webservices/{1}/endpoints/{2}/refresh", setting.WorkspaceId, webServiceId, endpointName); string body = "{\"OverwriteResources\": \"" + overwriteResources.ToString() + "\"}"; HttpResult hr = Util.HttpPost(query, body).Result; if (hr.StatusCode == 304) // no change detected so no update happened. { return(false); } if (!hr.IsSuccess) { throw new AmlRestApiException(hr); } return(true); }
public PackingServiceActivity GetActivityStatus(WorkspaceSetting setting, string activityId, bool isPacking) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string queryUrl = StudioApi + string.Format("workspaces/{0}/packages?{1}ActivityId={2}", setting.WorkspaceId, (isPacking ? "package" : "unpack"), activityId); //Console.WriteLine("Getting activity: GET " + queryUrl); HttpResult hr = Util.HttpGet(queryUrl, true).Result; if (hr.IsSuccess) { PackingServiceActivity activity = jss.Deserialize <PackingServiceActivity>(hr.Payload); return(activity); } else { throw new AmlRestApiException(hr); } }
public void AddWorkspaceUsers(WorkspaceSetting setting, string emails, string role) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string queryUrl = StudioApi + string.Format("workspaces/{0}/invitations", setting.WorkspaceId); string body = "{Role: \"" + role + "\", Emails:\"" + emails + "\"}"; HttpResult hr = Util.HttpPost(queryUrl, body).Result; if (hr.IsSuccess) { string p = hr.Payload; return; } else { throw new AmlRestApiException(hr); } }
public async Task GetExperimentsTest() { var dataStore = await TestHarness.GetCommonDataStoreWithUserToken(); ManagementSDK sdk = new ManagementSDK(); var workspaces = sdk.GetWorkspacesFromRdfe(dataStore.GetJson("AzureToken")["access_token"].ToString(), dataStore.GetJson("SelectedSubscription")["SubscriptionId"].ToString()); var workspaceSettings = new WorkspaceSetting() { AuthorizationToken = workspaces[0].AuthorizationToken.PrimaryToken, Location = workspaces[0].Region, WorkspaceId = workspaces[0].Id }; var experiments = sdk.GetExperiments(workspaceSettings); string rawJson = string.Empty; Experiment exp = sdk.GetExperimentById(workspaceSettings, experiments[0].ExperimentId, out rawJson); }
private void ReadConfigFromFile(bool throwExceptionIfFileDoesnotExist) { string currentPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); _configFilePath = Path.Combine(currentPath, _configFilePath); if (throwExceptionIfFileDoesnotExist && (!File.Exists(_configFilePath))) { throw new Exception("Can't find config file: " + _configFilePath); } if (File.Exists(_configFilePath)) { string configString = File.ReadAllText(_configFilePath); JavaScriptSerializer jss = new JavaScriptSerializer(); WorkspaceSetting config = jss.Deserialize <WorkspaceSetting>(configString); Location = config.Location; WorkspaceId = config.WorkspaceId; AuthorizationToken = config.AuthorizationToken; } }
public Experiment[] GetExperiments(WorkspaceSetting setting) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; string queryUrl = StudioApi + string.Format("workspaces/{0}/experiments", setting.WorkspaceId); HttpResult hr = Util.HttpGet(queryUrl).Result; if (hr.IsSuccess) { Experiment[] exps = jss.Deserialize <Experiment[]>(hr.Payload); // only display user's own experiments. exps = exps.Where(e => e.Category == "user" || string.IsNullOrEmpty(e.Category)).ToArray(); return(exps); } else { throw new AmlRestApiException(hr); } }
public Experiment GetExperimentById(WorkspaceSetting setting, string experimentId, out string rawJson) { ValidateWorkspaceSetting(setting); Util.AuthorizationToken = setting.AuthorizationToken; rawJson = string.Empty; string queryUrl = StudioApi + string.Format("workspaces/{0}/experiments/{1}", setting.WorkspaceId, experimentId); HttpResult hr = Util.HttpGet(queryUrl).Result; if (hr.IsSuccess) { rawJson = hr.Payload; Experiment exp = jss.Deserialize <Experiment>(hr.Payload); return(exp); } else { throw new AmlRestApiException(hr); } }