com.microsoft.azure.management.network.implementation.RouteTableImpl Maven / Gradle / Ivy
/**
* 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.implementation;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import com.microsoft.azure.management.apigeneration.LangDefinition;
import com.microsoft.azure.management.network.Route;
import com.microsoft.azure.management.network.RouteNextHopType;
import com.microsoft.azure.management.network.RouteTable;
import com.microsoft.azure.management.network.Subnet;
import com.microsoft.azure.management.network.model.GroupableParentResourceWithTagsImpl;
import com.microsoft.azure.management.resources.fluentcore.utils.Utils;
import rx.Observable;
import rx.functions.Func1;
/**
* Implementation for RouteTable.
*/
@LangDefinition
class RouteTableImpl
extends GroupableParentResourceWithTagsImpl<
RouteTable,
RouteTableInner,
RouteTableImpl,
NetworkManager>
implements
RouteTable,
RouteTable.Definition,
RouteTable.Update {
private Map routes;
RouteTableImpl(String name,
final RouteTableInner innerModel,
final NetworkManager networkManager) {
super(name, innerModel, networkManager);
}
@Override
protected Observable applyTagsToInnerAsync() {
return this.manager().inner().routeTables().updateTagsAsync(resourceGroupName(), name(), inner().getTags());
}
@Override
protected void initializeChildrenFromInner() {
this.routes = new TreeMap<>();
List inners = this.inner().routes();
if (inners != null) {
for (RouteInner inner : inners) {
RouteImpl route = new RouteImpl(inner, this);
this.routes.put(inner.name(), route);
}
}
}
// Getters
// Verbs
@Override
public Observable refreshAsync() {
return super.refreshAsync().map(new Func1() {
@Override
public RouteTable call(RouteTable routeTable) {
RouteTableImpl impl = (RouteTableImpl) routeTable;
impl.initializeChildrenFromInner();
return impl;
}
});
}
@Override
protected Observable getInnerAsync() {
return this.manager().inner().routeTables().getByResourceGroupAsync(this.resourceGroupName(), this.name());
}
@Override
public List listAssociatedSubnets() {
return this.myManager.listAssociatedSubnets(this.inner().subnets());
}
// Setters (fluent)
@Override
public RouteImpl defineRoute(String name) {
RouteInner inner = new RouteInner()
.withName(name);
return new RouteImpl(inner, this);
}
@Override
public RouteImpl updateRoute(String name) {
return (RouteImpl) this.routes.get(name);
}
@Override
public Update withoutRoute(String name) {
this.routes.remove(name);
return this;
}
@Override
public RouteTableImpl withRoute(String destinationAddressPrefix, RouteNextHopType nextHop) {
return this.defineRoute("route_" + this.name() + System.currentTimeMillis())
.withDestinationAddressPrefix(destinationAddressPrefix)
.withNextHop(nextHop)
.attach();
}
@Override
public RouteTableImpl withRouteViaVirtualAppliance(String destinationAddressPrefix, String ipAddress) {
return this.defineRoute("route_" + this.name() + System.currentTimeMillis())
.withDestinationAddressPrefix(destinationAddressPrefix)
.withNextHopToVirtualAppliance(ipAddress)
.attach();
}
RouteTableImpl withRoute(RouteImpl route) {
this.routes.put(route.name(), route);
return this;
}
// Helpers
@Override
protected void beforeCreating() {
// Reset and update routes
this.inner().withRoutes(innersFromWrappers(this.routes.values()));
}
@Override
protected void afterCreating() {
initializeChildrenFromInner();
}
@Override
protected Observable createInner() {
return this.manager().inner().routeTables().createOrUpdateAsync(this.resourceGroupName(), this.name(), this.inner());
}
@Override
public Map routes() {
return Collections.unmodifiableMap(this.routes);
}
@Override
public boolean isBgpRoutePropagationDisabled() {
return Utils.toPrimitiveBoolean(inner().disableBgpRoutePropagation());
}
@Override
public RouteTableImpl withDisableBgpRoutePropagation() {
inner().withDisableBgpRoutePropagation(true);
return this;
}
@Override
public RouteTableImpl withEnableBgpRoutePropagation() {
inner().withDisableBgpRoutePropagation(false);
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy