public SetStaticNatRulesAnswer(SetStaticNatRulesCommand cmd, String[] results, boolean success) { super(cmd, success, null); assert (cmd.getRules().length == results.length) : "Shouldn't the results match the commands?"; this.results = results; }
@Override public List<ConfigItem> generateConfig(final NetworkElementCommand cmd) { final SetStaticNatRulesCommand command = (SetStaticNatRulesCommand) cmd; final LinkedList<StaticNatRule> rules = new LinkedList<>(); for (final StaticNatRuleTO rule : command.getRules()) { final StaticNatRule staticNatRule = new StaticNatRule(rule.revoked(), rule.getProtocol(), rule.getSrcIp(), rule.getStringSrcPortRange(), rule.getDstIp()); rules.add(staticNatRule); } final StaticNatRules staticNatRules = new StaticNatRules(rules); return generateConfigItems(staticNatRules); }
private Answer execute(SetStaticNatRulesCommand cmd, int numRetries) { StaticNatRuleTO[] rules = cmd.getRules(); try { ArrayList<IPaloAltoCommand> commandList = new ArrayList<IPaloAltoCommand>(); for (StaticNatRuleTO rule : rules) { if (!rule.revoked()) { manageStcNatRule(commandList, PaloAltoPrimative.ADD, rule); } else { manageStcNatRule(commandList, PaloAltoPrimative.DELETE, rule); } } boolean status = requestWithCommit(commandList); return new Answer(cmd); } catch (ExecutionException e) { s_logger.error(e); if (numRetries > 0 && refreshPaloAltoConnection()) { int numRetriesRemaining = numRetries - 1; s_logger.debug("Retrying SetStaticNatRulesCommand. Number of retries remaining: " + numRetriesRemaining); return execute(cmd, numRetriesRemaining); } else { return new Answer(cmd, e); } } }