Search in sources :

Example 1 with ExecutionResult

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

Example 2 with ExecutionResult

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());
            }
        }
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) 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) AggregationControlCommand(com.cloud.legacymodel.communication.command.AggregationControlCommand) ExecutionResult(com.cloud.legacymodel.ExecutionResult) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Example 3 with ExecutionResult

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());
}
Also used : CheckS2SVpnConnectionsAnswer(com.cloud.legacymodel.communication.answer.CheckS2SVpnConnectionsAnswer) ExecutionResult(com.cloud.legacymodel.ExecutionResult)

Example 4 with ExecutionResult

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]);
}
Also used : ExecutionResult(com.cloud.legacymodel.ExecutionResult) GetDomRVersionAnswer(com.cloud.legacymodel.communication.answer.GetDomRVersionAnswer)

Example 5 with ExecutionResult

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());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) ExecutionResult(com.cloud.legacymodel.ExecutionResult) NetworkUsageCommand(com.cloud.legacymodel.communication.command.NetworkUsageCommand) Test(org.junit.Test)

Aggregations

ExecutionResult (com.cloud.legacymodel.ExecutionResult)13 Answer (com.cloud.legacymodel.communication.answer.Answer)4 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)4 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)4 ConfigurationException (javax.naming.ConfigurationException)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 SAXException (org.xml.sax.SAXException)4 CheckS2SVpnConnectionsAnswer (com.cloud.legacymodel.communication.answer.CheckS2SVpnConnectionsAnswer)3 GetDomRVersionAnswer (com.cloud.legacymodel.communication.answer.GetDomRVersionAnswer)3 XenAPIException (com.xensource.xenapi.Types.XenAPIException)3 MalformedURLException (java.net.MalformedURLException)3 TimeoutException (java.util.concurrent.TimeoutException)3 XmlRpcException (org.apache.xmlrpc.XmlRpcException)3 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)2 GroupAnswer (com.cloud.legacymodel.communication.answer.GroupAnswer)2 NetworkUsageCommand (com.cloud.legacymodel.communication.command.NetworkUsageCommand)2 Connection (com.xensource.xenapi.Connection)2 URLConnection (java.net.URLConnection)2 Test (org.junit.Test)2