Exemple #1
0
        public async Task <IActionResult> EditDynamic([FromQuery] string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                return(new NotFoundResult());
            }

            var httpClient = httpClientFactory.CreateClient();
            var json       = await httpClient.GetStringAsync(url).ConfigureAwait(false);

            var jsonSchema = JsonSchema.FromSampleJson(json);

            var schema = new SchemaLocation()
            {
                Key    = "_dynamic",
                Schema = jsonSchema.ToJson()
            };

            var model = new EditViewModel
            {
                CmsType          = "_dynamic",
                Id               = Guid.NewGuid(),
                SchemaLocation   = schema,
                CmsConfiguration = schemaService.GetCmsConfiguration(),
                Data             = JsonSerializer.Deserialize <CmsItem>(json)
            };

            return(View(nameof(Edit), model));
        }
Exemple #2
0
        private static XmlSchema LoadSchema(SchemaLocation loc)
        {
            var schemaRes = loc.Assembly.GetManifestResourceStream(loc.ResourceName);

            if (schemaRes == null)
            {
                throw new ArgumentException("Resource '" + loc.ResourceName + "' not found in assembly '"
                                            + loc.Assembly.FullName + "'");
            }
            return(XmlSchema.Read(schemaRes, null));
        }
        private Uri _BuildAbsoluteUri()
        {
            if (_currentUri == null || !_currentUri.IsAbsoluteUri)
            {
                return(null);
            }
            if (SchemaLocation.Segments.All(s => s.Value != RefKeyword.Name &&
                                            s.Value != RecursiveRefKeyword.Name))
            {
                return(null);
            }

            return(new Uri(_currentUri, SchemaLocation.ToString()));
        }
        public static async Task <string> GetServiceFabricExplorerUrl()
        {
            if (await HasValidHttpGatewayUrl())
            {
                return(httpGatewayUrl);
            }

            var tcpClient             = new FabricClient();
            var clusterManifestString = await tcpClient.ClusterManager.GetClusterManifestAsync();

            var manifestType = Utility.ReadXmlString <ClusterManifestType>(
                clusterManifestString,
                SchemaLocation.GetWindowsFabricSchemaLocation());

            var httpGatewayEndpoint = manifestType.NodeTypes.First().Endpoints.HttpGatewayEndpoint;
            var httpGatewayProtocol = httpGatewayEndpoint.Protocol.ToString();
            var httpGatewayPort     = httpGatewayEndpoint.Port;

            return(string.Format(serviceFabricExplorerUrlFormat, httpGatewayProtocol, httpGatewayPort));
        }
