HttpRequestUtils { public static ExecutionOptions parseFlowOptions(final HttpServletRequest req, final String flowName) throws ServletException { final ExecutionOptions execOptions = new ExecutionOptions(); if (hasParam(req, "failureAction")) { final String option = getParam(req, "failureAction"); if (option.equals("finishCurrent")) { execOptions.setFailureAction(FailureAction.FINISH_CURRENTLY_RUNNING); } else if (option.equals("cancelImmediately")) { execOptions.setFailureAction(FailureAction.CANCEL_ALL); } else if (option.equals("finishPossible")) { execOptions.setFailureAction(FailureAction.FINISH_ALL_POSSIBLE); } } if (hasParam(req, "failureEmailsOverride")) { final boolean override = getBooleanParam(req, "failureEmailsOverride", false); execOptions.setFailureEmailsOverridden(override); } if (hasParam(req, "successEmailsOverride")) { final boolean override = getBooleanParam(req, "successEmailsOverride", false); execOptions.setSuccessEmailsOverridden(override); } if (hasParam(req, "failureEmails")) { final String emails = getParam(req, "failureEmails"); if (!emails.isEmpty()) { final String[] emailSplit = emails.split("\\s*,\\s*|\\s*;\\s*|\\s+"); execOptions.setFailureEmails(Arrays.asList(emailSplit)); } } if (hasParam(req, "successEmails")) { final String emails = getParam(req, "successEmails"); if (!emails.isEmpty()) { final String[] emailSplit = emails.split("\\s*,\\s*|\\s*;\\s*|\\s+"); execOptions.setSuccessEmails(Arrays.asList(emailSplit)); } } if (hasParam(req, "notifyFailureFirst")) { execOptions.setNotifyOnFirstFailure(Boolean.parseBoolean(getParam(req, "notifyFailureFirst"))); } if (hasParam(req, "notifyFailureLast")) { execOptions.setNotifyOnLastFailure(Boolean.parseBoolean(getParam(req, "notifyFailureLast"))); } final String concurrentOption = getParam(req, "concurrentOption", "skip"); execOptions.setConcurrentOption(concurrentOption); if (concurrentOption.equals("pipeline")) { final int pipelineLevel = getIntParam(req, "pipelineLevel"); execOptions.setPipelineLevel(pipelineLevel); } else if (concurrentOption.equals("queue")) { final int queueLevel = getIntParam(req, "queueLevel", 1); execOptions.setPipelineLevel(queueLevel); } if (hasParam(req, "mailCreator")) { final String mailCreator = getParam(req, "mailCreator"); execOptions.setMailCreator(mailCreator); } final Map<String, String> slaSettings = getParamGroup(req, PARAM_SLA_SETTINGS); final String emailStr = getParam(req, PARAM_SLA_EMAILS, null); final List<SlaOption> slaOptions = SlaRequestUtils.parseSlaOptions(flowName, emailStr, slaSettings); if (!slaOptions.isEmpty()) { execOptions.setSlaOptions(slaOptions); } final Map<String, String> flowParamGroup = getParamGroup(req, "flowOverride"); execOptions.addAllFlowParameters(flowParamGroup); if (hasParam(req, "disabled")) { final String disabled = getParam(req, "disabled"); if (!disabled.isEmpty()) { final List<DisabledJob> disabledList = DisabledJob.fromDeprecatedObjectList((List<Object>) JSONUtils .parseJSONFromStringQuiet(disabled)); execOptions.setDisabledJobs(disabledList); } } return execOptions; }  static ExecutionOptions parseFlowOptions(final HttpServletRequest req,
      final String flowName); static void filterAdminOnlyFlowParams(final UserManager userManager,
      final ExecutionOptions options, final User user); static boolean validateIntegerParam(final Map<String, String> params,
      final String paramName); static boolean hasPermission(final UserManager userManager, final User user,
      final Permission.Type type); static boolean hasParam(final HttpServletRequest request, final String param); static String getParam(final HttpServletRequest request, final String name); static String getParam(final HttpServletRequest request, final String name,
      final String defaultVal); static int getIntParam(final HttpServletRequest request, final String name); static int getIntParam(final HttpServletRequest request, final String name,
      final int defaultVal); static boolean getBooleanParam(final HttpServletRequest request, final String name); static boolean getBooleanParam(final HttpServletRequest request,
      final String name, final boolean defaultVal); static long getLongParam(final HttpServletRequest request, final String name); static long getLongParam(final HttpServletRequest request, final String name,
      final long defaultVal); static Map<String, String> getParamGroup(final HttpServletRequest request,
      final String groupName); static Object getJsonBody(final HttpServletRequest request); static String getBody(final HttpServletRequest request); static final String PARAM_SLA_EMAILS; static final String PARAM_SLA_SETTINGS; }
@Test public void testParseFlowOptionsSla() throws Exception { final HttpServletRequest req = mockRequestWithSla(ImmutableMap.of( "slaSettings[1]", ",FINISH,2:30,true,false", "slaSettings[2]", "test_job,SUCCESS,12:00,false,true", "slaSettings[3]", ",SUCCESS,12:00,true,true")); final ExecutionOptions options = HttpRequestUtils.parseFlowOptions(req, "test-flow"); final List<SlaOption> slaOptions = options.getSlaOptions(); final List<SlaOption> expected = Arrays.asList( new SlaOption(SlaType.FLOW_FINISH, "test-flow", "", Duration.ofMinutes(150), ImmutableSet.of(SlaAction.ALERT), ImmutableList.of()), new SlaOption(SlaType.JOB_SUCCEED, "test-flow", "test_job", Duration.ofMinutes(720), ImmutableSet.of(SlaAction.KILL), ImmutableList.of()), new SlaOption(SlaType.FLOW_SUCCEED, "test-flow", "", Duration.ofMinutes(720), ImmutableSet.of(SlaAction.ALERT, SlaAction.KILL), ImmutableList.of()) ); Assert.assertEquals(expected, slaOptions); }
@Test public void testParseFlowOptionsSlaWithEmail() throws Exception { final HttpServletRequest req = mockRequestWithSla(ImmutableMap.of( "slaSettings[1]", ",FINISH,2:30,true,false", "slaEmails", "sla1@example.com,sla2@example.com")); final ExecutionOptions options = HttpRequestUtils.parseFlowOptions(req, "test-flow"); final List<SlaOption> slaOptions = options.getSlaOptions(); final List<SlaOption> expected = Arrays.asList(new SlaOption(SlaType.FLOW_FINISH, "test-flow", "", Duration.ofMinutes(150), ImmutableSet.of(SlaAction.ALERT), ImmutableList.of("sla1@example.com", "sla2@example.com"))); Assert.assertEquals(expected, slaOptions); }