com.microsoft.azure.management.network.LoadBalancer Java Examples

The following examples show how to use com.microsoft.azure.management.network.LoadBalancer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoadBalancerInventoryCollector.java    From pacbot with Apache License 2.0 6 votes vote down vote up
public List<LoadBalancerVH> fetchLoadBalancerDetails(SubscriptionVH subscription,
		Map<String, Map<String, String>> tagMap) {
	List<LoadBalancerVH> loadBalancerList = new ArrayList<>();

	Azure azure = azureCredentialProvider.getClient(subscription.getTenant(),subscription.getSubscriptionId());
	PagedList<LoadBalancer> loadBalancers = azure.loadBalancers().list();
	for (LoadBalancer loadBalancer : loadBalancers) {
		LoadBalancerVH loadBalancerVH = new LoadBalancerVH();
		loadBalancerVH.setHashCode(loadBalancer.hashCode());
		loadBalancerVH.setId(loadBalancer.id());
		loadBalancerVH.setKey(loadBalancer.key());
		loadBalancerVH.setPublicIPAddressIds(loadBalancer.publicIPAddressIds());
		loadBalancerVH.setName(loadBalancer.name());
		loadBalancerVH.setRegionName(loadBalancer.regionName());
		loadBalancerVH.setResourceGroupName(loadBalancer.resourceGroupName());
		loadBalancerVH.setTags(Util.tagsList(tagMap, loadBalancer.resourceGroupName(), loadBalancer.tags()));
		loadBalancerVH.setType(loadBalancer.type());
		loadBalancerVH.setSubscription(subscription.getSubscriptionId());
		loadBalancerVH.setSubscriptionName(subscription.getSubscriptionName());
		loadBalancerList.add(loadBalancerVH);

	}
	log.info("Target Type : {}  Total: {} ","LoadBalancer",loadBalancerList.size());
	return loadBalancerList;
}
 
Example #2
Source File: VirtualMachineScaleSetImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
private static void associateLoadBalancerToIpConfiguration(LoadBalancer loadBalancer,
                                                           VirtualMachineScaleSetIPConfiguration ipConfig) {
    Collection<LoadBalancerBackend> backends = loadBalancer.backends().values();
    String[] backendNames = new String[backends.size()];
    int i = 0;
    for (LoadBalancerBackend backend : backends) {
        backendNames[i] = backend.name();
        i++;
    }

    associateBackEndsToIpConfiguration(loadBalancer.id(),
            ipConfig,
            backendNames);

    Collection<LoadBalancerInboundNatPool> inboundNatPools = loadBalancer.inboundNatPools().values();
    String[] natPoolNames = new String[inboundNatPools.size()];
    i = 0;
    for (LoadBalancerInboundNatPool inboundNatPool : inboundNatPools) {
        natPoolNames[i] = inboundNatPool.name();
        i++;
    }

    associateInboundNATPoolsToIpConfiguration(loadBalancer.id(),
            ipConfig,
            natPoolNames);
}
 
Example #3
Source File: NicIPConfigurationBaseImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Override
public List<LoadBalancerInboundNatRule> listAssociatedLoadBalancerInboundNatRules() {
    final List<InboundNatRuleInner> inboundNatPoolRefs = this.inner().loadBalancerInboundNatRules();
    if (inboundNatPoolRefs == null) {
        return Collections.unmodifiableList(new ArrayList<LoadBalancerInboundNatRule>());
    }
    final Map<String, LoadBalancer> loadBalancers = new HashMap<>();
    final List<LoadBalancerInboundNatRule> rules = new ArrayList<>();
    for (InboundNatRuleInner ref : inboundNatPoolRefs) {
        String loadBalancerId = ResourceUtils.parentResourceIdFromResourceId(ref.id());
        LoadBalancer loadBalancer = loadBalancers.get(loadBalancerId.toLowerCase());
        if (loadBalancer == null) {
            loadBalancer = this.networkManager.loadBalancers().getById(loadBalancerId);
            loadBalancers.put(loadBalancerId.toLowerCase(), loadBalancer);
        }
        String ruleName = ResourceUtils.nameFromResourceId(ref.id());
        rules.add(loadBalancer.inboundNatRules().get(ruleName));
    }
    return Collections.unmodifiableList(rules);
}
 
