コード例 #1
0
ファイル: AzureMLSDK.cs プロジェクト: whoshane/azuremlps
        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);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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), "&region=" + 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);
        }
コード例 #12
0
        // 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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
        }
コード例 #15
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 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));
        }
コード例 #16
0
ファイル: AzureMLSDK.cs プロジェクト: mufukuha/azuremlps
        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);
        }
コード例 #17
0
 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);
 }
コード例 #18
0
        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);
        }
コード例 #19
0
        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);
            }
        }
コード例 #20
0
        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);
            }
        }
コード例 #21
0
        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);
            }
        }
コード例 #22
0
        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);
            }
        }
コード例 #23
0
        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);
            }
        }
コード例 #24
0
        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);
        }
コード例 #25
0
        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);
            }
        }
コード例 #26
0
        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);
            }
        }
コード例 #27
0
        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);
        }
コード例 #28
0
        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;
            }
        }
コード例 #29
0
        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);
            }
        }
コード例 #30
0
        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);
            }
        }