Exemplo n.º 1
0
        // format: serviceId="myapp~app1~svc1" for fabric:/myapp/app1/svc1
        private static void HandleServicesEvents(IResultWriter writer, string serviceId, QueryParametersWrapper queryParameters)
        {
            if (!ValidateStartAndEndTime(queryParameters.StartTimeUtc, queryParameters.EndTimeUtc))
            {
                OnUnsupportedUri(writer);
                return;
            }

            if (!string.IsNullOrWhiteSpace(serviceId))
            {
                serviceId = ConvertServiceIdToFullUri(serviceId);
            }

            var queryTracker = QueryStatTracker.CreateAndMarkQueryStart(ReaderConstants.Services, serviceId, queryParameters);
            var events       = new EventStoreReader()
                               .GetServiceEventsAsync(
                serviceId,
                new Duration(
                    queryParameters.StartTimeUtc,
                    queryParameters.EndTimeUtc),
                ConvertUserEventTypesToUnderlyingTypes(
                    EntityType.Service,
                    queryParameters.EventsTypesFilter),
                CancellationToken.None)
                               .GetAwaiter()
                               .GetResult()
                               .ToArray();

            queryTracker.MarkQueryEnd(events.Count());

            writer.Write(new JsonSerializerHelper().SerializeObject(events.Take(MaxRecordsInResult).OrderBy(item => item.TimeStamp)));
        }
Exemplo n.º 2
0
        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)));
        }
Exemplo n.º 3
0
        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)));
        }
Exemplo n.º 4
0
        // 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)));
        }