/// <summary>
 /// Query a specific commit point of a store
 /// </summary>
 /// <param name="commitPoint">The commit point be queried</param>
 /// <param name="queryExpression">The SPARQL query string</param>
 /// <param name="resultsFormat"> OPTIONAL: The format for the SPARQL results. Defaults to <see cref="SparqlResultsFormat.Xml"/></param>
 /// <returns>A stream containing SPARQL results in the requested format</returns>
 public Stream ExecuteQuery(ICommitPointInfo commitPoint, string queryExpression, SparqlResultsFormat resultsFormat = null)
 {
     if (commitPoint == null)
     {
         throw new ArgumentNullException("commitPoint");
     }
     if (queryExpression == null)
     {
         throw new ArgumentNullException("queryExpression", Strings.BrightstarServiceClient_QueryMustNotBeNull);
     }
     if (String.Empty.Equals(queryExpression))
     {
         throw new ArgumentException(Strings.BrightstarServiceClient_QueryMustNotBeEmptyString, "queryExpression");
     }
     try
     {
         return(_service.ExecuteQueryOnCommitPoint(
                    new CommitPointInfo
         {
             Id = commitPoint.Id,
             StoreName = commitPoint.StoreName,
             CommitTime = commitPoint.CommitTime,
             JobId = commitPoint.JobId
         },
                    queryExpression,
                    resultsFormat == null ? SparqlResultsFormat.Xml.MediaTypes.First() + "; charset=utf-8" : resultsFormat.ToString()));
     }
     catch (FaultException <ExceptionDetail> fault)
     {
         throw new BrightstarClientException(fault);
     }
 }
        /// <summary>
        /// Query a specific commit point of a store
        /// </summary>
        /// <param name="commitPoint">The commit point be queried</param>
        /// <param name="queryExpression">The SPARQL query string</param>
        /// <param name="resultsFormat">The format to use for the SPARQL results. Defaults to <see cref="SparqlResultsFormat.Xml"/></param>
        /// <returns>A stream containing XML SPARQL results</returns>
        public Stream ExecuteQuery(ICommitPointInfo commitPoint, string queryExpression, SparqlResultsFormat resultsFormat = null)
        {
            if (queryExpression == null)
            {
                throw new ArgumentNullException("queryExpression");
            }
            if (resultsFormat == null)
            {
                resultsFormat = SparqlResultsFormat.Xml;
            }

            try
            {
                var pStream = new MemoryStream();
#if SILVERLIGHT
                var t = new Thread(ExecuteQuery);
                t.Start(new QueryParams(commitPoint, queryExpression, resultsFormat, pStream));
                t.Join();
#else
                var t =
                    new Task(() => _serverCore.Query(commitPoint.StoreName, commitPoint.Id, queryExpression, resultsFormat, pStream));
                t.Start();
                t.Wait();
                if (t.IsFaulted && t.Exception != null)
                {
                    throw t.Exception;
                }
#endif
                pStream.Seek(0, SeekOrigin.Begin);
                return(pStream);
            }
            catch (AggregateException aggregateException)
            {
                Logging.LogError(BrightstarEventId.ServerCoreException,
                                 "Error querying store {0}@{1} with expression {2}", commitPoint.StoreName,
                                 commitPoint.Id, queryExpression);
                if (aggregateException.InnerExceptions.Count == 1)
                {
                    throw new BrightstarClientException(
                              String.Format("Error querying store {0}@{1} with expression {2}. {3}",
                                            commitPoint.StoreName, commitPoint.Id, queryExpression,
                                            aggregateException.InnerExceptions[0].Message));
                }
                var messages = String.Join("; ", aggregateException.InnerExceptions.Select(ex => ex.Message));
                throw new BrightstarClientException(
                          String.Format(
                              "Error querying store {0}@{1} with expression {2}. Multiple errors occurred: {3}",
                              commitPoint.StoreName, commitPoint.Id, queryExpression, messages));
            }
            catch (Exception ex)
            {
                Logging.LogError(BrightstarEventId.ServerCoreException,
                                 "Error querying store {0}@{1} with expression {2}", commitPoint.StoreName,
                                 commitPoint.Id, queryExpression);
                throw new BrightstarClientException(
                          String.Format("Error querying store {0}@{1} with expression {2}. {3}", commitPoint.StoreName,
                                        commitPoint.Id, queryExpression, ex.Message), ex);
            }
        }
 public QueryParams(ICommitPointInfo commitPoint, string queryExpression, SparqlResultsFormat resultsFormat, Stream outputStream)
 {
     StoreName       = commitPoint.StoreName;
     CommitPointId   = commitPoint.Id;
     WithCommitPoint = true;
     QueryExpression = queryExpression;
     OutputStream    = outputStream;
     ResultsFormat   = resultsFormat ?? SparqlResultsFormat.Xml;
 }
