public override async Task <IFabricOperationResult> GetAsync(IOperationDescription description, IOperationContext context)
        {
            Trace.WriteInfo(TraceType, "GetAsync called");
            description.ThrowIfNull(nameof(description));
            context.ThrowIfNull(nameof(context));

            string errorMessage;

            if (!this.ValidObjectType <ServiceOperationDescription>(description, out errorMessage))
            {
                throw new InvalidCastException(errorMessage);
            }

            var     serviceOperationDescription = (ServiceOperationDescription)description;
            Service clusterService = (await this.fabricClient.QueryManager.GetServiceListAsync(
                                          serviceOperationDescription.ApplicationName,
                                          serviceOperationDescription.ServiceName,
                                          context.ContinuationToken,
                                          context.GetRemainingTimeOrThrow(),
                                          context.CancellationToken)).FirstOrDefault();

            var result = new FabricOperationResult()
            {
                OperationStatus = null,
                QueryResult     = new ServiceClientFabricQueryResult(clusterService)
            };

            Trace.WriteInfo(
                TraceType,
                null == clusterService
                    ? "GetAsync: Service not found. Name: {0}."
                    : "GetAsync: Service exists. Name: {0}.",
                serviceOperationDescription.ServiceName);

            if (null == clusterService)
            {
                if (description.OperationType == OperationType.Delete)
                {
                    result.OperationStatus =
                        new ServiceOperationStatus(serviceOperationDescription)
                    {
                        Status       = ResultStatus.Succeeded,
                        Progress     = new JObject(),
                        ErrorDetails = new JObject()
                    };

                    return(result);
                }

                return(null);
            }

            var status       = GetResultStatus(clusterService.ServiceStatus);
            var progress     = new JObject();
            var errorDetails = new JObject(); //TODO: How to get the error details?

            result.OperationStatus =
                new ServiceOperationStatus(serviceOperationDescription)
            {
                Status       = status,
                Progress     = progress,
                ErrorDetails = errorDetails
            };

            return(result);
        }
        public override async Task<IFabricOperationResult> GetAsync(IOperationDescription description, IOperationContext context)
        {
            Trace.WriteInfo(TraceType, "GetAsync called");
            description.ThrowIfNull(nameof(description));
            context.ThrowIfNull(nameof(context));

            string errorMessage;
            if (!this.ValidObjectType<ApplicationOperationDescription>(description, out errorMessage))
            {
                throw new InvalidCastException(errorMessage);
            }

            var appDescription = (ApplicationOperationDescription)description;
            Application clusterApp = (await this.fabricClient.QueryManager.GetApplicationListAsync(
                appDescription.ApplicationUri,
                context.ContinuationToken,
                context.GetRemainingTimeOrThrow(),
                context.CancellationToken)).FirstOrDefault();

            var result = new FabricOperationResult()
            {
                OperationStatus = null,
                QueryResult = new ApplicationFabricQueryResult(clusterApp)
            };

            Trace.WriteInfo(
                TraceType,
                null == clusterApp
                    ? "GetAsync: Application not found. Name: {0}."
                    : "GetAsync: Application exists. Name: {0}.",
                appDescription.ApplicationUri);

            if (null == clusterApp)
            {
                if (description.OperationType == OperationType.Delete)
                {
                    result.OperationStatus =
                        new ApplicationOperationStatus(appDescription)
                        {
                            Status = ResultStatus.Succeeded,
                            Progress = new JObject(),
                            ErrorDetails = new JObject()
                        };

                    return result;
                }

                return null;
            }

            var status = GetResultStatus(clusterApp.ApplicationStatus);
            var progress = new JObject();
            var errorDetails = new JObject();
            if ((clusterApp.ApplicationStatus == ApplicationStatus.Ready && !appDescription.TypeVersion.Equals(clusterApp.ApplicationTypeVersion)) ||
                clusterApp.ApplicationStatus == ApplicationStatus.Upgrading ||
                clusterApp.ApplicationStatus == ApplicationStatus.Failed)
            {
                // TODO: Can deletions end up in a failed state?
                ApplicationUpgradeProgress upgradingApp =
                    await this.fabricClient.ApplicationManager.GetApplicationUpgradeProgressAsync(
                        appDescription.ApplicationUri,
                        context.OperationTimeout,
                        context.CancellationToken);

                if (upgradingApp.UpgradeState == ApplicationUpgradeState.RollingBackCompleted)
                {
                    // clusterApp.ApplicationStatus == ApplicationStatus.Ready

                    status = ResultStatus.Failed;
                    errorDetails = JObject.FromObject(
                        new
                        {
                            FailureReason = upgradingApp.FailureReason.HasValue ? upgradingApp.FailureReason.ToString() : string.Empty,
                            Details = upgradingApp.UpgradeStatusDetails
                        });
                }
                else if (upgradingApp.UpgradeState == ApplicationUpgradeState.RollingForwardCompleted)
                {
                    // clusterApp.ApplicationStatus == ApplicationStatus.Ready

                    status = ResultStatus.Failed;
                    errorDetails = JObject.FromObject(new { Details = $"Deployment completed with {clusterApp.ApplicationTypeVersion} version. Deployment goal was overriden through SF native APIs." });
                }
                else if (upgradingApp.UpgradeState == ApplicationUpgradeState.RollingBackInProgress ||
                         upgradingApp.UpgradeState == ApplicationUpgradeState.RollingForwardInProgress ||
                         upgradingApp.UpgradeState == ApplicationUpgradeState.RollingForwardPending)
                {
                    // clusterApp.ApplicationStatus == ApplicationStatus.Upgrading

                    status = ResultStatus.InProgress;
                    progress = JObject.FromObject(upgradingApp.CurrentUpgradeDomainProgress);
                }
                else if (upgradingApp.UpgradeState == ApplicationUpgradeState.Failed)
                {
                    // clusterApp.ApplicationStatus == ApplicationStatus.Failed

                    status = ResultStatus.Failed;
                    errorDetails = JObject.FromObject(
                        new
                        {
                            FailureReason = upgradingApp.FailureReason.HasValue ? upgradingApp.FailureReason.ToString() : string.Empty,
                            Details = upgradingApp.UpgradeStatusDetails
                        });
                }
            }

            result.OperationStatus = 
                new ApplicationOperationStatus(appDescription)
                {
                    Status = status,
                    Progress = progress,
                    ErrorDetails = errorDetails
                };

            return result;
        }
