Search in sources :

Example 1 with BlobContainer

use of com.microsoft.tooling.msservices.model.storage.BlobContainer in project azure-tools-for-java by Microsoft.

the class CreateBlobContainerForm method okPressed.

@Override
protected void okPressed() {
    final String name = nameTextField.getText();
    if (name.length() < NAME_MIN || name.length() > NAME_MAX || !name.matches(NAME_REGEX)) {
        DefaultLoader.getUIHelper().showError("Container names must start with a letter or number, and can contain only letters, numbers, and the dash (-) character.\n" + "Every dash (-) character must be immediately preceded and followed by a letter or number; consecutive dashes are not permitted in container names.\n" + "All letters in a container name must be lowercase.\n" + "Container names must be from 3 through 63 characters long.", "Azure Explorer");
        return;
    }
    DefaultLoader.getIdeHelper().runInBackground(null, "Creating blob container...", false, true, "Creating blob container...", new Runnable() {

        @Override
        public void run() {
            try {
                for (BlobContainer blobContainer : StorageClientSDKManager.getManager().getBlobContainers(connectionString)) {
                    if (blobContainer.getName().equals(name)) {
                        DefaultLoader.getIdeHelper().invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                DefaultLoader.getUIHelper().showError("A blob container with the specified name already exists.", "Azure Explorer");
                            }
                        });
                        return;
                    }
                }
                BlobContainer blobContainer = new BlobContainer(name, "", /*storageAccount.getBlobsUri() + name*/
                "", Calendar.getInstance(), "");
                StorageClientSDKManager.getManager().createBlobContainer(connectionString, blobContainer);
                if (onCreate != null) {
                    DefaultLoader.getIdeHelper().invokeLater(onCreate);
                }
            } catch (AzureCmdException e) {
                DefaultLoader.getUIHelper().showException("Error creating blob container", e, "Error creating blob container", false, true);
            }
        }
    });
    super.okPressed();
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) BlobContainer(com.microsoft.tooling.msservices.model.storage.BlobContainer)

Example 2 with BlobContainer

use of com.microsoft.tooling.msservices.model.storage.BlobContainer 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(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(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(String.format("Info : Begin uploading file %s to Azure Data Lake Store %s ...", localFile, uploadPath));
        String uploadedPath = StreamUtil.uploadArtifactToADLS(file, storageAccount, uploadFolderPath);
        HDInsightUtil.showInfoOnSubmissionMessageWindow(String.format("Info : Submit file to azure blob '%s' successfully.", uploadedPath));
        return uploadedPath;
    } else {
        throw new UnsupportedOperationException("unkown storage account type");
    }
}
Also used : CallableSingleArg(com.microsoft.tooling.msservices.helpers.CallableSingleArg) BufferedInputStream(java.io.BufferedInputStream) BlobContainer(com.microsoft.tooling.msservices.model.storage.BlobContainer) File(java.io.File) HDStorageAccount(com.microsoft.azure.hdinsight.sdk.storage.HDStorageAccount) FileInputStream(java.io.FileInputStream)

Example 3 with BlobContainer

use of com.microsoft.tooling.msservices.model.storage.BlobContainer in project azure-tools-for-java by Microsoft.

the class CreateBlobContainerForm method doOKAction.

@Override
protected void doOKAction() {
    final String name = nameTextField.getText();
    //Field outerFiele = onCreate.getClass().getDeclaredField("this$0");
    ProgressManager.getInstance().run(new Task.Backgroundable(project, "Creating blob container...", false) {

        @Override
        public void run(@NotNull ProgressIndicator progressIndicator) {
            try {
                progressIndicator.setIndeterminate(true);
                for (BlobContainer blobContainer : StorageClientSDKManager.getManager().getBlobContainers(connectionString)) {
                    if (blobContainer.getName().equals(name)) {
                        ApplicationManager.getApplication().invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                JOptionPane.showMessageDialog(null, "A blob container with the specified name already exists.", "Azure Explorer", JOptionPane.ERROR_MESSAGE);
                            }
                        });
                        return;
                    }
                }
                BlobContainer blobContainer = new BlobContainer(name, "", /*storageAccount.getBlobsUri() + name*/
                "", Calendar.getInstance(), "");
                StorageClientSDKManager.getManager().createBlobContainer(connectionString, blobContainer);
                if (onCreate != null) {
                    ApplicationManager.getApplication().invokeLater(onCreate);
                }
            } catch (AzureCmdException e) {
                String msg = "An error occurred while attempting to create blob container." + "\n" + String.format(message("webappExpMsg"), e.getMessage());
                PluginUtil.displayErrorDialogAndLog(message("errTtl"), msg, e);
            }
        }
    });
    sendTelemetry(OK_EXIT_CODE);
    this.close(DialogWrapper.OK_EXIT_CODE, true);
}
Also used : Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) BlobContainer(com.microsoft.tooling.msservices.model.storage.BlobContainer)

