Skip to content

Commit

Permalink
Merge pull request #1065 from martinsawicki/martin-networking
Browse files Browse the repository at this point in the history
need to move this simple tweak PR out of the way as a more fundamental change is coming
  • Loading branch information
Martin Sawicki authored Sep 15, 2016
2 parents 7d43103 + 05bedf4 commit 94d8785
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package com.microsoft.azure.management.network;

import java.util.Map;
import java.util.Set;

import com.microsoft.azure.management.network.implementation.BackendAddressPoolInner;
import com.microsoft.azure.management.network.model.HasLoadBalancingRules;
Expand All @@ -28,6 +29,11 @@ public interface Backend extends
*/
Map<String, String> backendNicIpConfigurationNames();

/**
* @return a list of the resource IDs of the virtual machines associated with this backend
*/
Set<String> getVirtualMachineIds();

/**
* Grouping of backend definition stages.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ interface Definition extends
DefinitionStages.WithProbe,
DefinitionStages.WithProbeOrLoadBalancingRule,
DefinitionStages.WithLoadBalancingRule,
DefinitionStages.WithLoadBalancingRuleOrCreate {
DefinitionStages.WithLoadBalancingRuleOrCreate,
DefinitionStages.WithCreateAndInboundNatPool,
DefinitionStages.WithCreateAndInboundNatRule,
DefinitionStages.WithCreateAndNatChoice {
}

/**
Expand Down Expand Up @@ -240,8 +243,7 @@ interface WithVirtualMachine<ReturnT> {
}

/**
* The stage of a load balancer definition allowing to add a public ip address as one of the load
* balancer's public frontends.
* The stage of a load balancer definition allowing to add a public IP address as the default public frontend.
* @param <ReturnT> the next stage of the definition
*/
interface WithPublicIpAddress<ReturnT> {
Expand Down Expand Up @@ -342,7 +344,7 @@ interface WithLoadBalancingRule {
/**
* The stage of a load balancer definition allowing to create a load balancing rule or create the load balancer.
*/
interface WithLoadBalancingRuleOrCreate extends WithLoadBalancingRule, WithCreate {
interface WithLoadBalancingRuleOrCreate extends WithLoadBalancingRule, WithCreateAndNatChoice {
}

/**
Expand All @@ -352,9 +354,32 @@ interface WithLoadBalancingRuleOrCreate extends WithLoadBalancingRule, WithCreat
*/
interface WithCreate extends
Creatable<LoadBalancer>,
Resource.DefinitionWithTags<WithCreate>,
DefinitionStages.WithInboundNatRule,
DefinitionStages.WithInboundNatPool {
Resource.DefinitionWithTags<WithCreate> {
}

/**
* The stage of a load balancer definition allowing to create the load balancer or start configuring optional inbound NAT rules or pools.
*/
interface WithCreateAndNatChoice extends
WithCreate,
WithInboundNatRule,
WithInboundNatPool {
}

/**
* The stage of a load balancer definition allowing to create the load balancer or add an inbound NAT pool.
*/
interface WithCreateAndInboundNatPool extends
WithCreate,
WithInboundNatPool {
}

/**
* The stage of a load balancer definition allowing to create the load balancer or add an inbound NAT rule.
*/
interface WithCreateAndInboundNatRule extends
WithCreate,
WithInboundNatRule {
}

/**
Expand All @@ -368,7 +393,7 @@ interface WithInboundNatRule {
* @param name the name of the inbound NAT rule
* @return the first stage of the new inbound NAT rule definition
*/
InboundNatRule.DefinitionStages.Blank<WithCreate> defineInboundNatRule(String name);
InboundNatRule.DefinitionStages.Blank<WithCreateAndInboundNatRule> defineInboundNatRule(String name);
}

/**
Expand All @@ -382,7 +407,7 @@ interface WithInboundNatPool {
* @param name the name of the inbound NAT pool
* @return the first stage of the new inbound NAT pool definition
*/
InboundNatPool.DefinitionStages.Blank<WithCreate> defineInboundNatPool(String name);
InboundNatPool.DefinitionStages.Blank<WithCreateAndInboundNatPool> defineInboundNatPool(String name);
}
}

Expand Down Expand Up @@ -531,7 +556,7 @@ interface WithLoadBalancingRule {
/**
* The stage of a load balancer update allowing to define, remove or edit Internet-facing frontends.
*/
interface WithInternetFrontend {
interface WithInternetFrontend extends WithPublicIpAddress {
/**
* Begins the update of a load balancer frontend.
* <p>
Expand All @@ -556,6 +581,46 @@ interface WithInternetFrontend {
PublicFrontend.Update updateInternetFrontend(String name);
}

/**
* The stage of a load balancer update allowing to add a public IP address as the default public frontend.
*/
interface WithPublicIpAddress {
/**
* Assigns the provided public IP address to the default public frontend to the load balancer.
* <p>
* This will create a new default frontend for the load balancer under the name "default", if one does not already exist.
* @param publicIpAddress an existing public IP address
* @return the next stage of the update
*/
Update withExistingPublicIpAddress(PublicIpAddress publicIpAddress);

/**
* Creates a new public IP address as the default public frontend of the load balancer,
* using an automatically generated name and leaf DNS label
* derived from the load balancer's name, in the same resource group and region.
* <p>
* This will create a new default frontend for the load balancer under the name "default", if one does not already exist.
* @return the next stage of the update
*/
Update withNewPublicIpAddress();

/**
* Adds a new public IP address as the default public frontend of the load balancer,
* using the specified DNS leaf label, an automatically generated frontend name derived from the DNS label,
* in the same resource group and region as the load balancer.
* @param dnsLeafLabel a DNS leaf label
* @return the next stage of the update
*/
Update withNewPublicIpAddress(String dnsLeafLabel);

/**
* Adds a new public IP address to the default front end of the load balancer.
* @param creatablePublicIpAddress the creatable stage of a public IP address definition
* @return the next stage of the update
*/
Update withNewPublicIpAddress(Creatable<PublicIpAddress> creatablePublicIpAddress);
}

/**
* The stage of a load balancer update allowing to define one or more private frontends.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ public interface NetworkInterface extends
*
* @return the network security group associated with this network interface.
*/
NetworkSecurityGroup networkSecurityGroup();
NetworkSecurityGroup getNetworkSecurityGroup();

/**
* @return the resource ID of the associated virtual machine, or null if none.
*/
String virtualMachineId();

// Setters (fluent)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ public interface PublicIpAddress extends
Wrapper<PublicIPAddressInner>,
Updatable<PublicIpAddress.Update> {

/***********************************************************
* Getters
***********************************************************/
// Getters

/**
* @return the IP version of the public IP address
*/
IPVersion version();

/**
* @return the assigned IP address
Expand Down Expand Up @@ -59,6 +62,16 @@ public interface PublicIpAddress extends
*/
int idleTimeoutInMinutes();

/**
* @return the load balancer frontend that this public IP address is assigned to
*/
Frontend getAssignedLoadBalancerFrontend();

/**
* @return true if this public IP address is assigned to a load balancer frontend
*/
boolean hasAssignedLoadBalancerFrontend();

/**************************************************************
* Fluent interfaces for builder pattern
**************************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
package com.microsoft.azure.management.network.implementation;

import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import com.microsoft.azure.CloudException;
import com.microsoft.azure.SubResource;
import com.microsoft.azure.management.network.Backend;
import com.microsoft.azure.management.network.LoadBalancer;
import com.microsoft.azure.management.network.LoadBalancingRule;
import com.microsoft.azure.management.network.NetworkInterface;
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;
import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.ChildResourceImpl;

Expand Down Expand Up @@ -70,6 +74,30 @@ public String name() {
return this.inner().name();
}

@Override
public Set<String> getVirtualMachineIds() {
Set<String> vmIds = new HashSet<>();
Map<String, String> nicConfigs = this.backendNicIpConfigurationNames();
if (nicConfigs != null) {
for (String nicId : nicConfigs.keySet()) {
try {
NetworkInterface nic = this.parent().manager().networkInterfaces().getById(nicId);
if (nic == null || nic.virtualMachineId() == null) {
continue;
} else {
vmIds.add(nic.virtualMachineId());
}
} catch (CloudException | IllegalArgumentException e) {
continue;
}
}
}

return vmIds;
}

// Verbs

@Override
public LoadBalancerImpl attach() {
this.parent().withBackend(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class InboundNatPoolImpl
extends ChildResourceImpl<InboundNatPoolInner, LoadBalancerImpl>
implements
InboundNatPool,
InboundNatPool.Definition<LoadBalancer.DefinitionStages.WithCreate>,
InboundNatPool.Definition<LoadBalancer.DefinitionStages.WithCreateAndInboundNatPool>,
InboundNatPool.UpdateDefinition<LoadBalancer.Update>,
InboundNatPool.Update {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class InboundNatRuleImpl
extends ChildResourceImpl<InboundNatRuleInner, LoadBalancerImpl>
implements
InboundNatRule,
InboundNatRule.Definition<LoadBalancer.DefinitionStages.WithCreate>,
InboundNatRule.Definition<LoadBalancer.DefinitionStages.WithCreateAndInboundNatRule>,
InboundNatRule.UpdateDefinition<LoadBalancer.Update>,
InboundNatRule.Update {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@ public NetworkInterfaceImpl withInternalDnsNameLabel(String dnsNameLabel) {

// Getters

@Override
public String virtualMachineId() {
if (this.inner().virtualMachine() != null) {
return this.inner().virtualMachine().id();
} else {
return null;
}
}

@Override
public boolean isIpForwardingEnabled() {
return Utils.toPrimitiveBoolean(this.inner().enableIPForwarding());
Expand Down Expand Up @@ -320,7 +329,7 @@ public String networkSecurityGroupId() {
}

@Override
public NetworkSecurityGroup networkSecurityGroup() {
public NetworkSecurityGroup getNetworkSecurityGroup() {
if (this.networkSecurityGroup == null && this.networkSecurityGroupId() != null) {
String id = this.networkSecurityGroupId();
this.networkSecurityGroup = super.myManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@

import com.microsoft.azure.management.apigeneration.LangDefinition;
import com.microsoft.azure.management.network.IPAllocationMethod;
import com.microsoft.azure.management.network.IPVersion;
import com.microsoft.azure.management.network.LoadBalancer;
import com.microsoft.azure.management.network.PublicFrontend;
import com.microsoft.azure.management.network.PublicIPAddressDnsSettings;
import com.microsoft.azure.management.network.PublicIpAddress;
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;
import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl;
import rx.Observable;

Expand Down Expand Up @@ -106,14 +110,27 @@ public IPAllocationMethod ipAllocationMethod() {
return this.inner().publicIPAllocationMethod();
}

@Override
public IPVersion version() {
return this.inner().publicIPAddressVersion();
}

@Override
public String fqdn() {
return this.inner().dnsSettings().fqdn();
if (this.inner().dnsSettings() != null) {
return this.inner().dnsSettings().fqdn();
} else {
return null;
}
}

@Override
public String reverseFqdn() {
return this.inner().dnsSettings().reverseFqdn();
if (this.inner().dnsSettings() != null) {
return this.inner().dnsSettings().reverseFqdn();
} else {
return null;
}
}

@Override
Expand Down Expand Up @@ -146,4 +163,28 @@ public Observable<PublicIpAddress> createResourceAsync() {
return this.client.createOrUpdateAsync(this.resourceGroupName(), this.name(), this.inner())
.map(innerToFluentMap(this));
}
}

@Override
public PublicFrontend getAssignedLoadBalancerFrontend() {
if (this.hasAssignedLoadBalancerFrontend()) {
final String refId = this.inner().ipConfiguration().id();
final String loadBalancerId = ResourceUtils.parentResourcePathFromResourceId(refId);
final LoadBalancer lb = this.myManager.loadBalancers().getById(loadBalancerId);
final String frontendName = ResourceUtils.nameFromResourceId(refId);
return (PublicFrontend) lb.frontends().get(frontendName);
} else {
return null;
}
}

@Override
public boolean hasAssignedLoadBalancerFrontend() {
if (this.inner().ipConfiguration() == null) {
return false;
} else {
final String refId = this.inner().ipConfiguration().id();
final String resourceType = ResourceUtils.resourceTypeFromResourceId(refId);
return resourceType.equalsIgnoreCase("frontendIPConfigurations");
}
}
}
Loading

0 comments on commit 94d8785

Please sign in to comment.