Example #4
Source File: NicIPConfigurationBaseImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Override
public List<LoadBalancerBackend> listAssociatedLoadBalancerBackends() {
    final List<BackendAddressPoolInner> backendRefs = this.inner().loadBalancerBackendAddressPools();
    if (backendRefs == null) {
        return Collections.unmodifiableList(new ArrayList<LoadBalancerBackend>());
    }
    final Map<String, LoadBalancer> loadBalancers = new HashMap<>();
    final List<LoadBalancerBackend> backends = new ArrayList<>();
    for (BackendAddressPoolInner backendRef : backendRefs) {
        String loadBalancerId = ResourceUtils.parentResourceIdFromResourceId(backendRef.id());
        LoadBalancer loadBalancer = loadBalancers.get(loadBalancerId.toLowerCase());
        if (loadBalancer == null) {
            loadBalancer = this.networkManager.loadBalancers().getById(loadBalancerId);
            loadBalancers.put(loadBalancerId.toLowerCase(), loadBalancer);
        }
        String backendName = ResourceUtils.nameFromResourceId(backendRef.id());
        backends.add(loadBalancer.backends().get(backendName));
    }
    return Collections.unmodifiableList(backends);
}
 
Example #5
Source File: VirtualMachineScaleSetImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public LoadBalancer getPrimaryInternalLoadBalancer() throws IOException {
    if (this.primaryInternalLoadBalancer == null) {
        loadCurrentPrimaryLoadBalancersIfAvailable();
    }
    return this.primaryInternalLoadBalancer;
}
 
Example #6
Source File: TestLoadBalancer.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public LoadBalancer updateResource(LoadBalancer resource) throws Exception {
    resource =  resource.update()
            .withoutBackend("backend1")
            .withoutLoadBalancingRule("rule1")
            .withoutInboundNatPool("natpool1")
            .withoutProbe("httpProbe1")
            .withoutProbe("tcpProbe1")
            .withTag("tag1", "value1")
            .withTag("tag2", "value2")
            .apply();

    resource.refresh();
    Assert.assertTrue(resource.tags().containsKey("tag1"));

    // Verify frontends
    Assert.assertEquals(1, resource.frontends().size());
    Assert.assertEquals(1,  resource.publicFrontends().size());
    Assert.assertEquals(0,  resource.privateFrontends().size());

    // Verify probes
    Assert.assertFalse(resource.httpProbes().containsKey("httpProbe1"));
    Assert.assertFalse(resource.httpProbes().containsKey("tcpProbe1"));
    Assert.assertEquals(0, resource.httpProbes().size());
    Assert.assertEquals(0, resource.tcpProbes().size());

    // Verify backends
    Assert.assertEquals(0, resource.backends().size());

    // Verify rules
    Assert.assertFalse(resource.loadBalancingRules().containsKey("rule1"));
    Assert.assertEquals(0, resource.loadBalancingRules().size());

    // Verify NAT pools
    Assert.assertFalse(resource.inboundNatPools().containsKey("natpool1"));

    return resource;
}
 
Example #7
Source File: TestLoadBalancer.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public LoadBalancer updateResource(LoadBalancer resource) throws Exception {
    // Once zone associated with a private front-end, it cannot be removed, updated or new
    // one cannot be added.
    //
    return resource;
}
 
