// TODO : Improve this Logic.
        public async Task StopAnalysisAsync(StopOptions options)
        {
            this.Logger.LogMessage("StopAnalysisAsync - Entering");

            // if token has already been signalled, well nothing that we can do now. we simply return.
            if (this.CancelToken.IsCancellationRequested)
            {
                this.Logger.LogWarning("StopAnalysisAsync - InsightLocalToken is already signalled. Indicate a potential Issue.");
                return;
            }

            if (options == StopOptions.StopAnalysis)
            {
                // There is really nothing that we have to do here.
                this.Logger.LogMessage("StopAnalysisAsync - No Op");
            }

            if (options == StopOptions.RemoveAllState)
            {
                this.Logger.LogMessage("StopAnalysisAsync - Deleting All State");
                await this.analysisContainerObjectStore.ClearAllAsync().ConfigureAwait(false);

                await this.analysisMetadataObjectStore.ClearAllAsync().ConfigureAwait(false);

                await this.signalWaitingToBeProcessedStoreInstance.ClearAsync(this.CancelToken).ConfigureAwait(false);
            }
        }
Example #2
0
        public Task Stop(StopMode mode = StopMode.GracefulShutdown, StopOptions options = StopOptions.StopChildren)
        {
            State = ExecutionState.Stopping;

            State = ExecutionState.Stopped;
            return(Task.CompletedTask);
        }
Example #3
0
        static async Task Stop(StopOptions options)
        {
            var query = GetQuery(options);
            await query.StopTimer();

            await Current(options);
        }
Example #4
0
        public override void Execute()
        {
            if (Result.StateServer)
            {
                _option = ParserCommand <StopOptions>();

                if (_option != null)
                {
                    if (_option.GetType() == typeof(StopOptions))
                    {
                        if (Result.StateServer)
                        {
                            if (Result.Clients != null)
                            {
                                foreach (var x in Result.Clients)
                                {
                                    if (x.Value.Connected)
                                    {
                                        x.Value.Close();
                                        x.Value.Dispose();
                                    }
                                }


                                Result.Clients.Clear();
                                Result.Clients = null;
                            }

                            if (Result.Socket != null)
                            {
                                Result.Socket.Close();
                                Result.Socket.Dispose();
                                Result.Socket = null;
                            }

                            if (Result.Point != null)
                            {
                                Result.Point = null;
                            }

                            if (Result.ListNumbers != null)
                            {
                                Result.ListNumbers.Clear();
                                Result.ListNumbers = null;
                            }
                            Result.StateServer = false;

                            Console.WriteLine("The server is stopped!");
                        }
                        else
                        {
                            Console.WriteLine("The server is not running!");
                        }
                    }
                }
            }
        }
        private async Task StopClusterInsightAsync(bool endUserCall, StopOptions stopOptions, CancellationToken token)
        {
            await this.startStopApiSingleAccessLock.WaitAsync(token).ConfigureAwait(false);

            try
            {
                var currentStatus = await this.GetCurrentStatusAsync(token).ConfigureAwait(false);

                if (currentStatus == AnalysisFeatureStatus.Default)
                {
                    this.logger.LogMessage("CI Was never Running.");

                    // TODO: What to do in this case, is throwing an exception the right way to respond to user API?
                    // Maybe throw strongly typed exception which upper layer can catch and return appropriate response to user?
                    throw new Exception("CI Service was never enabled");
                }

                if (currentStatus.CurrentState == FeatureState.Stopped)
                {
                    this.logger.LogMessage("Cluster Insight is currently Stopped");
                    return;
                }

                await this.runner.StopClusterAnalysisAsync(stopOptions, token).ConfigureAwait(false);

                // If this was called by end user, we update the user intention.
                if (endUserCall)
                {
                    currentStatus.UserDesiredState = FeatureState.Stopped;
                }

                // Update the current Status of the CI Service.
                currentStatus.CurrentState = FeatureState.Stopped;
                await this.PersisteCurrentStatusAsync(currentStatus, token).ConfigureAwait(false);
            }
            catch (OperationCanceledException)
            {
            }
            catch (Exception exp)
            {
                // Currently, for Preview, We swallow the Exception. This ensures we don't crash FAS.
                this.logger.LogError("Failed to Stop Cluster Analysis. Exception Encountered: {0}", exp);
            }
            finally
            {
                this.logger.LogMessage("Running Finalizer");

                this.stopCancellationTokenSource.Cancel();

                this.stopCancellationTokenSource = null;

                this.startStopApiSingleAccessLock.Release();
            }
        }
