public bool DeleteStackEvent(StackEvent entity)
 {
     if (entity == null) return false;
        _unitOfWork.StackEventRepository.Delete(entity);
        _unitOfWork.Save();
        return true;
 }
        /// <summary>
        /// Log an error if we expected success and got a rollback
        /// </summary>
        /// <param name="status">The status of the stack, or null if the stack does not exist</param>
        /// <param name="expectSuccess">True if the status should indicate success</param>
        /// <param name="missingIsFailure">True if the a missing stack indicates a failure, and false otherwise</param>
        /// <param name="deployment">The current deployment</param>
        private void LogRollbackError(
            RunningDeployment deployment,
            StackEvent status,
            bool expectSuccess,
            bool missingIsFailure)
        {
            Guard.NotNull(deployment, "deployment can not be null");

            var isUnsuccessful = StatusIsUnsuccessfulResult(status, missingIsFailure);
            var isStackType    = status?.ResourceType.Equals("AWS::CloudFormation::Stack") ?? true;

            if (expectSuccess && isUnsuccessful && isStackType)
            {
                Log.Warn(
                    "Stack was either missing, in a rollback state, or in a failed state. This means that the stack was not processed correctly. " +
                    "Review the stack in the AWS console to find any errors that may have occured during deployment.");
                try
                {
                    var progressStatus = StackEvent(stack => stack.ResourceStatusReason != null);
                    if (progressStatus != null)
                    {
                        Log.Warn(progressStatus.ResourceStatusReason);
                    }
                }
                catch (PermissionException)
                {
                    // ignore, it just means we won't display any of the status reasons
                }

                throw new RollbackException(
                          "AWS-CLOUDFORMATION-ERROR-0001: CloudFormation stack finished in a rollback or failed state. " +
                          "For more information visit https://g.octopushq.com/AwsCloudFormationDeploy#aws-cloudformation-error-0001");
            }
        }
Ejemplo n.º 3
0
        protected void PushEvent()
        {
            StackEvent e = onPush;

            if (e != null)
            {
                e();
            }
        }
