Search in sources :

Example 16 with Region

use of com.microsoft.azure.management.resources.fluentcore.arm.Region in project azure-sdk-for-java by Azure.

the class ServiceBusOperationsTests method canCreateDeleteTopicWithNamespace.

@Test
public void canCreateDeleteTopicWithNamespace() {
    Region region = Region.US_EAST;
    Creatable<ResourceGroup> rgCreatable = resourceManager.resourceGroups().define(RG_NAME).withRegion(region);
    String namespaceDNSLabel = generateRandomResourceName("jvsbns", 15);
    String topicName = generateRandomResourceName("topic1-", 15);
    // Create NS with Topic
    //
    ServiceBusNamespace namespace = serviceBusManager.namespaces().define(namespaceDNSLabel).withRegion(region).withNewResourceGroup(rgCreatable).withSku(NamespaceSku.PREMIUM_CAPACITY1).withNewTopic(topicName, 1024).create();
    Assert.assertNotNull(namespace);
    Assert.assertNotNull(namespace.inner());
    // Lookup topic
    //
    PagedList<Topic> topicsInNamespace = namespace.topics().list();
    Assert.assertNotNull(topicsInNamespace);
    Assert.assertEquals(1, topicsInNamespace.size());
    Topic foundTopic = null;
    for (Topic t : topicsInNamespace) {
        if (t.name().equalsIgnoreCase(topicName)) {
            foundTopic = t;
            break;
        }
    }
    Assert.assertNotNull(foundTopic);
    // Remove Topic
    //
    namespace.update().withoutTopic(topicName).apply();
    topicsInNamespace = namespace.topics().list();
    Assert.assertNotNull(topicsInNamespace);
    Assert.assertEquals(0, topicsInNamespace.size());
}
Also used : Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) Test(org.junit.Test)

Example 17 with Region

use of com.microsoft.azure.management.resources.fluentcore.arm.Region in project azure-sdk-for-java by Azure.

the class ServiceBusOperationsTests method canCreateDeleteQueueWithNamespace.

@Test
public void canCreateDeleteQueueWithNamespace() {
    Region region = Region.US_EAST;
    Creatable<ResourceGroup> rgCreatable = resourceManager.resourceGroups().define(RG_NAME).withRegion(region);
    String namespaceDNSLabel = generateRandomResourceName("jvsbns", 15);
    String queueName = generateRandomResourceName("queue1-", 15);
    // Create NS with Queue
    //
    ServiceBusNamespace namespace = serviceBusManager.namespaces().define(namespaceDNSLabel).withRegion(region).withNewResourceGroup(rgCreatable).withSku(NamespaceSku.PREMIUM_CAPACITY1).withNewQueue(queueName, 1024).create();
    Assert.assertNotNull(namespace);
    Assert.assertNotNull(namespace.inner());
    // Lookup queue
    //
    PagedList<Queue> queuesInNamespace = namespace.queues().list();
    Assert.assertNotNull(queuesInNamespace);
    Assert.assertEquals(1, queuesInNamespace.size());
    Queue foundQueue = null;
    for (Queue q : queuesInNamespace) {
        if (q.name().equalsIgnoreCase(queueName)) {
            foundQueue = q;
            break;
        }
    }
    Assert.assertNotNull(foundQueue);
    // Remove Queue
    //
    namespace.update().withoutQueue(queueName).apply();
    queuesInNamespace = namespace.queues().list();
    Assert.assertNotNull(queuesInNamespace);
    Assert.assertEquals(0, queuesInNamespace.size());
}
Also used : Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) Test(org.junit.Test)

Example 18 with Region

use of com.microsoft.azure.management.resources.fluentcore.arm.Region in project azure-sdk-for-java by Azure.

the class ServiceBusOperationsTests method canCreateNamespaceThenCRUDOnQueue.