Exemple #5
0
        /// <summary>
        /// This method makes sure FabricLogRoot and FabricDataRoot should not be updated through cluster config upgrade.
        /// </summary>
        private void ThrowIfUpdateRoot()
        {
            var currentClusterManifestFile = this.nodeSettings.DeploymentFoldersInfo.CurrentClusterManifestFile;

            if (File.Exists(currentClusterManifestFile))
            {
                // Check if cluster manifest is invalid. See RDBug 14040324.
                string fileContents = string.Empty;
                if (new FileInfo(currentClusterManifestFile).Length == 0 ||
                    new Func <bool>(() =>
                {
                    fileContents = File.ReadAllText(currentClusterManifestFile);
                    return(string.IsNullOrWhiteSpace(fileContents));
                }).Invoke())
                {
                    string errorMsg = string.Format(StringResources.ClusterManifestInvalidDeleting_Formatted, currentClusterManifestFile, fileContents);
                    DeployerTrace.WriteError(errorMsg);
                    File.Delete(currentClusterManifestFile);
                    throw new ClusterManifestValidationException(errorMsg);
                }

                ClusterManifestType currentManifest = XmlHelper.ReadXml <ClusterManifestType>(currentClusterManifestFile, SchemaLocation.GetWindowsFabricSchemaLocation());
                SetupSettings       currentSettings = new SetupSettings(currentManifest);
                SetupSettings       targetSettings  = new SetupSettings(this.clusterManifest);
                if (targetSettings.FabricDataRoot != null && targetSettings.FabricDataRoot != currentSettings.FabricDataRoot)
                {
                    string errorMsg = string.Format(StringResources.UpdateNotAllowed, Constants.ParameterNames.FabricDataRoot);
                    DeployerTrace.WriteError(errorMsg);
                    throw new ClusterManifestValidationException(errorMsg);
                }
                if (targetSettings.FabricLogRoot != null && targetSettings.FabricLogRoot != currentSettings.FabricLogRoot)
                {
                    string errorMsg = string.Format(StringResources.UpdateNotAllowed, Constants.ParameterNames.FabricLogRoot);
                    DeployerTrace.WriteError(errorMsg);
                    throw new ClusterManifestValidationException(errorMsg);
                }
            }
        }
        protected override void OnExecuteOperation(DeploymentParameters parameters, ClusterManifestType targetClusterManifest, Infrastructure infrastructure)
        {
            ClusterManifestType           currentClusterManifest;
            InfrastructureInformationType currentInfrastructureManifest;

            //Powershell Test-ServiceFabricClusterManifest Command
            if (!string.IsNullOrEmpty(parameters.OldClusterManifestLocation))
            {
                currentClusterManifest        = XmlHelper.ReadXml <ClusterManifestType>(parameters.OldClusterManifestLocation, SchemaLocation.GetWindowsFabricSchemaLocation());
                currentInfrastructureManifest = parameters.InfrastructureManifestLocation == null ?
                                                null :
                                                XmlHelper.ReadXml <InfrastructureInformationType>(parameters.InfrastructureManifestLocation, SchemaLocation.GetWindowsFabricSchemaLocation());
            }
            else //Hosting2 Fabric Upgrade Diff Validation
            {
                string currentClusterManifestPath = parameters.DeploymentSpecification.GetCurrentClusterManifestFile(parameters.NodeName);
                string infrastructureManifestPath = parameters.DeploymentSpecification.GetInfrastructureManfiestFile(parameters.NodeName);
                currentClusterManifest        = XmlHelper.ReadXml <ClusterManifestType>(currentClusterManifestPath, SchemaLocation.GetWindowsFabricSchemaLocation());
                currentInfrastructureManifest = XmlHelper.ReadXml <InfrastructureInformationType>(infrastructureManifestPath, SchemaLocation.GetWindowsFabricSchemaLocation());
            }

            //Update to the newest infrastructure
            infrastructure = targetClusterManifest == null ? null : Infrastructure.Create(targetClusterManifest.Infrastructure, currentInfrastructureManifest == null ? null : currentInfrastructureManifest.NodeList, targetClusterManifest.NodeTypes);
            FabricValidatorWrapper.CompareAndAnalyze(currentClusterManifest, targetClusterManifest, infrastructure, parameters);
        }
