Search in sources :

Example 1 with NetworkElementCommand

use of com.cloud.legacymodel.communication.command.NetworkElementCommand 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 (!this._vrAggregateCommandsSet.containsKey(routerName));
        this._vrAggregateCommandsSet.put(routerName, new LinkedBlockingQueue<>());
        return new Answer(aggregationCommand, true, "Command aggregation started");
    } else if (Action.Finish.equals(action)) {
        final Queue<NetworkElementCommand> queue = this._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();
            this._vrAggregateCommandsSet.remove(routerName);
        }
    }
    return new Answer(aggregationCommand, false, "Fail to recognize aggregation action " + action.toString());
}
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) Action(com.cloud.legacymodel.communication.command.AggregationControlCommand.Action) ArrayList(java.util.ArrayList) List(java.util.List) NetworkElementCommand(com.cloud.legacymodel.communication.command.NetworkElementCommand) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Queue(java.util.Queue)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)1 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)1 CheckS2SVpnConnectionsAnswer (com.cloud.legacymodel.communication.answer.CheckS2SVpnConnectionsAnswer)1 GetDomRVersionAnswer (com.cloud.legacymodel.communication.answer.GetDomRVersionAnswer)1 GroupAnswer (com.cloud.legacymodel.communication.answer.GroupAnswer)1 Action (com.cloud.legacymodel.communication.command.AggregationControlCommand.Action)1 NetworkElementCommand (com.cloud.legacymodel.communication.command.NetworkElementCommand)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Queue (java.util.Queue)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1