/// <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)); }
protected IO.Swagger.Model.Execute BuildExecute(OpenGis.Wps.Execute executeInput) { context.LogDebug(this, "BuildExecute"); var wps3 = GetWps3ProcessingFromDescribeProcess(this.Url); List <IO.Swagger.Model.Input> inputs = new List <IO.Swagger.Model.Input>(); foreach (var dataInput in executeInput.DataInputs) { var inp = new Inputs(); inp.Id = dataInput.Identifier.Value; context.LogDebug(this, "BuildExecute - input = " + dataInput.Identifier.Value); if (dataInput.Data != null && dataInput.Data.Item != null) { if (dataInput.Data.Item is OpenGis.Wps.LiteralDataType) { var datatype = "string"; foreach (var i in wps3.Process.Inputs) { if (inp.Id == i.Id) { if (i.Input.LiteralDataDomains != null) { var literaldomain = i.Input.LiteralDataDomains[0]; if (!string.IsNullOrEmpty(literaldomain.DataType.Reference)) { datatype = literaldomain.DataType.Reference; } } } } var ld = dataInput.Data.Item as OpenGis.Wps.LiteralDataType; string inputValue = ld.Value; Uri outUri; if (Uri.TryCreate(inputValue, UriKind.Absolute, out outUri) && (outUri.Scheme == Uri.UriSchemeHttp || outUri.Scheme == Uri.UriSchemeHttps)) { try { var urib = new UriBuilder(inputValue); var nvc = HttpUtility.ParseQueryString(urib.Query); //case WPS3 endpoint does not support format=json if (CatalogueFactory.IsCatalogUrl(urib.Uri) && !string.IsNullOrEmpty(context.GetConfigValue("wps3input-format"))) { nvc["format"] = context.GetConfigValue("wps3input-format"); } //case WPS3 endpoint needs a specific downloadorigin if (CatalogueFactory.IsCatalogUrl(urib.Uri) && !string.IsNullOrEmpty(context.GetConfigValue("wps3input-downloadorigin"))) { nvc["do"] = context.GetConfigValue("wps3input-downloadorigin"); } string[] queryString = Array.ConvertAll(nvc.AllKeys, key => string.Format("{0}={1}", key, nvc[key])); urib.Query = string.Join("&", queryString); inputValue = urib.Uri.AbsoluteUri; } catch (System.Exception e) { context.LogError(this, e.Message); } } StupidData literalData = new StupidData(inputValue, new StupidDataType(datatype)); inputs.Add(new IO.Swagger.Model.Input(dataInput.Identifier.Value, literalData)); } } } List <IO.Swagger.Model.Output> outputs = new List <IO.Swagger.Model.Output>(); var output = new IO.Swagger.Model.Output(); output.Id = "wf_outputs"; output.TransmissionMode = TransmissionMode.Reference; output.Format = new IO.Swagger.Model.Format("application/json"); outputs.Add(output); return(new IO.Swagger.Model.Execute(inputs, outputs, IO.Swagger.Model.Execute.ModeEnum.Async, IO.Swagger.Model.Execute.ResponseEnum.Raw, null)); }