use of com.cloud.utils.ExecutionResult in project cloudstack by apache.
the class VirtualRoutingResource method execute.
private CheckS2SVpnConnectionsAnswer execute(CheckS2SVpnConnectionsCommand cmd) {
StringBuffer buff = new StringBuffer();
for (String ip : cmd.getVpnIps()) {
buff.append(ip);
buff.append(" ");
}
ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), VRScripts.S2SVPN_CHECK, buff.toString());
return new CheckS2SVpnConnectionsAnswer(cmd, result.isSuccess(), result.getDetails());
}
use of com.cloud.utils.ExecutionResult in project cloudstack by apache.
the class VirtualRoutingResource method executeRequest.
public Answer executeRequest(final NetworkElementCommand cmd) {
boolean aggregated = false;
String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
Lock lock;
if (_vrLockMap.containsKey(routerName)) {
lock = _vrLockMap.get(routerName);
} else {
lock = new ReentrantLock();
_vrLockMap.put(routerName, lock);
}
lock.lock();
try {
ExecutionResult rc = _vrDeployer.prepareCommand(cmd);
if (!rc.isSuccess()) {
s_logger.error("Failed to prepare VR command due to " + rc.getDetails());
return new Answer(cmd, false, rc.getDetails());
}
assert cmd.getRouterAccessIp() != null : "Why there is no access IP for VR?";
if (cmd.isQuery()) {
return executeQueryCommand(cmd);
}
if (cmd instanceof AggregationControlCommand) {
return execute((AggregationControlCommand) cmd);
}
if (_vrAggregateCommandsSet.containsKey(routerName)) {
_vrAggregateCommandsSet.get(routerName).add(cmd);
aggregated = true;
//TODO: Deal with group answer as well
return new Answer(cmd);
}
List<ConfigItem> cfg = generateCommandCfg(cmd);
if (cfg == null) {
return Answer.createUnsupportedCommandAnswer(cmd);
}
return applyConfig(cmd, cfg);
} catch (final IllegalArgumentException e) {
return new Answer(cmd, false, e.getMessage());
} finally {
lock.unlock();
if (!aggregated) {
ExecutionResult rc = _vrDeployer.cleanupCommand(cmd);
if (!rc.isSuccess()) {
s_logger.error("Failed to cleanup VR command due to " + rc.getDetails());
}
}
}
}
use of com.cloud.utils.ExecutionResult 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 (timeout.isShorterThan(VRScripts.VR_SCRIPT_EXEC_TIMEOUT)) {
timeout = VRScripts.VR_SCRIPT_EXEC_TIMEOUT;
}
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 recongize aggregation action " + action.toString());
}
use of com.cloud.utils.ExecutionResult in project cloudstack by apache.
the class VirtualRoutingResource method execute.
private GetRouterAlertsAnswer execute(GetRouterAlertsCommand cmd) {
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
String args = cmd.getPreviousAlertTimeStamp();
ExecutionResult result = _vrDeployer.executeInVR(routerIp, VRScripts.ROUTER_ALERTS, args);
String[] alerts = null;
String lastAlertTimestamp = null;
if (result.isSuccess()) {
if (!result.getDetails().isEmpty() && !result.getDetails().trim().equals("No Alerts")) {
alerts = result.getDetails().trim().split("\\\\n");
String[] lastAlert = alerts[alerts.length - 1].split(",");
lastAlertTimestamp = lastAlert[0];
}
return new GetRouterAlertsAnswer(cmd, alerts, lastAlertTimestamp);
} else {
return new GetRouterAlertsAnswer(cmd, result.getDetails());
}
}
use of com.cloud.utils.ExecutionResult in project cloudstack by apache.
the class VirtualRoutingResource method execute.
private Answer execute(GetDomRVersionCmd cmd) {
final ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), VRScripts.VERSION, null);
if (!result.isSuccess()) {
return new GetDomRVersionAnswer(cmd, "GetDomRVersionCmd failed");
}
String[] lines = result.getDetails().split("&");
if (lines.length != 2) {
return new GetDomRVersionAnswer(cmd, result.getDetails());
}
return new GetDomRVersionAnswer(cmd, result.getDetails(), lines[0], lines[1]);
}
Aggregations