Search in sources :

Example 11 with Region

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

the class TestNetworkInterface method createResource.

@Override
public NetworkInterface createResource(NetworkInterfaces networkInterfaces) throws Exception {
    final String nicName = "nic" + this.testId;
    final String vnetName = "net" + this.testId;
    final String pipName = "pip" + this.testId;
    final Region region = Region.US_EAST;
    Network network = networkInterfaces.manager().networks().define(vnetName).withRegion(region).withNewResourceGroup().withAddressSpace("10.0.0.0/28").withSubnet("subnet1", "10.0.0.0/29").withSubnet("subnet2", "10.0.0.8/29").create();
    NetworkInterface nic = networkInterfaces.define(nicName).withRegion(region).withExistingResourceGroup(network.resourceGroupName()).withExistingPrimaryNetwork(network).withSubnet("subnet1").withPrimaryPrivateIPAddressDynamic().withNewPrimaryPublicIPAddress(pipName).withIPForwarding().create();
    // Verifications
    NicIPConfiguration ipConfig = nic.primaryIPConfiguration();
    Assert.assertNotNull(ipConfig);
    network = ipConfig.getNetwork();
    Assert.assertNotNull(network);
    Subnet subnet = network.subnets().get(ipConfig.subnetName());
    Assert.assertNotNull(subnet);
    Assert.assertEquals(1, subnet.networkInterfaceIPConfigurationCount());
    Set<NicIPConfiguration> ipConfigs = subnet.getNetworkInterfaceIPConfigurations();
    Assert.assertNotNull(ipConfigs);
    Assert.assertEquals(1, ipConfigs.size());
    NicIPConfiguration ipConfig2 = ipConfigs.iterator().next();
    Assert.assertEquals(ipConfig.name().toLowerCase(), ipConfig2.name().toLowerCase());
    return nic;
}
Also used : Network(com.microsoft.azure.management.network.Network) Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) NetworkInterface(com.microsoft.azure.management.network.NetworkInterface) Subnet(com.microsoft.azure.management.network.Subnet) NicIPConfiguration(com.microsoft.azure.management.network.NicIPConfiguration)

Example 12 with Region

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

the class TestTrafficManager method createResource.

