Ejemplo n.º 1
0
        private bool RequiresContainerGroupSetup(ServicePackageType currentServicePackage, ServicePackageType targetServicePackage)
        {
            bool requiresSetup         = false;
            int  currentContainerCount = 0;
            int  targetContainerCount  = 0;

            foreach (ServicePackageTypeDigestedCodePackage codePackage in currentServicePackage.DigestedCodePackage)
            {
                if (codePackage.CodePackage.EntryPoint.Item is ContainerHostEntryPointType)
                {
                    currentContainerCount++;
                }
            }
            foreach (ServicePackageTypeDigestedCodePackage codePackage in targetServicePackage.DigestedCodePackage)
            {
                if (codePackage.CodePackage.EntryPoint.Item is ContainerHostEntryPointType)
                {
                    targetContainerCount++;
                }
            }
            if (currentContainerCount <= 1 &&
                targetContainerCount > 1)
            {
                requiresSetup = true;
            }
            return(requiresSetup);
        }
Ejemplo n.º 2
0
        private void IntializeTargetPackageWithCurrentRolloutVersion(ServicePackageType currentServicePackage, ServicePackageType targetServicePackage)
        {
            //Set target rolloutversion to current before comparison
            for (int i = 0; i < targetServicePackage.DigestedCodePackage.Length; i++)
            {
                ServicePackageTypeDigestedCodePackage targetDigestedCodePackage = targetServicePackage.DigestedCodePackage[i];

                ServicePackageTypeDigestedCodePackage matchingCurrentDigestedCodePackage = currentServicePackage.DigestedCodePackage.FirstOrDefault(
                    digestedCodePackage => ImageBuilderUtility.Equals(digestedCodePackage.CodePackage.Name, targetDigestedCodePackage.CodePackage.Name));

                if (matchingCurrentDigestedCodePackage != null)
                {
                    targetDigestedCodePackage.RolloutVersion = matchingCurrentDigestedCodePackage.RolloutVersion;
                }
            }

            //Set target rolloutversion for config to current before comparison
            if (targetServicePackage.DigestedConfigPackage != null)
            {
                foreach (ServicePackageTypeDigestedConfigPackage targetDigestedConfigPackage in targetServicePackage.DigestedConfigPackage)
                {
                    ServicePackageTypeDigestedConfigPackage matchingCurrentDigestedConfigPackage = null;
                    if (currentServicePackage.DigestedConfigPackage != null)
                    {
                        matchingCurrentDigestedConfigPackage = currentServicePackage.DigestedConfigPackage.FirstOrDefault(
                            digestedConfigPackage => ImageBuilderUtility.Equals(digestedConfigPackage.ConfigPackage.Name, targetDigestedConfigPackage.ConfigPackage.Name));

                        if (matchingCurrentDigestedConfigPackage != null)
                        {
                            targetDigestedConfigPackage.RolloutVersion = matchingCurrentDigestedConfigPackage.RolloutVersion;
                        }
                    }
                }
            }

            //Set RolloutVersion for matching data packages to be same as current
            if (targetServicePackage.DigestedDataPackage != null)
            {
                foreach (ServicePackageTypeDigestedDataPackage targetDigestedDataPackage in targetServicePackage.DigestedDataPackage)
                {
                    ServicePackageTypeDigestedDataPackage matchingCurrentDigestedDataPackage = null;
                    if (currentServicePackage.DigestedDataPackage != null)
                    {
                        matchingCurrentDigestedDataPackage = currentServicePackage.DigestedDataPackage.FirstOrDefault(
                            digestedDataPackage => ImageBuilderUtility.Equals(digestedDataPackage.DataPackage.Name, targetDigestedDataPackage.DataPackage.Name));

                        if (matchingCurrentDigestedDataPackage != null)
                        {
                            targetDigestedDataPackage.RolloutVersion = matchingCurrentDigestedDataPackage.RolloutVersion;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void UpgradeDeployment()
        {
            string currentPackagePath = this.nodeSettings.DeploymentFoldersInfo.CurrentFabricPackageFile;

            if (!File.Exists(currentPackagePath))
            {
                DeployerTrace.WriteError("Current package file {0} not found. Upgrade can't proceed", currentPackagePath);
                throw new InvalidDeploymentParameterException(StringResources.Error_FabricDeployer_CurrentPackageFileNotFound_Formatted);
            }

            this.GenerateCodeDeployment();
            this.GenerateConfigDeployment();
            this.GenerateDataDeployment();
            ServicePackageType currentServicePackage = XmlHelper.ReadXml <ServicePackageType>(currentPackagePath);

            RolloutVersion updatedRolloutVersion = RolloutVersion.CreateRolloutVersion(currentServicePackage.RolloutVersion).NextMinorRolloutVersion();

            DeployerTrace.WriteNoise("Creating Service Package RolloutVersion = {0}", updatedRolloutVersion);
            this.DeployClusterManifest();
            this.DeploySeedInfoFile();
            this.GenerateAndDeployUnreliableTransportSettings();
            this.GenerateAndDeployFabricPackage(updatedRolloutVersion.ToString());
        }
Ejemplo n.º 4
0
        private void GenerateAndDeployFabricPackage(string rolloutVersion)
        {
            ServicePackageType package = new ServicePackageType();

            package.ManifestVersion       = this.nodeSettings.DeploymentFoldersInfo.versions.ClusterManifestVersion;
            package.Name                  = "Fabric";
            package.RolloutVersion        = rolloutVersion;
            package.DigestedConfigPackage = new ServicePackageTypeDigestedConfigPackage[1];
            package.DigestedDataPackage   = new ServicePackageTypeDigestedDataPackage[1];
            package.DigestedCodePackage   = new ServicePackageTypeDigestedCodePackage[this.servicesToBeDeployed.Length];
            package.DigestedServiceTypes  = new ServicePackageTypeDigestedServiceTypes();
            package.DigestedServiceTypes.RolloutVersion = rolloutVersion;
            package.DigestedServiceTypes.ServiceTypes   = new ServiceTypeType[this.servicesToBeDeployed.Length];
            package.DigestedResources = new ServicePackageTypeDigestedResources();
            package.DigestedResources.RolloutVersion = rolloutVersion;

            package.DigestedConfigPackage[0] = new ServicePackageTypeDigestedConfigPackage();
            package.DigestedConfigPackage[0].RolloutVersion        = rolloutVersion;
            package.DigestedConfigPackage[0].ConfigPackage         = new ConfigPackageType();
            package.DigestedConfigPackage[0].ConfigPackage.Name    = Constants.ConfigName;
            package.DigestedConfigPackage[0].ConfigPackage.Version = this.nodeSettings.DeploymentFoldersInfo.versions.ConfigVersion;

            package.DigestedDataPackage[0] = new ServicePackageTypeDigestedDataPackage();
            package.DigestedDataPackage[0].RolloutVersion      = rolloutVersion;
            package.DigestedDataPackage[0].DataPackage         = new DataPackageType();
            package.DigestedDataPackage[0].DataPackage.Name    = Constants.DataName;
            package.DigestedDataPackage[0].DataPackage.Version = string.Empty;

            int packageIndex = 0;

            foreach (string service in this.servicesToBeDeployed)
            {
                package.DigestedCodePackage[packageIndex] = new ServicePackageTypeDigestedCodePackage();
                package.DigestedCodePackage[packageIndex].RolloutVersion         = rolloutVersion;
                package.DigestedCodePackage[packageIndex].CodePackage            = new CodePackageType();
                package.DigestedCodePackage[packageIndex].CodePackage.Name       = service;
                package.DigestedCodePackage[packageIndex].CodePackage.Version    = string.Empty;
                package.DigestedCodePackage[packageIndex].CodePackage.EntryPoint =
                    new EntryPointDescriptionType
                {
                    Item = new EntryPointDescriptionTypeExeHost
                    {
                        Program       = Constants.ServiceExes[service],
                        Arguments     = null,
                        WorkingFolder = ExeHostEntryPointTypeWorkingFolder.Work
                    }
                };
                package.DigestedServiceTypes.ServiceTypes[packageIndex] = new StatefulServiceTypeType();
                package.DigestedServiceTypes.ServiceTypes[packageIndex].ServiceTypeName = service;
                packageIndex++;
            }

            string packageFilePath = this.nodeSettings.DeploymentFoldersInfo.GetVersionedFabricPackageFile(rolloutVersion);

            DeployerTrace.WriteNoise("Generating the fabric package file at {0}", packageFilePath);
            XmlHelper.WriteXmlExclusive <ServicePackageType>(packageFilePath, package);

            string currentPackageFilePath = this.nodeSettings.DeploymentFoldersInfo.CurrentFabricPackageFile;

            DeployerTrace.WriteInfo("Generating the fabric package file at {0}", currentPackageFilePath);
            XmlHelper.WriteXmlExclusive <ServicePackageType>(currentPackageFilePath, package);
        }
Ejemplo n.º 5
0
        public async Task UpgradeInstaceAsync(string outputFolder, TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            ImageBuilder.TraceSource.WriteInfo(
                TraceType,
                "Starting UpgradeInstace. ApplicationTypeName:{0}, TargetApplicationTypeVersion:{1}, CurrentApplicationInstance:{2}, ApplicationId:{3}, Timeout:{4}",
                this.ApplicationTypeName,
                this.ApplicationTypeVersion,
                this.currentApplicationInstanceVersion,
                this.ApplicationId,
                timeoutHelper.GetRemainingTime());

            StoreLayoutSpecification storeLayoutSpecification = StoreLayoutSpecification.Create();

            // Read the current ApplicationInstance and ApplicationPackage from the store
            string currentApplicationInstanceFile = storeLayoutSpecification.GetApplicationInstanceFile(this.ApplicationTypeName, this.ApplicationId, this.currentApplicationInstanceVersion.ToString(CultureInfo.InvariantCulture));
            ApplicationInstanceType currentApplicationInstanceType = this.ImageStoreWrapper.GetFromStore <ApplicationInstanceType>(currentApplicationInstanceFile, timeoutHelper.GetRemainingTime());

            string currentApplicationPackageFile = storeLayoutSpecification.GetApplicationPackageFile(this.ApplicationTypeName, this.ApplicationId, currentApplicationInstanceType.ApplicationPackageRef.RolloutVersion);
            ApplicationPackageType currentApplicationPackageType = this.ImageStoreWrapper.GetFromStore <ApplicationPackageType>(currentApplicationPackageFile, timeoutHelper.GetRemainingTime());

            // Read the current ServicePackages from the store
            List <Task <ServicePackageType> > getServicePackageTasks = new List <Task <ServicePackageType> >();
            TimeSpan remainingTime = timeoutHelper.GetRemainingTime();

            foreach (ApplicationInstanceTypeServicePackageRef servicePackageRef in currentApplicationInstanceType.ServicePackageRef)
            {
                string currentServicePackageFile = storeLayoutSpecification.GetServicePackageFile(
                    this.ApplicationTypeName,
                    this.ApplicationId,
                    servicePackageRef.Name,
                    servicePackageRef.RolloutVersion);
                var getServicePackageTask = this.ImageStoreWrapper.GetFromStoreAsync <ServicePackageType>(currentServicePackageFile, remainingTime);
                getServicePackageTasks.Add(getServicePackageTask);
            }

            await Task.WhenAll(getServicePackageTasks);

            Collection <ServicePackageType> currentServicePackages = new Collection <ServicePackageType>();

            getServicePackageTasks.ForEach(task => currentServicePackages.Add(task.Result));

            timeoutHelper.ThrowIfExpired();

            ApplicationInstanceContext targetAppInstanceContext = await base.CreateAndSortInstanceAsync(
                currentApplicationInstanceType.Version + 1,
                new Uri(currentApplicationPackageType.NameUri),
                timeoutHelper);

            // Validate the target ApplicationInstance and ServicePackages
            this.ValidateApplicationInstance(targetAppInstanceContext);

            // Update the Rollout version on the target ApplicationInstance
            this.UpdateTargetApplicationPackage(currentApplicationPackageType, targetAppInstanceContext.ApplicationPackage);
            targetAppInstanceContext.ApplicationInstance.ApplicationPackageRef.RolloutVersion = targetAppInstanceContext.ApplicationPackage.RolloutVersion;

            // Update the Rollout version on the target ServicePackages
            foreach (ServicePackageType targetServicePackage in targetAppInstanceContext.ServicePackages)
            {
                ServicePackageType matchingCurrentServicePackageType = currentServicePackages.FirstOrDefault(
                    currentServicePackage => ImageBuilderUtility.Equals(currentServicePackage.Name, targetServicePackage.Name));

                this.UpdateTargetServicePackage(matchingCurrentServicePackageType, targetServicePackage);

                ApplicationInstanceTypeServicePackageRef matchingServicePackageRef = targetAppInstanceContext.ApplicationInstance.ServicePackageRef.First(
                    servicePackageRef => ImageBuilderUtility.Equals(servicePackageRef.Name, targetServicePackage.Name));
                matchingServicePackageRef.RolloutVersion = targetServicePackage.RolloutVersion;
            }

            StoreLayoutSpecification clusterManagerOutputSpecification = null;

            if (outputFolder != null)
            {
                clusterManagerOutputSpecification = StoreLayoutSpecification.Create();
                clusterManagerOutputSpecification.SetRoot(outputFolder);
            }

            timeoutHelper.ThrowIfExpired();

            // Upload the target ApplicationInstance and ServicePackages to the store
            // Also, write the target ApplicationInstance and ServicePackages to the CM output folder
            await this.UploadInstanceAsync(
                targetAppInstanceContext.ApplicationInstance,
                targetAppInstanceContext.ApplicationPackage,
                targetAppInstanceContext.ServicePackages,
                storeLayoutSpecification,
                clusterManagerOutputSpecification,
                false,
                timeoutHelper);

            // Write the current ApplicationInstance and ServicePackages to the CM output folder
            await this.UploadInstanceAsync(
                currentApplicationInstanceType,
                currentApplicationPackageType,
                currentServicePackages,
                null /* Do not upload to store*/,
                clusterManagerOutputSpecification,
                true,
                timeoutHelper);

            ImageBuilder.TraceSource.WriteInfo(
                TraceType,
                "Completed UpgradeInstace. ApplicationTypeName:{0}, TargetApplicationTypeVersion:{1}, CurrentApplicationInstance:{2}, ApplicationId:{3}",
                this.ApplicationTypeName,
                this.ApplicationTypeVersion,
                this.currentApplicationInstanceVersion,
                this.ApplicationId);
        }
Ejemplo n.º 6
0
        private void UpdateTargetServicePackage(ServicePackageType currentServicePackage, ServicePackageType targetServicePackage)
        {
            if (currentServicePackage == null)
            {
                // New ServicePackage added
                return;
            }

            IntializeTargetPackageWithCurrentRolloutVersion(currentServicePackage, targetServicePackage);

            var hasServiceTypesChanged = ImageBuilderUtility.IsNotEqual(
                currentServicePackage.DigestedServiceTypes.ServiceTypes,
                targetServicePackage.DigestedServiceTypes.ServiceTypes);

            var hasResourcesChanged = ImageBuilderUtility.IsNotEqual(
                currentServicePackage.DigestedResources.DigestedEndpoints,
                targetServicePackage.DigestedResources.DigestedEndpoints);

            if (!hasResourcesChanged)
            {
                hasResourcesChanged =
                    ImageBuilderUtility.IsNotEqual(
                        currentServicePackage.DigestedResources.DigestedCertificates,
                        targetServicePackage.DigestedResources.DigestedCertificates);
            }

            var hasDiagnosticsChanged = ImageBuilderUtility.IsNotEqual(
                currentServicePackage.Diagnostics,
                targetServicePackage.Diagnostics);

            var hasCodePackagesChanged = ImageBuilderUtility.IsNotEqual(
                currentServicePackage.DigestedCodePackage,
                targetServicePackage.DigestedCodePackage);

            var hasConfigPackagesChanged = ImageBuilderUtility.IsNotEqual(
                currentServicePackage.DigestedConfigPackage,
                targetServicePackage.DigestedConfigPackage);

            var hasDataPackagesChanged = ImageBuilderUtility.IsNotEqual(
                currentServicePackage.DigestedDataPackage,
                targetServicePackage.DigestedDataPackage);

            var requiresContainerGroupSetup = RequiresContainerGroupSetup(
                currentServicePackage,
                targetServicePackage);

            var isOnDemandActivationImpacted = false;

            if (hasCodePackagesChanged)
            {
                isOnDemandActivationImpacted = this.IsOnDemandCodePackageActivationImapcted(
                    currentServicePackage.DigestedCodePackage,
                    targetServicePackage.DigestedCodePackage);
            }

            // Compute the target RolloutVersion
            var            currentRolloutVersion = RolloutVersion.CreateRolloutVersion(currentServicePackage.RolloutVersion);
            RolloutVersion targetRolloutVersion  = null;

            if (hasResourcesChanged || hasServiceTypesChanged || requiresContainerGroupSetup || isOnDemandActivationImpacted)
            {
                targetRolloutVersion = currentRolloutVersion.NextMajorRolloutVersion();
            }
            else if (hasCodePackagesChanged || hasConfigPackagesChanged || hasDataPackagesChanged || hasDiagnosticsChanged)
            {
                targetRolloutVersion = currentRolloutVersion.NextMinorRolloutVersion();
            }

            // Update the RolloutVersion on the target ServicePackage
            string targetRolloutVerionString = (targetRolloutVersion != null) ? targetRolloutVersion.ToString() : null;

            targetServicePackage.RolloutVersion = (targetRolloutVerionString != null) ? targetRolloutVerionString : currentServicePackage.RolloutVersion;
            targetServicePackage.DigestedServiceTypes.RolloutVersion = hasServiceTypesChanged ? targetRolloutVerionString : currentServicePackage.DigestedServiceTypes.RolloutVersion;
            targetServicePackage.DigestedResources.RolloutVersion    = hasResourcesChanged ? targetRolloutVerionString : currentServicePackage.DigestedResources.RolloutVersion;

            foreach (var targetDigestedCodePackage in targetServicePackage.DigestedCodePackage)
            {
                var matchingCurrentDigestedCodePackage = currentServicePackage.DigestedCodePackage.FirstOrDefault(
                    digestedCodePackage => ImageBuilderUtility.Equals(digestedCodePackage.CodePackage.Name, targetDigestedCodePackage.CodePackage.Name));

                if (matchingCurrentDigestedCodePackage != null)
                {
                    targetDigestedCodePackage.RolloutVersion = hasCodePackagesChanged && ImageBuilderUtility.IsNotEqual(matchingCurrentDigestedCodePackage, targetDigestedCodePackage)
                        ? targetRolloutVerionString
                        : matchingCurrentDigestedCodePackage.RolloutVersion;
                }
                else
                {
                    targetDigestedCodePackage.RolloutVersion = targetRolloutVerionString;
                }
            }

            if (targetServicePackage.DigestedConfigPackage != null)
            {
                foreach (ServicePackageTypeDigestedConfigPackage targetDigestedConfigPackage in targetServicePackage.DigestedConfigPackage)
                {
                    bool hasChanged = true;
                    ServicePackageTypeDigestedConfigPackage matchingCurrentDigestedConfigPackage = null;
                    if (currentServicePackage.DigestedConfigPackage != null)
                    {
                        matchingCurrentDigestedConfigPackage = currentServicePackage.DigestedConfigPackage.FirstOrDefault(
                            digestedConfigPackage => ImageBuilderUtility.Equals(digestedConfigPackage.ConfigPackage.Name, targetDigestedConfigPackage.ConfigPackage.Name));

                        if (matchingCurrentDigestedConfigPackage != null)
                        {
                            if (hasConfigPackagesChanged)
                            {
                                hasChanged = ImageBuilderUtility.IsNotEqual <ServicePackageTypeDigestedConfigPackage>(
                                    matchingCurrentDigestedConfigPackage,
                                    targetDigestedConfigPackage);
                            }
                            else
                            {
                                hasChanged = false;
                            }
                        }
                    }

                    targetDigestedConfigPackage.RolloutVersion = hasChanged ? targetRolloutVerionString : matchingCurrentDigestedConfigPackage.RolloutVersion;
                }
            }

            if (targetServicePackage.DigestedDataPackage != null)
            {
                foreach (ServicePackageTypeDigestedDataPackage targetDigestedDataPackage in targetServicePackage.DigestedDataPackage)
                {
                    bool hasChanged = true;
                    ServicePackageTypeDigestedDataPackage matchingCurrentDigestedDataPackage = null;
                    if (currentServicePackage.DigestedDataPackage != null)
                    {
                        matchingCurrentDigestedDataPackage = currentServicePackage.DigestedDataPackage.FirstOrDefault(
                            digestedDataPackage => ImageBuilderUtility.Equals(digestedDataPackage.DataPackage.Name, targetDigestedDataPackage.DataPackage.Name));

                        if (matchingCurrentDigestedDataPackage != null)
                        {
                            if (hasDataPackagesChanged)
                            {
                                hasChanged = ImageBuilderUtility.IsNotEqual <ServicePackageTypeDigestedDataPackage>(
                                    matchingCurrentDigestedDataPackage,
                                    targetDigestedDataPackage);
                            }
                            else
                            {
                                hasChanged = false;
                            }
                        }
                    }

                    targetDigestedDataPackage.RolloutVersion = hasChanged ? targetRolloutVerionString : matchingCurrentDigestedDataPackage.RolloutVersion;
                }
            }
        }