public ProjectionsStatisticsHttpFormatted(
     ProjectionManagementMessage.Statistics source, Func<string, string> makeAbsouteUrl)
 {
     _projections =
         source.Projections.Select(v => new ProjectionStatisticsHttpFormatted(v, makeAbsouteUrl)).ToArray();
     _transactionFileHeadPosition = source.TransactionFileHeadPosition;
 }
 public Definition(
     string name, string handlerType, string query, SlaveProjectionRequestedNumber requestedNumber,
     ProjectionMode mode, bool emitEnabled, bool checkpointsEnabled, bool enableRunAs,
     ProjectionManagementMessage.RunAs runAs)
 {
     _name = name;
     _handlerType = handlerType;
     _query = query;
     _requestedNumber = requestedNumber;
     _runAs = runAs;
     _enableRunAs = enableRunAs;
     _checkpointsEnabled = checkpointsEnabled;
     _emitEnabled = emitEnabled;
     _mode = mode;
 }
Пример #3
0
 public void Handle(ProjectionManagementMessage.Command.Abort message)
 {
     _lastAccessed = _timeProvider.Now;
     UpdateProjectionVersion();
     SetLastReplyEnvelope(message.Envelope);
     Disable();
     Abort();
 }
Пример #4
0
 private void DoDisable(ProjectionManagementMessage.Disable message)
 {
     if (!Enabled)
     {
         message.Envelope.ReplyWith(new ProjectionManagementMessage.OperationFailed("Not enabled"));
         return;
     }
     Disable();
     PrepareAndBeginWrite(
         forcePrepare: false,
         completed: () => message.Envelope.ReplyWith(new ProjectionManagementMessage.Updated(message.Name)));
 }
Пример #5
0
 public void InitializeNew(ProjectionManagementMessage.Post message, Action completed)
 {
     LoadPersistedState(
         new PersistedState
             {
                 Enabled = message.Enabled,
                 HandlerType = message.HandlerType,
                 Query = message.Query,
                 Mode = message.Mode
             });
     PrepareAndBeginWrite(forcePrepare: true, completed: () => StartNew(completed));
 }
Пример #6
0
 public void Handle(ProjectionManagementMessage.Enable message)
 {
     if (Enabled)
     {
         message.Envelope.ReplyWith(new ProjectionManagementMessage.OperationFailed("Not disabled"));
         return;
     }
     Enable();
     PrepareAndBeginWrite(
         forcePrepare: true,
         completed:
             () =>
             Start(
                 () => message.Envelope.ReplyWith(new ProjectionManagementMessage.Updated(message.Name))));
 }
Пример #7
0
 public void Handle(ProjectionManagementMessage.GetState message)
 {
     if (_state == ManagedProjectionState.Running)
     {
         var needRequest = false;
         if (_stateRequests == null)
         {
             _stateRequests = new Dictionary<string, List<IEnvelope>>();
         }
         List<IEnvelope> partitionRequests;
         if (!_stateRequests.TryGetValue(message.Partition, out partitionRequests))
         {
             partitionRequests = new List<IEnvelope>();
             _stateRequests.Add(message.Partition, partitionRequests);
             needRequest = true;
         }
         partitionRequests.Add(message.Envelope);
         if (needRequest)
             _coreQueue.Publish(
                 new CoreProjectionManagementMessage.GetState(
                     new PublishEnvelope(_inputQueue), _id, message.Partition));
     }
     else
     {
         //TODO: report right state here
         message.Envelope.ReplyWith(
             new ProjectionManagementMessage.ProjectionState(message.Name, "*** UNKNOWN ***"));
     }
 }
Пример #8
0
 public void Handle(ProjectionManagementMessage.GetQuery message)
 {
     message.Envelope.ReplyWith(new ProjectionManagementMessage.ProjectionQuery(_name, Query));
 }
