NIFI-4518:

- When the URI is too long, invoking the bulletin board multiple times for all specified component ids.
This commit is contained in:
Matt Gilman 2017-10-26 10:27:57 -04:00
parent 10f27cd5f0
commit 32c0e2be3b
No known key found for this signature in database
GPG Key ID: DF61EC19432AEE37
2 changed files with 89 additions and 14 deletions

View File

@ -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({
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: '../nifi-api/flow/bulletin-board',
data: {
sourceId: ids
},
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.
*

View File

@ -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);
// 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;
}
}
}
});