示例#1
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
        }
示例#2
0
        /// <summary>
        /// CreateOrUpdate operation inherits from RestartOperation.
        /// This api will invoke network reset only in the restart case.
        /// </summary>
        /// <param name="clusterManifest"></param>
        private void ResetNetworks(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure)
        {
            if (parameters.Operation == DeploymentOperations.None)
            {
                var lastBootUpTimeFromRegistry = Utility.GetNodeLastBootUpTimeFromRegistry();
                var lastBootUpTimeFromSystem   = Utility.GetNodeLastBootUpTimeFromSystem();
                DeployerTrace.WriteInfo("Last boot up time from registry:{0} from system:{1}", lastBootUpTimeFromRegistry, lastBootUpTimeFromSystem);

                // This is a work around to handle the case where the flat network was not usable after VM reboot.
                #region Container Network Reset
                if (!parameters.SkipContainerNetworkResetOnReboot)
                {
                    if (!string.Equals(lastBootUpTimeFromRegistry.ToString(), lastBootUpTimeFromSystem.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        DeployerTrace.WriteInfo("Invoking container network reset.");

                        var containerServiceArguments = (parameters.UseContainerServiceArguments) ? (parameters.ContainerServiceArguments) : (FlatNetworkConstants.ContainerServiceArguments);
                        containerServiceArguments = (parameters.EnableContainerServiceDebugMode)
                            ? (string.Format("{0} {1}", containerServiceArguments, FlatNetworkConstants.ContainerProviderServiceDebugModeArg))
                            : containerServiceArguments;

                        // This check is needed to allow clean up on azure. This is symmetrical to the set up condition.
                        if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsAzure ||
                            clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructurePaaS)
                        {
                            var containerNetworkCleanupOperation = new ContainerNetworkCleanupOperation();
                            containerNetworkCleanupOperation.ExecuteOperation(parameters.ContainerNetworkName, containerServiceArguments, parameters.FabricDataRoot, parameters.Operation);
                        }

                        if (parameters.ContainerNetworkSetup)
                        {
                            // Set up docker network.
                            var containerNetworkSetupOperation = new ContainerNetworkSetupOperation();
                            containerNetworkSetupOperation.ExecuteOperation(parameters, clusterManifest, infrastructure);
                        }

                        // Record last boot up time.
                        Utility.SaveNodeLastBootUpTimeToRegistry(lastBootUpTimeFromSystem);
                    }
                }
                else
                {
                    DeployerTrace.WriteInfo("Skipping container network reset on reboot because SkipContainerNetworkResetOnReboot flag is enabled.");
                }
                #endregion

                // This is a work around to handle the case where the isolated network was not usable after VM reboot.
                #region Isolated Network Reset
                if (parameters.EnableUnsupportedPreviewFeatures)
                {
                    if (!parameters.SkipIsolatedNetworkResetOnReboot)
                    {
                        if (!string.Equals(lastBootUpTimeFromRegistry.ToString(), lastBootUpTimeFromSystem.ToString(), StringComparison.OrdinalIgnoreCase))
                        {
                            DeployerTrace.WriteInfo("Invoking isolated network reset.");

                            // Clean up isolated network set up
                            var isolatedNetworkCleanupOperation = new IsolatedNetworkCleanupOperation();
                            isolatedNetworkCleanupOperation.ExecuteOperation(parameters.IsolatedNetworkName, parameters.FabricBinRoot, parameters.Operation);

                            if (parameters.IsolatedNetworkSetup)
                            {
                                var isolatedNetworkSetupOperation = new IsolatedNetworkSetupOperation();
                                isolatedNetworkSetupOperation.ExecuteOperation(parameters, clusterManifest, infrastructure);
                            }

                            // Record last boot up time.
                            Utility.SaveNodeLastBootUpTimeToRegistry(lastBootUpTimeFromSystem);
                        }
                    }
                    else
                    {
                        DeployerTrace.WriteInfo("Skipping isolated network reset on reboot because SkipIsolatedNetworkResetOnReboot flag is enabled.");
                    }
                }
                else
                {
                    DeployerTrace.WriteInfo("Isolated Network preview feature disabled for the cluster.");
                }
                #endregion
            }
        }
        protected override void OnExecuteOperation(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure)
        {
            var isRunningAsAdmin = AccountHelper.IsAdminUser();

            if (infrastructure == null)
            {
                DeployerTrace.WriteError("Cannot continue creating or updating deployment without infrastructure information");
                throw new InvalidDeploymentException(StringResources.Error_FabricDeployer_InvalidInfrastructure_Formatted);
            }

            if (parameters.Operation == DeploymentOperations.Update)
            {
                if (ShouldRemoveCurrentNode(parameters.NodeName, clusterManifest))
                {
#if !DotNetCoreClrLinux
                    DeployerTrace.WriteError("Current node is not present in the manifest list for Windows Server deployments. Changing DeploymentOperation to RemoveNodeConfig");
                    throw new ChangeDeploymentOperationToRemoveException("Modify Operation to RemoveNodeConfig");
#else
                    DeployerTrace.WriteInfo("CoreClrLinux: RemoveNodeConfigOperation is not enabled on Linux.");
                    return;
#endif
                }
            }

            AclClusterLevelCerts(clusterManifest);

#if !DotNetCoreClrIOT
            #region Container Network Setup

            if (parameters.ContainerNetworkSetup)
            {
                var containerNetworkSetupOperation = new ContainerNetworkSetupOperation();
                containerNetworkSetupOperation.ExecuteOperation(parameters, clusterManifest, infrastructure);
            }
            else
            {
                // Clean up docker network set up. This is needed for the SFRP scenario (there is no explicit uninstall)
                // when customers want to clean up container network set up through config upgrade.
#if !DotNetCoreClrLinux
                // This check is needed to allow clean up on azure. This is symmetrical to the set up condition.
                if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsAzure ||
                    clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructurePaaS)
                {
                    var containerNetworkCleanupOperation = new ContainerNetworkCleanupOperation();
                    containerNetworkCleanupOperation.ExecuteOperation(parameters.ContainerNetworkName, parameters.Operation);
                }
#else
                // This check is needed to disallow one box clean up on linux. This is symmetrical to the set up condition.
                // This was also needed because one box clean up resulted in an exception in the GetNetwork api.
                // Exception => System.Threading.Tasks.TaskCanceledException: A task was canceled
                if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructurePaaS)
                {
                    var containerNetworkCleanupOperation = new ContainerNetworkCleanupOperation();
                    containerNetworkCleanupOperation.ExecuteOperation(parameters.ContainerNetworkName, parameters.Operation);
                }
