コード例 #1
0
 protected void RemoveNodeConfiguration(bool deleteLog, bool usingFabricPackage, string machineName)
 {
     try
     {
         ConfigurationDeployer.RemoveNodeConfiguration(
             deleteLog,
             usingFabricPackage ? FabricPackageType.XCopyPackage : FabricPackageType.MSI,
             machineName);
         this.WriteObject(StringResources.Info_RemoveNodeConfigurationSucceeded);
     }
     catch (Exception exception)
     {
         this.ThrowTerminatingError(
             exception,
             Constants.RemoveNodeConfigurationErrorId,
             null);
     }
 }
コード例 #2
0
        protected void NewNodeConfiguration(
            string clusterManifestPath,
            string infrastructureManifestPath,
            string fabricDataRoot,
            string fabricLogRoot,
            PSCredential fabricHostCredential,
            bool runFabricHostServiceAsManual,
            bool removeExistingConfiguration,
            bool usingFabricPackage,
            string fabricPackageRoot,
            string machineName,
            string bootstrapMsiPath)
        {
            try
            {
                string clusterManifestAbsolutePath        = GetAbsolutePath(clusterManifestPath);
                string infrastructureManifestAbsolutePath = GetAbsolutePath(infrastructureManifestPath);

                if (string.IsNullOrEmpty(machineName) || usingFabricPackage)
                {
                    ConfigurationDeployer.NewNodeConfiguration(
                        clusterManifestAbsolutePath,
                        infrastructureManifestAbsolutePath,
                        null,
                        fabricDataRoot,
                        fabricLogRoot,
                        fabricHostCredential == null ? null : fabricHostCredential.UserName,
                        fabricHostCredential == null ? null : fabricHostCredential.Password,
                        runFabricHostServiceAsManual,
                        removeExistingConfiguration,
                        usingFabricPackage ? FabricPackageType.XCopyPackage : FabricPackageType.MSI,
                        fabricPackageRoot,
                        machineName,
                        bootstrapMsiPath);
                    this.WriteObject(StringResources.Info_NewNodeConfigurationSucceeded);
                }
                else
                {
                    WSManConnectionInfo connectionInfo = new WSManConnectionInfo();
                    connectionInfo.ComputerName = machineName;
                    Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo);
                    runspace.Open();
                    using (PowerShell ps = PowerShell.Create())
                    {
                        ps.Runspace = runspace;
                        if (!string.IsNullOrEmpty(clusterManifestAbsolutePath))
                        {
                            ps.AddCommand("New-ServiceFabricNodeConfiguration").AddParameter("ClusterManifestPath", clusterManifestAbsolutePath);
                        }

                        if (!string.IsNullOrEmpty(infrastructureManifestAbsolutePath))
                        {
                            ps.AddParameter("InfrastructureManifestAbsolutePath", infrastructureManifestAbsolutePath);
                        }

                        if (!string.IsNullOrEmpty(fabricDataRoot))
                        {
                            ps.AddParameter("FabricDataRoot", fabricDataRoot);
                        }

                        if (!string.IsNullOrEmpty(fabricLogRoot))
                        {
                            ps.AddParameter("FabricLogRoot", fabricLogRoot);
                        }

                        if (runFabricHostServiceAsManual)
                        {
                            ps.AddParameter("RunFabricHostServiceAsManual");
                        }

                        if (removeExistingConfiguration)
                        {
                            ps.AddParameter("RemoveExistingConfiguration");
                        }

                        if (!string.IsNullOrEmpty(bootstrapMsiPath))
                        {
                            ps.AddParameter("BootstrapMsiPath", bootstrapMsiPath);
                        }

                        if (fabricHostCredential != null)
                        {
                            ps.AddParameter("FabricHostCredential", fabricHostCredential);
                        }

                        var results = ps.Invoke();
                        foreach (PSObject r in results)
                        {
                            this.WriteObject(r);
                        }
                    }

                    runspace.Close();
                }
            }
            catch (Exception exception)
            {
                this.ThrowTerminatingError(
                    exception,
                    Constants.NewNodeConfigurationErrorId,
                    null);
            }
        }