Search in sources :

Example 6 with StorageAccount

use of com.microsoft.azure.management.storage.StorageAccount in project azure-tools-for-java by Microsoft.

the class TableExplorerFileEditorProvider method accept.

@Override
public boolean accept(@NotNull Project project, @NotNull VirtualFile virtualFile) {
    StorageAccount storageAccount = virtualFile.getUserData(UIHelperImpl.STORAGE_KEY);
    Table table = virtualFile.getUserData(TABLE_KEY);
    return (storageAccount != null && table != null);
}
Also used : Table(com.microsoft.tooling.msservices.model.storage.Table) StorageAccount(com.microsoft.azure.management.storage.StorageAccount) ClientStorageAccount(com.microsoft.tooling.msservices.model.storage.ClientStorageAccount)

Example 7 with StorageAccount

use of com.microsoft.azure.management.storage.StorageAccount in project azure-tools-for-java by Microsoft.

the class StorageModule method refreshItems.

@Override
protected void refreshItems() throws AzureCmdException {
    List<Pair<String, String>> failedSubscriptions = new ArrayList<>();
    try {
        AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
        // not signed in
        if (azureManager == null) {
            return;
        }
        SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
        Set<String> sidList = subscriptionManager.getAccountSidList();
        for (String sid : sidList) {
            try {
                Azure azure = azureManager.getAzure(sid);
                List<com.microsoft.azure.management.storage.StorageAccount> storageAccounts = azure.storageAccounts().list();
                for (StorageAccount sm : storageAccounts) {
                    addChildNode(new StorageNode(this, sid, sm));
                }
            } catch (Exception ex) {
                failedSubscriptions.add(new ImmutablePair<>(sid, ex.getMessage()));
                continue;
            }
        }
    } catch (Exception ex) {
        DefaultLoader.getUIHelper().logError("An error occurred when trying to load Storage Accounts\n\n" + ex.getMessage(), ex);
    }
    // load External Accounts
    for (ClientStorageAccount clientStorageAccount : ExternalStorageHelper.getList(getProject())) {
        ClientStorageAccount storageAccount = StorageClientSDKManager.getManager().getStorageAccount(clientStorageAccount.getConnectionString());
    //            addChildNode(new ExternalStorageNode(this, storageAccount));
    }
    if (!failedSubscriptions.isEmpty()) {
        StringBuilder errorMessage = new StringBuilder("An error occurred when trying to load Storage Accounts for the subscriptions:\n\n");
        for (Pair error : failedSubscriptions) {
            errorMessage.append(error.getKey()).append(": ").append(error.getValue()).append("\n");
        }
        DefaultLoader.getUIHelper().logError("An error occurred when trying to load Storage Accounts\n\n" + errorMessage.toString(), null);
    }
}
Also used : Azure(com.microsoft.azure.management.Azure) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) ArrayList(java.util.ArrayList) ClientStorageAccount(com.microsoft.tooling.msservices.model.storage.ClientStorageAccount) SubscriptionManager(com.microsoft.azuretools.authmanage.SubscriptionManager) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) StorageAccount(com.microsoft.azure.management.storage.StorageAccount) ClientStorageAccount(com.microsoft.tooling.msservices.model.storage.ClientStorageAccount) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair)

Example 8 with StorageAccount

use of com.microsoft.azure.management.storage.StorageAccount in project azure-tools-for-java by Microsoft.

the class AzureDockerUtils method getStorageAccounts.

public static List<AzureDockerStorageAccount> getStorageAccounts(Azure azureClient) {
    List<AzureDockerStorageAccount> result = new ArrayList<>();
    if (azureClient != null) {
        for (StorageAccount storageAccount : azureClient.storageAccounts().list()) {
            AzureDockerStorageAccount dockerStorageAccount = new AzureDockerStorageAccount();
            dockerStorageAccount.name = storageAccount.name();
            dockerStorageAccount.region = storageAccount.regionName();
            dockerStorageAccount.resourceGroup = storageAccount.resourceGroupName();
            dockerStorageAccount.sid = azureClient.subscriptionId();
            dockerStorageAccount.skuType = storageAccount.sku().name().name();
            result.add(dockerStorageAccount);
        }
    }
    return result;
}
Also used : StorageAccount(com.microsoft.azure.management.storage.StorageAccount)

Example 9 with StorageAccount

use of com.microsoft.azure.management.storage.StorageAccount in project azure-sdk-for-java by Azure.

the class RegistryImpl method handleStorageSettings.

