NIFI-250: - Only showing the enable button when the controller service is valid. - Adding polling during deactivation of controller service references to know when it's ok to attempt to disable the controller service.
Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/e61a01ac Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/e61a01ac Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/e61a01ac Branch: refs/heads/NIFI-250 Commit: e61a01ac6968ba2f1e4f8fa1d3ca9c2cbca400e6 Parents: f22407f Author: Matt Gilman <[email protected]> Authored: Tue Feb 17 14:55:44 2015 -0500 Committer: Matt Gilman <[email protected]> Committed: Tue Feb 17 14:55:44 2015 -0500 ---------------------------------------------------------------------- .../js/nf/canvas/nf-controller-service.js | 110 +++++++++++++++++-- .../src/main/webapp/js/nf/canvas/nf-settings.js | 9 +- 2 files changed, 110 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/e61a01ac/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-controller-service.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-controller-service.js b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-controller-service.js index aa62f79..cd8503e 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-controller-service.js +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-controller-service.js @@ -348,8 +348,89 @@ nf.ControllerService = (function () { }; // updates the referencing components with the specified state - var updateReferencingComponents = function (controllerService, state) { + var updateReferencingComponents = function (controllerService, activated) { + var revision = nf.Client.getRevision(); + + // issue the request to update the referencing components + var updated = $.ajax({ + type: 'PUT', + url: controllerService.uri + '/references', + data: { + clientId: revision.clientId, + version: revision.version, + activated: activated + }, + dataType: 'json' + }).done(function (response) { + // update the revision + nf.Client.setRevision(response.revision); + + // update the service + reloadControllerServiceReferences(controllerService); + }).fail(nf.Common.handleAjaxError); + // if we are activating, we can stop here + if (activated === true) { + return updated; + } + + // since we are deactivating, we want to keep polling until + // everything has stopped and there are 0 active threads + return $.Deferred(function(deferred) { + var current = 1; + var getTimeout = function () { + var val = current; + + // update the current timeout for the next time + current = Math.max(current * 2, 8); + + return val * 1000; + }; + + // polls for the current status of the referencing components + var pollReferencingComponent = function() { + $.ajax({ + type: 'GET', + url: controllerService.uri + '/references', + dataType: 'json' + }).done(function (response) { + checkDeactivated(response.controllerServiceReferencingComponents); + }).fail(function (xhr, status, error) { + deferred.reject(); + nf.Common.handleAjaxError(xhr, status, error); + }); + }; + + // checks the referencing components to see if any are still active + var checkDeactivated = function (controllerServiceReferencingComponents) { + var stillRunning = false; + + $.each(controllerServiceReferencingComponents, function(referencingComponent) { + if (referencingComponent.referenceType === 'ControllerService') { + if (referencingComponent.enable === true) { + stillRunning = true; + return false; + } + } else { + if (referencingComponent.state === 'RUNNING' || referencingComponent.activeThreadCount > 0) { + stillRunning = true; + return false; + } + } + }); + + if (stillRunning) { + setTimeout(pollReferencingComponent(), getTimeout()); + } else { + deferred.resolve(); + } + }; + + // see if the references have already stopped + updated.done(function(response) { + checkDeactivated(response.controllerServiceReferencingComponents); + }); + }).promise(); }; /** @@ -478,11 +559,17 @@ nf.ControllerService = (function () { var controllerServiceData = controllerServiceGrid.getData(); var controllerService = controllerServiceData.getItemById(controllerServiceId); - // disable all referencing components - updateReferencingComponents(controllerService, false); + // deactivate all referencing components + var deactivated = updateReferencingComponents(controllerService, false); - // enable this controller service - setEnabled(controllerService, false); + // once all referencing components have been deactivated... + deactivated.done(function() { + // disable this service + setEnabled(controllerService, false).done(function() { + // close the dialog + $('#disable-controller-service-dialog').modal('hide'); + }); + }); } } }, { @@ -534,13 +621,20 @@ nf.ControllerService = (function () { var controllerServiceData = controllerServiceGrid.getData(); var controllerService = controllerServiceData.getItemById(controllerServiceId); + // enable this controller service + var enabled = setEnabled(controllerService, true); + + // determine if we want to also activate referencing components var scope = $('#enable-controller-service-scope').combo('getSelectedOption').value; if (scope === config.serviceAndReferencingComponents) { - updateReferencingComponents(controllerService, true); + // once the service is enabled, activate all referencing components + enabled.done(function() { + updateReferencingComponents(controllerService, true); + }); } - // enable this controller service - setEnabled(controllerService, true); + // hide the dialog immediately as there's nothing to show + $(this).modal('hide'); } } }, { http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/e61a01ac/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 eef5448..744198f 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 @@ -751,7 +751,14 @@ nf.Settings = (function () { if (dataContext.enabled === true) { markup += '<img src="images/iconDisable.png" title="Disable" class="pointer disable-controller-service" style="margin-top: 2px;" /> '; } else { - markup += '<img src="images/iconEdit.png" title="Edit" class="pointer edit-controller-service" style="margin-top: 2px;" /> <img src="images/iconEnable.png" title="Enable" class="pointer enable-controller-service" style="margin-top: 2px;"/> <img src="images/iconDelete.png" title="Remove" class="pointer delete-controller-service" style="margin-top: 2px;" /> '; + 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 (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/iconDelete.png" title="Remove" class="pointer delete-controller-service" style="margin-top: 2px;" /> '; } return markup;