Exemple #7
0
        private static void ExecuteOperationPrivate(DeploymentParameters parameters)
        {
            DeployerTrace.WriteInfo("Executing {0}", parameters.ToString());
            DeploymentOperation operation = null;

            switch (parameters.Operation)
            {
            case DeploymentOperations.Configure:
                operation = new ConfigureOperation();
                break;

            case DeploymentOperations.ValidateClusterManifest:
                operation = new ValidateClusterManifestOperation();
                break;

            case DeploymentOperations.Create:
                operation = new CreateorUpdateOperation();
                break;

            case DeploymentOperations.Update:
                operation = new CreateorUpdateOperation();
                break;

            case DeploymentOperations.UpdateInstanceId:
                operation = new UpdateInstanceIdOperation();
                break;

            case DeploymentOperations.UpdateNodeState:
                operation = new UpdateNodeStateOperation();
                break;

            case DeploymentOperations.None:
                operation = new RestartOperation();
                break;

            case DeploymentOperations.Remove:
                operation = new RemoveOperation();
                break;

#if !DotNetCoreClrLinux
            case DeploymentOperations.RemoveNodeConfig:
                operation = new RemoveNodeConfigOperation();
                break;
#endif
            case DeploymentOperations.Rollback:
                operation = new RollbackOperation();
                break;

            case DeploymentOperations.Validate:
                operation = new ValidateOperation();
                break;

#if !DotNetCoreClrIOT
            case DeploymentOperations.DockerDnsSetup:
                operation = new DockerDnsSetupOperation();
                break;

            case DeploymentOperations.DockerDnsCleanup:
                operation = new DockerDnsCleanupOperation();
                break;

            case DeploymentOperations.ContainerNetworkSetup:
                operation = new ContainerNetworkSetupOperation();
                break;

            case DeploymentOperations.ContainerNetworkCleanup:
                operation = new ContainerNetworkCleanupOperation();
                break;
#endif
            default:
                throw new ArgumentException(StringResources.Warning_DeploymentOperationCantBeNull);
            }

            ClusterManifestType clusterManifest = parameters.ClusterManifestLocation == null ?
                                                  null :
                                                  XmlHelper.ReadXml <ClusterManifestType>(parameters.ClusterManifestLocation, SchemaLocation.GetWindowsFabricSchemaLocation());

            if (parameters.Operation != DeploymentOperations.Validate &&
                parameters.Operation != DeploymentOperations.ValidateClusterManifest &&
                parameters.Operation != DeploymentOperations.UpdateInstanceId &&
                parameters.Operation != DeploymentOperations.Remove &&
                parameters.Operation != DeploymentOperations.RemoveNodeConfig &&
                parameters.Operation != DeploymentOperations.Rollback &&
                parameters.Operation != DeploymentOperations.DockerDnsSetup &&
                parameters.Operation != DeploymentOperations.DockerDnsCleanup &&
                parameters.Operation != DeploymentOperations.ContainerNetworkSetup &&
                parameters.Operation != DeploymentOperations.ContainerNetworkCleanup &&
                parameters.Operation != DeploymentOperations.None &&
                clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsAzure &&
                parameters.InfrastructureManifestLocation == null)
            {
                throw new ArgumentException("InfrastructureManifestLocation");
            }

            InfrastructureInformationType infrastructureManifest = parameters.InfrastructureManifestLocation == null ?
                                                                   null :
                                                                   XmlHelper.ReadXml <InfrastructureInformationType>(parameters.InfrastructureManifestLocation, SchemaLocation.GetWindowsFabricSchemaLocation());


            Infrastructure infrastructure = clusterManifest == null ? null : Infrastructure.Create(clusterManifest.Infrastructure, infrastructureManifest == null ? null : infrastructureManifest.NodeList, clusterManifest.NodeTypes);
            DeployerTrace.WriteInfo("Running operation {0}", operation.GetType());
#if !DotNetCoreClrLinux
            bool isChangeDeploymentOperationToRemove = false;
#endif

            try
            {
                operation.OnExecuteOperation(parameters, clusterManifest, infrastructure);
            }
            catch (ChangeDeploymentOperationToRemoveException)
            {
#if !DotNetCoreClrLinux
                isChangeDeploymentOperationToRemove = true;
#endif
                DeployerTrace.WriteInfo("Deployment operation modification to remove detected");
            }

#if !DotNetCoreClrLinux
            if (isChangeDeploymentOperationToRemove)
            {
                var infraNode = infrastructure.InfrastructureNodes.SingleOrDefault(n => n.NodeName == parameters.NodeName);
                parameters.DeleteLog             = false;
                parameters.MachineName           = infraNode.IPAddressOrFQDN;
                parameters.DeploymentPackageType = FabricPackageType.XCopyPackage;
                operation = new RemoveNodeConfigOperation();
                DeployerTrace.WriteInfo("Deployment modified to RemoveNodeConfig. New parameters set: parameter.DeleteLog: {0}, parameters.MachineName: {1}, parameters.DeploymentPackageType: {2}",
                                        parameters.DeleteLog,
                                        parameters.MachineName,
                                        parameters.DeploymentPackageType);
                operation.OnExecuteOperation(parameters, clusterManifest, infrastructure);
            }

            if (Utility.GetTestFailDeployer())
            {
                DeployerTrace.WriteInfo("Failing deployment as test hook is found");
                Utility.DeleteTestFailDeployer();
                throw new InvalidDeploymentException(StringResources.Error_FabricDeployer_TestHookFound_Formatted);
            }
#endif
        }
