Search in sources :

Example 1 with PublicIPAddress

use of com.microsoft.azure.management.network.PublicIPAddress in project azure-sdk-for-java by Azure.

the class VirtualMachineOperationsTests method canStreamParallelCreatedVirtualMachinesAndRelatedResources.

@Test
public void canStreamParallelCreatedVirtualMachinesAndRelatedResources() throws Exception {
    String vmNamePrefix = "vmz";
    String publicIpNamePrefix = generateRandomResourceName("pip-", 15);
    String networkNamePrefix = generateRandomResourceName("vnet-", 15);
    int count = 5;
    final Set<String> virtualMachineNames = new HashSet<>();
    for (int i = 0; i < count; i++) {
        virtualMachineNames.add(String.format("%s-%d", vmNamePrefix, i));
    }
    final Set<String> networkNames = new HashSet<>();
    for (int i = 0; i < count; i++) {
        networkNames.add(String.format("%s-%d", networkNamePrefix, i));
    }
    final Set<String> publicIPAddressNames = new HashSet<>();
    for (int i = 0; i < count; i++) {
        publicIPAddressNames.add(String.format("%s-%d", publicIpNamePrefix, i));
    }
    final CreatablesInfo creatablesInfo = prepareCreatableVirtualMachines(REGION, vmNamePrefix, networkNamePrefix, publicIpNamePrefix, count);
    final AtomicInteger resourceCount = new AtomicInteger(0);
    List<Creatable<VirtualMachine>> virtualMachineCreatables = creatablesInfo.virtualMachineCreatables;
    computeManager.virtualMachines().createAsync(virtualMachineCreatables).map(new Func1<Indexable, Indexable>() {

        @Override
        public Indexable call(Indexable createdResource) {
            if (createdResource instanceof Resource) {
                Resource resource = (Resource) createdResource;
                System.out.println("Created: " + resource.id());
                if (resource instanceof VirtualMachine) {
                    VirtualMachine virtualMachine = (VirtualMachine) resource;
                    Assert.assertTrue(virtualMachineNames.contains(virtualMachine.name()));
                    Assert.assertNotNull(virtualMachine.id());
                } else if (resource instanceof Network) {
                    Network network = (Network) resource;
                    Assert.assertTrue(networkNames.contains(network.name()));
                    Assert.assertNotNull(network.id());
                } else if (resource instanceof PublicIPAddress) {
                    PublicIPAddress publicIPAddress = (PublicIPAddress) resource;
                    Assert.assertTrue(publicIPAddressNames.contains(publicIPAddress.name()));
                    Assert.assertNotNull(publicIPAddress.id());
                }
            }
            resourceCount.incrementAndGet();
            return createdResource;
        }
    }).toBlocking().last();
    // 1 resource group, 1 storage, 5 network, 5 publicIp, 5 nic, 5 virtual machines
    // Additional one for CreatableUpdatableResourceRoot.
    // TODO - ans - We should not emit CreatableUpdatableResourceRoot.
    Assert.assertEquals(resourceCount.get(), 23);
}
Also used : Resource(com.microsoft.azure.management.resources.fluentcore.arm.models.Resource) PublicIPAddress(com.microsoft.azure.management.network.PublicIPAddress) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Network(com.microsoft.azure.management.network.Network) Creatable(com.microsoft.azure.management.resources.fluentcore.model.Creatable) Indexable(com.microsoft.azure.management.resources.fluentcore.model.Indexable) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with PublicIPAddress

use of com.microsoft.azure.management.network.PublicIPAddress in project azure-sdk-for-java by Azure.

the class VirtualMachineOperationsTests method canCreateVirtualMachinesAndRelatedResourcesInParallel.