@Test
public void canCreateNamespaceThenCRUDOnQueue() {
    Region region = Region.US_EAST;
    Creatable<ResourceGroup> rgCreatable = resourceManager.resourceGroups().define(RG_NAME).withRegion(region);
    String namespaceDNSLabel = generateRandomResourceName("jvsbns", 15);
    ServiceBusNamespace namespace = serviceBusManager.namespaces().define(namespaceDNSLabel).withRegion(region).withNewResourceGroup(rgCreatable).withSku(NamespaceSku.PREMIUM_CAPACITY1).create();
    Assert.assertNotNull(namespace);
    Assert.assertNotNull(namespace.inner());
    String queueName = generateRandomResourceName("queue1-", 15);
    Queue queue = namespace.queues().define(queueName).create();
    Assert.assertNotNull(queue);
    Assert.assertNotNull(queue.inner());
    Assert.assertNotNull(queue.name());
    Assert.assertTrue(queue.name().equalsIgnoreCase(queueName));
    // Default lock duration is 1 minute, assert TimeSpan("00:01:00") parsing
    //
    Assert.assertEquals("00:01:00", queue.inner().lockDuration());
    Assert.assertEquals(60, queue.lockDurationInSeconds());
    Period dupDetectionDuration = queue.duplicateMessageDetectionHistoryDuration();
    Assert.assertNotNull(dupDetectionDuration);
    Assert.assertEquals(10, dupDetectionDuration.getMinutes());
    // Default message TTL is TimeSpan.Max, assert parsing
    //
    Assert.assertEquals("10675199.02:48:05.4775807", queue.inner().defaultMessageTimeToLive());
    Period msgTtlDuration = queue.defaultMessageTtlDuration();
    Assert.assertNotNull(msgTtlDuration);
    // Assert the default ttl TimeSpan("10675199.02:48:05.4775807") parsing
    //
    Assert.assertEquals(10675199, msgTtlDuration.getDays());
    Assert.assertEquals(2, msgTtlDuration.getHours());
    Assert.assertEquals(48, msgTtlDuration.getMinutes());
    // Assert the default max size In MB
    //
    Assert.assertEquals(1024, queue.maxSizeInMB());
    PagedList<Queue> queuesInNamespace = namespace.queues().list();
    Assert.assertNotNull(queuesInNamespace);
    Assert.assertTrue(queuesInNamespace.size() > 0);
    Queue foundQueue = null;
    for (Queue q : queuesInNamespace) {
        if (q.name().equalsIgnoreCase(queueName)) {
            foundQueue = q;
            break;
        }
    }
    Assert.assertNotNull(foundQueue);
    // Dead lettering disabled by default
    //
    Assert.assertFalse(foundQueue.isDeadLetteringEnabledForExpiredMessages());
    foundQueue = foundQueue.update().withMessageLockDurationInSeconds(120).withDefaultMessageTTL(new Period().withMinutes(20)).withExpiredMessageMovedToDeadLetterQueue().withMessageMovedToDeadLetterQueueOnMaxDeliveryCount(25).apply();
    Assert.assertEquals(120, foundQueue.lockDurationInSeconds());
    Assert.assertTrue(foundQueue.isDeadLetteringEnabledForExpiredMessages());
    Assert.assertEquals(25, foundQueue.maxDeliveryCountBeforeDeadLetteringMessage());
    namespace.queues().deleteByName(foundQueue.name());
}
Also used : Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) Period(org.joda.time.Period) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) Test(org.junit.Test)

Example 19 with Region

use of com.microsoft.azure.management.resources.fluentcore.arm.Region in project azure-sdk-for-java by Azure.

the class ServiceBusOperationsTests method canOperateOnAuthorizationRules.