Beispiel #4
0
 private static CommitPointResponseModel MakeResponseObject(ICommitPointInfo commitPointInfo)
 {
     return(new CommitPointResponseModel
     {
         Id = commitPointInfo.Id,
         CommitTime = commitPointInfo.CommitTime,
         JobId = commitPointInfo.JobId,
         StoreName = commitPointInfo.StoreName
     });
 }
 private static CommitPointResponseModel MakeResponseObject(ICommitPointInfo commitPointInfo)
 {
     return new CommitPointResponseModel
         {
             Id = commitPointInfo.Id,
             CommitTime = commitPointInfo.CommitTime,
             JobId = commitPointInfo.JobId,
             StoreName = commitPointInfo.StoreName
         };
 }
 /// <summary>
 /// This will make the commit point provided the new latest commit point. Blocks until the operation is complete.
 /// </summary>
 /// <param name="storeName">Name of the store</param>
 /// <param name="commitPoint">Commit point to revert to.</param>
 public void RevertToCommitPoint(string storeName, ICommitPointInfo commitPoint)
 {
     try
     {
         _serverCore.RevertToCommitPoint(storeName, commitPoint.Id);
     }
     catch (Exception ex)
     {
         Logging.LogError(BrightstarEventId.ServerCoreException, "Error reverting to commit point {0} for store {1}", commitPoint.Id, storeName);
         throw new BrightstarClientException(
                   String.Format("Error reverting to commit point {0} for store {1}. {2}", commitPoint.Id, storeName,
                                 ex.Message), ex);
     }
 }
Beispiel #7
0
        private static void QueryCommitPoint(IBrightstarService client, ICommitPointInfo commitPointInfo)
        {
            const string sparqlQuery =
                "SELECT ?l WHERE { ?s <http://www.w3.org/2000/01/rdf-schema#label> ?l } ORDER BY ?l";
            var resultsStream = client.ExecuteQuery(commitPointInfo, sparqlQuery);
            var resultsDoc    = XDocument.Load(resultsStream);
            var labels        = new List <string>();

            foreach (var row in resultsDoc.SparqlResultRows())
            {
                labels.Add(row.GetColumnValue("l").ToString());
            }
            Console.WriteLine("Query returns: {0}", string.Join(", ", labels));
        }
 /// <summary>
 /// This will make the commit point provided the new latest commit point. Blocks until the operation is complete.
 /// </summary>
 /// <param name="storeName"></param>
 /// <param name="commitPoint"></param>
 public void RevertToCommitPoint(string storeName, ICommitPointInfo commitPoint)
 {
     ValidateStoreName(storeName);
     if (commitPoint == null)
     {
         throw new ArgumentNullException("commitPoint", Strings.BrightstarServiceClient_CommitPointMustNotBeNull);
     }
     if (!(commitPoint is CommitPointInfoWrapper))
     {
         throw new ArgumentException(Strings.BrightstarServiceClient_InvalidCommitPointInfoObject, "commitPoint");
     }
     try
     {
         _service.RevertToCommitPoint(storeName, (commitPoint as CommitPointInfoWrapper).CommitPointInfo);
     }
     catch (FaultException <ExceptionDetail> fault)
     {
         throw new BrightstarClientException(fault);
     }
 }
