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()]));
}
}
Aggregations