Example #6
0
        public static void Stop(StopOptions opts)
        {
            if (!TryConnectRpc(opts, out SgxDaemon.SgxDaemonClient client))
            {
                return;
            }

            try
            {
                client.Stop(new Empty());
            }
            catch {}
        }
Example #7
0
        protected async Task DoStop(StopMode stopMode = StopMode.GracefulShutdown, StopOptions options = StopOptions.StopChildren)
        {
            DesiredExecutionState = ExecutionStateEx.Stopped;

            switch (State)
            {
            case ExecutionStateEx.Unspecified:
            case ExecutionStateEx.Uninitialized:
            case ExecutionStateEx.Faulted:
            case ExecutionStateEx.Stopped:
            //case ExecutionStateEx.Finished:
            case ExecutionStateEx.Disposed:
                return;

            case ExecutionStateEx.Initializing:
            case ExecutionStateEx.Ready:
            case ExecutionStateEx.Starting:
            case ExecutionStateEx.Started:
            case ExecutionStateEx.Pausing:
            case ExecutionStateEx.Paused:
            case ExecutionStateEx.Unpausing:
                break;

            case ExecutionStateEx.Stopping:
                break;

            default:
                throw new Exception();
            }

            SetState(ExecutionStateEx.Stopping);

            OnStopping();

            foreach (var child in Children.OfType <IStoppableEx>())
            {
                await child.Stop(stopMode, options).ConfigureAwait(false);
            }
            foreach (var child in Children.OfType <IStoppable>())
            {
                await child.Stop().ConfigureAwait(false);
            }

            SetState(ExecutionStateEx.Stopped);

            OnStopped();
        }
        public async Task StopAnalysisEngineAsync(StopOptions stopOptions, CancellationToken token)
        {
            await this.singleAccess.WaitAsync(token).ConfigureAwait(false);

            try
            {
                if (this.partitionInsightGenerator != null)
                {
                    await this.partitionInsightGenerator.StopGeneratingAsync(stopOptions);

                    this.partitionInsightGenerator = null;
                }

                if (this.nodeInsightGenerator != null)
                {
                    await this.nodeInsightGenerator.StopGeneratingAsync(stopOptions);

                    this.nodeInsightGenerator = null;
                }

                if (this.clusterInsightGenerator != null)
                {
                    await this.clusterInsightGenerator.StopGeneratingAsync(stopOptions);

                    this.clusterInsightGenerator = null;
                }

                if (stopOptions.HasFlag(StopOptions.RemoveAllState) || stopOptions.HasFlag(StopOptions.RemoveTemporaryState))
                {
                    await this.callBackStore.ResetCheckpointAsync(token).ConfigureAwait(false);

                    this.callBackStore = null;
                }

                // Release the Agent Directory Instance.
                AgentDirectory.ReleaseInstance();

                this.isRunning = false;
            }
            finally
            {
                this.singleAccess.Release();
            }
        }
Example #9
0
        public async Task StopClusterAnalysisAsync(StopOptions stopOptions, CancellationToken token)
        {
            try
            {
                await this.analysisEngine.StopAnalysisEngineAsync(stopOptions, token).ConfigureAwait(false);

                // Signal the cancellation token
                this.stopCancellationTokenSource.Cancel();
            }
            catch (OperationCanceledException exp)
            {
                this.logger.LogWarning("Op Cancelled Exception: {0}", exp);
            }
            catch (Exception exp)
            {
                this.logger.LogError("Task Died with Exception: {0}", exp);
                throw;
            }
        }
        /// <inheritdoc />
        public async Task StopGeneratingAsync(StopOptions stopOptions)
        {
            this.Logger.LogMessage("StopGeneratingAsync:: Stopping");

            // Stop signal triggered Agents
            await this.StopSignalTriggeredAgentsAsync(stopOptions).ConfigureAwait(false);

            this.Logger.LogMessage("StopGeneratingAsync:: Signalling token which will indicate to Agent that they should now stop");

            // Clear any state that we may have
            if (stopOptions == StopOptions.RemoveAllState)
            {
                await this.EntityStore.ClearAsync(this.InternalTokenSource.Token).ConfigureAwait(false);
            }

            // Give opportunity to kids to do any cleaning required
            await this.StopAsyncInternalAsync(stopOptions);

            // Signal the token
            this.InternalTokenSource.Cancel();
        }
        private async Task StopSignalTriggeredAgentsAsync(StopOptions stopOptions)
        {
            var signalTriggeredAgents = this.GetSignalTriggeredAgents();

            if (signalTriggeredAgents == null || !signalTriggeredAgents.Any())
            {
                return;
            }

            // Unregister the callbacks we have registered.
            Assert.IsNotNull(AgentDirectory.SingleInstance, "AgentDirectory.SingleInstance != null");
            foreach (var singleFilter in signalTriggeredAgents.SelectMany(agentIdentifier => AgentDirectory.SingleInstance.GetOrCreateAgentInstance(agentIdentifier).NotifyFilters))
            {
                this.Logger.LogMessage("StopSignalTriggeredAgentsAsync:: UnRegistering callback for scenario : '{0}'", singleFilter);
                await this.CallbackStore.UnRegisterCallbackAsync(singleFilter, this.HandleIncomingEventNotificationAsync, this.InsightLocalToken).ConfigureAwait(false);
            }

            // Convey stop intention to each agent.
            foreach (var oneAgentIdentifier in signalTriggeredAgents)
            {
                this.Logger.LogMessage("StopSignalTriggeredAgentsAsync:: Stopping Agent: '{0}'", oneAgentIdentifier);
                await AgentDirectory.SingleInstance.GetOrCreateAgentInstance(oneAgentIdentifier).StopAsync(stopOptions).ConfigureAwait(false);
            }
        }
 /// <inheritdoc />
 public override Task StopAsync(StopOptions options)
 {
     return(Task.FromResult(true));
 }
 /// <summary>
 /// In case child class need to have some custom logic executed when Stop is called, they can override this function.
 /// </summary>
 /// <returns></returns>
 protected virtual Task StopAsyncInternalAsync(StopOptions options)
 {
     return(Task.FromResult(true));
 }
