use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class VirtualNetworkApplianceManagerImpl method processConnect.
@Override
public void processConnect(final Host host, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
final List<DomainRouterVO> routers = _routerDao.listIsolatedByHostId(host.getId());
for (DomainRouterVO router : routers) {
if (router.isStopPending()) {
s_logger.info("Stopping router " + router.getInstanceName() + " due to stop pending flag found!");
final VirtualMachine.State state = router.getState();
if (state != VirtualMachine.State.Stopped && state != VirtualMachine.State.Destroyed) {
try {
stopRouter(router.getId(), false);
} catch (final ResourceUnavailableException e) {
s_logger.warn("Fail to stop router " + router.getInstanceName(), e);
throw new ConnectionException(false, "Fail to stop router " + router.getInstanceName());
} catch (final ConcurrentOperationException e) {
s_logger.warn("Fail to stop router " + router.getInstanceName(), e);
throw new ConnectionException(false, "Fail to stop router " + router.getInstanceName());
}
}
router.setStopPending(false);
router = _routerDao.persist(router);
}
}
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class VirtualNetworkApplianceManagerImpl method recoverRedundantNetwork.
// Ensure router status is update to date before execute this function. The
// function would try best to recover all routers except PRIMARY
protected void recoverRedundantNetwork(final DomainRouterVO primaryRouter, final DomainRouterVO backupRouter) {
if (primaryRouter.getState() == VirtualMachine.State.Running && backupRouter.getState() == VirtualMachine.State.Running) {
final HostVO primaryHost = _hostDao.findById(primaryRouter.getHostId());
final HostVO backupHost = _hostDao.findById(backupRouter.getHostId());
if (primaryHost.getState() == Status.Up && backupHost.getState() == Status.Up) {
final String title = "Reboot " + backupRouter.getInstanceName() + " to ensure redundant virtual routers work";
if (s_logger.isDebugEnabled()) {
s_logger.debug(title);
}
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, backupRouter.getDataCenterId(), backupRouter.getPodIdToDeployIn(), title, title);
try {
rebootRouter(backupRouter.getId(), true, false);
} catch (final ConcurrentOperationException e) {
s_logger.warn("Fail to reboot " + backupRouter.getInstanceName(), e);
} catch (final ResourceUnavailableException e) {
s_logger.warn("Fail to reboot " + backupRouter.getInstanceName(), e);
} catch (final InsufficientCapacityException e) {
s_logger.warn("Fail to reboot " + backupRouter.getInstanceName(), e);
}
}
}
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class VirtualNetworkApplianceManagerImpl method finalizeStop.
@Override
public void finalizeStop(final VirtualMachineProfile profile, final Answer answer) {
if (answer != null) {
final VirtualMachine vm = profile.getVirtualMachine();
final DomainRouterVO domR = _routerDao.findById(vm.getId());
processStopOrRebootAnswer(domR, answer);
final List<? extends Nic> routerNics = _nicDao.listByVmId(profile.getId());
for (final Nic nic : routerNics) {
final Network network = _networkModel.getNetwork(nic.getNetworkId());
final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
if (network.getTrafficType() == TrafficType.Guest && nic.getBroadcastUri() != null && nic.getBroadcastUri().getScheme().equals("pvlan")) {
final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic");
final NetworkTopology networkTopology = _networkTopologyContext.retrieveNetworkTopology(dcVO);
try {
networkTopology.setupDhcpForPvlan(false, domR, domR.getHostId(), nicProfile);
} catch (final ResourceUnavailableException e) {
s_logger.debug("ERROR in finalizeStop: ", e);
}
}
}
}
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class VirtualNetworkApplianceManagerImpl method startRemoteAccessVpn.
@Override
public boolean startRemoteAccessVpn(final Network network, final RemoteAccessVpn vpn, final List<? extends VirtualRouter> routers) throws ResourceUnavailableException {
if (routers == null || routers.isEmpty()) {
s_logger.warn("Failed to start remote access VPN: no router found for account and zone");
throw new ResourceUnavailableException("Failed to start remote access VPN: no router found for account and zone", DataCenter.class, network.getDataCenterId());
}
for (final VirtualRouter router : routers) {
if (router.getState() != VirtualMachine.State.Running) {
s_logger.warn("Failed to start remote access VPN: router not in right state " + router.getState());
throw new ResourceUnavailableException("Failed to start remote access VPN: router not in right state " + router.getState(), DataCenter.class, network.getDataCenterId());
}
final Commands cmds = new Commands(Command.OnError.Stop);
_commandSetupHelper.createApplyVpnCommands(true, vpn, router, cmds);
if (!_nwHelper.sendCommandsToRouter(router, cmds)) {
throw new AgentUnavailableException("Unable to send commands to virtual router ", router.getHostId());
}
Answer answer = cmds.getAnswer("users");
if (answer == null) {
s_logger.error("Unable to start vpn: unable add users to vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to null answer");
throw new ResourceUnavailableException("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to null answer", DataCenter.class, router.getDataCenterId());
}
if (!answer.getResult()) {
s_logger.error("Unable to start vpn: unable add users to vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails());
throw new ResourceUnavailableException("Unable to start vpn: Unable to add users to vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
}
answer = cmds.getAnswer("startVpn");
if (!answer.getResult()) {
s_logger.error("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails());
throw new ResourceUnavailableException("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
}
}
return true;
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class NetworkHelperImpl method handleSingleWorkingRedundantRouter.
@Override
public void handleSingleWorkingRedundantRouter(final List<? extends VirtualRouter> connectedRouters, final List<? extends VirtualRouter> disconnectedRouters, final String reason) throws ResourceUnavailableException {
if (connectedRouters.isEmpty() || disconnectedRouters.isEmpty()) {
return;
}
for (final VirtualRouter virtualRouter : connectedRouters) {
if (!virtualRouter.getIsRedundantRouter()) {
throw new ResourceUnavailableException("Who is calling this with non-redundant router or non-domain router?", DataCenter.class, virtualRouter.getDataCenterId());
}
}
for (final VirtualRouter virtualRouter : disconnectedRouters) {
if (!virtualRouter.getIsRedundantRouter()) {
throw new ResourceUnavailableException("Who is calling this with non-redundant router or non-domain router?", DataCenter.class, virtualRouter.getDataCenterId());
}
}
final DomainRouterVO connectedRouter = (DomainRouterVO) connectedRouters.get(0);
DomainRouterVO disconnectedRouter = (DomainRouterVO) disconnectedRouters.get(0);
if (s_logger.isDebugEnabled()) {
s_logger.debug("About to stop the router " + disconnectedRouter.getInstanceName() + " due to: " + reason);
}
final String title = "Virtual router " + disconnectedRouter.getInstanceName() + " would be stopped after connecting back, due to " + reason;
final String context = "Virtual router (name: " + disconnectedRouter.getInstanceName() + ", id: " + disconnectedRouter.getId() + ") would be stopped after connecting back, due to: " + reason;
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, disconnectedRouter.getDataCenterId(), disconnectedRouter.getPodIdToDeployIn(), title, context);
disconnectedRouter.setStopPending(true);
disconnectedRouter = _routerDao.persist(disconnectedRouter);
}
Aggregations