Skip to content

Commit

Permalink
Trying to fit both isolated and shared network life cycle with single…
Browse files Browse the repository at this point in the history
… state

machine may need addtional work. So set network state for shared network explicitly now.
  • Loading branch information
Murali Reddy committed Apr 10, 2013
1 parent 365ed73 commit 77c6991
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions server/src/com/cloud/network/NetworkManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,11 @@ public Pair<NetworkGuru, NetworkVO> implementNetwork(long networkId, DeployDesti
NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId());

network.setReservationId(context.getReservationId());
stateTransitTo(network, Event.ImplementNetwork);
if (isSharedNetworkWithServices(network)) {
network.setState(Network.State.Implementing);
} else {
stateTransitTo(network, Event.ImplementNetwork);
}

Network result = guru.implement(network, offering, dest, context);
network.setCidr(result.getCidr());
Expand All @@ -1437,7 +1441,11 @@ public Pair<NetworkGuru, NetworkVO> implementNetwork(long networkId, DeployDesti
// implement network elements and re-apply all the network rules
implementNetworkElementsAndResources(dest, context, network, offering);

stateTransitTo(network,Event.OperationSucceeded);
if (isSharedNetworkWithServices(network)) {
network.setState(Network.State.Implemented);
} else {
stateTransitTo(network,Event.OperationSucceeded);
}

network.setRestartRequired(false);
_networksDao.update(network.getId(), network);
Expand All @@ -1450,7 +1458,12 @@ public Pair<NetworkGuru, NetworkVO> implementNetwork(long networkId, DeployDesti
if (implemented.first() == null) {
s_logger.debug("Cleaning up because we're unable to implement the network " + network);
try {
stateTransitTo(network,Event.OperationFailed);
if (isSharedNetworkWithServices(network)) {
network.setState(Network.State.Shutdown);
_networksDao.update(networkId, network);
} else {
stateTransitTo(network,Event.OperationFailed);
}
} catch (NoTransitionException e) {
s_logger.error(e.getMessage());
}
Expand Down Expand Up @@ -2086,6 +2099,7 @@ public Network createGuestNetwork(long networkOfferingId, String name, String di
@DB
public boolean shutdownNetwork(long networkId, ReservationContext context, boolean cleanupElements) {
boolean result = false;
Transaction txn = Transaction.currentTxn();

NetworkVO network = _networksDao.lockRow(networkId, true);
if (network == null) {
Expand All @@ -2096,16 +2110,23 @@ public boolean shutdownNetwork(long networkId, ReservationContext context, boole
s_logger.debug("Network is not implemented: " + network);
return false;
}
try {
stateTransitTo(network, Event.DestroyNetwork);
} catch (NoTransitionException e) {

txn.start();
if (isSharedNetworkWithServices(network)) {
network.setState(Network.State.Shutdown);
_networksDao.update(network.getId(), network);
} else {
try {
stateTransitTo(network, Event.DestroyNetwork);
} catch (NoTransitionException e) {
network.setState(Network.State.Shutdown);
_networksDao.update(network.getId(), network);
}
}
txn.commit();

boolean success = shutdownNetworkElementsAndResources(context, cleanupElements, network);

Transaction txn = Transaction.currentTxn();
txn.start();
if (success) {
if (s_logger.isDebugEnabled()) {
Expand Down Expand Up @@ -2741,6 +2762,17 @@ public UserDataServiceProvider getSSHKeyResetProvider(Network network) {
return (UserDataServiceProvider)_networkModel.getElementImplementingProvider(SSHKeyProvider);
}

protected boolean isSharedNetworkWithServices(Network network) {
assert(network != null);
DataCenter zone = _configMgr.getZone(network.getDataCenterId());
if (network.getGuestType() == Network.GuestType.Shared &&
zone.getNetworkType() == NetworkType.Advanced &&
isSharedNetworkOfferingWithServices(network.getNetworkOfferingId())) {
return true;
}
return false;
}

protected boolean isSharedNetworkOfferingWithServices(long networkOfferingId) {
NetworkOfferingVO networkOffering = _networkOfferingDao.findById(networkOfferingId);
if ( (networkOffering.getGuestType() == Network.GuestType.Shared) && (
Expand Down

0 comments on commit 77c6991

Please sign in to comment.