Search in sources :

Example 1 with ExecutionResult

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());
}
Also used : CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) ExecutionResult(com.cloud.utils.ExecutionResult)

Example 2 with ExecutionResult

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());
            }
        }
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) GetRouterAlertsAnswer(com.cloud.agent.api.GetRouterAlertsAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AggregationControlCommand(com.cloud.agent.api.routing.AggregationControlCommand) ExecutionResult(com.cloud.utils.ExecutionResult) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Example 3 with ExecutionResult

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());
}
Also used : Action(com.cloud.agent.api.routing.AggregationControlCommand.Action) Duration(org.joda.time.Duration) ExecutionResult(com.cloud.utils.ExecutionResult) NetworkElementCommand(com.cloud.agent.api.routing.NetworkElementCommand) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) GetRouterAlertsAnswer(com.cloud.agent.api.GetRouterAlertsAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) ArrayList(java.util.ArrayList) List(java.util.List) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Queue(java.util.Queue)

Example 4 with ExecutionResult

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());
    }
}
Also used : ExecutionResult(com.cloud.utils.ExecutionResult) GetRouterAlertsAnswer(com.cloud.agent.api.GetRouterAlertsAnswer)

Example 5 with ExecutionResult

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]);
}
Also used : ExecutionResult(com.cloud.utils.ExecutionResult) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer)

Aggregations

ExecutionResult (com.cloud.utils.ExecutionResult)50 InternalErrorException (com.cloud.exception.InternalErrorException)23 IOException (java.io.IOException)20 ConfigurationException (javax.naming.ConfigurationException)20 IpAddressTO (com.cloud.agent.api.to.IpAddressTO)16 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)16 URISyntaxException (java.net.URISyntaxException)13 NicTO (com.cloud.agent.api.to.NicTO)11 ConnectException (java.net.ConnectException)11 RemoteException (java.rmi.RemoteException)11 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)9 SAXException (org.xml.sax.SAXException)9 XenAPIException (com.xensource.xenapi.Types.XenAPIException)8 MalformedURLException (java.net.MalformedURLException)8 TimeoutException (java.util.concurrent.TimeoutException)8 XmlRpcException (org.apache.xmlrpc.XmlRpcException)8 CloudException (com.cloud.exception.CloudException)7 Connection (com.xensource.xenapi.Connection)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 URI (java.net.URI)7