private async Task <DeployedCodePackageList> GetSystemServiceDummyCodepackagesAsync(
                NodeInfo node,
                ApplicationEntity applicationEntity,
                CancellationToken cancellationToken)
            {
                var presenceOfFmCmNs = await this.GetPresenceOfCodePackagelessSystemServiceAsync(
                    node,
                    applicationEntity,
                    cancellationToken).ConfigureAwait(false);

                var listOfDeployedDummyCodePacks = new DeployedCodePackageList();

                // FM present
                if (presenceOfFmCmNs.Item1)
                {
                    listOfDeployedDummyCodePacks.Add(this.GetDummyDeployedServiceCodepackage(ChaosConstants.DummyFMCodePackageVersion));
                }

                // CM present
                if (presenceOfFmCmNs.Item2)
                {
                    listOfDeployedDummyCodePacks.Add(this.GetDummyDeployedServiceCodepackage(ChaosConstants.DummyCMCodePackageVersion));
                }

                // NS present
                if (presenceOfFmCmNs.Item3)
                {
                    listOfDeployedDummyCodePacks.Add(this.GetDummyDeployedServiceCodepackage(ChaosConstants.DummyNSCodePackageVersion));
                }

                return(listOfDeployedDummyCodePacks);
            }
            private async Task PopulateApplicationEntityAsync(
                ApplicationEntity applicationEntity,
                CancellationToken cancellationToken)
            {
                // Get all services under this application
                var svcListResult = await FabricClientRetryHelper.ExecuteFabricActionWithRetryAsync(
                    () => this.testContext.FabricClient.QueryManager.GetServiceListAsync(
                        applicationEntity.Application.ApplicationName,
                        null,
                        this.requestTimeOut,
                        cancellationToken),
                    this.timer.GetRemainingTime(),
                    cancellationToken).ConfigureAwait(false);

                if (svcListResult != null)
                {
                    GetClusterStateSnapshotAction.ServiceCount += svcListResult.Count;

                    foreach (var svcResultItem in svcListResult)
                    {
                        var serviceEntity = applicationEntity.AddService(svcResultItem);
                        await this.PopulateServiceEntityAsync(serviceEntity, cancellationToken).ConfigureAwait(false);
                    }
                }
            }
            private void PopulateCodepackageWithDeployedPartitions(
                DeployedServiceReplica deployedReplica,
                CodePackageEntity codePackage,
                ApplicationEntity applicationEntity)
            {
                TestabilityTrace.TraceSource.WriteInfo(TraceType, "Inside PopulateCodepackageWithDeployedPartitions");

                var serviceEntity = applicationEntity.ServiceList.FirstOrDefault(s => s.Service.ServiceName == deployedReplica.ServiceName);

                TestabilityTrace.TraceSource.WriteInfo(TraceType, "ServiceEntity: {0}", serviceEntity);

                if (serviceEntity != null)
                {
                    var partitionEntity =
                        serviceEntity.PartitionList.FirstOrDefault(
                            p => p.Guid == deployedReplica.Partitionid);

                    TestabilityTrace.TraceSource.WriteInfo(TraceType, "PartitionEntity: {0}", partitionEntity);

                    if (partitionEntity != null)
                    {
                        codePackage.DeployedPartitions.Add(partitionEntity);

                        TestabilityTrace.TraceSource.WriteInfo(TraceType, "Added partitionEntity: {0} in codepack: {1}", partitionEntity, codePackage);
                    }
                    else
                    {
                        // This would mean that the service for this partition has been deleted and recreated hence the old partition does not exist
                    }
                }
                else
                {
                    // This could mean that the service for this replica has been deleted but the replica is still alive
                }
            }
            private async Task <Tuple <bool, bool, bool> > GetPresenceOfCodePackagelessSystemServiceAsync(
                NodeInfo node,
                ApplicationEntity application,
                CancellationToken cancellationToken)
            {
                var isSystemApplication = ClusterStateSnapshot.IsSystemApplication(application);

                if (!isSystemApplication)
                {
                    return(new Tuple <bool, bool, bool>(false, false, false));
                }

                var deployedSystemReplicaList = await this.GetDeployedSystemServiceReplicaListAsync(node, cancellationToken).ConfigureAwait(false);

                bool isFmPresent = false, isCmPresent = false, isNsPresent = false;

                foreach (var systemReplica in deployedSystemReplicaList)
                {
                    if (!isFmPresent &&
                        systemReplica.ServiceName.OriginalString.Equals(Constants.FailoverManagerServiceName, StringComparison.OrdinalIgnoreCase))
                    {
                        isFmPresent = true;
                    }
                    else if (!isCmPresent &&
                             systemReplica.ServiceName.OriginalString.Equals(Constants.ClusterManagerServiceName, StringComparison.OrdinalIgnoreCase))
                    {
                        isCmPresent = true;
                    }
                    else if (!isNsPresent &&
                             systemReplica.ServiceName.OriginalString.Equals(Constants.NamingServiceName, StringComparison.OrdinalIgnoreCase))
                    {
                        isNsPresent = true;
                    }
                }

                return(new Tuple <bool, bool, bool>(isFmPresent, isCmPresent, isNsPresent));
            }
