use of com.cloud.agent.api.routing.AggregationControlCommand.Action in project cloudstack by apache.
the class VirtualRoutingResource method execute.
private Answer execute(AggregationControlCommand cmd) {
Action action = cmd.getAction();
String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
assert routerName != null;
assert cmd.getRouterAccessIp() != null;
if (action == Action.Start) {
assert (!_vrAggregateCommandsSet.containsKey(routerName));
Queue<NetworkElementCommand> queue = new LinkedBlockingQueue<>();
_vrAggregateCommandsSet.put(routerName, queue);
return new Answer(cmd, true, "Command aggregation started");
} else if (action == Action.Finish) {
Queue<NetworkElementCommand> queue = _vrAggregateCommandsSet.get(routerName);
int answerCounts = 0;
try {
StringBuilder sb = new StringBuilder();
sb.append("#Apache CloudStack Virtual Router Config File\n");
sb.append("<version>\n" + _cfgVersion + "\n</version>\n");
for (NetworkElementCommand command : queue) {
answerCounts += command.getAnswersCount();
List<ConfigItem> cfg = generateCommandCfg(command);
if (cfg == null) {
s_logger.warn("Unknown commands for VirtualRoutingResource, but continue: " + cmd.toString());
continue;
}
for (ConfigItem c : cfg) {
sb.append(c.getAggregateCommand());
}
}
// TODO replace with applyConfig with a stop on fail
String cfgFileName = "VR-" + UUID.randomUUID().toString() + ".cfg";
FileConfigItem fileConfigItem = new FileConfigItem(VRScripts.CONFIG_CACHE_LOCATION, cfgFileName, sb.toString());
ScriptConfigItem scriptConfigItem = new ScriptConfigItem(VRScripts.VR_CFG, "-c " + VRScripts.CONFIG_CACHE_LOCATION + cfgFileName);
// 120s is the minimal timeout
Duration timeout = _eachTimeout.withDurationAdded(_eachTimeout.getStandardSeconds(), answerCounts);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Aggregate action timeout in seconds is " + timeout.getStandardSeconds());
}
ExecutionResult result = applyConfigToVR(cmd.getRouterAccessIp(), fileConfigItem, timeout);
if (!result.isSuccess()) {
return new Answer(cmd, false, result.getDetails());
}
result = applyConfigToVR(cmd.getRouterAccessIp(), scriptConfigItem, timeout);
if (!result.isSuccess()) {
return new Answer(cmd, false, result.getDetails());
}
return new Answer(cmd, true, "Command aggregation finished");
} finally {
queue.clear();
_vrAggregateCommandsSet.remove(routerName);
}
}
return new Answer(cmd, false, "Fail to recognize aggregation action " + action.toString());
}
use of com.cloud.agent.api.routing.AggregationControlCommand.Action in project cosmic by MissionCriticalCloud.
the class VirtualRoutingResource method execute.
private Answer execute(final AggregationControlCommand aggregationCommand) {
assert aggregationCommand.getRouterAccessIp() != null;
final String routerName = aggregationCommand.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
assert routerName != null;
final Action action = aggregationCommand.getAction();
if (Action.Start.equals(action)) {
assert (!_vrAggregateCommandsSet.containsKey(routerName));
_vrAggregateCommandsSet.put(routerName, new LinkedBlockingQueue<>());
return new Answer(aggregationCommand, true, "Command aggregation started");
} else if (Action.Finish.equals(action)) {
final Queue<NetworkElementCommand> queue = _vrAggregateCommandsSet.get(routerName);
try {
for (final NetworkElementCommand command : queue) {
final List<ConfigItem> cfg = generateCommandCfg(command);
if (cfg == null) {
s_logger.warn("Unknown commands for VirtualRoutingResource, but continue: " + aggregationCommand.toString());
continue;
}
final Answer commandAnswer = applyConfig(command, cfg);
if (!commandAnswer.getResult()) {
return new Answer(aggregationCommand, false, "Aggregated command failed to execute " + commandAnswer.getDetails());
}
}
return new Answer(aggregationCommand, true, "Command aggregation finished");
} finally {
queue.clear();
_vrAggregateCommandsSet.remove(routerName);
}
}
return new Answer(aggregationCommand, false, "Fail to recognize aggregation action " + action.toString());
}
Aggregations