Beispiel #9
0
        public StoreModule(IBrightstarService brightstarService, AbstractStorePermissionsProvider storePermissionsProvider)
        {
            this.RequiresBrightstarStorePermission(storePermissionsProvider, get: StorePermissions.Read, delete: StorePermissions.Admin);

            Get["/{storeName}"] = parameters =>
            {
                if (brightstarService.DoesStoreExist(parameters["storeName"]))
                {
                    if (Request.Method.ToUpperInvariant() == "HEAD")
                    {
                        var storeName = parameters["storeName"];
                        IEnumerable <ICommitPointInfo> commitPoints = brightstarService.GetCommitPoints(storeName, 0,
                                                                                                        1);
                        ICommitPointInfo commit = commitPoints.FirstOrDefault();
                        return
                            (Negotiate.WithHeader("Last-Modified", commit.CommitTime.ToUniversalTime().ToString("r"))
                             .WithStatusCode(HttpStatusCode.OK)
                             .WithModel(new StoreResponseModel(parameters["storeName"])));
                    }
                    return(new StoreResponseModel(parameters["storeName"]));
                }
                return(HttpStatusCode.NotFound);
            };

            Delete["/{storeName}"] = parameters =>
            {
                var storeName = parameters["storeName"];
                if (brightstarService.DoesStoreExist(storeName))
                {
                    brightstarService.DeleteStore(storeName);
                }
                return(Negotiate.WithMediaRangeModel(new MediaRange("text/html"),
                                                     new StoreDeletedModel {
                    StoreName = storeName
                }));
            };
        }
 public Stream ExecuteQuery(ICommitPointInfo commitPoint, string queryExpression, IEnumerable<string> defaultGraphUris, SparqlResultsFormat resultsFormat = null)
 {
     if (commitPoint == null) throw new ArgumentNullException("commitPoint");
     if (queryExpression == null)
         throw new ArgumentNullException("queryExpression", Strings.BrightstarServiceClient_QueryMustNotBeNull);
     if (String.Empty.Equals(queryExpression))
         throw new ArgumentException(Strings.BrightstarServiceClient_QueryMustNotBeEmptyString, "queryExpression");
     try
     {
         return _service.ExecuteQueryOnCommitPoint(
             new CommitPointInfo
                 {
                     Id = commitPoint.Id,
                     StoreName = commitPoint.StoreName,
                     CommitTime = commitPoint.CommitTime,
                     JobId = commitPoint.JobId
                 },
                 queryExpression, 
                 defaultGraphUris == null ? null : defaultGraphUris.ToArray(),
                 resultsFormat == null ? SparqlResultsFormat.Xml.MediaTypes.First() + "; charset=utf-8" : resultsFormat.ToString());
     }
     catch (FaultException<ExceptionDetail> fault)
     {
         throw new BrightstarClientException(fault);
     }
 }
 /// <summary>
 /// Query a specific commit point of a store
 /// </summary>
 /// <param name="commitPoint">The commit point be queried</param>
 /// <param name="queryExpression">The SPARQL query string</param>
 /// <param name="resultsFormat">OPTIONAL: Specifies the serialization format for the SPARQL results. Defaults to <see cref="SparqlResultsFormat.Xml"/></param>
 /// <returns>A stream containing XML SPARQL results</returns>
 public Stream ExecuteQuery(ICommitPointInfo commitPoint, string queryExpression,
                            SparqlResultsFormat resultsFormat = null)
 {
     return ExecuteQuery(commitPoint, queryExpression, (IEnumerable<string>) null, resultsFormat);
 }
 /// <summary>
 /// Query a specific commit point of a store
 /// </summary>
 /// <param name="commitPoint">The commit point be queried</param>
 /// <param name="queryExpression">The SPARQL query string</param>
 /// <param name="defaultGraphUri">The URI of the default graph for the query</param>
 /// <param name="resultsFormat">OPTIONAL: Specifies the serialization format for the SPARQL results. Defaults to <see cref="SparqlResultsFormat.Xml"/></param>
 /// <returns>A stream containing XML SPARQL results</returns>
 public Stream ExecuteQuery(ICommitPointInfo commitPoint, string queryExpression,
                            string defaultGraphUri, SparqlResultsFormat resultsFormat = null)
 {
     return ExecuteQuery(commitPoint, queryExpression, new[] {defaultGraphUri}, resultsFormat);
 }
 /// <summary>
 /// This will make the commit point provided the new latest commit point. Blocks until the operation is complete.
 /// </summary>
 /// <param name="storeName">Name of the store</param>
 /// <param name="commitPoint">Commit point to revert to.</param>
 public void RevertToCommitPoint(string storeName, ICommitPointInfo commitPoint)
 {
     try
     {
         _serverCore.RevertToCommitPoint(storeName, commitPoint.Id);
     }
     catch (Exception ex)
     {
         Logging.LogError(BrightstarEventId.ServerCoreException, "Error reverting to commit point {0} for store {1}",commitPoint.Id, storeName);
         throw new BrightstarClientException(
             String.Format("Error reverting to commit point {0} for store {1}. {2}", commitPoint.Id, storeName,
                           ex.Message), ex);
     }   
 }
