Skip to content

Commit 83b93d2

Browse files
authored
Merge pull request #1971 from bvbharatk/CLOUDSTACK-9726
CLOUDSTACK-9726 Update state is not changed to UPDATE_FAILED in case …
2 parents 7434d91 + 422787e commit 83b93d2

File tree

7 files changed

+69
-23
lines changed

7 files changed

+69
-23
lines changed

api/src/com/cloud/network/element/RedundantResource.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@
2424
public interface RedundantResource {
2525
public void configureResource(Network network);
2626
public int getResourceCount(Network network);
27+
public void finalize(Network network, boolean success);
2728
}

engine/api/src/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void implementNetworkElementsAndResources(DeployDestination dest, ReservationCon
227227

228228
void prepareAllNicsForMigration(VirtualMachineProfile vm, DeployDestination dest);
229229

230-
boolean canUpdateInSequence(Network network);
230+
boolean canUpdateInSequence(Network network, boolean forced);
231231

232232
List<String> getServicesNotSupportedInNewOffering(Network network, long newNetworkOfferingId);
233233

@@ -236,4 +236,6 @@ void implementNetworkElementsAndResources(DeployDestination dest, ReservationCon
236236
void configureUpdateInSequence(Network network);
237237

238238
int getResourceCount(Network network);
239+
240+
void finalizeUpdateInSequence(Network network, boolean success);
239241
}

engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import com.cloud.network.dao.RemoteAccessVpnVO;
4141
import com.cloud.network.dao.VpnUserDao;
4242
import com.cloud.network.element.RedundantResource;
43+
import com.cloud.network.router.VirtualRouter;
44+
import com.cloud.vm.DomainRouterVO;
4345
import com.cloud.vm.dao.DomainRouterDao;
4446
import org.apache.log4j.Logger;
4547
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
@@ -1298,14 +1300,23 @@ protected boolean prepareElement(final NetworkElement element, final Network net
12981300
}
12991301

13001302
@Override
1301-
public boolean canUpdateInSequence(Network network){
1303+
public boolean canUpdateInSequence(Network network, boolean forced){
13021304
List<Provider> providers = getNetworkProviders(network.getId());
13031305

13041306
//check if the there are no service provider other than virtualrouter.
13051307
for(Provider provider :providers){
13061308
if(provider!=Provider.VirtualRouter)
13071309
throw new UnsupportedOperationException("Cannot update the network resources in sequence when providers other than virtualrouter are used");
13081310
}
1311+
//check if routers are in correct state before proceeding with the update
1312+
List<DomainRouterVO> routers=_rotuerDao.listByNetworkAndRole(network.getId(), VirtualRouter.Role.VIRTUAL_ROUTER);
1313+
for(DomainRouterVO router :routers){
1314+
if(router.getRedundantState()== VirtualRouter.RedundantState.UNKNOWN){
1315+
if(!forced){
1316+
throw new CloudRuntimeException("Domain router: "+router.getInstanceName()+" is in unknown state, Cannot update network. set parameter forced to true for forcing an update");
1317+
}
1318+
}
1319+
}
13091320
return true;
13101321
}
13111322

@@ -1442,6 +1453,20 @@ public int getResourceCount(Network network){
14421453
return resourceCount;
14431454
}
14441455

1456+
@Override
1457+
public void finalizeUpdateInSequence(Network network, boolean success) {
1458+
List<Provider> providers = getNetworkProviders(network.getId());
1459+
for (NetworkElement element : networkElements) {
1460+
if (providers.contains(element.getProvider())) {
1461+
//currently only one element implements the redundant resource interface
1462+
if (element instanceof RedundantResource) {
1463+
((RedundantResource) element).finalize(network,success);
1464+
break;
1465+
}
1466+
}
1467+
}
1468+
}
1469+
14451470

14461471
@DB
14471472
protected void updateNic(final NicVO nic, final long networkId, final int count) {

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import javax.inject.Inject;
4040
import javax.naming.ConfigurationException;
4141

42-
import com.cloud.network.router.VirtualRouter;
4342
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
4443
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
4544
import org.apache.cloudstack.api.ApiConstants;
@@ -181,7 +180,6 @@
181180
import com.cloud.utils.exception.CloudRuntimeException;
182181
import com.cloud.utils.exception.ExceptionUtil;
183182
import com.cloud.utils.net.NetUtils;
184-
import com.cloud.vm.DomainRouterVO;
185183
import com.cloud.vm.Nic;
186184
import com.cloud.vm.NicSecondaryIp;
187185
import com.cloud.vm.NicVO;
@@ -2256,20 +2254,11 @@ public Network updateGuestNetwork(final long networkId, String name, String disp
22562254
int resourceCount=1;
22572255
if(updateInSequence && restartNetwork && _networkOfferingDao.findById(network.getNetworkOfferingId()).getRedundantRouter()
22582256
&& (networkOfferingId==null || _networkOfferingDao.findById(networkOfferingId).getRedundantRouter()) && network.getVpcId()==null) {
2259-
_networkMgr.canUpdateInSequence(network);
2257+
_networkMgr.canUpdateInSequence(network, forced);
22602258
NetworkDetailVO networkDetail =new NetworkDetailVO(network.getId(),Network.updatingInSequence,"true",true);
22612259
_networkDetailsDao.persist(networkDetail);
22622260
_networkMgr.configureUpdateInSequence(network);
22632261
resourceCount=_networkMgr.getResourceCount(network);
2264-
//check if routers are in correct state before proceeding with the update
2265-
List<DomainRouterVO> routers=_routerDao.listByNetworkAndRole(networkId, VirtualRouter.Role.VIRTUAL_ROUTER);
2266-
for(DomainRouterVO router :routers){
2267-
if(router.getRedundantState()== VirtualRouter.RedundantState.UNKNOWN){
2268-
if(!forced){
2269-
throw new CloudRuntimeException("Domain router: "+router.getInstanceName()+" is in unknown state, Cannot update network. set parameter forced to true for forcing an update");
2270-
}
2271-
}
2272-
}
22732262
}
22742263
List<String > servicesNotInNewOffering = null;
22752264
if(networkOfferingId != null)
@@ -2417,7 +2406,9 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
24172406
resourceCount--;
24182407
} while(updateInSequence && resourceCount>0);
24192408
}catch (Exception exception){
2420-
throw new CloudRuntimeException("failed to update network "+network.getUuid()+"due to "+exception.getMessage());
2409+
if(updateInSequence)
2410+
_networkMgr.finalizeUpdateInSequence(network,false);
2411+
throw new CloudRuntimeException("failed to update network "+network.getUuid()+" due to "+exception.getMessage());
24212412
}finally {
24222413
if(updateInSequence){
24232414
if( _networkDetailsDao.findDetail(networkId,Network.updatingInSequence)!=null){

server/src/com/cloud/network/element/VirtualRouterElement.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,13 @@ public boolean implement(final Network network, final NetworkOffering offering,
226226
routerCounts = 2;
227227
}
228228
if (routers == null || routers.size() < routerCounts) {
229-
throw new ResourceUnavailableException("Can't find all necessary running routers!", DataCenter.class, network.getDataCenterId());
229+
//we might have a router which is already deployed and running.
230+
//so check the no of routers in network currently.
231+
List<DomainRouterVO> current_routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
232+
if (current_routers.size() < 2) {
233+
updateToFailedState(network);
234+
throw new ResourceUnavailableException("Can't find all necessary running routers!", DataCenter.class, network.getDataCenterId());
235+
}
230236
}
231237

232238
return true;
@@ -724,7 +730,7 @@ public List<DomainRouterVO> getRouters(Network network){
724730

725731
@Override
726732
public boolean shutdown(final Network network, final ReservationContext context, final boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException {
727-
final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
733+
final List<DomainRouterVO> routers = getRouters(network);
728734
if (routers == null || routers.isEmpty()) {
729735
return true;
730736
}
@@ -1339,11 +1345,7 @@ public boolean completeAggregatedExecution(final Network network, final DeployDe
13391345
} finally {
13401346
if(!result && updateInSequence) {
13411347
//fail the network update. even if one router fails we fail the network update.
1342-
List<DomainRouterVO> routerList = _routerDao.listByNetworkAndRole(network.getId(), VirtualRouter.Role.VIRTUAL_ROUTER);
1343-
for (DomainRouterVO router : routerList) {
1344-
router.setUpdateState(VirtualRouter.UpdateState.UPDATE_FAILED);
1345-
_routerDao.persist(router);
1346-
}
1348+
updateToFailedState(network);
13471349
}
13481350
}
13491351
return result;
@@ -1373,4 +1375,20 @@ public int getResourceCount(Network network) {
13731375
return _routerDao.listByNetworkAndRole(network.getId(), VirtualRouter.Role.VIRTUAL_ROUTER).size();
13741376
}
13751377

1378+
@Override
1379+
public void finalize(Network network, boolean success) {
1380+
if(!success){
1381+
updateToFailedState(network);
1382+
}
1383+
}
1384+
1385+
private void updateToFailedState(Network network){
1386+
//fail the network update. even if one router fails we fail the network update.
1387+
List<DomainRouterVO> routerList = _routerDao.listByNetworkAndRole(network.getId(), VirtualRouter.Role.VIRTUAL_ROUTER);
1388+
for (DomainRouterVO router : routerList) {
1389+
router.setUpdateState(VirtualRouter.UpdateState.UPDATE_FAILED);
1390+
_routerDao.persist(router);
1391+
}
1392+
}
1393+
13761394
}

server/test/com/cloud/vpc/MockNetworkManagerImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ public void prepareAllNicsForMigration(VirtualMachineProfile vm, DeployDestinati
848848
}
849849

850850
@Override
851-
public boolean canUpdateInSequence(Network network) {
851+
public boolean canUpdateInSequence(Network network, boolean forced) {
852852
return false;
853853
}
854854

@@ -872,6 +872,11 @@ public int getResourceCount(Network network) {
872872
return 0;
873873
}
874874

875+
@Override
876+
public void finalizeUpdateInSequence(Network network, boolean success) {
877+
return;
878+
}
879+
875880
@Override
876881
public void prepareNicForMigration(VirtualMachineProfile vm, DeployDestination dest) {
877882
// TODO Auto-generated method stub

test/integration/component/maint/test_redundant_router.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def setUpClass(cls):
146146
cls.zone.id,
147147
cls.testdata["ostype"]
148148
)
149+
149150
cls.testdata["small"]["zoneid"] = cls.zone.id
150151
cls.testdata["small"]["template"] = cls.template.id
151152

@@ -1546,6 +1547,8 @@ def get_master_and_backupRouter(self):
15461547
listall=True
15471548
)
15481549
retry = retry-1
1550+
if len(routers) < 2:
1551+
continue
15491552
if not (routers[0].redundantstate == 'MASTER' or routers[1].redundantstate == 'MASTER'):
15501553
continue;
15511554
if routers[0].redundantstate == 'MASTER':
@@ -1556,6 +1559,7 @@ def get_master_and_backupRouter(self):
15561559
master_router = routers[1]
15571560
backup_router = routers[0]
15581561
break
1562+
self.info("master_router: %s, backup_router: %s" % (master_router, backup_router))
15591563
return master_router, backup_router
15601564

15611565

0 commit comments

Comments
 (0)