public async Task <ClusterInfo> Info() { NodeList nodes = await this.query.GetNodesAsync(); ApplicationTypeList appTypes = await this.query.GetApplicationTypesAsync(); ApplicationList applications = await this.query.GetApplicationsAsync(); ClusterLoadInformation clusterLoadInfo = await this.query.GetClusterLoadAsync(); ClusterHealth clusterHealth = await this.query.GetClusterHealthAsync(); ProvisionedFabricCodeVersion version = await this.query.GetFabricVersion(); long serviceCount = 0; long partitionCount = 0; long replicaCount = 0; foreach (Node node in nodes) { DeployedApplicationList deployedApplicationList = await this.query.GetDeployedApplicationsAsync(node.NodeName); foreach (DeployedApplication deployedApplication in deployedApplicationList) { DeployedServiceReplicaList deployedReplicas = await this.query.GetDeployedReplicasAsync(node.NodeName, deployedApplication.ApplicationName); replicaCount += deployedReplicas.Count; } } foreach (Application application in applications) { ServiceList services = await this.query.GetServicesAsync(application.ApplicationName); serviceCount += services.Count; } return(new ClusterInfo( clusterHealth.AggregatedHealthState.ToString(), version != null ? version.CodeVersion : "not based", nodes.Select(x => x.NodeType).Distinct().Count(), appTypes.Count(), nodes.Select(x => x.FaultDomain.ToString()).Distinct().Count(), nodes.Select(x => x.UpgradeDomain).Distinct().Count(), nodes.Count, applications.Count, serviceCount, partitionCount, // TODO: partition count replicaCount, clusterLoadInfo.LastBalancingStartTimeUtc, clusterLoadInfo.LastBalancingEndTimeUtc)); }
private async Task <long> GetNodeReplicaCountAsync(string nodeName) { long count = 0; DeployedApplicationList deployedApplications = await this.fabricClient.QueryManager.GetDeployedApplicationListAsync(nodeName); foreach (DeployedApplication application in deployedApplications) { DeployedServiceReplicaList replicas = await this.fabricClient.QueryManager.GetDeployedReplicaListAsync(nodeName, application.ApplicationName); count += replicas.Count; } return(count); }
private async Task <List <ReplicaOrInstanceMonitoringInfo> > GetDeployedApplicationReplicaOrInstanceListAsync( Uri applicationNameFilter = null, string applicationType = null) { DeployedApplicationList deployedApps = null; if (applicationNameFilter != null) { deployedApps = await this.FabricClientInstance.QueryManager.GetDeployedApplicationListAsync(this.NodeName, applicationNameFilter).ConfigureAwait(true); } else { deployedApps = await this.FabricClientInstance.QueryManager.GetDeployedApplicationListAsync(this.NodeName).ConfigureAwait(true); if (deployedApps.Count > 0 && !string.IsNullOrEmpty(applicationType)) { for (int i = 0; i < deployedApps.Count; i++) { var app = deployedApps[i]; if (app.ApplicationTypeName?.ToLower() != applicationType.ToLower()) { deployedApps.Remove(app); } } } } var currentReplicaInfoList = new List <ReplicaOrInstanceMonitoringInfo>(); foreach (var deployedApp in deployedApps) { List <string> filteredServiceList = null; var appFilter = this.targetList.Where(x => (x.Target != null || x.TargetType != null) && (x.Target?.ToLower() == deployedApp.ApplicationName?.OriginalString.ToLower() || x.TargetType?.ToLower() == deployedApp.ApplicationTypeName?.ToLower()) && (!string.IsNullOrEmpty(x.ServiceExcludeList) || !string.IsNullOrEmpty(x.ServiceIncludeList)))?.FirstOrDefault(); // Filter service list if include/exclude service(s) config setting is supplied. var filterType = ServiceFilterType.None; if (appFilter != null) { if (!string.IsNullOrEmpty(appFilter.ServiceExcludeList)) { filteredServiceList = appFilter.ServiceExcludeList.Split(',').ToList(); filterType = ServiceFilterType.Exclude; } else if (!string.IsNullOrEmpty(appFilter.ServiceIncludeList)) { filteredServiceList = appFilter.ServiceIncludeList.Split(',').ToList(); filterType = ServiceFilterType.Include; } } var replicasOrInstances = await this.GetDeployedPrimaryReplicaAsync( deployedApp.ApplicationName, filteredServiceList, filterType, applicationType).ConfigureAwait(true); currentReplicaInfoList.AddRange(replicasOrInstances); // This is for reporting. this.replicaOrInstanceList.AddRange(replicasOrInstances); } return(currentReplicaInfoList); }
private async Task <ClusterStateSnapshot> CaptureClusterStateSnapshotAndPopulateEntitiesAsync( FabricTestContext testContext, GetClusterStateSnapshotAction action, CancellationToken cancellationToken) { this.PartitionMapFromFM = new HashSet <string>(StringComparer.InvariantCulture); this.PartitionMapFromNodes = new HashSet <string>(StringComparer.InvariantCulture); this.requestTimeOut = action.RequestTimeout; this.timer = new TimeoutHelper(action.ActionTimeout); this.testContext = testContext; this.deployedSystemReplicaMap = new Dictionary <NodeInfo, DeployedServiceReplicaList>(); var nodes = await this.testContext.FabricCluster.GetLatestNodeInfoAsync(this.requestTimeOut, this.timer.GetRemainingTime(), cancellationToken).ConfigureAwait(false); var clusterSnapshot = new ClusterStateSnapshot(false, action.ShouldFaultSystem); var nodeInfos = nodes as IList <NodeInfo> ?? nodes.ToList(); clusterSnapshot.Nodes.AddNodes(nodeInfos); clusterSnapshot.PopulateNodeMaps(nodes); // Get all current active applications var appListResult = await FabricClientRetryHelper.ExecuteFabricActionWithRetryAsync( () => this.testContext.FabricClient.QueryManager.GetApplicationListAsync( null, string.Empty, this.requestTimeOut, cancellationToken), this.timer.GetRemainingTime(), cancellationToken).ConfigureAwait(false); if (appListResult != null) { foreach (var appResultItem in appListResult) { var applicationEntity = clusterSnapshot.Applications.AddApplication(appResultItem); await this.PopulateApplicationEntityAsync(applicationEntity, cancellationToken).ConfigureAwait(false); } var systemApplicationEntity = clusterSnapshot.Applications.AddApplication(SystemApplication); await this.PopulateApplicationEntityAsync(systemApplicationEntity, cancellationToken).ConfigureAwait(false); } foreach (var node in nodeInfos) { var node1 = node.Clone(); if (node1.IsNodeUp) { var retryableErrorsForGetDeployedApplicationList = new FabricClientRetryErrors(); retryableErrorsForGetDeployedApplicationList.RetryableFabricErrorCodes.Add(FabricErrorCode.InvalidAddress); var deployedApplicationList = await FabricClientRetryHelper.ExecuteFabricActionWithRetryAsync( () => this.testContext.FabricClient.QueryManager.GetDeployedApplicationListAsync( node1.NodeName, null, this.requestTimeOut, cancellationToken), retryableErrorsForGetDeployedApplicationList, this.timer.GetRemainingTime(), cancellationToken).ConfigureAwait(false); // Add system app entity in the deployed application list // so that we get the deployed replica list for the node if (await this.HasDeployedSystemServiceAsync(node1, cancellationToken).ConfigureAwait(false)) { if (deployedApplicationList == null) { deployedApplicationList = new DeployedApplicationList(); } deployedApplicationList.Add(DeployedSystemApplication); } TestabilityTrace.TraceSource.WriteInfo(TraceType, "Node: {0} has the following apps deployed...", node1); foreach (var app in deployedApplicationList) { TestabilityTrace.TraceSource.WriteInfo(TraceType, "Deployed app = {0}", app.ApplicationName.OriginalString); } foreach (var app in deployedApplicationList) { var application = app; var applicationEntity = clusterSnapshot.Applications.FirstOrDefault(a => a.Application.ApplicationName == application.ApplicationName); if (applicationEntity != null) { if (!await this.TryAssociateDeployedReplicaWithDeployedCodepackageAsync( node1, applicationEntity, cancellationToken).ConfigureAwait(false)) { return(null); } } } // iterate through the deployed apps } // if a node is up } // iterate through the nodes // Information acquired through queries could go stale due to the cluster dynamism. // This happened while the cluster snapshot was being taken -- making the snapshot internally inconsistent. // The fix is to ignore the inconsistent snapshot and capture it again. // // If FailoverManager's point of view coincides with that of the Nodes, return the snapshot; // otherwise, throw FabricException to indicate that the snapshot should be captured afresh. // if (!this.PartitionMapFromFM.SetEquals(this.PartitionMapFromNodes)) { StringBuilder exceptionMessageBuilder = new StringBuilder(); var copyOfFmInfo = new HashSet <string>(this.PartitionMapFromFM); this.PartitionMapFromFM.ExceptWith(this.PartitionMapFromNodes); if (this.PartitionMapFromFM.Any()) { exceptionMessageBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, "FM has the following extra information:")); foreach (var pinfo in this.PartitionMapFromFM) { exceptionMessageBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, ReplicaViewPrintFormat, Tab, pinfo)); } } this.PartitionMapFromNodes.ExceptWith(copyOfFmInfo); if (this.PartitionMapFromNodes.Any()) { exceptionMessageBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, "Nodes has the following partitions deployed, which FM does not know about:")); foreach (var pinfo in this.PartitionMapFromNodes) { exceptionMessageBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, ReplicaViewPrintFormat, Tab, pinfo)); } } TestabilityTrace.TraceSource.WriteWarning(TraceType, string.Format(CultureInfo.InvariantCulture, "{0}", exceptionMessageBuilder.ToString())); throw new ChaosInconsistentClusterSnapshotException(exceptionMessageBuilder.ToString()); } return(clusterSnapshot); }
public void Init() { // Application Type FABRIC_APPLICATION_TYPE_QUERY_RESULT_ITEM_ = this.random.CreateRandom <ApplicationType>(); FABRIC_APPLICATION_TYPE_QUERY_RESULT_ITEM_LIST_ = new ApplicationTypeList() { this.random.CreateRandom <ApplicationType>() }; FABRIC_APPLICATION_TYPE_QUERY_RESULT_ITEM_PAGED_LIST_ = new ApplicationTypePagedList(); FABRIC_APPLICATION_TYPE_QUERY_RESULT_ITEM_PAGED_LIST_.ContinuationToken = "ContinuationToken342741"; FABRIC_APPLICATION_TYPE_QUERY_RESULT_ITEM_PAGED_LIST_.Add(this.random.CreateRandom <ApplicationType>()); FABRIC_APPLICATION_TYPE_QUERY_RESULT_ITEM_PAGED_LIST_.Add(this.random.CreateRandom <ApplicationType>()); FABRIC_APPLICATION_TYPE_QUERY_RESULT_ITEM_PAGED_LIST_.Add(this.random.CreateRandom <ApplicationType>()); // Application FABRIC_APPLICATION_QUERY_RESULT_ITEM_ = this.random.CreateRandom <Application>(); FABRIC_APPLICATION_QUERY_RESULT_ITEM_LIST_ = new ApplicationList() { this.random.CreateRandom <Application>(), this.random.CreateRandom <Application>() }; // Service Type FABRIC_SERVICE_TYPE_DESCRIPTION_ = this.random.CreateRandom <ServiceTypeDescription>(); FABRIC_SERVICE_TYPE_QUERY_RESULT_ITEM_ = this.random.CreateRandom <ServiceType>(); FABRIC_SERVICE_TYPE_QUERY_RESULT_LIST_ = new ServiceTypeList() { this.random.CreateRandom <ServiceType>() }; //Replica FABRIC_SERVICE_REPLICA_QUERY_RESULT_ITEM_ = this.CreateReplica(); FABRIC_SERVICE_REPLICA_LIST_RESULT_ = new ServiceReplicaList(); FABRIC_SERVICE_REPLICA_LIST_RESULT_.ContinuationToken = "4387284"; FABRIC_SERVICE_REPLICA_LIST_RESULT_.Add(this.CreateReplica()); FABRIC_SERVICE_REPLICA_LIST_RESULT_.Add(this.CreateReplica()); // Partition FABRIC_SERVICE_PARTITION_INFORMATION_ = this.random.CreateRandom <ServicePartitionInformation>(); FABRIC_SERVICE_PARTITION_QUERY_RESULT_ITEM_ = CreatePartition(); FABRIC_SERVICE_PARTITION_LIST_RESULT_ = new ServicePartitionList(); FABRIC_SERVICE_PARTITION_LIST_RESULT_.ContinuationToken = Guid.NewGuid().ToString(); FABRIC_SERVICE_PARTITION_LIST_RESULT_.Add(this.CreatePartition()); FABRIC_SERVICE_PARTITION_LIST_RESULT_.Add(this.CreatePartition()); //Service FABRIC_SERVICE_QUERY_RESULT_ITEM_ = this.CreateServiceQueryItem(); FABRIC_SERVICE_QUERY_RESULT_LIST_ = new ServiceList() { this.CreateServiceQueryItem(), this.CreateServiceQueryItem() }; // Node FABRIC_NODE_DEACTIVATION_QUERY_RESULT_ITEM_ = this.random.CreateRandom <NodeDeactivationResult>(); FABRIC_NODE_DEACTIVATION_TASK_ = this.random.CreateRandom <NodeDeactivationTask>(); FABRIC_NODE_QUERY_RESULT_ITEM_ = this.random.CreateRandom <Node>(); // NodeList with continuation token FABRIC_NODE_LIST_QUERY_RESULT_ = new NodeList(); FABRIC_NODE_LIST_QUERY_RESULT_.ContinuationToken = "ContinuationToken34274"; FABRIC_NODE_LIST_QUERY_RESULT_.Add(this.random.CreateRandom <Node>()); FABRIC_NODE_LIST_QUERY_RESULT_.Add(this.random.CreateRandom <Node>()); FABRIC_NODE_LIST_QUERY_RESULT_.Add(this.random.CreateRandom <Node>()); // Deployed Application FABRIC_DEPLOYED_APPLICATION_QUERY_RESULT_ITEM_ = this.random.CreateRandom <DeployedApplication>(); FABRIC_DEPLOYED_APPLICATION_QUERY_RESULT_ITEM_LIST_ = new DeployedApplicationList() { FABRIC_DEPLOYED_APPLICATION_QUERY_RESULT_ITEM_ }; FABRIC_DEPLOYED_APPLICATION_QUERY_RESULT_ITEM_PAGED_LIST_ = new DeployedApplicationPagedList(); FABRIC_DEPLOYED_APPLICATION_QUERY_RESULT_ITEM_PAGED_LIST_.ContinuationToken = "ContinuationToken342741"; FABRIC_DEPLOYED_APPLICATION_QUERY_RESULT_ITEM_PAGED_LIST_.Add(this.random.CreateRandom <DeployedApplication>()); FABRIC_DEPLOYED_APPLICATION_QUERY_RESULT_ITEM_PAGED_LIST_.Add(this.random.CreateRandom <DeployedApplication>()); FABRIC_DEPLOYED_APPLICATION_QUERY_RESULT_ITEM_PAGED_LIST_.Add(this.random.CreateRandom <DeployedApplication>()); // Deployed Service FABRIC_DEPLOYED_SERVICE_REPLICA_QUERY_RESULT_ITEM_ = this.random.CreateRandom <DeployedStatefulServiceReplica>(); FABRIC_DEPLOYED_SERVICE_REPLICA_QUERY_RESULT_ITEM2_ = this.random.CreateRandom <DeployedStatelessServiceInstance>(); FABRIC_DEPLOYED_SERVICE_REPLICA_QUERY_RESULT_ITEM3_ = this.random.CreateRandom <DeployedServiceReplica>(); FABRIC_DEPLOYED_SERVICE_REPLICA_DETAIL_QUERY_RESULT_ITEM_ = this.random.CreateRandom <DeployedStatefulServiceReplicaDetail>(); FABRIC_DEPLOYED_SERVICE_REPLICA_DETAIL_QUERY_RESULT_ITEM2_ = this.random.CreateRandom <DeployedStatelessServiceInstanceDetail>(); // Code Package FABRIC_CODE_PACKAGE_ENTRY_POINT_STATISTICS_ = this.random.CreateRandom <CodePackageEntryPointStatistics>(); FABRIC_CODE_PACKAGE_ENTRY_POINT_ = this.random.CreateRandom <CodePackageEntryPoint>(); FABRIC_DEPLOYED_CODE_PACKAGE_QUERY_RESULT_ITEM_ = this.random.CreateRandom <DeployedCodePackage>(); FABRIC_DEPLOYED_CODE_PACKAGE_QUERY_RESULT_ITEM_LIST_ = new DeployedCodePackageList() { FABRIC_DEPLOYED_CODE_PACKAGE_QUERY_RESULT_ITEM_ }; FABRIC_DEPLOYED_SERVICE_PACKAGE_QUERY_RESULT_ITEM_ = this.random.CreateRandom <DeployedServicePackage>(); // Replicator FABRIC_PRIMARY_REPLICATOR_STATUS_QUERY_RESULT_ = this.random.CreateRandom <PrimaryReplicatorStatus>(); FABRIC_SECONDARY_REPLICATOR_STATUS_QUERY_RESULT_ = this.random.CreateRandom <SecondaryReplicatorStatus>(); // Load FABRIC_LOAD_METRIC_INFORMATION_ = this.random.CreateRandom <LoadMetricInformation>(); FABRIC_LOAD_METRIC_REPORT_ = this.random.CreateRandom <LoadMetricReport>(); FABRIC_NODE_LOAD_METRIC_INFORMATION_ = this.random.CreateRandom <NodeLoadMetricInformation>(); FABRIC_NODE_LOAD_INFORMATION_ = this.random.CreateRandom <NodeLoadInformation>(); FABRIC_PARTITION_LOAD_INFORMATION_ = this.random.CreateRandom <PartitionLoadInformation>(); FABRIC_REPLICA_LOAD_INFORMATION_ = this.random.CreateRandom <ReplicaLoadInformation>(); // Service Group FABRIC_SERVICE_GROUP_TYPE_MEMBER_DESCRIPTION_ = this.random.CreateRandom <ServiceGroupTypeMemberDescription>(); FABRIC_SERVICE_GROUP_MEMBER_TYPE_QUERY_RESULT_ITEM_ = this.random.CreateRandom <ServiceGroupMemberType>(); }