Beispiel #1
0
        /**********************************************************************/
        /**********************************************************************/

        /// <summary>
        /// Refreshs the wpjob status.
        /// </summary>
        /// <param name="context">Context.</param>
        public static void RefreshWpsjobStatus(IfyContext context)
        {
            var jobs = new EntityList <WpsJob>(context);

            jobs.SetFilter("Status", (int)WpsJobStatus.ACCEPTED + "," + (int)WpsJobStatus.NONE + "," + (int)WpsJobStatus.PAUSED + "," + (int)WpsJobStatus.STARTED);
            var jobsPoolSize      = context.GetConfigIntegerValue("action-jobPoolSize");
            var maxDaysJobRefresh = context.GetConfigIntegerValue("action-maxDaysJobRefresh");

            jobs.ItemsPerPage = jobsPoolSize;
            jobs.Load();
            context.WriteInfo(string.Format("RefreshWpjobStatus -- found {0} jobs (total result = {1})", jobs.Count, jobs.TotalResults));
            foreach (var job in jobs)
            {
                string status = job.StringStatus;
                if (job.Status != WpsJobStatus.FAILED && job.Status != WpsJobStatus.STAGED && job.Status != WpsJobStatus.COORDINATOR)
                {
                    try {
                        var jobresponse = job.UpdateStatus();
                        if (jobresponse is ExecuteResponse)
                        {
                            var execResponse = jobresponse as ExecuteResponse;

                            //if job status not updated and job is older than the max time allowed, we set as failed
                            if (status == job.StringStatus && DateTime.UtcNow.AddDays(-maxDaysJobRefresh) > job.CreatedTime)
                            {
                                job.Status = WpsJobStatus.FAILED;
                                job.Logs   = "Job did not complete before the max allowed time";
                                EventFactory.LogWpsJob(context, job, job.Logs);
                            }
                            job.Store();
                        }
                        else
                        {
                            //if job is an exception or older than the max time allowed, we set as failed
                            if (jobresponse is ExceptionReport || DateTime.UtcNow.AddDays(-maxDaysJobRefresh) > job.CreatedTime)
                            {
                                job.Status = WpsJobStatus.FAILED;
                                if (jobresponse is ExceptionReport)
                                {
                                    job.Logs = "Unknown exception";
                                }
                                else
                                {
                                    job.Logs = "Job did not complete before the max allowed time";
                                }
                                job.Store();
                                EventFactory.LogWpsJob(context, job, job.Logs);
                            }
                        }
                    }catch (WpsProxyException e) {
                        context.WriteError(string.Format("RefreshWpjobStatus -- job '{1}'-- '{0}'", e.Message, job.Identifier));
                        if (DateTime.UtcNow.AddDays(-maxDaysJobRefresh) > job.CreatedTime)   //if job is older than a month and makes an exception, we set as failed
                        {
                            job.Status = WpsJobStatus.FAILED;
                            job.Logs   = "Job did not complete before the max allowed time";
                            EventFactory.LogWpsJob(context, job, job.Logs);
                            job.Store();
                        }
                        else
                        {
                        }
                    }catch (Exception e) {
                        context.WriteError(string.Format("RefreshWpjobStatus -- job '{1}'-- '{0}'", e.Message, job.Identifier));
                    }
                    context.WriteInfo(string.Format("RefreshWpjobStatus -- job '{0}' -- status = {1} -> {2}", job.Identifier, status, job.StringStatus));
                }
            }
        }
Beispiel #2
0
        public string GetResultDescriptionFromS3Link(IfyContext context, WpsJob job, string s3link)
        {
            var resultdescription = s3link;

            if (System.Configuration.ConfigurationManager.AppSettings["SUPERVISOR_WPS_STAGE_URL"] != null && !string.IsNullOrEmpty(s3link))
            {
                var            url        = System.Configuration.ConfigurationManager.AppSettings["SUPERVISOR_WPS_STAGE_URL"];
                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
                if (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["ProxyHost"]))
                {
                    webRequest.Proxy = TepUtility.GetWebRequestProxy();
                }
                var access_token = DBCookie.LoadDBCookie(context, System.Configuration.ConfigurationManager.AppSettings["SUPERVISOR_COOKIE_TOKEN_ACCESS"]).Value;
                webRequest.Headers.Set(HttpRequestHeader.Authorization, "Bearer " + access_token);
                webRequest.Timeout     = 10000;
                webRequest.Method      = "POST";
                webRequest.ContentType = "application/json";

                var shareUri    = job.GetJobShareUri(job.AppIdentifier);
                var publishlink = new Wps3Utils.SyndicationLink {
                    Href       = shareUri.AbsoluteUri,
                    Rel        = "external",
                    Type       = "text/html",
                    Title      = "Producer Link",
                    Attributes = new List <KeyValuePair <string, string> > {
                        new KeyValuePair <string, string>("level", "primary")
                    }
                };
                context.LogDebug(job, string.Format("publish request to supervisor - s3link = {0} ; jobUrl = {1} ; index = {2}", s3link, shareUri.AbsoluteUri, job.Owner.Username));
                string authBasicHeader = null;
                try {
                    if (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["SUPERVISOR_FIXED_AUTH_HEADER"]))
                    {
                        authBasicHeader = System.Configuration.ConfigurationManager.AppSettings["SUPERVISOR_FIXED_AUTH_HEADER"];
                    }
                    else
                    {
                        var apikey = job.Owner.LoadApiKeyFromRemote();
                        authBasicHeader = "Basic " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(job.Owner.Username + ":" + apikey));
                    }
                }catch (Exception e) {
                    context.LogError(this, "Error get apikey : " + e.Message);
                }

                var jsonurl = new SupervisorPublish
                {
                    Url = s3link,
                    AuthorizationHeader = authBasicHeader,
                    Index       = job.Owner.Username,
                    CreateIndex = true,
                    Categories  = new List <Wps3Utils.SyndicationCategory> {
                        new Wps3Utils.SyndicationCategory {
                            Name = "appId", Label = job.AppIdentifier, Scheme = ""
                        }
                    },
                    Links = new List <Wps3Utils.SyndicationLink> {
                        publishlink
                    }
                };

                var json = ServiceStack.Text.JsonSerializer.SerializeToString(jsonurl);
                context.LogDebug(this, string.Format("publish request to supervisor - json = {0}", json));
                EventFactory.LogWpsJob(context, job, "Job published", "portal_job_publish");
                try {
                    using (var streamWriter = new StreamWriter(webRequest.GetRequestStream())) {
                        streamWriter.Write(json);
                        streamWriter.Flush();
                        streamWriter.Close();

                        using (var httpResponse = (HttpWebResponse)webRequest.GetResponse()) {
                            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                            {
                                var location = httpResponse.Headers["Location"];
                                if (!string.IsNullOrEmpty(location))
                                {
                                    context.LogDebug(this, "location = " + location);
                                    resultdescription = new Uri(location, UriKind.RelativeOrAbsolute).AbsoluteUri;
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    context.LogError(job, "Error Create user product request to supervisor: " + e.Message);
                }
            }
            return(resultdescription);
        }