Beispiel #3
0
        public override async Task <IFabricOperationResult> GetAsync(IOperationDescription description, IOperationContext context)
        {
            Trace.WriteInfo(TraceType, "GetAsync called");
            description.ThrowIfNull(nameof(description));
            context.ThrowIfNull(nameof(context));

            string errorMessage;

            if (!this.ValidObjectType <ApplicationTypeVersionOperationDescription>(description, out errorMessage))
            {
                throw new InvalidCastException(errorMessage);
            }

            var appTypeDescription = (ApplicationTypeVersionOperationDescription)description;
            var clusterAppTypes    = await this.fabricClient.QueryManager.GetApplicationTypeListAsync(
                appTypeDescription.TypeName,
                context.GetRemainingTimeOrThrow(),
                context.CancellationToken);

            var clusterAppType = clusterAppTypes
                                 .FirstOrDefault(a => a.ApplicationTypeVersion == appTypeDescription.TypeVersion);

            var result = new FabricOperationResult()
            {
                OperationStatus = null,
                QueryResult     = new ApplicationTypeFabricQueryResult(clusterAppType)
            };

            Trace.WriteInfo(
                TraceType,
                null == clusterAppType
                    ? "GetAsync: Application type not found. Name: {0}. Version: {1}"
                    : "GetAsync: Application type exists. Name: {0}. Version: {1}",
                appTypeDescription.TypeName,
                appTypeDescription.TypeVersion);

            if (null == clusterAppType)
            {
                if (description.OperationType == OperationType.Delete)
                {
                    result.OperationStatus =
                        new ApplicationTypeVersionOperationStatus(appTypeDescription)
                    {
                        Status       = ResultStatus.Succeeded,
                        Progress     = new JObject(),
                        ErrorDetails = new JObject()
                    };

                    return(result);
                }

                return(null);
            }

            var status       = GetResultStatus(clusterAppType.Status);
            var progress     = JObject.FromObject(new { Details = clusterAppType.StatusDetails });
            var errorDetails = new JObject();

            if (status == ResultStatus.Failed)
            {
                errorDetails = JObject.FromObject(new { Details = clusterAppType.StatusDetails });
            }

            var applicationTypeOperationStatus =
                new ApplicationTypeVersionOperationStatus(appTypeDescription)
            {
                Status       = status,
                Progress     = progress,
                ErrorDetails = errorDetails
            };

            if (status == ResultStatus.Succeeded)
            {
                applicationTypeOperationStatus.DefaultParameterList =
                    new Dictionary <string, string>(clusterAppType.DefaultParameters.AsDictionary());
            }

            result.OperationStatus = applicationTypeOperationStatus;
            return(result);
        }