public object Put(WpsJobUpdateRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); context.Open(); context.LogInfo(this, string.Format("/job/wps PUT Id='{0}'", request.Id)); WpsJob job = WpsJob.FromIdentifier(context, request.Identifier); try{ job.Name = request.Name; job.Store(); context.LogDebug(this, string.Format("WpsJob '{0}' updated", job.Name)); }catch (Exception e) { throw e; } EntityList <WpsJob> wpsjobs = new EntityList <WpsJob>(context); wpsjobs.ItemVisibility = EntityItemVisibility.OwnedOnly; wpsjobs.Load(); OpenSearchEngine ose = MasterCatalogue.OpenSearchEngine; string format; if (Request.QueryString["format"] == null) { format = "atom"; } else { format = Request.QueryString["format"]; } NameValueCollection nvc = new NameValueCollection(); nvc.Add("id", job.Identifier); Type responseType = OpenSearchFactory.ResolveTypeFromRequest(HttpContext.Current.Request.QueryString, HttpContext.Current.Request.Headers, ose); IOpenSearchResultCollection osr = ose.Query(wpsjobs, nvc, responseType); OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(wpsjobs, osr); context.Close(); return(new HttpResult(osr.SerializeToString(), osr.ContentType)); }
public object Put(WpsJobUpdateArchiveStatusRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); WebWpsJobTep result; try { context.Open(); context.LogInfo(this, string.Format("/job/wps/{{identifier}}/archive PUT identifier='{0}', status={1}", request.JobId, request.ArchiveStatus)); WpsJob job = WpsJob.FromIdentifier(context, request.JobId); job.ArchiveStatus = (WpsJobArchiveStatus)request.ArchiveStatus; job.Store(); result = new WebWpsJobTep(job); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
/// <summary> /// Gets the wpsjob recast response. /// </summary> /// <returns>The wpsjob recast response.</returns> /// <param name="wpsjob">Wpsjob.</param> /// <param name="execResponse">Exec response.</param> public static ExecuteResponse GetWpsjobRecastResponse(IfyContext context, WpsJob wpsjob, ExecuteResponse execResponse = null) { log.DebugFormat("GetWpsjobRecastResponse"); if (wpsjob.Status == WpsJobStatus.COORDINATOR) { log.DebugFormat("GetWpsjobRecastResponse -- Status is Coordinator"); var resultUrl = WpsJob.GetResultUrl(execResponse); if (resultUrl == null) { return(UpdateProcessOutputs(context, execResponse, wpsjob)); } wpsjob.StatusLocation = resultUrl; wpsjob.Store(); return(CreateExecuteResponseForStagedWpsjob(context, wpsjob, execResponse)); } if (wpsjob.Status != WpsJobStatus.SUCCEEDED) { log.DebugFormat("GetWpsjobRecastResponse -- Status is not Succeeded"); return(UpdateProcessOutputs(context, execResponse, wpsjob)); } if (execResponse == null) { var jobresponse = wpsjob.GetStatusLocationContent(); if (jobresponse is ExecuteResponse) { execResponse = jobresponse as ExecuteResponse; } else { throw new Exception("Error while creating Execute Response of job " + wpsjob.Identifier); } } if (wpsjob.Provider != null && !wpsjob.Provider.StageResults) { log.DebugFormat("GetWpsjobRecastResponse -- Provider does not allow staging"); return(UpdateProcessOutputs(context, execResponse, wpsjob)); } if (execResponse.Status.Item is ProcessSucceededType) { var resultUrl = WpsJob.GetResultUrl(execResponse); if (resultUrl == null) { return(UpdateProcessOutputs(context, execResponse, wpsjob)); } var url = new Uri(resultUrl); System.Text.RegularExpressions.Regex r; System.Text.RegularExpressions.Match m; string hostname = url.Host; string workflow = "", runId = ""; string recaststatusurl = "", newStatusLocation = ""; //case url is recast describe url if (resultUrl.StartsWith(string.Format("{0}/t2api/describe", recastBaseUrl))) { wpsjob.StatusLocation = resultUrl; wpsjob.Status = WpsJobStatus.STAGED; wpsjob.Store(); return(CreateExecuteResponseForStagedWpsjob(context, wpsjob, execResponse)); } else { //case old sandboxes r = new System.Text.RegularExpressions.Regex(@"^\/sbws\/wps\/(?<workflow>[a-zA-Z0-9_\-]+)\/(?<runid>[a-zA-Z0-9_\-]+)\/results"); m = r.Match(url.AbsolutePath); if (m.Success) { workflow = m.Result("${workflow}"); runId = m.Result("${runid}"); if (wpsjob.Provider != null && wpsjob.Provider.BaseUrl != null) { r = new System.Text.RegularExpressions.Regex(@"https?:\/\/ogc-eo-apps-0?[0-9@].terradue.com"); m = r.Match(wpsjob.Provider.BaseUrl); if (m.Success) { if (wpsjob.Owner != null) { var username = wpsjob.Owner.TerradueCloudUsername; var recastdescribeurl = string.Format("{0}/t2api/describe/{1}/_results/workflows/{2}/run/{3}", recastBaseUrl, username, workflow, runId); wpsjob.StatusLocation = recastdescribeurl; wpsjob.Status = WpsJobStatus.STAGED; wpsjob.Store(); return(CreateExecuteResponseForStagedWpsjob(context, wpsjob, execResponse)); } } } recaststatusurl = GetWpsJobRecastStatusUrl(hostname, workflow, runId); newStatusLocation = GetWpsJobRecastDescribeUrl(hostname, workflow, runId); } else { //case new sandboxes r = new System.Text.RegularExpressions.Regex(@"^\/sbws\/production\/run\/(?<workflow>[a-zA-Z0-9_\-]+)\/(?<runid>[a-zA-Z0-9_\-]+)\/products"); m = r.Match(url.AbsolutePath); if (m.Success) { workflow = m.Result("${workflow}"); runId = m.Result("${runid}"); recaststatusurl = GetWpsJobRecastStatusUrl(hostname, workflow, runId); newStatusLocation = GetWpsJobRecastDescribeUrl(hostname, workflow, runId); } else { //case production clusters r = new System.Text.RegularExpressions.Regex(@"^\/production\/(?<community>[a-zA-Z0-9_\-]+)\/results\/workflows\/(?<workflow>[a-zA-Z0-9_\-]+)\/runs\/(?<runid>[a-zA-Z0-9_\-]+)"); m = r.Match(url.AbsolutePath); if (m.Success) { workflow = m.Result("${workflow}"); runId = m.Result("${runid}"); var community = m.Result("${community}"); recaststatusurl = GetWpsJobRecastStatusUrl(hostname, workflow, runId); newStatusLocation = GetWpsJobRecastDescribeUrl(hostname, workflow, runId); } else { //case direct recast or catalog response if (url.Host == new Uri(recastBaseUrl).Host || CatalogueFactory.IsCatalogUrl(url)) { log.DebugFormat("Recasting (DIRECT) job {0} - url = {1}", wpsjob.Identifier, resultUrl); wpsjob.StatusLocation = resultUrl; wpsjob.Status = WpsJobStatus.STAGED; wpsjob.Store(); return(CreateExecuteResponseForStagedWpsjob(context, wpsjob, execResponse)); } else { //cases external providers var dataGatewaySubstitutions = JsonSerializer.DeserializeFromString <List <DataGatewaySubstitution> >(AppSettings["DataGatewaySubstitutions"]); if (dataGatewaySubstitutions != null) { foreach (var sub in dataGatewaySubstitutions) { if (url.Host.Equals(sub.host) && url.AbsolutePath.Contains(sub.oldvalue)) { var path = url.AbsolutePath; path = path.Replace(sub.oldvalue, sub.substitute); //we assume that result url is pointing to a metadata file path = path.Substring(0, path.LastIndexOf("/")); recaststatusurl = GetWpsJobRecastStatusUrl(path); newStatusLocation = GetWpsJobRecastDescribeUrl(path); continue; } } } //none of the above cases if (string.IsNullOrEmpty(recaststatusurl)) { log.DebugFormat("Recasting job {0} - url = {1} ; the url did not match any case", wpsjob.Identifier, url.AbsolutePath); return(UpdateProcessOutputs(context, execResponse, wpsjob)); } } } } } } try { var recaststatus = GetWpsjobRecastStatus(recaststatusurl); //error during recast if (recaststatus.status == statusError) { log.ErrorFormat("Recasting job {0} - url = {1} - message = {2}", wpsjob.Identifier, recaststatusurl, recaststatus.message); var exceptionReport = new ExceptionReport { Exception = new List <ExceptionType> { new ExceptionType { ExceptionText = new List <string> { "Error while staging data to store --- " + recaststatus.message } } } }; execResponse.Status = new StatusType { Item = new ProcessFailedType { ExceptionReport = exceptionReport }, ItemElementName = ItemChoiceType.ProcessFailed, creationTime = wpsjob.CreatedTime }; } //recast is still in progress else if (recaststatus.status == statusInProgress) { log.DebugFormat("Recasting STILL IN PROGRESS job {0} - url = {1} - message = {2}", wpsjob.Identifier, recaststatusurl, recaststatus.message); execResponse.Status = new StatusType { Item = new ProcessStartedType { Value = "Process in progress", percentCompleted = "99" }, ItemElementName = ItemChoiceType.ProcessStarted, creationTime = wpsjob.CreatedTime }; } //recast is completed else if (recaststatus.status == statusCompleted) { log.DebugFormat("Recasting job {0} - url = {1} - message = {2}", wpsjob.Identifier, recaststatusurl, recaststatus.message); wpsjob.StatusLocation = newStatusLocation; wpsjob.Status = WpsJobStatus.STAGED; wpsjob.Store(); return(CreateExecuteResponseForStagedWpsjob(context, wpsjob, execResponse)); } }catch (Exception) { } } return(UpdateProcessOutputs(context, execResponse, wpsjob)); }
private void CreateWpsJobs() { WpsProcessOffering process = CreateProcess(false); var usr1 = User.FromUsername(context, "testusr1"); var usr2 = User.FromUsername(context, "testusr2"); var usr3 = User.FromUsername(context, "testusr3"); var usr4 = User.FromUsername(context, "testusr4"); var domain = Domain.FromIdentifier(context, "myDomainTest"); var domain2 = Domain.FromIdentifier(context, "otherDomainTest"); //Create one wpsjob public for usr1 --- all should see it WpsJob job = CreateWpsJob("public-job-usr1", process, usr1); job.Store(); job.GrantGlobalPermissions(); //Create one wpsjob with domain where usr1 is member job = CreateWpsJob("domain1-job-usr2", process, usr2); job.Domain = domain; job.Store(); //Create one wpsjob with domain where usr1 is not member job = CreateWpsJob("domain2-job-usr3", process, usr3); job.Domain = domain2; job.Store(); //Create one wpsjob public for usr2 --- all should see it job = CreateWpsJob("public-job-usr2", process, usr2); job.Store(); job.GrantGlobalPermissions(); //Create one wpsjob restricted for usr1 job = CreateWpsJob("restricted-job-usr1-2", process, usr1); job.Store(); job.GrantPermissionsToUsers(new int[] { usr2.Id }); //Create one wpsjob restricted for usr2 job = CreateWpsJob("restricted-job-usr2-1", process, usr2); job.Store(); job.GrantPermissionsToUsers(new int[] { usr1.Id }); //Create one wpsjob restricted for usr2 job = CreateWpsJob("restricted-job-usr2-3", process, usr2); job.Store(); job.GrantPermissionsToUsers(new int[] { usr3.Id }); //Create one wpsjob private for usr1 job = CreateWpsJob("private-job-usr1", process, usr1); job.Store(); //Create one wpsjob private for usr2 job = CreateWpsJob("private-job-usr2", process, usr2); job.Store(); //Create one wpsjob private for usr3 job = CreateWpsJob("private-job-usr3", process, usr3); job.Store(); //Create one wpsjob private for usr4 job = CreateWpsJob("private-job-usr4", process, usr4); job.Store(); }