Beispiel #14
0
 /// <summary>
 /// Query a specific commit point of a store
 /// </summary>
 /// <param name="commitPoint">The commit point be queried</param>
 /// <param name="queryExpression">The SPARQL query string</param>
 /// <param name="resultsFormat"> </param>
 /// <returns>A stream containing XML SPARQL results</returns>
 public Stream ExecuteQuery(ICommitPointInfo commitPoint, string queryExpression, SparqlResultsFormat resultsFormat)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Query a specific commit point of a store
        /// </summary>
        /// <param name="commitPoint">The commit point be queried</param>
        /// <param name="queryExpression">The SPARQL query string</param>
        /// <param name="defaultGraphUris">An enumeration over the URIs of the graphs that will be taken together as the default graph for the query. May be NULL to use the built-in default graph</param>
        /// <param name="resultsFormat">Specifies the serialization format for the SPARQL result set returned by the query. May be NULL to indicate that an RDF graph is the expected result.</param>
        /// <param name="graphFormat">Specifies the serialization format for the RDF graph returned by the query. May be NULL to indicate that a SPARQL results set is the expected result.</param>
        /// <param name="streamFormat">Specifies the serialization format used in the returned <see cref="Stream"/>.</param>
        /// <returns>A stream containing the results of executing the query</returns>
        public Stream ExecuteQuery(ICommitPointInfo commitPoint, string queryExpression, IEnumerable<string> defaultGraphUris, 
            SparqlResultsFormat resultsFormat, RdfFormat graphFormat, out ISerializationFormat streamFormat)
        {
            if (queryExpression == null) throw new ArgumentNullException("queryExpression");
            if (resultsFormat == null) resultsFormat = SparqlResultsFormat.Xml;
            if (graphFormat == null) graphFormat = RdfFormat.RdfXml;

            try
            {
                var pStream = new MemoryStream();
                streamFormat = _serverCore.Query(commitPoint.StoreName, commitPoint.Id, queryExpression, defaultGraphUris, resultsFormat, graphFormat, pStream);
                return new MemoryStream(pStream.ToArray());
            }
#if !PORTABLE && !WINDOWS_PHONE
            catch (AggregateException aggregateException)
            {
                Logging.LogError(BrightstarEventId.ServerCoreException,
                                 "Error querying store {0}@{1} with expression {2}", commitPoint.StoreName,
                                 commitPoint.Id, queryExpression);
                if (aggregateException.InnerExceptions.Count == 1)
                {
                    throw new BrightstarClientException(
                        String.Format("Error querying store {0}@{1} with expression {2}. {3}",
                                      commitPoint.StoreName, commitPoint.Id, queryExpression,
                                      aggregateException.InnerExceptions[0].Message));
                }
                var messages = String.Join("; ", aggregateException.InnerExceptions.Select(ex => ex.Message));
                throw new BrightstarClientException(
                    String.Format(
                        "Error querying store {0}@{1} with expression {2}. Multiple errors occurred: {3}",
                        commitPoint.StoreName, commitPoint.Id, queryExpression, messages));
            }
#endif
            catch (Exception ex)
            {
                Logging.LogError(BrightstarEventId.ServerCoreException,
                                 "Error querying store {0}@{1} with expression {2}", commitPoint.StoreName,
                                 commitPoint.Id, queryExpression);
                throw new BrightstarClientException(
                    String.Format("Error querying store {0}@{1} with expression {2}. {3}", commitPoint.StoreName,
                                  commitPoint.Id, queryExpression, ex.Message), ex);
            }
        }
 /// <summary>
 /// Queues a job to create a snapshot of a store
 /// </summary>
 /// <param name="storeName">The name of the store to take a snapshot of</param>
 /// <param name="targetStoreName">The name of the store to be created to receive the snapshot</param>
 /// <param name="persistenceType">The type of persistence to use for the target store</param>
 /// <param name="sourceCommitPoint">OPTIONAL: the commit point in the source store to take a snapshot from</param>
 /// <param name="label">Optional user-friendly label for the job.</param>
 /// <returns>A <see cref="IJobInfo"/> instance for tracking the current status of the job.</returns>
 public IJobInfo CreateSnapshot(string storeName, string targetStoreName,
                                PersistenceType persistenceType,
                                ICommitPointInfo sourceCommitPoint = null,
     string label = null)
 {
     try
     {
         var jobId = _serverCore.CreateSnapshot(storeName, targetStoreName,
                                                persistenceType,
                                                sourceCommitPoint == null
                                                    ? StoreConstants.NullUlong
                                                    : sourceCommitPoint.Id,
                                                label);
         return GetJobInfo(storeName, jobId.ToString());
     }
     catch (Exception ex)
     {
         Logging.LogError(BrightstarEventId.ServerCoreException, "Error queuing snapshot job for store {0}",
                          storeName);
         throw new BrightstarClientException(
             "Error queuing snapshot job for store " + storeName + ". " + ex.Message, ex);
     }
 }
 public QueryParams(ICommitPointInfo commitPoint, string queryExpression, SparqlResultsFormat resultsFormat, Stream outputStream)
 {
     StoreName = commitPoint.StoreName;
     CommitPointId = commitPoint.Id;
     WithCommitPoint = true;
     QueryExpression = queryExpression;
     OutputStream = outputStream;
     ResultsFormat = resultsFormat ?? SparqlResultsFormat.Xml;
     DefaultGraphUris = null;
 }
 /// <summary>
 /// Query a specific commit point of a store
 /// </summary>
 /// <param name="commitPoint">The commit point be queried</param>
 /// <param name="queryExpression">The SPARQL query string</param>
 /// <param name="defaultGraphUris">OPTIONAL: An enumeration over the URIs of the graphs that will be taken together as the default graph for the query. May be NULL to use the built-in default graph</param>
 /// <param name="resultsFormat">OPTIONAL: Specifies the serialization format for the SPARQL results. Defaults to <see cref="SparqlResultsFormat.Xml"/></param>
 /// <param name="graphFormat">OPTIONAL: Specifies the serialization format for RDF graph results. Defaults to <see cref="RdfFormat.RdfXml"/></param>
 /// <returns>A stream containing XML SPARQL results</returns>
 public Stream ExecuteQuery(ICommitPointInfo commitPoint, string queryExpression,
                            IEnumerable<string> defaultGraphUris,
                            SparqlResultsFormat resultsFormat = null, RdfFormat graphFormat = null)
 {
     ISerializationFormat streamFormat;
     return ExecuteQuery(commitPoint, queryExpression, defaultGraphUris,
                         resultsFormat ?? SparqlResultsFormat.Xml, graphFormat ?? RdfFormat.RdfXml,
                         out streamFormat);
 }
 /// <summary>
 /// This will make the commit point provided the new latest commit point. Blocks until the operation is complete.
 /// </summary>
 /// <param name="storeName">The name of the store to be reverted</param>
 /// <param name="commitPoint">The commit point to revert to</param>
 public void RevertToCommitPoint(string storeName, ICommitPointInfo commitPoint)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Query a specific commit point of a store
        /// </summary>
        /// <param name="commitPoint">The commit point be queried</param>
        /// <param name="queryExpression">The SPARQL query string</param>
        /// <param name="defaultGraphUris">An enumeration over the URIs of the graphs that will be taken together as the default graph for the query</param>
        /// <param name="resultsFormat">OPTIONAL: Specifies the serialization format for the SPARQL results. Defaults to <see cref="SparqlResultsFormat.Xml"/></param>
        /// <returns>A stream containing XML SPARQL results</returns>
        public Stream ExecuteQuery(ICommitPointInfo commitPoint, string queryExpression, IEnumerable<string> defaultGraphUris, SparqlResultsFormat resultsFormat = null)
        {
            if (queryExpression == null) throw new ArgumentNullException("queryExpression");
            if (resultsFormat == null) resultsFormat = SparqlResultsFormat.Xml;

            try
            {
                var pStream = new MemoryStream();
#if SILVERLIGHT
                var t = new Thread(ExecuteQuery);
                t.Start(new QueryParams(commitPoint, queryExpression, resultsFormat, pStream));
                t.Join();
#else
                var t =
                    new Task(() => _serverCore.Query(commitPoint.StoreName, commitPoint.Id, queryExpression, defaultGraphUris, resultsFormat, pStream));
                t.Start();
                t.Wait();
                if (t.IsFaulted && t.Exception != null)
                {
                    throw t.Exception;
                }
#endif
                pStream.Seek(0, SeekOrigin.Begin);
                return pStream;
            }
            catch (AggregateException aggregateException)
            {
                Logging.LogError(BrightstarEventId.ServerCoreException,
                                 "Error querying store {0}@{1} with expression {2}", commitPoint.StoreName,
                                 commitPoint.Id, queryExpression);
                if (aggregateException.InnerExceptions.Count == 1)
                {
                    throw new BrightstarClientException(
                        String.Format("Error querying store {0}@{1} with expression {2}. {3}",
                                      commitPoint.StoreName, commitPoint.Id, queryExpression,
                                      aggregateException.InnerExceptions[0].Message));
                }
                var messages = String.Join("; ", aggregateException.InnerExceptions.Select(ex => ex.Message));
                throw new BrightstarClientException(
                    String.Format(
                        "Error querying store {0}@{1} with expression {2}. Multiple errors occurred: {3}",
                        commitPoint.StoreName, commitPoint.Id, queryExpression, messages));
            }
            catch (Exception ex)
            {
                Logging.LogError(BrightstarEventId.ServerCoreException,
                                 "Error querying store {0}@{1} with expression {2}", commitPoint.StoreName,
                                 commitPoint.Id, queryExpression);
                throw new BrightstarClientException(
                    String.Format("Error querying store {0}@{1} with expression {2}. {3}", commitPoint.StoreName,
                                  commitPoint.Id, queryExpression, ex.Message), ex);
            }
        }