@Test
public void canCreateVirtualMachinesAndRelatedResourcesInParallel() throws Exception {
    String vmNamePrefix = "vmz";
    String publicIpNamePrefix = generateRandomResourceName("pip-", 15);
    String networkNamePrefix = generateRandomResourceName("vnet-", 15);
    int count = 5;
    CreatablesInfo creatablesInfo = prepareCreatableVirtualMachines(REGION, vmNamePrefix, networkNamePrefix, publicIpNamePrefix, count);
    List<Creatable<VirtualMachine>> virtualMachineCreatables = creatablesInfo.virtualMachineCreatables;
    List<String> networkCreatableKeys = creatablesInfo.networkCreatableKeys;
    List<String> publicIpCreatableKeys = creatablesInfo.publicIpCreatableKeys;
    CreatedResources<VirtualMachine> createdVirtualMachines = computeManager.virtualMachines().create(virtualMachineCreatables);
    Assert.assertTrue(createdVirtualMachines.size() == count);
    Set<String> virtualMachineNames = new HashSet<>();
    for (int i = 0; i < count; i++) {
        virtualMachineNames.add(String.format("%s-%d", vmNamePrefix, i));
    }
    for (VirtualMachine virtualMachine : createdVirtualMachines.values()) {
        Assert.assertTrue(virtualMachineNames.contains(virtualMachine.name()));
        Assert.assertNotNull(virtualMachine.id());
    }
    Set<String> networkNames = new HashSet<>();
    for (int i = 0; i < count; i++) {
        networkNames.add(String.format("%s-%d", networkNamePrefix, i));
    }
    for (String networkCreatableKey : networkCreatableKeys) {
        Network createdNetwork = (Network) createdVirtualMachines.createdRelatedResource(networkCreatableKey);
        Assert.assertNotNull(createdNetwork);
        Assert.assertTrue(networkNames.contains(createdNetwork.name()));
    }
    Set<String> publicIPAddressNames = new HashSet<>();
    for (int i = 0; i < count; i++) {
        publicIPAddressNames.add(String.format("%s-%d", publicIpNamePrefix, i));
    }
    for (String publicIpCreatableKey : publicIpCreatableKeys) {
        PublicIPAddress createdPublicIPAddress = (PublicIPAddress) createdVirtualMachines.createdRelatedResource(publicIpCreatableKey);
        Assert.assertNotNull(createdPublicIPAddress);
        Assert.assertTrue(publicIPAddressNames.contains(createdPublicIPAddress.name()));
    }
}
Also used : Network(com.microsoft.azure.management.network.Network) Creatable(com.microsoft.azure.management.resources.fluentcore.model.Creatable) PublicIPAddress(com.microsoft.azure.management.network.PublicIPAddress) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with PublicIPAddress

use of com.microsoft.azure.management.network.PublicIPAddress in project azure-sdk-for-java by Azure.

the class ComputeManagementTest method createInternetFacingLoadBalancer.

protected LoadBalancer createInternetFacingLoadBalancer(Region region, ResourceGroup resourceGroup, String id) throws Exception {
    final String loadBalancerName = generateRandomResourceName("extlb" + id + "-", 18);
    final String publicIPName = "pip-" + loadBalancerName;
    final String frontendName = loadBalancerName + "-FE1";
    final String backendPoolName1 = loadBalancerName + "-BAP1";
    final String backendPoolName2 = loadBalancerName + "-BAP2";
    final String natPoolName1 = loadBalancerName + "-INP1";
    final String natPoolName2 = loadBalancerName + "-INP2";
    PublicIPAddress publicIPAddress = this.networkManager.publicIPAddresses().define(publicIPName).withRegion(region).withExistingResourceGroup(resourceGroup).withLeafDomainLabel(publicIPName).create();
    LoadBalancer loadBalancer = this.networkManager.loadBalancers().define(loadBalancerName).withRegion(region).withExistingResourceGroup(resourceGroup).definePublicFrontend(frontendName).withExistingPublicIPAddress(publicIPAddress).attach().defineBackend(backendPoolName1).attach().defineBackend(backendPoolName2).attach().defineHttpProbe("httpProbe").withRequestPath("/").attach().defineHttpProbe("httpsProbe").withRequestPath("/").attach().defineLoadBalancingRule("httpRule").withProtocol(TransportProtocol.TCP).withFrontend(frontendName).withFrontendPort(80).withProbe("httpProbe").withBackend(backendPoolName1).attach().defineLoadBalancingRule("httpsRule").withProtocol(TransportProtocol.TCP).withFrontend(frontendName).withFrontendPort(443).withProbe("httpsProbe").withBackend(backendPoolName2).attach().defineInboundNatPool(natPoolName1).withProtocol(TransportProtocol.TCP).withFrontend(frontendName).withFrontendPortRange(5000, 5099).withBackendPort(22).attach().defineInboundNatPool(natPoolName2).withProtocol(TransportProtocol.TCP).withFrontend(frontendName).withFrontendPortRange(6000, 6099).withBackendPort(23).attach().create();
    return loadBalancer;
}
Also used : LoadBalancer(com.microsoft.azure.management.network.LoadBalancer) PublicIPAddress(com.microsoft.azure.management.network.PublicIPAddress)

