com.microsoft.azure.storage.file.CloudFileClient Java Examples

The following examples show how to use com.microsoft.azure.storage.file.CloudFileClient. 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: AzureNotebookRepo.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
public void init(ZeppelinConfiguration conf) throws IOException {
  this.conf = conf;
  user = conf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_AZURE_USER);
  shareName = conf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_AZURE_SHARE);

  try {
    CloudStorageAccount account = CloudStorageAccount.parse(
        conf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_AZURE_CONNECTION_STRING));
    CloudFileClient client = account.createCloudFileClient();
    CloudFileShare share = client.getShareReference(shareName);
    share.createIfNotExists();

    CloudFileDirectory userDir = StringUtils.isBlank(user) ?
        share.getRootDirectoryReference() :
        share.getRootDirectoryReference().getDirectoryReference(user);
    userDir.createIfNotExists();

    rootDir = userDir.getDirectoryReference("notebook");
    rootDir.createIfNotExists();
  } catch (Exception e) {
    throw new IOException(e);
  }
}
 
Example #2
Source File: OldAzureNotebookRepo.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
public void init(ZeppelinConfiguration conf) throws IOException {
  this.conf = conf;
  user = conf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_AZURE_USER);
  shareName = conf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_AZURE_SHARE);

  try {
    CloudStorageAccount account = CloudStorageAccount.parse(
        conf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_AZURE_CONNECTION_STRING));
    CloudFileClient client = account.createCloudFileClient();
    CloudFileShare share = client.getShareReference(shareName);
    share.createIfNotExists();

    CloudFileDirectory userDir = StringUtils.isBlank(user) ?
        share.getRootDirectoryReference() :
        share.getRootDirectoryReference().getDirectoryReference(user);
    userDir.createIfNotExists();

    rootDir = userDir.getDirectoryReference("notebook");
    rootDir.createIfNotExists();
  } catch (Exception e) {
    throw new IOException(e);
  }
}
 
Example #3
Source File: TestHelper.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
public static CloudFileClient createCloudFileClient(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 fileUri = new URI(useHttps ? "https" : "http", sasAccount.getFileEndpoint().getAuthority(), 
    		sasAccount.getFileEndpoint().getPath(), sasAccount.getFileEndpoint().getQuery(), null);
    
    sasAccount = new CloudStorageAccount(
            creds, sasAccount.getBlobEndpoint(), sasAccount.getQueueEndpoint(), sasAccount.getTableEndpoint(),
            fileUri);
    return sasAccount.createCloudFileClient();
}
 
Example #4
Source File: ServicePropertiesTests.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
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 #5
Source File: ServicePropertiesTests.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Takes a CorsRule and tries to upload it. Then tries to download it and compares it to the initial CorsRule.
 */
private void testCorsRules(CorsRule rule, ServiceClient client, ServiceProperties properties,
        FileServiceProperties fileServiceProperties) throws StorageException, InterruptedException {
    CorsProperties cors = (fileServiceProperties == null) ? properties.getCors() : fileServiceProperties.getCors();
    cors.getCorsRules().clear();
    cors.getCorsRules().add(rule);

    if (fileServiceProperties == null) {
        callUploadServiceProps(client, properties, null);
        assertServicePropertiesAreEqual(properties, callDownloadServiceProperties(client));
    } else {
        CloudFileClient fileClient = ((CloudFileClient) client);
        fileClient.uploadServiceProperties(fileServiceProperties);
        Thread.sleep(30000);
        assertFileServicePropertiesAreEqual(fileServiceProperties, fileClient.downloadServiceProperties());
    }
}
 
Example #6
Source File: ServicePropertiesTests.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Takes a List of CorsRules and tries to upload them. Then tries to download them and compares the list to the
 * initial CorsRule List.
 */
private void testCorsRules(List<CorsRule> corsRules, ServiceClient client, ServiceProperties properties,
        FileServiceProperties fileServiceProperties) throws StorageException, InterruptedException {
    CorsProperties cors = (fileServiceProperties == null) ? properties.getCors() : fileServiceProperties.getCors();
    cors.getCorsRules().clear();

    for (CorsRule rule : corsRules) {
        cors.getCorsRules().add(rule);
    }

    if (fileServiceProperties == null) {
        callUploadServiceProps(client, properties, null);
        assertServicePropertiesAreEqual(properties, callDownloadServiceProperties(client));
    } else {
        CloudFileClient fileClient = ((CloudFileClient) client);
        fileClient.uploadServiceProperties(fileServiceProperties);
        Thread.sleep(30000);
        assertFileServicePropertiesAreEqual(fileServiceProperties, fileClient.downloadServiceProperties());
    }
}
 
Example #7
Source File: StorageAccountTests.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
@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 #8
Source File: CloudStorageAccount.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new File service client.
 * 
 * @return A {@link CloudFileClient} that represents the cloud File client.
 * 
 */