Beispiel #21
0
 /// <summary>
 /// Query a specific commit point of a store
 /// </summary>
 /// <param name="commitPoint">The commit point be queried</param>
 /// <param name="queryExpression">The SPARQL query string</param>
 /// <returns>A stream containing XML SPARQL results</returns>
 public Stream ExecuteQuery(ICommitPointInfo commitPoint, string queryExpression)
 {
     throw new NotImplementedException();
 }
 public IJobInfo CreateSnapshot(string storeName, string targetStoreName, PersistenceType persistenceType,
                                ICommitPointInfo sourceCommitPoint = null)
 {
     ValidateStoreName(storeName);
     ValidateStoreName(targetStoreName);
     try
     {
         if (sourceCommitPoint == null)
         {
             return new JobInfoWrapper(_service.CreateSnapshot(storeName, targetStoreName, persistenceType, null));
         }
         return
             new JobInfoWrapper(_service.CreateSnapshot(storeName, targetStoreName, persistenceType,
                                                        new CommitPointInfo
                                                            {
                                                                Id = sourceCommitPoint.Id,
                                                                StoreName = sourceCommitPoint.StoreName,
                                                                CommitTime = sourceCommitPoint.CommitTime,
                                                                JobId = sourceCommitPoint.JobId
                                                            }));
     }
     catch (FaultException<ExceptionDetail> fault)
     {
         throw new BrightstarClientException(fault);
     }
 }
