Search in sources :

Example 1 with Action

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());
}
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) GetRouterMonitorResultsAnswer(com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer) SetupKeystoreAnswer(org.apache.cloudstack.ca.SetupKeystoreAnswer) Answer(com.cloud.agent.api.Answer) SetupCertificateAnswer(org.apache.cloudstack.ca.SetupCertificateAnswer) DiagnosticsAnswer(org.apache.cloudstack.diagnostics.DiagnosticsAnswer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) PrepareFilesAnswer(org.apache.cloudstack.diagnostics.PrepareFilesAnswer) ArrayList(java.util.ArrayList) List(java.util.List) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Queue(java.util.Queue)

Example 2 with Action

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());
}
Also used : 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) Action(com.cloud.agent.api.routing.AggregationControlCommand.Action) ArrayList(java.util.ArrayList) List(java.util.List) NetworkElementCommand(com.cloud.agent.api.routing.NetworkElementCommand) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Queue(java.util.Queue)

Aggregations

Answer (com.cloud.agent.api.Answer)2 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)2 CheckS2SVpnConnectionsAnswer (com.cloud.agent.api.CheckS2SVpnConnectionsAnswer)2 GetDomRVersionAnswer (com.cloud.agent.api.GetDomRVersionAnswer)2 Action (com.cloud.agent.api.routing.AggregationControlCommand.Action)2 GroupAnswer (com.cloud.agent.api.routing.GroupAnswer)2 NetworkElementCommand (com.cloud.agent.api.routing.NetworkElementCommand)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Queue (java.util.Queue)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 GetRouterAlertsAnswer (com.cloud.agent.api.GetRouterAlertsAnswer)1 GetRouterMonitorResultsAnswer (com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer)1 ExecutionResult (com.cloud.utils.ExecutionResult)1 SetupCertificateAnswer (org.apache.cloudstack.ca.SetupCertificateAnswer)1 SetupKeystoreAnswer (org.apache.cloudstack.ca.SetupKeystoreAnswer)1 DiagnosticsAnswer (org.apache.cloudstack.diagnostics.DiagnosticsAnswer)1 PrepareFilesAnswer (org.apache.cloudstack.diagnostics.PrepareFilesAnswer)1 Duration (org.joda.time.Duration)1