public async Task WhenAzureBlobStorageContainerExists_ThenAzureBlobStorageServiceIsHealthy() { A.CallTo(() => fakeSalesCatalogueStorageService.GetStorageAccountConnectionString(string.Empty, string.Empty)).Returns(GetStorageAccountConnectionStringAndContainerName().Item1); A.CallTo(() => fakeAzureBlobStorageClient.CheckBlobContainerHealth(A <string> .Ignored, A <string> .Ignored)).Returns(HealthCheckResult.Healthy("Azure blob storage is healthy")); var response = await azureBlobStorageHealthCheck.CheckHealthAsync(new HealthCheckContext()); Assert.AreEqual(HealthStatus.Healthy, response.Status); }
public async Task WhenInvalidRequestDataInDeleteSearchAndDownloadCache_ThenReturnResponseFalse() { A.CallTo(() => fakeAzureTableStorageClient.RetrieveFromTableStorageAsync <FssSearchResponseCache>(A <string> .Ignored, A <string> .Ignored, A <string> .Ignored, A <string> .Ignored)).Returns(GetResponseCache()); A.CallTo(() => fakeAzureStorageService.GetStorageAccountConnectionString(A <string> .Ignored, A <string> .Ignored)).Returns(GetStorageAccountConnectionString()); await service.DeleteSearchAndDownloadCacheData(GetInvalidCacheRequestData(), FakeCorrelationId); A.CallTo(() => fakeAzureTableStorageClient.DeleteAsync(A <TableEntity> .Ignored, A <string> .Ignored, A <string> .Ignored, A <string> .Ignored)).MustNotHaveHappened(); A.CallTo(() => fakeAzureBlobStorageClient.DeleteCacheContainer(A <string> .Ignored, A <string> .Ignored)).MustNotHaveHappened(); }
public void WhenScsStorageAccountAccessKeyValueNotfound_ThenGetStorageAccountConnectionStringReturnsKeyNotFoundException() { SalesCatalogueServiceResponseQueueMessage scsResponseQueueMessage = GetScsResponseQueueMessage(); A.CallTo(() => fakeScsStorageService.GetStorageAccountConnectionString(null, null)) .Throws(new KeyNotFoundException("Storage account accesskey not found")); Assert.ThrowsAsync(Is.TypeOf <KeyNotFoundException>().And.Message.EqualTo("Storage account accesskey not found"), async delegate { await fulfilmentDataService.CreateExchangeSet(scsResponseQueueMessage, currentUtcDate); }); }
public async Task WhenAzureMessageQueueExists_ThenAzureMessageQueueIsHealthy() { A.CallTo(() => fakeSalesCatalogueStorageService.GetStorageAccountConnectionString(string.Empty, string.Empty)).Returns(GetStorageAccountConnectionStringAndContainerName().Item1); A.CallTo(() => fakeAzureMessageQueueHelperClient.CheckMessageQueueHealth(A <string> .Ignored, A <string> .Ignored)).Returns(new HealthCheckResult(HealthStatus.Healthy, "Azure message queue is healthy")); A.CallTo(() => fakeAzureBlobStorageService.GetInstanceCountBasedOnExchangeSetType(A <ExchangeSetType> .Ignored)).Returns(1); var response = await azureMessageQueueHealthCheck.CheckHealthAsync(new HealthCheckContext()); Assert.AreEqual(HealthStatus.Healthy, response.Status); }
public async Task WhenGetNonCachedProductDataForFssIsCalled_ThenReturnProductNotFound() { string exchangeSetRootPath = @"C:\\HOME"; A.CallTo(() => fakeAzureStorageService.GetStorageAccountConnectionString(A <string> .Ignored, A <string> .Ignored)).Returns(GetStorageAccountConnectionStringAndContainerName().Item1); A.CallTo(() => fakeAzureTableStorageClient.RetrieveFromTableStorageAsync <FssSearchResponseCache>(A <string> .Ignored, A <string> .Ignored, A <string> .Ignored, A <string> .Ignored)).Returns(GetResponseCache()); A.CallTo(() => fakeAzureBlobStorageClient.GetCloudBlockBlob(A <string> .Ignored, A <string> .Ignored, A <string> .Ignored)).Returns(new CloudBlockBlob(new System.Uri("http://tempuri.org/blob"))); A.CallTo(() => fakeFileSystemHelper.DownloadToFileAsync(A <CloudBlockBlob> .Ignored, A <string> .Ignored)); var response = await fileShareServiceCache.GetNonCachedProductDataForFss(GetProductdetails(), GetSearchBatchResponse(), exchangeSetRootPath, GetScsResponseQueueMessage(), null, CancellationToken.None); Assert.AreEqual(0, response.Count); }
public void WhenScsStorageAccountAccessKeyValueNotFound_ThenReturnKeyNotFoundException() { FakeAzureFileHelper fakeAzureFileHelper = new FakeAzureFileHelper(); A.CallTo(() => fakeScsStorageService.GetStorageAccountConnectionString(A <string> .Ignored, A <string> .Ignored)) .Throws(new KeyNotFoundException("Storage account accesskey not found")); Assert.ThrowsAsync(Is.TypeOf <KeyNotFoundException>() .And.Message.EqualTo("Storage account accesskey not found") , async delegate { await exchangeSetCleanUpService.DeleteHistoricFoldersAndFiles(); }); Assert.AreEqual(false, fakeAzureFileHelper.DeleteDirectoryAsyncIsCalled); }
public async Task <HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) { try { string[] exchangeSetTypes = essFulfilmentStorageConfiguration.Value.ExchangeSetTypes.Split(","); string storageAccountConnectionString = string.Empty; HealthCheckResult azureBlobStorageHealthStatus = new HealthCheckResult(HealthStatus.Healthy, "Azure blob storage is healthy"); foreach (string exchangeSetType in exchangeSetTypes) { Enum.TryParse(exchangeSetType, out ExchangeSetType exchangeSetTypeName); var storageAccountWithKey = azureBlobStorageService.GetStorageAccountNameAndKeyBasedOnExchangeSetType(exchangeSetTypeName); storageAccountConnectionString = scsStorageService.GetStorageAccountConnectionString(storageAccountWithKey.Item1, storageAccountWithKey.Item2); azureBlobStorageHealthStatus = await azureBlobStorageClient.CheckBlobContainerHealth(storageAccountConnectionString, essFulfilmentStorageConfiguration.Value.StorageContainerName); if (azureBlobStorageHealthStatus.Status == HealthStatus.Unhealthy) { logger.LogError(EventIds.AzureBlobStorageIsUnhealthy.ToEventId(), azureBlobStorageHealthStatus.Exception, "Azure blob storage is unhealthy for exchangeSetType: {exchangeSetType} with error {Message}", exchangeSetType, azureBlobStorageHealthStatus.Exception.Message); azureBlobStorageHealthStatus = HealthCheckResult.Unhealthy("Azure blob storage is unhealthy", azureBlobStorageHealthStatus.Exception); return(azureBlobStorageHealthStatus); } } logger.LogDebug(EventIds.AzureBlobStorageIsHealthy.ToEventId(), "Azure blob storage is healthy"); return(azureBlobStorageHealthStatus); } catch (Exception ex) { logger.LogError(EventIds.AzureBlobStorageIsUnhealthy.ToEventId(), ex, "Azure blob storage is unhealthy with error {Message}", ex.Message); return(HealthCheckResult.Unhealthy("Azure blob storage is unhealthy", ex)); } }
private async Task <HealthCheckResult> CheckAllMessageQueuesHealth() { string[] exchangeSetTypes = essFulfilmentStorageConfiguration.Value.ExchangeSetTypes.Split(","); string storageAccountConnectionString, queueName = string.Empty; HealthCheckResult messageQueueHealthStatus = new HealthCheckResult(HealthStatus.Healthy, "Azure message queue is healthy"); foreach (string exchangeSetTypeName in exchangeSetTypes) { Enum.TryParse(exchangeSetTypeName, out ExchangeSetType exchangeSetType); for (int i = 1; i <= azureBlobStorageService.GetInstanceCountBasedOnExchangeSetType(exchangeSetType); i++) { queueName = string.Format(essFulfilmentStorageConfiguration.Value.DynamicQueueName, i); var storageAccountWithKey = azureBlobStorageService.GetStorageAccountNameAndKeyBasedOnExchangeSetType(exchangeSetType); storageAccountConnectionString = scsStorageService.GetStorageAccountConnectionString(storageAccountWithKey.Item1, storageAccountWithKey.Item2); messageQueueHealthStatus = await azureMessageQueueHelper.CheckMessageQueueHealth(storageAccountConnectionString, queueName); if (messageQueueHealthStatus.Status == HealthStatus.Unhealthy) { logger.LogError(EventIds.AzureMessageQueueIsUnhealthy.ToEventId(), messageQueueHealthStatus.Exception, "Azure message queue {queueName} is unhealthy", queueName); return(messageQueueHealthStatus); } } } logger.LogDebug(EventIds.AzureMessageQueueIsHealthy.ToEventId(), "Azure message queue is healthy"); return(messageQueueHealthStatus); }
public async Task WhenCallStoreSaleCatalogueServiceResponseAsync_ThenReturnsTrue() { string batchId = "7b4cdf10-adfa-4ed6-b2fe-d1543d8b7272"; string containerName = "testContainer"; string callBackUri = "https://essTest/myCallback?secret=test&po=1234"; string correlationId = "a6670458-9bbc-4b52-95a2-d1f50fe9e3ae"; string storageAccountConnectionString = "DefaultEndpointsProtocol = https; AccountName = testessdevstorage2; AccountKey =testaccountkey; EndpointSuffix = core.windows.net"; SalesCatalogueProductResponse salesCatalogueProductResponse = GetSalesCatalogueServiceResponse(); CancellationToken cancellationToken = CancellationToken.None; A.CallTo(() => fakeScsStorageService.GetStorageAccountConnectionString(null, null)).Returns(storageAccountConnectionString); A.CallTo(() => fakeAzureBlobStorageClient.GetCloudBlockBlob(A <string> .Ignored, A <string> .Ignored, A <string> .Ignored)).Returns(new CloudBlockBlob(new System.Uri("http://tempuri.org/blob"))); A.CallTo(() => fakeSmallExchangeSetInstance.GetInstanceNumber(1)).Returns(3); var response = await azureBlobStorageService.StoreSaleCatalogueServiceResponseAsync(containerName, batchId, salesCatalogueProductResponse, callBackUri, correlationId, cancellationToken, fakeExpiryDate); Assert.IsTrue(response); }
public async Task <List <Products> > GetNonCachedProductDataForFss(List <Products> products, SearchBatchResponse internalSearchBatchResponse, string exchangeSetRootPath, SalesCatalogueServiceResponseQueueMessage queueMessage, CancellationTokenSource cancellationTokenSource, CancellationToken cancellationToken) { var internalProductsNotFound = new List <Products>(); foreach (var item in products) { if (cancellationToken.IsCancellationRequested) { logger.LogError(EventIds.CancellationTokenEvent.ToEventId(), "Operation cancelled as IsCancellationRequested flag is true while searching ENC files from cache for Product/CellName:{ProductName}, EditionNumber:{EditionNumber} and UpdateNumbers:[{UpdateNumbers}]. BatchId:{batchId} and _X-Correlation-ID:{CorrelationId}", item.ProductName, item.EditionNumber, string.Join(",", item.UpdateNumbers.Select(a => a.Value.ToString())), queueMessage.BatchId, queueMessage.CorrelationId); throw new OperationCanceledException(); } var internalProductItemNotFound = new Products { Cancellation = item.Cancellation, Dates = item.Dates, EditionNumber = item.EditionNumber, FileSize = item.FileSize, ProductName = item.ProductName, UpdateNumbers = new List <int?>() }; List <int?> updateNumbers = new List <int?>(); foreach (var itemUpdateNumber in item.UpdateNumbers) { var compareProducts = $"{item.ProductName}|{item.EditionNumber.Value}|{itemUpdateNumber.Value}"; var productList = new List <string>(); if (!productList.Contains(compareProducts)) { var storageConnectionString = azureStorageService.GetStorageAccountConnectionString(fssCacheConfiguration.Value.CacheStorageAccountName, fssCacheConfiguration.Value.CacheStorageAccountKey); var cacheInfo = (FssSearchResponseCache)await azureTableStorageClient.RetrieveFromTableStorageAsync <FssSearchResponseCache>(item.ProductName, item.EditionNumber + "|" + itemUpdateNumber.Value, fssCacheConfiguration.Value.FssSearchCacheTableName, storageConnectionString); if (cacheInfo != null && !string.IsNullOrEmpty(cacheInfo.Response)) { var internalBatchDetail = await CheckIfCacheProductsExistsInBlob(exchangeSetRootPath, queueMessage, item, updateNumbers, itemUpdateNumber, storageConnectionString, cacheInfo); internalSearchBatchResponse.Entries.Add(internalBatchDetail); productList.Add(compareProducts); } else { internalProductItemNotFound.UpdateNumbers.Add(itemUpdateNumber); } } } if (internalProductItemNotFound.UpdateNumbers != null && internalProductItemNotFound.UpdateNumbers.Any()) { internalProductsNotFound.Add(internalProductItemNotFound); } } return(internalProductsNotFound); }
public async Task <bool> StoreSaleCatalogueServiceResponseAsync(string containerName, string batchId, SalesCatalogueProductResponse salesCatalogueResponse, string callBackUri, string correlationId, CancellationToken cancellationToken, string expiryDate) { string uploadFileName = string.Concat(batchId, ".json"); long fileSize = CommonHelper.GetFileSize(salesCatalogueResponse); var fileSizeInMB = CommonHelper.ConvertBytesToMegabytes(fileSize); var instanceCountAndType = GetInstanceCountBasedOnFileSize(fileSizeInMB); var storageAccountWithKey = GetStorageAccountNameAndKeyBasedOnExchangeSetType(instanceCountAndType.Item2); string storageAccountConnectionString = scsStorageService.GetStorageAccountConnectionString(storageAccountWithKey.Item1, storageAccountWithKey.Item2); CloudBlockBlob cloudBlockBlob = await azureBlobStorageClient.GetCloudBlockBlob(uploadFileName, storageAccountConnectionString, containerName); cloudBlockBlob.Properties.ContentType = CONTENT_TYPE; await UploadSalesCatalogueServiceResponseToBlobAsync(cloudBlockBlob, salesCatalogueResponse); logger.LogInformation(EventIds.SCSResponseStoredToBlobStorage.ToEventId(), "Sales catalogue service response stored to blob storage with fileSizeInMB:{fileSizeInMB} for BatchId:{batchId} and _X-Correlation-ID:{CorrelationId} ", fileSizeInMB, batchId, correlationId); await AddQueueMessage(batchId, salesCatalogueResponse, callBackUri, correlationId, cloudBlockBlob, instanceCountAndType.Item1, storageAccountConnectionString, expiryDate); return(true); }
public async Task DeleteSearchAndDownloadCacheData(EnterpriseEventCacheDataRequest enterpriseEventCacheDataRequest, string correlationId) { var productCode = enterpriseEventCacheDataRequest.Attributes.Where(a => a.Key == "ProductCode").Select(a => a.Value).FirstOrDefault(); var cellName = enterpriseEventCacheDataRequest.Attributes.Where(a => a.Key == "CellName").Select(a => a.Value).FirstOrDefault(); var editionNumber = enterpriseEventCacheDataRequest.Attributes.Where(a => a.Key == "EditionNumber").Select(a => a.Value).FirstOrDefault(); var updateNumber = enterpriseEventCacheDataRequest.Attributes.Where(a => a.Key == "UpdateNumber").Select(a => a.Value).FirstOrDefault(); if (ValidateCacheAttributeData(enterpriseEventCacheDataRequest.BusinessUnit, productCode, cellName, editionNumber, updateNumber)) { var storageConnectionString = azureStorageService.GetStorageAccountConnectionString(cacheConfiguration.Value.CacheStorageAccountName, cacheConfiguration.Value.CacheStorageAccountKey); var cacheInfo = (FssSearchResponseCache)await azureTableStorageClient.RetrieveFromTableStorageAsync <FssSearchResponseCache>(cellName, editionNumber + "|" + updateNumber, cacheConfiguration.Value.FssSearchCacheTableName, storageConnectionString); logger.LogInformation(EventIds.DeleteSearchDownloadCacheDataEventStart.ToEventId(), "Search and Download cache data deletion from table and Blob started for ProductName:{cellName} and _X-Correlation-ID:{CorrelationId}", cellName, correlationId); if (cacheInfo != null && !string.IsNullOrEmpty(cacheInfo.Response)) { var cacheTableData = new CacheTableData { BatchId = cacheInfo.BatchId, PartitionKey = cacheInfo.PartitionKey, RowKey = cacheInfo.RowKey, ETag = "*" }; logger.LogInformation(EventIds.DeleteSearchDownloadCacheDataFromTableStarted.ToEventId(), "Deletion started for Search and Download cache data from table:{cacheConfiguration.Value.FssSearchCacheTableName} for ProductName:{cellName} and BatchId:{cacheInfo.BatchId} and _X-Correlation-ID:{CorrelationId}", cacheConfiguration.Value.FssSearchCacheTableName, cellName, cacheTableData.BatchId, correlationId); await azureTableStorageClient.DeleteAsync(cacheTableData, cacheConfiguration.Value.FssSearchCacheTableName, storageConnectionString, essFulfilmentStorageconfig.Value.StorageContainerName); logger.LogInformation(EventIds.DeleteSearchDownloadCacheDataFromTableCompleted.ToEventId(), "Deletion completed for Search and Download cache data from table:{cacheConfiguration.Value.FssSearchCacheTableName} for ProductName:{cellName} and BatchId:{cacheTableData.BatchId} and _X-Correlation-ID:{CorrelationId}", cacheConfiguration.Value.FssSearchCacheTableName, cellName, cacheTableData.BatchId, correlationId); logger.LogInformation(EventIds.DeleteSearchDownloadCacheDataFromContainerStarted.ToEventId(), "Deletion started for Search and Download cache data from Blob Container for ProductName:{cellName} and BatchId:{cacheTableData.BatchId} and _X-Correlation-ID:{CorrelationId}", cellName, cacheTableData.BatchId, correlationId); await azureBlobStorageClient.DeleteCacheContainer(storageConnectionString, cacheTableData.BatchId); logger.LogInformation(EventIds.DeleteSearchDownloadCacheDataFromContainerCompleted.ToEventId(), "Deletion completed for Search and Download cache data from Blob Container for ProductName:{cellName} and BatchId:{cacheTableData.BatchId} and _X-Correlation-ID:{CorrelationId}", cellName, cacheTableData.BatchId, correlationId); } else { logger.LogInformation(EventIds.DeleteSearchDownloadCacheNoDataFoundEvent.ToEventId(), "No Matching Product found in Search and Download Cache table:{cacheConfiguration.Value.FssSearchCacheTableName} and ProductName:{cellName} and _X-Correlation-ID:{CorrelationId}", cacheConfiguration.Value.FssSearchCacheTableName, cellName, correlationId); } logger.LogInformation(EventIds.DeleteSearchDownloadCacheDataEventCompleted.ToEventId(), "Search and Download cache data deletion from table and Blob completed for ProductName:{cellName} and _X-Correlation-ID:{CorrelationId}", cellName, correlationId); } else { logger.LogInformation(EventIds.DeleteSearchDownloadInvalidCacheDataFoundEvent.ToEventId(), "Invalid data found in Search and Download Cache Request for Productname:{cellName} and productCode:{productCode} and _X-Correlation-ID:{CorrelationId}", cellName, productCode, correlationId); } }
public async Task <bool> DeleteHistoricFoldersAndFiles() { string homeDirectoryPath = configuration["HOME"]; string storageAccountConnectionString = scsStorageService.GetStorageAccountConnectionString(); logger.LogInformation(EventIds.DeleteHistoricFoldersAndFilesStarted.ToEventId(), "Clean up process of historic folders and files started."); var response = await azureFileSystemHelper.DeleteDirectoryAsync(cleanUpConfig.Value.NumberOfDays, storageAccountConnectionString, storageConfig.Value.StorageContainerName, homeDirectoryPath); if (response) { logger.LogInformation(EventIds.DeleteHistoricFoldersAndFilesCompleted.ToEventId(), "Clean up process of historic folders and files completed."); return(response); } else { logger.LogError(EventIds.DeleteHistoricFoldersAndFilesFailed.ToEventId(), "Clean up process of historic folders and files failed."); return(response); } }