com.microsoft.azure.storage.table.CloudTableClient Java Examples
The following examples show how to use
com.microsoft.azure.storage.table.CloudTableClient.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServicePropertiesTests.java From azure-storage-android with Apache License 2.0 | 6 votes |
private void callUploadServiceProps( ServiceClient client, ServiceProperties props, FileServiceProperties fileProps) throws StorageException, InterruptedException { if (client.getClass().equals(CloudBlobClient.class)) { ((CloudBlobClient) client).uploadServiceProperties(props); } else if (client.getClass().equals(CloudTableClient.class)) { ((CloudTableClient) client).uploadServiceProperties(props); } else if (client.getClass().equals(CloudQueueClient.class)) { ((CloudQueueClient) client).uploadServiceProperties(props); } else if (client.getClass().equals(CloudFileClient.class)) { ((CloudFileClient) client).uploadServiceProperties(fileProps); } else { fail(); } Thread.sleep(30000); }
Example #2
Source File: ServicePropertiesTests.java From azure-storage-android with Apache License 2.0 | 6 votes |
private ServiceProperties callDownloadServiceProperties(ServiceClient client) throws StorageException { if (client.getClass().equals(CloudBlobClient.class)) { CloudBlobClient blobClient = (CloudBlobClient) client; return blobClient.downloadServiceProperties(); } else if (client.getClass().equals(CloudTableClient.class)) { CloudTableClient tableClient = (CloudTableClient) client; return tableClient.downloadServiceProperties(); } else if (client.getClass().equals(CloudQueueClient.class)) { CloudQueueClient queueClient = (CloudQueueClient) client; return queueClient.downloadServiceProperties(); } else { fail(); } return null; }
Example #3
Source File: SecondaryTests.java From azure-storage-android with Apache License 2.0 | 6 votes |
private static void testTableDownloadPermissions(LocationMode optionsLocationMode, LocationMode clientLocationMode, StorageLocation initialLocation, List<RetryContext> retryContextList, List<RetryInfo> retryInfoList) throws URISyntaxException, StorageException { CloudTableClient client = TestHelper.createCloudTableClient(); CloudTable table = client.getTableReference(TableTestHelper.generateRandomTableName()); MultiLocationTestHelper helper = new MultiLocationTestHelper(table.getServiceClient().getStorageUri(), initialLocation, retryContextList, retryInfoList); table.getServiceClient().getDefaultRequestOptions().setLocationMode(clientLocationMode); TableRequestOptions options = new TableRequestOptions(); options.setLocationMode(optionsLocationMode); options.setRetryPolicyFactory(helper.retryPolicy); try { table.downloadPermissions(options, helper.operationContext); } catch (StorageException ex) { assertEquals(HttpURLConnection.HTTP_NOT_FOUND, ex.getHttpStatusCode()); } finally { helper.close(); } }
Example #4
Source File: StorageAccountTests.java From azure-storage-android with Apache License 2.0 | 6 votes |
@Test public void testCloudStorageAccountClientUriVerify() throws URISyntaxException, StorageException { StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(cred, true); CloudBlobClient blobClient = cloudStorageAccount.createCloudBlobClient(); CloudBlobContainer container = blobClient.getContainerReference("container1"); assertEquals(cloudStorageAccount.getBlobEndpoint().toString() + "/container1", container.getUri().toString()); CloudQueueClient queueClient = cloudStorageAccount.createCloudQueueClient(); CloudQueue queue = queueClient.getQueueReference("queue1"); assertEquals(cloudStorageAccount.getQueueEndpoint().toString() + "/queue1", queue.getUri().toString()); CloudTableClient tableClient = cloudStorageAccount.createCloudTableClient(); CloudTable table = tableClient.getTableReference("table1"); assertEquals(cloudStorageAccount.getTableEndpoint().toString() + "/table1", table.getUri().toString()); CloudFileClient fileClient = cloudStorageAccount.createCloudFileClient(); CloudFileShare share = fileClient.getShareReference("share1"); assertEquals(cloudStorageAccount.getFileEndpoint().toString() + "/share1", share.getUri().toString()); }
Example #5
Source File: CloudStorageAccount.java From azure-storage-android with Apache License 2.0 | 6 votes |
/** * Creates a new Table service client. * * @return A client object that uses the Table service endpoint. */ public CloudTableClient createCloudTableClient() { if (this.getTableStorageUri() == null) { throw new IllegalArgumentException(SR.TABLE_ENDPOINT_NOT_CONFIGURED); } if (this.credentials == null) { throw new IllegalArgumentException(SR.MISSING_CREDENTIALS); } if (!StorageCredentialsHelper.canCredentialsGenerateClient(this.credentials)) { throw new IllegalArgumentException(SR.CREDENTIALS_CANNOT_SIGN_REQUEST); } return new CloudTableClient(this.getTableStorageUri(), this.getCredentials()); }
Example #6
Source File: TableClientFactory.java From breakerbox with Apache License 2.0 | 6 votes |
public TableClient create() { try { final CloudStorageAccount storageAccount = new CloudStorageAccount(azureTableConfiguration.getStorageCredentialsAccountAndKey(), true); final CloudTableClient cloudTableClient = storageAccount.createCloudTableClient(); final TableRequestOptions defaultOptions = new TableRequestOptions(); defaultOptions.setRetryPolicyFactory(new RetryLinearRetry( Ints.checkedCast(azureTableConfiguration.getRetryInterval().toMilliseconds()), azureTableConfiguration.getRetryAttempts())); defaultOptions.setTimeoutIntervalInMs(Ints.checkedCast(azureTableConfiguration.getTimeout().toMilliseconds())); cloudTableClient.setDefaultRequestOptions(defaultOptions); return new TableClient(cloudTableClient); } catch (URISyntaxException err) { LOGGER.error("Failed to create a TableClient", err); throw new IllegalArgumentException(err); } }
Example #7
Source File: GenericTests.java From azure-storage-android with Apache License 2.0 | 5 votes |
@Test public void testUserAgentString() throws URISyntaxException, StorageException { // Test with a blob request CloudBlobClient blobClient = TestHelper.createCloudBlobClient(); CloudBlobContainer container = blobClient.getContainerReference("container1"); OperationContext sendingRequestEventContext = new OperationContext(); sendingRequestEventContext.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() { @Override public void eventOccurred(SendingRequestEvent eventArg) { assertEquals( Constants.HeaderConstants.USER_AGENT_PREFIX + "/" + Constants.HeaderConstants.USER_AGENT_VERSION + " " + String.format(Utility.LOCALE_US, "(Android %s; %s; %s)", android.os.Build.VERSION.RELEASE, android.os.Build.BRAND, android.os.Build.MODEL), ((HttpURLConnection) eventArg.getConnectionObject()) .getRequestProperty(Constants.HeaderConstants.USER_AGENT)); } }); container.exists(null, null, sendingRequestEventContext); // Test with a queue request CloudQueueClient queueClient = TestHelper.createCloudQueueClient(); CloudQueue queue = queueClient.getQueueReference("queue1"); queue.exists(null, sendingRequestEventContext); // Test with a table request CloudTableClient tableClient = TestHelper.createCloudTableClient(); CloudTable table = tableClient.getTableReference("table1"); table.exists(null, sendingRequestEventContext); }
Example #8
Source File: MaximumExecutionTimeTests.java From azure-storage-android with Apache License 2.0 | 5 votes |
@Test @Category({ DevFabricTests.class, DevStoreTests.class, SecondaryTests.class }) public void testTableMaximumExecutionTime() throws URISyntaxException, StorageException { OperationContext opContext = new OperationContext(); setDelay(opContext, 2500); opContext.getResponseReceivedEventHandler().addListener(new StorageEvent<ResponseReceivedEvent>() { @Override public void eventOccurred(ResponseReceivedEvent eventArg) { // Set status code to 500 to force a retry eventArg.getRequestResult().setStatusCode(500); } }); // set the maximum execution time TableRequestOptions options = new TableRequestOptions(); options.setMaximumExecutionTimeInMs(2000); options.setTimeoutIntervalInMs(1000); CloudTableClient tableClient = TestHelper.createCloudTableClient(); CloudTable table = tableClient.getTableReference(generateRandomName("share")); try { // 1. insert entity will fail as the table does not exist // 2. the executor will attempt to retry as we set the status code to 500 // 3. maximum execution time should prevent the retry from being made DynamicTableEntity ent = new DynamicTableEntity("partition", "row"); TableOperation insert = TableOperation.insert(ent); table.execute(insert, options, opContext); fail("Maximum execution time was reached but request did not fail."); } catch (StorageException e) { assertEquals(SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, e.getMessage()); } }
Example #9
Source File: TestHelper.java From azure-storage-android with Apache License 2.0 | 5 votes |
public static CloudTableClient createCloudTableClient(SharedAccessAccountPolicy policy, boolean useHttps) throws StorageException, InvalidKeyException, URISyntaxException { CloudStorageAccount sasAccount = getAccount(); final String token = sasAccount.generateSharedAccessSignature(policy); final StorageCredentials creds = new StorageCredentialsSharedAccessSignature(token); final URI tableUri = new URI(useHttps ? "https" : "http", sasAccount.getTableEndpoint().getAuthority(), sasAccount.getTableEndpoint().getPath(), sasAccount.getTableEndpoint().getQuery(), null); sasAccount = new CloudStorageAccount(creds, sasAccount.getBlobEndpoint(), sasAccount.getQueueEndpoint(), tableUri, sasAccount.getFileEndpoint()); return sasAccount.createCloudTableClient(); }
Example #10
Source File: StorageAccountTests.java From azure-storage-android with Apache License 2.0 | 5 votes |
@Test public void testCloudStorageAccountClientMethods() throws URISyntaxException { StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); CloudStorageAccount account = new CloudStorageAccount(cred, false); CloudBlobClient blob = account.createCloudBlobClient(); CloudQueueClient queue = account.createCloudQueueClient(); CloudTableClient table = account.createCloudTableClient(); CloudFileClient file = account.createCloudFileClient(); // check endpoints assertEquals("Blob endpoint doesn't match account", account.getBlobEndpoint(), blob.getEndpoint()); assertEquals("Queue endpoint doesn't match account", account.getQueueEndpoint(), queue.getEndpoint()); assertEquals("Table endpoint doesn't match account", account.getTableEndpoint(), table.getEndpoint()); assertEquals("File endpoint doesn't match account", account.getFileEndpoint(), file.getEndpoint()); // check storage uris assertEquals("Blob endpoint doesn't match account", account.getBlobStorageUri(), blob.getStorageUri()); assertEquals("Queue endpoint doesn't match account", account.getQueueStorageUri(), queue.getStorageUri()); assertEquals("Table endpoint doesn't match account", account.getTableStorageUri(), table.getStorageUri()); assertEquals("File endpoint doesn't match account", account.getFileStorageUri(), file.getStorageUri()); // check creds assertEquals("Blob creds don't match account", account.getCredentials(), blob.getCredentials()); assertEquals("Queue creds don't match account", account.getCredentials(), queue.getCredentials()); assertEquals("Table creds don't match account", account.getCredentials(), table.getCredentials()); assertEquals("File creds don't match account", account.getCredentials(), file.getCredentials()); }
Example #11
Source File: StorageAccountTests.java From azure-storage-android with Apache License 2.0 | 5 votes |
@Test public void testCloudStorageAccountEndpointSuffix() throws InvalidKeyException, URISyntaxException, StorageException { final String mooncake = "core.chinacloudapi.cn"; final String fairfax = "core.usgovcloudapi.net"; // Endpoint suffix for mooncake CloudStorageAccount accountParse = CloudStorageAccount.parse( "DefaultEndpointsProtocol=http;AccountName=test;" + "AccountKey=abc=;EndpointSuffix=" + mooncake); CloudStorageAccount accountConstruct = new CloudStorageAccount(accountParse.getCredentials(), false, accountParse.getEndpointSuffix()); assertNotNull(accountParse); assertNotNull(accountConstruct); assertNotNull(accountParse.getBlobEndpoint()); assertEquals(accountParse.getBlobEndpoint(), accountConstruct.getBlobEndpoint()); assertTrue(accountParse.getBlobEndpoint().toString().endsWith(mooncake)); // Endpoint suffix for fairfax accountParse = CloudStorageAccount.parse( "TableEndpoint=http://tables/;DefaultEndpointsProtocol=http;" + "AccountName=test;AccountKey=abc=;EndpointSuffix=" + fairfax); accountConstruct = new CloudStorageAccount(accountParse.getCredentials(), false, accountParse.getEndpointSuffix()); assertNotNull(accountParse); assertNotNull(accountConstruct); assertNotNull(accountParse.getBlobEndpoint()); assertEquals(accountParse.getBlobEndpoint(), accountConstruct.getBlobEndpoint()); assertTrue(accountParse.getBlobEndpoint().toString().endsWith(fairfax)); // Explicit table endpoint should override endpoint suffix for fairfax CloudTableClient tableClientParse = accountParse.createCloudTableClient(); assertNotNull(tableClientParse); assertEquals(accountParse.getTableEndpoint(), tableClientParse.getEndpoint()); assertTrue(tableClientParse.getEndpoint().toString().endsWith("tables/")); }
Example #12
Source File: AzureAccess.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
public AzureAccess(CloudTableClient client, String tableName) throws AzureAccessNotPossibleException { try { table = client.getTableReference(tableName); table.createIfNotExists(); } catch (URISyntaxException | StorageException e) { LOG.error("Azure communication failed", e); throw new AzureAccessNotPossibleException("Azure communication failed"); } }
Example #13
Source File: AzureVreAuthorizationAccess.java From timbuctoo with GNU General Public License v3.0 | 4 votes |
public AzureVreAuthorizationAccess(CloudTableClient client) throws AzureAccessNotPossibleException { super(client, "vreAuthorization"); }
Example #14
Source File: AzureClient.java From samza with Apache License 2.0 | 4 votes |
public CloudTableClient getTableClient() { return tableClient; }
Example #15
Source File: AzurePermissionConfiguration.java From timbuctoo with GNU General Public License v3.0 | 4 votes |
public AzurePermissionConfiguration(CloudTableClient client) throws AzureAccessNotPossibleException { super(client, TABLE); }
Example #16
Source File: AzureLoginAccess.java From timbuctoo with GNU General Public License v3.0 | 4 votes |
public AzureLoginAccess(CloudTableClient client) throws AzureAccessNotPossibleException { super(client, "logins"); }
Example #17
Source File: AzureUserAccess.java From timbuctoo with GNU General Public License v3.0 | 4 votes |
public AzureUserAccess(CloudTableClient client) throws AzureAccessNotPossibleException { super(client, "users"); }
Example #18
Source File: TestHelper.java From azure-storage-android with Apache License 2.0 | 4 votes |
public static CloudTableClient createCloudTableClient() throws StorageException { return getAccount().createCloudTableClient(); }
Example #19
Source File: AzureStorageTableService.java From components with Apache License 2.0 | 4 votes |
public Iterable<String> listTables() throws InvalidKeyException, URISyntaxException { CloudTableClient cloudTableClient = connection.getCloudStorageAccount().createCloudTableClient(); return cloudTableClient.listTables(null, null, AzureStorageUtils.getTalendOperationContext()); }
Example #20
Source File: CloudAnalyticsClient.java From azure-storage-android with Apache License 2.0 | 3 votes |
/** * Initializes a new instance of the <code>CloudAnalyticsClient</code> class using the specified blob and table * service endpoints and account credentials. * * @param blobStorageUri * A {@link StorageUri} object containing the Blob service endpoint to use to create the client. * @param tableStorageUri * A {@link StorageUri} object containing the Table service endpoint to use to create the client. * @param credentials * A {@link StorageCredentials} object. */ public CloudAnalyticsClient(StorageUri blobStorageUri, StorageUri tableStorageUri, StorageCredentials credentials) { Utility.assertNotNull("blobStorageUri", blobStorageUri); Utility.assertNotNull("tableStorageUri", tableStorageUri); this.blobClient = new CloudBlobClient(blobStorageUri, credentials); this.tableClient = new CloudTableClient(tableStorageUri, credentials); }