예제 #1
0
        /// <summary>
        /// TODO: Persist time the Object was first created. That will be insight start time.
        /// </summary>
        /// <param name="insightRuntime"></param>
        /// <param name="token"></param>
        protected BaseInsightGenerator(IInsightRuntime insightRuntime, ICallbackStore callbackStore, CancellationToken token)
        {
            Assert.IsNotNull(insightRuntime, "Runtime can't be null");
            Assert.IsNotNull(callbackStore, "Callback store can't be null");
            this.InsightRuntime = insightRuntime;
            this.Logger         = this.InsightRuntime.GetLogProvider().CreateLoggerInstance(this.GetType().ToString().Split('.').Last());
            this.CallbackStore  = callbackStore;

            // Since we may launch a task that we need to cancel, we go ahead create a linked token.
            // Any launched task will respect this linked entity. So effectively, we can chose to cancel it,
            // as well as the creator of this class.
            this.InternalTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token);
            this.InsightLocalToken   = this.InternalTokenSource.Token;

            this.ClusterQueryInstance = this.InsightRuntime.GetService(typeof(IClusterQuery)) as IClusterQuery;
            Assert.IsNotNull(this.ClusterQueryInstance, "Runtime doesn't have a valid ClusterQuery object");

            this.EntityStore = this.InsightRuntime.GetStoreProvider()
                               .CreatePersistentStoreForStringsAsync(this.GetType() + "_EntityStore", AgeBasedRetentionPolicy.OneMonth, this.InsightLocalToken).GetAwaiter().GetResult();

            this.analysisScheduler = (AnalysisScheduler)this.InsightRuntime.GetService(typeof(AnalysisScheduler));
            Assert.IsNotNull(this.analysisScheduler, "AnalysisScheduler can't be null");
        }
예제 #2
0
        public async Task StartAnalysisEngineAsync(IList <InsightType> insightTypes, IInsightRuntime runtime, CancellationToken token)
        {
            await this.singleAccess.WaitAsync(token).ConfigureAwait(false);

            try
            {
                if (this.isRunning)
                {
                    throw new ClusterAnalysisAlreadyStartedException();
                }

                var connectionInfo       = (TraceStoreConnectionInformation)runtime.GetService(typeof(TraceStoreConnectionInformation));
                var traceStoreConnection = new TraceStoreConnection(connectionInfo, runtime.GetLogProvider());

                // Add the connection to Runtime. TODO Get rid of this and pass this explicitly.
                runtime.AddService(typeof(TraceStoreConnection), traceStoreConnection);

                var analysisScheduler = new AnalysisScheduler(
                    runtime.GetLogProvider(),
                    runtime.GetStoreProvider(),
                    runtime.TaskRunner,
                    traceStoreConnection,
                    token);

                runtime.AddService(typeof(AnalysisScheduler), analysisScheduler);

                Assert.IsNotNull(connectionInfo, "connectionInfo != null");

                this.callBackStore = new SimpleCallbackStore(
                    runtime.GetStoreProvider(),
                    runtime.TaskRunner,
                    runtime.GetLogProvider(),
                    traceStoreConnection.EventStoreReader,
                    token);

                AgentDirectory.InitializeSingleInstance(
                    runtime.GetCurrentConfig(),
                    runtime.GetLogProvider(),
                    runtime.GetStoreProvider(),
                    runtime.TaskRunner,
                    traceStoreConnection,
                    (IClusterQuery)runtime.GetService(typeof(IClusterQuery)),
                    token);

                foreach (var oneInsightType in insightTypes)
                {
                    switch (oneInsightType)
                    {
                    case InsightType.PartitionInsight:
                        this.partitionInsightGenerator = new PartitionInsightGenerator(runtime, this.callBackStore, token);
                        await this.partitionInsightGenerator.StartGeneratingAsync().ConfigureAwait(false);

                        break;

                    case InsightType.ReplicaInsight:
                        break;

                    case InsightType.CodePackageInsight:
                        break;

                    case InsightType.NodeInsight:
                        break;

                    case InsightType.ClusterInsight:
                        break;

                    default:
                        throw new NotSupportedException(
                                  string.Format(CultureInfo.InvariantCulture, "Insight Type '{0}' is currently not supported", oneInsightType));
                    }
                }

                this.isRunning = true;
            }
            catch
            {
                AgentDirectory.ReleaseInstance();
                throw;
            }
            finally
            {
                this.singleAccess.Release();
            }
        }