private Observable<StorageAccountParameters> handleStorageSettings() {
    final Func1<StorageAccount, StorageAccountParameters> onStorageAccountReady = new Func1<StorageAccount, StorageAccountParameters>() {

        @Override
        public StorageAccountParameters call(StorageAccount storageAccount) {
            RegistryImpl.this.storageAccount = storageAccount;
            List<StorageAccountKey> keys = storageAccount.getKeys();
            StorageAccountParameters storageAccountParameters = new StorageAccountParameters();
            storageAccountParameters.withName(storageAccount.name());
            storageAccountParameters.withAccessKey(keys.get(0).value());
            return storageAccountParameters;
        }
    };
    if (this.creatableStorageAccountKey != null) {
        return Observable.just((StorageAccount) this.createdResource(this.creatableStorageAccountKey)).map(onStorageAccountReady);
    } else {
        return Observable.just(this.storageAccount).map(onStorageAccountReady);
    }
}
Also used : StorageAccount(com.microsoft.azure.management.storage.StorageAccount) StorageAccountKey(com.microsoft.azure.management.storage.StorageAccountKey) Func1(rx.functions.Func1) StorageAccountParameters(com.microsoft.azure.management.containerregistry.StorageAccountParameters)

Example 10 with StorageAccount

use of com.microsoft.azure.management.storage.StorageAccount in project azure-sdk-for-java by Azure.

the class RedisCacheOperationsTests method canCRUDRedisCache.

