private ClusterQuery(IInsightRuntime runtime) { this.fabricClient = runtime.GetService(typeof(FabricClient)) as FabricClient; Assert.IsNotNull(this.fabricClient, "Runtime needs to supply non-null Fabric client"); this.logger = runtime.GetLogProvider().CreateLoggerInstance("ClusterQuery.log"); this.logProvider = runtime.GetLogProvider(); }
/// <summary> /// </summary> /// <param name="runtime"></param> /// <param name="token"></param> protected BaseCallbackStore(IInsightRuntime runtime, CancellationToken token) { this.singleAccessLock = new SemaphoreSlim(1); this.callbackMap = new Dictionary <NotifyFilter, IList <Func <ScenarioData, Task> > >(); this.Runtime = runtime; string typeName = this.GetType().ToString(); this.Logger = this.Runtime.GetLogProvider().CreateLoggerInstance(typeName.Split('.').Last()); this.taskRunner = runtime.TaskRunner; this.InternalTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token); token = this.InternalTokenSource.Token; this.Query = this.Runtime.GetService(typeof(IClusterQuery)) as IClusterQuery; Assert.IsNotNull(this.Query, "Runtime doesn't contain valid Cluster Query object"); // Some signals may not show up immedietly so we don't want their last seen time bailing on us. this.signalSeenTillThisTimeStore = this.Runtime.GetStoreProvider() .CreatePersistentStoreForTimeAsync(SignalSeenTillTimeStoreName, AgeBasedRetentionPolicy.TwoWeek, token).GetAwaiter().GetResult(); // This store keeps track of unique Ids of signals seen to avoid duplicate reporting. The entries in this // collection needs to be long lived. Consider a signal that is living in the system for a long time // If we don't track that this has been reported, we may try to report it again. this.reportedSignalsUniqueIdsStore = this.Runtime.GetStoreProvider() .CreatePersistentStoreForIntAsync(ReportedSignalUniqueIdsStoreName, AgeBasedRetentionPolicy.OneWeek, token).GetAwaiter().GetResult(); this.signalsInDispatchQueuePersistentStore = this.Runtime.GetStoreProvider() .CreatePersistentStoreForStringsAsync(SignalsInDispatchQueueStoreName, AgeBasedRetentionPolicy.OneHour, token).GetAwaiter().GetResult(); this.producerConsumerBufferBlock = new BufferBlock <ScenarioNotificationData>(); this.InitSignalSeenBookmarkStoreAsync(token).Wait(token); }
public HttpServiceClientHandler(IInsightRuntime runtime, IResolveServiceEndpoint serviceEndpointResolver) { Assert.IsNotNull(runtime, "Runtime can't be null"); Assert.IsNotNull(serviceEndpointResolver, "Service Endpoint resolver can't be null"); this.serviceResolver = serviceEndpointResolver; this.logger = runtime.GetLogProvider().CreateLoggerInstance("HttpServiceClientHandler"); }
private void AddServiceToRuntime(IInsightRuntime runtime, Type type, object service) { if (runtime.GetService(type) == null) { runtime.AddService(type, service); } }
/// <summary> /// Create an instance of <see cref="SimpleCallbackStore"/> /// </summary> /// <remarks> /// Keeping private to control who can create an instance. /// </remarks> internal SimpleCallbackStore(IInsightRuntime runtime, FabricTraceStore traceStore, CancellationToken token) : base( runtime, token) { // TODO: Think the Policy passing through this.eventStore = new EventStoreImpl(runtime, traceStore, AgeBasedRetentionPolicy.OneWeek, token); this.SetStoreIsBehindByDuration(TimeSpan.FromMinutes(5)); }
public async Task StartClusterAnalysisAsync(IInsightRuntime runtime, IList <IAnalysisConsumer> consumers, CancellationToken token) { // Create a linked token source. this.stopCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token); this.logger.LogMessage("Creating Generators"); try { var insightTypesToLoad = new List <InsightType> { InsightType.ClusterInsight, InsightType.PartitionInsight, InsightType.CodePackageInsight, InsightType.ReplicaInsight }; await this.analysisEngine.StartAnalysisEngineAsync(insightTypesToLoad, runtime, token).ConfigureAwait(false); this.logger.LogMessage("Created Generators"); foreach (var oneConsumer in consumers) { foreach (var oneInsightType in insightTypesToLoad) { this.analysisEngine.AddConsumer(oneInsightType, oneConsumer, ConsumeOptions.Finished); } } } catch (Exception e) { this.logger.LogError("StartClusterAnalysisAsync:: Encountered Exception {0} while launching Cluster Analysis.", e); this.analysisEngine.StopAnalysisEngineAsync(StopOptions.StopAnalysis, token).GetAwaiter().GetResult(); throw; } }
/// <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"); }
/// <inheritdoc /> internal NodeInsightGenerator(IInsightRuntime runtime, ICallbackStore callbackStore, CancellationToken token) : base(runtime, callbackStore, token) { this.Logger.LogMessage("NodeInsightGenerator:: Creating Object"); }
/// <summary> /// Get singleton instance of Cluster Query /// </summary> /// <param name="runtime"></param> /// <returns></returns> public static IClusterQuery CreateClusterQueryInstance(IInsightRuntime runtime) { Assert.IsNotNull(runtime, "Runtime can't be null"); return(new ClusterQuery(runtime)); }
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(); } }
internal PartitionInsightGenerator(IInsightRuntime runtime, ICallbackStore callbackStore, CancellationToken token) : base(runtime, callbackStore, token) { Assert.IsNotNull(runtime, "runtime != null"); this.primaryMoveAnalysisAgentIdentifier = AgentIdentifier.PrimaryMoveAnalysisAgent; }