Repository: incubator-nifi Updated Branches: refs/heads/NIFI-250 2211741ca -> 74d45aefb
NIFI-250: - Adding methods to obtain all reporting tasks. - Adding parameters to update the scheduled state of a reporting task. - Adding action buttons to the reporting task table. Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/74d45aef Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/74d45aef Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/74d45aef Branch: refs/heads/NIFI-250 Commit: 74d45aefbf6f74b04cd23808e4bb866cce027dc9 Parents: 2211741 Author: Matt Gilman <[email protected]> Authored: Wed Mar 11 15:26:45 2015 -0400 Committer: Matt Gilman <[email protected]> Committed: Wed Mar 11 15:26:45 2015 -0400 ---------------------------------------------------------------------- .../cluster/manager/impl/WebClusterManager.java | 9 +- .../reporting/ReportingTaskProvider.java | 6 ++ .../apache/nifi/controller/FlowController.java | 5 +- .../nifi/controller/StandardFlowSerializer.java | 2 +- .../nifi/web/api/ReportingTaskResource.java | 4 +- .../web/dao/impl/StandardReportingTaskDAO.java | 90 ++++++++++++++++++-- .../src/main/webapp/js/nf/canvas/nf-settings.js | 22 +++-- 7 files changed, 111 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/74d45aef/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManager.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManager.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManager.java index 94541e5..b5f3647 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManager.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManager.java @@ -1447,7 +1447,7 @@ public class WebClusterManager implements HttpClusterManager, ProtocolHandler, C final Element rootElement = document.createElement("reportingTasks"); document.appendChild(rootElement); - for ( final ReportingTaskNode taskNode : getReportingTasks() ) { + for ( final ReportingTaskNode taskNode : getAllReportingTasks() ) { StandardFlowSerializer.addReportingTask(rootElement, taskNode, encryptor); } @@ -1483,8 +1483,8 @@ public class WebClusterManager implements HttpClusterManager, ProtocolHandler, C } } - - public Set<ReportingTaskNode> getReportingTasks() { + @Override + public Set<ReportingTaskNode> getAllReportingTasks() { readLock.lock(); try { return new HashSet<>(reportingTasks.values()); @@ -1492,8 +1492,7 @@ public class WebClusterManager implements HttpClusterManager, ProtocolHandler, C readLock.unlock("getReportingTasks"); } } - - + public ReportingTaskNode getReportingTaskNode(final String taskId) { readLock.lock(); try { http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/74d45aef/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/reporting/ReportingTaskProvider.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/reporting/ReportingTaskProvider.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/reporting/ReportingTaskProvider.java index c58115f..ddd9d1a 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/reporting/ReportingTaskProvider.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/reporting/ReportingTaskProvider.java @@ -16,6 +16,7 @@ */ package org.apache.nifi.controller.reporting; +import java.util.Set; import org.apache.nifi.controller.ReportingTaskNode; /** @@ -47,6 +48,11 @@ public interface ReportingTaskProvider { */ ReportingTaskNode getReportingTaskNode(String identifier); + /** + * Returns a Set of all Reporting Tasks that exist for this service provider. + * @return + */ + Set<ReportingTaskNode> getAllReportingTasks(); /** * Removes the given reporting task from the flow http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/74d45aef/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java index f6e9aae..6173014 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java @@ -2568,8 +2568,9 @@ public class FlowController implements EventAccess, ControllerServiceProvider, R reportingTasks.remove(reportingTaskNode.getIdentifier()); } - Collection<ReportingTaskNode> getReportingTasks() { - return reportingTasks.values(); + @Override + public Set<ReportingTaskNode> getAllReportingTasks() { + return new HashSet<>(reportingTasks.values()); } @Override http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/74d45aef/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowSerializer.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowSerializer.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowSerializer.java index 832df7c..7cd9d3b 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowSerializer.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowSerializer.java @@ -89,7 +89,7 @@ public class StandardFlowSerializer implements FlowSerializer { final Element reportingTasksNode = doc.createElement("reportingTasks"); rootNode.appendChild(reportingTasksNode); - for ( final ReportingTaskNode taskNode : controller.getReportingTasks() ) { + for ( final ReportingTaskNode taskNode : controller.getAllReportingTasks() ) { addReportingTask(reportingTasksNode, taskNode, encryptor); } http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/74d45aef/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ReportingTaskResource.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ReportingTaskResource.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ReportingTaskResource.java index 09f5217..aae1afc 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ReportingTaskResource.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ReportingTaskResource.java @@ -344,6 +344,7 @@ public class ReportingTaskResource extends ApplicationResource { * @param name The name of the reporting task * @param annotationData The annotation data for the reporting task * @param markedForDeletion Array of property names whose value should be removed. + * @param state The updated scheduled state * @param formParams Additionally, the processor properties and styles are * specified in the form parameters. Because the property names and styles * differ from processor to processor they are specified in a map-like @@ -372,7 +373,7 @@ public class ReportingTaskResource extends ApplicationResource { @FormParam(CLIENT_ID) @DefaultValue(StringUtils.EMPTY) ClientIdParameter clientId, @PathParam("availability") String availability, @PathParam("id") String id, @FormParam("name") String name, @FormParam("annotationData") String annotationData, @FormParam("markedForDeletion[]") List<String> markedForDeletion, - MultivaluedMap<String, String> formParams) { + @FormParam("state") String state, MultivaluedMap<String, String> formParams) { // create collections for holding the reporting task properties final Map<String, String> updatedProperties = new LinkedHashMap<>(); @@ -402,6 +403,7 @@ public class ReportingTaskResource extends ApplicationResource { final ReportingTaskDTO reportingTaskDTO = new ReportingTaskDTO(); reportingTaskDTO.setId(id); reportingTaskDTO.setName(name); + reportingTaskDTO.setState(state); reportingTaskDTO.setAnnotationData(annotationData); // only set the properties when appropriate http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/74d45aef/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardReportingTaskDAO.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardReportingTaskDAO.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardReportingTaskDAO.java index aa4e034..0bdbe42 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardReportingTaskDAO.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardReportingTaskDAO.java @@ -17,16 +17,17 @@ package org.apache.nifi.web.dao.impl; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.RejectedExecutionException; import org.apache.nifi.controller.FlowController; import org.apache.nifi.controller.ReportingTaskNode; +import org.apache.nifi.controller.ScheduledState; +import org.apache.nifi.controller.exception.ProcessorLifeCycleException; import org.apache.nifi.controller.exception.ValidationException; import org.apache.nifi.controller.reporting.ReportingTaskInstantiationException; -import org.apache.nifi.controller.reporting.ReportingTaskProvider; import org.apache.nifi.web.NiFiCoreException; import org.apache.nifi.web.ResourceNotFoundException; import org.apache.nifi.web.api.dto.ReportingTaskDTO; @@ -34,7 +35,7 @@ import org.apache.nifi.web.dao.ReportingTaskDAO; public class StandardReportingTaskDAO extends ComponentDAO implements ReportingTaskDAO { - private ReportingTaskProvider reportingTaskProvider; + private FlowController reportingTaskProvider; /** * Locates the specified reporting task. @@ -107,7 +108,7 @@ public class StandardReportingTaskDAO extends ComponentDAO implements ReportingT */ @Override public Set<ReportingTaskNode> getReportingTasks() { - return new HashSet<>(); + return reportingTaskProvider.getAllReportingTasks(); } /** @@ -119,17 +120,54 @@ public class StandardReportingTaskDAO extends ComponentDAO implements ReportingT @Override public ReportingTaskNode updateReportingTask(final ReportingTaskDTO reportingTaskDTO) { // get the reporting task - final ReportingTaskNode controllerService = locateReportingTask(reportingTaskDTO.getId()); + final ReportingTaskNode reportingTask = locateReportingTask(reportingTaskDTO.getId()); // ensure we can perform the update - verifyUpdate(controllerService, reportingTaskDTO); + verifyUpdate(reportingTask, reportingTaskDTO); // perform the update - configureReportingTask(controllerService, reportingTaskDTO); + configureReportingTask(reportingTask, reportingTaskDTO); // configure scheduled state + // see if an update is necessary + if (isNotNull(reportingTaskDTO.getState())) { + final ScheduledState purposedScheduledState = ScheduledState.valueOf(reportingTaskDTO.getState()); + + // only attempt an action if it is changing + if (!purposedScheduledState.equals(reportingTask.getScheduledState())) { + try { + // perform the appropriate action + switch (purposedScheduledState) { + case RUNNING: + reportingTaskProvider.startReportingTask(reportingTask); + break; + case STOPPED: + switch (reportingTask.getScheduledState()) { + case RUNNING: + reportingTaskProvider.stopReportingTask(reportingTask); + break; + case DISABLED: + reportingTaskProvider.enableReportingTask(reportingTask); + break; + } + break; + case DISABLED: + reportingTaskProvider.disableReportingTask(reportingTask); + break; + } + } catch (IllegalStateException | ProcessorLifeCycleException ise) { + throw new NiFiCoreException(ise.getMessage(), ise); + } catch (RejectedExecutionException ree) { + throw new NiFiCoreException("Unable to schedule all tasks for the specified reporting task.", ree); + } catch (NullPointerException npe) { + throw new NiFiCoreException("Unable to update reporting task run state.", npe); + } catch (Exception e) { + throw new NiFiCoreException("Unable to update reporting task run state: " + e, e); + } + } + } - return controllerService; + return reportingTask; } /** @@ -163,6 +201,40 @@ public class StandardReportingTaskDAO extends ComponentDAO implements ReportingT * @param reportingTaskDTO */ private void verifyUpdate(final ReportingTaskNode reportingTask, final ReportingTaskDTO reportingTaskDTO) { + // ensure the state, if specified, is valid + if (isNotNull(reportingTaskDTO.getState())) { + try { + final ScheduledState purposedScheduledState = ScheduledState.valueOf(reportingTaskDTO.getState()); + + // only attempt an action if it is changing + if (!purposedScheduledState.equals(reportingTask.getScheduledState())) { + // perform the appropriate action + switch (purposedScheduledState) { + case RUNNING: + reportingTask.verifyCanStart(); + break; + case STOPPED: + switch (reportingTask.getScheduledState()) { + case RUNNING: + reportingTask.verifyCanStop(); + break; + case DISABLED: + reportingTask.verifyCanEnable(); + break; + } + break; + case DISABLED: + reportingTask.verifyCanDisable(); + break; + } + } + } catch (IllegalArgumentException iae) { + throw new IllegalArgumentException(String.format( + "The specified reporting task state (%s) is not valid. Valid options are 'RUNNING', 'STOPPED', and 'DISABLED'.", + reportingTaskDTO.getState())); + } + } + boolean modificationRequest = false; if (isAnyNotNull(reportingTaskDTO.getName(), reportingTaskDTO.getAnnotationData(), @@ -226,7 +298,7 @@ public class StandardReportingTaskDAO extends ComponentDAO implements ReportingT /* setters */ - public void setReportingTaskProvider(ReportingTaskProvider reportingTaskProvider) { + public void setReportingTaskProvider(FlowController reportingTaskProvider) { this.reportingTaskProvider = reportingTaskProvider; } } http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/74d45aef/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-settings.js ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-settings.js b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-settings.js index faed3cc..0353e27 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-settings.js +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-settings.js @@ -1313,17 +1313,17 @@ nf.Settings = (function () { var reportingTaskActionFormatter = function (row, cell, value, columnDef, dataContext) { var markup = ''; - if (dataContext.state === 'ENABLED' || dataContext.state === 'ENABLING') { - markup += '<img src="images/iconDisable.png" title="Disable" class="pointer disable-controller-service" style="margin-top: 2px;" /> '; - } else if (dataContext.state === 'DISABLED') { - markup += '<img src="images/iconEdit.png" title="Edit" class="pointer edit-controller-service" style="margin-top: 2px;" /> '; - - // only enable the enable icon if the service has no validation errors + if (dataContext.state === 'RUNNING') { + markup += '<img src="images/iconStop.png" title="Stop" class="pointer stop-reporting-task" style="margin-top: 2px;" /> '; + } else if (dataContext.state === 'STOPPED') { + markup += '<img src="images/iconEdit.png" title="Edit" class="pointer edit-reporting-task" style="margin-top: 2px;" /> '; + + // only enable the start icon if the reporting task has no validation errors if (nf.Common.isEmpty(dataContext.validationErrors)) { - markup += '<img src="images/iconEnable.png" title="Enable" class="pointer enable-controller-service" style="margin-top: 2px;"/> '; + markup += '<img src="images/iconRun.png" title="Start" class="pointer start-reporting-task" style="margin-top: 2px;"/> '; } - - markup += '<img src="images/iconDelete.png" title="Remove" class="pointer delete-controller-service" style="margin-top: 2px;" /> '; + + markup += '<img src="images/iconDelete.png" title="Remove" class="pointer delete-reporting-task" style="margin-top: 2px;" /> '; } return markup; @@ -1366,9 +1366,13 @@ nf.Settings = (function () { // determine the desired action if (reportingTasksGrid.getColumns()[args.cell].id === 'actions') { if (target.hasClass('edit-reporting-task')) { + nf.ReportingTask.showConfiguration(reportingTask); } else if (target.hasClass('start-reporting-task')) { + nf.ReportingTask.start(reportingTask); } else if (target.hasClass('stop-reporting-task')) { + nf.ReportingTask.stop(reportingTask); } else if (target.hasClass('delete-reporting-task')) { + nf.ReportingTask.remove(reportingTask); } } else if (reportingTasksGrid.getColumns()[args.cell].id === 'moreDetails') { if (target.hasClass('view-reporting-task')) {