#endif
            }

            #endregion
#endif

            base.OnExecuteOperation(parameters, clusterManifest, infrastructure);

            if (fabricValidator.IsTVSEnabled)
            {
#if !DotNetCoreClr // Disable compiling on windows. Need to correct when porting FabricDeployer.
                if (!TVSSetup.SetupInfrastructureForClaimsAuth(isRunningAsAdmin))
                {
                    DeployerTrace.WriteError("Enabling WIF failed when creating or updating deployment with claims authentication.");
                    throw new InvalidDeploymentException(StringResources.Error_FabricDeployer_TVSSetupFailed_Formatted);
                }
#else
                DeployerTrace.WriteInfo("CoreClr: Token validation service is not enabled on Linux.");
#endif
            }
        }
示例#4
0
        protected override void OnExecuteOperation(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure)
        {
            var isRunningAsAdmin = AccountHelper.IsAdminUser();

            if (!isRunningAsAdmin)
            {
                DeployerTrace.WriteWarning(StringResources.Warning_DeployerNotRunAsAdminSkipFirewallAndPerformanceCounter);
                return;
            }

            if (clusterManifest == null)
            {
                DeployerTrace.WriteError(StringResources.Error_FabricHostStartedWithoutConfiguringTheNode);
                throw new ArgumentException(StringResources.Error_FabricHostStartedWithoutConfiguringTheNode);
            }

            this.parameters      = parameters;
            this.manifest        = clusterManifest;
            this.infrastructure  = infrastructure;
            this.fabricValidator = new FabricValidatorWrapper(parameters, manifest, infrastructure);
            fabricValidator.ValidateAndEnsureDefaultImageStore();

            if (!parameters.SkipFirewallConfiguration)
            {
                var securitySection = manifest.FabricSettings.FirstOrDefault(fabSetting => fabSetting.Name.Equals(Constants.SectionNames.Security, StringComparison.OrdinalIgnoreCase));

#if DotNetCoreClrLinux
                if (isRunningAsAdmin && clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureLinux)
                {
                    var currentInfrastructure = clusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureLinux;
#else
                if (isRunningAsAdmin && clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsServer)
                {
                    var currentInfrastructure = clusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureWindowsServer;
#endif

                    var nodeSettings = GetNodeSettings();
                    var isScaleMin   = currentInfrastructure.IsScaleMin;
                    FirewallManager.EnableFirewallSettings(nodeSettings, isScaleMin, securitySection, this is UpdateNodeStateOperation);
                    NetworkApiHelper.ReduceDynamicPortRange(nodeSettings, isScaleMin);
                }
                else if (isRunningAsAdmin)
                {
                    var nodeSettings = GetNodeSettings();
                    FirewallManager.EnableFirewallSettings(nodeSettings, false, securitySection, this is UpdateNodeStateOperation);
                    NetworkApiHelper.ReduceDynamicPortRange(nodeSettings, false);
                }
            }

#if !DotNetCoreClrIOT && !DotNetCoreClrLinux
            #region Container Network Reset
            // CreateOrUpdate operation inherits from RestartOperation.
            // This check will invoke network reset only in the restart case.
            // This is a work around to handle the case where the flat network was not usable after VM reboot.
            if (parameters.Operation == DeploymentOperations.None)
            {
                if (!parameters.SkipContainerNetworkResetOnReboot)
                {
                    var lastBootUpTimeFromRegistry = Utility.GetNodeLastBootUpTimeFromRegistry();
                    var lastBootUpTimeFromSystem   = Utility.GetNodeLastBootUpTimeFromSystem();
                    DeployerTrace.WriteInfo("Last boot up time from registry:{0} from system:{1}", lastBootUpTimeFromRegistry, lastBootUpTimeFromSystem);

                    if (!string.Equals(lastBootUpTimeFromRegistry.ToString(), lastBootUpTimeFromSystem.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        DeployerTrace.WriteInfo("Invoking container network reset.");

                        // This check is needed to allow clean up on azure. This is symmetrical to the set up condition.
                        if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsAzure ||
                            clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructurePaaS)
                        {
                            var containerNetworkCleanupOperation = new ContainerNetworkCleanupOperation();
                            containerNetworkCleanupOperation.ExecuteOperation(parameters.ContainerNetworkName, parameters.Operation);
                        }

                        if (parameters.ContainerNetworkSetup)
                        {
                            // set up docker network.
                            var containerNetworkSetupOperation = new ContainerNetworkSetupOperation();
                            containerNetworkSetupOperation.ExecuteOperation(parameters, clusterManifest, infrastructure);
                        }

                        // Record last boot up time
                        Utility.SaveNodeLastBootUpTimeToRegistry(lastBootUpTimeFromSystem);
                    }
                }
                else
                {
                    DeployerTrace.WriteInfo("Skipping container network reset on reboot because SkipContainerNetworkResetOnReboot flag is enabled.");
                }
            }
            #endregion
#endif

#if !DotNetCoreClrIOT
            if (parameters.ContainerDnsSetup == ContainerDnsSetup.Allow || parameters.ContainerDnsSetup == ContainerDnsSetup.Require)
            {
                try
                {
                    string currentNodeIPAddressOrFQDN = string.Empty;
                    if ((infrastructure != null) && (infrastructure.InfrastructureNodes != null))
                    {
                        foreach (var infraNode in infrastructure.InfrastructureNodes)
                        {
                            DeployerTrace.WriteInfo("Infra node <{0}> params.NodeName <{1}>", infraNode.NodeName, parameters.NodeName);
                            if (NetworkApiHelper.IsAddressForThisMachine(infraNode.IPAddressOrFQDN))
                            {
                                currentNodeIPAddressOrFQDN = infraNode.IPAddressOrFQDN;
                                DeployerTrace.WriteInfo("Found node IPAddressOrFQDN <{0}>", currentNodeIPAddressOrFQDN);
                                break;
                            }
                        }
                    }

                    new DockerDnsHelper(parameters, currentNodeIPAddressOrFQDN).SetupAsync().GetAwaiter().GetResult();
                }
                catch (Exception ex)
                {
                    if (parameters.ContainerDnsSetup == ContainerDnsSetup.Require)
                    {
                        DeployerTrace.WriteError(
                            StringResources.Error_FabricDeployer_DockerDnsSetup_ErrorNotContinuing,
                            Constants.ParameterNames.ContainerDnsSetup,
                            parameters.ContainerDnsSetup,
                            ex);
                        throw;
                    }

                    DeployerTrace.WriteWarning(
                        StringResources.Warning_FabricDeployer_DockerDnsSetup_ErrorContinuing,
                        Constants.ParameterNames.ContainerDnsSetup,
                        parameters.ContainerDnsSetup,
                        ex);
                }
            }
            else if (parameters.ContainerDnsSetup == ContainerDnsSetup.Disallow)
            {
                // cleanupasync catches all exceptions
                new DockerDnsHelper(parameters, string.Empty).CleanupAsync().GetAwaiter().GetResult();
            }
#endif

#if !DotNetCoreClr // Disable compiling on windows for now. Need to correct when porting FabricDeployer for windows.
            if (!PerformanceCounters.StartCollection(clusterManifest.FabricSettings, parameters.DeploymentSpecification))
            {
                DeployerTrace.WriteWarning(StringResources.Error_FabricDeployer_StartCounterCollectionFailed_Formatted);
            }

            if (fabricValidator.ShouldRegisterSpnForMachineAccount)
            {
                if (!SpnManager.EnsureSpn())
                {
                    throw new InvalidDeploymentException(StringResources.Error_FabricDeployer_FailedToRegisterSpn_Formatted);
                }
            }
#endif
        }
        /// <summary>
        /// Sets up or cleans up two types of networks -
        /// 1) Open Network
        /// 2) Isolated Network
        /// </summary>
        private void ManageNetworks(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure)
        {
            #region Container Network Setup

            if (parameters.ContainerNetworkSetup)
            {
                var containerNetworkSetupOperation = new ContainerNetworkSetupOperation();
                containerNetworkSetupOperation.ExecuteOperation(parameters, clusterManifest, infrastructure);
            }
            else
            {
                // Clean up docker network set up. This is needed for the SFRP scenario (there is no explicit uninstall)
                // when customers want to clean up container network set up through config upgrade.

                var containerServiceArguments = (parameters.UseContainerServiceArguments) ? (parameters.ContainerServiceArguments) : (FlatNetworkConstants.ContainerServiceArguments);

#if !DotNetCoreClrLinux
                containerServiceArguments = (parameters.EnableContainerServiceDebugMode)
                    ? (string.Format("{0} {1}", containerServiceArguments, FlatNetworkConstants.ContainerProviderServiceDebugModeArg)) : containerServiceArguments;

                // This check is needed to allow clean up on azure. This is symmetrical to the set up condition.
                if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsAzure ||
                    clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructurePaaS)
                {
                    var containerNetworkCleanupOperation = new ContainerNetworkCleanupOperation();
                    containerNetworkCleanupOperation.ExecuteOperation(parameters.ContainerNetworkName, containerServiceArguments, parameters.FabricDataRoot, parameters.Operation);
                }
#else
                // This check is needed to disallow one box clean up on linux. This is symmetrical to the set up condition.
                // This was also needed because one box clean up resulted in an exception in the GetNetwork api.
                // Exception => System.Threading.Tasks.TaskCanceledException: A task was canceled
                if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructurePaaS)
                {
                    var containerNetworkCleanupOperation = new ContainerNetworkCleanupOperation();
                    containerNetworkCleanupOperation.ExecuteOperation(parameters.ContainerNetworkName, containerServiceArguments, parameters.FabricDataRoot, parameters.Operation);
                }
#endif // !DotNetCoreClrLinux
            }

            #endregion

            #region Isolated Network Setup

            if (parameters.EnableUnsupportedPreviewFeatures)
            {
                if (parameters.IsolatedNetworkSetup)
                {
                    var isolatedNetworkSetupOperation = new IsolatedNetworkSetupOperation();
                    isolatedNetworkSetupOperation.ExecuteOperation(parameters, clusterManifest, infrastructure);
                }
                else
                {
                    var isolatedNetworkCleanupOperation = new IsolatedNetworkCleanupOperation();
                    isolatedNetworkCleanupOperation.ExecuteOperation(parameters.IsolatedNetworkName, parameters.FabricBinRoot, parameters.Operation);
                }
            }
            else
            {
                DeployerTrace.WriteInfo("Isolated Network preview feature disabled for the cluster.");
            }
            #endregion
        }