Example #8
Source File: TestPublicIPAddress.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
public static void printPIP(PublicIPAddress resource) {
    StringBuilder info = new StringBuilder().append("Public IP Address: ").append(resource.id())
            .append("\n\tName: ").append(resource.name())
            .append("\n\tResource group: ").append(resource.resourceGroupName())
            .append("\n\tRegion: ").append(resource.region())
            .append("\n\tTags: ").append(resource.tags())
            .append("\n\tIP Address: ").append(resource.ipAddress())
            .append("\n\tLeaf domain label: ").append(resource.leafDomainLabel())
            .append("\n\tFQDN: ").append(resource.fqdn())
            .append("\n\tReverse FQDN: ").append(resource.reverseFqdn())
            .append("\n\tIdle timeout (minutes): ").append(resource.idleTimeoutInMinutes())
            .append("\n\tIP allocation method: ").append(resource.ipAllocationMethod().toString())
            .append("\n\tIP version: ").append(resource.version().toString());

    // Show the associated load balancer if any
    info.append("\n\tLoad balancer association: ");
    if (resource.hasAssignedLoadBalancer()) {
        final LoadBalancerPublicFrontend frontend = resource.getAssignedLoadBalancerFrontend();
        final LoadBalancer lb = frontend.parent();
        info.append("\n\t\tLoad balancer ID: ").append(lb.id())
            .append("\n\t\tFrontend name: ").append(frontend.name());
    } else {
        info.append("(None)");
    }

    // Show the associated NIC if any
    info.append("\n\tNetwork interface association: ");
    if (resource.hasAssignedNetworkInterface()) {
        final NicIPConfiguration nicIp = resource.getAssignedNetworkInterfaceIPConfiguration();
        final NetworkInterface nic = nicIp.parent();
        info.append("\n\t\tNetwork interface ID: ").append(nic.id())
            .append("\n\t\tIP config name: ").append(nicIp.name());
    } else {
        info.append("(None)");
    }

    System.out.println(info.toString());
}
 
Example #9
Source File: VirtualMachineScaleSetImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
private static Map<String, LoadBalancerInboundNatPool> getInboundNatPoolsAssociatedWithIpConfiguration(LoadBalancer loadBalancer,
                                                                                                       VirtualMachineScaleSetIPConfiguration ipConfig) {
    String loadBalancerId = loadBalancer.id();
    Map<String, LoadBalancerInboundNatPool> attachedInboundNatPools = new HashMap<>();
    Map<String, LoadBalancerInboundNatPool> lbInboundNatPools = loadBalancer.inboundNatPools();
    for (LoadBalancerInboundNatPool lbInboundNatPool : lbInboundNatPools.values()) {
        String inboundNatPoolId =  mergePath(loadBalancerId, "inboundNatPools", lbInboundNatPool.name());
        for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) {
            if (subResource.id().equalsIgnoreCase(inboundNatPoolId)) {
                attachedInboundNatPools.put(lbInboundNatPool.name(), lbInboundNatPool);
            }
        }
    }
    return attachedInboundNatPools;
}
 
Example #10
Source File: VirtualMachineScaleSetImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
private static Map<String, LoadBalancerBackend> getBackendsAssociatedWithIpConfiguration(LoadBalancer loadBalancer,
                                                                                         VirtualMachineScaleSetIPConfiguration ipConfig) {
    String loadBalancerId = loadBalancer.id();
    Map<String, LoadBalancerBackend> attachedBackends = new HashMap<>();
    Map<String, LoadBalancerBackend> lbBackends = loadBalancer.backends();
    for (LoadBalancerBackend lbBackend : lbBackends.values()) {
        String backendId =  mergePath(loadBalancerId, "backendAddressPools", lbBackend.name());
        for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) {
            if (subResource.id().equalsIgnoreCase(backendId)) {
                attachedBackends.put(lbBackend.name(), lbBackend);
            }
        }
    }
    return attachedBackends;
}
 
Example #11
Source File: NicIPConfigurationImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public NicIPConfigurationImpl withExistingLoadBalancerBackend(LoadBalancer loadBalancer, String backendName) {
    if (loadBalancer != null) {
        for (BackendAddressPoolInner pool : loadBalancer.inner().backendAddressPools()) {
            if (pool.name().equalsIgnoreCase(backendName)) {
                ensureLoadBalancerBackendAddressPools().add(pool);
                return this;
            }
        }
    }

    return null;
}
 
Example #12
Source File: VirtualMachineScaleSetImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public VirtualMachineScaleSetImpl withExistingPrimaryInternetFacingLoadBalancer(LoadBalancer loadBalancer) {
    if (loadBalancer.publicIPAddressIds().isEmpty()) {
        throw new IllegalArgumentException("Parameter loadBalancer must be an Internet facing load balancer");
    }

    if (isInCreateMode()) {
        this.primaryInternetFacingLoadBalancer = loadBalancer;
        associateLoadBalancerToIpConfiguration(this.primaryInternetFacingLoadBalancer,
                this.primaryNicDefaultIPConfiguration());
    } else {
        this.primaryInternetFacingLoadBalancerToAttachOnUpdate = loadBalancer;
    }
    return this;
}
 