Ejemplo n.º 4
0
        protected void PopEvent()
        {
            StackEvent e = onPop;

            if (e != null)
            {
                e();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Read a stack event
        /// </summary>
        /// <param name="from">Origin</param>
        /// <param name="channel">Code channel where the stack event occurred</param>
        /// <param name="stackDepth">New stack depth</param>
        /// <param name="flags">Flags of the stack</param>
        /// <param name="feedrate">Feedrate in mm/s</param>
        /// <returns>Number of bytes read</returns>
        /// <seealso cref="Request.StackEvent"/>
        public static int ReadStackEvent(ReadOnlySpan <byte> from, out CodeChannel channel, out byte stackDepth, out StackFlags flags, out float feedrate)
        {
            StackEvent header = MemoryMarshal.Cast <byte, StackEvent>(from)[0];

            channel    = (CodeChannel)header.Channel;
            stackDepth = header.StackDepth;
            flags      = (StackFlags)header.Flags;
            feedrate   = header.Feedrate;
            return(Marshal.SizeOf(header));
        }
Ejemplo n.º 6
0
 public bool DeleteStackEvent(StackEvent entity)
 {
     if (entity == null)
     {
         return(false);
     }
     _unitOfWork.StackEventRepository.Delete(entity);
     _unitOfWork.Save();
     return(true);
 }
Ejemplo n.º 7
0
 public void Push(T obj)
 {
     data.Add(obj);
     if (StackEvent != null)
     {
         StackEvent.Invoke(this, new StackEventData <T> {
             IsPushed = true, Value = obj
         });
     }
 }
Ejemplo n.º 8
0
        public virtual StackEvent Dropoff(IStack stack)
        {
            var dropoff = new StackEvent(World.Environment, TriggerPickup, CancelDrop)
            {
                Stack = stack, Size = stack.Size
            };

            DropoffQueue.AddLast(dropoff);
            TriggerDropoff();
            return(dropoff);
        }
Ejemplo n.º 9
0
        public virtual StackEvent Pickup(int size)
        {
            var pickup = new StackEvent(World.Environment, TriggerDropoff, CancelPick)
            {
                Size = size
            };

            PickupQueue.AddLast(pickup);
            TriggerPickup();
            return(pickup);
        }
 /// <summary>
 /// These status indicate that an update or create was not successful.
 /// http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-describing-stacks.html#w2ab2c15c15c17c11
 /// </summary>
 /// <param name="status">The status to check</param>
 /// <param name="defaultValue">The default value if status is null</param>
 /// <returns>true if the status indcates a failed create or update, and false otherwise</returns>
 private bool StatusIsUnsuccessfulResult(StackEvent status, bool defaultValue)
 {
     return(new[]
     {
         "CREATE_ROLLBACK_COMPLETE", "CREATE_ROLLBACK_FAILED", "UPDATE_ROLLBACK_COMPLETE",
         "UPDATE_ROLLBACK_FAILED", "ROLLBACK_COMPLETE", "ROLLBACK_FAILED", "DELETE_FAILED",
         "CREATE_FAILED"
     }.Any(x =>
           status?.ResourceStatus.Value.Equals(x, StringComparison.InvariantCultureIgnoreCase) ??
           defaultValue));
 }
Ejemplo n.º 11
0
        public bool AddStackEvent(StackEvent entity)
        {
            try
            {
                _unitOfWork.StackEventRepository.Add(entity);
                _unitOfWork.Save();
            }
            catch (Exception ex)
            {
                throw;
            }

            return(true);
        }
        /// <summary>
        /// Write the state of the stack, but only if it changed since last time. If we are
        /// writing the same message more than once, do it as verbose logging.
        /// </summary>
        /// <param name="status">The current status of the stack</param>
        private void LogCurrentStates(StackEvent status)
        {
            var statusMessage =
                $"{status?.ResourceType.Map(type => type + " ")}{status?.ResourceStatus.Value ?? "Does not exist"}";

            if (statusMessage != lastMessage)
            {
                Log.Info($"Current stack state: {statusMessage}");
            }
            else
            {
                Log.Verbose($"Current stack state: {statusMessage}");
            }

            lastMessage = statusMessage;
        }
Ejemplo n.º 13
0
        public T Pop()
        {
            if (data.Count == 0)
            {
                throw new InvalidOperationException();
            }
            var result = data[data.Count - 1];

            if (StackEvent != null)
            {
                StackEvent.Invoke(this, new StackEventData <T> {
                    IsPushed = false, Value = result
                });
            }
            return(result);
        }
Ejemplo n.º 14
0
            /// <summary>
            /// Stack events
            /// </summary>
            /// <param name="e"></param>
            /// <returns></returns>
            public override int OnStackEvent(StackEvent e)
            {
                short  code   = e.getCode();
                String phrase = e.getPhrase();

                if (code == tinyWRAP.tsip_event_code_stack_started)
                {
                    this.sipService.SipStack.State = MySipStack.STACK_STATE.STARTED;

                    EventHandlerTrigger.TriggerEvent <StackEventArgs>(this.sipService.onStackEvent, this.sipService,
                                                                      new StackEventArgs(StackEventTypes.START_OK, phrase));
                }

                else if (code == tinyWRAP.tsip_event_code_stack_failed_to_start)
                {
                    EventHandlerTrigger.TriggerEvent <StackEventArgs>(this.sipService.onStackEvent, this.sipService,
                                                                      new StackEventArgs(StackEventTypes.START_NOK, phrase));
                }

                else if (code == tinyWRAP.tsip_event_code_stack_failed_to_stop)
                {
                    EventHandlerTrigger.TriggerEvent <StackEventArgs>(this.sipService.onStackEvent, this.sipService,
                                                                      new StackEventArgs(StackEventTypes.STOP_NOK, phrase));
                }

                else if (code == tinyWRAP.tsip_event_code_stack_stopped)
                {
                    this.sipService.SipStack.State = MySipStack.STACK_STATE.STOPPED;

                    // Reset contents
                    this.sipService.subWinfoContent = null;
                    this.sipService.subRegContent   = null;
                    this.sipService.subRLSContent   = null;
                    this.sipService.subMwiContent   = null;

                    EventHandlerTrigger.TriggerEvent <StackEventArgs>(this.sipService.onStackEvent, this.sipService,
                                                                      new StackEventArgs(StackEventTypes.STOP_OK, phrase));
                }

                return(0);
            }
 public bool AddStackEvent(StackEvent entity)
 {
     _unitOfWork.StackEventRepository.Add(entity);
        _unitOfWork.Save();
        return true;
 }
Ejemplo n.º 16
0
 /// <inheritdoc />
 public void LogStackEvent(StackEvent @event)
 {
 }
 public static bool StackIsUnrecoverable(this StackEvent status)
 {
     Guard.NotNull(status, "Status should not be null");
     return(UnrecoverableStackStatuses.Contains(status.ResourceStatus.Value));
 }
 /// <summary>
 /// Check the stack event status to determine whether it was successful.
 /// http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-describing-stacks.html#w2ab2c15c15c17c11
 /// </summary>
 /// <param name="status">The status to check</param>
 /// <returns>true if the status indicates a failed create or update, and false otherwise</returns>
 public static Maybe <bool> MaybeIndicatesSuccess(this StackEvent status)
 {
     return(status.ToMaybe().Select(x => !UnsuccessfulStackEvents.Contains(x.ResourceStatus.Value)));
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Logs a stack event.
 /// </summary>
 /// <param name="event">The event.</param>
 public override void LogStackEvent(StackEvent @event)
 {
     this.StackEvents.Add(@event);
 }
Ejemplo n.º 20
0
 private static bool IsFinalStackEvent(StackEvent evt)
 => (evt.ResourceType == "AWS::CloudFormation::Stack") && _finalStates.Contains(evt.ResourceStatus);
Ejemplo n.º 21
0
 public void Publish(object sender, TEventArgs eventArg)
 {
     StackEvent?.Invoke(sender, eventArg);
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Logs a stack event.
        /// </summary>
        /// <param name="event">The event.</param>
        public override void LogStackEvent(StackEvent @event)
        {
            const int TimeColWidth     = 8;
            var       stackColWidth    = Math.Max(9, Math.Min(this.StackNameColumnWidth, 40));
            var       resourceColWidth = Math.Max(11, Math.Min(this.ResourceNameColumnWidth, 40));

            var ui = this.cmdlet.Host.UI;
            var bg = ui.RawUI.BackgroundColor;

            if (this.isFirstEvent)
            {
                var eventFormatString =
                    $"{{0,-{TimeColWidth}}} {{1,-{stackColWidth}}} {{2,-{resourceColWidth}}} {{3,-{this.StatusColumnWidth}}} {{4}}";

                // Resize window to be wide enough for a reasonable amount of description per line
                this.ResizeWindow(string.Format(eventFormatString, "x", "x", "x", "x", Padding30).Length);

                this.isFirstEvent = false;
                this.LogInformation(eventFormatString, "Time", "StackName", "Logical ID", "Status", "Status Reason");
                this.LogInformation(eventFormatString, "----", "---------", "----------", "------", "-------------");
            }

            var leftIndent = GetLeftMarginForLastColumn(
                TimeColWidth,
                stackColWidth,
                resourceColWidth,
                this.StatusColumnWidth);
            var maxLineLength = ui.RawUI.WindowSize.Width - leftIndent;

            ui.Write($"{@event.Timestamp:HH:mm:ss} ");
            ui.Write(this.EllipsisString(@event.StackName, stackColWidth).PadRight(stackColWidth + 1));
            ui.Write(this.EllipsisString(@event.LogicalResourceId, resourceColWidth).PadRight(resourceColWidth + 1));

            var fg     = ui.RawUI.ForegroundColor;
            var status = @event.ResourceStatus.Value;

            if (status.Contains("ROLLBACK") || ErrorStatus.IsMatch(status))
            {
                fg = ConsoleColor.Red;
            }
            else if (status.EndsWith("IN_PROGRESS"))
            {
                fg = ConsoleColor.Cyan;
            }
            else if (status.EndsWith("COMPLETE"))
            {
                fg = ConsoleColor.Green;
            }

            ui.Write(fg, bg, status.PadRight(this.StatusColumnWidth + 1));

            if (string.IsNullOrEmpty(@event.ResourceStatusReason))
            {
                ui.WriteLine("-");
            }
            else
            {
                fg = ErrorStatus.IsMatch(status) ? ConsoleColor.Red : ui.RawUI.ForegroundColor;

                // Split text to fit in space we have in the window
                var charCount = 0;

                var lines = @event.ResourceStatusReason.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                            .GroupBy(w => (charCount += w.Length + 1) / (maxLineLength - 1)).Select(g => string.Join(" ", g))
                            .ToList();

                ui.WriteLine(fg, bg, lines.First());

                foreach (var line in lines.Skip(1))
                {
                    ui.WriteLine(fg, bg, new string(' ', leftIndent) + line);
                }
            }
        }
 /// <summary>
 /// Logs a stack event.
 /// </summary>
 /// <param name="event">The event.</param>
 /// <remarks>
 /// Not implemented here as the client may want to do funky things like coloring the output
 /// </remarks>
 public abstract void LogStackEvent(StackEvent @event);
 public bool EditStackEvent(StackEvent entity)
 {
     _unitOfWork.StackEventRepository.Edit(entity);
        _unitOfWork.Save();
        return true;
 }
Ejemplo n.º 25
0
 public bool AddStackEvent(StackEvent entity)
 {
     _unitOfWork.StackEventRepository.Add(entity);
     _unitOfWork.Save();
     return(true);
 }
Ejemplo n.º 26
0
 private static bool IsSuccessfulFinalStackEvent(StackEvent evt)
 => (evt.ResourceType == "AWS::CloudFormation::Stack") &&
 ((evt.ResourceStatus == "CREATE_COMPLETE") || (evt.ResourceStatus == "UPDATE_COMPLETE"));
Ejemplo n.º 27
0
 public bool EditStackEvent(StackEvent entity)
 {
     _unitOfWork.StackEventRepository.Edit(entity);
     _unitOfWork.Save();
     return(true);
 }