Search in sources :

Example 46 with NotNull

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

the class StorageClientSDKManager method getTableEntity.

@NotNull
private static TableEntity getTableEntity(@NotNull String tableName, @NotNull DynamicTableEntity dte) {
    String partitionKey = Strings.nullToEmpty(dte.getPartitionKey());
    String rowKey = Strings.nullToEmpty(dte.getRowKey());
    String eTag = Strings.nullToEmpty(dte.getEtag());
    Calendar timestamp = new GregorianCalendar();
    if (dte.getTimestamp() != null) {
        timestamp.setTime(dte.getTimestamp());
    }
    Map<String, Property> properties = new HashMap<String, Property>();
    if (dte.getProperties() != null) {
        for (Entry<String, EntityProperty> entry : dte.getProperties().entrySet()) {
            if (entry.getKey() != null && entry.getValue() != null) {
                String key = entry.getKey();
                Property property;
                switch(entry.getValue().getEdmType()) {
                    case BOOLEAN:
                        property = new Property(entry.getValue().getValueAsBooleanObject());
                        break;
                    case DATE_TIME:
                        Calendar value = new GregorianCalendar();
                        value.setTime(entry.getValue().getValueAsDate());
                        property = new Property(value);
                        break;
                    case DOUBLE:
                        property = new Property(entry.getValue().getValueAsDoubleObject());
                        break;
                    case GUID:
                        property = new Property(entry.getValue().getValueAsUUID());
                        break;
                    case INT32:
                        property = new Property(entry.getValue().getValueAsIntegerObject());
                        break;
                    case INT64:
                        property = new Property(entry.getValue().getValueAsLongObject());
                        break;
                    case STRING:
                        property = new Property(entry.getValue().getValueAsString());
                        break;
                    default:
                        property = new Property(entry.getValue().getValueAsString());
                        break;
                }
                properties.put(key, property);
            }
        }
    }
    return new TableEntity(partitionKey, rowKey, tableName, eTag, timestamp, properties);
}
Also used : TableEntity(com.microsoft.tooling.msservices.model.storage.TableEntity) Property(com.microsoft.tooling.msservices.model.storage.TableEntity.Property) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 47 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 48 with NotNull

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

the class StorageClientSDKManager method createBlobFile.

@NotNull
public BlobFile createBlobFile(@NotNull ClientStorageAccount storageAccount, @NotNull BlobDirectory parentBlobDirectory, @NotNull BlobFile blobFile) throws AzureCmdException {
    try {
        CloudBlobClient client = getCloudBlobClient(storageAccount);
        String containerName = parentBlobDirectory.getContainerName();
        CloudBlobContainer container = client.getContainerReference(containerName);
        CloudBlobDirectory parentDirectory = container.getDirectoryReference(parentBlobDirectory.getPath());
        CloudBlob blob = getCloudBlob(parentDirectory, blobFile);
        blob.upload(new ByteArrayInputStream(new byte[0]), 0);
        return reloadBlob(blob, containerName, blobFile);
    } catch (Throwable t) {
        throw new AzureCmdException("Error creating the Blob File", t);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 49 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 50 with NotNull

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

the class StorageClientSDKManager method updateTableEntity.

@NotNull
public TableEntity updateTableEntity(@NotNull StorageAccount storageAccount, @NotNull TableEntity tableEntity) throws AzureCmdException {
    try {
        CloudTableClient client = getCloudTableClient(storageAccount);
        CloudTable cloudTable = client.getTableReference(tableEntity.getTableName());
        DynamicTableEntity entity = getDynamicTableEntity(tableEntity);
        TableRequestOptions tro = new TableRequestOptions();
        tro.setTablePayloadFormat(TablePayloadFormat.JsonFullMetadata);
        TableResult result = cloudTable.execute(TableOperation.replace(entity), tro, null);
        DynamicTableEntity resultEntity = result.getResultAsType();
        return getTableEntity(tableEntity.getTableName(), resultEntity);
    } catch (Throwable t) {
        throw new AzureCmdException("Error updating the Table Entity", t);
    }
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Aggregations

NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)65 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)21 Nullable (com.microsoft.azuretools.azurecommons.helpers.Nullable)8 File (java.io.File)8 IOException (java.io.IOException)8 IClusterDetail (com.microsoft.azure.hdinsight.sdk.cluster.IClusterDetail)7 java.util (java.util)7 Observable (rx.Observable)7 URI (java.net.URI)6 HDIException (com.microsoft.azure.hdinsight.sdk.common.HDIException)5 ObjectConvertUtils (com.microsoft.azure.hdinsight.sdk.rest.ObjectConvertUtils)5 List (java.util.List)5 StringUtils (org.apache.commons.lang3.StringUtils)5 Project (com.intellij.openapi.project.Project)4 CloudQueue (com.microsoft.azure.storage.queue.CloudQueue)4 CloudQueueClient (com.microsoft.azure.storage.queue.CloudQueueClient)4 ExecutionException (java.util.concurrent.ExecutionException)4 Collectors (java.util.stream.Collectors)4 ExecutionException (com.intellij.execution.ExecutionException)3 Artifact (com.intellij.packaging.artifacts.Artifact)3