Example #13
Source File: VirtualMachineScaleSetImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public List<String> primaryPublicIPAddressIds() throws IOException {
    LoadBalancer loadBalancer = this.getPrimaryInternetFacingLoadBalancer();
    if (loadBalancer != null) {
        return loadBalancer.publicIPAddressIds();
    }
    return new ArrayList<>();
}
 
Example #14
Source File: VirtualMachineScaleSetImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public LoadBalancer getPrimaryInternetFacingLoadBalancer() throws IOException {
    if (this.primaryInternetFacingLoadBalancer == null) {
        loadCurrentPrimaryLoadBalancersIfAvailable();
    }
    return this.primaryInternetFacingLoadBalancer;
}
 
Example #15
Source File: NicIPConfigurationImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public NicIPConfigurationImpl withExistingLoadBalancerInboundNatRule(LoadBalancer loadBalancer, String inboundNatRuleName) {
    if (loadBalancer != null) {
        for (InboundNatRuleInner rule : loadBalancer.inner().inboundNatRules()) {
            if (rule.name().equalsIgnoreCase(inboundNatRuleName)) {
                ensureInboundNatRules().add(rule);
                return this;
            }
        }
    }

    return null;
}
 
Example #16
Source File: PublicIPAddressImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public LoadBalancerPublicFrontend getAssignedLoadBalancerFrontend() {
    if (this.hasAssignedLoadBalancer()) {
        final String refId = this.inner().ipConfiguration().id();
        final String loadBalancerId = ResourceUtils.parentResourceIdFromResourceId(refId);
        final LoadBalancer lb = this.myManager.loadBalancers().getById(loadBalancerId);
        final String frontendName = ResourceUtils.nameFromResourceId(refId);
        return (LoadBalancerPublicFrontend) lb.frontends().get(frontendName);
    } else {
        return null;
    }
}
 
Example #17
Source File: LoadBalancerImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public Observable<LoadBalancer> refreshAsync() {
    return super.refreshAsync().map(new Func1<LoadBalancer, LoadBalancer>() {
        @Override
        public LoadBalancer call(LoadBalancer loadBalancer) {
            LoadBalancerImpl impl = (LoadBalancerImpl) loadBalancer;
            impl.initializeChildrenFromInner();
            return impl;
        }
    });
}
 
Example #18
Source File: TestLoadBalancer.java    From azure-libraries-for-java with MIT License 4 votes vote down vote up
@Override
public void print(LoadBalancer resource) {
    TestLoadBalancer.printLB(resource);
}
 
Example #19
Source File: TestLoadBalancer.java    From azure-libraries-for-java with MIT License 4 votes vote down vote up
@Override
public void print(LoadBalancer resource) {
    TestLoadBalancer.printLB(resource);
}
 
Example #20
Source File: TestLoadBalancer.java    From azure-libraries-for-java with MIT License 4 votes vote down vote up
@Override
public LoadBalancer updateResource(LoadBalancer resource) throws Exception {
    String backendName = resource.backends().values().iterator().next().name();
    String frontendName = resource.frontends().values().iterator().next().name();

    List<NetworkInterface> nics = new ArrayList<>();
    for (String nicId : resource.backends().get(backendName).backendNicIPConfigurationNames().keySet()) {
        nics.add(resource.manager().networkInterfaces().getById(nicId));
    }
    NetworkInterface nic1 = nics.get(0);
    NetworkInterface nic2 = nics.get(1);

    // Remove the NIC associations
    nic1.update()
        .withoutLoadBalancerBackends()
        .withoutLoadBalancerInboundNatRules()
        .apply();
    Assert.assertTrue(nic1.primaryIPConfiguration().listAssociatedLoadBalancerBackends().size() == 0);

    nic2.update()
        .withoutLoadBalancerBackends()
        .withoutLoadBalancerInboundNatRules()
        .apply();
    Assert.assertTrue(nic2.primaryIPConfiguration().listAssociatedLoadBalancerBackends().size() == 0);

    // Update the load balancer
    ensurePIPs(resource.manager().publicIPAddresses());
    PublicIPAddress pip = resource.manager().publicIPAddresses().getByResourceGroup(GROUP_NAME, PIP_NAMES[1]);
    resource =  resource.update()
            .updatePublicFrontend(frontendName)
                .withExistingPublicIPAddress(pip)
                .parent()
            .withoutLoadBalancingRule("rule1")
            .withoutInboundNatRule("natrule1")
            .withTag("tag1", "value1")
            .withTag("tag2", "value2")
            .apply();
    Assert.assertTrue(resource.tags().containsKey("tag1"));
    Assert.assertEquals(0, resource.inboundNatRules().size());

    // Verify frontends
    LoadBalancerFrontend frontend = resource.frontends().get(frontendName);
    Assert.assertEquals(1,  resource.publicFrontends().size());
    Assert.assertEquals(0,  resource.privateFrontends().size());
    Assert.assertNotNull(frontend);
    Assert.assertTrue(frontend.isPublic());
    LoadBalancerPublicFrontend publicFrontend = (LoadBalancerPublicFrontend) frontend;
    Assert.assertTrue(pip.id().equalsIgnoreCase(publicFrontend.publicIPAddressId()));

    return resource;
}
 
