Search in sources :

Example 1 with GroupAnswer

use of com.cloud.agent.api.routing.GroupAnswer in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method updateRouterHealthChecksConfig.

/**
 * Updates router health check config to the virtual router that it uses for health checks.
 * @param router - the router ID that data needs to be sent to.
 * @return success of whether data was sent or not
 */
private boolean updateRouterHealthChecksConfig(DomainRouterVO router) {
    if (!RouterHealthChecksEnabled.value()) {
        return false;
    }
    String controlIP = _routerControlHelper.getRouterControlIp(router.getId());
    if (StringUtils.isBlank(controlIP) || controlIP.equals("0.0.0.0")) {
        s_logger.debug("Skipping update data on router " + router.getUuid() + " because controlIp is not correct.");
        return false;
    }
    s_logger.info("Updating data for router health checks for router " + router.getUuid());
    Answer origAnswer = null;
    try {
        SetMonitorServiceCommand command = createMonitorServiceCommand(router, null, true, true);
        origAnswer = _agentMgr.easySend(router.getHostId(), command);
    } catch (final Exception e) {
        s_logger.error("Error while sending update data for health check to router: " + router.getInstanceName(), e);
        return false;
    }
    if (origAnswer == null) {
        s_logger.error("Unable to update health checks data to router " + router.getHostName());
        return false;
    }
    GroupAnswer answer = null;
    if (origAnswer instanceof GroupAnswer) {
        answer = (GroupAnswer) origAnswer;
    } else {
        s_logger.error("Unable to update health checks data to router " + router.getHostName() + " Received answer " + origAnswer.getDetails());
        return false;
    }
    if (!answer.getResult()) {
        s_logger.error("Unable to update health checks data to router " + router.getHostName() + ", details : " + answer.getDetails());
    }
    return answer.getResult();
}
Also used : GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) GetRouterMonitorResultsAnswer(com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer) GetRouterAlertsAnswer(com.cloud.agent.api.GetRouterAlertsAnswer) SetMonitorServiceCommand(com.cloud.agent.api.routing.SetMonitorServiceCommand) GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) ConnectionException(com.cloud.exception.ConnectionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) JsonSyntaxException(com.google.gson.JsonSyntaxException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ParseException(java.text.ParseException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException)

Example 2 with GroupAnswer

use of com.cloud.agent.api.routing.GroupAnswer in project cloudstack by apache.

the class VirtualRoutingResourceTest method testSetPortForwardingRulesCommand.

@Test
public void testSetPortForwardingRulesCommand() {
    final SetPortForwardingRulesCommand cmd = generateSetPortForwardingRulesCommand();
    // Reset rule check count
    _count = 0;
    final Answer answer = _resource.executeRequest(cmd);
    assertTrue(answer instanceof GroupAnswer);
    assertEquals(((GroupAnswer) answer).getResults().length, 2);
    assertTrue(answer.getResult());
}
Also used : GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) Answer(com.cloud.agent.api.Answer) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) Test(org.junit.Test)

Example 3 with GroupAnswer

use of com.cloud.agent.api.routing.GroupAnswer in project cloudstack by apache.

the class VirtualRoutingResourceTest method testIpAssocCommand.

@Test
public void testIpAssocCommand() {
    final IpAssocCommand cmd = generateIpAssocCommand();
    _count = 0;
    final Answer answer = _resource.executeRequest(cmd);
    assertTrue(answer instanceof GroupAnswer);
    assertEquals(2, ((GroupAnswer) answer).getResults().length);
    assertTrue(answer.getResult());
}
Also used : GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) Answer(com.cloud.agent.api.Answer) IpAssocCommand(com.cloud.agent.api.routing.IpAssocCommand) GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) Test(org.junit.Test)

Example 4 with GroupAnswer

use of com.cloud.agent.api.routing.GroupAnswer in project cosmic by MissionCriticalCloud.

the class VirtualRoutingResource method applyConfig.

private Answer applyConfig(final NetworkElementCommand cmd, final List<ConfigItem> cfg) {
    if (cfg.isEmpty()) {
        return new Answer(cmd, true, "Nothing to do");
    }
    final List<ExecutionResult> results = new ArrayList<>();
    final List<String> details = new ArrayList<>();
    boolean finalResult = false;
    for (final ConfigItem configItem : cfg) {
        final long startTimestamp = System.currentTimeMillis();
        ExecutionResult result = applyConfigToVR(cmd.getRouterAccessIp(), configItem);
        if (s_logger.isDebugEnabled()) {
            final long elapsed = System.currentTimeMillis() - startTimestamp;
            s_logger.debug("Processing " + configItem + " took " + elapsed + "ms");
        }
        if (result == null) {
            result = new ExecutionResult(false, "null execution result");
        }
        results.add(result);
        details.add(configItem.getInfo() + (result.isSuccess() ? " - success: " : " - failed: ") + result.getDetails());
        finalResult = result.isSuccess();
    }
    // Not sure why this matters, but log it anyway
    if (cmd.getAnswersCount() != results.size()) {
        s_logger.warn("Expected " + cmd.getAnswersCount() + " answers while executing " + cmd.getClass().getSimpleName() + " but received " + results.size());
    }
    if (results.size() == 1) {
        return new Answer(cmd, finalResult, results.get(0).getDetails());
    } else {
        return new GroupAnswer(cmd, finalResult, results.size(), details.toArray(new String[details.size()]));
    }
}
Also used : GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) ArrayList(java.util.ArrayList) ExecutionResult(com.cloud.utils.ExecutionResult) GroupAnswer(com.cloud.agent.api.routing.GroupAnswer)

