コード例 #1
0
ファイル: RequestRouter.cs プロジェクト: zmyer/service-fabric
        private static void HandleNodesEvents(IResultWriter writer, string nodeName, QueryParametersWrapper queryParameters)
        {
            if (!ValidateStartAndEndTime(queryParameters.StartTimeUtc, queryParameters.EndTimeUtc))
            {
                OnUnsupportedUri(writer);
                return;
            }

            var queryTracker = QueryStatTracker.CreateAndMarkQueryStart(ReaderConstants.Nodes, nodeName, queryParameters);
            var events       = new EventStoreReader()
                               .GetNodeEventsAsync(
                nodeName,
                new Duration(
                    queryParameters.StartTimeUtc,
                    queryParameters.EndTimeUtc),
                ConvertUserEventTypesToUnderlyingTypes(
                    EntityType.Node,
                    queryParameters.EventsTypesFilter),
                CancellationToken.None)
                               .GetAwaiter()
                               .GetResult()
                               .ToArray();

            queryTracker.MarkQueryEnd(events.Count());

            writer.Write(new JsonSerializerHelper().SerializeObject(events.Take(MaxRecordsInResult).OrderBy(item => item.TimeStamp)));
        }
コード例 #2
0
        private QueryStatTracker(string typeEntity, string identifier, QueryParametersWrapper queryParams)
        {
            Assert.IsNotNull(typeEntity, "typeEntity != null");
            Assert.IsNotNull(queryParams, "queryParams != null");

            this.entityType        = typeEntity;
            this.queryParamWrapper = queryParams;

            this.isIdentifierPresent = false;
            if (!string.IsNullOrEmpty(identifier))
            {
                this.isIdentifierPresent = true;
            }

            if (queryParams.EventsTypesFilter == null || !queryParams.EventsTypesFilter.Any())
            {
                this.eventTypeFilters = "Null";
            }
            else
            {
                this.eventTypeFilters = string.Join(",", queryParams.EventsTypesFilter);
            }

            this.startTime = DateTime.UtcNow;
        }
コード例 #3
0
ファイル: RequestRouter.cs プロジェクト: zmyer/service-fabric
        private static void HandleContainersEvents(IResultWriter writer, QueryParametersWrapper queryParameters)
        {
            if (!ValidateStartAndEndTime(queryParameters.StartTimeUtc, queryParameters.EndTimeUtc))
            {
                OnUnsupportedUri(writer);
                return;
            }

            throw new EventStoreException(ErrorCodes.EntityTypeNotSupported, "Container Type not supported currently");
        }
コード例 #4
0
ファイル: RequestRouter.cs プロジェクト: zmyer/service-fabric
        private static void HandleClusterEvents(IResultWriter writer, QueryParametersWrapper queryParameters)
        {
            if (!ValidateStartAndEndTime(queryParameters.StartTimeUtc, queryParameters.EndTimeUtc))
            {
                OnUnsupportedUri(writer);
                return;
            }

            var events = new EventStoreReader()
                         .GetClusterEventsAsync(
                new Duration(
                    queryParameters.StartTimeUtc,
                    queryParameters.EndTimeUtc),
                ConvertUserEventTypesToUnderlyingTypes(
                    EntityType.Cluster,
                    queryParameters.EventsTypesFilter),
                CancellationToken.None)
                         .GetAwaiter()
                         .GetResult()
                         .ToArray();

            writer.Write(new JsonSerializerHelper().SerializeObject(events.Take(MaxRecordsInResult).OrderBy(item => item.TimeStamp)));
        }