Example 4 with PublicIPAddress

use of com.microsoft.azure.management.network.PublicIPAddress in project azure-sdk-for-java by Azure.

the class LoadBalancerImpl method beforeCreating.

@Override
protected void beforeCreating() {
    // Account for the newly created public IPs
    for (Entry<String, String> pipFrontendAssociation : this.creatablePIPKeys.entrySet()) {
        PublicIPAddress pip = (PublicIPAddress) this.createdResource(pipFrontendAssociation.getKey());
        if (pip != null) {
            withExistingPublicIPAddress(pip.id(), pipFrontendAssociation.getValue());
        }
    }
    this.creatablePIPKeys.clear();
    // Reset and update probes
    List<ProbeInner> innerProbes = innersFromWrappers(this.httpProbes.values());
    innerProbes = innersFromWrappers(this.tcpProbes.values(), innerProbes);
    if (innerProbes == null) {
        innerProbes = new ArrayList<>();
    }
    this.inner().withProbes(innerProbes);
    // Reset and update backends
    List<BackendAddressPoolInner> innerBackends = innersFromWrappers(this.backends.values());
    if (null == innerBackends) {
        innerBackends = new ArrayList<>();
    }
    this.inner().withBackendAddressPools(innerBackends);
    // Reset and update frontends
    List<FrontendIPConfigurationInner> innerFrontends = innersFromWrappers(this.frontends.values());
    if (null == innerFrontends) {
        innerFrontends = new ArrayList<>();
    }
    this.inner().withFrontendIPConfigurations(innerFrontends);
    // Reset and update inbound NAT rules
    List<InboundNatRuleInner> innerNatRules = innersFromWrappers(this.inboundNatRules.values());
    if (null == innerNatRules) {
        innerNatRules = new ArrayList<>();
    }
    this.inner().withInboundNatRules(innerNatRules);
    for (LoadBalancerInboundNatRule natRule : this.inboundNatRules.values()) {
        // Clear deleted frontend references
        SubResource ref = natRule.inner().frontendIPConfiguration();
        if (ref != null && !this.frontends().containsKey(ResourceUtils.nameFromResourceId(ref.id()))) {
            natRule.inner().withFrontendIPConfiguration(null);
        }
    }
    // Reset and update inbound NAT pools
    List<InboundNatPoolInner> innerNatPools = innersFromWrappers(this.inboundNatPools.values());
    if (null == innerNatPools) {
        innerNatPools = new ArrayList<>();
    }
    this.inner().withInboundNatPools(innerNatPools);
    for (LoadBalancerInboundNatPool natPool : this.inboundNatPools.values()) {
        // Clear deleted frontend references
        SubResource ref = natPool.inner().frontendIPConfiguration();
        if (ref != null && !this.frontends().containsKey(ResourceUtils.nameFromResourceId(ref.id()))) {
            natPool.inner().withFrontendIPConfiguration(null);
        }
    }
    // Reset and update load balancing rules
    List<LoadBalancingRuleInner> innerRules = innersFromWrappers(this.loadBalancingRules.values());
    if (innerRules == null) {
        innerRules = new ArrayList<>();
    }
    this.inner().withLoadBalancingRules(innerRules);
    for (LoadBalancingRule lbRule : this.loadBalancingRules.values()) {
        SubResource ref;
        // Clear deleted frontend references
        ref = lbRule.inner().frontendIPConfiguration();
        if (ref != null && !this.frontends().containsKey(ResourceUtils.nameFromResourceId(ref.id()))) {
            lbRule.inner().withFrontendIPConfiguration(null);
        }
        // Clear deleted backend references
        ref = lbRule.inner().backendAddressPool();
        if (ref != null && !this.backends().containsKey(ResourceUtils.nameFromResourceId(ref.id()))) {
            lbRule.inner().withBackendAddressPool(null);
        }
        // Clear deleted probe references
        ref = lbRule.inner().probe();
        if (ref != null && !this.httpProbes().containsKey(ResourceUtils.nameFromResourceId(ref.id())) && !this.tcpProbes().containsKey(ResourceUtils.nameFromResourceId(ref.id()))) {
            lbRule.inner().withProbe(null);
        }
    }
}
Also used : SubResource(com.microsoft.azure.SubResource) LoadBalancingRule(com.microsoft.azure.management.network.LoadBalancingRule) PublicIPAddress(com.microsoft.azure.management.network.PublicIPAddress) LoadBalancerInboundNatPool(com.microsoft.azure.management.network.LoadBalancerInboundNatPool) LoadBalancerInboundNatRule(com.microsoft.azure.management.network.LoadBalancerInboundNatRule)