Example #14
0
 /// <summary>
 /// Stop Async.
 /// </summary>
 /// <remarks>
 /// A hook for children to stop themselves and clear state (if requested).
 /// This is marked abstract so that child classes are forced to implement and most importantly think about this.
 /// So, for example, if some kid is creating their own storage and stop intent is to remove data, they should clear it.
 /// </remarks>
 /// <param name="options"></param>
 /// <returns></returns>
 public abstract Task StopAsync(StopOptions options);
        public static int Run(StopOptions options, string[] args)
        {
            // read in tracking file
            TimeTrackingFile timeTracking = TimeTrackingFile.toObject(File.ReadAllText(Program.TRACKING_FILE_PATH));

            if (timeTracking == null)
            {
                // write out error message
                ConsoleColor userDefaultColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: Encountered error generating kronos time.");
                Console.WriteLine("Open " + Program.TRACKING_FILE_PATH + " to view all times.");
                Console.WriteLine("Run kronos clean to fix and reset (note you will lose all previously logged times.");
                Console.ForegroundColor = userDefaultColor;

                return(1);
            }

            // if not currently tracking anything, send error
            if (timeTracking.currentTracking == null)
            {
                // write out error message
                ConsoleColor userDefaultColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: No work session in progress.");
                Console.WriteLine("Run kronos log to start a work session.");
                Console.ForegroundColor = userDefaultColor;

                return(2);
            }
            // if currently tracking, close out and save
            else
            {
                timeTracking.currentTracking.endTime    = DateTime.Now;
                timeTracking.currentTracking.totalHours = (timeTracking.currentTracking.endTime - timeTracking.currentTracking.startTime).TotalHours;

                // figure out message
                List <string> trimmedArgs = new List <string>(args);
                trimmedArgs.RemoveAll(s => s.StartsWith("-") || s == "stop");

                if (trimmedArgs.Count > 0)
                {
                    timeTracking.currentTracking.message = trimmedArgs.ToArray()[0];
                }

                // move current tracking to historicals
                timeTracking.previousTimes.Add(timeTracking.currentTracking);
                timeTracking.currentTracking = null;

                // save
                TimeTrackingFile.SaveToFile(timeTracking);

                // write out success message
                ConsoleColor userDefaultColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Successfully closed work session.");
                Console.ForegroundColor = userDefaultColor;

                return(0);
            }
        }
 /// <summary>
 /// Stop Cluster Analysis
 /// </summary>
 /// <remarks>
 /// This abstraction get Invoked when User calls the rest API to Stop Analysis.
 /// </remarks>
 /// <param name="stopOptions"></param>
 /// <param name="token"></param>
 /// <returns></returns>
 public Task StopClusterInsightAsync(StopOptions stopOptions, CancellationToken token)
 {
     // This is a user facing API, so we call stop with the mention that its an end user call with an intent to stop.
     return(this.StopClusterInsightAsync(endUserCall: true, stopOptions: stopOptions, token: token));
 }