protected override void OnExecuteOperation(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure) { try { CleanupDeployment(parameters); } finally { #if !DotNetCoreClr if (AccountHelper.IsAdminUser()) { CollectEventLogs(); } #endif } }
private void ConfigureFromManifest(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure) { SetupSettings settings = new SetupSettings(clusterManifest); #if !DotNetCoreClrLinux if (!string.IsNullOrEmpty(settings.ServiceRunAsAccountName)) { FabricDeployerServiceController.SetServiceCredentials(settings.ServiceRunAsAccountName, settings.ServiceRunAsPassword, parameters.MachineName); DeployerTrace.WriteInfo("Set Service Fabric Host Service to run as {0}", settings.ServiceRunAsAccountName); } #endif string clusterManifestTargetLocation = Helpers.GetRemotePath(Path.Combine(parameters.FabricDataRoot, "clusterManifest.xml"), parameters.MachineName); DeployerTrace.WriteInfo("Copying ClusterManifest to {0}", clusterManifestTargetLocation); if (!ArePathesEqual(parameters.ClusterManifestLocation, clusterManifestTargetLocation)) { File.Copy(parameters.ClusterManifestLocation, clusterManifestTargetLocation, true); } #if !DotNetCoreClrLinux string serviceStartupType = "DelayedAutoStart"; if (!string.IsNullOrEmpty(parameters.ServiceStartupType)) { FabricDeployerServiceController.SetStartupType(parameters.ServiceStartupType); serviceStartupType = parameters.ServiceStartupType; } else if (!string.IsNullOrEmpty(settings.ServiceStartupType)) { FabricDeployerServiceController.SetStartupType(settings.ServiceStartupType); serviceStartupType = settings.ServiceStartupType; } else { if (infrastructure is AzureInfrastructure) { FabricDeployerServiceController.SetServiceStartupType(FabricDeployerServiceController.ServiceStartupType.Manual, parameters.MachineName); serviceStartupType = FabricDeployerServiceController.ServiceStartupType.Manual.ToString(); } else { FabricDeployerServiceController.SetStartupTypeDelayedAuto(parameters.MachineName); } } DeployerTrace.WriteInfo("Set Service Fabric Host Service to start up type to {0}", serviceStartupType); #endif }
protected override void OnExecuteOperation(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure) { var containerNetworkName = (parameters != null) ? (parameters.ContainerNetworkName) : (FlatNetworkConstants.NetworkName); var operation = (parameters != null) ? (parameters.Operation) : (DeploymentOperations.None); var containerServiceArguments = (parameters != null && parameters.UseContainerServiceArguments) ? (parameters.ContainerServiceArguments) : (FlatNetworkConstants.ContainerServiceArguments); #if !DotNetCoreClrLinux containerServiceArguments = (parameters != null && parameters.EnableContainerServiceDebugMode) ? (string.Format("{0} {1}", containerServiceArguments, FlatNetworkConstants.ContainerProviderServiceDebugModeArg)) : containerServiceArguments; #endif var fabricDataRoot = (parameters != null) ? (parameters.FabricDataRoot) : (string.Empty); ExecuteOperation(containerNetworkName, containerServiceArguments, fabricDataRoot, operation); }
private void RevertTarget(DeploymentParameters parameters) { string targetInformationFile = parameters.DeploymentSpecification.GetTargetInformationFile(); if (!File.Exists(targetInformationFile)) { DeployerTrace.WriteInfo("TargetInformation.xml file not found. Return as no operation is needed."); return; } TargetInformationType targetInfo = XmlHelper.ReadXml <TargetInformationType>(targetInformationFile); if (targetInfo.CurrentInstallation == null) { DeployerTrace.WriteInfo("No current information. No operation to be done."); return; } TargetInformationType newTargetInfo = new TargetInformationType(); newTargetInfo.TargetInstallation = targetInfo.CurrentInstallation; newTargetInfo.CurrentInstallation = targetInfo.TargetInstallation; XmlHelper.WriteXml <TargetInformationType>(targetInformationFile, newTargetInfo); // Do not need to reinstall the old MSI on rollback on linux. The updater service takes care of this #if !DotNetCoreClrLinux if (!string.IsNullOrEmpty(targetInfo.CurrentInstallation.MSILocation)) { string[] batFileContent = new string[4]; batFileContent[0] = "sc stop FabricHostSvc"; batFileContent[1] = "TIMEOUT /T 10"; batFileContent[2] = string.Format( CultureInfo.InvariantCulture, "msiexec /i \"{0}\" /lv \"{1}\" /q IACCEPTEULA=Yes", targetInfo.CurrentInstallation.MSILocation, parameters.DeploymentSpecification.GetInstallerLogFile("Revert", Utility.GetCurrentCodeVersion(null))); batFileContent[3] = "sc start FabrichostSvc"; string installerScriptFileLocation = parameters.DeploymentSpecification.GetInstallerScriptFile("Revert"); File.WriteAllLines(installerScriptFileLocation, batFileContent); ExecuteScript(installerScriptFileLocation); } #endif }
private static void RemoveNetworks(DeploymentParameters parameters) { var containerServiceArguments = (parameters.UseContainerServiceArguments) ? (parameters.ContainerServiceArguments) : (FlatNetworkConstants.ContainerServiceArguments); #if !DotNetCoreClrLinux containerServiceArguments = (parameters.EnableContainerServiceDebugMode) ? (string.Format("{0} {1}", containerServiceArguments, FlatNetworkConstants.ContainerProviderServiceDebugModeArg)) : containerServiceArguments; #endif bool exceptionOccurred = false; string exceptionMsg = string.Empty; try { // Clean up container network set up var containerNetworkCleanupOperation = new ContainerNetworkCleanupOperation(); containerNetworkCleanupOperation.ExecuteOperation(parameters.ContainerNetworkName, containerServiceArguments, parameters.FabricDataRoot); } catch (Exception ex) { // we will throw this exception after isolated network clean up. exceptionOccurred = true; exceptionMsg = ex.Message; } try { // Clean up isolated network set up var isolatedNetworkCleanupOperation = new IsolatedNetworkCleanupOperation(); isolatedNetworkCleanupOperation.ExecuteOperation(parameters.IsolatedNetworkName, parameters.FabricBinRoot); } catch (Exception ex) { DeployerTrace.WriteError("Error occurred while cleaning up isolated network setup exception {0}", ex); } if (exceptionOccurred) { throw new InvalidDeploymentException(exceptionMsg); } }
private void SetFabricRegistrySettings(DeploymentParameters parameters) { string machineNameForRegistry = string.IsNullOrEmpty(parameters.MachineName) ? null : @"\\" + parameters.MachineName; if (!string.IsNullOrEmpty(parameters.FabricPackageRoot)) { DeployerTrace.WriteInfo("Setting FabricRoot to {0} on machine {1}", parameters.FabricPackageRoot, parameters.MachineName); FabricEnvironment.SetFabricRoot(parameters.FabricPackageRoot, machineNameForRegistry); string fabricBinRoot = Path.Combine(parameters.FabricPackageRoot, Constants.FabricBinRootRelativePath); DeployerTrace.WriteInfo("Setting FabricBinRoot to {0} on machine {1}", fabricBinRoot, parameters.MachineName); FabricEnvironment.SetFabricBinRoot(fabricBinRoot, machineNameForRegistry); string fabricCodePath = Path.Combine(parameters.FabricPackageRoot, Constants.FabricCodePathRelativePath); DeployerTrace.WriteInfo("Setting FabricCodePath to {0} on machine {1}", fabricCodePath, parameters.MachineName); FabricEnvironment.SetFabricCodePath(fabricCodePath, machineNameForRegistry); } if (!string.IsNullOrEmpty(parameters.FabricDataRoot)) { DeployerTrace.WriteInfo("Setting FabricDataRoot to {0} on machine {1}", parameters.FabricDataRoot, parameters.MachineName); FabricEnvironment.SetDataRoot(parameters.FabricDataRoot, machineNameForRegistry); } if (!string.IsNullOrEmpty(parameters.FabricLogRoot)) { DeployerTrace.WriteInfo("Setting FabricLogRoot to {0} on machine {1}", parameters.FabricLogRoot, parameters.MachineName); FabricEnvironment.SetLogRoot(parameters.FabricLogRoot, machineNameForRegistry); } DeployerTrace.WriteInfo("Setting EnableCircularTraceSession to {0} on machine {1}", parameters.EnableCircularTraceSession, parameters.MachineName); FabricEnvironment.SetEnableCircularTraceSession(parameters.EnableCircularTraceSession, machineNameForRegistry); // Set the state for preview features that need to lightup at runtime DeployerTrace.WriteInfo("Setting EnableUnsupportedPreviewFeatures to {0} on machine {1}", parameters.EnableUnsupportedPreviewFeatures, parameters.MachineName); FabricEnvironment.SetEnableUnsupportedPreviewFeatures(parameters.EnableUnsupportedPreviewFeatures, machineNameForRegistry); DeployerTrace.WriteInfo("Setting IsSFVolumeDiskServiceEnabled to {0} on machine {1}", parameters.IsSFVolumeDiskServiceEnabled, parameters.MachineName); FabricEnvironment.SetIsSFVolumeDiskServiceEnabled(parameters.IsSFVolumeDiskServiceEnabled, machineNameForRegistry); }
protected override void OnExecuteOperation(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure) { RemoveLogicalDirectoriesIfExist(parameters.FabricDataRoot, parameters.MachineName); if (parameters.DeploymentPackageType == FabricPackageType.XCopyPackage) { RemoveNodeConfigurationXCopy(parameters.MachineName, parameters.DeleteLog, parameters.NodeName); } else { if (string.IsNullOrEmpty(parameters.MachineName) || parameters.MachineName == Constants.LocalHostMachineName || parameters.MachineName.Equals(Helpers.GetMachine())) { this.RemoveNodeConfigurationMsi(parameters.DeleteLog); } else { throw new ArgumentException(StringResources.Error_RemoveNodeConfigOperationNotSupportedRemovelyWithMSI); } } }
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); }
protected abstract void OnExecuteOperation(DeploymentParameters parameters, ClusterManifestType clusteManifest, Infrastructure infrastructure);
public static void ExecuteOperation(DeploymentParameters parameters, bool disableFileTrace) { try { parameters.Initialize(); DeployerTrace.UpdateFileLocation(parameters.DeploymentSpecification.GetTracesFolder()); DeployerTrace.WriteInfo("Running deployer with {0}", parameters.ToString()); if (parameters.FabricDataRoot == null) { if (parameters.Operation == DeploymentOperations.ValidateClusterManifest || parameters.Operation == DeploymentOperations.DockerDnsSetup || parameters.Operation == DeploymentOperations.DockerDnsCleanup || parameters.Operation == DeploymentOperations.ContainerNetworkSetup || parameters.Operation == DeploymentOperations.ContainerNetworkCleanup) // Some operations may not require FDR { try { ExecuteOperationPrivate(parameters); } catch (Exception) { parameters.DeleteTargetFile = false; throw; } } else { throw new ArgumentNullException( String.Format("parameters.FabricDataRoot Operation {0} requires Fabric Data Root to be defined but was passed as null.", parameters.Operation)); } } else { string fileLockPath = Helpers.GetRemotePath(parameters.FabricDataRoot, parameters.MachineName); fileLockPath = Path.Combine(fileLockPath, "lock"); // Remove uses a different lock than the other operations, because it can be launched by the deployer separately when RemoveNodeConfig is running if (parameters.Operation == DeploymentOperations.Remove) { fileLockPath += "_Remove"; } try { Helpers.CreateDirectoryIfNotExist(parameters.FabricDataRoot, parameters.MachineName); using (FileWriterLock fileWriterLock = new FileWriterLock(fileLockPath)) { TimeSpan timeout = TimeSpan.FromMinutes(2); if (!fileWriterLock.Acquire(timeout)) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Could not acquire lock: {0} in {1}", fileLockPath, timeout)); } ExecuteOperationPrivate(parameters); } } catch (Exception) { parameters.DeleteTargetFile = false; throw; } } } finally { if (disableFileTrace) { DeployerTrace.CloseHandle(); } } }
public static void ExecuteOperation(DeploymentParameters parameters) { DeploymentOperation.ExecuteOperation(parameters, true); }
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 }
internal FabricValidatorWrapper(DeploymentParameters parameters, ClusterManifestType manifest, Infrastructure infrastructure) { this.parameters = parameters; this.manifest = manifest; this.infrastructure = infrastructure; }
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; } }
protected override void OnExecuteOperation(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure) { this.manifest = clusterManifest; this.infrastructure = infrastructure; this.parameters = parameters; this.fabricValidator = new FabricValidatorWrapper(parameters, manifest, infrastructure); fabricValidator.ValidateAndEnsureDefaultImageStore(); this.nodeSettings = GetNodeSettings(); // creating a ClusterSettings without Unreliable Transport settings var clusterSettingsNoUnreliableTransport = new ClusterSettings(this.manifest.FabricSettings, GetVotes(), GetSeedNodes(), manifest.Certificates != null ? this.manifest.Certificates.SecretsCertificate : null); clusterSettingsNoUnreliableTransport.Settings.RemoveAll(x => x.Name == FabricValidatorConstants.SectionNames.UnreliableTransport); var clusterSettings = new ClusterSettings(this.manifest.FabricSettings, GetVotes(), GetSeedNodes(), manifest.Certificates != null ? this.manifest.Certificates.SecretsCertificate : null); this.UpdateClusterSettings(clusterSettingsNoUnreliableTransport); var fabricHostSettings = InitializeFabricHostSettings(clusterSettingsNoUnreliableTransport, nodeSettings); var servicesToBeEnabled = GetServicesToBeEnabled(); for (int i = 0; i < nodeSettings.Count; i++) { NodeSettings nodeSetting = nodeSettings[i]; List <string> servicesToBeDeployed = GetServicesToBeDeployed(i); DeploymentNode node = new DeploymentNode(nodeSetting, clusterSettings, infrastructure, servicesToBeDeployed.ToArray(), servicesToBeEnabled.ToArray(), this.manifest); if (string.IsNullOrEmpty(parameters.NodeName) || parameters.NodeName.Equals(nodeSetting.NodeName, StringComparison.OrdinalIgnoreCase)) { if (parameters.Operation == DeploymentOperations.Update || parameters.Operation == DeploymentOperations.UpdateInstanceId) { node.UpgradeDeployment(); } else if (parameters.Operation == DeploymentOperations.Create) { node.CreateDeployment(); //update infrastructure manifest } } // Gateway service activation is managed by Fabric.exe, and so its settings shouldn't be written to FabricHostSettings.xml fabricHostSettings.AddRange(node.GetHostedServices().FindAll( delegate(SettingsTypeSection section) { string hostedServiceName = string.Format( CultureInfo.InvariantCulture, Constants.SectionNames.HostSettingsSectionPattern, nodeSetting.NodeName, Constants.HttpGatewayService); return(section.Name != hostedServiceName); })); } WriteFabricHostSettingsFile(parameters.DeploymentSpecification.GetDataRoot(), new SettingsType() { Section = fabricHostSettings.ToArray() }, parameters.MachineName); var currentType = this as CreateorUpdateOperation; if (currentType != null) { base.OnExecuteOperation(parameters, clusterManifest, infrastructure); } }
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 } } #if !DotNetCoreClrLinux AclClusterLevelCerts(clusterManifest); #endif // !DotNetCoreClrLinux #if !DotNetCoreClrIOT #if DotNetCoreClrLinux BootstrapContainerSetup(); #endif // DotNetCoreClrLinux // Creates or deletes supported networks based on configuration. ManageNetworks(parameters, clusterManifest, infrastructure); #endif // !DotNetCoreClrIOT #if !DotNetCoreClrIOT && DotNetCoreClrLinux // On Linux, FabricDeployer configure operation is not called. // Adding the registry entries in create operatio. // Do not update the entries in operations other than Create/Update if (parameters.Operation == DeploymentOperations.Create || parameters.Operation == DeploymentOperations.Update) { Utility.SetFabricRegistrySettings(parameters); } #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 // !DotNetCoreClrLinux } }
protected void CleanupDeployment(DeploymentParameters parameters) { #if !DotNetCoreClr // Disable compiling on windows for now. Need to correct when porting FabricDeployer for windows. if (AccountHelper.IsAdminUser()) { CollectEventLogs(); FabricDeployerServiceController.DisableService(); if (!parameters.SkipFirewallConfiguration) { FirewallManager.DisableFirewallSettings(); } DeployerTrace.WriteInfo("Stopping data collectors"); PerformanceCounters.StopDataCollector(); DeployerTrace.WriteInfo("Deleting data collectors"); PerformanceCounters.DeleteDataCollector(); } else { DeployerTrace.WriteWarning( "Deployer is not run as Administrator. Skipping Firewall Management and Performance Counter Management. Possible Post remove cleanup required"); } if (FabricDeployerServiceController.IsRunning(parameters.MachineName)) { throw new InvalidDeploymentException(StringResources.Error_FabricDeployer_FabricHostStillRunning_Formatted); } #else DeployerTrace.WriteInfo("CoreClr: Skipping Firewall Management and Performance Counter Management cleanup on CoreClr."); #endif string targetInformationFileName = Path.Combine(parameters.FabricDataRoot, Constants.FileNames.TargetInformation); DeleteTargetInformationFile(targetInformationFileName); #if DotNetCoreClr // Disable compiling on windows for now. Need to correct when porting FabricDeployer for windows. bool skipDeleteFabricDataRoot = Utility.GetSkipDeleteFabricDataRoot() || (parameters.SkipDeleteFabricDataRoot != null && string.Equals(parameters.SkipDeleteFabricDataRoot, "true", StringComparison.OrdinalIgnoreCase)); #else bool skipDeleteFabricDataRoot = Utility.GetSkipDeleteFabricDataRoot() || (parameters.SkipDeleteFabricDataRoot != null && string.Equals(parameters.SkipDeleteFabricDataRoot, "true", StringComparison.InvariantCultureIgnoreCase)); #endif if (skipDeleteFabricDataRoot) { DeployerTrace.WriteInfo("Skipping deletion of Data Root."); } else { NetCloseResource(parameters.FabricDataRoot); SafeDeleteDirectory(parameters.FabricDataRoot, parameters.FabricLogRoot, Path.Combine(parameters.FabricDataRoot, Constants.FileNames.FabricHostSettings)); List <SettingsTypeSection> sections = new List <SettingsTypeSection>(); sections.Add(new SettingsTypeSection() { Name = Constants.SectionNames.Setup }); WriteFabricHostSettingsFile(parameters.FabricDataRoot, new SettingsType() { Section = sections.ToArray() }, parameters.MachineName); } #if !DotNetCoreClr // Disable compiling on windows for now. Need to correct when porting FabricDeployer for windows. SpnManager.CleanupSpn(); #else DeployerTrace.WriteInfo("CoreClrLinux: SPN cleanning skipped for Linux"); #endif #if !DotNetCoreClrIOT new DockerDnsHelper(parameters, string.Empty).CleanupAsync().GetAwaiter().GetResult(); // Clean up docker network set up var containerNetworkCleanupOperation = new ContainerNetworkCleanupOperation(); containerNetworkCleanupOperation.ExecuteOperation(parameters.ContainerNetworkName); #endif }
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 ResetNetworks(parameters, clusterManifest, infrastructure); #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> /// 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 (!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 }
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 } }
internal void ExecuteOperation(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure) { if (!parameters.IsolatedNetworkSetup) { DeployerTrace.WriteInfo("Skipping isolated network set up since it has been disabled."); return; } if (!Utility.IsContainersFeaturePresent()) { DeployerTrace.WriteInfo("Skipping isolated network set up since containers feature has been disabled."); return; } #if !DotNetCoreClrLinux if (!Utility.IsContainerNTServicePresent()) { DeployerTrace.WriteInfo("Skipping isolated network set up since containers NT service is not installed."); return; } #endif var networkName = (!string.IsNullOrEmpty(parameters.IsolatedNetworkName)) ? (parameters.IsolatedNetworkName) : (IsolatedNetworkConstants.NetworkName); DeployerTrace.WriteInfo("Isolated network set up invoked in context: {0}.", parameters.Operation); var networkInterfaceName = string.Empty; if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsAzure || clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructurePaaS) { networkInterfaceName = parameters.IsolatedNetworkInterfaceName; } else { if (string.IsNullOrEmpty(parameters.IsolatedNetworkInterfaceName)) { string message = "Failed to set up isolated network on-prem because isolated network interface name not provided."; DeployerTrace.WriteError(message); throw new InvalidDeploymentException(message); } else { networkInterfaceName = parameters.IsolatedNetworkInterfaceName; } } #if !DotNetCoreClr bool networkPluginRunning = false; if (parameters.Operation == DeploymentOperations.Update || parameters.Operation == DeploymentOperations.UpdateInstanceId) { networkPluginRunning = IsNetworkPluginRunning(); DeployerTrace.WriteInfo("Isolated network plugin running: {0}.", networkPluginRunning); } if (SetupIsolatedNetwork(infrastructure, networkName, parameters.IsolatedNetworkInterfaceName, parameters.FabricBinRoot, networkPluginRunning)) #else if (SetupIsolatedNetwork(parameters.IsolatedNetworkInterfaceName)) #endif { DeployerTrace.WriteInfo("Successfully set up isolated network."); } else { string message = "Failed to set up isolated network."; DeployerTrace.WriteError(message); throw new InvalidDeploymentException(message); } }
/// <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 }
internal static void CompareAndAnalyze(ClusterManifestType currentClusterManifest, ClusterManifestType targetClusterManifest, Infrastructure infrastructure, DeploymentParameters parameters) { // If the infrastructure elements are different, the update cannot continue if (targetClusterManifest.Infrastructure.Item.GetType() != currentClusterManifest.Infrastructure.Item.GetType()) { DeployerTrace.WriteError("Invalid Operation. Cannot update from 1 infrastructure type to another"); throw new ClusterManifestValidationException(StringResources.Error_FabricDeployer_InvalidClusterManifest_Formatted); } // Validate that the new cluster manifest and the node list are valid try { var currentWindowsFabricSettings = new WindowsFabricSettings(currentClusterManifest); var targetWindowsFabricSettings = new WindowsFabricSettings(targetClusterManifest); FabricValidator.Create(targetClusterManifest, infrastructure.InfrastructureNodes, targetWindowsFabricSettings, parameters.Operation).Validate(); //Validate if the SeedNodeCount increases by one int currentSeedNodes = 0, targetSeedNodes = 0; List <String> currentSeedNodesList = new List <String>(); List <String> targetSeedNodesList = new List <String>(); if (currentClusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsAzure) { ClusterManifestTypeInfrastructureWindowsAzure currentInfrastructure = currentClusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureWindowsAzure; ClusterManifestTypeInfrastructureWindowsAzure targetInfrastructure = targetClusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureWindowsAzure; for (int i = 0; i < currentInfrastructure.Roles.Length; i++) { currentSeedNodes += currentInfrastructure.Roles[i].SeedNodeCount; } for (int j = 0; j < targetInfrastructure.Roles.Length; j++) { targetSeedNodes += targetInfrastructure.Roles[j].SeedNodeCount; } } else if (currentClusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsAzureStaticTopology) { ClusterManifestTypeInfrastructureWindowsAzureStaticTopology currentInfrastructure = currentClusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureWindowsAzureStaticTopology; ClusterManifestTypeInfrastructureWindowsAzureStaticTopology targetInfrastructure = targetClusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureWindowsAzureStaticTopology; foreach (FabricNodeType nodelist in currentInfrastructure.NodeList) { if (nodelist.IsSeedNode) { currentSeedNodes++; } } foreach (FabricNodeType nodelist in targetInfrastructure.NodeList) { if (nodelist.IsSeedNode) { targetSeedNodes++; } } } #if DotNetCoreClrLinux else if (currentClusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureLinux) { var currentInfrastructure = currentClusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureLinux; var targetInfrastructure = targetClusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureLinux; #else else if (currentClusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsServer) { var currentInfrastructure = currentClusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureWindowsServer; var targetInfrastructure = targetClusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureWindowsServer; #endif foreach (FabricNodeType nodelist in currentInfrastructure.NodeList) { if (nodelist.IsSeedNode) { currentSeedNodes++; currentSeedNodesList.Add(nodelist.NodeName); } } foreach (FabricNodeType nodelist in targetInfrastructure.NodeList) { if (nodelist.IsSeedNode) { targetSeedNodes++; targetSeedNodesList.Add(nodelist.NodeName); } } } if (System.Math.Abs(currentSeedNodes - targetSeedNodes) > 1) { DeployerTrace.WriteError(StringResources.Warning_SeedNodeCountCanOnlyChangeByOne); throw new ClusterManifestValidationException(StringResources.Warning_SeedNodeCountCanOnlyChangeByOne); } else if (currentSeedNodesList.Except(targetSeedNodesList).Union(targetSeedNodesList.Except(currentSeedNodesList)).Count() > 1) { DeployerTrace.WriteError(StringResources.Warning_SeedNodeSetCannotHaveMultipleChanges); throw new ClusterManifestValidationException(StringResources.Warning_SeedNodeSetCannotHaveMultipleChanges); } var fabricValidator = FabricValidator.Create(currentClusterManifest, null, currentWindowsFabricSettings, parameters.Operation); // Finally, compare the settings and decide if fabric must restart or not IEnumerable <KeyValuePair <string, string> > modifiedStaticSettings = fabricValidator.CompareAndAnalyze(targetClusterManifest, parameters.NodeTypeName); if (modifiedStaticSettings.Count() > 0) { WriteModifiedStaticSettingsToFile(modifiedStaticSettings, targetClusterManifest.FabricSettings, parameters.OutputFile); throw new FabricHostRestartRequiredException("Fabric host restart is required"); } else { throw new FabricHostRestartNotRequiredException("Fabric host restart is not required"); } } catch (Exception e) { if (e is FabricHostRestartRequiredException || e is FabricHostRestartNotRequiredException) { throw e; } else { throw new ClusterManifestValidationException( string.Format(StringResources.Error_FabricDeployer_InvalidClusterManifest_Formatted, e)); } } }
protected override void OnExecuteOperation(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure) { CleanupDeployment(parameters); }
protected override void OnExecuteOperation(DeploymentParameters parameters, ClusterManifestType clusteManifest, Infrastructure infrastructure) { this.RevertTarget(parameters); }
protected override void OnExecuteOperation(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure) { #if !DotNetCoreClrLinux if (FabricDeployerServiceController.IsRunning(parameters.MachineName)) { string message = string.Format(StringResources.Error_FabricDeployer_FabricHostStillRunning_Formatted, parameters.MachineName); DeployerTrace.WriteError(message); throw new InvalidOperationException(message); } #endif DeployerTrace.WriteInfo("Creating FabricDataRoot {0}, if it doesn't exist on machine {1}", parameters.FabricDataRoot, parameters.MachineName); Helpers.CreateDirectoryIfNotExist(parameters.FabricDataRoot, parameters.MachineName); DeployerTrace.WriteInfo("Creating FabricLogRoot {0}, if it doesn't exist on machine {1}", parameters.FabricLogRoot, parameters.MachineName); Helpers.CreateDirectoryIfNotExist(Path.Combine(parameters.FabricLogRoot, Constants.TracesFolderName), parameters.MachineName); List <LogicalDirectoryType[]> logicalDirectorysSetForThisMachine = new List <LogicalDirectoryType[]>(); // For single machine scale min, fabric deployer only runs once for all nodes. It may miss the nodeType that has the logicalApplicationDirectory section. // So here, we need to extract all the logicalApplicationDirectories sections from clusterManifest. if ((clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsServer && ((ClusterManifestTypeInfrastructureWindowsServer)clusterManifest.Infrastructure.Item).IsScaleMin) || (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureLinux && ((ClusterManifestTypeInfrastructureLinux)clusterManifest.Infrastructure.Item).IsScaleMin)) { FabricNodeType[] nodeList; nodeList = clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsServer ? ((ClusterManifestTypeInfrastructureWindowsServer)clusterManifest.Infrastructure.Item).NodeList : ((ClusterManifestTypeInfrastructureLinux)clusterManifest.Infrastructure.Item).NodeList; foreach (var node in nodeList) { var logicalDirectories = clusterManifest.NodeTypes.Where(nodeType => nodeType.Name == node.NodeTypeRef).First().LogicalDirectories; if (logicalDirectories != null) { logicalDirectorysSetForThisMachine.Add(logicalDirectories); } } } else if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructurePaaS || clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsServer || clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureLinux) // PaaS doesn't support Scale Min. { if (!string.IsNullOrEmpty(parameters.MachineName)) //For cab deployment { var logicalDirectories = clusterManifest.NodeTypes.Where(nt => nt.Name == Utility.GetNodeTypeFromMachineName(clusterManifest, infrastructure.GetInfrastructureManifest(), parameters.MachineName)).First().LogicalDirectories; if (logicalDirectories != null) { logicalDirectorysSetForThisMachine.Add(logicalDirectories); } } else //For msi deployment { foreach (var infrastructureNode in infrastructure.InfrastructureNodes) { bool isNodeForThisMachine = NetworkApiHelper.IsNodeForThisMachine(infrastructureNode); if (isNodeForThisMachine) { var logicalDirectories = clusterManifest.NodeTypes.Where(nt => nt.Name == infrastructureNode.NodeTypeRef).First().LogicalDirectories; if (logicalDirectories != null) { logicalDirectorysSetForThisMachine.Add(logicalDirectories); } } } } } if (logicalDirectorysSetForThisMachine.Any()) { CreateLogicalDirectoriesForAllTheNodesOnThisMachineAndEnableRegKey(parameters.MachineName, logicalDirectorysSetForThisMachine); } FabricValidatorWrapper fabricValidator = new FabricValidatorWrapper(parameters, clusterManifest, infrastructure); fabricValidator.ValidateAndEnsureDefaultImageStore(); if (!string.IsNullOrEmpty(parameters.BootstrapMSIPath)) // Mandatory for Standalone path { CopyBaselinePackageIfPathExists(parameters.BootstrapMSIPath, parameters.FabricDataRoot, parameters.DeploymentPackageType, parameters.MachineName); } SetFabricRegistrySettings(parameters); ConfigureFromManifest(parameters, clusterManifest, infrastructure); string destinationCabPath = Path.Combine(parameters.FabricDataRoot, Constants.FileNames.BaselineCab); WriteTargetInformationFile( parameters.ClusterManifestLocation, parameters.InfrastructureManifestLocation, parameters.FabricDataRoot, parameters.MachineName, destinationCabPath, parameters.DeploymentPackageType, parameters.BootstrapMSIPath); WriteFabricHostSettingsFile(parameters.FabricDataRoot, new SettingsType(), parameters.MachineName); #if !DotNetCoreClrLinux if (!string.IsNullOrEmpty(parameters.FabricPackageRoot)) { FabricDeployerServiceController.InstallFabricInstallerService(parameters.FabricPackageRoot, parameters.MachineName); } #endif if (!string.IsNullOrEmpty(parameters.JsonClusterConfigLocation)) { string destinationConfigPath = Helpers.GetRemotePath( Path.Combine(parameters.FabricDataRoot, Constants.FileNames.BaselineJsonClusterConfig), parameters.MachineName); File.Copy(parameters.JsonClusterConfigLocation, destinationConfigPath, true); } }
internal void ExecuteOperation(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure) { #if !DotNetCoreClrLinux if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsAzure || clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructurePaaS) { if (parameters.ContainerNetworkSetup) { if (Utility.IsContainersFeaturePresent()) { if (IsContainerServiceInstalled()) { if (IsWireServerAvailable()) { var networkName = (!string.IsNullOrEmpty(parameters.ContainerNetworkName)) ? (parameters.ContainerNetworkName) : (FlatNetworkConstants.NetworkName); DeployerTrace.WriteInfo("Container network set up invoked in context: {0}", parameters.Operation); bool containerServiceRunningOnCustomPort = false; if (parameters.Operation == DeploymentOperations.Update || parameters.Operation == DeploymentOperations.UpdateInstanceId) { containerServiceRunningOnCustomPort = IsContainerServiceRunning(); DeployerTrace.WriteInfo("Container service running on custom port: {0}", containerServiceRunningOnCustomPort); } if (SetupContainerNetwork(networkName, containerServiceRunningOnCustomPort)) { DeployerTrace.WriteInfo("Successfully set up container network."); } else { DeployerTrace.WriteError("Failed to set up container network."); throw new InvalidDeploymentException("Failed to set up container network."); } } else { DeployerTrace.WriteInfo("Skipping container network set up since wire server is not available."); } } else { DeployerTrace.WriteInfo("Skipping container network set up since containers service is not installed."); } } else { DeployerTrace.WriteInfo("Skipping container network set up since containers feature has been disabled."); } } else { DeployerTrace.WriteInfo("Skipping container network set up since it has been disabled."); } } else { DeployerTrace.WriteInfo("Skipping container network set up since we are not on Azure."); } #else if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructurePaaS) { if (parameters.ContainerNetworkSetup) { var networkName = (!string.IsNullOrEmpty(parameters.ContainerNetworkName)) ? (parameters.ContainerNetworkName) : (FlatNetworkConstants.NetworkName); DeployerTrace.WriteInfo("Container network set up invoked in context: {0}", parameters.Operation); bool containerServiceRunningOnCustomPort = false; if (parameters.Operation == DeploymentOperations.Update || parameters.Operation == DeploymentOperations.UpdateInstanceId) { containerServiceRunningOnCustomPort = IsContainerServiceRunning(); DeployerTrace.WriteInfo("Container service running on custom port: {0}", containerServiceRunningOnCustomPort); } if (SetupContainerNetwork(networkName, parameters.FabricBinRoot, containerServiceRunningOnCustomPort)) { DeployerTrace.WriteInfo("Successfully set up container network."); } else { DeployerTrace.WriteError("Failed to set up container network."); throw new InvalidDeploymentException("Failed to set up container network."); } } else { DeployerTrace.WriteInfo("Skipping container network set up since it has been disabled."); } } else { DeployerTrace.WriteInfo("Skipping container network set up since we are not on Azure."); } #endif }
protected override void OnExecuteOperation(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure) { var fabricValidator = new FabricValidatorWrapper(parameters, clusterManifest, infrastructure); fabricValidator.ValidateAndEnsureDefaultImageStore(); }
internal void ExecuteOperation(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure) { #if !DotNetCoreClrLinux if (!(clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsAzure) && !(clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructurePaaS)) #else if (!(clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructurePaaS)) #endif { DeployerTrace.WriteInfo("Skipping container network set up since we are not on Azure."); return; } if (!parameters.ContainerNetworkSetup) { DeployerTrace.WriteInfo("Skipping container network set up since it has been disabled."); return; } if (!Utility.IsContainersFeaturePresent()) { DeployerTrace.WriteInfo("Skipping container network set up since containers feature has been disabled."); return; } if (!Utility.IsContainerServiceInstalled()) { DeployerTrace.WriteInfo("Skipping container network set up since containers service is not installed."); return; } #if !DotNetCoreClrLinux if (!Utility.IsContainerNTServicePresent()) { DeployerTrace.WriteInfo("Skipping container network setup up since containers NT service is not installed."); return; } #endif if (!IsWireServerAvailable()) { DeployerTrace.WriteInfo("Skipping container network set up since wire server is not available."); return; } var networkName = (!string.IsNullOrEmpty(parameters.ContainerNetworkName)) ? (parameters.ContainerNetworkName) : (FlatNetworkConstants.NetworkName); var containerServiceArguments = (parameters.UseContainerServiceArguments) ? (parameters.ContainerServiceArguments) : (FlatNetworkConstants.ContainerServiceArguments); DeployerTrace.WriteInfo("Container network set up invoked in context: {0}", parameters.Operation); bool containerServiceRunning = false; if (parameters.Operation == DeploymentOperations.Update || parameters.Operation == DeploymentOperations.UpdateInstanceId) { containerServiceRunning = IsContainerServiceRunning(); DeployerTrace.WriteInfo("Container service running : {0}", containerServiceRunning); } #if !DotNetCoreClrLinux containerServiceArguments = (parameters.EnableContainerServiceDebugMode) ? (string.Format("{0} {1}", containerServiceArguments, FlatNetworkConstants.ContainerProviderServiceDebugModeArg)) : containerServiceArguments; if (SetupContainerNetwork(networkName, containerServiceArguments, parameters.FabricDataRoot, containerServiceRunning)) #else if (SetupContainerNetwork(networkName, containerServiceArguments, parameters.FabricDataRoot, parameters.FabricBinRoot, containerServiceRunning)) #endif { DeployerTrace.WriteInfo("Successfully set up container network."); } else { string message = "Failed to set up container network."; DeployerTrace.WriteError(message); throw new InvalidDeploymentException(message); } }