Search in sources :

Example 1 with GroupAnswer

use of com.cloud.legacymodel.communication.answer.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 : GroupAnswer(com.cloud.legacymodel.communication.answer.GroupAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.legacymodel.communication.answer.CheckS2SVpnConnectionsAnswer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) GetDomRVersionAnswer(com.cloud.legacymodel.communication.answer.GetDomRVersionAnswer) ArrayList(java.util.ArrayList) ExecutionResult(com.cloud.legacymodel.ExecutionResult) GroupAnswer(com.cloud.legacymodel.communication.answer.GroupAnswer)

Aggregations

ExecutionResult (com.cloud.legacymodel.ExecutionResult)1 Answer (com.cloud.legacymodel.communication.answer.Answer)1 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)1 CheckS2SVpnConnectionsAnswer (com.cloud.legacymodel.communication.answer.CheckS2SVpnConnectionsAnswer)1 GetDomRVersionAnswer (com.cloud.legacymodel.communication.answer.GetDomRVersionAnswer)1 GroupAnswer (com.cloud.legacymodel.communication.answer.GroupAnswer)1 ArrayList (java.util.ArrayList)1