Skip to content

Commit b3ff533

Browse files
committed
bug 8795: start domR after corresponding network is shutdown - implement network before starting the domR
status 8795: resolved fixed Conflicts: api/src/com/cloud/deploy/DeployDestination.java
1 parent e772bfa commit b3ff533

5 files changed

Lines changed: 71 additions & 7 deletions

File tree

api/src/com/cloud/deploy/DeployDestination.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,33 @@ public boolean equals(Object obj) {
8989

9090
@Override
9191
public String toString() {
92+
93+
Long dcId = null;
94+
Long podId = null;
95+
Long clusterId = null;
96+
Long hostId = null;
97+
98+
if (_dc != null) {
99+
dcId = _dc.getId();
100+
}
101+
102+
if (_pod != null) {
103+
podId = _pod.getId();
104+
}
105+
106+
if (_cluster != null) {
107+
clusterId = _cluster.getId();
108+
}
109+
110+
if (_host != null) {
111+
hostId = _host.getId();
112+
}
113+
92114
StringBuilder destination = new StringBuilder("Dest[Zone(Id)-Pod(Id)-Cluster(Id)-Host(Id)-Storage(Volume(Id|Type-->Pool(Id))] : Dest[");
93-
destination.append("Zone(").append(_dc.getId()).append(")").append("-");
94-
destination.append("Pod(").append(_pod.getId()).append(")").append("-");
95-
destination.append("Cluster(").append(_cluster.getId()).append(")").append("-");
96-
destination.append("Host(").append(_host.getId()).append(")").append("-");
115+
destination.append("Zone(").append(dcId).append(")").append("-");
116+
destination.append("Pod(").append(podId).append(")").append("-");
117+
destination.append("Cluster(").append(clusterId).append(")").append("-");
118+
destination.append("Host(").append(hostId).append(")").append("-");
97119
destination.append("Storage(");
98120
if(_storage != null){
99121
String storageStr = "";

api/src/com/cloud/network/NetworkService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.cloud.api.commands.DisassociateIPAddrCmd;
2626
import com.cloud.api.commands.ListNetworksCmd;
2727
import com.cloud.api.commands.RestartNetworkCmd;
28+
import com.cloud.deploy.DeployDestination;
2829
import com.cloud.exception.ConcurrentOperationException;
2930
import com.cloud.exception.InsufficientAddressCapacityException;
3031
import com.cloud.exception.InsufficientCapacityException;
@@ -35,6 +36,7 @@
3536
import com.cloud.network.Network.Capability;
3637
import com.cloud.network.Network.Service;
3738
import com.cloud.offering.NetworkOffering;
39+
import com.cloud.vm.ReservationContext;
3840

3941

4042
public interface NetworkService {

server/src/com/cloud/network/NetworkManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.List;
2121
import java.util.Map;
2222

23-
import com.cloud.api.commands.RestartNetworkCmd;
2423
import com.cloud.dc.Vlan;
2524
import com.cloud.dc.Vlan.VlanType;
2625
import com.cloud.deploy.DeployDestination;
@@ -182,4 +181,6 @@ boolean associateIpAddressListToAccount(long userId, long accountId, long zoneId
182181

183182
Network getNetworkWithSecurityGroupEnabled(Long zoneId);
184183

184+
boolean startNetwork(long networkId, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
185+
185186
}

server/src/com/cloud/network/NetworkManagerImpl.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,8 +2141,6 @@ public boolean restartNetwork(RestartNetworkCmd cmd) throws ConcurrentOperationE
21412141
User caller = _accountMgr.getActiveUser(UserContext.current().getCallerUserId());
21422142
Account callerAccount = _accountMgr.getActiveAccount(caller.getAccountId());
21432143

2144-
2145-
21462144
//Check if network exists
21472145
NetworkVO network = _networksDao.findById(networkId);
21482146
if (network == null) {
@@ -2173,6 +2171,26 @@ public boolean restartNetwork(RestartNetworkCmd cmd) throws ConcurrentOperationE
21732171
return success;
21742172
}
21752173

2174+
@Override
2175+
public boolean startNetwork(long networkId, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
2176+
2177+
//Check if network exists
2178+
NetworkVO network = _networksDao.findById(networkId);
2179+
if (network == null) {
2180+
throw new InvalidParameterValueException("Network with id=" + networkId + " doesn't exist");
2181+
}
2182+
2183+
//implement the network
2184+
s_logger.debug("Starting network " + network + "...");
2185+
Pair<NetworkGuru, NetworkVO> implementedNetwork = implementNetwork(networkId, dest, context);
2186+
if (implementedNetwork.first() == null) {
2187+
s_logger.warn("Failed to start the network " + network);
2188+
return false;
2189+
} else {
2190+
return true;
2191+
}
2192+
}
2193+
21762194
private boolean restartNetwork(long networkId, boolean restartElements, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
21772195
boolean success = true;
21782196

server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import com.cloud.configuration.dao.ResourceLimitDao;
6868
import com.cloud.dc.DataCenter;
6969
import com.cloud.dc.DataCenter.NetworkType;
70+
import com.cloud.dc.HostPodVO;
7071
import com.cloud.dc.dao.AccountVlanMapDao;
7172
import com.cloud.dc.dao.DataCenterDao;
7273
import com.cloud.dc.dao.HostPodDao;
@@ -155,6 +156,7 @@
155156
import com.cloud.vm.NicProfile;
156157
import com.cloud.vm.NicVO;
157158
import com.cloud.vm.ReservationContext;
159+
import com.cloud.vm.ReservationContextImpl;
158160
import com.cloud.vm.UserVmVO;
159161
import com.cloud.vm.VMInstanceVO;
160162
import com.cloud.vm.VirtualMachine;
@@ -1322,13 +1324,32 @@ public DomainRouterVO findByName(String name) {
13221324
@Override
13231325
public VirtualRouter startRouter(long routerId, boolean restartNetwork) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException {
13241326
Account account = UserContext.current().getCaller();
1327+
User caller = _accountMgr.getActiveUser(UserContext.current().getCallerUserId());
13251328

13261329
// verify parameters
13271330
DomainRouterVO router = _routerDao.findById(routerId);
13281331
if (router == null) {
13291332
throw new InvalidParameterValueException("Unable to find router by id " + routerId + ".");
13301333
}
13311334
_accountMgr.checkAccess(account, router);
1335+
1336+
Account owner = _accountMgr.getAccount(router.getAccountId());
1337+
1338+
//Check if all networks are implemented for the domR; if not - implement them
1339+
DataCenter dc = _dcDao.findById(router.getDataCenterId());
1340+
HostPodVO pod = _podDao.findById(router.getPodId());
1341+
DeployDestination dest = new DeployDestination(dc, pod, null, null);
1342+
1343+
ReservationContext context = new ReservationContextImpl(null, null, caller, owner);
1344+
1345+
List<NicVO> nics = _nicDao.listByVmId(routerId);
1346+
1347+
for (NicVO nic : nics) {
1348+
if (!_networkMgr.startNetwork(nic.getNetworkId(), dest, context)) {
1349+
s_logger.warn("Failed to start network id=" + nic.getNetworkId() + " as a part of domR start");
1350+
throw new CloudRuntimeException("Failed to start network id=" + nic.getNetworkId() + " as a part of domR start");
1351+
}
1352+
}
13321353

13331354
UserVO user = _userDao.findById(UserContext.current().getCallerUserId());
13341355
Map<Param, Object> params = new HashMap<Param, Object>();

0 commit comments

Comments
 (0)