Example #21
Source File: VirtualMachineScaleSetEMSILMSIOperationsTests.java    From azure-libraries-for-java with MIT License 4 votes vote down vote up
private LoadBalancer createInternalLoadBalancer(Region region, ResourceGroup resourceGroup,
                                                  Network network, String id) throws Exception {
    final String loadBalancerName = generateRandomResourceName("InternalLb" + id + "-", 18);
    final String privateFrontEndName = loadBalancerName + "-FE1";
    final String backendPoolName1 = loadBalancerName + "-BAP1";
    final String backendPoolName2 = loadBalancerName + "-BAP2";
    final String natPoolName1 = loadBalancerName + "-INP1";
    final String natPoolName2 = loadBalancerName + "-INP2";
    final String subnetName = "subnet1";

    LoadBalancer loadBalancer = this.networkManager.loadBalancers().define(loadBalancerName)
            .withRegion(region)
            .withExistingResourceGroup(resourceGroup)
            // Add two rules that uses above backend and probe
            .defineLoadBalancingRule("httpRule")
            .withProtocol(TransportProtocol.TCP)
            .fromFrontend(privateFrontEndName)
            .fromFrontendPort(1000)
            .toBackend(backendPoolName1)
            .withProbe("httpProbe")
            .attach()
            .defineLoadBalancingRule("httpsRule")
            .withProtocol(TransportProtocol.TCP)
            .fromFrontend(privateFrontEndName)
            .fromFrontendPort(1001)
            .toBackend(backendPoolName2)
            .withProbe("httpsProbe")
            .attach()

            // Add two NAT pools to enable direct VM connectivity to port 44 and 45
            .defineInboundNatPool(natPoolName1)
            .withProtocol(TransportProtocol.TCP)
            .fromFrontend(privateFrontEndName)
            .fromFrontendPortRange(8000, 8099)
            .toBackendPort(44)
            .attach()
            .defineInboundNatPool(natPoolName2)
            .withProtocol(TransportProtocol.TCP)
            .fromFrontend(privateFrontEndName)
            .fromFrontendPortRange(9000, 9099)
            .toBackendPort(45)
            .attach()

            // Explicitly define the frontend
            .definePrivateFrontend(privateFrontEndName)
            .withExistingSubnet(network, subnetName) // Frontend with VNET means internal load-balancer
            .attach()

            // Add two probes one per rule
            .defineHttpProbe("httpProbe")
            .withRequestPath("/")
            .attach()
            .defineHttpProbe("httpsProbe")
            .withRequestPath("/")
            .attach()

            .create();
    return loadBalancer;
}
 
