Skip to content

Commit ecd1ac2

Browse files
yadvrMurali Reddy
authored andcommitted
CLOUDSTACK-70: Improve Network Restart Behaviour for Basic Zone: Restarting Network Fails
If cleanup=true, removes all VRs and creates VR, implements network. If cleanup=false, skips running VRs, implements network for stopped/deleted VRs. Signed-off-by: Rohit Yadav <rohit.yadav@citrix.com>
1 parent 5a9d7a7 commit ecd1ac2

6 files changed

Lines changed: 75 additions & 26 deletions

File tree

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

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import com.cloud.dc.DataCenter;
6969
import com.cloud.dc.DataCenter.NetworkType;
7070
import com.cloud.dc.DataCenterVO;
71+
import com.cloud.dc.HostPodVO;
7172
import com.cloud.dc.Pod;
7273
import com.cloud.dc.PodVlanMapVO;
7374
import com.cloud.dc.Vlan;
@@ -77,6 +78,7 @@
7778
import com.cloud.dc.dao.DataCenterDao;
7879
import com.cloud.dc.dao.PodVlanMapDao;
7980
import com.cloud.dc.dao.VlanDao;
81+
import com.cloud.dc.dao.HostPodDao;
8082
import com.cloud.deploy.DataCenterDeployment;
8183
import com.cloud.deploy.DeployDestination;
8284
import com.cloud.deploy.DeploymentPlan;
@@ -202,6 +204,7 @@
202204
import com.cloud.utils.exception.CloudRuntimeException;
203205
import com.cloud.utils.net.Ip;
204206
import com.cloud.utils.net.NetUtils;
207+
import com.cloud.vm.DomainRouterVO;
205208
import com.cloud.vm.Nic;
206209
import com.cloud.vm.NicProfile;
207210
import com.cloud.vm.NicVO;
@@ -232,6 +235,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
232235
@Inject
233236
DataCenterDao _dcDao = null;
234237
@Inject
238+
HostPodDao _podDao = null;
239+
@Inject
235240
VlanDao _vlanDao = null;
236241
@Inject
237242
IPAddressDao _ipAddressDao = null;
@@ -240,6 +245,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
240245
@Inject
241246
DomainDao _domainDao = null;
242247
@Inject
248+
DomainRouterDao _domainRouterDao = null;
249+
@Inject
243250
UserStatisticsDao _userStatsDao = null;
244251
@Inject
245252
EventDao _eventDao = null;
@@ -3807,12 +3814,6 @@ public boolean restartNetwork(RestartNetworkCmd cmd, boolean cleanup) throws Con
38073814
throw new InvalidParameterValueException("Network is not in the right state to be restarted. Correct states are: " + Network.State.Implemented + ", " + Network.State.Setup);
38083815
}
38093816

3810-
// don't allow clenaup=true for the network in Basic zone
3811-
DataCenter zone = _configMgr.getZone(network.getDataCenterId());
3812-
if (zone.getNetworkType() == NetworkType.Basic && cleanup) {
3813-
throw new InvalidParameterValueException("Cleanup can't be true when restart network in Basic zone");
3814-
}
3815-
38163817
_accountMgr.checkAccess(callerAccount, null, true, network);
38173818