コード例 #5
0
ファイル: RequestRouter.cs プロジェクト: zmyer/service-fabric
        private static void HandleCorrelatedEvents(IResultWriter writer, string eventInstanceId, QueryParametersWrapper queryParameters)
        {
            if (string.IsNullOrWhiteSpace(eventInstanceId))
            {
                EventStoreLogger.Logger.LogWarning("HandleCorrelatedEvents:: Event Instance id in param is empty/null");
                OnUnsupportedUri(writer);
                return;
            }

            var eventInstanceGuid = Guid.Empty;

            if (!Guid.TryParse(eventInstanceId, out eventInstanceGuid))
            {
                EventStoreLogger.Logger.LogWarning("HandleCorrelatedEvents:: EventInstance ID : {0} Is not a valid Guid", eventInstanceId);
                OnUnsupportedUri(writer);
                return;
            }

            if (eventInstanceGuid == Guid.Empty)
            {
                EventStoreLogger.Logger.LogWarning("HandleCorrelatedEvents:: Empty Guid for Event Instance Id");
                OnUnsupportedUri(writer);
                return;
            }

            var duration     = new Duration(DateTime.UtcNow - TimeSpan.FromDays(MaxDurationForCorrelationLookupInDays), DateTime.UtcNow);
            var queryTracker = QueryStatTracker.CreateAndMarkQueryStart(ReaderConstants.CorrelatedEvents, eventInstanceId, queryParameters);
            var events       = new EventStoreReader()
                               .GetCorrelatedEvents(
                eventInstanceGuid,
                duration,
                CancellationToken.None)
                               .GetAwaiter()
                               .GetResult()
                               .ToArray();

            queryTracker.MarkQueryEnd(events.Count());

            writer.Write(new JsonSerializerHelper().SerializeObject(events.Take(MaxRecordsInResult).OrderBy(item => item.TimeStamp)));
        }
コード例 #6
0
ファイル: RequestRouter.cs プロジェクト: zmyer/service-fabric
        // partitionId will always have a value here.
        private static void HandleReplicasEvents(IResultWriter writer, string partitionIdString, string replicaIdString, QueryParametersWrapper queryParameters)
        {
            if (!ValidateStartAndEndTime(queryParameters.StartTimeUtc, queryParameters.EndTimeUtc))
            {
                OnUnsupportedUri(writer);
                return;
            }

            var partitionGuid = Guid.Empty;

            if (!string.IsNullOrWhiteSpace(partitionIdString))
            {
                if (!Guid.TryParse(partitionIdString, out partitionGuid))
                {
                    EventStoreLogger.Logger.LogWarning("HandleReplicaEvents:: Partition ID : {0} Is not a valid Guid", partitionIdString);
                    OnUnsupportedUri(writer);
                    return;
                }
            }

            // For replica events, Partition ID needs to be valid. So, verify that we have a valid ID Now.
            if (partitionGuid == Guid.Empty)
            {
                EventStoreLogger.Logger.LogWarning("HandleReplicaEvents:: Partition Guid Not Valid", string.IsNullOrEmpty(partitionIdString) ? "Empty" : partitionIdString);
                OnUnsupportedUri(writer);
                return;
            }

            long?replicaId = null;

            if (!string.IsNullOrWhiteSpace(replicaIdString))
            {
                long id = 0;
                if (!long.TryParse(replicaIdString, out id))
                {
                    EventStoreLogger.Logger.LogWarning("HandleReplicaEvents:: ReplicaId : {0} Is Invalid", replicaIdString);
                    OnUnsupportedUri(writer);
                    return;
                }

                replicaId = id;
            }

            var queryTracker = QueryStatTracker.CreateAndMarkQueryStart(ReaderConstants.Replicas, string.Format("{0}:{1}", partitionGuid, replicaId), queryParameters);
            var events       = new EventStoreReader()
                               .GetReplicaEventsAsync(
                partitionGuid,
                replicaId,
                new Duration(
                    queryParameters.StartTimeUtc,
                    queryParameters.EndTimeUtc),
                ConvertUserEventTypesToUnderlyingTypes(
                    EntityType.Replica,
                    queryParameters.EventsTypesFilter),
                CancellationToken.None)
                               .GetAwaiter()
                               .GetResult()
                               .ToArray();

            queryTracker.MarkQueryEnd(events.Count());

            writer.Write(new JsonSerializerHelper().SerializeObject(events.Take(MaxRecordsInResult).OrderBy(item => item.TimeStamp)));
        }
