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