Example #22
Source File: TestLoadBalancer.java    From azure-libraries-for-java with MIT License 4 votes vote down vote up
@Override
public LoadBalancer createResource(LoadBalancers resources) throws Exception {
    VirtualMachine[] existingVMs = ensureVMs(resources.manager().networks(), this.computeManager, 2);
    ensurePIPs(resources.manager().publicIPAddresses());
    PublicIPAddress pip0 = resources.manager().publicIPAddresses().getByResourceGroup(GROUP_NAME, PIP_NAMES[0]);

    // Create a load balancer
    LoadBalancer lb = resources.define(TestLoadBalancer.LB_NAME)
            .withRegion(REGION)
            .withExistingResourceGroup(GROUP_NAME)

            // Load balancing rules
            .defineLoadBalancingRule("rule1")
                .withProtocol(TransportProtocol.TCP)    // Required
                .fromExistingPublicIPAddress(pip0)
                .fromFrontendPort(81)
                .toBackend("backend1")
                .toBackendPort(82)                    // Optionals
                .withProbe("tcpProbe1")
                .withIdleTimeoutInMinutes(10)
                .withLoadDistribution(LoadDistribution.SOURCE_IP)
                .attach()

            // Inbound NAT pools
            .defineInboundNatPool("natpool1")
                .withProtocol(TransportProtocol.TCP)
                .fromExistingPublicIPAddress(pip0)
                .fromFrontendPortRange(2000, 2001)
                .toBackendPort(8080)
                .attach()

           // Probes (Optional)
           .defineTcpProbe("tcpProbe1")
                .withPort(25)               // Required
                .withIntervalInSeconds(15)  // Optionals
                .withNumberOfProbes(5)
                .attach()
           .defineHttpProbe("httpProbe1")
                .withRequestPath("/")       // Required
                .withIntervalInSeconds(13)  // Optionals
                .withNumberOfProbes(4)
                .attach()

            // Backends
            .defineBackend("backend1")
                .withExistingVirtualMachines(existingVMs)
                .attach()

            .create();

    // Verify frontends
    Assert.assertEquals(1, lb.frontends().size());
    Assert.assertEquals(1, lb.publicFrontends().size());
    Assert.assertEquals(0, lb.privateFrontends().size());
    LoadBalancerFrontend frontend = lb.frontends().values().iterator().next();
    Assert.assertTrue(frontend.isPublic());
    LoadBalancerPublicFrontend publicFrontend = (LoadBalancerPublicFrontend) frontend;
    Assert.assertTrue(pip0.id().equalsIgnoreCase(publicFrontend.publicIPAddressId()));

    // Verify backends
    Assert.assertEquals(1, lb.backends().size());

    // Verify probes
    Assert.assertEquals(1, lb.httpProbes().size());
    Assert.assertTrue(lb.httpProbes().containsKey("httpProbe1"));
    Assert.assertEquals(1, lb.tcpProbes().size());
    Assert.assertTrue(lb.tcpProbes().containsKey("tcpProbe1"));

    // Verify rules
    Assert.assertEquals(1, lb.loadBalancingRules().size());
    Assert.assertTrue(lb.loadBalancingRules().containsKey("rule1"));
    LoadBalancingRule rule = lb.loadBalancingRules().get("rule1");
    Assert.assertNotNull(rule.backend());
    Assert.assertTrue(rule.probe().name().equalsIgnoreCase("tcpProbe1"));

    // Verify inbound NAT pools
    Assert.assertTrue(lb.inboundNatPools().containsKey("natpool1"));
    Assert.assertEquals(1, lb.inboundNatPools().size());
    LoadBalancerInboundNatPool inboundNatPool = lb.inboundNatPools().get("natpool1");
    Assert.assertEquals(2000, inboundNatPool.frontendPortRangeStart());
    Assert.assertEquals(2001, inboundNatPool.frontendPortRangeEnd());
    Assert.assertEquals(8080, inboundNatPool.backendPort());

    return lb;
}
 
Example #23
Source File: TestLoadBalancer.java    From azure-libraries-for-java with MIT License 4 votes vote down vote up
@Override
public void print(LoadBalancer resource) {
    TestLoadBalancer.printLB(resource);
}
 