@Test
public void canCRUDRedisCache() throws Exception {
    // Create
    Creatable<ResourceGroup> resourceGroups = resourceManager.resourceGroups().define(RG_NAME_SECOND).withRegion(Region.US_CENTRAL);
    Creatable<RedisCache> redisCacheDefinition1 = redisManager.redisCaches().define(RR_NAME).withRegion(Region.ASIA_EAST).withNewResourceGroup(RG_NAME).withBasicSku();
    Creatable<RedisCache> redisCacheDefinition2 = redisManager.redisCaches().define(RR_NAME_SECOND).withRegion(Region.US_CENTRAL).withNewResourceGroup(resourceGroups).withPremiumSku().withShardCount(10).withPatchSchedule(DayOfWeek.SUNDAY, 10, Period.minutes(302));
    Creatable<RedisCache> redisCacheDefinition3 = redisManager.redisCaches().define(RR_NAME_THIRD).withRegion(Region.US_CENTRAL).withNewResourceGroup(resourceGroups).withPremiumSku(2).withRedisConfiguration("maxclients", "2").withNonSslPort();
    CreatedResources<RedisCache> batchRedisCaches = redisManager.redisCaches().create(redisCacheDefinition1, redisCacheDefinition2, redisCacheDefinition3);
    StorageAccount storageAccount = storageManager.storageAccounts().define(SA_NAME).withRegion(Region.US_CENTRAL).withExistingResourceGroup(RG_NAME_SECOND).create();
    RedisCache redisCache = batchRedisCaches.get(redisCacheDefinition1.key());
    RedisCache redisCachePremium = batchRedisCaches.get(redisCacheDefinition3.key());
    Assert.assertEquals(RG_NAME, redisCache.resourceGroupName());
    Assert.assertEquals(SkuName.BASIC, redisCache.sku().name());
    // List by Resource Group
    List<RedisCache> redisCaches = redisManager.redisCaches().listByResourceGroup(RG_NAME);
    boolean found = false;
    for (RedisCache existingRedisCache : redisCaches) {
        if (existingRedisCache.name().equals(RR_NAME)) {
            found = true;
        }
    }
    Assert.assertTrue(found);
    Assert.assertEquals(1, redisCaches.size());
    // List all Redis resources
    redisCaches = redisManager.redisCaches().list();
    found = false;
    for (RedisCache existingRedisCache : redisCaches) {
        if (existingRedisCache.name().equals(RR_NAME)) {
            found = true;
        }
    }
    Assert.assertTrue(found);
    Assert.assertTrue(redisCaches.size() >= 3);
    // Get
    RedisCache redisCacheGet = redisManager.redisCaches().getByResourceGroup(RG_NAME, RR_NAME);
    Assert.assertNotNull(redisCacheGet);
    Assert.assertEquals(redisCache.id(), redisCacheGet.id());
    Assert.assertEquals(redisCache.provisioningState(), redisCacheGet.provisioningState());
    // Get Keys
    RedisAccessKeys redisKeys = redisCache.keys();
    Assert.assertNotNull(redisKeys);
    Assert.assertNotNull(redisKeys.primaryKey());
    Assert.assertNotNull(redisKeys.secondaryKey());
    // Regen key
    RedisAccessKeys oldKeys = redisCache.refreshKeys();
    RedisAccessKeys updatedPrimaryKey = redisCache.regenerateKey(RedisKeyType.PRIMARY);
    RedisAccessKeys updatedSecondaryKey = redisCache.regenerateKey(RedisKeyType.SECONDARY);
    Assert.assertNotNull(oldKeys);
    Assert.assertNotNull(updatedPrimaryKey);
    Assert.assertNotNull(updatedSecondaryKey);
    Assert.assertNotEquals(oldKeys.primaryKey(), updatedPrimaryKey.primaryKey());
    Assert.assertEquals(oldKeys.secondaryKey(), updatedPrimaryKey.secondaryKey());
    Assert.assertNotEquals(oldKeys.secondaryKey(), updatedSecondaryKey.secondaryKey());
    Assert.assertNotEquals(updatedPrimaryKey.secondaryKey(), updatedSecondaryKey.secondaryKey());
    Assert.assertEquals(updatedPrimaryKey.primaryKey(), updatedSecondaryKey.primaryKey());
    // Update to STANDARD Sku from BASIC SKU
    redisCache = redisCache.update().withStandardSku().apply();
    Assert.assertEquals(SkuName.STANDARD, redisCache.sku().name());
    Assert.assertEquals(SkuFamily.C, redisCache.sku().family());
    try {
        redisCache.update().withBasicSku(1).apply();
        fail();
    } catch (CloudException e) {
    // expected since Sku downgrade is not supported
    }
    // Refresh
    redisCache.refresh();
    // delete
    redisManager.redisCaches().deleteById(redisCache.id());
    // Premium SKU Functionality
    RedisCachePremium premiumCache = redisCachePremium.asPremium();
    Assert.assertEquals(SkuFamily.P, premiumCache.sku().family());
    // Redis configuration update
    premiumCache.update().withRedisConfiguration("maxclients", "3").apply();
    premiumCache.update().withoutRedisConfiguration("maxclients").apply();
    premiumCache.update().withoutRedisConfiguration().apply();
    premiumCache.update().withPatchSchedule(DayOfWeek.MONDAY, 1).withPatchSchedule(DayOfWeek.TUESDAY, 5).apply();
    // Reboot
    premiumCache.forceReboot(RebootType.ALL_NODES);
    // Patch Schedule
    List<ScheduleEntry> patchSchedule = premiumCache.listPatchSchedules();
    Assert.assertEquals(2, patchSchedule.size());
    premiumCache.deletePatchSchedule();
    patchSchedule = redisManager.redisCaches().getById(premiumCache.id()).asPremium().listPatchSchedules();
    Assert.assertNull(patchSchedule);
// currently throws because SAS url of the container should be provided as
// {"error":{
//      "code":"InvalidRequestBody",
//      "message": "One of the SAS URIs provided could not be used for the following reason:
//                  The SAS token is poorly formatted.\r\nRequestID=ed105089-b93b-427e-9cbb-d78ed80d23b0",
//      "target":null}}
// com.microsoft.azure.CloudException: One of the SAS URIs provided could not be used for the following reason: The SAS token is poorly formatted.
/*premiumCache.exportData(storageAccount.name(),"snapshot1");

        premiumCache.importData(Arrays.asList("snapshot1"));*/
}
Also used : CloudException(com.microsoft.azure.CloudException) StorageAccount(com.microsoft.azure.management.storage.StorageAccount) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) Test(org.junit.Test)

Aggregations

StorageAccount (com.microsoft.azure.management.storage.StorageAccount)30 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)9 ArrayList (java.util.ArrayList)8 ClientStorageAccount (com.microsoft.tooling.msservices.model.storage.ClientStorageAccount)7 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)5 Network (com.microsoft.azure.management.network.Network)5 Region (com.microsoft.azure.management.resources.fluentcore.arm.Region)5 Creatable (com.microsoft.azure.management.resources.fluentcore.model.Creatable)5 StorageAccountKey (com.microsoft.azure.management.storage.StorageAccountKey)5 Test (org.junit.Test)5 Func1 (rx.functions.Func1)4 Indexable (com.microsoft.azure.management.resources.fluentcore.model.Indexable)3 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)3 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)3 StopWatch (org.apache.commons.lang3.time.StopWatch)3 CloudException (com.microsoft.azure.CloudException)2 WebApp (com.microsoft.azure.management.appservice.WebApp)2 PublicIPAddress (com.microsoft.azure.management.network.PublicIPAddress)2 Resource (com.microsoft.azure.management.resources.fluentcore.arm.models.Resource)2 StorageAccounts (com.microsoft.azure.management.storage.StorageAccounts)2