NIFI-2678: - Ensuring the most recent version of each component is save for rendering on the canvas.

This closes #979.

Signed-off-by: Bryan Bende <bbende@apache.org>
This commit is contained in:
Matt Gilman 2016-08-31 15:03:47 -04:00 committed by Bryan Bende
parent 9e10371c8a
commit 96a766464c
No known key found for this signature in database
GPG Key ID: A0DDA9ED50711C39
8 changed files with 154 additions and 52 deletions

View File

@ -1582,17 +1582,29 @@ nf.Connection = (function () {
transition = nf.Common.isDefinedAndNotNull(options.transition) ? options.transition : transition;
}
var set = function (connectionEntity) {
// add the connection
connectionMap.set(connectionEntity.id, $.extend({
type: 'Connection'
}, connectionEntity));
var set = function (proposedConnectionEntity) {
var currentConnectionEntity = connectionMap.get(proposedConnectionEntity.id);
// set the connection if appropriate
if (nf.Client.isNewerRevision(currentConnectionEntity, proposedConnectionEntity)) {
connectionMap.set(proposedConnectionEntity.id, $.extend({
type: 'Connection'
}, proposedConnectionEntity));
}
};
// determine how to handle the specified connection
if ($.isArray(connectionEntities)) {
$.each(connectionMap.keys(), function (_, key) {
connectionMap.remove(key);
var currentConnectionEntity = connectionMap.get(key);
var isPresent = $.grep(connectionEntities, function (proposedConnectionEntity) {
return proposedConnectionEntity.id === currentConnectionEntity.id;
});
// if the current connection is not present, remove it
if (isPresent.length === 0) {
connectionMap.remove(key);
}
});
$.each(connectionEntities, function (_, connectionEntity) {
set(connectionEntity);

View File

@ -218,18 +218,29 @@ nf.Funnel = (function () {
transition = nf.Common.isDefinedAndNotNull(options.transition) ? options.transition : transition;
}
var set = function (funnelEntity) {
// add the funnel
funnelMap.set(funnelEntity.id, $.extend({
type: 'Funnel',
dimensions: dimensions
}, funnelEntity));
var set = function (proposedFunnelEntity) {
var currentFunnelEntity = funnelMap.get(proposedFunnelEntity.id);
// set the funnel if appropriate
if (nf.Client.isNewerRevision(currentFunnelEntity, proposedFunnelEntity)) {
funnelMap.set(proposedFunnelEntity.id, $.extend({
type: 'Funnel',
dimensions: dimensions
}, proposedFunnelEntity));
}
};
// determine how to handle the specified funnel status
if ($.isArray(funnelEntities)) {
$.each(funnelMap.keys(), function (_, key) {
funnelMap.remove(key);
var currentFunnelEntity = funnelMap.get(key);
var isPresent = $.grep(funnelEntities, function (proposedFunnelEntity) {
return proposedFunnelEntity.id === currentFunnelEntity.id;
});
// if the current funnel is not present, remove it
if (isPresent.length === 0) {
funnelMap.remove(key);
}
});
$.each(funnelEntities, function (_, funnelEntity) {
set(funnelEntity);

View File

@ -399,17 +399,28 @@ nf.Label = (function () {
transition = nf.Common.isDefinedAndNotNull(options.transition) ? options.transition : transition;
}
var set = function (labelEntity) {
// add the label
labelMap.set(labelEntity.id, $.extend({
type: 'Label'
}, labelEntity));
var set = function (proposedLabelEntity) {
var currentLabelEntity = labelMap.get(proposedLabelEntity.id);
// set the processor if appropriate
if (nf.Client.isNewerRevision(currentLabelEntity, proposedLabelEntity)) {
labelMap.set(proposedLabelEntity.id, $.extend({
type: 'Label'
}, proposedLabelEntity));
}
};
// determine how to handle the specified label status
if ($.isArray(labelEntities)) {
$.each(labelMap.keys(), function (_, key) {
labelMap.remove(key);
var currentLabelEntity = labelMap.get(key);
var isPresent = $.grep(labelEntities, function (proposedLabelEntity) {
return proposedLabelEntity.id === currentLabelEntity.id;
});
// if the current label is not present, remove it
if (isPresent.length === 0) {
labelMap.remove(key);
}
});
$.each(labelEntities, function (_, labelEntity) {
set(labelEntity);

View File

@ -540,21 +540,34 @@ nf.Port = (function () {
dimensions = remotePortDimensions;
}
var set = function (portEntity) {
// add the port
portMap.set(portEntity.id, $.extend({
type: 'Port',
dimensions: dimensions,
status: {
activeThreadCount: 0
}
}, portEntity));
var set = function (proposedPortEntity) {
var currentPortEntity = portMap.get(proposedPortEntity.id);
// set the port if appropriate
if (nf.Client.isNewerRevision(currentPortEntity, proposedPortEntity)) {
// add the port
portMap.set(proposedPortEntity.id, $.extend({
type: 'Port',
dimensions: dimensions,
status: {
activeThreadCount: 0
}
}, proposedPortEntity));
}
};
// determine how to handle the specified port status
if ($.isArray(portEntities)) {
$.each(portMap.keys(), function (_, key) {
portMap.remove(key);
var currentPortEntity = portMap.get(key);
var isPresent = $.grep(portEntities, function (proposedPortEntity) {
return proposedPortEntity.id === currentPortEntity.id;
});
// if the current port is not present, remove it
if (isPresent.length === 0) {
portMap.remove(key);
}
});
$.each(portEntities, function (_, portNode) {
set(portNode);

View File

@ -1018,18 +1018,30 @@ nf.ProcessGroup = (function () {
transition = nf.Common.isDefinedAndNotNull(options.transition) ? options.transition : transition;
}
var set = function (processGroupEntity) {
// add the process group
processGroupMap.set(processGroupEntity.id, $.extend({
type: 'ProcessGroup',
dimensions: dimensions
}, processGroupEntity));
var set = function (proposedProcessGroupEntity) {
var currentProcessGroupEntity = processGroupMap.get(proposedProcessGroupEntity.id);
// set the process group if appropriate
if (nf.Client.isNewerRevision(currentProcessGroupEntity, proposedProcessGroupEntity)) {
processGroupMap.set(proposedProcessGroupEntity.id, $.extend({
type: 'ProcessGroup',
dimensions: dimensions
}, proposedProcessGroupEntity));
}
};
// determine how to handle the specified process groups
if ($.isArray(processGroupEntities)) {
$.each(processGroupMap.keys(), function (_, key) {
processGroupMap.remove(key);
var currentProcessGroupEntity = processGroupMap.get(key);
var isPresent = $.grep(processGroupEntities, function (proposedProcessGroupEntity) {
return proposedProcessGroupEntity.id === currentProcessGroupEntity.id;
});
// if the current process group is not present, remove it
if (isPresent.length === 0) {
processGroupMap.remove(key);
}
});
$.each(processGroupEntities, function (_, processGroupEntity) {
set(processGroupEntity);

View File

@ -791,18 +791,30 @@ nf.Processor = (function () {
transition = nf.Common.isDefinedAndNotNull(options.transition) ? options.transition : transition;
}
var set = function (processorEntity) {
// add the processor
processorMap.set(processorEntity.id, $.extend({
type: 'Processor',
dimensions: dimensions
}, processorEntity));
var set = function (proposedProcessorEntity) {
var currentProcessorEntity = processorMap.get(proposedProcessorEntity.id);
// set the processor if appropriate
if (nf.Client.isNewerRevision(currentProcessorEntity, proposedProcessorEntity)) {
processorMap.set(proposedProcessorEntity.id, $.extend({
type: 'Processor',
dimensions: dimensions
}, proposedProcessorEntity));
}
};
// determine how to handle the specified processor
if ($.isArray(processorEntities)) {
$.each(processorMap.keys(), function (_, key) {
processorMap.remove(key);
var currentProcessorEntity = processorMap.get(key);
var isPresent = $.grep(processorEntities, function (proposedProcessorEntity) {
return proposedProcessorEntity.id === currentProcessorEntity.id;
});
// if the current processor is not present, remove it
if (isPresent.length === 0) {
processorMap.remove(key);
}
});
$.each(processorEntities, function (_, processorEntity) {
set(processorEntity);

View File

@ -872,18 +872,30 @@ nf.RemoteProcessGroup = (function () {
transition = nf.Common.isDefinedAndNotNull(options.transition) ? options.transition : transition;
}
var set = function (remoteProcessGroupEntity) {
// add the remote process group
remoteProcessGroupMap.set(remoteProcessGroupEntity.id, $.extend({
type: 'RemoteProcessGroup',
dimensions: dimensions
}, remoteProcessGroupEntity));
var set = function (proposedRemoteProcessGroupEntity) {
var currentRemoteProcessGroupEntity = remoteProcessGroupMap.get(proposedRemoteProcessGroupEntity.id);
// set the remote process group if appropriate
if (nf.Client.isNewerRevision(currentRemoteProcessGroupEntity, proposedRemoteProcessGroupEntity)) {
remoteProcessGroupMap.set(proposedRemoteProcessGroupEntity.id, $.extend({
type: 'RemoteProcessGroup',
dimensions: dimensions
}, proposedRemoteProcessGroupEntity));
}
};
// determine how to handle the specified remote process groups
if ($.isArray(remoteProcessGroupEntities)) {
$.each(remoteProcessGroupMap.keys(), function (_, key) {
remoteProcessGroupMap.remove(key);
var currentRemoteProcessGroupEntity = remoteProcessGroupMap.get(key);
var isPresent = $.grep(remoteProcessGroupEntities, function (proposedRemoteProcessGroupEntity) {
return proposedRemoteProcessGroupEntity.id === currentRemoteProcessGroupEntity.id;
});
// if the current remote process group is not present, remove it
if (isPresent.length === 0) {
remoteProcessGroupMap.remove(key);
}
});
$.each(remoteProcessGroupEntities, function (_, remoteProcessGroupEntity) {
set(remoteProcessGroupEntity);

View File

@ -45,6 +45,25 @@ nf.Client = (function() {
'clientId': clientId,
'version': d.revision.version
};
},
/**
* Determines whether the proposedData is newer than the currentData.
*
* @param currentData Maybe be null, if the proposedData is new to this canvas
* @param proposedData Maybe not be null
* @return {boolean} whether proposedData is newer than currentData
*/
isNewerRevision: function (currentData, proposedData) {
if (nf.Common.isDefinedAndNotNull(currentData)) {
var currentRevision = currentData.revision;
var proposedRevision = proposedData.revision;
// return whether the proposed revision is newer
return proposedRevision.version > currentRevision.version;
} else {
return true;
}
}
};
}());