Example 4 with BlobContainer

use of com.microsoft.tooling.msservices.model.storage.BlobContainer in project azure-tools-for-java by Microsoft.

the class BlobExplorerFileEditorProvider method createEditor.

@NotNull
@Override
public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile virtualFile) {
    BlobExplorerFileEditor blobExplorerFileEditor = new BlobExplorerFileEditor(project);
    StorageAccount storageAccount = virtualFile.getUserData(UIHelperImpl.STORAGE_KEY);
    BlobContainer blobContainer = virtualFile.getUserData(CONTAINER_KEY);
    blobExplorerFileEditor.setBlobContainer(blobContainer);
    if (storageAccount != null) {
        blobExplorerFileEditor.setConnectionString(StorageClientSDKManager.getConnectionString(storageAccount));
        blobExplorerFileEditor.setStorageAccount(storageAccount.name());
    } else {
        blobExplorerFileEditor.setConnectionString(virtualFile.getUserData(UIHelperImpl.CLIENT_STORAGE_KEY).getConnectionString());
        blobExplorerFileEditor.setStorageAccount(virtualFile.getUserData(UIHelperImpl.CLIENT_STORAGE_KEY).getName());
    }
    blobExplorerFileEditor.fillGrid();
    return blobExplorerFileEditor;
}
Also used : StorageAccount(com.microsoft.azure.management.storage.StorageAccount) ClientStorageAccount(com.microsoft.tooling.msservices.model.storage.ClientStorageAccount) BlobContainer(com.microsoft.tooling.msservices.model.storage.BlobContainer) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with BlobContainer

use of com.microsoft.tooling.msservices.model.storage.BlobContainer in project azure-tools-for-java by Microsoft.

the class StorageClientSDKManager method getBlobContainers.

@NotNull
public List<BlobContainer> getBlobContainers(@NotNull String connectionString) throws AzureCmdException {
    List<BlobContainer> bcList = new ArrayList<BlobContainer>();
    try {
        CloudBlobClient client = getCloudBlobClient(connectionString);
        for (CloudBlobContainer container : client.listContainers(null, ContainerListingDetails.ALL, null, null)) {
            String uri = container.getUri() != null ? container.getUri().toString() : "";
            String eTag = "";
            Calendar lastModified = new GregorianCalendar();
            BlobContainerProperties properties = container.getProperties();
            if (properties != null) {
                eTag = Strings.nullToEmpty(properties.getEtag());
                if (properties.getLastModified() != null) {
                    lastModified.setTime(properties.getLastModified());
                }
            }
            String publicReadAccessType = "";
            BlobContainerPermissions blobContainerPermissions = container.downloadPermissions();
            if (blobContainerPermissions != null && blobContainerPermissions.getPublicAccess() != null) {
                publicReadAccessType = blobContainerPermissions.getPublicAccess().toString();
            }
            bcList.add(new BlobContainer(Strings.nullToEmpty(container.getName()), uri, eTag, lastModified, publicReadAccessType));
        }
        return bcList;
    } catch (Throwable t) {
        throw new AzureCmdException("Error retrieving the Blob Container list", t);
    }
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) BlobContainer(com.microsoft.tooling.msservices.model.storage.BlobContainer) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Aggregations

BlobContainer (com.microsoft.tooling.msservices.model.storage.BlobContainer)8 HDStorageAccount (com.microsoft.azure.hdinsight.sdk.storage.HDStorageAccount)3 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)3 StorageAccount (com.microsoft.azure.management.storage.StorageAccount)2 CallableSingleArg (com.microsoft.tooling.msservices.helpers.CallableSingleArg)2 ClientStorageAccount (com.microsoft.tooling.msservices.model.storage.ClientStorageAccount)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 NotNull (org.jetbrains.annotations.NotNull)1