Search in sources :

Example 6 with BlobProperties

use of com.azure.storage.blob.models.BlobProperties in project ambry by linkedin.

the class AzureBlobDataAccessorTest method setupMockBlobClient.

static BlockBlobClient setupMockBlobClient(BlobServiceClient mockServiceClient) {
    BlobContainerClient mockContainerClient = mock(BlobContainerClient.class);
    BlobClient mockBlobClient = mock(BlobClient.class);
    BlockBlobClient mockBlockBlobClient = mock(BlockBlobClient.class);
    when(mockServiceClient.getBlobContainerClient(anyString())).thenReturn(mockContainerClient);
    when(mockContainerClient.getBlobClient(anyString())).thenReturn(mockBlobClient);
    when(mockContainerClient.exists()).thenReturn(false);
    when(mockBlobClient.getBlockBlobClient()).thenReturn(mockBlockBlobClient);
    // Rest is to mock getPropertiesWithResponse and not needed everywhere
    BlobProperties mockBlobProperties = mock(BlobProperties.class);
    Map<String, String> metadataMap = new HashMap<>();
    lenient().when(mockBlobProperties.getMetadata()).thenReturn(metadataMap);
    Response<BlobProperties> mockPropertiesResponse = mock(Response.class);
    lenient().when(mockPropertiesResponse.getValue()).thenReturn(mockBlobProperties);
    lenient().when(mockBlockBlobClient.getPropertiesWithResponse(any(), any(), any())).thenReturn(mockPropertiesResponse);
    return mockBlockBlobClient;
}
Also used : BlobContainerClient(com.azure.storage.blob.BlobContainerClient) BlobClient(com.azure.storage.blob.BlobClient) BlockBlobClient(com.azure.storage.blob.specialized.BlockBlobClient) BlockBlobClient(com.azure.storage.blob.specialized.BlockBlobClient) HashMap(java.util.HashMap) BlobProperties(com.azure.storage.blob.models.BlobProperties)

Example 7 with BlobProperties

use of com.azure.storage.blob.models.BlobProperties in project ambry by linkedin.

the class AzureCloudDestinationTest method testGetOneMetadata.

/**
 * Test to make sure that getting metadata for single blob calls ABS when not vcr and Cosmos when vcr.
 */
@Test
public void testGetOneMetadata() throws Exception {
    // 
    // Test 1: isVcr = false (already setup)
    // 
    // Get for existing blob
    Response<BlobProperties> mockResponse = mock(Response.class);
    BlobProperties mockProperties = mock(BlobProperties.class);
    CloudBlobMetadata blobMetadata = new CloudBlobMetadata(blobId, 0, -1, 0, null);
    Map<String, String> propertyMap = blobMetadata.toMap();
    when(mockProperties.getMetadata()).thenReturn(propertyMap);
    when(mockResponse.getValue()).thenReturn(mockProperties);
    when(mockBlockBlobClient.getPropertiesWithResponse(any(), any(), any())).thenReturn(mockResponse);
    List<BlobId> singleBlobList = Collections.singletonList(blobId);
    Map<String, CloudBlobMetadata> metadataMap = azureDest.getBlobMetadata(singleBlobList);
    assertEquals("Expected map of one", 1, metadataMap.size());
    verify(mockBlockBlobClient).getPropertiesWithResponse(any(), any(), any());
    verifyZeroInteractions(mockumentClient);
    // Get for nonexistent blob
    BlobStorageException ex = mockStorageException(BlobErrorCode.BLOB_NOT_FOUND);
    when(mockBlockBlobClient.getPropertiesWithResponse(any(), any(), any())).thenThrow(ex);
    metadataMap = azureDest.getBlobMetadata(singleBlobList);
    assertTrue("Expected empty map", metadataMap.isEmpty());
    verify(mockBlockBlobClient, times(2)).getPropertiesWithResponse(any(), any(), any());
    verifyZeroInteractions(mockumentClient);
    // 
    // Test 2: isVcr = true
    // 
    azureDest.close();
    azureDest = new AzureCloudDestination(mockServiceClient, mockBlobBatchClient, mockumentClient, "foo", "bar", clusterName, azureMetrics, defaultAzureReplicationFeedType, clusterMap, true, configProps);
    // Existing blob
    List<Document> docList = Collections.singletonList(createDocumentFromCloudBlobMetadata(blobMetadata));
    Observable<FeedResponse<Document>> feedResponse = mock(Observable.class);
    mockObservableForQuery(docList, feedResponse);
    when(mockumentClient.queryDocuments(anyString(), any(SqlQuerySpec.class), any(FeedOptions.class))).thenReturn(feedResponse);
    metadataMap = azureDest.getBlobMetadata(singleBlobList);
    assertEquals("Expected map of one", 1, metadataMap.size());
    verify(mockumentClient).queryDocuments(anyString(), any(SqlQuerySpec.class), any(FeedOptions.class));
    verify(mockBlockBlobClient, times(2)).getPropertiesWithResponse(any(), any(), any());
}
Also used : CloudBlobMetadata(com.github.ambry.cloud.CloudBlobMetadata) FeedResponse(com.microsoft.azure.cosmosdb.FeedResponse) Document(com.microsoft.azure.cosmosdb.Document) SqlQuerySpec(com.microsoft.azure.cosmosdb.SqlQuerySpec) FeedOptions(com.microsoft.azure.cosmosdb.FeedOptions) BlobProperties(com.azure.storage.blob.models.BlobProperties) BlobId(com.github.ambry.commons.BlobId) BlobStorageException(com.azure.storage.blob.models.BlobStorageException) Test(org.junit.Test)

