use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.
the class StopRouterCmd method execute.
@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
CallContext.current().setEventDetails("Router Id: " + getId());
VirtualRouter result = null;
final VirtualRouter router = _routerService.findRouter(getId());
if (router == null || router.getRole() != Role.VIRTUAL_ROUTER) {
throw new InvalidParameterValueException("Can't find router by id");
} else {
result = _routerService.stopRouter(getId(), isForced());
}
if (result != null) {
final DomainRouterResponse response = _responseGenerator.createDomainRouterResponse(result);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to stop router");
}
}
use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.
the class UpgradeRouterCmd method execute.
@Override
public void execute() {
final VirtualRouter router = _routerService.upgradeRouter(this);
if (router != null) {
final DomainRouterResponse routerResponse = _responseGenerator.createDomainRouterResponse(router);
routerResponse.setResponseName(getCommandName());
setResponseObject(routerResponse);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upgrade router");
}
}
use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.
the class StartRouterCmd method execute.
@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
CallContext.current().setEventDetails("Router Id: " + getId());
VirtualRouter result = null;
final VirtualRouter router = _routerService.findRouter(getId());
if (router == null || router.getRole() != Role.VIRTUAL_ROUTER) {
throw new InvalidParameterValueException("Can't find router by id");
} else {
result = _routerService.startRouter(getId());
}
if (result != null) {
final DomainRouterResponse routerResponse = _responseGenerator.createDomainRouterResponse(result);
routerResponse.setResponseName(getCommandName());
setResponseObject(routerResponse);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to start router");
}
}
use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.
the class UserVmDomRInvestigator method isVmAlive.
@Override
public boolean isVmAlive(final VirtualMachine vm, final Host host) throws UnknownVM {
if (vm.getType() != VirtualMachineType.User) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Not a User Vm, unable to determine state of " + vm + " returning null");
}
throw new UnknownVM();
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("testing if " + vm + " is alive");
}
// to verify that the VM is alive, we ask the domR (router) to ping the VM (private IP)
final UserVmVO userVm = _userVmDao.findById(vm.getId());
final List<? extends Nic> nics = _networkMgr.getNicsForTraffic(userVm.getId(), TrafficType.Guest);
for (final Nic nic : nics) {
if (nic.getIPv4Address() == null) {
continue;
}
final List<VirtualRouter> routers = _vnaMgr.getRoutersForNetwork(nic.getNetworkId());
if (routers == null || routers.isEmpty()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to find a router in network " + nic.getNetworkId() + " to ping " + vm);
}
continue;
}
Boolean result = null;
for (final VirtualRouter router : routers) {
result = testUserVM(vm, nic, router);
if (result != null) {
break;
}
}
if (result == null) {
continue;
}
return result;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Returning null since we're unable to determine state of " + vm);
}
throw new UnknownVM();
}
use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.
the class NetworkHelperImplTest method testSendCommandsToRouterWithTrueResult.
/**
* The only way result can be true is if each and every command receive a true result
*
* @throws AgentUnavailableException
* @throws OperationTimedoutException
*/
@Test
public void testSendCommandsToRouterWithTrueResult() throws AgentUnavailableException, OperationTimedoutException, ResourceUnavailableException {
// Prepare
final NetworkHelperImpl nwHelperUT = spy(this.nwHelper);
final VirtualRouter vr = mock(VirtualRouter.class);
when(vr.getHostId()).thenReturn(HOST_ID);
doReturn(true).when(nwHelperUT).checkRouterVersion(vr);
final Commands commands = mock(Commands.class);
when(commands.size()).thenReturn(3);
final Answer answer1 = mock(Answer.class);
final Answer answer2 = mock(Answer.class);
final Answer answer3 = mock(Answer.class);
// In the second iteration it should match and return, without invoking the third
final Answer[] answers = { answer1, answer2, answer3 };
when(answer1.getResult()).thenReturn(true);
when(answer2.getResult()).thenReturn(true);
when(answer3.getResult()).thenReturn(true);
when(this.agentManager.send(HOST_ID, commands)).thenReturn(answers);
// Execute
final boolean result = nwHelperUT.sendCommandsToRouter(vr, commands);
// Assert
verify(this.agentManager, times(1)).send(HOST_ID, commands);
verify(answer1, times(1)).getResult();
verify(answer2, times(1)).getResult();
verify(answer3, times(1)).getResult();
assertTrue(result);
}
Aggregations