Skip to content

Commit c3ee3d6

Browse files
bvbharatbvbharatk
authored andcommitted
CLOUDSTACK-9726 Update state is not changed to UPDATE_FAILED in case when Host is put in Maintenance Mode.
1 parent cd68e99 commit c3ee3d6

File tree

6 files changed

+64
-22
lines changed

6 files changed

+64
-22
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;
@@ -2252,20 +2250,11 @@ public Network updateGuestNetwork(final long networkId, String name, String disp
22522250
int resourceCount=1;
22532251
if(updateInSequence && restartNetwork && _networkOfferingDao.findById(network.getNetworkOfferingId()).getRedundantRouter()
22542252
&& (networkOfferingId==null || _networkOfferingDao.findById(networkOfferingId).getRedundantRouter()) && network.getVpcId()==null) {
2255-
_networkMgr.canUpdateInSequence(network);
2253+
_networkMgr.canUpdateInSequence(network, forced);
22562254
NetworkDetailVO networkDetail =new NetworkDetailVO(network.getId(),Network.updatingInSequence,"true",true);
22572255
_networkDetailsDao.persist(networkDetail);
22582256
_networkMgr.configureUpdateInSequence(network);
22592257
resourceCount=_networkMgr.getResourceCount(network);
2260-
//check if routers are in correct state before proceeding with the update
2261-
List<DomainRouterVO> routers=_routerDao.listByNetworkAndRole(networkId, VirtualRouter.Role.VIRTUAL_ROUTER);
2262-
for(DomainRouterVO router :routers){
2263-
if(router.getRedundantState()== VirtualRouter.RedundantState.UNKNOWN){
2264-
if(!forced){
2265-
throw new CloudRuntimeException("Domain router: "+router.getInstanceName()+" is in unknown state, Cannot update network. set parameter forced to true for forcing an update");
2266-
}
2267-
}
2268-
}
22692258
}
22702259
List<String > servicesNotInNewOffering = null;
22712260
if(networkOfferingId != null)
@@ -2413,7 +2402,9 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
24132402
resourceCount--;
24142403
} while(updateInSequence && resourceCount>0);
24152404
}catch (Exception exception){
2416-
throw new CloudRuntimeException("failed to update network "+network.getUuid()+"due to "+exception.getMessage());
2405+
if(updateInSequence)
2406+
_networkMgr.finalizeUpdateInSequence(network,false);
2407+
throw new CloudRuntimeException("failed to update network "+network.getUuid()+" due to "+exception.getMessage());
24172408
}finally {
24182409
if(updateInSequence){
24192410
if( _networkDetailsDao.findDetail(networkId,Network.updatingInSequence)!=null){

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

Lines changed: 24 additions & 6 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;
@@ -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

0 commit comments

Comments
 (0)