public void UpgradeFabric(
            string currentFabricVersion,
            string targetFabricVersion,
#if !DotNetCoreClrLinux && !DotNetCoreClrIOT
            string configurationCsvFilePath,
#endif
            TimeSpan timeout,
            out bool isConfigOnly)
        {
            isConfigOnly = false;

            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            ImageBuilder.TraceSource.WriteInfo(
                TraceType,
                "UpgradeFabric started: CurrentFabricVersion:{0}, TargetFabricVersion:{1}, Timeout:{2}",
                currentFabricVersion,
                targetFabricVersion,
                timeoutHelper.GetRemainingTime());

            // If the current version is invalid (ie. Cluster FabricVersion is not determined)
            // then do not validate
            if (ImageBuilderUtility.Equals(currentFabricVersion, FabricVersion.Invalid.ToString()))
            {
                return;
            }

            FabricVersion currentVersion, targetVersion;

            bool isValid = FabricVersion.TryParse(currentFabricVersion, out currentVersion);

            if (!isValid)
            {
                ImageBuilderUtility.TraceAndThrowValidationError(
                    TraceType,
                    StringResources.ImageBuilderError_InvalidValue,
                    "CurrentFabricVersion",
                    currentFabricVersion);
            }

            isValid = FabricVersion.TryParse(targetFabricVersion, out targetVersion);
            if (!isValid)
            {
                ImageBuilderUtility.TraceAndThrowValidationError(
                    TraceType,
                    StringResources.ImageBuilderError_InvalidValue,
                    "TargetFabricVersion",
                    targetFabricVersion);
            }

            WinFabStoreLayoutSpecification winFabLayout = WinFabStoreLayoutSpecification.Create();
            string currentClusterManifestPath           = winFabLayout.GetClusterManifestFile(currentVersion.ConfigVersion);
            string targetClusterManifestPath            = winFabLayout.GetClusterManifestFile(targetVersion.ConfigVersion);

            ClusterManifestType currentClusterManifest = this.imageStoreWrapper.GetFromStore <ClusterManifestType>(currentClusterManifestPath, timeoutHelper.GetRemainingTime());
            ClusterManifestType targetClusterManifest  = this.imageStoreWrapper.GetFromStore <ClusterManifestType>(targetClusterManifestPath, timeoutHelper.GetRemainingTime());

            timeoutHelper.ThrowIfExpired();

            try
            {
                // todo: Vaishnav to pass node list object loaded from the location
                FabricValidator fabricValidator = FabricValidator.Create(currentClusterManifest, null, new WindowsFabricSettings(currentClusterManifest), DeploymentOperations.Update);
                IEnumerable <KeyValuePair <string, string> > modifiedStaticSettings = fabricValidator.CompareAndAnalyze(targetClusterManifest, null /*Detect changes for any NodeType*/);
                isConfigOnly = !modifiedStaticSettings.Any();
            }
            catch (Exception e)
            {
                ImageBuilderUtility.TraceAndThrowValidationError(
                    TraceType,
                    StringResources.ImageBuilderError_InvalidConfigFabricUpgrade,
                    e.ToString(),
                    currentFabricVersion,
                    targetFabricVersion);
            }

            ImageBuilder.TraceSource.WriteInfo(
                TraceType,
                "UpgradeFabric completed: CurrentFabricVersion:{0}, TargetFabricVersion:{1}, ConfigOnly:{2}",
                currentFabricVersion,
                targetFabricVersion,
                isConfigOnly);
        }
        public void ProvisionFabric(
            string localCodePath,
            string localConfigPath,
#if !DotNetCoreClrLinux && !DotNetCoreClrIOT
            string configurationCsvFilePath,
#endif
            string infrastructureManifestFilePath,
            bool validateOnly,
            TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

#if DotNetCoreClrLinux || DotNetCoreClrIOT
            ImageBuilder.TraceSource.WriteInfo(
                TraceType,
                "Starting ProvisionFabric. CodePath:{0}, ConfigPath:{1}, InfrastructureManifestFilePath:{2}, Timeout:{3}",
                localCodePath,
                localConfigPath,
                infrastructureManifestFilePath,
                timeoutHelper.GetRemainingTime());
#else
            ImageBuilder.TraceSource.WriteInfo(
                TraceType,
                "Starting ProvisionFabric. CodePath:{0}, ConfigPath:{1}, ConfigurationCsvFilePath:{2}, InfrastructureManifestFilePath:{3}, Timeout:{4}",
                localCodePath,
                localConfigPath,
                configurationCsvFilePath,
                infrastructureManifestFilePath,
                timeoutHelper.GetRemainingTime());
#endif

            // TODO: Once FabricTest has been modified to generate InfrastructureManifest.xml file, we should not
            // allow InfrastructureManifest file to be optional
            if (string.IsNullOrEmpty(infrastructureManifestFilePath) || !FabricFile.Exists(infrastructureManifestFilePath))
            {
                infrastructureManifestFilePath = null;
                ImageBuilder.TraceSource.WriteWarning(
                    TraceType,
                    "The InfrastrucutreManifestFile:{0} is not found",
                    infrastructureManifestFilePath);
            }

            string codeVersion = string.Empty, clusterManifestVersion = string.Empty;

            if (!string.IsNullOrEmpty(localCodePath))
            {
                codeVersion = GetCodeVersion(localCodePath);
            }

            if (!string.IsNullOrEmpty(localConfigPath))
            {
                try
                {
                    var parameters = new Dictionary <string, dynamic>
                    {
                        { DeploymentParameters.ClusterManifestString, localConfigPath },
                        { DeploymentParameters.InfrastructureManifestString, infrastructureManifestFilePath }
                    };

                    var deploymentParameters = new DeploymentParameters();
                    deploymentParameters.SetParameters(parameters, DeploymentOperations.ValidateClusterManifest);
                    DeploymentOperation.ExecuteOperation(deploymentParameters);
                }
                catch (Exception e)
                {
                    ImageBuilderUtility.TraceAndThrowValidationError(
                        FabricProvisionOperation.TraceType,
                        StringResources.ImageBuilderError_ClusterManifestValidationFailed,
                        e.ToString(),
                        localConfigPath);
                }
            }

            if (!validateOnly)
            {
                timeoutHelper.ThrowIfExpired();

                WinFabStoreLayoutSpecification winFabLayout = WinFabStoreLayoutSpecification.Create();
                if (!string.IsNullOrEmpty(localCodePath))
                {
                    // Upload MSP file
                    string destinationCodePath;
                    if (ImageBuilderUtility.IsInstaller(localCodePath))
                    {
                        destinationCodePath = winFabLayout.GetPatchFile(codeVersion);
                    }
                    else if (ImageBuilderUtility.IsCabFile(localCodePath))
                    {
                        // Upload CAB file
                        destinationCodePath = winFabLayout.GetCabPatchFile(codeVersion);
                    }
                    else
                    {
                        destinationCodePath = winFabLayout.GetCodePackageFolder(codeVersion);
                    }

                    this.imageStoreWrapper.UploadContent(destinationCodePath, localCodePath, timeoutHelper.GetRemainingTime());
                }

                ClusterManifestType clusterManifest = null;
                if (!string.IsNullOrEmpty(localConfigPath))
                {
                    clusterManifest        = ImageBuilderUtility.ReadXml <ClusterManifestType>(localConfigPath, this.validatingXmlReaderSettings);
                    clusterManifestVersion = clusterManifest.Version;
                }

                if (clusterManifest != null)
                {
                    // Upload ClusterManifest file

                    ReplaceDefaultImageStoreConnectionString(clusterManifest);

                    string destinationConfigPath = winFabLayout.GetClusterManifestFile(clusterManifestVersion);
                    imageStoreWrapper.SetToStore <ClusterManifestType>(destinationConfigPath, clusterManifest, timeoutHelper.GetRemainingTime());
                }
            }

#if DotNetCoreClrLinux || DotNetCoreClrIOT
            ImageBuilder.TraceSource.WriteInfo(
                TraceType,
                "Completed ProvisionFabric. CodePath:{0}, ConfigPath:{1}",
                localCodePath,
                localConfigPath);
#else
            ImageBuilder.TraceSource.WriteInfo(
                TraceType,
                "Completed ProvisionFabric. CodePath:{0}, ConfigPath:{1}, ConfigurationCsvFilePath:{2}",
                localCodePath,
                localConfigPath,
                configurationCsvFilePath);
#endif
        }