use of com.microsoft.azure.SubResource in project azure-sdk-for-java by Azure.
the class VirtualMachineScaleSetImpl method loadCurrentPrimaryLoadBalancersIfAvailable.
private void loadCurrentPrimaryLoadBalancersIfAvailable() throws IOException {
if (this.primaryInternetFacingLoadBalancer != null && this.primaryInternalLoadBalancer != null) {
return;
}
String firstLoadBalancerId = null;
VirtualMachineScaleSetIPConfigurationInner ipConfig = primaryNicDefaultIPConfiguration();
if (!ipConfig.loadBalancerBackendAddressPools().isEmpty()) {
firstLoadBalancerId = ResourceUtils.parentResourceIdFromResourceId(ipConfig.loadBalancerBackendAddressPools().get(0).id());
}
if (firstLoadBalancerId == null && !ipConfig.loadBalancerInboundNatPools().isEmpty()) {
firstLoadBalancerId = ResourceUtils.parentResourceIdFromResourceId(ipConfig.loadBalancerInboundNatPools().get(0).id());
}
if (firstLoadBalancerId == null) {
return;
}
LoadBalancer loadBalancer1 = this.networkManager.loadBalancers().getById(firstLoadBalancerId);
if (loadBalancer1.publicIPAddressIds() != null && loadBalancer1.publicIPAddressIds().size() > 0) {
this.primaryInternetFacingLoadBalancer = loadBalancer1;
} else {
this.primaryInternalLoadBalancer = loadBalancer1;
}
String secondLoadBalancerId = null;
for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) {
if (!subResource.id().toLowerCase().startsWith(firstLoadBalancerId.toLowerCase())) {
secondLoadBalancerId = ResourceUtils.parentResourceIdFromResourceId(subResource.id());
break;
}
}
if (secondLoadBalancerId == null) {
for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) {
if (!subResource.id().toLowerCase().startsWith(firstLoadBalancerId.toLowerCase())) {
secondLoadBalancerId = ResourceUtils.parentResourceIdFromResourceId(subResource.id());
break;
}
}
}
if (secondLoadBalancerId == null) {
return;
}
LoadBalancer loadBalancer2 = this.networkManager.loadBalancers().getById(secondLoadBalancerId);
if (loadBalancer2.publicIPAddressIds() != null && loadBalancer2.publicIPAddressIds().size() > 0) {
this.primaryInternetFacingLoadBalancer = loadBalancer2;
} else {
this.primaryInternalLoadBalancer = loadBalancer2;
}
}
use of com.microsoft.azure.SubResource in project photon-model by vmware.
the class AzureInstanceService method newAzureNetworkInterface.
/**
* Converts Photon model constructs to underlying Azure NetworkInterface model.
*/
private NetworkInterfaceInner newAzureNetworkInterface(AzureInstanceContext ctx, AzureNicContext nicCtx) {
NetworkInterfaceDescription description = nicCtx.nicStateWithDesc.description;
NetworkInterfaceIPConfigurationInner ipConfig = new NetworkInterfaceIPConfigurationInner();
ipConfig.withName(AzureUtils.generateClusterCommonName(NICCONFIG_NAME_PREFIX, ctx));
ipConfig.withSubnet(nicCtx.subnet);
if (nicCtx.publicIP != null) {
// Public IP is not auto-assigned so check for existence
ipConfig.withPublicIPAddress(new SubResource().withId(nicCtx.publicIP.id()));
}
ipConfig.withPrivateIPAllocationMethod(new IPAllocationMethod(description.assignment.name()));
if (description.assignment == IpAssignment.STATIC) {
ipConfig.withPrivateIPAddress(description.address);
}
NetworkInterfaceInner nic = new NetworkInterfaceInner();
nic.withLocation(ctx.resourceGroup.location());
// Azure's custom serializers don't handle well collections constructed with
// Collections.singletonList(), so initialize an ArrayList
List<NetworkInterfaceIPConfigurationInner> ipConfigs = new ArrayList<>();
ipConfigs.add(ipConfig);
nic.withIpConfigurations(ipConfigs);
if (nicCtx.securityGroup != null) {
// Security group is optional so check for existence
nic.withNetworkSecurityGroup(new SubResource().withId(nicCtx.securityGroup.id()));
}
return nic;
}
use of com.microsoft.azure.SubResource in project photon-model by vmware.
the class AzureLoadBalancerService method buildFrontendIPConfiguration.
/**
* Build Azure Frontend IP configuration model
*
* @param context Azure load balancer context
* @return List of frontendIPConfiguration objects
*/
private List<FrontendIPConfigurationInner> buildFrontendIPConfiguration(AzureLoadBalancerContext context) {
List<FrontendIPConfigurationInner> frontendIPConfigurationInners = Lists.newArrayList();
if (context.loadBalancerStateExpanded.internetFacing) {
FrontendIPConfigurationInner frontendIPConfiguration = new FrontendIPConfigurationInner().withName(String.format("%s-public-frontend", context.loadBalancerStateExpanded.name));
frontendIPConfiguration.withPublicIPAddress(new SubResource().withId(context.publicIPAddressInner.id()));
frontendIPConfigurationInners.add(frontendIPConfiguration);
} else {
context.loadBalancerStateExpanded.subnets.forEach(subnet -> {
FrontendIPConfigurationInner frontendIPConfiguration = new FrontendIPConfigurationInner().withName(String.format("%s-%s-frontend", context.loadBalancerStateExpanded.name, subnet.name));
frontendIPConfiguration.withSubnet(new SubResource().withId(subnet.id));
frontendIPConfiguration.withPrivateIPAllocationMethod(IPAllocationMethod.DYNAMIC);
frontendIPConfigurationInners.add(frontendIPConfiguration);
});
}
return frontendIPConfigurationInners;
}
use of com.microsoft.azure.SubResource in project azure-sdk-for-java by Azure.
the class VirtualMachineScaleSetImpl method getInboundNatPoolsAssociatedWithIpConfiguration.
private static Map<String, LoadBalancerInboundNatPool> getInboundNatPoolsAssociatedWithIpConfiguration(LoadBalancer loadBalancer, VirtualMachineScaleSetIPConfigurationInner 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;
}
use of com.microsoft.azure.SubResource in project azure-sdk-for-java by Azure.
the class VirtualMachineScaleSetImpl method associateInboundNATPoolsToIpConfiguration.
private static void associateInboundNATPoolsToIpConfiguration(String loadBalancerId, VirtualMachineScaleSetIPConfigurationInner ipConfig, String... inboundNatPools) {
List<SubResource> inboundNatPoolSubResourcesToAssociate = new ArrayList<>();
for (String inboundNatPool : inboundNatPools) {
String inboundNatPoolId = mergePath(loadBalancerId, "inboundNatPools", inboundNatPool);
boolean found = false;
for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) {
if (subResource.id().equalsIgnoreCase(inboundNatPoolId)) {
found = true;
break;
}
}
if (!found) {
inboundNatPoolSubResourcesToAssociate.add(new SubResource().withId(inboundNatPoolId));
}
}
for (SubResource backendSubResource : inboundNatPoolSubResourcesToAssociate) {
ipConfig.loadBalancerInboundNatPools().add(backendSubResource);
}
}
Aggregations