From 1bb277d2ad851afcfc8f5893c9efd656bf08af93 Mon Sep 17 00:00:00 2001 From: Cheng Ren Date: Tue, 2 Jan 2018 16:10:23 -0800 Subject: [PATCH] Remove all associated schedules when deleting the project (#1589) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deletion of a project will automatically remove all of its associated schedules and go through even though associated trigger instances or flows are running. Current behavior of Azkaban is to disallow any project deletion while the project contains any flow currently being scheduled or running. User needs to remove associated schedules first and wait for all associated flows to finish or cancel any running flows in order to delete the project. However if schedule info is part of the project zip as part of flow 2.0 design, it’s impossible for user to unschedule without removing the project which becomes a deadlock scenario. This also reduces user manual labor when deleting projects. Tested locally, but unit test or integration test will follow up. --- .../webapp/servlet/ProjectManagerServlet.java | 54 ++++++------------- .../webapp/servlet/velocity/projectmodals.vm | 4 +- 2 files changed, 19 insertions(+), 39 deletions(-) diff --git a/azkaban-web-server/src/main/java/azkaban/webapp/servlet/ProjectManagerServlet.java b/azkaban-web-server/src/main/java/azkaban/webapp/servlet/ProjectManagerServlet.java index 2a2e26183c..457b43e671 100644 --- a/azkaban-web-server/src/main/java/azkaban/webapp/servlet/ProjectManagerServlet.java +++ b/azkaban-web-server/src/main/java/azkaban/webapp/servlet/ProjectManagerServlet.java @@ -586,6 +586,19 @@ private void handlePurgeProject(final HttpServletRequest req, this.writeJSON(resp, ret); } + private void removeAssociatedSchedules(final Project project) throws ServletException { + try { + for (final Schedule schedule : this.scheduleManager.getSchedules()) { + if (schedule.getProjectId() == project.getId()) { + logger.info("removing schedule " + schedule.getScheduleId()); + this.scheduleManager.removeSchedule(schedule); + } + } + } catch (final ScheduleManagerException e) { + throw new ServletException(e); + } + } + private void handleRemoveProject(final HttpServletRequest req, final HttpServletResponse resp, final Session session) throws ServletException, IOException { @@ -607,42 +620,7 @@ private void handleRemoveProject(final HttpServletRequest req, return; } - // Check if scheduled - Schedule sflow = null; - try { - for (final Schedule flow : this.scheduleManager.getSchedules()) { - - if (flow.getProjectId() == project.getId()) { - sflow = flow; - break; - } - } - } catch (final ScheduleManagerException e) { - throw new ServletException(e); - } - - if (sflow != null) { - this.setErrorMessageInCookie(resp, "Cannot delete. Please unschedule " - + sflow.getScheduleName() + "."); - - resp.sendRedirect(req.getRequestURI() + "?project=" + projectName); - return; - } - - // Check if executing - ExecutableFlow exflow = null; - for (final ExecutableFlow flow : this.executorManager.getRunningFlows()) { - if (flow.getProjectId() == project.getId()) { - exflow = flow; - break; - } - } - if (exflow != null) { - this.setErrorMessageInCookie(resp, "Cannot delete. Executable flow " - + exflow.getExecutionId() + " is still running."); - resp.sendRedirect(req.getRequestURI() + "?project=" + projectName); - return; - } + removeAssociatedSchedules(project); try { this.projectManager.removeProject(project, user); @@ -653,7 +631,7 @@ private void handleRemoveProject(final HttpServletRequest req, } this.setSuccessMessageInCookie(resp, "Project '" + projectName - + "' was successfully deleted."); + + "' was successfully deleted and associated schedules are removed."); resp.sendRedirect(req.getContextPath()); } @@ -787,7 +765,7 @@ private void fillFlowInfo(final Project project, final String flowId, final Flow flow = project.getFlow(flowId); if (flow == null) { ret.put("error", - "Flow " + flowId + " not found in project " + project.getName()); + "Flow " + flowId + " not found in project " + project.getName()); return; } diff --git a/azkaban-web-server/src/main/resources/azkaban/webapp/servlet/velocity/projectmodals.vm b/azkaban-web-server/src/main/resources/azkaban/webapp/servlet/velocity/projectmodals.vm index 637408a300..3350ace4f2 100644 --- a/azkaban-web-server/src/main/resources/azkaban/webapp/servlet/velocity/projectmodals.vm +++ b/azkaban-web-server/src/main/resources/azkaban/webapp/servlet/velocity/projectmodals.vm @@ -77,7 +77,9 @@