public CloudFileClient createCloudFileClient() {
    if (this.getFileStorageUri() == null) {
        throw new IllegalArgumentException(SR.FILE_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 CloudFileClient(this.getFileStorageUri(), this.getCredentials());
}
 
Example #9
Source File: ContainerGroupImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
private Observable<Triple<String, String, String>> createFileShareAsync(final StorageAccount storageAccount) {
    return storageAccount.getKeysAsync()
            .map(new Func1<List<StorageAccountKey>, String>() {
                @Override
                public String call(List<StorageAccountKey> storageAccountKeys) {
                    return storageAccountKeys.get(0).value();
                }
            })
            .flatMap(new Func1<String, Observable<Triple<String, String, String>>>() {
                CloudFileClient cloudFileClient;
                @Override
                public Observable<Triple<String, String, String>> call(final String storageAccountKey) {
                    try {
                        cloudFileClient = CloudStorageAccount.parse(Utils.getStorageConnectionString(
                                storageAccount.name(),
                                storageAccountKey,
                                manager().inner().restClient()))
                                .createCloudFileClient();
                    } catch (URISyntaxException syntaxException) {
                        throw Exceptions.propagate(syntaxException);
                    } catch (InvalidKeyException keyException) {
                        throw Exceptions.propagate(keyException);
                    }
                    return Observable.from(newFileShares.entrySet())
                            .flatMap(new Func1<Map.Entry<String, String>, Observable<Triple<String, String, String>>>() {
                                @Override
                                public Observable<Triple<String, String, String>> call(Map.Entry<String, String> fileShareEntry) {
                                    return createSingleFileShareAsync(cloudFileClient, fileShareEntry.getKey(), fileShareEntry.getValue(), storageAccountKey);
                                }
                            });
                }
            });
}
 
Example #10
Source File: ContainerGroupImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
private Observable<Triple<String, String, String>> createSingleFileShareAsync(final CloudFileClient client, final String volumeName, final String fileShareName, final String storageAccountKey) {
    return Observable.fromCallable(new Callable<Triple<String, String, String>>() {
        @Override
        public Triple<String, String, String> call() throws Exception {
            CloudFileShare cloudFileShare = client.getShareReference(fileShareName);
            cloudFileShare.createIfNotExists();

            return Triple.of(volumeName, fileShareName, storageAccountKey);
        }
    });
}
 
Example #11
Source File: MaximumExecutionTimeTests.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
@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());
    }
}
 
Example #12
Source File: StorageAccountTests.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
@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 #13
Source File: TestHelper.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
public static CloudFileClient createCloudFileClient() throws StorageException {
return getAccount().createCloudFileClient();
  }
 
Example #14
Source File: ServicePropertiesTests.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
private void testAnalyticsHourMetricsLevel(
        ServiceClient client, ServiceProperties props, FileServiceProperties fileProps)
        throws StorageException, InterruptedException {

    final MetricsProperties hours = (props == null) ? fileProps.getHourMetrics() : props.getHourMetrics();

    // None
    hours.setMetricsLevel(MetricsLevel.DISABLED);
    hours.setRetentionIntervalInDays(null);
    hours.setVersion("1.0");
    callUploadServiceProps(client, props, fileProps);

    if (props == null) {
        assertFileServicePropertiesAreEqual(fileProps, ((CloudFileClient) client).downloadServiceProperties());
    }
    else {
        assertServicePropertiesAreEqual(props, callDownloadServiceProperties(client));
    }

    // Service
    hours.setMetricsLevel(MetricsLevel.SERVICE);
    callUploadServiceProps(client, props, fileProps);

    if (props == null) {
        assertFileServicePropertiesAreEqual(fileProps, ((CloudFileClient) client).downloadServiceProperties());
    }
    else {
        assertServicePropertiesAreEqual(props, callDownloadServiceProperties(client));
    }

    // ServiceAndAPI
    hours.setMetricsLevel(MetricsLevel.SERVICE_AND_API);
    callUploadServiceProps(client, props, fileProps);

    if (props == null) {
        assertFileServicePropertiesAreEqual(fileProps, ((CloudFileClient) client).downloadServiceProperties());
    }
    else {
        assertServicePropertiesAreEqual(props, callDownloadServiceProperties(client));
    }
}
 
Example #15
Source File: ServicePropertiesTests.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
private void testAnalyticsMinuteMetricsLevel(
        final ServiceClient client, final ServiceProperties props, final FileServiceProperties fileProps)
        throws StorageException, InterruptedException {

    final MetricsProperties minutes = (props == null) ? fileProps.getMinuteMetrics() : props.getMinuteMetrics();

    // None
    minutes.setMetricsLevel(MetricsLevel.DISABLED);
    minutes.setRetentionIntervalInDays(null);
    minutes.setVersion("1.0");
    callUploadServiceProps(client, props, fileProps);

    if (props == null) {
        assertFileServicePropertiesAreEqual(fileProps, ((CloudFileClient) client).downloadServiceProperties());
    }
    else {
        assertServicePropertiesAreEqual(props, callDownloadServiceProperties(client));
    }

    // Service
    minutes.setMetricsLevel(MetricsLevel.SERVICE);
    callUploadServiceProps(client, props, fileProps);

    if (props == null) {
        assertFileServicePropertiesAreEqual(fileProps, ((CloudFileClient) client).downloadServiceProperties());
    }
    else {
        assertServicePropertiesAreEqual(props, callDownloadServiceProperties(client));
    }

    // ServiceAndAPI
    minutes.setMetricsLevel(MetricsLevel.SERVICE_AND_API);
    callUploadServiceProps(client, props, fileProps);

    if (props == null) {
        assertFileServicePropertiesAreEqual(fileProps, ((CloudFileClient) client).downloadServiceProperties());
    }
    else {
        assertServicePropertiesAreEqual(props, callDownloadServiceProperties(client));
    }
}