From 32c0e2be3b824deaf749278718d9ca35e43e33e3 Mon Sep 17 00:00:00 2001 From: Matt Gilman Date: Thu, 26 Oct 2017 10:27:57 -0400 Subject: [PATCH] NIFI-4518: - When the URI is too long, invoking the bulletin board multiple times for all specified component ids. --- .../webapp/js/nf/canvas/nf-canvas-utils.js | 89 ++++++++++++++++--- .../js/nf/canvas/nf-variable-registry.js | 14 ++- 2 files changed, 89 insertions(+), 14 deletions(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas-utils.js b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas-utils.js index 4ead97b8dc..f9178e2ec6 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas-utils.js +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas-utils.js @@ -65,6 +65,8 @@ } }; + var MAX_URL_LENGTH = 2000; // the maximum (suggested) safe string length of a URL supported by all browsers and application servers + var TWO_PI = 2 * Math.PI; var binarySearch = function (length, comparator) { @@ -245,16 +247,83 @@ * @returns {deferred} */ queryBulletins: function (componentIds) { - var ids = componentIds.join('|'); + var queries = []; - return $.ajax({ - type: 'GET', - url: '../nifi-api/flow/bulletin-board', - data: { - sourceId: ids - }, - dataType: 'json' - }).fail(nfErrorHandler.handleAjaxError); + var query = function (ids) { + var url = new URL(window.location); + var endpoint = url.origin + '/nifi-api/flow/bulletin-board?' + $.param({ + sourceId: ids.join('|') + }); + + if (endpoint.length > MAX_URL_LENGTH) { + // split into two arrays and recurse with both halves + var mid = Math.ceil(ids.length / 2); + + // left half + var left = ids.slice(0, mid); + if (left.length > 0) { + query(left); + } + + // right half + var right = ids.slice(mid); + if (right.length > 0) { + query(right); + } + } else { + queries.push($.ajax({ + type: 'GET', + url: endpoint, + dataType: 'json' + })); + } + }; + + // initiate the queries + query(componentIds); + + if (queries.length === 1) { + // if there was only one query, return it + return queries[0].fail(nfErrorHandler.handleAjaxError); + } else { + // if there were multiple queries, wait for each to complete + return $.Deferred(function (deferred) { + $.when.apply(window, queries).done(function () { + var results = $.makeArray(arguments); + + var generated = null; + var bulletins = []; + + $.each(results, function (_, result) { + var response = result[0]; + var bulletinBoard = response.bulletinBoard; + + // use the first generated timestamp + if (generated === null) { + generated = bulletinBoard.generated; + } + + // build up all the bulletins + Array.prototype.push.apply(bulletins, bulletinBoard.bulletins); + }); + + // sort all the bulletins + bulletins.sort(function (a, b) { + return b.id - a.id; + }); + + // resolve with a aggregated result + deferred.resolve({ + bulletinBoard: { + generated: generated, + bulletins: bulletins + } + }); + }).fail(function () { + deferred.reject(); + }).fail(nfErrorHandler.handleAjaxError); + }).promise(); + } }, /** @@ -418,8 +487,6 @@ } }, - MAX_URL_LENGTH: 2000, // the maximum (suggested) safe string length of a URL supported by all browsers and application servers - /** * Set the parameters of the URL. * diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-variable-registry.js b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-variable-registry.js index 1614632a13..668d1d2088 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-variable-registry.js +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-variable-registry.js @@ -71,6 +71,8 @@ }(this, function ($, d3, Slick, nfCanvas, nfCanvasUtils, nfErrorHandler, nfDialog, nfClient, nfCommon, nfNgBridge, nfProcessor, nfProcessGroup, nfProcessGroupConfiguration) { 'use strict'; + var lastSelectedId = null; + // text editor var textEditor = function (args) { var scope = this; @@ -568,9 +570,15 @@ var variableIndex = args.rows[0]; var variable = variablesGrid.getDataItem(variableIndex); - // update the details for this variable - $('#affected-components-context').removeClass('unset').text(variable.name); - populateAffectedComponents(variable.affectedComponents); + // only populate affected components if this variable is different than the last selected + if (lastSelectedId === null || lastSelectedId !== variable.id) { + // update the details for this variable + $('#affected-components-context').removeClass('unset').text(variable.name); + populateAffectedComponents(variable.affectedComponents); + + // update the last selected id + lastSelectedId = variable.id; + } } } });