Search in sources :

Example 16 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 17 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)

Example 18 with NotNull

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

the class IDEHelperImpl method getArtifacts.

@NotNull
@Override
public List<ArtifactDescriptor> getArtifacts(@NotNull ProjectDescriptor projectDescriptor) throws AzureCmdException {
    Project project = findOpenProject(projectDescriptor);
    List<ArtifactDescriptor> artifactDescriptors = new ArrayList<ArtifactDescriptor>();
    for (Artifact artifact : ArtifactUtil.getArtifactWithOutputPaths(project)) {
        artifactDescriptors.add(new ArtifactDescriptor(artifact.getName(), artifact.getArtifactType().getId()));
    }
    return artifactDescriptors;
}
Also used : Project(com.intellij.openapi.project.Project) ArrayList(java.util.ArrayList) Artifact(com.intellij.packaging.artifacts.Artifact) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 19 with NotNull

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

the class ClusterOperationImpl method requestWithToken.

@NotNull
public <T> T requestWithToken(@NotNull String tenantId, @NotNull final RequestCallback<T> requestCallback) throws Throwable {
    AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
    // not signed in
    if (azureManager == null) {
        return null;
    }
    String accessToken = azureManager.getAccessToken(tenantId);
    return requestCallback.execute(accessToken);
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 20 with NotNull

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

the class StorageClientSDKManager method getBlobItems.

@NotNull
public List<BlobItem> getBlobItems(@NotNull String connectionString, @NotNull BlobDirectory blobDirectory) throws AzureCmdException {
    List<BlobItem> biList = new ArrayList<BlobItem>();
    try {
        CloudBlobClient client = getCloudBlobClient(connectionString);
        String containerName = blobDirectory.getContainerName();
        String delimiter = client.getDirectoryDelimiter();
        CloudBlobContainer container = client.getContainerReference(containerName);
        CloudBlobDirectory directory = container.getDirectoryReference(blobDirectory.getPath());
        for (ListBlobItem item : directory.listBlobs()) {
            String uri = item.getUri() != null ? item.getUri().toString() : "";
            if (item instanceof CloudBlobDirectory) {
                CloudBlobDirectory subDirectory = (CloudBlobDirectory) item;
                String name = extractBlobItemName(subDirectory.getPrefix(), delimiter);
                String path = Strings.nullToEmpty(subDirectory.getPrefix());
                biList.add(new BlobDirectory(name, uri, containerName, path));
            } else if (item instanceof CloudBlob) {
                CloudBlob blob = (CloudBlob) item;
                String name = extractBlobItemName(blob.getName(), delimiter);
                String path = Strings.nullToEmpty(blob.getName());
                String type = "";
                String cacheControlHeader = "";
                String contentEncoding = "";
                String contentLanguage = "";
                String contentType = "";
                String contentMD5Header = "";
                String eTag = "";
                Calendar lastModified = new GregorianCalendar();
                long size = 0;
                BlobProperties properties = blob.getProperties();
                if (properties != null) {
                    if (properties.getBlobType() != null) {
                        type = properties.getBlobType().toString();
                    }
                    cacheControlHeader = Strings.nullToEmpty(properties.getCacheControl());
                    contentEncoding = Strings.nullToEmpty(properties.getContentEncoding());
                    contentLanguage = Strings.nullToEmpty(properties.getContentLanguage());
                    contentType = Strings.nullToEmpty(properties.getContentType());
                    contentMD5Header = Strings.nullToEmpty(properties.getContentMD5());
                    eTag = Strings.nullToEmpty(properties.getEtag());
                    if (properties.getLastModified() != null) {
                        lastModified.setTime(properties.getLastModified());
                    }
                    size = properties.getLength();
                }
                biList.add(new BlobFile(name, uri, containerName, path, type, cacheControlHeader, contentEncoding, contentLanguage, contentType, contentMD5Header, eTag, lastModified, size));
            }
        }
        return biList;
    } catch (Throwable t) {
        throw new AzureCmdException("Error retrieving the Blob Item list", t);
    }
}
Also used : BlobDirectory(com.microsoft.tooling.msservices.model.storage.BlobDirectory) BlobFile(com.microsoft.tooling.msservices.model.storage.BlobFile) BlobItem(com.microsoft.tooling.msservices.model.storage.BlobItem) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) 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