protected async Task <ApplicationInstanceContext> CreateAndSortInstanceAsync(
            int appInstanceVersion,
            Uri nameUri,
            TimeoutHelper timeoutHelper,
            ApplicationTypeContext validatedApplicationTypeContext = null)
        {
            ApplicationTypeContext applicationTypeContext = (validatedApplicationTypeContext == null)
                ? await this.GetApplicationTypeContextAsync(timeoutHelper)
                : validatedApplicationTypeContext;

            IDictionary <string, string> validatedParameters = VaidateAndMergeParameters(this.UserParameters, applicationTypeContext.ApplicationManifest.Parameters);

            ImageBuilder.TraceSource.WriteInfo(
                TraceType,
                "Creating ApplicationInstance, ApplicationPackage and ServicePackages from ApplicationManifest and ServiceManifest. ApplicationTypeName:{0}, ApplicationTypeVersion:{1}.",
                this.ApplicationTypeName,
                this.ApplicationTypeVersion);

            RolloutVersion defaultRolloutVersion = RolloutVersion.CreateRolloutVersion();

            ApplicationInstanceBuilder       applicationInstanceBuilder = new ApplicationInstanceBuilder(applicationTypeContext, validatedParameters, ImageStoreWrapper, timeoutHelper);
            ApplicationPackageType           applicationPackage         = applicationInstanceBuilder.BuildApplicationPackage(this.ApplicationId, nameUri, defaultRolloutVersion.ToString());
            ApplicationInstanceType          applicationInstance        = applicationInstanceBuilder.BuildApplicationInstanceType(this.ApplicationId, nameUri, appInstanceVersion, defaultRolloutVersion.ToString());
            IEnumerable <ServicePackageType> servicePackages            = applicationInstanceBuilder.BuildServicePackage(RolloutVersion.CreateRolloutVersion(appInstanceVersion).ToString());

            // Sort parameterizable elements in ApplicationPackage
            ImageBuilderSorterUtility.SortApplicationPackageType(applicationPackage);

            return(new ApplicationInstanceContext(
                       applicationInstance,
                       applicationPackage,
                       servicePackages,
                       validatedParameters));
        }
Esempio n. 2
0
        public void CreateDeployment()
        {
            this.GenerateCodeDeployment();
            this.GenerateConfigDeployment();
            this.GenerateDataDeployment();
            this.GenerateWorkFolders();
            RolloutVersion rolloutVersion = RolloutVersion.CreateRolloutVersion();

            this.DeployClusterManifest();
            this.DeploySeedInfoFile();
            this.GenerateAndDeployUnreliableTransportSettings();
            this.GenerateAndDeployFabricPackage(rolloutVersion.ToString());
        }
Esempio n. 3
0
        private void UpdateTargetApplicationPackage(ApplicationPackageType currentApplicationPackageType, ApplicationPackageType targetApplicationPackageType)
        {
            bool hasPoliciesChanged = ImageBuilderUtility.IsNotEqual <ApplicationPoliciesType>(
                currentApplicationPackageType.DigestedEnvironment.Policies,
                targetApplicationPackageType.DigestedEnvironment.Policies);

            bool hasPrincipalsChanged = ImageBuilderUtility.IsNotEqual <SecurityPrincipalsType>(
                currentApplicationPackageType.DigestedEnvironment.Principals,
                targetApplicationPackageType.DigestedEnvironment.Principals);

            bool hasDiagnosticsChanged = ImageBuilderUtility.IsNotEqual <DiagnosticsType>(
                currentApplicationPackageType.DigestedEnvironment.Diagnostics,
                targetApplicationPackageType.DigestedEnvironment.Diagnostics);

            bool hasApplicationEnvironmentChanged = hasPoliciesChanged || hasPrincipalsChanged || hasDiagnosticsChanged;

            bool hasSecretsCertificateChanged = ImageBuilderUtility.IsNotEqual <FabricCertificateType>(
                currentApplicationPackageType.DigestedCertificates.SecretsCertificate,
                targetApplicationPackageType.DigestedCertificates.SecretsCertificate);

            bool hasEndpointCertificateChanged =
                ImageBuilderUtility.IsNotEqual <EndpointCertificateType>(
                    currentApplicationPackageType.DigestedCertificates.EndpointCertificate,
                    targetApplicationPackageType.DigestedCertificates.EndpointCertificate);

            // Computer the target RolloutVersion
            RolloutVersion currentRolloutVersion = RolloutVersion.CreateRolloutVersion(currentApplicationPackageType.RolloutVersion);
            RolloutVersion targetRolloutVersion  = currentRolloutVersion;

            if (hasApplicationEnvironmentChanged || hasSecretsCertificateChanged || hasEndpointCertificateChanged)
            {
                targetRolloutVersion = currentRolloutVersion.NextMajorRolloutVersion();
            }

            // Update the RolloutVersion on the target ApplicationInstance
            targetApplicationPackageType.DigestedEnvironment.RolloutVersion =
                hasApplicationEnvironmentChanged ? targetRolloutVersion.ToString() : currentApplicationPackageType.DigestedEnvironment.RolloutVersion;

            targetApplicationPackageType.DigestedCertificates.RolloutVersion =
                (hasSecretsCertificateChanged || hasEndpointCertificateChanged) ? targetRolloutVersion.ToString() : currentApplicationPackageType.DigestedCertificates.RolloutVersion;

            targetApplicationPackageType.RolloutVersion = targetRolloutVersion.ToString();
        }
Esempio n. 4
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());
        }
Esempio n. 5
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;
                }
            }
        }
Esempio n. 6
0
        public static ApplicationInstanceType GetApplicationInstance(BuildLayoutInfo buildLayoutInfo, string applicationId, int applicationInstanceVersion, RolloutVersion rolloutVersion = null)
        {
            string applicationDigestPath   = Path.Combine("Store", buildLayoutInfo.ApplicationManifestType.ApplicationTypeName, "apps", applicationId);
            string applicationInstanceFile = Path.Combine(applicationDigestPath, string.Format("ApplicationInstance.{0}.xml", applicationInstanceVersion));

            return(buildLayoutInfo.ImageStoreWrapper.GetFromStore <ApplicationInstanceType>(applicationInstanceFile, TestUtility.ImageStoreDefaultTimeout));
        }
Esempio n. 7
0
        public static void VerifyApplicationDigestLayout(BuildLayoutInfo buildLayoutInfo, string applicationId, int applicationInstanceVersion, RolloutVersion rolloutVersion)
        {
            string applicationDigestPath = Path.Combine("Store", buildLayoutInfo.ApplicationManifestType.ApplicationTypeName, "apps", applicationId);

            string applicationInstanceFile = Path.Combine(applicationDigestPath, string.Format("ApplicationInstance.{0}.xml", applicationInstanceVersion));

            Assert.IsTrue(buildLayoutInfo.ImageStore.DoesContentExist(applicationInstanceFile, TimeSpan.MaxValue));

            string applicationPackageFile = Path.Combine(applicationDigestPath, string.Format("ApplicationPackage.{0}.xml", rolloutVersion));

            Assert.IsTrue(buildLayoutInfo.ImageStore.DoesContentExist(applicationPackageFile, TimeSpan.MaxValue));

            foreach (var serviceManifestType in buildLayoutInfo.ServiceManifestTypes)
            {
                string servicePackageFile = Path.Combine(applicationDigestPath, string.Format("{0}.Package.{1}.xml", serviceManifestType.Name, rolloutVersion));
                Assert.IsTrue(buildLayoutInfo.ImageStore.DoesContentExist(servicePackageFile, TimeSpan.MaxValue));
            }
        }