Example 8 with BlobProperties

use of com.azure.storage.blob.models.BlobProperties in project carina by qaprosoft.

the class CarinaListener method updateAzureAppPath.

/**
 * Method to update MOBILE_APP path in case if apk is located in Azure storage.
 */
private static void updateAzureAppPath() {
    Pattern AZURE_CONTAINER_PATTERN = Pattern.compile("\\/\\/([a-z0-9]{3,24})\\.blob.core.windows.net\\/(?:(\\$root|(?:[a-z0-9](?!.*--)[a-z0-9-]{1,61}[a-z0-9]))\\/)?(.{1,1024})");
    String mobileAppPath = Configuration.getMobileApp();
    Matcher matcher = AZURE_CONTAINER_PATTERN.matcher(mobileAppPath);
    LOGGER.info("Analyzing if mobile app is located on Azure...");
    if (matcher.find()) {
        LOGGER.info("app artifact is located on Azure...");
        String accountName = matcher.group(1);
        String containerName = matcher.group(2) == null ? "$root" : matcher.group(2);
        String remoteFilePath = matcher.group(3);
        LOGGER.info("Account: " + accountName + "\n" + "Container: " + containerName + "\n" + "RemotePath: " + remoteFilePath + "\n");
        R.CONFIG.put(Parameter.AZURE_ACCOUNT_NAME.getKey(), accountName);
        BlobProperties blobProperties = AzureManager.getInstance().get(containerName, remoteFilePath);
        String azureLocalStorage = Configuration.get(Parameter.AZURE_LOCAL_STORAGE);
        String localFilePath = azureLocalStorage + File.separator + StringUtils.substringAfterLast(remoteFilePath, "/");
        File file = new File(localFilePath);
        try {
            // verify requested artifact by checking the checksum
            if (file.exists() && FileManager.getFileChecksum(FileManager.Checksum.MD5, file).equals(Base64.encodeBase64String(blobProperties.getContentMd5()))) {
                LOGGER.info("build artifact with the same checksum already downloaded: " + file.getAbsolutePath());
            } else {
                LOGGER.info(String.format("Following data was extracted: container: %s, remotePath: %s, local file: %s", containerName, remoteFilePath, file.getAbsolutePath()));
                AzureManager.getInstance().download(containerName, remoteFilePath, file);
            }
        } catch (Exception exception) {
            LOGGER.error("Azure app path update exception detected!", exception);
        }
        Configuration.setMobileApp(file.getAbsolutePath());
        // try to redefine app_version if it's value is latest or empty
        String appVersion = Configuration.get(Parameter.APP_VERSION);
        if (appVersion.equals("latest") || appVersion.isEmpty()) {
            Configuration.setBuild(file.getName());
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) BlobProperties(com.azure.storage.blob.models.BlobProperties) File(java.io.File) SkipException(org.testng.SkipException)

Example 9 with BlobProperties

use of com.azure.storage.blob.models.BlobProperties in project carina by qaprosoft.

the class AzureClientTest method testGetPropsNull.

@Test(expectedExceptions = { RuntimeException.class, IOException.class, NoSuchAlgorithmException.class })
public void testGetPropsNull() throws IOException, NoSuchAlgorithmException {
    String localPath = Configuration.get(Configuration.Parameter.AZURE_LOCAL_STORAGE);
    BlobProperties value = AzureManager.getInstance().get("resources", "apk-StableDev.apk");
    String remoteFileMD5 = Base64.encodeBase64String(value.getContentMd5());
    File file = new File("./apk-StableDev.apk");
    String localFileMD5 = FileManager.getFileChecksum(FileManager.Checksum.MD5, file);
    System.out.println(remoteFileMD5);
    System.out.println(localFileMD5);
    System.out.println(remoteFileMD5.equals(localFileMD5));
    Assert.fail("Key verification doesn't work!");
}
Also used : BlobProperties(com.azure.storage.blob.models.BlobProperties) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

BlobProperties (com.azure.storage.blob.models.BlobProperties)9 BlobStorageException (com.azure.storage.blob.models.BlobStorageException)5 IOException (java.io.IOException)3 BlobClient (com.azure.storage.blob.BlobClient)2 BlobContainerClient (com.azure.storage.blob.BlobContainerClient)2 CloudBlobMetadata (com.github.ambry.cloud.CloudBlobMetadata)2 BlobId (com.github.ambry.commons.BlobId)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 Duration (java.time.Duration)2 ArrayList (java.util.ArrayList)2 Pattern (java.util.regex.Pattern)2 PublicAtsApi (com.axway.ats.common.PublicAtsApi)1 ProxyOptions (com.azure.core.http.ProxyOptions)1 Response (com.azure.core.http.rest.Response)1 Context (com.azure.core.util.Context)1 BlobServiceClient (com.azure.storage.blob.BlobServiceClient)1 BlobBatchClient (com.azure.storage.blob.batch.BlobBatchClient)1 BlobErrorCode (com.azure.storage.blob.models.BlobErrorCode)1 BlobItem (com.azure.storage.blob.models.BlobItem)1