Beispiel #23
0
 private static void QueryCommitPoint(IBrightstarService client, ICommitPointInfo commitPointInfo)
 {
     const string sparqlQuery =
         "SELECT ?l WHERE { ?s <http://www.w3.org/2000/01/rdf-schema#label> ?l } ORDER BY ?l";
     var resultsStream = client.ExecuteQuery(commitPointInfo, sparqlQuery);
     var resultsDoc = XDocument.Load(resultsStream);
     var labels = new List<string>();
     foreach(var row in resultsDoc.SparqlResultRows())
     {
         labels.Add(row.GetColumnValue("l").ToString());
     }
     Console.WriteLine("Query returns: {0}", string.Join(", ",labels));
 }
 public CommitPointViewModel(ICommitPointInfo commitPointInfo)
 {
     CommitTime = commitPointInfo.CommitTime;
     Id = commitPointInfo.Id;
     JobId = commitPointInfo.JobId;
 }
Beispiel #25
0
        public JobsModule(IBrightstarService brightstarService, AbstractStorePermissionsProvider permissionsProvider)
        {
            this.RequiresBrightstarStorePermissionData(permissionsProvider);

            Get["/{storeName}/jobs"] = parameters =>
            {
                var jobsRequestObject = this.Bind <JobsRequestModel>();
                if (jobsRequestObject == null || jobsRequestObject.StoreName == null)
                {
                    return(HttpStatusCode.BadRequest);
                }
                if (jobsRequestObject.Take <= 0)
                {
                    jobsRequestObject.Take = DefaultPageSize;
                }
                var jobs = brightstarService.GetJobInfo(jobsRequestObject.StoreName, jobsRequestObject.Skip,
                                                        jobsRequestObject.Take + 1);
                return(Negotiate.WithPagedList(jobsRequestObject,
                                               jobs.Select(j => j.MakeResponseObject(jobsRequestObject.StoreName)),
                                               jobsRequestObject.Skip, jobsRequestObject.Take, DefaultPageSize,
                                               "jobs"));
            };

            Get["/{storeName}/jobs/{jobId}"] = parameters =>
            {
                var request = this.Bind <JobRequestModel>();
                if (request == null ||
                    request.StoreName == null ||
                    request.JobId == null)
                {
                    return(HttpStatusCode.BadRequest);
                }
                var job = brightstarService.GetJobInfo(request.StoreName, request.JobId);
                if (job == null)
                {
                    return(HttpStatusCode.NotFound);
                }
                var responseDto = job.MakeResponseObject(request.StoreName);
                return(responseDto);
            };

            Post["/{storeName}/jobs"] = parameters =>
            {
                var jobRequestObject = this.Bind <JobRequestObject>();

                // Validate
                if (jobRequestObject == null)
                {
                    return(HttpStatusCode.BadRequest);
                }
                if (String.IsNullOrWhiteSpace(jobRequestObject.JobType))
                {
                    return(HttpStatusCode.BadRequest);
                }

                var storeName = parameters["storeName"];
                var label     = jobRequestObject.Label;
                try
                {
                    IJobInfo queuedJobInfo;
                    switch (jobRequestObject.JobType.ToLowerInvariant())
                    {
                    case "consolidate":
                        AssertPermission(StorePermissions.Admin);
                        queuedJobInfo = brightstarService.ConsolidateStore(storeName, label);
                        break;

                    case "createsnapshot":
                        AssertPermission(StorePermissions.Admin);
                        PersistenceType persistenceType;

                        // Validate TargetStoreName and PersistenceType parameters
                        if (!jobRequestObject.JobParameters.ContainsKey("TargetStoreName") ||
                            String.IsNullOrWhiteSpace(jobRequestObject.JobParameters["TargetStoreName"]) ||
                            !jobRequestObject.JobParameters.ContainsKey("PersistenceType") ||
                            !Enum.TryParse(jobRequestObject.JobParameters["PersistenceType"],
                                           out persistenceType))
                        {
                            return(HttpStatusCode.BadRequest);
                        }
                        // Extract optional commit point parameter
                        ICommitPointInfo commitPoint = null;
                        if (jobRequestObject.JobParameters.ContainsKey("CommitId"))
                        {
                            ulong commitId;
                            if (!UInt64.TryParse(jobRequestObject.JobParameters["CommitId"], out commitId))
                            {
                                return(HttpStatusCode.BadRequest);
                            }
                            commitPoint = brightstarService.GetCommitPoint(storeName, commitId);
                            if (commitPoint == null)
                            {
                                return(HttpStatusCode.BadRequest);
                            }
                        }

                        // Execute
                        queuedJobInfo = brightstarService.CreateSnapshot(
                            storeName, jobRequestObject.JobParameters["TargetStoreName"],
                            persistenceType, commitPoint, label);
                        break;

                    case "export":
                        AssertPermission(StorePermissions.Export);
                        if (!jobRequestObject.JobParameters.ContainsKey("FileName") ||
                            String.IsNullOrWhiteSpace(jobRequestObject.JobParameters["FileName"]))
                        {
                            return(HttpStatusCode.BadRequest);
                        }
                        RdfFormat format = jobRequestObject.JobParameters.ContainsKey("Format")
                                                       ? RdfFormat.GetResultsFormat(
                            jobRequestObject.JobParameters["Format"])
                                                       : RdfFormat.NQuads;

                        queuedJobInfo = brightstarService.StartExport(
                            storeName,
                            jobRequestObject.JobParameters["FileName"],
                            jobRequestObject.JobParameters.ContainsKey("GraphUri") ? jobRequestObject.JobParameters["GraphUri"] : null,
                            format,
                            label);
                        break;

                    case "import":
                        AssertPermission(StorePermissions.TransactionUpdate);
                        if (!jobRequestObject.JobParameters.ContainsKey("FileName") ||
                            String.IsNullOrWhiteSpace(jobRequestObject.JobParameters["FileName"]))
                        {
                            return(HttpStatusCode.BadRequest);
                        }
                        queuedJobInfo = brightstarService.StartImport(
                            storeName,
                            jobRequestObject.JobParameters["FileName"],
                            jobRequestObject.JobParameters.ContainsKey("DefaultGraphUri") ? jobRequestObject.JobParameters["DefaultGraphUri"] : Constants.DefaultGraphUri,
                            label);
                        break;

                    case "repeattransaction":
                        AssertPermission(StorePermissions.Admin);
                        if (!jobRequestObject.JobParameters.ContainsKey("JobId") ||
                            String.IsNullOrWhiteSpace(jobRequestObject.JobParameters["JobId"]))
                        {
                            return(HttpStatusCode.BadRequest);
                        }
                        Guid jobId;
                        if (!Guid.TryParse(jobRequestObject.JobParameters["JobId"], out jobId))
                        {
                            return(HttpStatusCode.BadRequest);
                        }
                        var transaction = brightstarService.GetTransaction(storeName, jobId);
                        if (transaction == null)
                        {
                            return(HttpStatusCode.BadRequest);
                        }
                        queuedJobInfo = brightstarService.ReExecuteTransaction(storeName, transaction, label);
                        break;

                    case "sparqlupdate":
                        AssertPermission(StorePermissions.SparqlUpdate);
                        if (!jobRequestObject.JobParameters.ContainsKey("UpdateExpression") ||
                            String.IsNullOrWhiteSpace(jobRequestObject.JobParameters["UpdateExpression"]))
                        {
                            return(HttpStatusCode.BadRequest);
                        }
                        queuedJobInfo = brightstarService.ExecuteUpdate(
                            storeName,
                            jobRequestObject.JobParameters["UpdateExpression"],
                            false,
                            label);
                        break;

                    case "transaction":
                        AssertPermission(StorePermissions.TransactionUpdate);
                        var preconditions = jobRequestObject.JobParameters.ContainsKey("Preconditions")
                                                        ? jobRequestObject.JobParameters["Preconditions"]
                                                        : null;
                        var nonexistence =
                            jobRequestObject.JobParameters.ContainsKey("NonexistencePreconditions")
                                        ? jobRequestObject.JobParameters["NonexistencePreconditions"]
                                        : null;
                        var deletePatterns = jobRequestObject.JobParameters.ContainsKey("Deletes")
                                                         ? jobRequestObject.JobParameters["Deletes"]
                                                         : null;
                        var insertTriples = jobRequestObject.JobParameters.ContainsKey("Inserts")
                                                        ? jobRequestObject.JobParameters["Inserts"]
                                                        : null;
                        var defaultGraphUri =
                            jobRequestObject.JobParameters.ContainsKey("DefaultGraphUri") &&
                            !String.IsNullOrEmpty(jobRequestObject.JobParameters["DefaultGraphUri"])
                                        ? jobRequestObject.JobParameters["DefaultGraphUri"]
                                        : null;

                        queuedJobInfo = brightstarService.ExecuteTransaction(
                            storeName, new UpdateTransactionData
                        {
                            ExistencePreconditions    = preconditions,
                            NonexistencePreconditions = nonexistence,
                            DeletePatterns            = deletePatterns,
                            InsertData      = insertTriples,
                            DefaultGraphUri = defaultGraphUri
                        },
                            false,
                            label);
                        break;

                    case "updatestats":
                        AssertPermission(StorePermissions.Admin);
                        queuedJobInfo = brightstarService.UpdateStatistics(storeName, label);
                        break;

                    default:
                        return(HttpStatusCode.BadRequest);
                    }

                    var jobUri = (string)storeName + "/jobs/" + queuedJobInfo.JobId;
                    return(Negotiate.WithModel(new JobResponseModel
                    {
                        JobId = queuedJobInfo.JobId,
                        Label = queuedJobInfo.Label,
                        StatusMessage = queuedJobInfo.StatusMessage,
                        JobStatus = queuedJobInfo.GetJobStatusString(),
                        ExceptionInfo = queuedJobInfo.ExceptionInfo,
                        QueuedTime = queuedJobInfo.QueuedTime,
                        StartTime = queuedJobInfo.StartTime,
                        EndTime = queuedJobInfo.EndTime
                    })
                           .WithHeader("Location", jobUri)
                           .WithStatusCode(HttpStatusCode.Created));
                }
                catch (UnauthorizedAccessException)
                {
                    return(HttpStatusCode.Unauthorized);
                }
            };
        }
 /// <summary>
 /// This will make the commit point provided the new latest commit point. Blocks until the operation is complete.
 /// </summary>
 /// <param name="storeName"></param>
 /// <param name="commitPoint"></param>
 public void RevertToCommitPoint(string storeName, ICommitPointInfo commitPoint)
 {
     ValidateStoreName(storeName);
     if (commitPoint == null) throw new ArgumentNullException("commitPoint", Strings.BrightstarServiceClient_CommitPointMustNotBeNull);
     if (!(commitPoint is CommitPointInfoWrapper)) throw new ArgumentException(Strings.BrightstarServiceClient_InvalidCommitPointInfoObject, "commitPoint");
     try
     {
         _service.RevertToCommitPoint(storeName, (commitPoint as CommitPointInfoWrapper).CommitPointInfo);
     }
     catch (FaultException<ExceptionDetail> fault)
     {
         throw new BrightstarClientException(fault);
     }
 }
 public CommitPointViewModel(ICommitPointInfo commitPointInfo)
 {
     CommitTime = commitPointInfo.CommitTime;
     Id         = commitPointInfo.Id;
     JobId      = commitPointInfo.JobId;
 }
Beispiel #28
0
 /// <summary>
 /// This will make the commit point provided the new latest commit point. Blocks until the operation is complete.
 /// </summary>
 /// <param name="storeName">The name of the store to be reverted</param>
 /// <param name="commitPoint">The commit point to revert to</param>
 public void RevertToCommitPoint(string storeName, ICommitPointInfo commitPoint)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Query a specific commit point of a store
 /// </summary>
 /// <param name="commitPoint">The commit point be queried</param>
 /// <param name="queryExpression">The SPARQL query string</param>
 /// <returns>A stream containing XML SPARQL results</returns>
 public Stream ExecuteQuery(ICommitPointInfo commitPoint, string queryExpression)
 {
     throw new NotImplementedException();
 }