Exemplo n.º 1
0
        /// <summary>
        /// Create ExecuteResponse for failed wps job
        /// </summary>
        /// <param name="wpsjob"></param>
        /// <returns></returns>
        public static ExecuteResponse CreateExecuteResponseForFailedWpsjob(WpsJob wpsjob)
        {
            ExecuteResponse response = new ExecuteResponse();

            response.statusLocation = wpsjob.StatusLocation;

            var uri = new Uri(wpsjob.StatusLocation);

            response.serviceInstance = string.Format("{0}://{1}/", uri.Scheme, uri.Host);
            response.service         = "WPS";
            response.version         = "1.0.0";

            var exceptionReport = new ExceptionReport {
                Exception = new List <ExceptionType> {
                    new ExceptionType {
                        ExceptionText = new List <string> {
                            wpsjob.Logs
                        }
                    }
                }
            };

            response.Status = new StatusType {
                ItemElementName = ItemChoiceType.ProcessFailed,
                Item            = new ProcessFailedType {
                    ExceptionReport = exceptionReport
                },
                creationTime = wpsjob.CreatedTime
            };
            return(response);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Post the specified request.
        /// </summary>
        /// <param name="request">Request.</param>
        public object Post(WpsJobAddGroupRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly);

            try {
                context.Open();
                context.LogInfo(this, string.Format("/job/wps/{{jobId}}/group POST jobId='{0}',Id='{1}'", request.JobId, request.Id));
                WpsJob wps = WpsJob.FromIdentifier(context, request.JobId);

                var        gids = wps.GetAuthorizedGroupIds();
                List <int> ids  = gids != null?gids.ToList() : new List <int>();

                List <Group> groups = new List <Group>();
                foreach (int id in ids)
                {
                    groups.Add(Group.FromId(context, id));
                }

                foreach (Group grp in groups)
                {
                    if (grp.Id == request.Id)
                    {
                        return(new WebResponseBool(false));
                    }
                }
                wps.GrantPermissionsToGroups(new int[] { request.Id });

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(new WebResponseBool(true));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Terradue.Tep.WpsJobOpenSearchable"/> class.
        /// </summary>
        /// <param name="url">URL.</param>
        /// <param name="ose">Ose.</param>
        public WpsJobProductOpenSearchable(WpsJob job, IfyContext context)
        {
            this.context = context;
            this.Wpsjob  = job;

            this.openSearchable = job.GetProductOpenSearchable();
        }
Exemplo n.º 4
0
        public object Post(WpsJobSendContactEmailRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.UserView);

            try {
                context.Open();
                context.LogInfo(this, string.Format("/job/wps/{{identifier}}/contact POST identifier='{0}', subject='{1}', body='{2}'",
                                                    request.JobId, request.Subject, request.Body));

                WpsJob job = WpsJob.FromIdentifier(context, request.JobId);

                //user must be the owner of the job
                if (context.UserId != job.OwnerId)
                {
                    throw new Exception("Sorry, you must be the owner of the job to contact the service provider for job analysis.");
                }

                if (job.Provider == null)
                {
                    throw new Exception("Unable to find WPS Provider contact");
                }
                var contact = job.ExtractProviderContact(job.Provider.Contact);

                //send email from job's owner to mailto
                context.SendMail(job.Owner.Email, contact, request.Subject, request.Body);

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(new WebResponseBool(true));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Tos the entity.
        /// </summary>
        /// <returns>The entity.</returns>
        /// <param name="context">Context.</param>
        /// <param name="input">Input.</param>
        public WpsJob ToEntity(IfyContext context, WpsJob input)
        {
            WpsJob entity = (input == null ? new WpsJob(context) : input);

            entity.Identifier = this.Identifier;
            entity.Name       = this.Name;
            entity.OwnerId    = context.UserId;
            entity.ProcessId  = this.ProcessId;
            if (!string.IsNullOrEmpty(this.DomainId))
            {
                entity.DomainId = Int32.Parse(this.DomainId);
            }
            if (String.IsNullOrEmpty(this.WpsId) && !String.IsNullOrEmpty(this.ProcessId))
            {
                entity.WpsId = entity.Process.Provider.Identifier;
            }
            else
            {
                entity.WpsId = this.WpsId;
            }
            entity.Parameters     = this.Parameters;
            entity.StatusLocation = this.StatusLocation;
            entity.CreatedTime    = this.CreatedTime;
            entity.EndTime        = this.EndTime;
            entity.WpsVersion     = this.WpsVersion;
            entity.WpsName        = this.WpsName;
            entity.OwsUrl         = this.OwsUrl;
            entity.AppIdentifier  = this.AppIdentifier;
            return(entity);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Terradue.Tep.WebServer.WebWpsJob"/> class.
        /// </summary>
        /// <param name="entity">Entity.</param>
        public WebWpsJobTep(WpsJob entity, IfyContext context = null) : base(entity)
        {
            this.WpsId = entity.WpsId;

            this.ProcessId = entity.ProcessId;
            if (context != null)
            {
                try {
                    this.ProcessName = Service.FromIdentifier(context, entity.ProcessId).Name;
                } catch (Exception) {
                }
                try{
                    this.Username = User.FromId(context, entity.OwnerId).Username;
                }catch (Exception) {}
            }

            this.StatusLocation   = entity.StatusLocation;
            this.Parameters       = entity.Parameters;
            this.CreatedTime      = entity.CreatedTime;
            this.EndTime          = entity.EndTime;
            this.RemoteIdentifier = entity.RemoteIdentifier;
            this.Status           = (int)entity.Status;
            this.WpsVersion       = entity.WpsVersion;
            this.WpsName          = entity.WpsName;
            this.OwsUrl           = entity.OwsUrl;
            this.AppIdentifier    = entity.AppIdentifier;
            this.ArchiveStatus    = (int)entity.ArchiveStatus;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Get the specified request.
        /// </summary>
        /// <param name="request">Request.</param>
        public object Get(WpsJobGetGroupsRequestTep request)
        {
            List <WebGroup> result = new List <WebGroup>();

            var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly);

            try {
                context.Open();
                context.LogInfo(this, string.Format("/job/wps/{{jobId}}/group GET jobId='{0}'", request.JobId));

                WpsJob job = WpsJob.FromIdentifier(context, request.JobId);

                var        gids = job.GetAuthorizedGroupIds();
                List <int> ids  = gids != null?gids.ToList() : new List <int>();

                List <Group> groups = new List <Group>();
                foreach (int id in ids)
                {
                    groups.Add(Group.FromId(context, id));
                }

                foreach (Group grp in groups)
                {
                    result.Add(new WebGroup(grp));
                }

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }
Exemplo n.º 8
0
        public async System.Threading.Tasks.Task <Event> GetLogEvent(WpsJob job, string message, string eventid)
        {
            var logevent = GetLogEvent(job, message).ContinueWith <Event>(
                jobevent => {
                if (jobevent != null)
                {
                    jobevent.Result.EventId = eventid;
                    return(jobevent.Result);
                }
                return(null);
            }
                );

            return(await logevent);
        }
Exemplo n.º 9
0
        private WpsJob CreateWpsJob(string name, WpsProcessOffering wps, User owner)
        {
            WpsJob wpsjob = new WpsJob(context);

            wpsjob.Name             = name;
            wpsjob.RemoteIdentifier = Guid.NewGuid().ToString();
            wpsjob.Identifier       = name;
            wpsjob.OwnerId          = owner.Id;
            wpsjob.WpsId            = wps.Provider.Identifier;
            wpsjob.ProcessId        = wps.Identifier;
            wpsjob.CreatedTime      = DateTime.UtcNow;
            wpsjob.DomainId         = owner.DomainId;
            wpsjob.Parameters       = new List <KeyValuePair <string, string> >();
            wpsjob.StatusLocation   = "http://dem.terradue.int:8080/wps/WebProcessingService";
            return(wpsjob);
        }
Exemplo n.º 10
0
        public object Get(ProxyWpsJobDescriptionRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);

            context.Open();
            context.LogInfo(this, string.Format("/proxy/wps/{{jobid}}/description GET jobid='{0}'", request.jobid));

            WpsJob wpsjob = WpsJob.FromIdentifier(context, request.jobid);

            context.LogDebug(this, string.Format("Wps Proxy description for wpsjob {0}", wpsjob.Identifier));

            OpenSearchDescription osd = GetWpsOpenSearchDescription(context, request.jobid, wpsjob.Name);

            context.Close();
            return(new HttpResult(osd, "application/opensearchdescription+xml"));
        }
Exemplo n.º 11
0
        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));
        }
Exemplo n.º 12
0
        protected Dictionary <string, object> GetJobBasicProperties(WpsJob job)
        {
            var properties = new Dictionary <string, object>();

            properties.Add("remote_identifier", job.RemoteIdentifier);
            properties.Add("wf_id", job.WpsName);
            properties.Add("wf_version", job.WpsVersion);
            properties.Add("app_id", job.AppIdentifier);
            properties.Add("status_url", job.StatusLocation);
            if (job.Owner != null)
            {
                var author = new Dictionary <string, string>();
                author.Add("username", job.Owner.Username);
                if (!string.IsNullOrEmpty(job.Owner.Affiliation))
                {
                    author.Add("affiliation", job.Owner.Affiliation);
                }
                if (!string.IsNullOrEmpty(job.Owner.Country))
                {
                    author.Add("country", job.Owner.Country);
                }
                properties.Add("author", author);
            }
            var inputProperties = new Dictionary <string, object>();

            foreach (var p in job.Parameters)
            {
                if (!inputProperties.ContainsKey(p.Key))
                {
                    inputProperties.Add(p.Key, p.Value);
                }
                else
                {
                    if (!(inputProperties[p.Key] is List <string>))
                    {
                        inputProperties[p.Key] = new List <string> {
                            inputProperties[p.Key] as string
                        }
                    }
                    ;
                    (inputProperties[p.Key] as List <string>).Add(p.Value);
                }
            }
            properties.Add("parameters", inputProperties);
            return(properties);
        }
    }