Exemple #8
0
        /// <summary>
        /// This method makes sure FabricLogRoot and FabricDataRoot should not be updated through cluster config upgrade.
        /// </summary>
        private void ThrowIfUpdateRoot()
        {
            var currentClusterManifestFile = this.nodeSettings.DeploymentFoldersInfo.CurrentClusterManifestFile;

            if (File.Exists(currentClusterManifestFile))
            {
                ClusterManifestType currentManifest = XmlHelper.ReadXml <ClusterManifestType>(currentClusterManifestFile, SchemaLocation.GetWindowsFabricSchemaLocation());
                SetupSettings       currentSettings = new SetupSettings(currentManifest);
                SetupSettings       targetSettings  = new SetupSettings(this.clusterManifest);
                if (targetSettings.FabricDataRoot != null && targetSettings.FabricDataRoot != currentSettings.FabricDataRoot)
                {
                    string errorMsg = string.Format(StringResources.UpdateNotAllowed, Constants.ParameterNames.FabricDataRoot);
                    DeployerTrace.WriteError(errorMsg);
                    throw new ClusterManifestValidationException(errorMsg);
                }
                if (targetSettings.FabricLogRoot != null && targetSettings.FabricLogRoot != currentSettings.FabricLogRoot)
                {
                    string errorMsg = string.Format(StringResources.UpdateNotAllowed, Constants.ParameterNames.FabricLogRoot);
                    DeployerTrace.WriteError(errorMsg);
                    throw new ClusterManifestValidationException(errorMsg);
                }
            }
        }
        public void CreateFromFile()
        {
            DeleteTargetFile    = true;
            this.FabricDataRoot = FabricEnvironment.GetDataRoot();
            this.DeploymentSpecification.SetDataRoot(FabricDataRoot);
            SetFabricLogRoot();
            this.DeploymentSpecification.SetLogRoot(this.FabricLogRoot);
            var targetInformationFilePath = Path.Combine(this.FabricDataRoot, Constants.FileNames.TargetInformation);

            if (!File.Exists(targetInformationFilePath))
            {
                this.Operation = DeploymentOperations.None;
                this.ClusterManifestLocation        = Helpers.GetCurrentClusterManifestPath(this.FabricDataRoot);
                this.InfrastructureManifestLocation = Helpers.GetInfrastructureManifestPath(this.FabricDataRoot);
            }
            else
            {
                this.Operation = DeploymentOperations.Create;
                var targetInformation  = XmlHelper.ReadXml <TargetInformationType>(targetInformationFilePath, SchemaLocation.GetWindowsFabricSchemaLocation());
                var targetInstallation = targetInformation.TargetInstallation;
                if (targetInstallation == null)
                {
                    throw new InvalidDeploymentParameterException(StringResources.Error_FabricDeployer_InvalidTargetInstallation_Formatted);
                }

                this.InfrastructureManifestLocation = targetInstallation.InfrastructureManifestLocation;
                this.InstanceId = targetInstallation.InstanceId;
                this.NodeName   = targetInstallation.NodeName;
                if (string.IsNullOrEmpty(this.InfrastructureManifestLocation) && !string.IsNullOrEmpty(this.NodeName))
                {
                    this.InfrastructureManifestLocation = this.DeploymentSpecification.GetInfrastructureManfiestFile(this.NodeName);
                }

                this.TargetVersion           = targetInstallation.TargetVersion;
                this.ClusterManifestLocation = targetInstallation.ClusterManifestLocation;
            }

            if (!string.IsNullOrEmpty(this.ClusterManifestLocation))
            {
                var manifest = XmlHelper.ReadXml <ClusterManifestType>(this.ClusterManifestLocation, SchemaLocation.GetWindowsFabricSchemaLocation());
                var settings = new SetupSettings(manifest);
                this.SkipFirewallConfiguration = settings.SkipFirewallConfiguration;

                SetOptionalFeatureParameters(settings);
            }
        }
        public void Initialize()
        {
            DeploymentOperations operation = Operation;

            if (operation == DeploymentOperations.Create || operation == DeploymentOperations.Update || operation == DeploymentOperations.Configure)
            {
                if (this.ClusterManifestLocation == null || !File.Exists(this.ClusterManifestLocation))
                {
                    throw new InvalidDeploymentParameterException(StringResources.Error_FabricDeployer_ClusterManifestNotFound_Formatted);
                }
            }

            switch (operation)
            {
            case DeploymentOperations.Configure:
            {
                ClusterManifestType manifest = XmlHelper.ReadXml <ClusterManifestType>(this.ClusterManifestLocation, SchemaLocation.GetWindowsFabricSchemaLocation());
                SetupSettings       settings = new SetupSettings(manifest);
                this.FabricDataRoot = settings.FabricDataRoot == null ? this.FabricDataRoot : settings.FabricDataRoot;
                this.FabricLogRoot  = settings.FabricLogRoot == null ? this.FabricLogRoot : settings.FabricLogRoot;
                bool isDataRootProvided = this.FabricDataRoot != null;
                ResolveDataRoot(isDataRootProvided);
                DeploymentSpecification.SetDataRoot(this.FabricDataRoot);
                ResolveLogRoot(isDataRootProvided);
                DeploymentSpecification.SetLogRoot(this.FabricLogRoot);
            }
            break;

            case DeploymentOperations.RemoveNodeConfig:
                // for RemoveNodeConfig the user does not pass the data root in, so it has to be determined
                this.FabricDataRoot = FabricEnvironment.GetDataRoot(this.MachineName);
                this.FabricLogRoot  = FabricEnvironment.GetLogRoot(this.MachineName);
                DeploymentSpecification.SetDataRoot(this.FabricDataRoot);
                DeploymentSpecification.SetLogRoot(this.FabricLogRoot);
                break;

            case DeploymentOperations.Create:
            case DeploymentOperations.None:
            case DeploymentOperations.Remove:
            case DeploymentOperations.Rollback:
            case DeploymentOperations.Update:
            case DeploymentOperations.UpdateNodeState:
            case DeploymentOperations.UpdateInstanceId:
                SetCommonRoots();
                break;

            case DeploymentOperations.ValidateClusterManifest:
                SetCommonRoots(Directory.GetCurrentDirectory());
                break;

            case DeploymentOperations.Validate:
                if (this.OldClusterManifestLocation != null && File.Exists(this.OldClusterManifestLocation) && this.FabricDataRoot == null)
                {
                    SetCommonRoots(Path.GetDirectoryName(this.OldClusterManifestLocation));
                }
                else
                {
                    SetCommonRoots();
                }
                break;

            case DeploymentOperations.DockerDnsSetup:
            case DeploymentOperations.DockerDnsCleanup:
            case DeploymentOperations.ContainerNetworkSetup:
            case DeploymentOperations.ContainerNetworkCleanup:
            case DeploymentOperations.IsolatedNetworkSetup:
            case DeploymentOperations.IsolatedNetworkCleanup:
                break;

            default:
                throw new InvalidOperationException(String.Format("The operation {0} has no explicit deployment criteria.", operation.ToString()));
            }

            if (this.InfrastructureManifestLocation == null && this.NodeName != null)
            {
                this.InfrastructureManifestLocation = this.DeploymentSpecification.GetInfrastructureManfiestFile(this.NodeName);
            }

            if (operation == DeploymentOperations.UpdateNodeState ||
                operation == DeploymentOperations.Remove ||
                operation == DeploymentOperations.UpdateInstanceId ||
                (operation == DeploymentOperations.RemoveNodeConfig && !string.IsNullOrEmpty(this.FabricDataRoot) && Directory.Exists(this.FabricDataRoot)))
            {
                this.ClusterManifestLocation        = Helpers.GetCurrentClusterManifestPath(this.FabricDataRoot);
                this.InfrastructureManifestLocation = Helpers.GetInfrastructureManifestPath(this.FabricDataRoot);
            }

            if (!string.IsNullOrEmpty(this.ClusterManifestLocation))
            {
                ClusterManifestType manifest = XmlHelper.ReadXml <ClusterManifestType>(this.ClusterManifestLocation, SchemaLocation.GetWindowsFabricSchemaLocation());
                SetupSettings       settings = new SetupSettings(manifest);
                this.SkipFirewallConfiguration = settings.SkipFirewallConfiguration;
                this.ContainerDnsSetup         = settings.ContainerDnsSetup;
                this.ContainerNetworkSetup     = settings.ContainerNetworkSetup;
                this.ContainerNetworkName      = settings.ContainerNetworkName;
#if !DotNetCoreClrLinux
                this.SkipContainerNetworkResetOnReboot = settings.SkipContainerNetworkResetOnReboot;
                this.SkipIsolatedNetworkResetOnReboot  = settings.SkipIsolatedNetworkResetOnReboot;
#endif
                this.IsolatedNetworkSetup            = settings.IsolatedNetworkSetup;
                this.IsolatedNetworkName             = settings.IsolatedNetworkName;
                this.IsolatedNetworkInterfaceName    = settings.IsolatedNetworkInterfaceName;
                this.UseContainerServiceArguments    = settings.UseContainerServiceArguments;
                this.ContainerServiceArguments       = settings.ContainerServiceArguments;
                this.EnableContainerServiceDebugMode = settings.EnableContainerServiceDebugMode;

                SetOptionalFeatureParameters(settings);
            }
            else
            {
                this.SkipFirewallConfiguration = false;
            }

            Validate();
        }
        public void CreateFromFile()
        {
            DeleteTargetFile    = true;
            this.FabricDataRoot = FabricEnvironment.GetDataRoot();
            this.DeploymentSpecification.SetDataRoot(FabricDataRoot);
            SetFabricLogRoot();
            this.DeploymentSpecification.SetLogRoot(this.FabricLogRoot);
            var targetInformationFilePath = Path.Combine(this.FabricDataRoot, Constants.FileNames.TargetInformation);

            if (!File.Exists(targetInformationFilePath))
            {
                this.Operation = DeploymentOperations.None;
                this.ClusterManifestLocation        = Helpers.GetCurrentClusterManifestPath(this.FabricDataRoot);
                this.InfrastructureManifestLocation = Helpers.GetInfrastructureManifestPath(this.FabricDataRoot);
            }
            else
            {
                this.Operation = DeploymentOperations.Create;
                var targetInformation  = XmlHelper.ReadXml <TargetInformationType>(targetInformationFilePath, SchemaLocation.GetWindowsFabricSchemaLocation());
                var targetInstallation = targetInformation.TargetInstallation;
                if (targetInstallation == null)
                {
                    throw new InvalidDeploymentParameterException(StringResources.Error_FabricDeployer_InvalidTargetInstallation_Formatted);
                }

                this.InfrastructureManifestLocation = targetInstallation.InfrastructureManifestLocation;
                this.InstanceId = targetInstallation.InstanceId;
                this.NodeName   = targetInstallation.NodeName;
                if (string.IsNullOrEmpty(this.InfrastructureManifestLocation) && !string.IsNullOrEmpty(this.NodeName))
                {
                    this.InfrastructureManifestLocation = this.DeploymentSpecification.GetInfrastructureManfiestFile(this.NodeName);
                }

                this.TargetVersion           = targetInstallation.TargetVersion;
                this.ClusterManifestLocation = targetInstallation.ClusterManifestLocation;
            }

            if (!string.IsNullOrEmpty(this.ClusterManifestLocation))
            {
                var manifest = XmlHelper.ReadXml <ClusterManifestType>(this.ClusterManifestLocation, SchemaLocation.GetWindowsFabricSchemaLocation());
                var settings = new SetupSettings(manifest);
                this.SkipFirewallConfiguration = settings.SkipFirewallConfiguration;

                // Initialize the properties used to reflect state of preview features that need to lightup at runtime
                this.EnableUnsupportedPreviewFeatures = settings.EnableUnsupportedPreviewFeatures;
                this.IsSFVolumeDiskServiceEnabled     = settings.IsSFVolumeDiskServiceEnabled;
            }
        }
