示例#1
0
 public ApplicationUpgradeInstanceOperation(
     int currentApplicationInstanceVersion,
     string applicationTypeName,
     string targetAppTypeVersion,
     string applicationId,
     IDictionary <string, string> userParameters,
     ImageStoreWrapper imageStoreWrapper,
     IEnumerable <IApplicationValidator> validators)
     : base(applicationTypeName, targetAppTypeVersion, applicationId, userParameters, imageStoreWrapper, validators)
 {
     this.currentApplicationInstanceVersion = currentApplicationInstanceVersion;
 }
 public ApplicationCreateInstanceOperation(
     string applicationTypeName,
     string applicationTypeVersion,
     string applicationId,
     Uri nameUri,
     IDictionary <string, string> userParameters,
     ImageStoreWrapper imageStoreWrapper,
     IEnumerable <IApplicationValidator> validators)
     : base(applicationTypeName, applicationTypeVersion, applicationId, userParameters, imageStoreWrapper, validators)
 {
     this.nameUri = nameUri;
 }
        protected ApplicationInstanceOperationBase(
            string applicationTypeName,
            string applicationTypeVersion,
            string applicationId,
            IDictionary <string, string> userParameters,
            ImageStoreWrapper imageStoreWrapper,
            IEnumerable <IApplicationValidator> validators)
        {
            this.ApplicationTypeName    = applicationTypeName;
            this.ApplicationTypeVersion = applicationTypeVersion;
            this.ApplicationId          = applicationId;
            this.UserParameters         = userParameters;

            this.ImageStoreWrapper = imageStoreWrapper;
            this.Validators        = validators;
        }
        public static void CompareAndFixTargetManifestVersionsForUpgrade(
            System.Fabric.Common.ImageModel.StoreLayoutSpecification storeLayoutSpecification,
            ImageStoreWrapper destinationImageStoreWrapper,
            TimeoutHelper timeoutHelper,
            Dictionary <string, Dictionary <string, SettingsType> > settingsType,
            string typeName,
            ApplicationManifestType currentApplicationManifest,
            ApplicationManifestType targetApplicationManifest,
            IList <ServiceManifestType> currentServiceManifests,
            ref IList <ServiceManifestType> targetServiceManifests)
        {
            // Service manifest imports that exist in both current and target.
            var targetServiceManifestImports = targetApplicationManifest.ServiceManifestImport;
            var commonServiceManifestImports = currentApplicationManifest.ServiceManifestImport.Where(
                ci => targetServiceManifestImports.Any(ti => ti.ServiceManifestRef.ServiceManifestName == ci.ServiceManifestRef.ServiceManifestName));

            List <ServiceManifestType> unchangedServiceManifests = new List <ServiceManifestType>();

            foreach (ApplicationManifestTypeServiceManifestImport currentManifestImport in commonServiceManifestImports)
            {
                var currentManifest = currentServiceManifests.FirstOrDefault(item => item.Name == currentManifestImport.ServiceManifestRef.ServiceManifestName);
                var targetManifest  = targetServiceManifests.FirstOrDefault(item => item.Name == currentManifestImport.ServiceManifestRef.ServiceManifestName);
                // TODO: would codepackage versions be different than manifest version?
                var currentManifestVersion = currentManifest.Version;
                var targetManifestVersion  = targetManifest.Version;

                bool equal = ImageBuilderUtility.IsEqual <ServiceManifestType>(
                    ReplaceVersion(currentManifest, "0"), ReplaceVersion(targetManifest, "0"));

                ReplaceVersion(currentManifest, currentManifestVersion);
                ReplaceVersion(targetManifest, targetManifestVersion);

                #region Determine if settings have been changed since last version
                if (equal && settingsType != null)
                {
                    string serviceManifestName = currentManifest.Name;

                    // 1. Check if setting count remains the same
                    int newSettingsTypeCount = 0;
                    if (settingsType.ContainsKey(serviceManifestName))
                    {
                        newSettingsTypeCount = settingsType[serviceManifestName].Count(cp => cp.Key != null);
                    }
                    int currentSettingsTypeCount = 0;
                    if (currentManifest.ConfigPackage != null)
                    {
                        currentSettingsTypeCount = currentManifest.ConfigPackage.Count();
                    }

                    if (newSettingsTypeCount != currentSettingsTypeCount)
                    {
                        equal = false;
                    }

                    // 2. Read settings from each configPackage and compare the value
                    if (equal && currentManifest.ConfigPackage != null)
                    {
                        foreach (var configPackage in currentManifest.ConfigPackage)
                        {
                            SettingsType newSettingsType = null;
                            if (settingsType.ContainsKey(serviceManifestName) && settingsType[serviceManifestName].ContainsKey(configPackage.Name))
                            {
                                newSettingsType = settingsType[serviceManifestName][configPackage.Name];
                            }

                            string       configPackageDirectory = storeLayoutSpecification.GetConfigPackageFolder(typeName, serviceManifestName, configPackage.Name, configPackage.Version);
                            string       settingsFile           = storeLayoutSpecification.GetSettingsFile(configPackageDirectory);
                            SettingsType currentSettingsType    = null;
                            if (destinationImageStoreWrapper.DoesContentExists(settingsFile, timeoutHelper.GetRemainingTime()))
                            {
                                currentSettingsType = destinationImageStoreWrapper.GetFromStore <SettingsType>(settingsFile, timeoutHelper.GetRemainingTime());
                            }

                            equal &= CompareSettingsType(currentSettingsType, newSettingsType);
                            if (!equal)
                            {
                                break;
                            }
                        }
                    }

                    // Code pacakge versions not change for settings upgrade
                    if (!equal)
                    {
                        if (targetManifest.CodePackage != null)
                        {
                            for (int i = 0; i < targetManifest.CodePackage.Count(); ++i)
                            {
                                ReplaceVersion(ref targetManifest.CodePackage[i], currentManifestVersion);
                            }
                        }
                    }
                }
                #endregion

                if (equal)
                {
                    unchangedServiceManifests.Add(currentManifest);
                }
            }

            // Use the unchanged manifests.
            if (unchangedServiceManifests.Count() != 0)
            {
                List <ServiceManifestType> updatedTargetServiceManifests = new List <ServiceManifestType>();
                foreach (var manifest in targetServiceManifests)
                {
                    var unchangedManifest = unchangedServiceManifests.FirstOrDefault(item => item.Name == manifest.Name);
                    if (unchangedManifest != default(ServiceManifestType))
                    {
                        updatedTargetServiceManifests.Add(unchangedManifest);
                        for (int i = 0; i < targetApplicationManifest.ServiceManifestImport.Count(); ++i)
                        {
                            if (targetApplicationManifest.ServiceManifestImport[i].ServiceManifestRef.ServiceManifestName == manifest.Name)
                            {
                                targetApplicationManifest.ServiceManifestImport[i].ServiceManifestRef.ServiceManifestVersion = unchangedManifest.Version;
                                break;
                            }
                        }
                    }
                    else
                    {
                        updatedTargetServiceManifests.Add(manifest);
                    }
                }

                targetServiceManifests = updatedTargetServiceManifests;
            }
        }
 public FabricUpgradeOperation(ImageStoreWrapper storeWrapper)
 {
     this.imageStoreWrapper = storeWrapper;
 }
 public FabricProvisionOperation(XmlReaderSettings validatingXmlReaderSettings, ImageStoreWrapper storeWrapper)
 {
     this.validatingXmlReaderSettings = validatingXmlReaderSettings;
     this.imageStoreWrapper           = storeWrapper;
 }