Example #5
0
 public ServiceEntity(Service service, ApplicationEntity applicationEntity)
 {
     this.Service = service;
     this.ParentApplicationEntity = applicationEntity;
     this.PartitionList           = new List <PartitionEntity>();
 }
Example #6
0
 internal static bool IsSystemApplication(ApplicationEntity app)
 {
     return(app.Application.ApplicationName.OriginalString.Equals(
                Constants.SystemApplicationName,
                StringComparison.OrdinalIgnoreCase));
 }
            private async Task <bool> TryAssociateDeployedReplicaWithDeployedCodepackageAsync(
                NodeInfo node1,
                ApplicationEntity applicationEntity,
                CancellationToken cancellationToken)
            {
                // Handle the case where application is deployed but code package is not
                var retryableErrorsForGetDeployedCodePackageList = new FabricClientRetryErrors();

                // RDBug 5408739: GetDeployedApplicationList found the application;
                // but, by the time GetDeployedCodePackageList was issued, the application is no longer deployed on the node
                retryableErrorsForGetDeployedCodePackageList.RetrySuccessFabricErrorCodes.Add(FabricErrorCode.ApplicationNotFound);

                // RDBug 5420064 : GetDeployed(Application/CodePackage)ListRequest fails with FABRIC_E_INVALID_ADDRESS
                retryableErrorsForGetDeployedCodePackageList.RetryableFabricErrorCodes.Add(FabricErrorCode.InvalidAddress);

                var deployedCodePackageList = await FabricClientRetryHelper.ExecuteFabricActionWithRetryAsync(
                    () => this.testContext.FabricClient.QueryManager.GetDeployedCodePackageListAsync(
                        node1.NodeName,
                        applicationEntity.Application.ApplicationName,
                        string.Empty,
                        string.Empty,
                        this.requestTimeOut,
                        cancellationToken),
                    retryableErrorsForGetDeployedCodePackageList,
                    this.timer.GetRemainingTime(),
                    cancellationToken).ConfigureAwait(false);

                // If FM, CM, or NS replicas are on the node, we add corresponding dummy codepackages in the deployedCodePackageList
                // This is required, because when we want to fault a node, we want to reach the deployed FM/CM/NS replicas through these
                // deployed dummy codepackages
                var listOfDeployedCodePackages = await this.GetSystemServiceDummyCodepackagesAsync(
                    node1,
                    applicationEntity,
                    cancellationToken).ConfigureAwait(false);

                listOfDeployedCodePackages.AddRangeNullSafe(deployedCodePackageList);

                TestabilityTrace.TraceSource.WriteInfo(TraceType, "Deployed codepacks for app entity: {0}...", applicationEntity.Application.ApplicationName.OriginalString);

                if (listOfDeployedCodePackages != null && listOfDeployedCodePackages.Any())
                {
                    foreach (var dcp in listOfDeployedCodePackages)
                    {
                        TestabilityTrace.TraceSource.WriteInfo(TraceType, "Deployed codepack: {0}", dcp.CodePackageName + dcp.ServiceManifestName + dcp.CodePackageVersion);
                    }

                    var deployedReplicaList =
                        await FabricClientRetryHelper.ExecuteFabricActionWithRetryAsync(
                            () =>
                            this.testContext.FabricClient.QueryManager.GetDeployedReplicaListAsync(
                                node1.NodeName,
                                applicationEntity.Application.ApplicationName,
                                string.Empty,
                                Guid.Empty,
                                this.requestTimeOut,
                                cancellationToken),
                            FabricClientRetryErrors.GetDeployedClusterEntityErrors.Value,
                            this.timer.GetRemainingTime(),
                            cancellationToken).ConfigureAwait(false);

                    TestabilityTrace.TraceSource.WriteInfo(TraceType, "Deployed replicas...");

                    foreach (var dr in deployedReplicaList)
                    {
                        TestabilityTrace.TraceSource.WriteInfo(TraceType, "Deployed replica: {0}", dr.ServiceName.OriginalString + dr.Partitionid);
                    }

                    foreach (var dc in listOfDeployedCodePackages)
                    {
                        DeployedCodePackage          deployedCodePackage = dc;
                        DeployedServicePackageHealth spHealth;
                        if (!string.IsNullOrEmpty(deployedCodePackage.ServiceManifestName))
                        {
                            DeployedServicePackageHealthQueryDescription desc = new DeployedServicePackageHealthQueryDescription(applicationEntity.Application.ApplicationName, node1.NodeName, deployedCodePackage.ServiceManifestName, deployedCodePackage.ServicePackageActivationId);

                            spHealth = await FabricClientRetryHelper.ExecuteFabricActionWithRetryAsync <DeployedServicePackageHealth>(
                                () =>
                                this.testContext.FabricClient.HealthManager.GetDeployedServicePackageHealthAsync(desc, this.requestTimeOut, cancellationToken),
                                FabricClientRetryErrors.GetDeployedClusterEntityErrors.Value,
                                this.timer.GetRemainingTime(),
                                cancellationToken).ConfigureAwait(false);
                        }
                        else
                        {
                            spHealth = DefaultDeployedServicePackageHealth;
                        }

                        var codePackage = applicationEntity.AddCodePackage(
                            deployedCodePackage,
                            node1.NodeName,
                            spHealth);

                        foreach (var replica in deployedReplicaList)
                        {
                            string partitionIdentifier = string.Format(ReplicaViewFormat, replica.Partitionid, node1.NodeName, replica.ReplicaStatus);

                            this.PartitionMapFromNodes.Add(partitionIdentifier);

                            DeployedServiceReplica deployedReplica = replica;

                            var isSystemServiceReplicaWithoutCodepackage =
                                string.IsNullOrEmpty(deployedReplica.CodePackageName) &&
                                string.IsNullOrEmpty(deployedReplica.ServiceManifestName);

                            TestabilityTrace.TraceSource.WriteInfo(TraceType, "Deployed replica: {0} isSystemServiceReplicaWithoutCodepackage={1}", deployedReplica.ServiceName.OriginalString + deployedReplica.Partitionid, isSystemServiceReplicaWithoutCodepackage);

                            // Handle FM/CM/NS replica separately, because these
                            // services do not have an actual codepackage
                            if ((isSystemServiceReplicaWithoutCodepackage && this.MatchFmCmNsReplicaWithDummyCodepackage(deployedReplica, deployedCodePackage)) ||
                                (!isSystemServiceReplicaWithoutCodepackage && this.MatchReplicaWithCodepackage(deployedReplica, deployedCodePackage)))
                            {
                                TestabilityTrace.TraceSource.WriteInfo(TraceType, "Deployed replica:{0} is in codepack: {1} so need to add deployed partition to codepack", deployedReplica.ServiceName.OriginalString + deployedReplica.Partitionid, deployedCodePackage.CodePackageName + deployedCodePackage.ServiceManifestName + deployedCodePackage.CodePackageVersion);

                                this.PopulateCodepackageWithDeployedPartitions(deployedReplica, codePackage, applicationEntity);
                            }
                        } // iterate through deployed replicas
                    }     // iterate through deployed codepacks
                }         // if there are deployed codepacks

                return(true);
            }
 // No throw
 // Returns non-null.
 public static Uri ApplicationName(this ApplicationEntity appInfo)
 {
     return(DefaultOnNullException <Uri>(
                () =>
                appInfo.Application.ApplicationName));
 }
 public CodePackageEntity(DeployedCodePackage codePackageResult, string nodeName, ApplicationEntity applicationEntity, DeployedServicePackageHealth health)
 {
     this.CodePackageResult       = codePackageResult;
     this.NodeName                = nodeName;
     this.ParentApplicationEntity = applicationEntity;
     this.DeployedPartitions      = new List <PartitionEntity>();
     this.CodePackageFlags        = ClusterEntityFlags.Excluded;
     this.health = health;
 }