예제 #1
0
        public static int Main(string[] args)
        {
            string argsString = string.Join(" ", args);

            try
            {
                DeployerTrace.WriteInfo("Deployer called with {0}", argsString);
                DeploymentParameters parameters = CommandLineInfo.Parse(args);
                DeploymentOperation.ExecuteOperation(parameters, false);
                return(Constants.ErrorCode_Success);
            }
            catch (FabricHostRestartRequiredException e)
            {
                DeployerTrace.WriteInfo(e.ToString());
                return(Constants.ErrorCode_RestartRequired);
            }
            catch (FabricHostRestartNotRequiredException e)
            {
                DeployerTrace.WriteInfo(e.ToString());
                return(Constants.ErrorCode_RestartNotRequired);
            }
            catch (Exception e)
            {
                DeployerTrace.WriteError("Deployer failed with args: {0}", argsString);
                DeployerTrace.WriteError(e.ToString());
                return(Constants.ErrorCode_Failure);
            }
        }
예제 #2
0
        private static void RemoveNodeConfigurationInner(bool deleteLog, FabricPackageType fabricPackageType, string machineName)
        {
            var parameters = new Dictionary <string, dynamic>
            {
                { DeploymentParameters.MachineNameString, machineName }
            };

            // Create DeploymentParameters object with conditional retrieval of FabricBinRoot (to work around infinite recursion due to invalid reflection)
            bool setBinRoot           = fabricPackageType != FabricPackageType.XCopyPackage;
            var  deploymentParameters = new DeploymentParameters(setBinRoot);

            deploymentParameters.DeleteLog             = deleteLog;
            deploymentParameters.DeploymentPackageType = fabricPackageType;
            deploymentParameters.SetParameters(parameters, DeploymentOperations.RemoveNodeConfig);

            try
            {
                DeploymentOperation.ExecuteOperation(deploymentParameters);
            }
            catch (Exception e)
            {
                DeployerTrace.WriteError("{0}", e.ToString());
                throw;
            }
        }
        private void ValidateClusterManifest(string clusterManifestFilePath, bool exceptionExcpected)
        {
            bool exceptionFound = false;

            try
            {
                DeploymentParameters parameters = new DeploymentParameters();
                parameters.SetParameters(new Dictionary <string, dynamic>()
                {
                    { DeploymentParameters.ClusterManifestString, clusterManifestFilePath },
                    { DeploymentParameters.FabricDataRootString, "TestFabricDataRoot" }
                },
                                         DeploymentOperations.ValidateClusterManifest);
                DeploymentOperation.ExecuteOperation(parameters);
            }
            catch (Exception e)
            {
                DeployerTrace.WriteInfo("Test", "ValidateClusterManifest failed with exception {0}", e);
                exceptionFound = true;
            }
            Verify.AreEqual(exceptionExcpected, exceptionFound);
        }
예제 #4
0
 public static void ExecuteOperation(DeploymentParameters parameters)
 {
     DeploymentOperation.ExecuteOperation(parameters, true);
 }
예제 #5
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
        }
예제 #6
0
        private static void NewNodeConfigurationInner(
            string clusterManifestPath,
            string infrastructureManifestPath,
            string jsonClusterConfigPath,
            string fabricDataRoot,
            string fabricLogRoot,
            string fabricHostCredentialUser,
            SecureString fabricHostCredentialPassword,
            bool runFabricHostServiceAsManual,
            bool removeExistingConfiguration,
            FabricPackageType fabricPackageType,
            string fabricPackageRoot,
            string machineName,
            string bootstrapPackagePath)
        {
            if (!string.IsNullOrEmpty(machineName))
            {
                if (!string.IsNullOrEmpty(fabricHostCredentialUser) || fabricHostCredentialPassword != null)
                {
                    throw new InvalidOperationException(StringResources.Error_RemoteNodeConfigNotSupportedWithCredential);
                }
            }

            // Delete the registry value used for RemoveNodeConfiguration if it is present
            if (fabricPackageType == FabricPackageType.MSI)
            {
                RemoveNodeConfigOperation.DeleteRemoveNodeConfigurationRegistryValue(machineName);
            }

            if (removeExistingConfiguration)
            {
                RemoveNodeConfigurationInner(true, fabricPackageType, machineName);
            }

            var parameters = new Dictionary <string, dynamic>
            {
                { DeploymentParameters.ClusterManifestString, clusterManifestPath },
                { DeploymentParameters.InfrastructureManifestString, infrastructureManifestPath },
                { DeploymentParameters.FabricDataRootString, fabricDataRoot },
                { DeploymentParameters.FabricLogRootString, fabricLogRoot }
            };

            if (fabricHostCredentialUser != null)
            {
                parameters.Add(DeploymentParameters.RunAsUserNameString, fabricHostCredentialUser);
            }

            if (jsonClusterConfigPath != null)
            {
                parameters.Add(DeploymentParameters.JsonClusterConfigLocationString, jsonClusterConfigPath);
            }

            if (fabricHostCredentialPassword != null)
            {
                parameters.Add(DeploymentParameters.RunAsPaswordString, fabricHostCredentialPassword);
            }

            if (machineName != null)
            {
                parameters.Add(DeploymentParameters.MachineNameString, machineName);
            }

            if (fabricPackageRoot != null)
            {
                parameters.Add(DeploymentParameters.FabricPackageRootString, fabricPackageRoot);
            }

            if (runFabricHostServiceAsManual)
            {
                parameters.Add(DeploymentParameters.ServiceStartupTypeString, FabricDeployerServiceController.ServiceStartupType.Manual.ToString());
            }

            if (bootstrapPackagePath != null)
            {
                parameters.Add(DeploymentParameters.BootstrapMSIPathString, bootstrapPackagePath);
            }

            // Create DeploymentParameters object with conditional retrieval of FabricBinRoot (to work around infinite recursion due to invalid reflection)
            bool setBinRoot           = fabricPackageType != FabricPackageType.XCopyPackage;
            var  deploymentParameters = new DeploymentParameters(setBinRoot);

            deploymentParameters.DeploymentPackageType = fabricPackageType;

            try
            {
                deploymentParameters.SetParameters(parameters, DeploymentOperations.Configure);

                DeploymentOperation.ExecuteOperation(deploymentParameters);
            }
            catch (Exception e)
            {
                DeployerTrace.WriteError("{0}", e.ToString());
                throw;
            }
        }