Example 5 with PublicIPAddress

use of com.microsoft.azure.management.network.PublicIPAddress in project azure-sdk-for-java by Azure.

the class ManageManagedDisks method prepareLoadBalancer.

private static LoadBalancer prepareLoadBalancer(Azure azure, Region region, String rgName) {
    final String loadBalancerName1 = SdkContext.randomResourceName("intlb" + "-", 18);
    final String frontendName = loadBalancerName1 + "-FE1";
    final String backendPoolName1 = loadBalancerName1 + "-BAP1";
    final String backendPoolName2 = loadBalancerName1 + "-BAP2";
    final String httpProbe = "httpProbe";
    final String httpsProbe = "httpsProbe";
    final String httpLoadBalancingRule = "httpRule";
    final String httpsLoadBalancingRule = "httpsRule";
    final String natPool50XXto22 = "natPool50XXto22";
    final String natPool60XXto23 = "natPool60XXto23";
    final String publicIpName = "pip-" + loadBalancerName1;
    PublicIPAddress publicIPAddress = azure.publicIPAddresses().define(publicIpName).withRegion(region).withExistingResourceGroup(rgName).withLeafDomainLabel(publicIpName).create();
    LoadBalancer loadBalancer = azure.loadBalancers().define(loadBalancerName1).withRegion(region).withExistingResourceGroup(rgName).definePublicFrontend(frontendName).withExistingPublicIPAddress(publicIPAddress).attach().defineBackend(backendPoolName1).attach().defineBackend(backendPoolName2).attach().defineHttpProbe(httpProbe).withRequestPath("/").withPort(80).attach().defineHttpProbe(httpsProbe).withRequestPath("/").withPort(443).attach().defineLoadBalancingRule(httpLoadBalancingRule).withProtocol(TransportProtocol.TCP).withFrontend(frontendName).withFrontendPort(80).withProbe(httpProbe).withBackend(backendPoolName1).attach().defineLoadBalancingRule(httpsLoadBalancingRule).withProtocol(TransportProtocol.TCP).withFrontend(frontendName).withFrontendPort(443).withProbe(httpsProbe).withBackend(backendPoolName2).attach().defineInboundNatPool(natPool50XXto22).withProtocol(TransportProtocol.TCP).withFrontend(frontendName).withFrontendPortRange(5000, 5099).withBackendPort(22).attach().defineInboundNatPool(natPool60XXto23).withProtocol(TransportProtocol.TCP).withFrontend(frontendName).withFrontendPortRange(6000, 6099).withBackendPort(23).attach().create();
    return loadBalancer;
}
Also used : LoadBalancer(com.microsoft.azure.management.network.LoadBalancer) PublicIPAddress(com.microsoft.azure.management.network.PublicIPAddress)

Aggregations

PublicIPAddress (com.microsoft.azure.management.network.PublicIPAddress)24 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)10 Network (com.microsoft.azure.management.network.Network)10 ArrayList (java.util.ArrayList)10 LoadBalancer (com.microsoft.azure.management.network.LoadBalancer)7 Region (com.microsoft.azure.management.resources.fluentcore.arm.Region)7 Creatable (com.microsoft.azure.management.resources.fluentcore.model.Creatable)6 LoadBalancerInboundNatRule (com.microsoft.azure.management.network.LoadBalancerInboundNatRule)5 NetworkInterface (com.microsoft.azure.management.network.NetworkInterface)4 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)4 Date (java.util.Date)4 VirtualMachineScaleSet (com.microsoft.azure.management.compute.VirtualMachineScaleSet)3 VirtualMachineScaleSetVM (com.microsoft.azure.management.compute.VirtualMachineScaleSetVM)3 VirtualMachineScaleSetNetworkInterface (com.microsoft.azure.management.network.VirtualMachineScaleSetNetworkInterface)3 VirtualMachineScaleSetNicIPConfiguration (com.microsoft.azure.management.network.VirtualMachineScaleSetNicIPConfiguration)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 JSch (com.jcraft.jsch.JSch)2 Session (com.jcraft.jsch.Session)2 HashSet (java.util.HashSet)2