38183819
boolean success = restartNetwork(networkId, callerAccount, callerUser, cleanup);
@@ -3857,10 +3858,6 @@ private boolean restartNetwork(long networkId, Account callerAccount, User calle
38573858
ReservationContext context = new ReservationContextImpl(null, null, callerUser, callerAccount);
38583859

38593860
if (cleanup) {
3860-
if (network.getGuestType() != GuestType.Isolated) {
3861-
s_logger.warn("Only support clean up network for isolated network!");
3862-
return false;
3863-
}
38643861
// shutdown the network
38653862
s_logger.debug("Shutting down the network id=" + networkId + " as a part of network restart");
38663863

@@ -3873,14 +3870,43 @@ private boolean restartNetwork(long networkId, Account callerAccount, User calle
38733870
s_logger.debug("Skip the shutting down of network id=" + networkId);
38743871
}
38753872

3876-
// implement the network elements and rules again
3877-
DeployDestination dest = new DeployDestination(_dcDao.findById(network.getDataCenterId()), null, null, null);
3878-
38793873
s_logger.debug("Implementing the network " + network + " elements and resources as a part of network restart");
38803874
NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
38813875

38823876
try {
3883-
implementNetworkElementsAndResources(dest, context, network, offering);
3877+
DataCenter dc = _dcDao.findById(network.getDataCenterId());
3878+
//Pod based network restart for basic network, one VR per pod
3879+
if (dc.getNetworkType() == NetworkType.Basic) {
3880+
//Loop through all pods with running user vms and restart network
3881+
for (HostPodVO pod: _podDao.listByDataCenterId(dc.getId())) {
3882+
s_logger.debug("Trying to restart network for Pod: " + pod.getName() + ", id=" + pod.getId());
3883+
//If cleanup is false, don't implement network on running VRs
3884+
List<DomainRouterVO> virtualRouters = _domainRouterDao.listByPodId(pod.getId());
3885+
Boolean podHasSingleVR = (virtualRouters.size() == 1);
3886+
if (!podHasSingleVR) {
3887+
s_logger.warn("Pod should have only one VR in Basic Zone, please check!");
3888+
}
3889+
if (!cleanup && virtualRouters != null && podHasSingleVR
3890+
&& virtualRouters.get(0).getState() == VirtualMachine.State.Running) {
3891+
s_logger.debug("Cleanup=false: Found a running VR, skipping network implementation for the pod");
3892+
continue;
3893+
}
3894+
//Implement network only if there are running user vms in 'pod'
3895+
List<VMInstanceVO> vms = _vmDao.listByPodId(pod.getId());
3896+
for (VMInstanceVO vm: vms) {
3897+
// implement the network elements and rules again
3898+
if (vm.getType() == Type.User && vm.getState() == VirtualMachine.State.Running) {
3899+
DeployDestination dest = new DeployDestination(dc, pod, null, null);
3900+
implementNetworkElementsAndResources(dest, context, network, offering);
3901+
break;
3902+
}
3903+
}
3904+
}
3905+
} else {
3906+
// implement the network elements and rules again
3907+
DeployDestination dest = new DeployDestination(dc, null, null, null);
3908+
implementNetworkElementsAndResources(dest, context, network, offering);
3909+
}
38843910
setRestartRequired(network, true);
38853911
} catch (Exception ex) {
38863912
s_logger.warn("Failed to implement network " + network + " elements and resources as a part of network restart due to ", ex);

server/src/com/cloud/vm/dao/DomainRouterDao.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,14 @@ public interface DomainRouterDao extends GenericDao<DomainRouterVO, Long> {
6161
*/
6262
public List<DomainRouterVO> listByHostId(Long hostId);
6363
public List<DomainRouterVO> listByLastHostId(Long hostId);
64-
64+
65+
/**
66+
* virtual machine routers.
67+
* @param podId id of the pod. null if to get all.
68+
* @return list of DomainRouterVO
69+
*/
70+
public List<DomainRouterVO> listByPodId(Long podId);
71+
6572
/**
6673
* list virtual machine routers by host id.
6774
* pass in null to get all

server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ public List<DomainRouterVO> listByHostId(Long hostId) {
177177
return listBy(sc);
178178
}
179179

180+
@Override
181+
public List<DomainRouterVO> listByPodId(Long podId) {
182+
SearchCriteria<DomainRouterVO> sc = AllFieldsSearch.create();
183+
sc.setParameters("podId", podId);
184+
return listBy(sc);
185+
}
186+
180187
@Override
181188
public List<DomainRouterVO> listIsolatedByHostId(Long hostId) {
182189
SearchCriteria<DomainRouterVO> sc = HostUpSearch.create();

server/src/com/cloud/vm/dao/VMInstanceDao.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ public interface VMInstanceDao extends GenericDao<VMInstanceVO, Long>, StateDao<
4646
* @return list of VMInstanceVO in the specified zone
4747
*/
4848
List<VMInstanceVO> listByZoneId(long zoneId);
49-
49+
50+
/**
51+
* List VMs by pod ID
52+
* @param podId
53+
* @return list of VMInstanceVO in the specified pod
54+
*/
55+
List<VMInstanceVO> listByPodId(long podId);
56+
5057
/**
5158
* Lists non-expunged VMs by zone ID and templateId
5259
* @param zoneId

server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ protected VMInstanceDaoImpl() {
127127
AllFieldsSearch.and("lastHost", AllFieldsSearch.entity().getLastHostId(), Op.EQ);
128128
AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ);
129129
AllFieldsSearch.and("zone", AllFieldsSearch.entity().getDataCenterIdToDeployIn(), Op.EQ);
130+
AllFieldsSearch.and("pod", AllFieldsSearch.entity().getPodIdToDeployIn(), Op.EQ);
130131
AllFieldsSearch.and("type", AllFieldsSearch.entity().getType(), Op.EQ);
131132
AllFieldsSearch.and("account", AllFieldsSearch.entity().getAccountId(), Op.EQ);
132133
AllFieldsSearch.done();
@@ -230,7 +231,14 @@ public List<VMInstanceVO> listByZoneId(long zoneId) {
230231

231232
return listBy(sc);
232233
}
233-
234+
235+
@Override
236+
public List<VMInstanceVO> listByPodId(long podId) {
237+
SearchCriteria<VMInstanceVO> sc = AllFieldsSearch.create();
238+
sc.setParameters("pod", podId);
239+
return listBy(sc);
240+
}
241+
234242
@Override
235243
public List<VMInstanceVO> listByClusterId(long clusterId) {
236244
SearchCriteria<VMInstanceVO> sc = VMClusterSearch.create();

ui/scripts/network.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -604,15 +604,9 @@
604604
success: function(json){
605605
zoneObj = json.listzonesresponse.zone[0];
606606
}
607-
});
608-
if(zoneObj.networktype == "Basic") {
609-
args.$form.find('.form-item[rel=cleanup]').find('input').removeAttr('checked'); //unchecked
610-
args.$form.find('.form-item[rel=cleanup]').hide(); //hidden
611-
}
612-
else {
613-
args.$form.find('.form-item[rel=cleanup]').find('input').attr('checked', 'checked'); //checked
614-
args.$form.find('.form-item[rel=cleanup]').css('display', 'inline-block'); //shown
615-
}
607+
});
608+
args.$form.find('.form-item[rel=cleanup]').find('input').attr('checked', 'checked'); //checked
609+
args.$form.find('.form-item[rel=cleanup]').css('display', 'inline-block'); //shown
616610
},
617611
fields: {
618612
cleanup: {

0 commit comments

Comments
 (0)