internal static unsafe CodePackage CreateFromNative(NativeRuntime.IFabricCodePackage nativePackage) { ReleaseAssert.AssertIfNull(nativePackage, "nativePackage"); string path = NativeTypes.FromNativeString(nativePackage.get_Path()); var nativeDescription = *((NativeTypes.FABRIC_CODE_PACKAGE_DESCRIPTION *)nativePackage.get_Description()); var description = CodePackageDescription.CreateFromNative(nativeDescription, path); var returnValue = new CodePackage() { Description = description, Path = path }; var nativePackage2 = (NativeRuntime.IFabricCodePackage2)nativePackage; if (nativePackage2.get_SetupEntryPointRunAsPolicy() != IntPtr.Zero) { returnValue.SetupEntryPointRunAsPolicy = RunAsPolicyDescription.CreateFromNative( *(NativeTypes.FABRIC_RUNAS_POLICY_DESCRIPTION *)nativePackage2.get_SetupEntryPointRunAsPolicy()); } if (nativePackage2.get_EntryPointRunAsPolicy() != IntPtr.Zero) { returnValue.EntryPointRunAsPolicy = RunAsPolicyDescription.CreateFromNative( *(NativeTypes.FABRIC_RUNAS_POLICY_DESCRIPTION *)nativePackage2.get_EntryPointRunAsPolicy()); } GC.KeepAlive(nativePackage2); GC.KeepAlive(nativePackage); return(returnValue); }
internal RestartNodeResult(SelectedReplica selectedReplica, NodeResult nodeResult) { ReleaseAssert.AssertIfNull(nodeResult, "Node result cannot be null"); ReleaseAssert.AssertIfNull(selectedReplica, "Selected replica cannot be null"); this.NodeResult = nodeResult; this.SelectedReplica = selectedReplica; }
/// <summary> /// Start Cluster Analysis /// </summary> /// <remarks> /// This abstraction get Invoked when User calls the rest API to Start Analysis. /// </remarks> /// <param name="configuration">The start configuration</param> /// <param name="token"></param> /// <returns></returns> public Task StartClusterAnalysisAsync(ClusterAnalysisConfiguration configuration, CancellationToken token) { ReleaseAssert.AssertIfNull(configuration, "configuration"); // Please note - since this is a user call, the end user call parameter value is true. return(this.StartClusterAnalysisInternalAsync(endUserCall: true, configuration: configuration, token: token)); }
void IStateProviderReplica.Initialize(StatefulServiceInitializationParameters initializationParameters) { this.initiParams = initializationParameters; this.traceId = ActorTrace.GetTraceIdForReplica(this.initiParams.PartitionId, this.initiParams.ReplicaId); var statefulServiceContext = new StatefulServiceContext( FabricRuntime.GetNodeContext(), this.initiParams.CodePackageActivationContext, this.initiParams.ServiceTypeName, this.initiParams.ServiceName, this.initiParams.InitializationData, this.initiParams.PartitionId, this.initiParams.ReplicaId); var stateManagerConfig = this.userDefinedStateManagerConfig; if (stateManagerConfig == null) { var actorImplType = this.actorTypeInformation.ImplementationType; stateManagerConfig = new ReliableStateManagerConfiguration( ActorNameFormat.GetConfigPackageName(actorImplType), ActorNameFormat.GetFabricServiceReplicatorSecurityConfigSectionName(actorImplType), ActorNameFormat.GetFabricServiceReplicatorConfigSectionName(actorImplType)); } this.stateManager = new ReliableStateManager(statefulServiceContext, stateManagerConfig); ReleaseAssert.AssertIfNull(this.onDataLossAsyncFunc, "onDataLossAsync event handler cannot be null."); this.stateManager.OnDataLossAsync = this.onDataLossAsyncFunc; this.stateManager.Initialize(this.initiParams); }
/// <summary> /// Move secondary replica result constructor. /// </summary> /// <param name="currentSecondaryNodeName">Current node name where secodary replica exist.</param> /// <param name="newSecondaryNodeName">New node name where secondary replica need to move.</param> /// <param name="selectedPartition">Selected partion result object</param> internal MoveSecondaryResult(string currentSecondaryNodeName, string newSecondaryNodeName, SelectedPartition selectedPartition) { ReleaseAssert.AssertIf(string.IsNullOrEmpty(currentSecondaryNodeName), "Current secondary node name cannot be null or empty"); this.CurrentSecondaryNodeName = currentSecondaryNodeName; this.NewSecondaryNodeName = newSecondaryNodeName; ReleaseAssert.AssertIfNull(selectedPartition, "Selected partition cannot be null"); this.SelectedPartition = selectedPartition; }
public void Release() { ReleaseAssert.AssertIfNull(this.sharedNativeObject, "sharedNativeObject"); AppTrace.TraceSource.WriteNoise(this.traceType, "SharedNativeObject<{0}>.Release: CurrentReferenceCount={1}", this.typeName, this.GetCurrentCount()); if (this.referenceCount.Release() == 0) { Utility.SafeReleaseComObject(this.sharedNativeObject); } }
protected override async Task ExecuteActionAsync(FabricTestContext testContext, IsClusterUpgradingAction action, CancellationToken cancellationToken) { var currentProgress = await FabricClientRetryHelper.ExecuteFabricActionWithRetryAsync( () => testContext.FabricClient.ClusterManager.GetFabricUpgradeProgressAsync( action.RequestTimeout, cancellationToken), FabricClientRetryErrors.UpgradeFabricErrors.Value, action.ActionTimeout, cancellationToken).ConfigureAwait(false); ReleaseAssert.AssertIfNull(currentProgress, "currentProgress"); action.Result = currentProgress.UpgradeState != FabricUpgradeState.RollingBackCompleted && currentProgress.UpgradeState != FabricUpgradeState.RollingForwardCompleted; ResultTraceString = "IsClusterUpgradingAction succeeded"; }
internal static unsafe DataPackage CreateFromNative(NativeRuntime.IFabricDataPackage nativePackage) { ReleaseAssert.AssertIfNull(nativePackage, "nativePackage"); string path = NativeTypes.FromNativeString(nativePackage.get_Path()); var nativeDescription = *((NativeTypes.FABRIC_DATA_PACKAGE_DESCRIPTION *)nativePackage.get_Description()); var description = DataPackageDescription.CreateFromNative(nativeDescription, path); var returnValue = new DataPackage() { Description = description, Path = path }; GC.KeepAlive(nativePackage); return(returnValue); }
public T TryAcquire() { ReleaseAssert.AssertIfNull(this.sharedNativeObject, "sharedNativeObject"); if (this.referenceCount.TryAdd() > 0) { AppTrace.TraceSource.WriteNoise(this.traceType, "{0}.TryAdd: SUCCESS. CurrentReferenceCount={1}", this.typeName, this.GetCurrentCount()); return(this.sharedNativeObject); } else { AppTrace.TraceSource.WriteNoise(this.traceType, "{0}.TryAdd: FAILED. CurrentReferenceCount={1}", this.typeName, this.GetCurrentCount()); return(null); } }
internal static unsafe ConfigurationPackage CreateFromNative(NativeRuntime.IFabricConfigurationPackage nativePackage) { ReleaseAssert.AssertIfNull(nativePackage, "nativePackage"); string path = NativeTypes.FromNativeString(nativePackage.get_Path()); var settings = ConfigurationSettings.CreateFromNative(nativePackage.get_Settings()); var nativeDescription = *((NativeTypes.FABRIC_CONFIGURATION_PACKAGE_DESCRIPTION *)nativePackage.get_Description()); var description = ConfigurationPackageDescription.CreateFromNative(nativeDescription, path, settings); var returnValue = new ConfigurationPackage() { Description = description, Path = path, Settings = settings }; GC.KeepAlive(nativePackage); return(returnValue); }
public AzureInfrastructure(ClusterManifestTypeInfrastructure cmInfrastructure, InfrastructureNodeType[] inputInfrastructureNodes, Dictionary <string, ClusterManifestTypeNodeType> nameToNodeTypeMap) { ReleaseAssert.AssertIfNull(cmInfrastructure, "cmInfrastructure"); ReleaseAssert.AssertIfNull(nameToNodeTypeMap, "nameToNodeTypeMap"); this.votes = new List <SettingsTypeSectionParameter>(); this.seedNodeClientConnectionAddresses = new List <SettingsTypeSectionParameter>(); this.voteMappings = new Dictionary <string, string>(); this.nodes = new List <InfrastructureNodeType>(); TopologyProvider.TopologyProviderType topologyProviderType = TopologyProvider.GetTopologyProviderTypeFromClusterManifestTypeInfrastructure(cmInfrastructure); if (topologyProviderType == TopologyProvider.TopologyProviderType.ServiceRuntimeTopologyProvider) { this.InitializeFromServiceRuntimeTopologyProvider(cmInfrastructure.Item as ClusterManifestTypeInfrastructureWindowsAzure, inputInfrastructureNodes, nameToNodeTypeMap); } else if (topologyProviderType == TopologyProvider.TopologyProviderType.StaticTopologyProvider) { this.InitializeFromStaticTopologyProvider(cmInfrastructure.Item as ClusterManifestTypeInfrastructureWindowsAzureStaticTopology, inputInfrastructureNodes, nameToNodeTypeMap); } }
protected List <NodeStatus> GetNodesToBeDisabled(string nodeTypeName, int toBeDisabledNodeCount) { List <NodeStatus> nodesToBeDisabled = new List <NodeStatus>(); SortedList <string, NodeStatus> nodeTypeNodeStatusList = this.ClusterResource.NodeTypeNodeStatusList[nodeTypeName]; ReleaseAssert.AssertIfNull(nodeTypeNodeStatusList, "nodeTypeNodeStatusList"); var seedNodes = new HashSet <string>(((ClusterManifestTypeInfrastructurePaaS)this.ExternalState.ClusterManifest.Infrastructure.Item).Votes.Select(vote => vote.NodeName)); foreach (var nodeStatusKeyValue in nodeTypeNodeStatusList.Reverse()) { if (toBeDisabledNodeCount <= 0) { break; } var nodeStatus = nodeStatusKeyValue.Value; if (!seedNodes.Contains(nodeStatus.NodeName)) { nodesToBeDisabled.Add(nodeStatus); toBeDisabledNodeCount--; } } if (toBeDisabledNodeCount > 0) { this.TraceLogger.WriteError( TraceType, "{0} nodes in NodeType {1} could be disabled since the are no more nodes left which are not seed nodes. Total current nodes in node type: {2}", toBeDisabledNodeCount, nodeTypeName, nodeTypeNodeStatusList.Count); } return(nodesToBeDisabled); }
internal void WriteTargetInformationFile(string clusterManifestLocation, string infrastructureManifestLocation, string fabricDataRoot, string machineName, string packageLocation, FabricPackageType fabricPackageType, string sourcePackageLocation) { ReleaseAssert.AssertIfNull(fabricDataRoot, "DataRoot Should not be null after configuration"); TargetInformationType targetInformation = new TargetInformationType { TargetInstallation = new WindowsFabricDeploymentInformation { TargetVersion = Utility.GetCurrentCodeVersion(sourcePackageLocation), ClusterManifestLocation = clusterManifestLocation, UpgradeEntryPointExe = "FabricSetup.exe", UpgradeEntryPointExeParameters = "/operation:Install" } }; if (fabricPackageType == FabricPackageType.XCopyPackage) { targetInformation.TargetInstallation.MSILocation = packageLocation; } if (!string.IsNullOrEmpty(infrastructureManifestLocation)) { targetInformation.TargetInstallation.InfrastructureManifestLocation = infrastructureManifestLocation; } string targetInformationFileName = Path.Combine(fabricDataRoot, Constants.FileNames.TargetInformation); DeployerTrace.WriteInfo("TargetInformationFileName is {0}", targetInformationFileName); if (!string.IsNullOrEmpty(machineName) && !machineName.Equals(Helpers.GetMachine())) { targetInformation.TargetInstallation.ClusterManifestLocation = Path.Combine(fabricDataRoot, "clusterManifest.xml"); targetInformationFileName = Helpers.GetRemotePath(targetInformationFileName, machineName); } XmlHelper.WriteXmlExclusive <TargetInformationType>(targetInformationFileName, targetInformation); DeployerTrace.WriteInfo("Target information file {0} written on machine: {1}", targetInformationFileName, machineName); }
/// <summary> /// Restart deployed code package result constructor. /// </summary> /// <param name="nodeName">node name</param> /// <param name="applicationName">application name</param> /// <param name="serviceManifestName">service manifest name</param> /// <param name="servicePackageActivationId">service package ActivationId</param> /// <param name="codePackageName">code package name</param> /// <param name="codePackageInstanceId">code package instance id</param> /// <param name="selectedReplica">selected replica</param> internal RestartDeployedCodePackageResult( string nodeName, Uri applicationName, string serviceManifestName, string servicePackageActivationId, string codePackageName, long codePackageInstanceId, SelectedReplica selectedReplica) { ReleaseAssert.AssertIfNull(applicationName, "Application name cannot be null"); this.ApplicationName = applicationName; ReleaseAssert.AssertIf(string.IsNullOrEmpty(nodeName), "Node name cannot be null or empty"); this.NodeName = nodeName; ReleaseAssert.AssertIf(string.IsNullOrEmpty(serviceManifestName), "Service manifestName cannot be null or empty"); this.ServiceManifestName = serviceManifestName; ReleaseAssert.AssertIf(string.IsNullOrEmpty(codePackageName), "Code package name cannot be null or empty"); this.CodePackageName = codePackageName; ReleaseAssert.AssertIf(codePackageInstanceId == 0, "Code package instance id cannot be zero"); this.CodePackageInstanceId = codePackageInstanceId; this.SelectedReplica = selectedReplica; ReleaseAssert.AssertIfNull(servicePackageActivationId, "ServicePackageActivationId cannot be null"); this.ServicePackageActivationId = servicePackageActivationId; }
/// <summary> /// Replica result constructor. /// </summary> /// <param name="selectedReplica">Selected replica</param> internal ReplicaResult(SelectedReplica selectedReplica) { ReleaseAssert.AssertIfNull(selectedReplica, "Selected replica cannot be null"); this.SelectedReplica = selectedReplica; }
/// <summary> /// Move primary replica result object constructor. /// </summary> /// <param name="nodeName">Node name where primary will be moving.</param> /// <param name="selectedPartition">Selected partition</param> internal MovePrimaryResult(string nodeName, SelectedPartition selectedPartition) { this.NodeName = nodeName; ReleaseAssert.AssertIfNull(selectedPartition, "Selected partition cannot be null"); this.SelectedPartition = selectedPartition; }
/// <summary> /// Restart partition result constructor. /// </summary> /// <param name="selectedPartition">selected partition</param> internal RestartPartitionResult(SelectedPartition selectedPartition) { ReleaseAssert.AssertIfNull(selectedPartition, "Selected partition cannot be null"); this.SelectedPartition = selectedPartition; }
internal ClusterAnalysisRunner(ILogProvider logProvider) { ReleaseAssert.AssertIfNull(logProvider, "logProvider != null"); this.logger = logProvider.CreateLoggerInstance(ClusterAnalyzerRunnerTraceIdentifier); this.analysisEngine = new ClusterAnalysisEngine(); }
private void InitializeFromServiceRuntimeTopologyProvider(ClusterManifestTypeInfrastructureWindowsAzure azureInfrastructure, InfrastructureNodeType[] inputInfrastructureNodes, Dictionary <string, ClusterManifestTypeNodeType> nameToNodeTypeMap) { // For service runtime topology provider, source of cluster topology is infrastructure manifest provided by azure wrapper service. // Seed nodes are determined as the first SeedNodeCount nodes of the seed node role. ReleaseAssert.AssertIfNull(inputInfrastructureNodes, "inputInfrastructureNodes"); Dictionary <string, int> seedInfo = new Dictionary <string, int>(); Dictionary <string, string> roleToTypeMap = new Dictionary <string, string>(); foreach (var role in azureInfrastructure.Roles) { try { seedInfo.Add(role.RoleName, role.SeedNodeCount); roleToTypeMap.Add(role.RoleName, role.NodeTypeRef); } catch (ArgumentException) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Role name {0} is duplicate", role.RoleName)); } } foreach (var nodeInfo in inputInfrastructureNodes) { string nodeIndex = nodeInfo.NodeName.Split(".".ToCharArray()).Last(); int index = int.Parse(nodeIndex); ClusterManifestTypeNodeType nodeType = null; if (roleToTypeMap.ContainsKey(nodeInfo.RoleOrTierName)) { var nodeTypeName = roleToTypeMap[nodeInfo.RoleOrTierName]; if (nameToNodeTypeMap.ContainsKey(nodeTypeName)) { nodeType = nameToNodeTypeMap[nodeTypeName]; } else { throw new ArgumentException( string.Format( CultureInfo.InvariantCulture, "Node type {0} specified for role {1} in node {2} not found", nodeTypeName, nodeInfo.RoleOrTierName, nodeInfo.NodeName)); } } else { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Role name {0} specified in node {1} not found", nodeInfo.NodeName, nodeInfo.RoleOrTierName)); } var node = new InfrastructureNodeType() { FaultDomain = nodeInfo.FaultDomain, IPAddressOrFQDN = nodeInfo.IPAddressOrFQDN, IsSeedNode = index < seedInfo[nodeInfo.RoleOrTierName], NodeName = nodeInfo.NodeName, NodeTypeRef = roleToTypeMap[nodeInfo.RoleOrTierName], UpgradeDomain = nodeInfo.UpgradeDomain, RoleOrTierName = nodeInfo.RoleOrTierName, Endpoints = nodeInfo.Endpoints, Certificates = nodeType.Certificates }; this.nodes.Add(node); if (node.IsSeedNode) { // Add vote mappings string connectionAddress = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", node.IPAddressOrFQDN, node.Endpoints.ClusterConnectionEndpoint.Port); this.voteMappings.Add(node.NodeName, connectionAddress); FabricValidator.TraceSource.WriteNoise(FabricValidatorUtility.TraceTag, "Mapping {0}-{1} added", node.NodeName, connectionAddress); // Add votes. string key = node.NodeName; string value = string.Format(CultureInfo.InvariantCulture, "{0},{1}", "WindowsAzure", node.NodeName); this.votes.Add(new SettingsTypeSectionParameter() { Name = key, Value = value, MustOverride = false }); FabricValidator.TraceSource.WriteNoise(FabricValidatorUtility.TraceTag, "Vote {0}-{1} added", key, value); string clientConnectionAddress = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", node.IPAddressOrFQDN, node.Endpoints.ClientConnectionEndpoint.Port); this.seedNodeClientConnectionAddresses.Add(new SettingsTypeSectionParameter() { Name = key, Value = clientConnectionAddress, MustOverride = false }); FabricValidator.TraceSource.WriteNoise(FabricValidatorUtility.TraceTag, "Seed Nodes {0}-{1} added", key, clientConnectionAddress); } } this.isScaleMin = FabricValidatorUtility.IsAddressLoopback(nodes[0].IPAddressOrFQDN); }
private bool TryInterruptPendingUpgrade() { if (!this.clusterResource.Pending.CanInterruptUpgrade()) { this.traceLogger.WriteInfo(TraceType, "TryInterruptPendingUpgrade: Can not interrupt pending upgrade since Pending.CanInterruptUpgrade is false"); return(false); } var pendingCsmConfig = this.clusterResource.Pending.TargetCsmConfig; var pendingWrpConfig = this.clusterResource.Pending.TargetWrpConfig; var pendingNodeConfig = this.clusterResource.Pending.TargetNodeConfig; if (this.clusterResource.Pending.IsUserInitiatedUpgrade()) { if (this.clusterResource.TargetCsmConfig == null) { throw new ValidationException( ClusterManagementErrorCode.OperationInconsistentWithStateMachine, "this.clusterResource.TargetCsmConfig cannot be null"); } if (!this.clusterResource.TargetCsmConfig.Version.Equals(pendingCsmConfig.Version) && !this.clusterResource.TargetCsmConfigUpgradeFailed) { pendingCsmConfig = this.clusterResource.TargetCsmConfig; if (this.clusterResource.TargetNodeConfig != null && this.clusterResource.TargetNodeConfig.IsUserSet) { // If the current target node config is set by user // then set it as part of the pending upgrade pendingNodeConfig = this.clusterResource.TargetNodeConfig; } } if (this.clusterResource.TargetWrpConfig != null && this.clusterResource.TargetWrpConfig.IsUserSet) { // If the current target wrp config is set by user // then set it as part of the pending upgrade pendingWrpConfig = this.clusterResource.TargetWrpConfig; } else if (pendingWrpConfig.IsUserSet) { // If the upgrade to be interrupted contains user initiated wrp config, then // use wrp config of current since all of user's upgrade has to be interrupted pendingWrpConfig = this.clusterResource.Current.WRPConfig; } } else if (this.clusterResource.Pending.IsAdminInitiatedUpgrade()) { if (this.clusterResource.TargetWrpConfig == null) { throw new ValidationException( ClusterManagementErrorCode.OperationInconsistentWithStateMachine, "this.clusterResource.TargetWrpConfig cannot be null"); } // Current upgrade is driven from WRP if (!this.clusterResource.TargetWrpConfig.Version.Equals(pendingWrpConfig.Version) && !this.clusterResource.TargetWrpConfigUpgradeFailed) { pendingWrpConfig = this.clusterResource.TargetWrpConfig; if (this.clusterResource.TargetWrpConfig.IsUserSet) { ReleaseAssert.AssertIfNull(this.clusterResource.TargetCsmConfig, "TargetCsmConfig should not be null when TargetWrpConfig is user set."); // If the interrupting wrp config is set by user // then set the target csm config as well pendingCsmConfig = this.clusterResource.TargetCsmConfig; } } } else if (this.clusterResource.Pending.IsAutoScaleUpgrade()) { if (this.clusterResource.TargetNodeConfig == null) { throw new ValidationException( ClusterManagementErrorCode.OperationInconsistentWithStateMachine, "this.clusterResource.TargetNodeConfig cannot be null"); } // Current upgrade is auto-scale upgrade if (!this.clusterResource.TargetNodeConfig.Version.Equals(pendingNodeConfig.Version)) { pendingNodeConfig = this.clusterResource.TargetNodeConfig; } } if (pendingCsmConfig.Version.Equals(this.clusterResource.Pending.TargetCsmConfig.Version) && pendingWrpConfig.Version.Equals(this.clusterResource.Pending.TargetWrpConfig.Version) && pendingNodeConfig.Version.Equals(this.clusterResource.Pending.TargetNodeConfig.Version)) { this.traceLogger.WriteInfo(TraceType, "TryInterruptPendingUpgrade: No need to interrupt pending upgrade since the target config versions are the same"); return(false); } ClusterUpgradeStateBase pendingUpgrade; if (!this.UpgradeFactory.TryCreateUpgradeState( pendingCsmConfig, pendingWrpConfig, pendingNodeConfig, out pendingUpgrade)) { this.traceLogger.WriteInfo(TraceType, "TryInterruptPendingUpgrade: Tried to interrupt but fails since UpgradeFactory.TryCreateUpgradeState returns false"); return(false); } var clusterState = pendingUpgrade.ClusterUpgradeStarted(); if (clusterState != null) { throw new ValidationException( ClusterManagementErrorCode.OperationInconsistentWithStateMachine, "ClusterUpgradeStarted should return null clusterState when there is a PendingUpgrade"); } this.traceLogger.WriteInfo(TraceType, "TryInterruptPendingUpgrade: Interrupt successfully"); this.clusterResource.Pending = pendingUpgrade; return(true); }
internal PartitionRestartResult(SelectedPartition selectedPartition, int errorCode) { ReleaseAssert.AssertIfNull(selectedPartition, "Selected partition cannot be null"); this.SelectedPartition = selectedPartition; this.ErrorCode = errorCode; }