Exemple #12
0
        internal void InternalGenerateClusterManifestTest(string clusterConfigPath, string clusterManifestPath)
        {
            MockupJsonModel jsonConfig = Utility.GetJsonConfigFromFile(Path.Combine(Constant.TestDirectory, clusterConfigPath));

            var userConfig      = jsonConfig.GetUserConfig();
            var clusterTopology = jsonConfig.GetClusterTopology();
            var adminConfig     = new MockupAdminConfig();
            var logger          = new MockupTraceLogger();

            List <NodeStatus> nodesStatus = new List <NodeStatus>();

            foreach (NodeDescription node in clusterTopology.Nodes.Values)
            {
                NodeStatus nodeStatus = new NodeStatus()
                {
                    NodeName               = node.NodeName,
                    InstanceId             = 0,
                    NodeDeactivationIntent = WrpNodeDeactivationIntent.Invalid,
                    NodeState              = NodeState.Enabled,
                    NodeType               = node.NodeTypeRef
                };

                nodesStatus.Add(nodeStatus);
            }

            MockupCluster clusterResource = new MockupCluster(adminConfig, userConfig, clusterTopology, logger);
            MockupClusterManifestBuilder mockupClusterManifestBuilder = new MockupClusterManifestBuilder(
                clusterTopology,
                clusterResource.SeedNodeSelector,
                userConfig,
                adminConfig,
                new ClusterNodeConfig(nodesStatus, 2),
                new MockupManifestVersionGenerator(),
                clusterResource.FabricSettingsActivator,
                clusterResource.ClusterManifestGeneratorSettings,
                new MockupTraceLogger());

            var generatedClusterManifest = mockupClusterManifestBuilder.GenerateClusterManifest();
            var expectedClusterManifest  = System.Fabric.Interop.Utility.ReadXml <ClusterManifestType>(Path.Combine(Constant.TestDirectory, clusterManifestPath), SchemaLocation.GetWindowsFabricSchemaLocation());

            Assert.AreEqual(Utility.RemoveRandomGuid(Utility.GetClusterManifestXMLString(generatedClusterManifest)), Utility.RemoveRandomGuid(Utility.GetClusterManifestXMLString(expectedClusterManifest)));
        }