Example #24
Source File: VirtualMachineScaleSetBootDiagnosticsTests.java    From azure-libraries-for-java with MIT License 4 votes vote down vote up
@Test
public void bootDiagnosticsShouldUseVMSSUnManagedDisksExplicitStorage() throws Exception {
    final String storageName = SdkContext.randomResourceName("st", 14);
    final String vmssName = generateRandomResourceName("vmss", 10);

    ResourceGroup resourceGroup = this.resourceManager.resourceGroups()
            .define(RG_NAME)
            .withRegion(REGION)
            .create();

    Network network = this.networkManager
            .networks()
            .define("vmssvnet")
            .withRegion(REGION)
            .withExistingResourceGroup(resourceGroup)
            .withAddressSpace("10.0.0.0/28")
            .withSubnet("subnet1", "10.0.0.0/28")
            .create();

    LoadBalancer publicLoadBalancer = createInternetFacingLoadBalancer(REGION,
            resourceGroup,
            "1",
            LoadBalancerSkuType.BASIC);

    List<String> backends = new ArrayList<>();
    for (String backend : publicLoadBalancer.backends().keySet()) {
        backends.add(backend);
    }
    Assert.assertTrue(backends.size() == 2);

    StorageAccount storageAccount = storageManager.storageAccounts()
            .define(storageName)
            .withRegion(REGION)
            .withNewResourceGroup(RG_NAME)
            .create();

    VirtualMachineScaleSet virtualMachineScaleSet = this.computeManager.virtualMachineScaleSets()
            .define(vmssName)
            .withRegion(REGION)
            .withExistingResourceGroup(resourceGroup)
            .withSku(VirtualMachineScaleSetSkuTypes.STANDARD_A0)
            .withExistingPrimaryNetworkSubnet(network, "subnet1")
            .withExistingPrimaryInternetFacingLoadBalancer(publicLoadBalancer)
            .withPrimaryInternetFacingLoadBalancerBackends(backends.get(0), backends.get(1))
            .withoutPrimaryInternalLoadBalancer()
            .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
            .withRootUsername("jvuser")
            .withRootPassword("123OData!@#123")
            .withUnmanagedDisks()
            .withBootDiagnostics()
            .withExistingStorageAccount(storageAccount) // This storage account must be shared by disk and boot diagnostics
            .create();

    Assert.assertNotNull(virtualMachineScaleSet);
    Assert.assertTrue(virtualMachineScaleSet.isBootDiagnosticsEnabled());
    Assert.assertNotNull(virtualMachineScaleSet.bootDiagnosticsStorageUri());
    Assert.assertTrue(virtualMachineScaleSet.bootDiagnosticsStorageUri().contains(storageName));

    VirtualMachineScaleSetInner inner = virtualMachineScaleSet.inner();
    Assert.assertNotNull(inner);
    Assert.assertNotNull(inner.virtualMachineProfile());
    Assert.assertNotNull(inner.virtualMachineProfile().storageProfile());
    Assert.assertNotNull(inner.virtualMachineProfile().storageProfile().osDisk());
    List<String> containers = inner.virtualMachineProfile().storageProfile().osDisk().vhdContainers();
    Assert.assertFalse(containers.isEmpty());
}
 
Example #25
Source File: TestLoadBalancer.java    From azure-libraries-for-java with MIT License 4 votes vote down vote up
@Override
public LoadBalancer createResource(LoadBalancers resources) throws Exception {
    VirtualMachine[] existingVMs = ensureVMs(resources.manager().networks(), computeManager, 2);
    Creatable<PublicIPAddress> pipDef = resources.manager().publicIPAddresses().define(PIP_NAMES[0])
            .withRegion(TestLoadBalancer.REGION)
            .withExistingResourceGroup(TestLoadBalancer.GROUP_NAME)
            .withLeafDomainLabel(PIP_NAMES[0]);

    // Create a load balancer
    LoadBalancer lb = resources.define(TestLoadBalancer.LB_NAME)
            .withRegion(TestLoadBalancer.REGION)
            .withExistingResourceGroup(TestLoadBalancer.GROUP_NAME)
            // Inbound NAT rule
            .defineInboundNatRule("natrule1")
                .withProtocol(TransportProtocol.TCP)
                .fromNewPublicIPAddress(pipDef)
                .fromFrontendPort(88)
                .toBackendPort(80)
                .attach()
            // Backend
            .defineBackend("backend1")
                .withExistingVirtualMachines(existingVMs)
                .attach()
            .create();

    // Verify frontends
    Assert.assertEquals(1, lb.frontends().size());
    Assert.assertEquals(1, lb.publicFrontends().size());
    Assert.assertEquals(0,  lb.privateFrontends().size());
    LoadBalancerPublicFrontend frontend = lb.publicFrontends().values().iterator().next();
    Assert.assertNotNull(frontend);
    Assert.assertNotNull(frontend.publicIPAddressId());

    // Verify probes
    Assert.assertTrue(lb.tcpProbes().isEmpty());
    Assert.assertTrue(lb.httpProbes().isEmpty());

    // Verify LB rules
    Assert.assertEquals(0, lb.loadBalancingRules().size());

    // Verify NAT rules
    Assert.assertEquals(1, lb.inboundNatRules().size());
    LoadBalancerInboundNatRule natRule = lb.inboundNatRules().get("natrule1");
    Assert.assertNotNull(natRule);
    Assert.assertEquals(TransportProtocol.TCP, natRule.protocol());
    Assert.assertNotNull(natRule.frontend());
    Assert.assertTrue(natRule.frontend().isPublic());
    LoadBalancerPublicFrontend publicFrontend = (LoadBalancerPublicFrontend) natRule.frontend();
    PublicIPAddress pip = publicFrontend.getPublicIPAddress();
    Assert.assertNotNull(pip);
    Assert.assertEquals(pip.name(), PIP_NAMES[0]);
    Assert.assertEquals(pip.leafDomainLabel(), PIP_NAMES[0]);
    Assert.assertEquals(88, natRule.frontendPort());

    // Verify backends
    Assert.assertEquals(1, lb.backends().size());
    LoadBalancerBackend backend = lb.backends().values().iterator().next();
    Assert.assertNotNull(backend);
    Assert.assertEquals(2, backend.backendNicIPConfigurationNames().size());
    for (VirtualMachine vm : existingVMs) {
        Assert.assertTrue(backend.backendNicIPConfigurationNames().containsKey(vm.primaryNetworkInterfaceId()));
    }

    return lb;
}
 