@Test
public void canOperateOnAuthorizationRules() {
    Region region = Region.US_EAST;
    Creatable<ResourceGroup> rgCreatable = resourceManager.resourceGroups().define(RG_NAME).withRegion(region);
    String namespaceDNSLabel = generateRandomResourceName("jvsbns", 15);
    String queueName = generateRandomResourceName("queue1-", 15);
    String topicName = generateRandomResourceName("topic1-", 15);
    String nsRuleName = generateRandomResourceName("nsrule1-", 15);
    // Create NS with Queue, Topic and authorization rule
    //
    ServiceBusNamespace namespace = serviceBusManager.namespaces().define(namespaceDNSLabel).withRegion(region).withNewResourceGroup(rgCreatable).withSku(NamespaceSku.PREMIUM_CAPACITY1).withNewQueue(queueName, 1024).withNewTopic(topicName, 1024).withNewManageRule(nsRuleName).create();
    // Lookup ns authorization rule
    //
    PagedList<NamespaceAuthorizationRule> rulesInNamespace = namespace.authorizationRules().list();
    Assert.assertNotNull(rulesInNamespace);
    // Default + one explicit
    Assert.assertEquals(2, rulesInNamespace.size());
    NamespaceAuthorizationRule foundNsRule = null;
    for (NamespaceAuthorizationRule rule : rulesInNamespace) {
        if (rule.name().equalsIgnoreCase(nsRuleName)) {
            foundNsRule = rule;
            break;
        }
    }
    Assert.assertNotNull(foundNsRule);
    AuthorizationKeys nsRuleKeys = foundNsRule.getKeys();
    Assert.assertNotNull(nsRuleKeys);
    Assert.assertNotNull(nsRuleKeys.inner());
    String primaryKey = nsRuleKeys.primaryKey();
    Assert.assertNotNull(primaryKey);
    Assert.assertNotNull(nsRuleKeys.secondaryKey());
    Assert.assertNotNull(nsRuleKeys.primaryConnectionString());
    Assert.assertNotNull(nsRuleKeys.secondaryConnectionString());
    nsRuleKeys = foundNsRule.regenerateKey(Policykey.PRIMARY_KEY);
    Assert.assertNotEquals(nsRuleKeys.primaryKey(), primaryKey);
    // Lookup queue & operate on auth rules
    //
    PagedList<Queue> queuesInNamespace = namespace.queues().list();
    Assert.assertNotNull(queuesInNamespace);
    Assert.assertEquals(1, queuesInNamespace.size());
    Queue queue = queuesInNamespace.get(0);
    Assert.assertNotNull(queue);
    Assert.assertNotNull(queue.inner());
    QueueAuthorizationRule qRule = queue.authorizationRules().define("rule1").withListeningEnabled().create();
    Assert.assertNotNull(qRule);
    Assert.assertNotNull(qRule.rights().contains(AccessRights.LISTEN));
    qRule = qRule.update().withManagementEnabled().apply();
    Assert.assertNotNull(qRule.rights().contains(AccessRights.MANAGE));
    PagedList<QueueAuthorizationRule> rulesInQueue = queue.authorizationRules().list();
    Assert.assertTrue(rulesInQueue.size() > 0);
    boolean foundQRule = false;
    for (QueueAuthorizationRule r : rulesInQueue) {
        if (r.name().equalsIgnoreCase(qRule.name())) {
            foundQRule = true;
            break;
        }
    }
    Assert.assertTrue(foundQRule);
    queue.authorizationRules().deleteByName(qRule.name());
    // Lookup topic & operate on auth rules
    //
    PagedList<Topic> topicsInNamespace = namespace.topics().list();
    Assert.assertNotNull(topicsInNamespace);
    Assert.assertEquals(1, topicsInNamespace.size());
    Topic topic = topicsInNamespace.get(0);
    Assert.assertNotNull(topic);
    Assert.assertNotNull(topic.inner());
    TopicAuthorizationRule tRule = topic.authorizationRules().define("rule2").withSendingEnabled().create();
    Assert.assertNotNull(tRule);
    Assert.assertNotNull(tRule.rights().contains(AccessRights.SEND));
    tRule = tRule.update().withManagementEnabled().apply();
    Assert.assertNotNull(tRule.rights().contains(AccessRights.MANAGE));
    PagedList<TopicAuthorizationRule> rulesInTopic = topic.authorizationRules().list();
    Assert.assertTrue(rulesInTopic.size() > 0);
    boolean foundTRule = false;
    for (TopicAuthorizationRule r : rulesInTopic) {
        if (r.name().equalsIgnoreCase(tRule.name())) {
            foundTRule = true;
            break;
        }
    }
    Assert.assertTrue(foundTRule);
    topic.authorizationRules().deleteByName(tRule.name());
}
Also used : Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) Test(org.junit.Test)