Пример #9
0
 private void DoDelete(ProjectionManagementMessage.Delete message)
 {
     if (Enabled)
         Disable();
     Delete();
     Action completed = () =>
         {
             message.Envelope.ReplyWith(new ProjectionManagementMessage.Updated(_name));
             DisposeCoreProjection();
             _output.Publish(new ProjectionManagementMessage.Internal.Deleted(_name, Id));
         };
     UpdateProjectionVersion();
     if (Enabled)
         Prepare(() => BeginWrite(completed));
     else
         BeginWrite(completed);
 }
Пример #10
0
 private void UpdateQuery(ProjectionManagementMessage.Command.UpdateQuery message)
 {
     PersistedProjectionState.HandlerType = message.HandlerType ?? HandlerType;
     PersistedProjectionState.Query = message.Query;
     PersistedProjectionState.EmitEnabled = message.EmitEnabled ?? PersistedProjectionState.EmitEnabled;
     _pendingWritePersistedState = true;
     if (_state == ManagedProjectionState.Completed)
     {
         Reset();
     }
 }
Пример #11
0
 private void SetRunAs(ProjectionManagementMessage.Command.SetRunAs message)
 {
     PersistedProjectionState.RunAs = message.Action == ProjectionManagementMessage.Command.SetRunAs.SetRemove.Set
         ? SerializedRunAs.SerializePrincipal(message.RunAs)
         : null;
     _runAs = SerializedRunAs.DeserializePrincipal(PersistedProjectionState.RunAs);
     _pendingWritePersistedState = true;
 }
Пример #12
0
 public void Handle(ProjectionManagementMessage.Command.Reset message)
 {
     _lastAccessed = _timeProvider.Now;
     Prepared = false;
     _pendingWritePersistedState = true;
     Reset();
     UpdateProjectionVersion();
     SetLastReplyEnvelope(message.Envelope);
     StopUnlessPreparedOrLoaded();
 }
Пример #13
0
        public void Handle(ProjectionManagementMessage.Command.Delete message)
        {
            if ((_state != ManagedProjectionState.Stopped && _state != ManagedProjectionState.Faulted) && Mode != ProjectionMode.Transient)
                throw new InvalidOperationException("Cannot delete a projection that hasn't been stopped or faulted.");
            _lastAccessed = _timeProvider.Now;

            PersistedProjectionState.DeleteCheckpointStream = message.DeleteCheckpointStream;
            PersistedProjectionState.DeleteStateStream = message.DeleteStateStream;
            PersistedProjectionState.DeleteEmittedStreams = message.DeleteEmittedStreams;

            if (PersistedProjectionState.DeleteCheckpointStream)
            {
                PersistedProjectionState.NumberOfPrequisitesMetForDeletion++;
            }
            if ((PersistedProjectionState.EmitEnabled ?? false) && ((PersistedProjectionState.TrackEmittedStreams ?? false) && PersistedProjectionState.DeleteEmittedStreams))
            {
                PersistedProjectionState.NumberOfPrequisitesMetForDeletion++;
            }

            Delete();
            UpdateProjectionVersion();
            SetLastReplyEnvelope(message.Envelope);
            SetState(ManagedProjectionState.Deleting);
            StopUnlessPreparedOrLoaded();
        }
Пример #14
0
 public void Handle(ProjectionManagementMessage.Command.SetRunAs message)
 {
     _lastAccessed = _timeProvider.Now;
     Prepared = false;
     SetRunAs(message);
     UpdateProjectionVersion();
     SetLastReplyEnvelope(message.Envelope);
     StopUnlessPreparedOrLoaded();
 }
Пример #15
0
 public void Handle(ProjectionManagementMessage.Command.Enable message)
 {
     _lastAccessed = _timeProvider.Now;
     if (Enabled
         && !(_state == ManagedProjectionState.Completed || _state == ManagedProjectionState.Faulted
              || _state == ManagedProjectionState.Aborted || _state == ManagedProjectionState.Loaded
              || _state == ManagedProjectionState.Prepared || _state == ManagedProjectionState.Stopped))
     {
         //Projection is probably Running
         message.Envelope.ReplyWith(new ProjectionManagementMessage.Updated(message.Name));
         return;
     }
     Enable();
     _pendingWritePersistedState = true;
     UpdateProjectionVersion();
     SetLastReplyEnvelope(message.Envelope);
     StopUnlessPreparedOrLoaded();
 }
