private static void RenameFolder(string srcFolderName, string dstFolderName) { if (string.IsNullOrEmpty(srcFolderName) || !FabricDirectory.Exists(srcFolderName)) { throw new ArgumentException("Invalid source folder name specified"); } if (string.IsNullOrEmpty(dstFolderName) || FabricDirectory.Exists(dstFolderName)) { throw new ArgumentException("Invalid destination folder name specified"); } for (int i = 1; i <= MaxRetryAttempts; i++) { try { FabricFile.Move(srcFolderName, dstFolderName); if (i > 1) { // Try sleeping second time around Thread.Sleep(500); } //This is for the rare case of renaming failed without any error from the common library; referring to incident #45017448 if (!FabricDirectory.Exists(dstFolderName)) { traceSource.WriteWarning( ClassName, "Failed to rename folder {0} to {1} without any error, and retrying", srcFolderName, dstFolderName); } else { break; } } catch (Exception ex) { traceSource.WriteError( ClassName, "Failed to rename folder {0} to {1} with error {2}, and detail exception {3}", srcFolderName, dstFolderName, ex.Message, ex); } } }
/// <summary> /// This method executes the test with the specified parameter set passed into the constructor. /// </summary> /// <param name="token">the Cancellation token for the async operation.</param> /// <exception cref= "System.Fabric.FabricValidationException" >If any service does not stabilize within the specified timeout.</exception> /// <returns>Returns a Task which represents the asynchronous operation.</returns> public async Task ExecuteAsync(CancellationToken token) { DateTime testStartTime = DateTime.UtcNow; try { this.stopwatch = new Stopwatch(); this.stopwatch.Start(); this.TestContext = this.FabricClient.FaultManager.TestContext; // Call derived class method OnExecuteAsync() await this.OnExecuteAsync(token); this.ReportProgress("Scenario complete"); await this.ValidateScenarioAtExitAsync(token); Log.WriteInfo(TraceType, "ExecuteAsync(): Scenario completed."); } catch (OperationCanceledException) { Log.WriteWarning(TraceType, "ExecuteAsync(): Cancellation was requested while running the scenario."); throw; } catch (Exception e) { Log.WriteError(TraceType, "ExecuteAsync(): Exception was thrown while running the scenario: {0}", e); throw; } }
private static bool GetDestinationPathFromUri( FabricEvents.ExtensionsEvents traceSource, string logSourceId, string sectionName, string destinationPathAsUri, out string destinationPath) { destinationPath = string.Empty; try { Uri uri = new Uri(destinationPathAsUri); destinationPath = uri.LocalPath; } catch (UriFormatException e) { traceSource.WriteError( logSourceId, "The value '{0}' specified as the file share destination in section {1} could not be parsed as a URI. Exception information: {2}.", destinationPathAsUri, sectionName, e); return(false); } return(true); }
internal static TableServiceExceptionAction ProcessTableServiceQueryException(FabricEvents.ExtensionsEvents traceSource, string logSourceId, Exception e, TableServiceAction failedAction) { traceSource.WriteError( logSourceId, "Exception encountered when performing operation {0}. Exception information: {1}", failedAction, e); DataServiceQueryException eDataServiceQuery = e as DataServiceQueryException; if (null != eDataServiceQuery) { if (Utility.IsNetworkError(eDataServiceQuery.Response.StatusCode)) { // We encountered a network error that wasn't resolved even // after retries. throw new MaxRetriesException(); } else { return(TableServiceExceptionAction.Abort); } } StorageException eStorage = e as StorageException; if (null != eStorage) { return(ProcessStorageException(eStorage)); } return(TableServiceExceptionAction.Abort); }
public void WriteError(TraceType traceType, string format, params object[] args) { if (!string.IsNullOrEmpty(this.TraceId)) { TraceSource.WriteErrorWithId(traceType.Name, this.TraceId, format, args); } else { TraceSource.WriteError(traceType.Name, format, args); } }
public static PerfCounterFolderProcessor Create( FabricEvents.ExtensionsEvents traceSource, string logSourceId, ConfigReader configReader, string logDirectory, string outputFolderPath, out bool isEnabled, out List <string> additionalFoldersToTrim) { additionalFoldersToTrim = null; isEnabled = false; // Create a new instance of the folder processor PerfCounterFolderProcessor folderProcessor = new PerfCounterFolderProcessor(); // PerfCounterFolderProcessor is a singleton, so make sure there are no other instances. object original = Interlocked.CompareExchange(ref folderProcessorSingleton, folderProcessor, null); if (null != original) { traceSource.WriteError( logSourceId, "Cannot have more than one producer of type {0}, whose {1} value is {2}.", StandardPluginTypes.FolderProducer, FolderProducerValidator.FolderTypeParamName, FolderProducerValidator.ServiceFabricPerformanceCounters); return(null); } // Initialize the folder processor if (false == folderProcessor.Initialize(traceSource, logSourceId, configReader, logDirectory, outputFolderPath)) { return(null); } isEnabled = folderProcessor.perfCounterCollectionEnabled; if (isEnabled) { // In addition to the output folder, which is already trimmed by default, we also need // the perf counter binary folder and the perf counter binary archive folder to be trimmed. additionalFoldersToTrim = new List <string> { folderProcessor.perfCounterBinaryFolder }; if (false == folderProcessor.archiveFolderIsUnderBinaryFolder) { additionalFoldersToTrim.Add(folderProcessor.perfCounterBinaryArchiveFolder); } } return(folderProcessor); }
internal static TableServiceExceptionAction ProcessTableServiceRequestException(FabricEvents.ExtensionsEvents traceSource, string logSourceId, Exception e, TableServiceAction failedAction) { traceSource.WriteError( logSourceId, "Exception encountered when performing operation {0}. Exception information: {1}", failedAction, e); StorageException eStorage = e as StorageException; if (null != eStorage) { return(ProcessStorageException(eStorage)); } return(TableServiceExceptionAction.Abort); }
public bool ReadUnencryptedBool(string sectionName, string keyName, FabricEvents.ExtensionsEvents traceSource, string traceType, bool throwIfInvalid) { NativeConfigStore configStore = NativeConfigStore.FabricGetConfigStore(); string propertyValueStr = configStore.ReadUnencryptedString(sectionName, keyName); bool propertyValue = false; traceSource.WriteInfo(traceType, "{0} {1}", keyName, propertyValueStr); if (!bool.TryParse(propertyValueStr, out propertyValue)) { string message = string.Format("{0} could not parse: {1}", keyName, propertyValueStr); traceSource.WriteError(traceType, message); if (throwIfInvalid) { throw new InvalidDataException(message); } else { propertyValue = false; } } return(propertyValue); }
public static void WriteError(string format, params object[] args) { traceSource.WriteError(DeployerTrace.TraceType, format, args); }
public static void WriteError(TraceType traceType, string format, params object[] args) { traceSource.WriteError(traceType.Name, format, args); }
private static void WriteException(Exception ex) { TraceSource.WriteError(TraceType, "{0}", ex); }
public static void ReserveUrl(string networkUrl, string securityDescriptor) { TraceSource.WriteInfo( PortAclUtility.TraceType, "Started to Reserve Url. networkUrl: {0}, securityDescriptor: {1}.", networkUrl, securityDescriptor); uint retVal = (uint)NOERROR; // NOERROR = 0 HTTPAPI_VERSION httpApiVersion = new HTTPAPI_VERSION(1, 0); retVal = HttpInitialize(httpApiVersion, HTTP_INITIALIZE_CONFIG, IntPtr.Zero); TraceSource.WriteInfo( PortAclUtility.TraceType, "HttpInitialize completed with return value: {0}.", retVal); if ((uint)NOERROR == retVal) { HTTP_SERVICE_CONFIG_URLACL_KEY keyDesc = new HTTP_SERVICE_CONFIG_URLACL_KEY(networkUrl); HTTP_SERVICE_CONFIG_URLACL_PARAM paramDesc = new HTTP_SERVICE_CONFIG_URLACL_PARAM(securityDescriptor); HTTP_SERVICE_CONFIG_URLACL_SET inputConfigInfoSet = new HTTP_SERVICE_CONFIG_URLACL_SET { KeyDesc = keyDesc, ParamDesc = paramDesc }; IntPtr pInputConfigInfo = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_URLACL_SET))); Marshal.StructureToPtr(inputConfigInfoSet, pInputConfigInfo, false); retVal = HttpSetServiceConfiguration(IntPtr.Zero, HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, pInputConfigInfo, Marshal.SizeOf(inputConfigInfoSet), IntPtr.Zero); TraceSource.WriteInfo( PortAclUtility.TraceType, "HttpSetServiceConfiguration completed with return value: {0}.", retVal); if ((uint)ERROR_ALREADY_EXISTS == retVal) // ERROR_ALREADY_EXISTS = 183 { retVal = HttpDeleteServiceConfiguration(IntPtr.Zero, HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, pInputConfigInfo, Marshal.SizeOf(inputConfigInfoSet), IntPtr.Zero); TraceSource.WriteInfo( PortAclUtility.TraceType, "HttpDeleteServiceConfiguration(outer) completed with return value: {0}.", retVal); if ((uint)ERROR_FILE_NOT_FOUND == retVal) { // This means its possible that the URL is ACLed for the same port but different protocol (http/https) // Try deleting ACL using the other protocol var networkUrlInner = networkUrl.ToLower(); if (networkUrlInner.Contains("https")) { networkUrlInner = networkUrlInner.Replace("https", "http"); } else { networkUrlInner = networkUrlInner.Replace("http", "https"); } HTTP_SERVICE_CONFIG_URLACL_KEY keyDescInner = new HTTP_SERVICE_CONFIG_URLACL_KEY(networkUrlInner); HTTP_SERVICE_CONFIG_URLACL_SET inputConfigInfoSetInner = new HTTP_SERVICE_CONFIG_URLACL_SET { KeyDesc = keyDescInner }; IntPtr pInputConfigInfoInner = IntPtr.Zero; try { pInputConfigInfoInner = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_URLACL_SET))); Marshal.StructureToPtr(inputConfigInfoSetInner, pInputConfigInfoInner, false); retVal = HttpDeleteServiceConfiguration(IntPtr.Zero, HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, pInputConfigInfoInner, Marshal.SizeOf(inputConfigInfoSetInner), IntPtr.Zero); TraceSource.WriteWarning( PortAclUtility.TraceType, "HttpDeleteServiceConfiguration(Inner) completed with return value: {0}.", retVal); } finally { if (IntPtr.Zero != pInputConfigInfoInner) { Marshal.FreeCoTaskMem(pInputConfigInfoInner); } } } if ((uint)NOERROR == retVal) { retVal = HttpSetServiceConfiguration(IntPtr.Zero, HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, pInputConfigInfo, Marshal.SizeOf(inputConfigInfoSet), IntPtr.Zero); TraceSource.WriteInfo( PortAclUtility.TraceType, "HttpSetServiceConfiguration completed with return value: {0}.", retVal); } } Marshal.FreeCoTaskMem(pInputConfigInfo); HttpTerminate(HTTP_INITIALIZE_CONFIG, IntPtr.Zero); } if ((uint)NOERROR != retVal) { TraceSource.WriteError( PortAclUtility.TraceType, "ReserveUrl failed with error: {0}.", retVal); throw new Win32Exception(Convert.ToInt32(retVal)); } }
internal static bool GetAccessInfo( FabricEvents.ExtensionsEvents traceSource, string logSourceId, ConfigReader configReader, string sectionName, out FileShareUploader.AccessInformation accessInfo) { accessInfo = new FileShareUploader.AccessInformation { AccountType = FileShareUploader.FileShareAccessAccountType.None }; string accountType = configReader.GetUnencryptedConfigValue( sectionName, FileShareUploaderConstants.StoreAccessAccountType, string.Empty); if (string.IsNullOrEmpty(accountType)) { // Access information has not been specified return(true); } if (false == Enum.TryParse( accountType, out accessInfo.AccountType)) { traceSource.WriteError( logSourceId, "Account type {0} in section {1} is not supported.", accountType, sectionName); return(false); } string accountName = configReader.GetUnencryptedConfigValue( sectionName, FileShareUploaderConstants.StoreAccessAccountName, string.Empty); if (false == AccountHelper.TryParseUserAccountName( accountName, accessInfo.AccountType == FileShareUploader.FileShareAccessAccountType.ManagedServiceAccount, out accessInfo.UserName, out accessInfo.DomainName)) { traceSource.WriteError( logSourceId, "Domain name and user name could not be obtained from the account name {0} in section {1}.", accountName, sectionName); return(false); } if (FileShareUploader.FileShareAccessAccountType.ManagedServiceAccount == accessInfo.AccountType) { accessInfo.AccountPassword = NativeHelper.SERVICE_ACCOUNT_PASSWORD; accessInfo.AccountPasswordIsEncrypted = false; } else if (FileShareUploader.FileShareAccessAccountType.DomainUser == accessInfo.AccountType) { if (configReader.IsReadingFromApplicationManifest) { // When reading from the application manifest, the config reader does // cannot automatically figure out whether or not the value is encrypted. // So we figure it out ourselves. accessInfo.AccountPassword = configReader.GetUnencryptedConfigValue( sectionName, FileShareUploaderConstants.StoreAccessAccountPassword, string.Empty); string passwordEncrypted = configReader.GetUnencryptedConfigValue( sectionName, FileShareUploaderConstants.StoreAccessAccountPasswordIsEncrypted, FileShareUploaderConstants.PasswordEncryptedDefaultValue); if (false == bool.TryParse( passwordEncrypted, out accessInfo.AccountPasswordIsEncrypted)) { traceSource.WriteError( logSourceId, "Unable to determine whether the account password in section {0} is encrypted because {1} could not be parsed as a boolean value.", sectionName, passwordEncrypted); return(false); } } else { accessInfo.AccountPassword = configReader.ReadString( sectionName, FileShareUploaderConstants.StoreAccessAccountPassword, out accessInfo.AccountPasswordIsEncrypted); } } return(true); }