/** * Gets a {@link CloudFileShare} object with the specified name. * * @param shareName * The name of the share, which must adhere to share naming rules. The share name should not * include any path separator characters (/). * Share names must be lowercase, between 3-63 characters long and must start with a letter or * number. Share names may contain only letters, numbers, and the dash (-) character. * * @return A reference to a {@link CloudFileShare} object. * @throws StorageException * @throws URISyntaxException * * @see <a href="http://msdn.microsoft.com/en-us/library/azure/dn167011.aspx">Naming and Referencing Shares, * Directories, Files, and Metadata</a> */ public CloudFileShare getShareReference(final String shareName) throws URISyntaxException, StorageException { Utility.assertNotNullOrEmpty("shareName", shareName); return this.getShareReference(shareName, null); }
/** * Gets a {@link CloudFileShare} object with the specified name. * * @param shareName * The name of the share, which must adhere to share naming rules. The share name should not * include any path separator characters (/). * Share names must be lowercase, between 3-63 characters long and must start with a letter or * number. Share names may contain only letters, numbers, and the dash (-) character. * * @return A reference to a {@link CloudFileShare} object. * @throws StorageException * @throws URISyntaxException * * @see <a href="http://msdn.microsoft.com/en-us/library/azure/dn167011.aspx">Naming and Referencing Shares, * Directories, Files, and Metadata</a> */ public CloudFileShare getShareReference(final String shareName) throws URISyntaxException, StorageException { Utility.assertNotNullOrEmpty("shareName", shareName); return this.getShareReference(shareName, null); }
@Override public Triple<String, String, String> call() throws Exception { CloudFileShare cloudFileShare = client.getShareReference(fileShareName); cloudFileShare.createIfNotExists(); return Triple.of(volumeName, fileShareName, storageAccountKey); } });
@Override public Triple<String, String, String> call() throws Exception { CloudFileShare cloudFileShare = client.getShareReference(fileShareName); cloudFileShare.createIfNotExists(); return Triple.of(volumeName, fileShareName, storageAccountKey); } });
FileStorageResource(CloudFileClient fileClient, String location, boolean autoCreateFiles) { assertIsAzureStorageLocation(location); this.autoCreateFiles = autoCreateFiles; this.fileClient = fileClient; this.location = location; try { this.fileShare = fileClient.getShareReference(getContainerName(location)); this.cloudFile = fileShare.getRootDirectoryReference().getFileReference(getFileName(location)); } catch (URISyntaxException | StorageException e) { log.error(MSG_FAIL_GET, e); throw new RuntimeException(MSG_FAIL_GET, e); } }
/** * Returns the share for this directory. * * @return A {@link CloudFileShare} that represents the share for this directory. * * @throws StorageException * If a storage service error occurred. * @throws URISyntaxException * If the resource URI is invalid. */ @Override public CloudFileShare getShare() throws StorageException, URISyntaxException { if (this.share == null) { this.share = this.fileServiceClient.getShareReference(PathUtility.getShareNameFromUri(this.getUri(), this.fileServiceClient.isUsePathStyleUris())); } return this.share; }
/** * Returns the share for this directory. * * @return A {@link CloudFileShare} that represents the share for this directory. * * @throws StorageException * If a storage service error occurred. * @throws URISyntaxException * If the resource URI is invalid. */ @Override public CloudFileShare getShare() throws StorageException, URISyntaxException { if (this.share == null) { this.share = this.fileServiceClient.getShareReference(PathUtility.getShareNameFromUri(this.getUri(), this.fileServiceClient.isUsePathStyleUris())); } return this.share; }
public static CloudFileShare getRandomShareReference() throws URISyntaxException, StorageException { String shareName = generateRandomShareName(); CloudFileClient fileClient = TestHelper.createCloudFileClient(); CloudFileShare share = fileClient.getShareReference(shareName); return share; }
for (int i = 0; i < 30; i++) { shareList.add(prefix + i); fileClient.getShareReference(prefix + i).create(); fileClient.getShareReference(shareName).deleteIfExists();
@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()); }
private void testFileAccountSas(final boolean useHttps, final int bits) throws InvalidKeyException, StorageException, URISyntaxException, IOException { SharedAccessAccountPolicy policy = generatePolicy(bits, SharedAccessAccountService.FILE, null, null); this.fileShare = this.fileClient.getShareReference("filetest" + bits); try { testFileAccountSas(this.fileShare, useHttps, policy); } catch (StorageException ex) { if (bits < AccountSasTests.OBJECT_CODE || bits % AccountSasTests.OBJECT_CODE == AccountSasTests.EMPTY_PERMS_CODE) { // Expected failure if permissions or resource type is empty. assertEquals(AccountSasTests.QUERY_PARAM_MISSING_MESSAGE, ex.getMessage()); } else { throw ex; } } finally { this.fileShare.deleteIfExists(); } }
CloudFileShare share2 = client.getShareReference(this.share.getName()); assertPermissionsEqual(permissions, share2.downloadPermissions());
@Test public void testFileSAS() throws InvalidKeyException, IllegalArgumentException, StorageException, URISyntaxException, InterruptedException { SharedAccessFilePolicy policy = createSharedAccessPolicy( EnumSet.of(SharedAccessFilePermissions.READ, SharedAccessFilePermissions.LIST), 300); FileSharePermissions perms = new FileSharePermissions(); perms.getSharedAccessPolicies().put("readperm", policy); this.share.uploadPermissions(perms); Thread.sleep(30000); CloudFile sasFile = new CloudFile( new URI(this.file.getUri().toString() + "?" + this.file.generateSharedAccessSignature(null, "readperm"))); sasFile.download(new ByteArrayOutputStream()); // do not give the client and check that the new file's client has the correct permissions CloudFile fileFromUri = new CloudFile(PathUtility.addToQuery(this.file.getStorageUri(), this.file.generateSharedAccessSignature(null, "readperm"))); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), fileFromUri.getServiceClient().getCredentials().getClass().toString()); // create credentials from sas StorageCredentials creds = new StorageCredentialsSharedAccessSignature( this.file.generateSharedAccessSignature(policy, null, null)); CloudFileClient client = new CloudFileClient(sasFile.getServiceClient().getStorageUri(), creds); CloudFile fileFromClient = client.getShareReference(this.file.getShare().getName()).getRootDirectoryReference() .getFileReference(this.file.getName()); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), fileFromClient.getServiceClient().getCredentials().getClass().toString()); assertEquals(client, fileFromClient.getServiceClient()); }
CloudFileClient client = new CloudFileClient(this.share.getServiceClient().getStorageUri(), creds); CloudFileShare shareFromClient = client.getShareReference(readListShare.getName()); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), shareFromClient.getServiceClient().getCredentials().getClass().toString());
assertEquals("value1", this.share.getMetadata().get("key1")); CloudFileShare share2 = this.share.getServiceClient().getShareReference(this.share.getName()); share2.downloadAttributes(); assertEquals(1, share2.getMetadata().size());
@Test public void testListSharesWithSnapshot() throws StorageException, URISyntaxException { CloudFileClient fileClient = FileTestHelper.createCloudFileClient(); CloudFileShare share = fileClient.getShareReference(UUID.randomUUID().toString()); try { share.create();
@Test public void testDeleteShareSnapshotOptions() throws StorageException, URISyntaxException, IOException { // create share with metadata this.share.create(); assertTrue(this.share.exists()); // verify that exists() call on snapshot populates metadata CloudFileShare snapshot = this.share.createSnapshot(); CloudFileClient client = FileTestHelper.createCloudFileClient(); CloudFileShare snapshotRef = client.getShareReference(snapshot.name, snapshot.snapshotID); assertTrue(snapshotRef.exists()); try { share.delete(); } catch (final StorageException e) { assertEquals(StorageErrorCodeStrings.SHARE_HAS_SNAPSHOTS, e.getErrorCode()); } share.delete(DeleteShareSnapshotsOption.INCLUDE_SNAPSHOTS, null, null, null); assertFalse(share.exists()); assertFalse(snapshot.exists()); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class, SecondaryTests.class }) public void testFileMaximumExecutionTime() 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 FileRequestOptions options = new FileRequestOptions(); options.setMaximumExecutionTimeInMs(2000); options.setTimeoutIntervalInMs(1000); CloudFileClient fileClient = TestHelper.createCloudFileClient(); CloudFileShare share = fileClient.getShareReference(generateRandomName("share")); try { // 1. download attributes will fail as the share 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 share.downloadAttributes(null, options, opContext); fail("Maximum execution time was reached but request did not fail."); } catch (StorageException e) { assertEquals(SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, e.getMessage()); } }
/** * Validate share references * * @throws StorageException * @throws URISyntaxException */ @Test public void testCloudFileShareReference() throws StorageException, URISyntaxException { CloudFileClient client = FileTestHelper.createCloudFileClient(); CloudFileShare share = client.getShareReference("share"); CloudFileDirectory directory = share.getRootDirectoryReference().getDirectoryReference("directory3"); CloudFileDirectory directory2 = directory.getDirectoryReference("directory4"); assertEquals(share.getStorageUri().toString(), directory.getShare().getStorageUri().toString()); assertEquals(share.getStorageUri().toString(), directory2.getShare().getStorageUri().toString()); assertEquals(share.getStorageUri().toString(), directory2.getParent().getShare().getStorageUri().toString()); }
CloudFileShare snapshotRef = client.getShareReference(snapshot.name, snapshot.snapshotID);