Exemple #13
0
        internal void InternalUpdateClusterManifestTest(string v1clusterConfigPath, string v2clusterConfigPath, string targetClusterManifestPath)
        {
            MockupJsonModel jsonConfig = Utility.GetJsonConfigFromFile(Path.Combine(Constant.TestDirectory, v1clusterConfigPath));

            var userConfig      = jsonConfig.GetUserConfig();
            var clusterTopology = jsonConfig.GetClusterTopology();
            var adminConfig     = new MockupAdminConfig();
            var logger          = new MockupTraceLogger();

            List <NodeStatus> nodesStatus = new List <NodeStatus>();

            foreach (NodeDescription node in clusterTopology.Nodes.Values)
            {
                NodeStatus nodeStatus = new NodeStatus()
                {
                    NodeName               = node.NodeName,
                    InstanceId             = 0,
                    NodeDeactivationIntent = WrpNodeDeactivationIntent.Invalid,
                    NodeState              = NodeState.Enabled,
                    NodeType               = node.NodeTypeRef
                };

                nodesStatus.Add(nodeStatus);
            }

            MockupCluster clusterResource = new MockupCluster(adminConfig, userConfig, clusterTopology, logger);
            MockupClusterManifestBuilder v1mockupClusterManifestBuilder = new MockupClusterManifestBuilder(
                clusterTopology,
                clusterResource.SeedNodeSelector,
                userConfig,
                adminConfig,
                new ClusterNodeConfig(nodesStatus, 2),
                new MockupManifestVersionGenerator(),
                clusterResource.FabricSettingsActivator,
                clusterResource.ClusterManifestGeneratorSettings,
                new MockupTraceLogger());

            MockupJsonModel v2JsonConfig = Utility.GetJsonConfigFromFile(Path.Combine(Constant.TestDirectory, v2clusterConfigPath));
            var             v2generatedClusterManifest = v1mockupClusterManifestBuilder.UpdateClusterManifest(v1mockupClusterManifestBuilder.GenerateClusterManifest(), new MockupAdminConfig().GetFabricSettingsMetadata());

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(ClusterManifestType));

            StringWriter generatedClusterManifestWriter = new StringWriter();

            xmlSerializer.Serialize(generatedClusterManifestWriter, v2generatedClusterManifest);
            string generatedClusterManifestString = generatedClusterManifestWriter.ToString();

            var          targetClusterManifest       = System.Fabric.Interop.Utility.ReadXml <ClusterManifestType>(Path.Combine(Constant.TestDirectory, targetClusterManifestPath), SchemaLocation.GetWindowsFabricSchemaLocation());
            StringWriter targetClusterManifestWriter = new StringWriter();

            xmlSerializer.Serialize(targetClusterManifestWriter, targetClusterManifest);
            string targetClusterManifestString = targetClusterManifestWriter.ToString();

            Assert.AreEqual(Utility.RemoveRandomGuid(generatedClusterManifestString), Utility.RemoveRandomGuid(targetClusterManifestString));
        }
        internal static string GetNodeConfiguration(string machineName)
        {
            string dataRoot = FabricEnvironment.GetDataRoot(machineName);

            if (!Directory.Exists(dataRoot))
            {
                return(null);
            }

            dataRoot = machineName == null || Helpers.IsLocalIpAddress(machineName)
                ? dataRoot
                : Helpers.GetRemotePath(dataRoot, machineName);
            if (!Directory.Exists(dataRoot))
            {
                return(null);
            }

            var stringwriter = new System.IO.StringWriter();
            var serializer   = new XmlSerializer(typeof(ClusterManifestType));

            if (File.Exists(Path.Combine(dataRoot, Constants.TargetInformationFileName)))
            {
                var targetInformation = Utility.ReadXml <TargetInformationType>(Path.Combine(dataRoot, Constants.TargetInformationFileName), SchemaLocation.GetWindowsFabricSchemaLocation());
                if (!string.IsNullOrEmpty(targetInformation.TargetInstallation.ClusterManifestLocation))
                {
                    var clusterManifestLocation = machineName == null ?
                                                  targetInformation.TargetInstallation.ClusterManifestLocation
                        : Helpers.GetRemotePath(targetInformation.TargetInstallation.ClusterManifestLocation, machineName);
                    serializer.Serialize(stringwriter, Utility.ReadXml <ClusterManifestType>(clusterManifestLocation, SchemaLocation.GetWindowsFabricSchemaLocation()));
                    return(stringwriter.ToString());
                }
            }

            string clusterManifestFile = Helpers.GetCurrentClusterManifestPath(dataRoot);

            if (clusterManifestFile != null)
            {
                serializer.Serialize(stringwriter, Utility.ReadXml <ClusterManifestType>(clusterManifestFile, SchemaLocation.GetWindowsFabricSchemaLocation()));
                return(stringwriter.ToString());
            }

            return(null);
        }