Пример #16
0
        public static SerializedRunAs SerializePrincipal(ProjectionManagementMessage.RunAs runAs)
        {
            if (runAs.Principal == null)
                return null; // anonymous
            if (runAs.Principal == SystemAccount.Principal)
                return new SerializedRunAs {Name = "$system"};

            var genericPrincipal = runAs.Principal as OpenGenericPrincipal;
            if (genericPrincipal == null)
                throw new ArgumentException(
                    "OpenGenericPrincipal is the only supported principal type in projections", "runAs");
            return new SerializedRunAs {Name = runAs.Principal.Identity.Name, Roles = genericPrincipal.Roles};
        }
Пример #17
0
 private void DoUpdateQuery(ProjectionManagementMessage.UpdateQuery message)
 {
     _persistedState.HandlerType = message.HandlerType ?? HandlerType;
     _persistedState.Query = message.Query;
     _persistedState.EmitEnabled = message.EmitEnabled ?? _persistedState.EmitEnabled;
     if (_state == ManagedProjectionState.Completed)
     {
         ResetProjection();
     }
     Action completed = () =>
         {
             StartOrLoadStopped(() => { });
             message.Envelope.ReplyWith(new ProjectionManagementMessage.Updated(message.Name));
         };
     UpdateProjectionVersion();
     Prepare(() => BeginWrite(completed));
 }
Пример #18
0
        public void Handle(ProjectionManagementMessage.GetQuery message)
        {
            _lastAccessed = _timeProvider.Now;
            if (!ProjectionManagementMessage.RunAs.ValidateRunAs(Mode, ReadWrite.Read, _runAs, message)) return;

            var emitEnabled = _persistedState.EmitEnabled ?? false;
            message.Envelope.ReplyWith(
                new ProjectionManagementMessage.ProjectionQuery(_name, Query, emitEnabled, _persistedState.SourceDefinition));
        }
Пример #19
0
 public void Handle(ProjectionManagementMessage.GetState message)
 {
     _lastAccessed = _timeProvider.Now;
     if (_state >= ManagedProjectionState.Stopped)
     {
         _getStateDispatcher.Publish(
             new CoreProjectionManagementMessage.GetState(
                 new PublishEnvelope(_inputQueue), Guid.NewGuid(), Id, message.Partition),
             m =>
             message.Envelope.ReplyWith(
                 new ProjectionManagementMessage.ProjectionState(_name, m.Partition, m.State, m.Position)));
     }
     else
     {
         message.Envelope.ReplyWith(
             new ProjectionManagementMessage.ProjectionState(
                 message.Name, message.Partition, "*** UNKNOWN ***", position: null));
     }
 }
Пример #20
0
 public void Handle(ProjectionManagementMessage.Abort message)
 {
     _lastAccessed = _timeProvider.Now;
     if (!ProjectionManagementMessage.RunAs.ValidateRunAs(Mode, ReadWrite.Write, _runAs, message)) return;
     Abort(() => DoDisable(message.Envelope, message.Name));
 }
Пример #21
0
 public void Handle(ProjectionManagementMessage.UpdateQuery message)
 {
     Stop(() => DoUpdateQuery(message));
 }
Пример #22
0
 public void Handle(ProjectionManagementMessage.Enable message)
 {
     _lastAccessed = _timeProvider.Now;
     if (!ProjectionManagementMessage.RunAs.ValidateRunAs(Mode, ReadWrite.Write, _runAs, message)) return;
     if (Enabled
         && !(_state == ManagedProjectionState.Completed || _state == ManagedProjectionState.Faulted
              || _state == ManagedProjectionState.Loaded || _state == ManagedProjectionState.Prepared
              || _state == ManagedProjectionState.Stopped))
     {
         message.Envelope.ReplyWith(
             new ProjectionManagementMessage.OperationFailed("Invalid state"));
         return;
     }
     if (!Enabled)
         Enable();
     Action completed = () =>
         {
             if (_state == ManagedProjectionState.Prepared)
                 StartOrLoadStopped(() => message.Envelope.ReplyWith(new ProjectionManagementMessage.Updated(message.Name)));
             else
                 message.Envelope.ReplyWith(
                     new ProjectionManagementMessage.Updated(message.Name));
         };
     UpdateProjectionVersion();
     Prepare(() => BeginWrite(completed));
 }