Example #26
Source File: TestLoadBalancer.java    From azure-libraries-for-java with MIT License 4 votes vote down vote up
@Override
public void print(LoadBalancer resource) {
    TestLoadBalancer.printLB(resource);
}
 
Example #27
Source File: TestLoadBalancer.java    From azure-libraries-for-java with MIT License 4 votes vote down vote up
@Override
public void print(LoadBalancer resource) {
    TestLoadBalancer.printLB(resource);
}
 
Example #28
Source File: TestLoadBalancer.java    From azure-libraries-for-java with MIT License 4 votes vote down vote up
@Override
public void print(LoadBalancer resource) {
    TestLoadBalancer.printLB(resource);
}
 
Example #29
Source File: ManageManagedDisks.java    From azure-libraries-for-java with MIT License 4 votes vote down vote up
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)
            // Add two rules that uses above backend and probe
            .defineLoadBalancingRule(httpLoadBalancingRule)
                .withProtocol(TransportProtocol.TCP)
                .fromFrontend(frontendName)
                .fromFrontendPort(80)
                .toBackend(backendPoolName1)
                .withProbe(httpProbe)
                .attach()
            .defineLoadBalancingRule(httpsLoadBalancingRule)
                .withProtocol(TransportProtocol.TCP)
                .fromFrontend(frontendName)
                .fromFrontendPort(443)
                .toBackend(backendPoolName2)
                .withProbe(httpsProbe)
                .attach()
            // Add nat pools to enable direct VM connectivity for
            //  SSH to port 22 and TELNET to port 23
            .defineInboundNatPool(natPool50XXto22)
                .withProtocol(TransportProtocol.TCP)
                .fromFrontend(frontendName)
                .fromFrontendPortRange(5000, 5099)
                .toBackendPort(22)
                .attach()
            .defineInboundNatPool(natPool60XXto23)
                .withProtocol(TransportProtocol.TCP)
                .fromFrontend(frontendName)
                .fromFrontendPortRange(6000, 6099)
                .toBackendPort(23)
                .attach()
            // Explicitly define a frontend
            .definePublicFrontend(frontendName)
                .withExistingPublicIPAddress(publicIPAddress)
                .attach()
            // Add two probes one per rule
            .defineHttpProbe(httpProbe)
                .withRequestPath("/")
                .withPort(80)
                .attach()
            .defineHttpProbe(httpsProbe)
                .withRequestPath("/")
                .withPort(443)
                .attach()

            .create();
    return loadBalancer;
}
 
Example #30
Source File: NetworkInterfaceImpl.java    From azure-libraries-for-java with MIT License 4 votes vote down vote up
@Override
public NetworkInterfaceImpl withExistingLoadBalancerBackend(LoadBalancer loadBalancer, String backendName) {
    this.primaryIPConfiguration().withExistingLoadBalancerBackend(loadBalancer, backendName);
    return this;
}