use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.
the class AdvancedNetworkVisitor method visit.
@Override
public boolean visit(final NicPlugInOutRules nicPlugInOutRules) throws ResourceUnavailableException {
final VirtualRouter router = nicPlugInOutRules.getRouter();
final Commands commands = nicPlugInOutRules.getNetUsageCommands();
if (commands.size() > 0) {
return _networkGeneralHelper.sendCommandsToRouter(router, commands);
}
return true;
}
use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.
the class AdvancedNetworkVisitor method visit.
@Override
public boolean visit(final StaticRoutesRules staticRoutesRules) throws ResourceUnavailableException {
final VirtualRouter router = staticRoutesRules.getRouter();
final Commands cmds = new Commands(Command.OnError.Continue);
final NetworkOverviewTO networkOverview = _commandSetupHelper.createNetworkOverviewFromRouter(router, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), null, null, null);
final UpdateNetworkOverviewCommand updateNetworkOverviewCommand = _commandSetupHelper.createUpdateNetworkOverviewCommand(router, networkOverview);
cmds.addCommand(updateNetworkOverviewCommand);
return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
}
use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.
the class BasicNetworkTopology method applyRules.
@Override
public boolean applyRules(final Network network, final VirtualRouter router, final String typeString, final boolean isPodLevelException, final Long podId, final boolean failWhenDisconnect, final RuleApplierWrapper<RuleApplier> ruleApplierWrapper) throws ResourceUnavailableException {
if (router == null) {
s_logger.warn("Unable to apply " + typeString + ", virtual router doesn't exist in the network " + network.getId());
throw new ResourceUnavailableException("Unable to apply " + typeString, DataCenter.class, network.getDataCenterId());
}
final RuleApplier ruleApplier = ruleApplierWrapper.getRuleType();
final DataCenter dc = _dcDao.findById(network.getDataCenterId());
final boolean isZoneBasic = dc.getNetworkType() == NetworkType.Basic;
// isPodLevelException and podId is only used for basic zone
assert !(!isZoneBasic && isPodLevelException || isZoneBasic && isPodLevelException && podId == null);
final List<VirtualRouter> connectedRouters = new ArrayList<>();
final List<VirtualRouter> disconnectedRouters = new ArrayList<>();
boolean result = true;
final String msg = "Unable to apply " + typeString + " on disconnected router ";
if (router.getState() == State.Running) {
s_logger.debug("Applying " + typeString + " in network " + network);
if (router.isStopPending()) {
if (_hostDao.findById(router.getHostId()).getState() == HostStatus.Up) {
throw new ResourceUnavailableException("Unable to process due to the stop pending router " + router.getInstanceName() + " haven't been stopped after it's host coming back!", DataCenter.class, router.getDataCenterId());
}
s_logger.debug("Router " + router.getInstanceName() + " is stop pending, so not sending apply " + typeString + " commands to the backend");
return false;
}
try {
result = ruleApplier.accept(getVisitor(), router);
connectedRouters.add(router);
} catch (final AgentUnavailableException e) {
s_logger.warn(msg + router.getInstanceName(), e);
disconnectedRouters.add(router);
}
// disconnection, no need to proceed with the rest
if (!result) {
if (isZoneBasic && isPodLevelException) {
throw new ResourceUnavailableException("Unable to apply " + typeString + " on router ", Pod.class, podId);
}
throw new ResourceUnavailableException("Unable to apply " + typeString + " on router ", DataCenter.class, router.getDataCenterId());
}
} else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending apply " + typeString + " commands to the backend");
} else {
s_logger.warn("Unable to apply " + typeString + ", virtual router is not in the right state " + router.getState());
if (isZoneBasic && isPodLevelException) {
throw new ResourceUnavailableException("Unable to apply " + typeString + ", virtual router is not in the right state", Pod.class, podId);
}
throw new ResourceUnavailableException("Unable to apply " + typeString + ", virtual router is not in the right state", DataCenter.class, router.getDataCenterId());
}
if (!connectedRouters.isEmpty()) {
// Shouldn't we include this check inside the method?
if (!isZoneBasic && !disconnectedRouters.isEmpty()) {
// now, stop them for synchronization
for (final VirtualRouter virtualRouter : disconnectedRouters) {
// If we have at least 1 disconnected redundant router, callhandleSingleWorkingRedundantRouter().
if (virtualRouter.getIsRedundantRouter()) {
_networkHelper.handleSingleWorkingRedundantRouter(connectedRouters, disconnectedRouters, msg);
break;
}
}
}
} else if (!disconnectedRouters.isEmpty()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(msg + router.getInstanceName() + "(" + router.getId() + ")");
}
if (isZoneBasic && isPodLevelException) {
throw new ResourceUnavailableException(msg, Pod.class, podId);
}
throw new ResourceUnavailableException(msg, DataCenter.class, disconnectedRouters.get(0).getDataCenterId());
}
result = true;
if (failWhenDisconnect) {
result = !connectedRouters.isEmpty();
}
return result;
}
use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.
the class BasicNetworkVisitor method visit.
@Override
public boolean visit(final UserdataPwdRules userdata) throws ResourceUnavailableException {
final VirtualRouter router = userdata.getRouter();
final Commands commands = new Commands(Command.OnError.Stop);
final VirtualMachineProfile profile = userdata.getProfile();
final NicVO nicVO = userdata.getNicVo();
final DeployDestination destination = userdata.getDestination();
if (router.getPodIdToDeployIn() == destination.getPod().getId()) {
_commandSetupHelper.createPasswordCommand(router, profile, nicVO, commands);
final VMOverviewTO vmOverview = _commandSetupHelper.createVmOverviewFromRouter(router);
final UpdateVmOverviewCommand updateVmOverviewCommand = _commandSetupHelper.createUpdateVmOverviewCommand(router, vmOverview);
commands.addCommand(updateVmOverviewCommand);
return _networkGeneralHelper.sendCommandsToRouter(router, commands);
}
return true;
}
use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.
the class VpcVirtualRouterElement method destroy.
@Override
public boolean destroy(final Network config, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
final Long vpcId = config.getVpcId();
if (vpcId == null) {
s_logger.debug("Network " + config + " doesn't belong to any vpc, so skipping unplug nic part");
return true;
}
boolean success = true;
final List<? extends VirtualRouter> routers = _routerDao.listByVpcId(vpcId);
for (final VirtualRouter router : routers) {
// 1) Check if router is already a part of the network
if (!_networkMdl.isVmPartOfNetwork(router.getId(), config.getId())) {
s_logger.debug("Router " + router + " is not a part the network " + config);
continue;
}
// 2) Call unplugNics in the network service
success = success && _vpcRouterMgr.removeVpcRouterFromGuestNetwork(router, config);
if (!success) {
s_logger.warn("Failed to unplug nic in network " + config + " for virtual router " + router);
} else {
s_logger.debug("Successfully unplugged nic in network " + config + " for virtual router " + router);
}
}
return success;
}
Aggregations