Skip to content

Commit

Permalink
Merge pull request Azure#1123 from martinsawicki/compute-2017-03-netw…
Browse files Browse the repository at this point in the history
…ork-2017-08-regen

moving GatewayUse enum outside NetworkPeering
  • Loading branch information
Martin Sawicki authored Sep 12, 2017
2 parents 59d0022 + 9f9d7db commit a08b092
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,6 @@ public interface NetworkPeering extends
Refreshable<NetworkPeering>,
Updatable<NetworkPeering.Update> {

/**
* Possible gateway use scenarios.
*/
enum GatewayUse {
/**
* The remote network is allowed to use this network's gateway (but not necessarily using it currently).
*/
BY_REMOTE_NETWORK,

/**
* This network is configured to use the remote network's gateway.
*/
ON_REMOTE_NETWORK,

/**
* No gateway use is configured.
*/
NONE
}

/**
* @return the local virtual network's ID
*/
Expand Down Expand Up @@ -95,7 +75,7 @@ enum GatewayUse {
/**
* @return the type of gateway use enabled for this network
*/
GatewayUse gatewayUse();
NetworkPeeringGatewayUse gatewayUse();

/**
* @return true if traffic forwarding from the remote network is allowed into this network
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
package com.microsoft.azure.management.network;

/**
* Possible gateway use scenarios.
*/
public enum NetworkPeeringGatewayUse {
/**
* The remote network is allowed to use this network's gateway (but not necessarily using it currently).
*/
BY_REMOTE_NETWORK,

/**
* This network is configured to use the remote network's gateway.
*/
ON_REMOTE_NETWORK,

/**
* No gateway use is configured.
*/
NONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.microsoft.azure.SubResource;
import com.microsoft.azure.management.apigeneration.LangDefinition;
import com.microsoft.azure.management.network.NetworkPeeringGatewayUse;
import com.microsoft.azure.management.network.Network;
import com.microsoft.azure.management.network.NetworkPeering;
import com.microsoft.azure.management.network.NetworkPeering.DefinitionStages.WithCreate;
Expand Down Expand Up @@ -319,11 +320,11 @@ public Observable<Indexable> call(NetworkPeering remotePeering) {
// Update gateway use permission on the remote peering if needed
if (localPeering.allowGatewayUseOnRemoteNetwork == null) {
// No change, so ignore
} else if (localPeering.allowGatewayUseOnRemoteNetwork.booleanValue() && remotePeering.gatewayUse() != GatewayUse.BY_REMOTE_NETWORK) {
} else if (localPeering.allowGatewayUseOnRemoteNetwork.booleanValue() && remotePeering.gatewayUse() != NetworkPeeringGatewayUse.BY_REMOTE_NETWORK) {
// Allow gateway use on remote network
isUpdateNeeded = true;
remotePeeringUpdate.withGatewayUseByRemoteNetworkAllowed();
} else if (!localPeering.allowGatewayUseOnRemoteNetwork.booleanValue() && remotePeering.gatewayUse() == GatewayUse.BY_REMOTE_NETWORK) {
} else if (!localPeering.allowGatewayUseOnRemoteNetwork.booleanValue() && remotePeering.gatewayUse() == NetworkPeeringGatewayUse.BY_REMOTE_NETWORK) {
// Disallow gateway use on remote network
isUpdateNeeded = true;
remotePeeringUpdate.withoutGatewayUseByRemoteNetwork();
Expand All @@ -332,10 +333,10 @@ public Observable<Indexable> call(NetworkPeering remotePeering) {
// Update gateway use start on the remote peering if needed
if (localPeering.startGatewayUseByRemoteNetwork == null) {
// No change, so ignore
} else if (localPeering.startGatewayUseByRemoteNetwork.booleanValue() && remotePeering.gatewayUse() != GatewayUse.ON_REMOTE_NETWORK) {
} else if (localPeering.startGatewayUseByRemoteNetwork.booleanValue() && remotePeering.gatewayUse() != NetworkPeeringGatewayUse.ON_REMOTE_NETWORK) {
remotePeeringUpdate.withGatewayUseOnRemoteNetworkStarted();
isUpdateNeeded = true;
} else if (!localPeering.startGatewayUseByRemoteNetwork.booleanValue() && remotePeering.gatewayUse() == GatewayUse.ON_REMOTE_NETWORK) {
} else if (!localPeering.startGatewayUseByRemoteNetwork.booleanValue() && remotePeering.gatewayUse() == NetworkPeeringGatewayUse.ON_REMOTE_NETWORK) {
remotePeeringUpdate.withoutGatewayUseOnRemoteNetwork();
isUpdateNeeded = true;
}
Expand Down Expand Up @@ -443,7 +444,7 @@ public Observable<Network> getRemoteNetworkAsync() {
final NetworkPeeringImpl self = this;
if (self.remoteNetwork != null) {
return Observable.just(self.remoteNetwork);
} else if (ResourceUtils.subscriptionFromResourceId(this.remoteNetworkId()).equalsIgnoreCase(ResourceUtils.subscriptionFromResourceId(this.id()))) {
} else if (this.isSameSubscription()) {
// Fetch the remote network if within the same subscription
return this.manager().networks().getByIdAsync(this.remoteNetworkId())
.doOnNext(new Action1<Network>() {
Expand Down Expand Up @@ -482,13 +483,13 @@ public Observable<NetworkPeering> call(Network remoteNetwork) {
}

@Override
public GatewayUse gatewayUse() {
public NetworkPeeringGatewayUse gatewayUse() {
if (Utils.toPrimitiveBoolean(this.inner().allowGatewayTransit())) {
return GatewayUse.BY_REMOTE_NETWORK;
return NetworkPeeringGatewayUse.BY_REMOTE_NETWORK;
} else if (Utils.toPrimitiveBoolean(this.inner().useRemoteGateways())) {
return GatewayUse.ON_REMOTE_NETWORK;
return NetworkPeeringGatewayUse.ON_REMOTE_NETWORK;
} else {
return GatewayUse.NONE;
return NetworkPeeringGatewayUse.NONE;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

import org.junit.Assert;

import com.microsoft.azure.management.network.NetworkPeeringGatewayUse;
import com.microsoft.azure.management.network.Network;
import com.microsoft.azure.management.network.NetworkPeering;
import com.microsoft.azure.management.network.NetworkSecurityGroup;
import com.microsoft.azure.management.network.Networks;
import com.microsoft.azure.management.network.RouteTable;
import com.microsoft.azure.management.network.Subnet;
import com.microsoft.azure.management.network.VirtualNetworkPeeringState;
import com.microsoft.azure.management.network.NetworkPeering.GatewayUse;
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;

Expand Down Expand Up @@ -174,7 +174,7 @@ public Network createResource(Networks networks) throws Exception {
Assert.assertEquals(VirtualNetworkPeeringState.CONNECTED, localPeering.state());
Assert.assertTrue(localPeering.isTrafficForwardingFromRemoteNetworkAllowed());
// TODO Assert.assertFalse(localPeering.isAccessFromRemoteNetworkAllowed());
Assert.assertEquals(GatewayUse.BY_REMOTE_NETWORK, localPeering.gatewayUse());
Assert.assertEquals(NetworkPeeringGatewayUse.BY_REMOTE_NETWORK, localPeering.gatewayUse());

// Verify remote peering
Assert.assertNotNull(remoteNetwork.peerings());
Expand All @@ -185,7 +185,7 @@ public Network createResource(Networks networks) throws Exception {
Assert.assertEquals(VirtualNetworkPeeringState.CONNECTED, remotePeering.state());
Assert.assertTrue(remotePeering.isTrafficForwardingFromRemoteNetworkAllowed());
// TODO Assert.assertFalse(remotePeering.isAccessFromRemoteNetworkAllowed());
Assert.assertEquals(GatewayUse.NONE, remotePeering.gatewayUse());
Assert.assertEquals(NetworkPeeringGatewayUse.NONE, remotePeering.gatewayUse());

return localNetwork;
}
Expand Down Expand Up @@ -214,14 +214,14 @@ public Network updateResource(Network resource) throws Exception {
// Verify local peering changes
Assert.assertFalse(localPeering.isTrafficForwardingFromRemoteNetworkAllowed());
// TODO Assert.assertTrue(localPeering.isAccessFromRemoteNetworkAllowed());
Assert.assertEquals(GatewayUse.NONE, localPeering.gatewayUse());
Assert.assertEquals(NetworkPeeringGatewayUse.NONE, localPeering.gatewayUse());

// Verify remote peering changes
NetworkPeering remotePeering = localPeering.getRemotePeering();
Assert.assertNotNull(remotePeering);
Assert.assertFalse(remotePeering.isTrafficForwardingFromRemoteNetworkAllowed());
// TODO Assert.assertTrue(remotePeering.isAccessFromRemoteNetworkAllowed());
Assert.assertEquals(GatewayUse.NONE, remotePeering.gatewayUse());
Assert.assertEquals(NetworkPeeringGatewayUse.NONE, remotePeering.gatewayUse());

// Delete the peering
resource.peerings().deleteById(remotePeering.id());
Expand Down

0 comments on commit a08b092

Please sign in to comment.