Пример #23
0
 public void Handle(ProjectionManagementMessage.Disable message)
 {
     Stop(() => DoDisable(message));
 }
Пример #24
0
        public void Handle(ProjectionManagementMessage.SetRunAs message)
        {
            _lastAccessed = _timeProvider.Now;
            if (
                !ProjectionManagementMessage.RunAs.ValidateRunAs(
                    Mode, ReadWrite.Write, _runAs, message,
                    message.Action == ProjectionManagementMessage.SetRunAs.SetRemove.Set)) return;


            Stop(
                () =>
                    {
                        UpdateProjectionVersion();
                        _persistedState.RunAs = message.Action == ProjectionManagementMessage.SetRunAs.SetRemove.Set
                                                    ? SerializePrincipal(message.RunAs)
                                                    : null;
                        _runAs = DeserializePrincipal(_persistedState.RunAs);

                        Prepare(
                            () => BeginWrite(
                                () =>
                                    {
                                        StartOrLoadStopped(() => { });
                                        message.Envelope.ReplyWith(
                                            new ProjectionManagementMessage.Updated(message.Name));
                                    }));
                    });
        }
Пример #25
0
 public void Handle(ProjectionManagementMessage.Delete message)
 {
     Stop(() => DoDelete(message));
 }
Пример #26
0
 public void Handle(ProjectionManagementMessage.Reset message)
 {
     _lastAccessed = _timeProvider.Now;
     if (!ProjectionManagementMessage.RunAs.ValidateRunAs(Mode, ReadWrite.Write, _runAs, message)) return;
     Stop(
         () =>
         {
             ResetProjection();
             Prepare(
                     () =>
                     BeginWrite(
                         () =>
                         StartOrLoadStopped(
                             () =>
                                 message.Envelope.ReplyWith(new ProjectionManagementMessage.Updated(message.Name)))));
         });
 }
Пример #27
0
 private void DoDelete(ProjectionManagementMessage.Delete message)
 {
     if (Enabled)
         Disable();
     Delete();
     PrepareAndBeginWrite(
         forcePrepare: false,
         completed: () => message.Envelope.ReplyWith(new ProjectionManagementMessage.Updated(message.Name)));
 }
Пример #28
0
 public void Handle(ProjectionManagementMessage.Delete message)
 {
     _lastAccessed = _timeProvider.Now;
     if (!ProjectionManagementMessage.RunAs.ValidateRunAs(Mode, ReadWrite.Write, _runAs, message)) return;
     Stop(() => DoDelete(message));
 }
Пример #29
0
 private void DoUpdateQuery(ProjectionManagementMessage.UpdateQuery message)
 {
     UpdateQuery(message.HandlerType ?? HandlerType, message.Query);
     PrepareAndBeginWrite(
         forcePrepare: true, completed: () =>
             {
                 if (Enabled)
                     Start(() => { });
                 message.Envelope.ReplyWith(new ProjectionManagementMessage.Updated(message.Name));
             });
 }
Пример #30
0
 public void Handle(ProjectionManagementMessage.Internal.CleanupExpired message)
 {
     //TODO: configurable expiration
     if (IsExpiredProjection())
     {
         if (_state == ManagedProjectionState.Creating)
         {
             // NOTE: workaround for stop not working on creating state (just ignore them)
             return;
         }
         Stop(
             () =>
                 Handle(
                     new ProjectionManagementMessage.Delete(
                         new NoopEnvelope(), _name, ProjectionManagementMessage.RunAs.System, false, false)));
     }
 }