Exemplo n.º 13
0
        public object Put(WpsJobCopyRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly);

            try {
                context.Open();
                context.LogInfo(this, string.Format("/job/wps/copy PUT Id='{0}'", request.Id));

                WpsJob job    = WpsJob.FromIdentifier(context, request.Identifier);
                WpsJob newjob = WpsJob.Copy(job, context);

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(new WebResponseBool(true));
        }
Exemplo n.º 14
0
 /// <summary>
 /// Gets the human readable reference.
 /// </summary>
 /// <returns>The human readable reference.</returns>
 public string GetHumanReadableReference()
 {
     if (Entity != null && EntityId != 0)
     {
         try {
             if (Entity is WpsJob)
             {
                 var job = WpsJob.FromId(context, EntityId);
                 return(string.Format("Wpsjob '{0}'", job.Name));
             }
             else if (Entity is DataPackage)
             {
                 return(string.Format("Datapackage '{0}'", Entity.Name));
             }
         } catch (Exception e) {
             context.LogError(this, e.Message);
         }
     }
     return(Identifier);
 }
Exemplo n.º 15
0
        public object Put(WpsJobUpdateNbResultsRequestTep request)
        {
            var context   = TepWebContext.GetWebContext(PagePrivileges.AdminOnly);
            int nbresults = 0;

            try {
                context.Open();
                context.LogInfo(this, string.Format("/job/wps/{{identifier}}/nbresults PUT identifier='{0}'", request.JobId));

                WpsJob job = WpsJob.FromIdentifier(context, request.JobId);
                job.UpdateResultCount();
                nbresults = job.NbResults;
                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(nbresults);
        }
Exemplo n.º 16
0
        //[Test]
        public void RefreshWpsjobResultNb()
        {
            var usr4 = User.FromUsername(context, "testusr4");

            context.StartImpersonation(usr4.Id);
            try{
                var job = WpsJob.FromIdentifier(context, "private-job-usr4");
                job.Status         = WpsJobStatus.STAGED;
                job.StatusLocation = "https://recast.terradue.com/t2api/describe/fpacini/_results/workflows/geohazards_tep_dcs_rss_band_combination_band_combination_1_30_0/run/16641c36-f94f-11e8-bd04-0242ac110019/0003839-180627100334574-oozie-oozi-W";
                job.Store();

                Assert.AreEqual(job.NbResults, -1);
                Actions.RefreshWpsjobResultNb(context);
                job = WpsJob.FromIdentifier(context, "private-job-usr4");
                Assert.AreEqual(job.NbResults, 4);
            } catch (Exception e) {
                Assert.Fail(e.Message);
            } finally {
                context.EndImpersonation();
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Create a job event (metrics)
        /// </summary>
        /// <returns></returns>
        public async System.Threading.Tasks.Task <Event> GetLogEvent(WpsJob job, string message = null)
        {
            try
            {
                var durations = new Dictionary <string, int>();
                durations.Add("from_start", ((int)(DateTime.UtcNow - job.CreatedTime).TotalSeconds));
                if (job.EndTime != DateTime.MinValue)
                {
                    durations.Add("from_end", ((int)(DateTime.UtcNow - job.EndTime).TotalSeconds));
                }

                var properties = GetJobBasicProperties(job);
                var stacItems  = job.GetJobInputsStacItems();
                properties.Add("stac_items", stacItems);

                var logevent = new Event
                {
                    EventId     = GetEventIdForWpsJob(job.Status),
                    Project     = EventFactory.EventLogConfig.Settings["project"].Value,
                    Status      = job.StringStatus,
                    Durations   = durations,
                    Transmitter = EventFactory.EventLogConfig.Settings["transmitter"].Value,
                    Message     = message,
                    Item        = new EventItem
                    {
                        Created    = job.CreatedTime,
                        Updated    = job.EndTime != DateTime.MinValue ? job.EndTime : job.CreatedTime,
                        Id         = job.Identifier,
                        Title      = job.Name,
                        Type       = "portal_job",
                        Properties = properties
                    }
                };

                return(logevent);
            }catch (Exception e) {
                context.LogError(job, "Log event error: " + e.Message);
            }
            return(null);
        }
Exemplo n.º 18
0
        public void LoadWpsJobStatus()
        {
            WpsProvider provider = CreateProvider("planetek", "planetek", "http://urban-tep.planetek.it/wps/WebProcessingService", true);

            provider.Store();
            WpsProcessOffering process = CreateProcess(provider, "it.planetek.wps.extension.Processor", "Title of the processor");

            process.Store();
            WpsJob job = new WpsJob(context);

            job.WpsId          = process.Identifier;
            job.StatusLocation = "http://urban-tep.planetek.it/wps/RetrieveResultServlet?id=72ed982a-8522-4c02-bb71-77f4c22a7808";

            var jobresponse  = job.GetStatusLocationContent();
            var execResponse = jobresponse as ExecuteResponse;

            job.UpdateStatusFromExecuteResponse(execResponse);

            //get job recast response
            execResponse = ProductionResultHelper.GetWpsjobRecastResponse(context, job, execResponse);
            Assert.True(true);
        }
Exemplo n.º 19
0
        public object Get(WpsJobGetOneRequestTep request)
        {
            var          context = TepWebContext.GetWebContext(PagePrivileges.UserView);
            WebWpsJobTep result  = new WebWpsJobTep();

            try {
                context.Open();
                context.ConsoleDebug = true;
                context.LogInfo(this, string.Format("/job/wps/{{Id}} GET Id='{0}'", request.Id));

                WpsJob job = WpsJob.FromId(context, request.Id);
                result = new WebWpsJobTep(job, context);

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }

            return(result);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Put the specified request.
        /// </summary>
        /// <param name="request">Request.</param>
        public object Put(WpsJobUpdateGroupsRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly);

            try {
                context.Open();
                context.LogInfo(this, string.Format("/job/wps/{{jobId}}/group PUT jobId='{0}',Id='{1}'", request.JobId, request.ToArray() != null ? string.Join(",", request.ToArray()) : "null"));
                WpsJob wps = WpsJob.FromIdentifier(context, request.JobId);

                string sql = String.Format("DELETE FROM wpsjob_perm WHERE id_wpsjob={0} AND id_grp IS NOT NULL;", wps.Id);
                context.Execute(sql);

                wps.GrantPermissionsToGroups(request.ToArray());

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(new WebResponseBool(true));
        }
Exemplo n.º 21
0
        public void ShareWpsJobToUser()
        {
            context.AccessLevel = EntityAccessLevel.Administrator;
            var wpsjob = WpsJob.FromIdentifier(context, "restricted-job-usr1-2");
            var usr1   = User.FromUsername(context, "testusr1");

            context.AccessLevel = EntityAccessLevel.Privilege;
            context.StartImpersonation(usr1.Id);

            try {
                Assert.True(wpsjob.IsSharedToUser());

                EntityList <WpsJob> wpsjobs = new EntityList <WpsJob>(context);
                var parameters = new NameValueCollection();
                parameters.Set("q", "restricted-job-usr1-2");
                IOpenSearchResultCollection osr = ose.Query(wpsjobs, parameters);
                Assert.AreEqual(1, osr.TotalResults);
                bool hasSharedLink = false;
                foreach (var item in osr.Items)
                {
                    if (item.Identifier == "restricted-job-usr1-2")
                    {
                        foreach (var link in item.Links)
                        {
                            if (link.RelationshipType == "results")
                            {
                                hasSharedLink = true;
                            }
                        }
                    }
                }
                Assert.True(hasSharedLink);
            } catch (Exception e) {
                Assert.Fail(e.Message);
            } finally {
                context.EndImpersonation();
            }
        }
Exemplo n.º 22
0
        public object Delete(WpsJobDeleteRequestTep request)
        {
            var  context = TepWebContext.GetWebContext(PagePrivileges.UserView);
            bool result  = false;

            try {
                context.Open();
                context.LogInfo(this, string.Format("/job/wps/{{Id}} DELETE Id='{0}'", request.id));

                WpsJob job = null;
                job = WpsJob.FromIdentifier(context, request.id);
                EventFactory.LogWpsJob(context, job, "Job deleted", "portal_job_delete");
                job.Delete();
                result = true;

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(new WebResponseBool(result));
        }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 24
0
        public void SearchCommunitiesForWpsJob()
        {
            context.AccessLevel = EntityAccessLevel.Administrator;
            ThematicCommunity community = ThematicCommunity.FromIdentifier(context, "community-public-1");
            var wpsjob = WpsJob.FromIdentifier(context, "private-job-usr1");

            context.AccessLevel = EntityAccessLevel.Privilege;

            var usr1 = User.FromUsername(context, "testusr1");

            context.StartImpersonation(usr1.Id);

            try {
                community.TryJoinCurrentUser();

                //share as owner and member of community
                community.ShareEntity(wpsjob);

                var communities = new EntityList <ThematicCommunity>(context);
                var parameters  = new NameValueCollection();
                parameters.Set("correlatedTo", string.Format("{0}/job/wps/search?uid={1}", context.BaseUrl, "private-job-usr1"));
                IOpenSearchResultCollection osr = ose.Query(communities, parameters);
                Assert.AreEqual(1, osr.TotalResults);

                //unshare the job
                wpsjob.RevokePermissionsFromAll(true, false);
                wpsjob.DomainId = wpsjob.Owner.DomainId;
                wpsjob.Store();

                Assert.False(wpsjob.IsSharedToCommunity());
            } catch (Exception e) {
                Assert.Fail(e.Message);
            } finally {
                context.EndImpersonation();
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Delete the specified request.
        /// </summary>
        /// <param name="request">Request.</param>
        public object Delete(WpsJobDeleteGroupRequestTep request)
        {
            List <WebGroup> result = new List <WebGroup>();

            var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly);

            try {
                context.Open();
                context.LogInfo(this, string.Format("/job/wps/{{jobId}}/group/{{Id}} DELETE jobId='{0}',Id='{1}'", request.JobId, request.Id));

                WpsJob job = WpsJob.FromIdentifier(context, request.JobId);

                //TODO: replace once http://project.terradue.com/issues/13954 is resolved
                string sql = String.Format("DELETE FROM wpjob_perm WHERE id_wpsjob={0} AND id_grp={1};", request.JobId, job.Id);
                context.Execute(sql);

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(new WebResponseBool(true));
        }
Exemplo n.º 26
0
        public object Get(WpsJobProductSearchRequestTep request)
        {
            var        context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);
            HttpResult result  = null;

            try {
                context.Open();
                context.LogInfo(this, string.Format("/job/wps/{0}/products/search GET", request.JobId));

                WpsJob wpsjob = null;

                try {
                    wpsjob = WpsJob.FromIdentifier(context, request.JobId);
                } catch (Exception e) {
                    if (request.Key != null)                     //or if public
                    {
                        context.AccessLevel = EntityAccessLevel.Administrator;
                        wpsjob = WpsJob.FromIdentifier(context, request.JobId);
                        if (request.Key != null && !request.Key.Equals(wpsjob.AccessKey))
                        {
                            throw new UnauthorizedAccessException(CustomErrorMessages.WRONG_ACCESSKEY);
                        }
                    }
                    else
                    {
                        throw e;
                    }
                }

                OpenSearchEngine ose         = MasterCatalogue.OpenSearchEngine;
                HttpRequest      httpRequest = HttpContext.Current.Request;
                Type             type        = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose);
                var nvc = httpRequest.QueryString;

                if (CatalogueFactory.IsCatalogUrl(new Uri(wpsjob.StatusLocation)))
                {
                    var settings = MasterCatalogue.OpenSearchFactorySettings;
                    OpenSearchableFactorySettings specsettings = (OpenSearchableFactorySettings)settings.Clone();

                    //get credentials from current user
                    if (context.UserId != 0)
                    {
                        var user     = UserTep.FromId(context, context.UserId);
                        var apikey   = user.GetSessionApiKey();
                        var t2userid = user.TerradueCloudUsername;
                        if (!string.IsNullOrEmpty(apikey))
                        {
                            specsettings.Credentials = new System.Net.NetworkCredential(t2userid, apikey);
                        }
                    }
                    GenericOpenSearchable urlToShare = new GenericOpenSearchable(new OpenSearchUrl(wpsjob.StatusLocation), specsettings);
                    var res = ose.Query(urlToShare, nvc, type);
                    result = new HttpResult(res.SerializeToString(), res.ContentType);
                }
                else
                {
                    WpsJobProductOpenSearchable wpsjobProductOs = new WpsJobProductOpenSearchable(wpsjob, context);

                    //var nvc = wpsjobUrl.GetParameters ();
                    var res = ose.Query(wpsjobProductOs, nvc, type);
                    OpenSearchFactory.ReplaceSelfLinks(wpsjobProductOs, httpRequest.QueryString, res, EntrySelfLinkTemplate);
                    OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(wpsjobProductOs, res);
                    result = new HttpResult(res.SerializeToString(), res.ContentType);
                }

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }
Exemplo n.º 27
0
        public object Post(WpsJobSendSupportEmailRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.UserView);

            try {
                context.Open();
                context.LogInfo(this, string.Format("/job/wps/{{identifier}}/support POST identifier='{0}', subject='{1}', body='{2}'",
                                                    request.JobId, request.Subject, request.Body));

                WpsJob job = WpsJob.FromIdentifier(context, request.JobId);

                //user must be the owner of the job
                if (context.UserId != job.OwnerId)
                {
                    throw new Exception("Sorry, you must be the owner of the job to contact the support for job analysis.");
                }

                var supportModes = context.GetConfigValue("wpsjob-support-mode").Split(',');
                if (supportModes.Contains("mail"))
                {
                    //send email from job's owner to mailto
                    context.SendMail(job.Owner.Email ?? context.GetConfigValue("MailSenderAddress"), context.GetConfigValue("MailSenderAddress"), request.Subject, request.Body);
                }
                if (supportModes.Contains("jira"))
                {
                    //create JIRA ticket
                    var components       = new List <JiraNameProperty>();
                    var configComponents = context.GetConfigValue("jira-helpdesk-components");
                    if (!string.IsNullOrEmpty(configComponents))
                    {
                        var componentsList = configComponents.Split(',');
                        foreach (var component in componentsList)
                        {
                            components.Add(new JiraNameProperty {
                                name = component
                            });
                        }
                    }
                    var labels       = new List <string>();
                    var configLabels = context.GetConfigValue("jira-helpdesk-labels");
                    if (!string.IsNullOrEmpty(configLabels))
                    {
                        labels = configLabels.Split(',').ToList();
                    }
                    var owner = job.Owner;
                    if (string.IsNullOrEmpty(owner.TerradueCloudUsername))
                    {
                        owner.LoadCloudUsername();
                    }
                    var raiseOnBehalfOf = owner.TerradueCloudUsername;
                    var issue           = new JiraServiceDeskIssueRequest {
                        serviceDeskId      = context.GetConfigValue("jira-helpdesk-serviceDeskId"),
                        requestTypeId      = context.GetConfigValue("jira-helpdesk-requestTypeId"),
                        raiseOnBehalfOf    = raiseOnBehalfOf,
                        requestFieldValues = new JiraServiceDeskIssueFields {
                            summary     = request.Subject,
                            description = request.Body,
                            components  = components,
                            labels      = labels
                        }
                    };
                    if (!string.IsNullOrEmpty(context.GetConfigValue("jira-helpdesk-customfield-ThematicAppLabel")))
                    {
                        issue.requestFieldValues.thematicAppLabels = new List <string> {
                            request.AppId
                        };
                    }
                    if (!string.IsNullOrEmpty(context.GetConfigValue("jira-helpdesk-customfield-ProcessingServiceLabel")))
                    {
                        if (job.Process != null && !string.IsNullOrEmpty(job.Process.Name))
                        {
                            var process = job.Process.Name.Replace(' ', '-');
                            issue.requestFieldValues.processingServicesLabels = new List <string> {
                                process
                            };
                        }
                    }
                    var jira = new JiraClient(context);
                    try {
                        jira.CreateServiceDeskIssue(issue);
                    }catch (Exception) {
                        issue.raiseOnBehalfOf = job.Owner.Email;
                        jira.CreateServiceDeskIssue(issue);
                    }
                }

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(new WebResponseBool(true));
        }
Exemplo n.º 28
0
        /// <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));
        }
Exemplo n.º 29
0
        /// <summary>
        /// Creates the execute response for staged wpsjob.
        /// </summary>
        /// <returns>The execute response for staged wpsjob.</returns>
        /// <param name="context">Context.</param>
        /// <param name="wpsjob">Wpsjob.</param>
        public static ExecuteResponse CreateExecuteResponseForStagedWpsjob(IfyContext context, WpsJob wpsjob, ExecuteResponse response)
        {
            if (response == null)
            {
                response        = new ExecuteResponse();
                response.Status = new StatusType {
                    Item = new ProcessSucceededType {
                        Value = "Process successful"
                    },
                    ItemElementName = ItemChoiceType.ProcessSucceeded,
                    creationTime    = wpsjob.EndTime != DateTime.MinValue ? wpsjob.EndTime : wpsjob.CreatedTime
                };
            }

            var statusurl      = wpsjob.StatusLocation;
            var url            = new Uri(statusurl);
            var searchableUrls = JsonSerializer.DeserializeFromString <List <string> >(AppSettings["OpenSearchableUrls"]);

            if (searchableUrls == null || searchableUrls.Count == 0)
            {
                searchableUrls = new List <string>();
                searchableUrls.Add(recastBaseUrl);//in case appsettings not set
            }
            var recognizedHost = false;

            foreach (var u in searchableUrls)
            {
                if (new Uri(u).Host == url.Host)
                {
                    recognizedHost = true;
                }
            }
            bool statusNotOpensearchable =
                !recognizedHost &&
                !statusurl.Contains("/search") &&
                !statusurl.Contains("/description");

            context.LogDebug(wpsjob, string.Format("Status url {0} is opensearchable : {1}", statusurl, statusNotOpensearchable ? "false" : "true"));
            if (statusNotOpensearchable)
            {
                statusurl = context.BaseUrl + "/job/wps/" + wpsjob.Identifier + "/products/description";
            }

            response.statusLocation  = context.BaseUrl + "/wps/RetrieveResultServlet?id=" + wpsjob.Identifier;
            response.serviceInstance = context.BaseUrl + "/wps/WebProcessingService?REQUEST=GetCapabilities&SERVICE=WPS";
            response.ProcessOutputs  = new List <OutputDataType> {
            };
            response.ProcessOutputs.Add(new OutputDataType {
                Identifier = new CodeType {
                    Value = "result_osd"
                },
                Item = new DataType {
                    Item = new ComplexDataType {
                        mimeType  = "application/xml",
                        Reference = new OutputReferenceType {
                            href     = statusurl,
                            mimeType = "application/opensearchdescription+xml"
                        }
                    }
                }
            });

            if (!string.IsNullOrEmpty(wpsjob.OwsUrl))
            {
                response.ProcessOutputs.Add(new OutputDataType {
                    Identifier = new CodeType {
                        Value = "job_ows"
                    },
                    Item = new DataType {
                        Item = new ComplexDataType {
                            mimeType  = "application/xml",
                            Reference = new OutputReferenceType {
                                href     = wpsjob.OwsUrl,
                                mimeType = "application/xml"
                            }
                        }
                    }
                });
            }

            return(response);
        }
Exemplo n.º 30
0
        public object Get(WpsJobProductDescriptionRequestTep request)
        {
            var        context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);
            HttpResult result  = null;

            try {
                context.Open();
                context.LogInfo(this, string.Format("/job/wps/{0}/products/description GET", request.JobId));

                WpsJob wpsjob = WpsJob.FromIdentifier(context, request.JobId);

                OpenSearchEngine ose         = MasterCatalogue.OpenSearchEngine;
                HttpRequest      httpRequest = HttpContext.Current.Request;

                OpenSearchDescription osd;

                if (CatalogueFactory.IsCatalogUrl(new Uri(wpsjob.StatusLocation)))
                {
                    var settings = MasterCatalogue.OpenSearchFactorySettings;
                    OpenSearchableFactorySettings specsettings = (OpenSearchableFactorySettings)settings.Clone();

                    //get credentials from current user
                    if (context.UserId != 0)
                    {
                        var user     = UserTep.FromId(context, context.UserId);
                        var apikey   = user.GetSessionApiKey();
                        var t2userid = user.TerradueCloudUsername;
                        if (!string.IsNullOrEmpty(apikey))
                        {
                            specsettings.Credentials = new System.Net.NetworkCredential(t2userid, apikey);
                        }
                    }
                    GenericOpenSearchable urlToShare = new GenericOpenSearchable(new OpenSearchUrl(wpsjob.StatusLocation), specsettings);
                    osd = urlToShare.GetOpenSearchDescription();
                    var oldUri = new UriBuilder(osd.DefaultUrl.Template);
                    var newUri = new UriBuilder(context.BaseUrl + "/job/wps/" + wpsjob.Identifier + "/products/search");
                    newUri.Query            = oldUri.Query.TrimStart("?".ToCharArray());
                    osd.DefaultUrl.Template = HttpUtility.UrlDecode(newUri.Uri.AbsoluteUri);
                    foreach (var url in osd.Url)
                    {
                        oldUri       = new UriBuilder(url.Template);
                        newUri       = new UriBuilder(context.BaseUrl + "/job/wps/" + wpsjob.Identifier + "/products/search");
                        newUri.Query = oldUri.Query.TrimStart("?".ToCharArray());
                        url.Template = HttpUtility.UrlDecode(newUri.Uri.AbsoluteUri);
                    }
                }
                else
                {
                    WpsJobProductOpenSearchable wpsjobProductOs = new WpsJobProductOpenSearchable(wpsjob, context);
                    osd = wpsjobProductOs.GetProxyOpenSearchDescription();
                }

                result = new HttpResult(osd, "application/opensearchdescription+xml");

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }