Skip to content

Commit e08cb11

Browse files
fixing check style issues
Conflicts: server/src/com/cloud/network/element/VpcVirtualRouterElement.java server/src/com/cloud/network/rules/AdvancedVpnRules.java server/src/com/cloud/network/rules/RuleApplier.java server/src/com/cloud/network/rules/VirtualNetworkApplianceFactory.java server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java server/src/org/apache/cloudstack/network/topology/AdvancedNetworkVisitor.java server/src/org/apache/cloudstack/network/topology/BasicNetworkTopology.java server/src/org/apache/cloudstack/network/topology/BasicNetworkVisitor.java server/src/org/apache/cloudstack/network/topology/NetworkTopology.java
1 parent 01edc8e commit e08cb11

9 files changed

Lines changed: 192 additions & 133 deletions

File tree

‎server/src/com/cloud/network/element/VpcVirtualRouterElement.java‎

Lines changed: 37 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@
7272
import com.cloud.vm.VirtualMachine;
7373
import com.cloud.vm.VirtualMachineProfile;
7474

75-
@Local(value = {NetworkElement.class, FirewallServiceProvider.class, DhcpServiceProvider.class, UserDataServiceProvider.class, StaticNatServiceProvider.class,
75+
@Local(value = { NetworkElement.class, FirewallServiceProvider.class, DhcpServiceProvider.class, UserDataServiceProvider.class, StaticNatServiceProvider.class,
7676
LoadBalancingServiceProvider.class, PortForwardingServiceProvider.class, IpDeployer.class, VpcProvider.class, Site2SiteVpnServiceProvider.class,
77-
NetworkACLServiceProvider.class})
77+
NetworkACLServiceProvider.class })
7878
public class VpcVirtualRouterElement extends VirtualRouterElement implements VpcProvider, Site2SiteVpnServiceProvider, NetworkACLServiceProvider {
7979
private static final Logger s_logger = Logger.getLogger(VpcVirtualRouterElement.class);
8080
@Inject
@@ -133,18 +133,13 @@ protected boolean canHandle(final Network network, final Service service) {
133133

134134
@Override
135135
public boolean implementVpc(final Vpc vpc, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException,
136-
InsufficientCapacityException {
136+
InsufficientCapacityException {
137137

138138
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
139139
params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
140140

141-
RouterDeploymentDefinition routerDeploymentDefinition =
142-
routerDeploymentDefinitionBuilder.create()
143-
.setVpc(vpc)
144-
.setDeployDestination(dest)
145-
.setAccountOwner(_accountMgr.getAccount(vpc.getAccountId()))
146-
.setParams(params)
147-
.build();
141+
RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create().setVpc(vpc).setDeployDestination(dest)
142+
.setAccountOwner(_accountMgr.getAccount(vpc.getAccountId())).setParams(params).build();
148143

149144
routerDeploymentDefinition.deployVirtualRouter();
150145

@@ -165,8 +160,8 @@ public boolean shutdownVpc(final Vpc vpc, final ReservationContext context) thro
165160
}
166161

167162
@Override
168-
public boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws ResourceUnavailableException,
169-
ConcurrentOperationException, InsufficientCapacityException {
163+
public boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context)
164+
throws ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
170165

171166
Long vpcId = network.getVpcId();
172167
if (vpcId == null) {
@@ -183,13 +178,8 @@ public boolean implement(final Network network, final NetworkOffering offering,
183178
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
184179
params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
185180

186-
RouterDeploymentDefinition routerDeploymentDefinition =
187-
routerDeploymentDefinitionBuilder.create()
188-
.setVpc(vpc)
189-
.setDeployDestination(dest)
190-
.setAccountOwner(_accountMgr.getAccount(vpc.getAccountId()))
191-
.setParams(params)
192-
.build();
181+
RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create().setVpc(vpc).setDeployDestination(dest)
182+
.setAccountOwner(_accountMgr.getAccount(vpc.getAccountId())).setParams(params).build();
193183

194184
List<DomainRouterVO> routers = routerDeploymentDefinition.deployVirtualRouter();
195185

@@ -202,7 +192,7 @@ public boolean implement(final Network network, final NetworkOffering offering,
202192
}
203193

204194
DomainRouterVO router = routers.get(0);
205-
//Add router to guest network if needed
195+
// Add router to guest network if needed
206196
if (!_networkMdl.isVmPartOfNetwork(router.getId(), network.getId())) {
207197
Map<VirtualMachineProfile.Param, Object> paramsForRouter = new HashMap<VirtualMachineProfile.Param, Object>(1);
208198
if (network.getState() == State.Setup) {
@@ -238,13 +228,8 @@ public boolean prepare(final Network network, final NicProfile nic, final Virtua
238228
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
239229
params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
240230

241-
RouterDeploymentDefinition routerDeploymentDefinition =
242-
routerDeploymentDefinitionBuilder.create()
243-
.setVpc(vpc)
244-
.setDeployDestination(dest)
245-
.setAccountOwner(_accountMgr.getAccount(vpc.getAccountId()))
246-
.setParams(params)
247-
.build();
231+
RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create().setVpc(vpc).setDeployDestination(dest)
232+
.setAccountOwner(_accountMgr.getAccount(vpc.getAccountId())).setParams(params).build();
248233
List<DomainRouterVO> routers = routerDeploymentDefinition.deployVirtualRouter();
249234

250235
if (routers == null || routers.size() == 0) {
@@ -256,7 +241,7 @@ public boolean prepare(final Network network, final NicProfile nic, final Virtua
256241
}
257242

258243
DomainRouterVO router = routers.get(0);
259-
//Add router to guest network if needed
244+
// Add router to guest network if needed
260245
if (!_networkMdl.isVmPartOfNetwork(router.getId(), network.getId())) {
261246
Map<VirtualMachineProfile.Param, Object> paramsForRouter = new HashMap<VirtualMachineProfile.Param, Object>(1);
262247
// need to reprogram guest network if it comes in a setup state
@@ -285,12 +270,12 @@ public boolean shutdown(final Network network, final ReservationContext context,
285270

286271
List<? extends VirtualRouter> routers = _routerDao.listByVpcId(vpcId);
287272
for (VirtualRouter router : routers) {
288-
//1) Check if router is already a part of the network
273+
// 1) Check if router is already a part of the network
289274
if (!_networkMdl.isVmPartOfNetwork(router.getId(), network.getId())) {
290275
s_logger.debug("Router " + router + " is not a part the network " + network);
291276
continue;
292277
}
293-
//2) Call unplugNics in the network service
278+
// 2) Call unplugNics in the network service
294279
success = success && _vpcRouterMgr.removeVpcRouterFromGuestNetwork(router, network, false);
295280
if (!success) {
296281
s_logger.warn("Failed to unplug nic in network " + network + " for virtual router " + router);
@@ -313,12 +298,12 @@ public boolean destroy(final Network config, final ReservationContext context) t
313298

314299
List<? extends VirtualRouter> routers = _routerDao.listByVpcId(vpcId);
315300
for (VirtualRouter router : routers) {
316-
//1) Check if router is already a part of the network
301+
// 1) Check if router is already a part of the network
317302
if (!_networkMdl.isVmPartOfNetwork(router.getId(), config.getId())) {
318303
s_logger.debug("Router " + router + " is not a part the network " + config);
319304
continue;
320305
}
321-
//2) Call unplugNics in the network service
306+
// 2) Call unplugNics in the network service
322307
success = success && _vpcRouterMgr.removeVpcRouterFromGuestNetwork(router, config, false);
323308
if (!success) {
324309
s_logger.warn("Failed to unplug nic in network " + config + " for virtual router " + router);
@@ -349,10 +334,10 @@ private static Map<Service, Map<Capability, String>> setCapabilities() {
349334
vpnCapabilities.put(Capability.VpnTypes, "s2svpn");
350335
capabilities.put(Service.Vpn, vpnCapabilities);
351336

352-
//remove firewall capability
337+
// remove firewall capability
353338
capabilities.remove(Service.Firewall);
354339

355-
//add network ACL capability
340+
// add network ACL capability
356341
Map<Capability, String> networkACLCapabilities = new HashMap<Capability, String>();
357342
networkACLCapabilities.put(Capability.SupportedProtocols, "tcp,udp,icmp");
358343
capabilities.put(Service.NetworkACL, networkACLCapabilities);
@@ -374,8 +359,7 @@ public boolean createPrivateGateway(final PrivateGateway gateway) throws Concurr
374359

375360
List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(gateway.getVpcId());
376361
if (routers == null || routers.isEmpty()) {
377-
s_logger.debug(getName() + " element doesn't need to create Private gateway on the backend; VPC virtual " + "router doesn't exist in the vpc id=" +
378-
gateway.getVpcId());
362+
s_logger.debug(getName() + " element doesn't need to create Private gateway on the backend; VPC virtual " + "router doesn't exist in the vpc id=" + gateway.getVpcId());
379363
return true;
380364
}
381365

@@ -384,7 +368,7 @@ public boolean createPrivateGateway(final PrivateGateway gateway) throws Concurr
384368
}
385369

386370
VirtualRouter router = routers.get(0);
387-
371+
388372
DataCenterVO dcVO = _dcDao.findById(gateway.getZoneId());
389373
NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
390374

@@ -400,7 +384,7 @@ public boolean createPrivateGateway(final PrivateGateway gateway) throws Concurr
400384
return false;
401385
}
402386
} else {
403-
s_logger.debug ("Failed to setup private gateway "+ gateway);
387+
s_logger.debug("Failed to setup private gateway " + gateway);
404388
return false;
405389
}
406390
return true;
@@ -415,8 +399,7 @@ public boolean deletePrivateGateway(final PrivateGateway gateway) throws Concurr
415399

416400
List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(gateway.getVpcId());
417401
if (routers == null || routers.isEmpty()) {
418-
s_logger.debug(getName() + " element doesn't need to delete Private gateway on the backend; VPC virtual " + "router doesn't exist in the vpc id=" +
419-
gateway.getVpcId());
402+
s_logger.debug(getName() + " element doesn't need to delete Private gateway on the backend; VPC virtual " + "router doesn't exist in the vpc id=" + gateway.getVpcId());
420403
return true;
421404
}
422405

@@ -441,8 +424,8 @@ public boolean applyIps(final Network network, final List<? extends PublicIpAddr
441424
if (canHandle) {
442425
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
443426
if (routers == null || routers.isEmpty()) {
444-
s_logger.debug(getName() + " element doesn't need to associate ip addresses on the backend; VPC virtual " + "router doesn't exist in the network " +
445-
network.getId());
427+
s_logger.debug(getName() + " element doesn't need to associate ip addresses on the backend; VPC virtual " + "router doesn't exist in the network "
428+
+ network.getId());
446429
return true;
447430
}
448431

@@ -460,8 +443,7 @@ public boolean applyNetworkACLs(final Network network, final List<? extends Netw
460443
if (canHandle(network, Service.NetworkACL)) {
461444
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
462445
if (routers == null || routers.isEmpty()) {
463-
s_logger.debug("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual " + "router doesn't exist in the network " +
464-
network.getId());
446+
s_logger.debug("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual " + "router doesn't exist in the network " + network.getId());
465447
return true;
466448
}
467449

@@ -514,8 +496,7 @@ public boolean applyACLItemsToPrivateGw(final PrivateGateway gateway, final List
514496

515497
List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(gateway.getVpcId());
516498
if (routers == null || routers.isEmpty()) {
517-
s_logger.debug("Virtual router element doesn't need to apply network acl rules on the backend; virtual " + "router doesn't exist in the network " +
518-
network.getId());
499+
s_logger.debug("Virtual router element doesn't need to apply network acl rules on the backend; virtual " + "router doesn't exist in the network " + network.getId());
519500
return true;
520501
}
521502

@@ -549,8 +530,8 @@ public boolean startSite2SiteVpn(final Site2SiteVpnConnection conn) throws Resou
549530

550531
List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(ip.getVpcId());
551532
if (routers == null || routers.size() != 1) {
552-
throw new ResourceUnavailableException("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip.getVpcId(),
553-
DataCenter.class, vpc.getZoneId());
533+
throw new ResourceUnavailableException("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip.getVpcId(), DataCenter.class,
534+
vpc.getZoneId());
554535
}
555536

556537
return _vpcRouterMgr.startSite2SiteVpn(conn, routers.get(0));
@@ -576,8 +557,8 @@ public boolean stopSite2SiteVpn(final Site2SiteVpnConnection conn) throws Resour
576557

577558
List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(ip.getVpcId());
578559
if (routers == null || routers.size() != 1) {
579-
throw new ResourceUnavailableException("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip.getVpcId(),
580-
DataCenter.class, vpc.getZoneId());
560+
throw new ResourceUnavailableException("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip.getVpcId(), DataCenter.class,
561+
vpc.getZoneId());
581562
}
582563

583564
return _vpcRouterMgr.stopSite2SiteVpn(conn, routers.get(0));
@@ -594,7 +575,12 @@ public String[] applyVpnUsers(final RemoteAccessVpn vpn, final List<? extends Vp
594575
s_logger.debug("Cannot apply vpn users on the backend; virtual router doesn't exist in the network " + vpn.getVpcId());
595576
return null;
596577
}
597-
return _vpcRouterMgr.applyVpnUsers(vpn, users, routers.get(0));
578+
579+
Network network = _networkDao.findById(vpn.getNetworkId());
580+
DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
581+
NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
582+
583+
return networkTopology.applyVpnUsers(vpn, users, routers.get(0));
598584
}
599585

600586
@Override
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package com.cloud.network.rules;
19+
20+
import java.util.List;
21+
22+
import org.apache.cloudstack.network.topology.NetworkTopologyVisitor;
23+
import org.apache.log4j.Logger;
24+
25+
import com.cloud.dc.DataCenter;
26+
import com.cloud.exception.ResourceUnavailableException;
27+
import com.cloud.network.RemoteAccessVpn;
28+
import com.cloud.network.VpnUser;
29+
import com.cloud.network.router.VirtualRouter;
30+
import com.cloud.network.vpc.Vpc;
31+
import com.cloud.vm.VirtualMachine.State;
32+
33+
public class AdvancedVpnRules extends BasicVpnRules {
34+
35+
private static final Logger s_logger = Logger.getLogger(AdvancedVpnRules.class);
36+
37+
private final RemoteAccessVpn _remoteAccessVpn;
38+
39+
public AdvancedVpnRules(final RemoteAccessVpn remoteAccessVpn, final List<? extends VpnUser> users) {
40+
super(null, users);
41+
_remoteAccessVpn = remoteAccessVpn;
42+
}
43+
44+
@Override
45+
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
46+
_router = router;
47+
48+
Vpc vpc = _vpcDao.findById(_remoteAccessVpn.getVpcId());
49+
50+
if (router.getState() != State.Running) {
51+
s_logger.warn("Failed to add/remove Remote Access VPN users: router not in running state");
52+
throw new ResourceUnavailableException("Failed to add/remove Remote Access VPN users: router not in running state: " + router.getState(), DataCenter.class,
53+
vpc.getZoneId());
54+
}
55+
56+
return visitor.visit(this);
57+
}
58+
}

0 commit comments

Comments
 (0)