コード例 #1
0
  @Override
  public boolean sendCommandsToRouter(final VirtualRouter router, final Commands cmds)
      throws AgentUnavailableException, ResourceUnavailableException {
    if (!checkRouterVersion(router)) {
      s_logger.debug(
          "Router requires upgrade. Unable to send command to router:"
              + router.getId()
              + ", router template version : "
              + router.getTemplateVersion()
              + ", minimal required version : "
              + NetworkOrchestrationService.MinVRVersion.valueIn(router.getDataCenterId()));
      throw new ResourceUnavailableException(
          "Unable to send command. Router requires upgrade", VirtualRouter.class, router.getId());
    }
    Answer[] answers = null;
    try {
      answers = _agentMgr.send(router.getHostId(), cmds);
    } catch (final OperationTimedoutException e) {
      s_logger.warn("Timed Out", e);
      throw new AgentUnavailableException(
          "Unable to send commands to virtual router ", router.getHostId(), e);
    }

    if (answers == null || answers.length != cmds.size()) {
      return false;
    }

    // FIXME: Have to return state for individual command in the future
    boolean result = true;
    for (final Answer answer : answers) {
      if (!answer.getResult()) {
        result = false;
        break;
      }
    }
    return result;
  }
  @Override
  public boolean startRemoteAccessVpn(final RemoteAccessVpn vpn, final VirtualRouter router)
      throws ResourceUnavailableException {
    if (router.getState() != State.Running) {
      s_logger.warn(
          "Unable to apply remote access VPN configuration, virtual router is not in the right state "
              + router.getState());
      throw new ResourceUnavailableException(
          "Unable to apply remote access VPN configuration,"
              + " virtual router is not in the right state",
          DataCenter.class,
          router.getDataCenterId());
    }

    final Commands cmds = new Commands(Command.OnError.Stop);
    _commandSetupHelper.createApplyVpnCommands(true, vpn, router, cmds);

    try {
      _agentMgr.send(router.getHostId(), cmds);
    } catch (final OperationTimedoutException e) {
      s_logger.debug("Failed to start remote access VPN: ", e);
      throw new AgentUnavailableException(
          "Unable to send commands to virtual router ", router.getHostId(), e);
    }
    Answer answer = cmds.getAnswer("users");
    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;
  }