コード例 #1
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;
                        }
                    }
                }
            }
        }
コード例 #2
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;
                }
            }
        }