Example 5 with GroupAnswer

use of com.cloud.agent.api.routing.GroupAnswer in project cloudstack by apache.

the class VirtualRoutingResource method applyConfig.

private Answer applyConfig(NetworkElementCommand cmd, List<ConfigItem> cfg) {
    if (cfg.isEmpty()) {
        return new Answer(cmd, true, "Nothing to do");
    }
    List<ExecutionResult> results = new ArrayList<ExecutionResult>();
    List<String> details = new ArrayList<String>();
    boolean finalResult = false;
    for (ConfigItem configItem : cfg) {
        long startTimestamp = System.currentTimeMillis();
        ExecutionResult result = applyConfigToVR(cmd.getRouterAccessIp(), configItem, VRScripts.VR_SCRIPT_EXEC_TIMEOUT);
        if (s_logger.isDebugEnabled()) {
            long elapsed = System.currentTimeMillis() - startTimestamp;
            s_logger.debug("Processing " + configItem + " took " + elapsed + "ms");
        }
        if (result == null) {
            result = new ExecutionResult(false, "null execution result");
        }
        results.add(result);
        details.add(configItem.getInfo() + (result.isSuccess() ? " - success: " : " - failed: ") + result.getDetails());
        finalResult = result.isSuccess();
    }
    // Not sure why this matters, but log it anyway
    if (cmd.getAnswersCount() != results.size()) {
        s_logger.warn("Expected " + cmd.getAnswersCount() + " answers while executing " + cmd.getClass().getSimpleName() + " but received " + results.size());
    }
    if (results.size() == 1) {
        return new Answer(cmd, finalResult, results.get(0).getDetails());
    } else {
        return new GroupAnswer(cmd, finalResult, results.size(), details.toArray(new String[details.size()]));
    }
}
Also used : GetRouterAlertsAnswer(com.cloud.agent.api.GetRouterAlertsAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) GetRouterMonitorResultsAnswer(com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer) SetupKeystoreAnswer(org.apache.cloudstack.ca.SetupKeystoreAnswer) Answer(com.cloud.agent.api.Answer) SetupCertificateAnswer(org.apache.cloudstack.ca.SetupCertificateAnswer) DiagnosticsAnswer(org.apache.cloudstack.diagnostics.DiagnosticsAnswer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) PrepareFilesAnswer(org.apache.cloudstack.diagnostics.PrepareFilesAnswer) ArrayList(java.util.ArrayList) ExecutionResult(com.cloud.utils.ExecutionResult) GroupAnswer(com.cloud.agent.api.routing.GroupAnswer)

Aggregations

Answer (com.cloud.agent.api.Answer)7 GroupAnswer (com.cloud.agent.api.routing.GroupAnswer)7 Test (org.junit.Test)4 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)3 CheckS2SVpnConnectionsAnswer (com.cloud.agent.api.CheckS2SVpnConnectionsAnswer)3 GetDomRVersionAnswer (com.cloud.agent.api.GetDomRVersionAnswer)3 GetRouterAlertsAnswer (com.cloud.agent.api.GetRouterAlertsAnswer)2 GetRouterMonitorResultsAnswer (com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer)2 ExecutionResult (com.cloud.utils.ExecutionResult)2 ArrayList (java.util.ArrayList)2 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)1 NetworkUsageAnswer (com.cloud.agent.api.NetworkUsageAnswer)1 IpAssocCommand (com.cloud.agent.api.routing.IpAssocCommand)1 IpAssocVpcCommand (com.cloud.agent.api.routing.IpAssocVpcCommand)1 SetMonitorServiceCommand (com.cloud.agent.api.routing.SetMonitorServiceCommand)1 SetPortForwardingRulesCommand (com.cloud.agent.api.routing.SetPortForwardingRulesCommand)1 SetPortForwardingRulesVpcCommand (com.cloud.agent.api.routing.SetPortForwardingRulesVpcCommand)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 ConnectionException (com.cloud.exception.ConnectionException)1