Search in sources :

Example 16 with ResourceGroup

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

the class TestResourceStreaming method createResource.

@Override
public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exception {
    final String vmName = "vm" + this.testId;
    System.out.println("In createResource \n\n\n");
    Creatable<ResourceGroup> rgCreatable = virtualMachines.manager().resourceManager().resourceGroups().define(SdkContext.randomResourceName("rg" + vmName, 20)).withRegion(Region.US_EAST);
    Creatable<StorageAccount> storageCreatable = this.storageAccounts.define(SdkContext.randomResourceName("stg", 20)).withRegion(Region.US_EAST).withNewResourceGroup(rgCreatable);
    final AtomicInteger resourceCount = new AtomicInteger(0);
    VirtualMachine virtualMachine = (VirtualMachine) virtualMachines.define(vmName).withRegion(Region.US_EAST).withNewResourceGroup(rgCreatable).withNewPrimaryNetwork("10.0.0.0/28").withPrimaryPrivateIPAddressDynamic().withNewPrimaryPublicIPAddress(SdkContext.randomResourceName("pip", 20)).withPopularWindowsImage(KnownWindowsVirtualMachineImage.WINDOWS_SERVER_2012_R2_DATACENTER).withAdminUsername("testuser").withAdminPassword("12NewPA$$w0rd!").withSize(VirtualMachineSizeTypes.STANDARD_D1_V2).withNewStorageAccount(storageCreatable).withNewAvailabilitySet(SdkContext.randomResourceName("avset", 10)).createAsync().map(new Func1<Indexable, Resource>() {

        @Override
        public Resource call(Indexable resource) {
            resourceCount.incrementAndGet();
            Resource createdResource = (Resource) resource;
            System.out.println("Created :" + createdResource.id());
            return createdResource;
        }
    }).toBlocking().last();
    Assert.assertTrue(resourceCount.get() == 7);
    return virtualMachine;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StorageAccount(com.microsoft.azure.management.storage.StorageAccount) Resource(com.microsoft.azure.management.resources.fluentcore.arm.models.Resource) Indexable(com.microsoft.azure.management.resources.fluentcore.model.Indexable) Func1(rx.functions.Func1) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine)

Example 17 with ResourceGroup

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

the class ServiceBusOperationsTests method canCreateNamespaceThenCRUDOnTopic.

@Test
public void canCreateNamespaceThenCRUDOnTopic() {
    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.STANDARD).create();
    Assert.assertNotNull(namespace);
    Assert.assertNotNull(namespace.inner());
    String topicName = generateRandomResourceName("topic1-", 15);
    Topic topic = namespace.topics().define(topicName).create();
    Assert.assertNotNull(topic);
    Assert.assertNotNull(topic.inner());
    Assert.assertNotNull(topic.name());
    Assert.assertTrue(topic.name().equalsIgnoreCase(topicName));
    Period dupDetectionDuration = topic.duplicateMessageDetectionHistoryDuration();
    Assert.assertNotNull(dupDetectionDuration);
    Assert.assertEquals(10, dupDetectionDuration.getMinutes());
    // Default message TTL is TimeSpan.Max, assert parsing
    //
    Assert.assertEquals("10675199.02:48:05.4775807", topic.inner().defaultMessageTimeToLive());
    Period msgTtlDuration = topic.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, topic.maxSizeInMB());
    PagedList<Topic> topicsInNamespace = namespace.topics().list();
    Assert.assertNotNull(topicsInNamespace);
    Assert.assertTrue(topicsInNamespace.size() > 0);
    Topic foundTopic = null;
    for (Topic t : topicsInNamespace) {
        if (t.name().equalsIgnoreCase(topic.name())) {
            foundTopic = t;
            break;
        }
    }
    Assert.assertNotNull(foundTopic);
    foundTopic = foundTopic.update().withDefaultMessageTTL(new Period().withMinutes(20)).withDuplicateMessageDetectionHistoryDuration(new Period().withMinutes(15)).withDeleteOnIdleDurationInMinutes(25).apply();
    Period ttlDuration = foundTopic.defaultMessageTtlDuration();
    Assert.assertNotNull(ttlDuration);
    Assert.assertEquals(20, ttlDuration.getMinutes());
    Period duplicateDetectDuration = foundTopic.duplicateMessageDetectionHistoryDuration();
    Assert.assertNotNull(duplicateDetectDuration);
    Assert.assertEquals(15, duplicateDetectDuration.getMinutes());
    Assert.assertEquals(25, foundTopic.deleteOnIdleDurationInMinutes());
    // Delete
    namespace.topics().deleteByName(foundTopic.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 18 with ResourceGroup

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

the class ServiceBusOperationsTests method canPerformCRUDOnSubscriptions.

@Test
public void canPerformCRUDOnSubscriptions() {
    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);
    String subscriptionName = generateRandomResourceName("sub1-", 15);
    // Create NS with Topic
    //
    ServiceBusNamespace namespace = serviceBusManager.namespaces().define(namespaceDNSLabel).withRegion(region).withNewResourceGroup(rgCreatable).withSku(NamespaceSku.PREMIUM_CAPACITY1).withNewTopic(topicName, 1024).create();
    // Create Topic subscriptions and list it
    //
    Topic topic = namespace.topics().getByName(topicName);
    ServiceBusSubscription subscription = topic.subscriptions().define(subscriptionName).withDefaultMessageTTL(new Period().withMinutes(20)).create();
    Assert.assertNotNull(subscription);
    Assert.assertNotNull(subscription.inner());
    Assert.assertEquals(20, subscription.defaultMessageTtlDuration().getMinutes());
    subscription = topic.subscriptions().getByName(subscriptionName);
    Assert.assertNotNull(subscription);
    Assert.assertNotNull(subscription.inner());
    PagedList<ServiceBusSubscription> subscriptionsInTopic = topic.subscriptions().list();
    Assert.assertTrue(subscriptionsInTopic.size() > 0);
    boolean foundSubscription = false;
    for (ServiceBusSubscription s : subscriptionsInTopic) {
        if (s.name().equalsIgnoreCase(subscription.name())) {
            foundSubscription = true;
            break;
        }
    }
    Assert.assertTrue(foundSubscription);
    topic.subscriptions().deleteByName(subscriptionName);
    subscriptionsInTopic = topic.subscriptions().list();
    Assert.assertTrue(subscriptionsInTopic.size() == 0);
}
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 ResourceGroup

use of com.microsoft.azure.management.resources.ResourceGroup 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 20 with ResourceGroup

use of com.microsoft.azure.management.resources.ResourceGroup 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)

Aggregations

ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)53 Test (org.junit.Test)22 Region (com.microsoft.azure.management.resources.fluentcore.arm.Region)13 SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)12 ArrayList (java.util.ArrayList)10 Network (com.microsoft.azure.management.network.Network)9 StorageAccount (com.microsoft.azure.management.storage.StorageAccount)9 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)8 Creatable (com.microsoft.azure.management.resources.fluentcore.model.Creatable)7 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)7 Azure (com.microsoft.azure.management.Azure)6 AppServicePlan (com.microsoft.azure.management.appservice.AppServicePlan)6 WebApp (com.microsoft.azure.management.appservice.WebApp)6 HashMap (java.util.HashMap)5 StopWatch (org.apache.commons.lang3.time.StopWatch)5 PublicIPAddress (com.microsoft.azure.management.network.PublicIPAddress)4 Location (com.microsoft.azure.management.resources.Location)4 CloudException (com.microsoft.azure.CloudException)3 Period (org.joda.time.Period)3 ApplicationGateway (com.microsoft.azure.management.network.ApplicationGateway)2