Search in sources :

Example 11 with VirtualRouter

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");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) DomainRouterResponse(com.cloud.api.response.DomainRouterResponse) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter)

Example 12 with VirtualRouter

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");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) DomainRouterResponse(com.cloud.api.response.DomainRouterResponse) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter)

Example 13 with VirtualRouter

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");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) DomainRouterResponse(com.cloud.api.response.DomainRouterResponse) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter)

Example 14 with VirtualRouter

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();
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) Nic(com.cloud.legacymodel.network.Nic) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter)

Example 15 with VirtualRouter

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);
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) Commands(com.cloud.agent.manager.Commands) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter) Test(org.junit.Test)

Aggregations

VirtualRouter (com.cloud.legacymodel.network.VirtualRouter)36 Commands (com.cloud.agent.manager.Commands)21 UpdateVmOverviewCommand (com.cloud.legacymodel.communication.command.UpdateVmOverviewCommand)8 VMOverviewTO (com.cloud.legacymodel.to.VMOverviewTO)8 NicVO (com.cloud.vm.NicVO)8 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)8 UpdateNetworkOverviewCommand (com.cloud.legacymodel.communication.command.UpdateNetworkOverviewCommand)7 NetworkOverviewTO (com.cloud.legacymodel.to.NetworkOverviewTO)7 DomainRouterVO (com.cloud.vm.DomainRouterVO)7 ServerApiException (com.cloud.api.ServerApiException)5 DomainRouterResponse (com.cloud.api.response.DomainRouterResponse)5 Zone (com.cloud.db.model.Zone)5 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)5 Ip (com.cloud.legacymodel.network.Ip)5 UserVmVO (com.cloud.vm.UserVmVO)5 ArrayList (java.util.ArrayList)5 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)4 Network (com.cloud.legacymodel.network.Network)4 Config (com.cloud.configuration.Config)3 ZoneRepository (com.cloud.db.repository.ZoneRepository)3