Search in sources :

Example 6 with NotNull

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

the class UIHelperImpl method getDetails.

@NotNull
private static String getDetails(@Nullable Throwable ex) {
    String details = "";
    if (ex != null) {
        StringWriter sw = new StringWriter();
        ex.printStackTrace(new PrintWriter(sw));
        details = sw.toString();
        if (ex instanceof AzureCmdException) {
            String errorLog = ((AzureCmdException) ex).getErrorLog();
            if (errorLog != null && !errorLog.isEmpty()) {
                details = errorLog;
            }
        }
    }
    return details;
}
Also used : StringWriter(java.io.StringWriter) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) PrintWriter(java.io.PrintWriter) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 7 with NotNull

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

the class AzureAADHelper method getHttpsURLConnectionProvider.

@NotNull
private static HttpsURLConnectionProvider getHttpsURLConnectionProvider(@NotNull final String accessToken, @NotNull final RestServiceManager manager) {
    return new HttpsURLConnectionProvider() {

        @Override
        @NotNull
        public HttpsURLConnection getSSLConnection(@NotNull String managementUrl, @NotNull String path, @NotNull ContentType contentType) throws AzureCmdException {
            HttpsURLConnection sslConnection = manager.getSSLConnection(managementUrl, path, contentType);
            sslConnection.addRequestProperty(AUTHORIZATION_HEADER, "Bearer " + accessToken);
            return sslConnection;
        }
    };
}
Also used : HttpsURLConnectionProvider(com.microsoft.tooling.msservices.helpers.azure.rest.RestServiceManager.HttpsURLConnectionProvider) ContentType(com.microsoft.tooling.msservices.helpers.azure.rest.RestServiceManager.ContentType) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 8 with NotNull

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

the class RestServiceManagerBaseImpl method executeRequest.

@NotNull
public String executeRequest(@NotNull String managementUrl, @NotNull String path, @NotNull ContentType contentType, @NotNull String method, @Nullable String postData, @NotNull HttpsURLConnectionProvider sslConnectionProvider) throws AzureCmdException {
    try {
        HttpsURLConnection sslConnection = sslConnectionProvider.getSSLConnection(managementUrl, path, contentType);
        HttpResponse response = getResponse(method, postData, sslConnection);
        int code = response.getCode();
        if (code < 200 || code >= 300) {
            throw new AzureCmdException(String.format("Error status code %s: %s", code, response.getMessage()), response.getContent());
        }
        return response.getContent();
    } catch (IOException e) {
        throw new AzureCmdException(e.getMessage(), e);
    }
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 9 with NotNull

use of com.microsoft.azuretools.azurecommons.helpers.NotNull 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)

Example 10 with NotNull

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

the class StorageClientSDKManager method dequeueFirstQueueMessage.

@NotNull
public QueueMessage dequeueFirstQueueMessage(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
    try {
        CloudQueueClient client = getCloudQueueClient(storageAccount);
        String queueName = queue.getName();
        CloudQueue cloudQueue = client.getQueueReference(queueName);
        CloudQueueMessage cqm = cloudQueue.retrieveMessage();
        String id = "";
        String content = "";
        Calendar insertionTime = new GregorianCalendar();
        Calendar expirationTime = new GregorianCalendar();
        int dequeueCount = 0;
        if (cqm != null) {
            id = Strings.nullToEmpty(cqm.getId());
            content = Strings.nullToEmpty(cqm.getMessageContentAsString());
            if (cqm.getInsertionTime() != null) {
                insertionTime.setTime(cqm.getInsertionTime());
            }
            if (cqm.getExpirationTime() != null) {
                expirationTime.setTime(cqm.getExpirationTime());
            }
            dequeueCount = cqm.getDequeueCount();
        }
        QueueMessage queueMessage = new QueueMessage(id, queueName, content, insertionTime, expirationTime, dequeueCount);
        if (cqm != null) {
            cloudQueue.deleteMessage(cqm);
        }
        return queueMessage;
    } catch (Throwable t) {
        throw new AzureCmdException("Error dequeuing the first Queue Message", t);
    }
}
Also used : QueueMessage(com.microsoft.tooling.msservices.model.storage.QueueMessage) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) CloudQueueClient(com.microsoft.azure.storage.queue.CloudQueueClient) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) 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