Example 20 with Region

use of com.microsoft.azure.management.resources.fluentcore.arm.Region in project azure-sdk-for-java by Azure.

the class ResourceGroupsTests method canCreateResourceGroup.

@Test
public void canCreateResourceGroup() throws Exception {
    final String rgName = SdkContext.randomResourceName("rg", 9);
    Region region = Region.US_SOUTH_CENTRAL;
    // Create
    resourceGroups.define(rgName).withRegion(Region.US_SOUTH_CENTRAL).withTag("department", "finance").withTag("tagname", "tagvalue").create();
    // List
    ResourceGroup groupResult = null;
    for (ResourceGroup rg : resourceGroups.listByTag("department", "finance")) {
        if (rg.name().equals(rgName)) {
            groupResult = rg;
            break;
        }
    }
    Assert.assertNotNull(groupResult);
    Assert.assertEquals("finance", groupResult.tags().get("department"));
    Assert.assertEquals("tagvalue", groupResult.tags().get("tagname"));
    Assert.assertTrue(region.name().equalsIgnoreCase(groupResult.regionName()));
    // Check existence
    Assert.assertTrue(resourceGroups.checkExistence(rgName));
    // Get
    ResourceGroup getGroup = resourceGroups.getByName(rgName);
    Assert.assertNotNull(getGroup);
    Assert.assertEquals(rgName, getGroup.name());
    // Update
    ResourceGroup updatedGroup = getGroup.update().withTag("tag1", "value1").apply();
    Assert.assertEquals("value1", updatedGroup.tags().get("tag1"));
    Assert.assertTrue(region.name().equalsIgnoreCase(getGroup.regionName()));
    // Delete
    resourceGroups.deleteByName(rgName);
    Assert.assertFalse(resourceGroups.checkExistence(rgName));
}
Also used : Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) Test(org.junit.Test)

Aggregations

Region (com.microsoft.azure.management.resources.fluentcore.arm.Region)52 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)20 ArrayList (java.util.ArrayList)19 Network (com.microsoft.azure.management.network.Network)16 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)14 Test (org.junit.Test)12 Disk (com.microsoft.azure.management.compute.Disk)8 PublicIPAddress (com.microsoft.azure.management.network.PublicIPAddress)8 Date (java.util.Date)8 Creatable (com.microsoft.azure.management.resources.fluentcore.model.Creatable)7 VirtualMachineDataDisk (com.microsoft.azure.management.compute.VirtualMachineDataDisk)6 NetworkInterface (com.microsoft.azure.management.network.NetworkInterface)6 StorageAccount (com.microsoft.azure.management.storage.StorageAccount)6 VirtualMachineScaleSet (com.microsoft.azure.management.compute.VirtualMachineScaleSet)4 LoadBalancer (com.microsoft.azure.management.network.LoadBalancer)4 Indexable (com.microsoft.azure.management.resources.fluentcore.model.Indexable)4 StopWatch (org.apache.commons.lang3.time.StopWatch)4 JSchException (com.jcraft.jsch.JSchException)3 VirtualMachineCustomImage (com.microsoft.azure.management.compute.VirtualMachineCustomImage)3 TrafficManagerProfile (com.microsoft.azure.management.trafficmanager.TrafficManagerProfile)3