use of com.cloud.legacymodel.ExecutionResult 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()]));
}
}
use of com.cloud.legacymodel.ExecutionResult in project cosmic by MissionCriticalCloud.
the class VirtualRoutingResource method executeRequest.
public Answer executeRequest(final NetworkElementCommand cmd) {
boolean aggregated = false;
final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
final Lock lock;
if (this._vrLockMap.containsKey(routerName)) {
lock = this._vrLockMap.get(routerName);
} else {
lock = new ReentrantLock();
this._vrLockMap.put(routerName, lock);
}
lock.lock();
try {
final ExecutionResult rc = this._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 (this._vrAggregateCommandsSet.containsKey(routerName)) {
this._vrAggregateCommandsSet.get(routerName).add(cmd);
aggregated = true;
// TODO: Deal with group answer as well
return new Answer(cmd);
}
final 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) {
final ExecutionResult rc = this._vrDeployer.cleanupCommand(cmd);
if (!rc.isSuccess()) {
s_logger.error("Failed to cleanup VR command due to " + rc.getDetails());
}
}
}
}
use of com.cloud.legacymodel.ExecutionResult in project cosmic by MissionCriticalCloud.
the class VirtualRoutingResource method execute.
private CheckS2SVpnConnectionsAnswer execute(final CheckS2SVpnConnectionsCommand cmd) {
final StringBuilder str = new StringBuilder();
for (final String ip : cmd.getVpnIps()) {
str.append(ip);
str.append(" ");
}
final ExecutionResult result = this._vrDeployer.executeInVR(cmd.getRouterAccessIp(), VRScripts.S2SVPN_CHECK, str.toString());
return new CheckS2SVpnConnectionsAnswer(cmd, result.isSuccess(), result.getDetails());
}
use of com.cloud.legacymodel.ExecutionResult in project cosmic by MissionCriticalCloud.
the class VirtualRoutingResource method execute.
private Answer execute(final GetDomRVersionCommand cmd) {
final ExecutionResult result = this._vrDeployer.executeInVR(cmd.getRouterAccessIp(), VRScripts.VERSION, null);
if (!result.isSuccess()) {
return new GetDomRVersionAnswer(cmd, "GetDomRVersionCommand failed");
}
final 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]);
}
use of com.cloud.legacymodel.ExecutionResult in project cosmic by MissionCriticalCloud.
the class XenServer56WrapperTest method testNetworkUsageCommandCreateVpcFailure.
@Test
public void testNetworkUsageCommandCreateVpcFailure() {
final ExecutionResult executionResult = Mockito.mock(ExecutionResult.class);
final NetworkUsageCommand networkCommand = new NetworkUsageCommand("192.168.10.10", "domRName", true, "192.168.10.1", "10.1.1.1/24");
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
final String args = " -l 192.168.10.1 -c -v 10.1.1.1/24";
when(this.xenServer56Resource.executeInVR(networkCommand.getPrivateIP(), "vpc_netusage.sh", args)).thenReturn(executionResult);
when(executionResult.isSuccess()).thenReturn(false);
final Answer answer = wrapper.execute(networkCommand, this.xenServer56Resource);
assertFalse(answer.getResult());
}
Aggregations