@Override
public TrafficManagerProfile createResource(TrafficManagerProfiles profiles) throws Exception {
    final Region region = Region.US_EAST;
    final String groupName = "rg" + this.testId;
    final String pipName = "pip" + this.testId;
    final String pipDnsLabel = SdkContext.randomResourceName("contoso", 15);
    final String tmProfileName = "tm" + this.testId;
    final String nestedTmProfileName = "nested" + tmProfileName;
    final String tmProfileDnsLabel = SdkContext.randomResourceName("tmdns", 15);
    final String nestedTmProfileDnsLabel = "nested" + tmProfileDnsLabel;
    ResourceGroup.DefinitionStages.WithCreate rgCreatable = profiles.manager().resourceManager().resourceGroups().define(groupName).withRegion(region);
    // Creates a TM profile that will be used as a nested profile endpoint in parent TM profile
    //
    TrafficManagerProfile nestedProfile = profiles.define(nestedTmProfileName).withNewResourceGroup(rgCreatable).withLeafDomainLabel(nestedTmProfileDnsLabel).withPriorityBasedRouting().defineExternalTargetEndpoint("external-ep-1").toFqdn("www.gitbook.com").fromRegion(Region.INDIA_CENTRAL).attach().withHttpsMonitoring().withTimeToLive(500).create();
    Assert.assertTrue(nestedProfile.isEnabled());
    Assert.assertNotNull(nestedProfile.monitorStatus());
    Assert.assertEquals(nestedProfile.monitoringPort(), 443);
    Assert.assertEquals(nestedProfile.monitoringPath(), "/");
    Assert.assertEquals(nestedProfile.azureEndpoints().size(), 0);
    Assert.assertEquals(nestedProfile.nestedProfileEndpoints().size(), 0);
    Assert.assertEquals(nestedProfile.externalEndpoints().size(), 1);
    Assert.assertEquals(nestedProfile.fqdn(), nestedTmProfileDnsLabel + ".trafficmanager.net");
    Assert.assertEquals(nestedProfile.timeToLive(), 500);
    // Creates a public ip to be used as an Azure endpoint
    //
    PublicIPAddress publicIPAddress = this.publicIPAddresses.define(pipName).withRegion(region).withNewResourceGroup(rgCreatable).withLeafDomainLabel(pipDnsLabel).create();
    Assert.assertNotNull(publicIPAddress.fqdn());
    // Creates a TM profile
    //
    TrafficManagerProfile profile = profiles.define(tmProfileName).withNewResourceGroup(rgCreatable).withLeafDomainLabel(tmProfileDnsLabel).withWeightBasedRouting().defineExternalTargetEndpoint(externalEndpointName21).toFqdn(externalFqdn21).fromRegion(Region.US_EAST).withRoutingPriority(1).withRoutingWeight(1).attach().defineExternalTargetEndpoint(externalEndpointName22).toFqdn(externalFqdn22).fromRegion(Region.US_EAST2).withRoutingPriority(2).withRoutingWeight(1).withTrafficDisabled().attach().defineAzureTargetEndpoint(azureEndpointName).toResourceId(publicIPAddress.id()).withRoutingPriority(3).attach().defineNestedTargetEndpoint(nestedProfileEndpointName).toProfile(nestedProfile).fromRegion(Region.INDIA_CENTRAL).withMinimumEndpointsToEnableTraffic(1).withRoutingPriority(4).attach().withHttpMonitoring().create();
    Assert.assertTrue(profile.isEnabled());
    Assert.assertNotNull(profile.monitorStatus());
    Assert.assertEquals(profile.monitoringPort(), 80);
    Assert.assertEquals(profile.monitoringPath(), "/");
    Assert.assertEquals(profile.azureEndpoints().size(), 1);
    Assert.assertEquals(profile.nestedProfileEndpoints().size(), 1);
    Assert.assertEquals(profile.externalEndpoints().size(), 2);
    Assert.assertEquals(profile.fqdn(), tmProfileDnsLabel + ".trafficmanager.net");
    // Default
    Assert.assertEquals(profile.timeToLive(), 300);
    profile = profile.refresh();
    Assert.assertEquals(profile.azureEndpoints().size(), 1);
    Assert.assertEquals(profile.nestedProfileEndpoints().size(), 1);
    Assert.assertEquals(profile.externalEndpoints().size(), 2);
    int c = 0;
    for (TrafficManagerExternalEndpoint endpoint : profile.externalEndpoints().values()) {
        Assert.assertEquals(endpoint.endpointType(), EndpointType.EXTERNAL);
        if (endpoint.name().equalsIgnoreCase(externalEndpointName21)) {
            Assert.assertEquals(endpoint.routingPriority(), 1);
            Assert.assertEquals(endpoint.fqdn(), externalFqdn21);
            Assert.assertNotNull(endpoint.monitorStatus());
            Assert.assertEquals(endpoint.sourceTrafficLocation(), Region.US_EAST);
            c++;
        } else if (endpoint.name().equalsIgnoreCase(externalEndpointName22)) {
            Assert.assertEquals(endpoint.routingPriority(), 2);
            Assert.assertEquals(endpoint.fqdn(), externalFqdn22);
            Assert.assertNotNull(endpoint.monitorStatus());
            Assert.assertEquals(endpoint.sourceTrafficLocation(), Region.US_EAST2);
            c++;
        }
    }
    Assert.assertEquals(c, 2);
    c = 0;
    for (TrafficManagerAzureEndpoint endpoint : profile.azureEndpoints().values()) {
        Assert.assertEquals(endpoint.endpointType(), EndpointType.AZURE);
        if (endpoint.name().equalsIgnoreCase(azureEndpointName)) {
            Assert.assertEquals(endpoint.routingPriority(), 3);
            Assert.assertNotNull(endpoint.monitorStatus());
            Assert.assertEquals(endpoint.targetAzureResourceId(), publicIPAddress.id());
            Assert.assertEquals(endpoint.targetResourceType(), TargetAzureResourceType.PUBLICIP);
            c++;
        }
    }
    Assert.assertEquals(c, 1);
    c = 0;
    for (TrafficManagerNestedProfileEndpoint endpoint : profile.nestedProfileEndpoints().values()) {
        Assert.assertEquals(endpoint.endpointType(), EndpointType.NESTED_PROFILE);
        if (endpoint.name().equalsIgnoreCase(nestedProfileEndpointName)) {
            Assert.assertEquals(endpoint.routingPriority(), 4);
            Assert.assertNotNull(endpoint.monitorStatus());
            Assert.assertEquals(endpoint.minimumChildEndpointCount(), 1);
            Assert.assertEquals(endpoint.nestedProfileId(), nestedProfile.id());
            Assert.assertEquals(endpoint.sourceTrafficLocation(), Region.INDIA_CENTRAL);
            c++;
        }
    }
    Assert.assertEquals(c, 1);
    return profile;
}
Also used : TrafficManagerExternalEndpoint(com.microsoft.azure.management.trafficmanager.TrafficManagerExternalEndpoint) TrafficManagerNestedProfileEndpoint(com.microsoft.azure.management.trafficmanager.TrafficManagerNestedProfileEndpoint) TrafficManagerAzureEndpoint(com.microsoft.azure.management.trafficmanager.TrafficManagerAzureEndpoint) TrafficManagerProfile(com.microsoft.azure.management.trafficmanager.TrafficManagerProfile) Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) PublicIPAddress(com.microsoft.azure.management.network.PublicIPAddress) TrafficManagerExternalEndpoint(com.microsoft.azure.management.trafficmanager.TrafficManagerExternalEndpoint) TrafficManagerAzureEndpoint(com.microsoft.azure.management.trafficmanager.TrafficManagerAzureEndpoint) TrafficManagerNestedProfileEndpoint(com.microsoft.azure.management.trafficmanager.TrafficManagerNestedProfileEndpoint)

Example 13 with Region

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

the class AzureTests method testRegions.

/**
     * Tests the regions enum.
     */
@Test
public void testRegions() {
    // Show built-in regions
    System.out.println("Built-in regions list:");
    int regionsCount = Region.values().length;
    for (Region region : Region.values()) {
        System.out.println("Name: " + region.name() + ", Label: " + region.label());
    }
    // Look up built-in region
    Region region = Region.fromName("westus");
    Assert.assertTrue(region == Region.US_WEST);
    // Add a region
    Region region2 = Region.fromName("madeUpRegion");
    Assert.assertNotNull(region2);
    Assert.assertTrue(region2.name().equalsIgnoreCase("madeUpRegion"));
    Region region3 = Region.fromName("madeupregion");
    Assert.assertEquals(region3, region2);
    Assert.assertEquals(Region.values().length, regionsCount + 1);
}
Also used : Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) Test(org.junit.Test)

Example 14 with Region

use of com.microsoft.azure.management.resources.fluentcore.arm.Region 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 15 with Region

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

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