Search in sources :

Example 6 with HDStorageAccount

use of com.microsoft.azure.hdinsight.sdk.storage.HDStorageAccount in project azure-tools-for-java by Microsoft.

the class StorageAccountFolderNode method refreshItems.

@Override
protected void refreshItems() throws AzureCmdException {
    if (clusterDetail != null && !clusterDetail.isEmulator()) {
        try {
            clusterDetail.getConfigurationInfo(getProject());
            addChildNode(new StorageAccountNode(this, clusterDetail.getStorageAccount(), true));
            List<HDStorageAccount> additionalStorageAccount = clusterDetail.getAdditionalStorageAccounts();
            if (additionalStorageAccount != null) {
                for (HDStorageAccount account : additionalStorageAccount) {
                    addChildNode(new StorageNode(this, account, false));
                }
            }
        } catch (Exception exception) {
            DefaultLoader.getUIHelper().showException("Failed to get HDInsight cluster configuration.", exception, "HDInsight Explorer", false, true);
        }
    }
}
Also used : HDStorageAccount(com.microsoft.azure.hdinsight.sdk.storage.HDStorageAccount) StorageNode(com.microsoft.tooling.msservices.serviceexplorer.azure.storage.asm.StorageNode) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)

Example 7 with HDStorageAccount

use of com.microsoft.azure.hdinsight.sdk.storage.HDStorageAccount in project azure-tools-for-java by Microsoft.

the class SparkSubmitHelper method uploadFileToHDFS.

public String uploadFileToHDFS(Project project, String localFile, IHDIStorageAccount storageAccount, String defaultContainerName, String uploadFolderPath) throws Exception {
    final File file = new File(localFile);
    if (storageAccount.getAccountType() == StorageAccountTypeEnum.BLOB) {
        try (FileInputStream fileInputStream = new FileInputStream(file)) {
            try (BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream)) {
                final CallableSingleArg<Void, Long> callable = new CallableSingleArg<Void, Long>() {

                    @Override
                    public Void call(Long uploadedBytes) throws Exception {
                        double progress = ((double) uploadedBytes) / file.length();
                        return null;
                    }
                };
                HDStorageAccount blobStorageAccount = (HDStorageAccount) storageAccount;
                BlobContainer defaultContainer = getSparkClusterDefaultContainer(blobStorageAccount, defaultContainerName);
                String path = String.format("SparkSubmission/%s/%s", uploadFolderPath, file.getName());
                String uploadedPath = String.format("wasb://%s@%s/%s", defaultContainerName, blobStorageAccount.getFullStorageBlobName(), path);
                HDInsightUtil.showInfoOnSubmissionMessageWindow(project, String.format("Info : Begin uploading file %s to Azure Blob Storage Account %s ...", localFile, uploadedPath));
                StorageClientSDKManager.getManager().uploadBlobFileContent(blobStorageAccount.getConnectionString(), defaultContainer, path, bufferedInputStream, callable, 1024 * 1024, file.length());
                HDInsightUtil.showInfoOnSubmissionMessageWindow(project, String.format("Info : Submit file to azure blob '%s' successfully.", uploadedPath));
                return uploadedPath;
            }
        }
    } else if (storageAccount.getAccountType() == StorageAccountTypeEnum.ADLS) {
        String uploadPath = String.format("adl://%s.azuredatalakestore.net%s%s", storageAccount.getName(), storageAccount.getDefaultContainerOrRootPath(), "SparkSubmission");
        HDInsightUtil.showInfoOnSubmissionMessageWindow(project, String.format("Info : Begin uploading file %s to Azure Datalake store %s ...", localFile, uploadPath));
        String uploadedPath = StreamUtil.uploadArtifactToADLS(file, storageAccount, uploadFolderPath);
        HDInsightUtil.showInfoOnSubmissionMessageWindow(project, String.format("Info : Submit file to Azure Datalake store '%s' successfully.", uploadedPath));
        return uploadedPath;
    } else {
        throw new UnsupportedOperationException("unknown storage account type");
    }
}
Also used : CallableSingleArg(com.microsoft.tooling.msservices.helpers.CallableSingleArg) BlobContainer(com.microsoft.tooling.msservices.model.storage.BlobContainer) HDStorageAccount(com.microsoft.azure.hdinsight.sdk.storage.HDStorageAccount)

Aggregations

HDStorageAccount (com.microsoft.azure.hdinsight.sdk.storage.HDStorageAccount)7 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)3 BlobContainer (com.microsoft.tooling.msservices.model.storage.BlobContainer)3 HDIException (com.microsoft.azure.hdinsight.sdk.common.HDIException)2 CallableSingleArg (com.microsoft.tooling.msservices.helpers.CallableSingleArg)2 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 ClientStorageAccount (com.microsoft.tooling.msservices.model.storage.ClientStorageAccount)1 StorageNode (com.microsoft.tooling.msservices.serviceexplorer.azure.storage.asm.StorageNode)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1