Search in sources :

Example 26 with NotNull

use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.

the class StorageClientSDKManager method createBlobContainer.

@NotNull
public BlobContainer createBlobContainer(@NotNull String connectionString, @NotNull BlobContainer blobContainer) throws AzureCmdException {
    try {
        CloudBlobClient client = getCloudBlobClient(connectionString);
        CloudBlobContainer container = client.getContainerReference(blobContainer.getName());
        container.createIfNotExists();
        container.downloadAttributes();
        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();
        }
        blobContainer.setUri(uri);
        blobContainer.setETag(eTag);
        blobContainer.setLastModified(lastModified);
        blobContainer.setPublicReadAccessType(publicReadAccessType);
        return blobContainer;
    } catch (Throwable t) {
        throw new AzureCmdException("Error creating the Blob Container", t);
    }
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 27 with NotNull

use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.

the class StorageClientSDKManager method getQueues.

@NotNull
public List<Queue> getQueues(@NotNull StorageAccount storageAccount) throws AzureCmdException {
    List<Queue> qList = new ArrayList<Queue>();
    try {
        CloudQueueClient client = getCloudQueueClient(storageAccount);
        for (CloudQueue cloudQueue : client.listQueues(null, QueueListingDetails.ALL, null, null)) {
            String uri = cloudQueue.getUri() != null ? cloudQueue.getUri().toString() : "";
            qList.add(new Queue(Strings.nullToEmpty(cloudQueue.getName()), uri, cloudQueue.getApproximateMessageCount()));
        }
        return qList;
    } catch (Throwable t) {
        throw new AzureCmdException("Error retrieving the Queue list", t);
    }
}
Also used : CloudQueueClient(com.microsoft.azure.storage.queue.CloudQueueClient) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) Queue(com.microsoft.tooling.msservices.model.storage.Queue) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 28 with NotNull

use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.

the class StorageClientSDKManager method createBlobDirectory.

@NotNull
public BlobDirectory createBlobDirectory(@NotNull StorageAccount storageAccount, @NotNull BlobDirectory parentBlobDirectory, @NotNull BlobDirectory blobDirectory) throws AzureCmdException {
    try {
        CloudBlobClient client = getCloudBlobClient(storageAccount);
        String containerName = parentBlobDirectory.getContainerName();
        CloudBlobContainer container = client.getContainerReference(containerName);
        CloudBlobDirectory parentDirectory = container.getDirectoryReference(parentBlobDirectory.getPath());
        CloudBlobDirectory directory = parentDirectory.getDirectoryReference(blobDirectory.getName());
        String uri = directory.getUri() != null ? directory.getUri().toString() : "";
        String path = Strings.nullToEmpty(directory.getPrefix());
        blobDirectory.setUri(uri);
        blobDirectory.setContainerName(containerName);
        blobDirectory.setPath(path);
        return blobDirectory;
    } catch (Throwable t) {
        throw new AzureCmdException("Error creating the Blob Directory", t);
    }
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 29 with NotNull

use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.

the class IDEHelperImpl method getArray.

@NotNull
private static byte[] getArray(@NotNull InputStream is) throws IOException {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    int nRead;
    byte[] data = new byte[16384];
    while ((nRead = is.read(data, 0, data.length)) != -1) {
        buffer.write(data, 0, nRead);
    }
    buffer.flush();
    return buffer.toByteArray();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 30 with NotNull

use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.

the class IDEHelperImpl method buildArtifact.

@NotNull
@Override
public ListenableFuture<String> buildArtifact(@NotNull ProjectDescriptor projectDescriptor, @NotNull ArtifactDescriptor artifactDescriptor) {
    try {
        Project project = findOpenProject(projectDescriptor);
        final Artifact artifact = findProjectArtifact(project, artifactDescriptor);
        final SettableFuture<String> future = SettableFuture.create();
        Futures.addCallback(buildArtifact(project, artifact, false), new FutureCallback<Boolean>() {

            @Override
            public void onSuccess(@Nullable Boolean succeded) {
                if (succeded != null && succeded) {
                    future.set(artifact.getOutputFilePath());
                } else {
                    future.setException(new AzureCmdException("An error occurred while building the artifact"));
                }
            }

            @Override
            public void onFailure(Throwable throwable) {
                if (throwable instanceof ExecutionException) {
                    future.setException(new AzureCmdException("An error occurred while building the artifact", throwable.getCause()));
                } else {
                    future.setException(new AzureCmdException("An error occurred while building the artifact", throwable));
                }
            }
        });
        return future;
    } catch (AzureCmdException e) {
        return Futures.immediateFailedFuture(e);
    }
}
Also used : Project(com.intellij.openapi.project.Project) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) ExecutionException(java.util.concurrent.ExecutionException) Artifact(com.intellij.packaging.artifacts.Artifact) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Aggregations

NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)32 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)20 CloudQueue (com.microsoft.azure.storage.queue.CloudQueue)4 CloudQueueClient (com.microsoft.azure.storage.queue.CloudQueueClient)4 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)4 Project (com.intellij.openapi.project.Project)3 Artifact (com.intellij.packaging.artifacts.Artifact)2 CloudQueueMessage (com.microsoft.azure.storage.queue.CloudQueueMessage)2 ContentType (com.microsoft.tooling.msservices.helpers.azure.rest.RestServiceManager.ContentType)2 HttpsURLConnectionProvider (com.microsoft.tooling.msservices.helpers.azure.rest.RestServiceManager.HttpsURLConnectionProvider)2 BlobDirectory (com.microsoft.tooling.msservices.model.storage.BlobDirectory)2 BlobFile (com.microsoft.tooling.msservices.model.storage.BlobFile)2 QueueMessage (com.microsoft.tooling.msservices.model.storage.QueueMessage)2 TableEntity (com.microsoft.tooling.msservices.model.storage.TableEntity)2 Property (com.microsoft.tooling.msservices.model.storage.TableEntity.Property)2 FileType (com.intellij.openapi.fileTypes.FileType)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)1 Nullable (com.microsoft.azuretools.azurecommons.helpers.Nullable)1 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)1