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);
}
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()));
}
}
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;
}
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);
}
}
}
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;
}
Aggregations