Example #1
0
 /// <summary>
 /// Converts the specified cluster connection into a generic cluster connection type.
 /// </summary>
 /// <typeparam name="T">The type of the cluster connection.</typeparam>
 /// <param name="clusterConnection">The cluster connection.</param>
 /// <returns>The generic typed cluster connection instance.</returns>
 public static T?As <T>(this IClusterConnection clusterConnection)
     where T : class, IClusterConnection => clusterConnection is T result ? result : null;
        private void GetImageStoreContentByAppVersionImpl(
            List <ImageStoreFile> sourceFiles,
            List <ImageStoreFolder> sourceFolders,
            List <ImageStoreFile> targetFiles,
            List <ImageStoreFolder> targetFolders,
            string version,
            IImageStore imageStore,
            StoreLayoutSpecification storeLayoutSpecification,
            IClusterConnection clusterConnection,
            TimeoutHelper helper)
        {
            Action <string, string, string, string, bool> updateStoreInfo = (string path, string serviceName, string serviceVersion, string appVersion, bool isFile) =>
            {
                if (isFile)
                {
                    var existingFile = (from file in targetFiles
                                        where string.Compare(file.StoreRelativePath, path, StringComparison.OrdinalIgnoreCase) == 0
                                        select file).FirstOrDefault();

                    if (existingFile != null)
                    {
                        existingFile.VersionInfo.ConfigVersionInfo(serviceName, serviceVersion, appVersion);
                    }
                    else
                    {
                        existingFile = (from file in sourceFiles
                                        where string.Compare(file.StoreRelativePath, path, StringComparison.OrdinalIgnoreCase) == 0
                                        select file).FirstOrDefault();

                        if (existingFile != null)
                        {
                            existingFile.VersionInfo.ConfigVersionInfo(serviceName, serviceVersion, appVersion);
                            targetFiles.Add(existingFile);
                        }
                        else
                        {
                            throw new ArgumentException(StringResources.Error_ImageStoreRelativePathNotExist);
                        }
                    }
                }
                else
                {
                    var existingFolder = (from folder in targetFolders
                                          where string.Compare(folder.StoreRelativePath, path, StringComparison.OrdinalIgnoreCase) == 0
                                          select folder).FirstOrDefault();

                    if (existingFolder != null)
                    {
                        existingFolder.VersionInfo.ConfigVersionInfo(serviceName, serviceVersion, appVersion);
                    }
                    else
                    {
                        existingFolder = (from folder in sourceFolders
                                          where string.Compare(folder.StoreRelativePath, path, StringComparison.OrdinalIgnoreCase) == 0
                                          select folder).FirstOrDefault();

                        if (existingFolder != null)
                        {
                            existingFolder.VersionInfo.ConfigVersionInfo(serviceName, serviceVersion, appVersion);
                            targetFolders.Add(existingFolder);
                        }
                        else
                        {
                            throw new ArgumentException(StringResources.Error_ImageStoreRelativePathNotExist);
                        }
                    }
                }
            };

            if (helper != null)
            {
                helper.ThrowIfExpired();
            }

            var    foldersPath             = new Dictionary <string, Tuple <string, string> >();
            string applicationManifestPath = storeLayoutSpecification.GetApplicationManifestFile(this.ApplicationTypeName, version);

            updateStoreInfo(applicationManifestPath, string.Empty, string.Empty, version, true);
            var serviceTypeList = clusterConnection.GetServiceTypeListAsync(this.ApplicationTypeName, version, null, this.GetTimeout(), this.GetCancellationToken()).Result;

            foreach (var serviceType in serviceTypeList)
            {
                if (helper != null)
                {
                    helper.ThrowIfExpired();
                }

                string serviceManifestPath = storeLayoutSpecification.GetServiceManifestFile(this.ApplicationTypeName, serviceType.ServiceManifestName, serviceType.ServiceManifestVersion);
                updateStoreInfo(serviceManifestPath, serviceType.ServiceManifestName, serviceType.ServiceManifestVersion, version, true);
                if (helper != null)
                {
                    helper.ThrowIfExpired();
                }

                string serviceManifestChecksumPath = storeLayoutSpecification.GetServiceManifestChecksumFile(this.ApplicationTypeName, serviceType.ServiceManifestName, serviceType.ServiceManifestVersion);
                updateStoreInfo(serviceManifestChecksumPath, serviceType.ServiceManifestName, serviceType.ServiceManifestVersion, version, true);
                string localPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), serviceManifestPath.Substring(serviceManifestPath.LastIndexOf(@"\") + 1));
                try
                {
                    if (helper != null)
                    {
                        helper.ThrowIfExpired();
                        imageStore.DownloadContent(serviceManifestPath, localPath, helper.GetRemainingTime(), CopyFlag.AtomicCopy);
                    }
                    else
                    {
                        imageStore.DownloadContent(serviceManifestPath, localPath, this.GetTimeout(), CopyFlag.AtomicCopy);
                    }

                    foreach (var packagePath in this.GetPackagesPath(localPath, storeLayoutSpecification))
                    {
                        updateStoreInfo(packagePath, serviceType.ServiceManifestName, serviceType.ServiceManifestVersion, version, false);
                        updateStoreInfo(string.Format("{0}.{1}", packagePath, ChecksumFileExtension), serviceType.ServiceManifestName, serviceType.ServiceManifestVersion, version, true);
                    }
                }
                catch (Exception exception)
                {
                    this.ThrowTerminatingError(exception, Constants.GetImageStoreContentErrorId, null);
                }
                finally
                {
                    File.Delete(localPath);
                }
            }
        }
Example #3
0
 internal abstract Task <RestartDeployedCodePackageResult> InvokeCommandAsync(
     IClusterConnection clusterConnection,
     Uri uri,
     ReplicaSelector replicaSelector);
        private void GetAllPagesImpl(ComposeDeploymentStatusQueryDescription queryDescription, IClusterConnection clusterConnection)
        {
            bool   morePages = true;
            string currentContinuationToken = queryDescription.ContinuationToken;

            while (morePages)
            {
                // Override continuation token
                queryDescription.ContinuationToken = currentContinuationToken;

                var queryResult = clusterConnection.GetComposeDeploymentStatusPagedListAsync(
                    queryDescription,
                    this.GetTimeout(),
                    this.GetCancellationToken()).Result;

                foreach (var item in queryResult)
                {
                    this.WriteObject(this.FormatOutput(item));
                }

                morePages = Helpers.ResultHasMorePages(this, queryResult.ContinuationToken, out currentContinuationToken);
            }
        }
Example #5
0
 /// <summary>
 /// The invoke command async.
 /// </summary>
 /// <param name="clusterConnection">
 /// The cluster connection.
 /// </param>
 /// <param name="replicaSelector">
 /// The replica selector.
 /// </param>
 /// <param name="completionMode">
 /// The completion mode.
 /// </param>
 /// <param name="cancellationToken">
 /// The cancellation token.
 /// </param>
 /// <returns>
 /// The <see cref="Task"/>.
 /// </returns>
 internal abstract Task <ReplicaResult> InvokeCommandAsync(
     IClusterConnection clusterConnection,
     ReplicaSelector replicaSelector,
     CompletionMode completionMode,
     CancellationToken cancellationToken);
Example #6
0
 public abstract Task <ClusterJob> SubmitJobAsync(IClusterConnection connection, IEnumerable <KeyValuePair <string, object> > properties, CancellationToken cancellationToken = default);
 internal InternalClusterConnection(
     IClusterConnection connection)
 {
     this.connection = connection;
 }
Example #8
0
 public abstract Task <ClusterState> GetStateAsync(IClusterConnection connection, CancellationToken cancellationToken = default);
Example #9
0
 public abstract Task <ClusterJob> GetJobAsync(IClusterConnection connection, string localJobId, CancellationToken cancellation = default);
Example #10
0
 public Register(IClusterConnection clusterConnection, ILogOutput logger)
     : base(clusterConnection, logger)
 {
 }
Example #11
0
 protected BaseEndpoint(IClusterConnection clusterConnection, ILogOutput logger)
 {
     ClusterConnection = clusterConnection;
     Logger            = logger;
 }
Example #12
0
        internal void ReportHealth(HealthReport healthReport, HealthReportSendOptions sendOptions, IClusterConnection clusterConnection)
        {
            try
            {
                /// Warn user if health report will not be sent immediately.
                this.WarnIfHealthReportBatchingOn(clusterConnection);

                /// Sending the healthReport received from derived class to cluster-health-manager service.
                clusterConnection.ReportHealth(healthReport, sendOptions);
            }
            catch (Exception anyException)
            {
                this.ThrowTerminatingError(
                    anyException,
                    this.SendHealthReportErrorId,
                    clusterConnection);
            }
        }