コード例 #7
0
ファイル: RequestRouter.cs プロジェクト: zmyer/service-fabric
        public static void RouteUri(ParsedUri uri, IResultWriter writer)
        {
            if (uri.BaseCollection == null ||
                !uri.BaseCollection.Equals(ReaderConstants.EventsStoreBaseCollection, StringComparison.OrdinalIgnoreCase) ||
                uri.PathCollections.Count < 1 ||
                uri.RequestCollectionOrMethod == null ||
                !uri.RequestCollectionOrMethod.Equals(ReaderConstants.EventsCollection, StringComparison.OrdinalIgnoreCase))
            {
                OnUnsupportedUri(writer);
                return;
            }

            var queryParamsWrapper = new QueryParametersWrapper(uri.QueryParameters);

            if (!CheckApiVersion(queryParamsWrapper.APIVersion))
            {
                OnUnsupportedUri(writer);
                return;
            }

            if (uri.PathCollections.Count == 1)
            {
                var collection = uri.PathCollections[0];
                switch (collection.Name.ToLower())
                {
                case ReaderConstants.Cluster:
                    if (collection.HasKeySet())
                    {
                        OnUnsupportedUri(writer);
                        return;
                    }
                    HandleClusterEvents(writer, queryParamsWrapper);
                    break;

                case ReaderConstants.Containers:
                    if (collection.HasKeySet())
                    {
                        OnUnsupportedUri(writer);
                        return;
                    }
                    HandleContainersEvents(writer, queryParamsWrapper);
                    break;

                case ReaderConstants.Nodes:
                    HandleNodesEvents(writer, collection.GetValueOfCollectionKey(), queryParamsWrapper);
                    break;

                case ReaderConstants.Applications:
                    HandleApplicationsEvents(writer, collection.GetValueOfCollectionKey(), queryParamsWrapper);
                    break;

                case ReaderConstants.Services:
                    HandleServicesEvents(writer, collection.GetValueOfCollectionKey(), queryParamsWrapper);
                    break;

                case ReaderConstants.Partitions:
                    HandlePartitionsEvents(writer, collection.GetValueOfCollectionKey(), queryParamsWrapper);
                    break;

                case ReaderConstants.CorrelatedEvents:
                    HandleCorrelatedEvents(writer, collection.GetValueOfCollectionKey(), queryParamsWrapper);
                    break;

                default:
                    OnUnsupportedUri(writer);
                    break;
                }
            }
            else if (uri.PathCollections.Count == 2)
            {
                var collection    = uri.PathCollections[0];
                var subCollection = uri.PathCollections[1];

                if (!collection.HasKeySet())
                {
                    OnUnsupportedUri(writer);
                    return;
                }

                var composedName = string.Concat(collection.Name.ToLower(), ":", subCollection.Name.ToLower());
                switch (composedName)
                {
                case ReaderConstants.PartitionsReplicas:
                    HandleReplicasEvents(writer, collection.GetValueOfCollectionKey(), subCollection.GetValueOfCollectionKey(), queryParamsWrapper);
                    break;

                default:
                    OnUnsupportedUri(writer);
                    break;
                }
            }
            else
            {
                OnUnsupportedUri(writer);
            }
        }
コード例 #8
0
ファイル: RequestRouter.cs プロジェクト: zmyer/service-fabric
        private static void HandlePartitionsEvents(IResultWriter writer, string partitionIdString, QueryParametersWrapper queryParameters)
        {
            if (!ValidateStartAndEndTime(queryParameters.StartTimeUtc, queryParameters.EndTimeUtc))
            {
                OnUnsupportedUri(writer);
                return;
            }

            var partitionGuid = Guid.Empty;

            if (!string.IsNullOrWhiteSpace(partitionIdString))
            {
                if (!Guid.TryParse(partitionIdString, out partitionGuid))
                {
                    EventStoreLogger.Logger.LogWarning("HandlePartitionsEvents:: Partition ID : {0} Is not a valid Guid", partitionIdString);
                    OnUnsupportedUri(writer);
                    return;
                }
            }

            var queryTracker = QueryStatTracker.CreateAndMarkQueryStart(ReaderConstants.Partitions, partitionIdString, queryParameters);
            var events       = new EventStoreReader()
                               .GetPartitionEventsAsync(
                partitionGuid,
                new Duration(
                    queryParameters.StartTimeUtc,
                    queryParameters.EndTimeUtc),
                ConvertUserEventTypesToUnderlyingTypes(
                    EntityType.Partition,
                    queryParameters.EventsTypesFilter),
                CancellationToken.None)
                               .GetAwaiter()
                               .GetResult()
                               .ToArray();

            queryTracker.MarkQueryEnd(events.Count());

            writer.Write(new JsonSerializerHelper().SerializeObject(events.Take(MaxRecordsInResult).OrderBy(item => item.TimeStamp)));
        }
コード例 #9
0
 // Mark Query Start
 public static QueryStatTracker CreateAndMarkQueryStart(string typeEntity, string identifier, QueryParametersWrapper queryParams)
 {
     return(new QueryStatTracker(typeEntity, identifier, queryParams));
 }