adarmiento commented on a change in pull request #3700: NIFI-6638: Empty
multiple queues at once at different flow levels
URL: https://github.com/apache/nifi/pull/3700#discussion_r322242326
##########
File path:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-actions.js
##########
@@ -1086,183 +1497,173 @@
},
/**
- * Deletes the flow files in the specified connection.
+ * Deletes the flow files inside the selected connections.
*
* @param {type} selection
*/
- emptyQueue: function (selection) {
- if (selection.size() !== 1 ||
!nfCanvasUtils.isConnection(selection)) {
- return;
- }
+ emptySelectedQueues: function (selection) {
+ var connections = selection.filter(function (d) {
+ var selectionItem = d3.select(this);
+ return nfCanvasUtils.isConnection(selectionItem);
+ });
+
+ var actionName = selection.size() > 1 ? 'Empty Selected Queues' :
'Empty Selected Queue';
+
+ var dialogContent = selection.size() > 1
+ ? 'Are you sure you want to empty the selected queues? All
FlowFiles waiting at the time of the request will be removed.'
+ : 'Are you sure you want to empty the selected queue? All
FlowFiles waiting at the time of the request will be removed.';
// prompt the user before emptying the queue
nfDialog.showYesNoDialog({
- headerText: 'Empty Queue',
- dialogContent: 'Are you sure you want to empty this queue? All
FlowFiles waiting at the time of the request will be removed.',
+ headerText: actionName,
+ dialogContent: dialogContent,
noText: 'Cancel',
yesText: 'Empty',
yesHandler: function () {
- // get the connection data
- var connection = selection.datum();
-
- var MAX_DELAY = 4;
- var cancelled = false;
- var dropRequest = null;
- var dropRequestTimer = null;
-
- // updates the progress bar
- var updateProgress = function (percentComplete) {
- // remove existing labels
- var progressBar = $('#drop-request-percent-complete');
- progressBar.find('div.progress-label').remove();
- progressBar.find('md-progress-linear').remove();
-
- // update the progress bar
- var label = $('<div
class="progress-label"></div>').text(percentComplete + '%');
-
(nfNgBridge.injector.get('$compile')($('<md-progress-linear ng-cloak
ng-value="' + percentComplete + '" class="md-hue-2" md-mode="determinate"
aria-label="Drop request percent
complete"></md-progress-linear>'))(nfNgBridge.rootScope)).appendTo(progressBar);
- progressBar.append(label);
- };
+ emptyQueues(actionName,connections.data(),undefined);
+ }
+ });
+ },
- // update the button model of the drop request status
dialog
- $('#drop-request-status-dialog').modal('setButtonModel', [{
- buttonText: 'Stop',
- color: {
- base: '#728E9B',
- hover: '#004849',
- text: '#ffffff'
- },
- handler: {
- click: function () {
- cancelled = true;
-
- // we are waiting for the next poll attempt
- if (dropRequestTimer !== null) {
- // cancel it
- clearTimeout(dropRequestTimer);
-
- // cancel the drop request
- completeDropRequest();
- }
- }
- }
- }]);
+ /**
+ * Empty all the queues inside the selected process groups.
+ *
+ * @param {type} selection
+ */
+ emptyProcessGroupsQueues: function (selection) {
+ var selectionSize = selection.size();
+ var connections = [];
+ var errors = [];
+ var actionName = '';
+ var dialogContent = '';
+
+ if(selectionSize === 0) {
+ actionName = 'Empty Current Process Group Queues';
+ dialogContent = 'Are you sure you want to empty all queues
inside the current process group? All FlowFiles waiting at the time of the
request will be removed.';
+ connections = d3.selectAll('g.connection').data();
+
+ if(connections.length === 0) {
+ // display the "no queues to empty" dialog
+ nfDialog.showOkDialog({
+ headerText: actionName,
+ dialogContent: 'No queues to empty.'
+ });
+ return;
+ }
+ }
+ else if(selectionSize === 1) {
+ actionName = 'Empty Selected Process Group Queues';
+ dialogContent = 'Are you sure you want to empty all queues
inside the selected process group? All FlowFiles waiting at the time of the
request will be removed.';
+ }
+ else {
+ actionName = 'Empty Selected Process Groups Queues';
+ dialogContent = 'Are you sure you want to empty all queues
inside the selected process groups? All FlowFiles waiting at the time of the
request will be removed.';
+ }
- // completes the drop request by removing it and showing
how many flowfiles were deleted
- var completeDropRequest = function () {
- // reload the connection status
- nfConnection.reloadStatus(connection.id);
+ // prompt the user before emptying the queue
+ nfDialog.showYesNoDialog({
+ headerText: actionName,
+ dialogContent: dialogContent,
+ noText: 'Cancel',
+ yesText: 'Empty',
+ yesHandler: function () {
+ if(selectionSize === 0) {
+ emptyQueues(actionName,connections,undefined);
+ }
+ else {
+ var processGroupIDs = selection.filter(function (d) {
+ var selectionItem = d3.select(this);
+ return nfCanvasUtils.isProcessGroup(selectionItem);
+ }).data().map(function (selectedProcessGroup) {
+ return selectedProcessGroup.id;
+ });
- // clean up as appropriate
- if (nfCommon.isDefinedAndNotNull(dropRequest)) {
- $.ajax({
- type: 'DELETE',
- url: dropRequest.uri,
- dataType: 'json'
- }).done(function (response) {
- // report the results of this drop request
- dropRequest = response.dropRequest;
-
- // build the results
- var droppedTokens =
dropRequest.dropped.split(/ \/ /);
- var results = $('<div></div>');
- $('<span
class="label"></span>').text(droppedTokens[0]).appendTo(results);
- $('<span></span>').text(' FlowFiles (' +
droppedTokens[1] + ')').appendTo(results);
-
- // if the request did not complete, include
the original
- if (dropRequest.percentCompleted < 100) {
- var originalTokens =
dropRequest.original.split(/ \/ /);
- $('<span class="label"></span>').text('
out of ' + originalTokens[0]).appendTo(results);
- $('<span></span>').text(' (' +
originalTokens[1] + ')').appendTo(results);
- }
- $('<span></span>').text(' were removed from
the queue.').appendTo(results);
+ getProcessGroupsConnections(processGroupIDs,
false).then(function (response) {
+ response.connections.forEach(function (connection)
{
+ connections.push(connection);
+ });
- // if this request failed so the error
- if
(nfCommon.isDefinedAndNotNull(dropRequest.failureReason)) {
-
$('<br/><br/><span></span>').text(dropRequest.failureReason).appendTo(results);
- }
+ response.errorMessages.forEach(function
(errorMessage) {
+ errors.push(errorMessage);
+ });
- // display the results
+ if(connections.length === 0 && errors.length ===
0) {
+ // display the "no queues to empty" dialog
nfDialog.showOkDialog({
- headerText: 'Empty Queue',
- dialogContent: results
+ headerText: actionName,
+ dialogContent: 'No queues to empty.'
});
- }).always(function () {
- $('#drop-request-status-dialog').modal('hide');
- });
- } else {
- // nothing was removed
- nfDialog.showOkDialog({
- headerText: 'Empty Queue',
- dialogContent: 'No FlowFiles were removed.'
- });
-
- // close the dialog
- $('#drop-request-status-dialog').modal('hide');
- }
- };
+ }
+ else {
+ emptyQueues(actionName,connections,errors);
+ }
+ });
+ }
+ }
+ });
+ },
- // process the drop request
- var processDropRequest = function (delay) {
- // update the percent complete
- updateProgress(dropRequest.percentCompleted);
+ emptyProcessGroupsQueuesRecursive: function (selection) {
+ var selectionSize = selection.size();
+ var connections = [];
+ var errors = [];
+ var actionName = '';
+ var dialogContent = '';
+
+ if(selectionSize === 0) {
+ actionName = 'Empty Current Process Group Queues (Recursive)';
+ dialogContent = 'Are you sure you want to empty all queues
inside the current process group and all its sub process groups (recursive)?
All FlowFiles waiting at the time of the request will be removed.';
+ connections = d3.selectAll('g.connection').data();
+ }
+ else if(selectionSize === 1) {
+ actionName = 'Empty Selected Process Group Queues (Recursive)';
+ dialogContent = 'Are you sure you want to empty all queues
inside the selected process group and all its sub process groups (recursive)?
All FlowFiles waiting at the time of the request will be removed.';
+ }
+ else {
+ actionName = 'Empty Selected Process Groups Queues
(Recursive)';
+ dialogContent = 'Are you sure you want to empty all queues
inside the selected process groups and all their sub process groups
(recursive)? All FlowFiles waiting at the time of the request will be removed.';
+ }
- // update the status of the drop request
-
$('#drop-request-status-message').text(dropRequest.state);
+ // prompt the user before emptying the queue
+ nfDialog.showYesNoDialog({
+ headerText: actionName,
+ dialogContent: dialogContent,
+ noText: 'Cancel',
+ yesText: 'Empty',
+ yesHandler: function () {
+ var processGroupIDs = selectionSize === 0
+ ?
+ d3.selectAll('g.process-group')
+ .data()
+ .map(function (processGroup) {
+ return processGroup.id;
+ })
+ :
+ selection.filter(function (d) {
+ var selectionItem = d3.select(this);
+ return nfCanvasUtils.isProcessGroup(selectionItem);
+ }).data().map(function (selectedProcessGroup) {
+ return selectedProcessGroup.id;
+ });
- // close the dialog if the
- if (dropRequest.finished === true || cancelled ===
true) {
- completeDropRequest();
- } else {
- // wait delay to poll again
- dropRequestTimer = setTimeout(function () {
- // clear the drop request timer
- dropRequestTimer = null;
-
- // schedule to poll the status again in
nextDelay
- pollDropRequest(Math.min(MAX_DELAY, delay *
2));
- }, delay * 1000);
- }
- };
+ getProcessGroupsConnections(processGroupIDs,
true).then(function (response) {
+ response.connections.forEach(function (connection) {
+ connections.push(connection);
+ });
- // schedule for the next poll iteration
- var pollDropRequest = function (nextDelay) {
- $.ajax({
- type: 'GET',
- url: dropRequest.uri,
- dataType: 'json'
- }).done(function (response) {
- dropRequest = response.dropRequest;
- processDropRequest(nextDelay);
- }).fail(function (xhr, status, error) {
- if (xhr.status === 403) {
- nfErrorHandler.handleAjaxError(xhr, status,
error);
- } else {
- completeDropRequest()
- }
+ response.errorMessages.forEach(function (errorMessage)
{
+ errors.push(errorMessage);
});
- };
- // issue the request to delete the flow files
- $.ajax({
- type: 'POST',
- url: '../nifi-api/flowfile-queues/' +
encodeURIComponent(connection.id) + '/drop-requests',
- dataType: 'json',
- contentType: 'application/json'
- }).done(function (response) {
- // initialize the progress bar value
- updateProgress(0);
-
- // show the progress dialog
- $('#drop-request-status-dialog').modal('show');
-
- // process the drop request
- dropRequest = response.dropRequest;
- processDropRequest(1);
- }).fail(function (xhr, status, error) {
- if (xhr.status === 403) {
- nfErrorHandler.handleAjaxError(xhr, status, error);
- } else {
- completeDropRequest()
+ if(connections.length === 0 && errors.length === 0) {
Review comment:
```suggestion
if (connections.length === 0 && errors.length === 0)
{
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services