NIFI-427: Allow Process Groups to be deleted as long as no incoming or outgoing connections (unless they are also selected), all components stopped, no FlowFiles queued

This commit is contained in:
Mark Payne 2015-06-05 12:59:15 -04:00
parent 8d1536ed24
commit 5c1afc0897
2 changed files with 75 additions and 24 deletions

View File

@ -641,6 +641,17 @@ public interface ProcessGroup {
void verifyCanDelete();
/**
* Ensures that the ProcessGroup is eligible to be deleted.
*
* @param ignorePortConnections if true, the Connections that are currently connected to Ports
* will be ignored. Otherwise, the ProcessGroup is not eligible for deletion if its input ports
* or output ports have any connections
*
* @throws IllegalStateException if the ProcessGroup is not eligible for deletion
*/
void verifyCanDelete(boolean ignorePortConnections);
void verifyCanStart();
void verifyCanStop();

View File

@ -548,9 +548,7 @@ public final class StandardProcessGroup implements ProcessGroup {
@Override
public void removeProcessGroup(final ProcessGroup group) {
if (!requireNonNull(group).isEmpty()) {
throw new IllegalStateException("Cannot remove " + group + " because it is not empty");
}
requireNonNull(group).verifyCanDelete();
writeLock.lock();
try {
@ -558,7 +556,7 @@ public final class StandardProcessGroup implements ProcessGroup {
if (toRemove == null) {
throw new IllegalStateException(group + " is not a member of this Process Group");
}
verifyCanRemove(toRemove);
toRemove.verifyCanDelete();
processGroups.remove(group.getIdentifier());
@ -568,12 +566,6 @@ public final class StandardProcessGroup implements ProcessGroup {
}
}
private void verifyCanRemove(final ProcessGroup childGroup) {
if (!childGroup.isEmpty()) {
throw new IllegalStateException("Cannot remove ProcessGroup because it is not empty");
}
}
@Override
public void addRemoteProcessGroup(final RemoteProcessGroup remoteGroup) {
writeLock.lock();
@ -1646,9 +1638,7 @@ public final class StandardProcessGroup implements ProcessGroup {
// verify that all of the ProcessGroups in the snippet are empty
for (final String groupId : snippet.getProcessGroups()) {
final ProcessGroup toRemove = getProcessGroup(groupId);
if (!toRemove.isEmpty()) {
throw new IllegalStateException("Process Group with name " + toRemove.getName() + " cannot be removed because it is not empty");
}
toRemove.verifyCanDelete(true);
}
for (final String id : connectionIdsToRemove) {
@ -1666,15 +1656,15 @@ public final class StandardProcessGroup implements ProcessGroup {
for (final String id : replaceNullWithEmptySet(snippet.getLabels())) {
removeLabel(labels.get(id));
}
for (final String id : replaceNullWithEmptySet(snippet.getProcessGroups())) {
removeProcessGroup(processGroups.get(id));
}
for (final String id : replaceNullWithEmptySet(snippet.getProcessors())) {
removeProcessor(processors.get(id));
}
for (final String id : replaceNullWithEmptySet(snippet.getRemoteProcessGroups())) {
removeRemoteProcessGroup(remoteGroups.get(id));
}
for (final String id : replaceNullWithEmptySet(snippet.getProcessGroups())) {
removeProcessGroup(processGroups.get(id));
}
} finally {
writeLock.unlock();
}
@ -1850,8 +1840,58 @@ public final class StandardProcessGroup implements ProcessGroup {
@Override
public void verifyCanDelete() {
if (!isEmpty()) {
throw new IllegalStateException(this + " is not empty");
verifyCanDelete(false);
}
@Override
public void verifyCanDelete(final boolean ignoreConnections) {
readLock.lock();
try {
for (final Port port : inputPorts.values()) {
port.verifyCanDelete(true);
}
for (final Port port : outputPorts.values()) {
port.verifyCanDelete(true);
}
for (final ProcessorNode procNode : processors.values()) {
procNode.verifyCanDelete(true);
}
for (final Connection connection : connections.values()) {
connection.verifyCanDelete();
}
for (final ProcessGroup childGroup : processGroups.values()) {
childGroup.verifyCanDelete();
}
if (!ignoreConnections) {
for (final Port port : inputPorts.values()) {
for (final Connection connection : port.getIncomingConnections()) {
if (connection.getSource().equals(port)) {
connection.verifyCanDelete();
} else {
throw new IllegalStateException("Cannot delete Process Group because Input Port " + port +
" has at least one incoming connection from a component outside of the Process Group. Delete this connection first.");
}
}
}
for (final Port port : outputPorts.values()) {
for (final Connection connection : port.getConnections()) {
if (connection.getDestination().equals(port)) {
connection.verifyCanDelete();
} else {
throw new IllegalStateException("Cannot delete Process Group because Output Port " + port +
" has at least one outgoing connection to a component outside of the Process Group. Delete this connection first.");
}
}
}
}
} finally {
readLock.unlock();
}
}
@ -1936,7 +1976,7 @@ public final class StandardProcessGroup implements ProcessGroup {
if (group == null) {
throw new IllegalStateException("Snippet references Process Group with ID " + id + ", which does not exist in this ProcessGroup");
}
group.verifyCanDelete();
group.verifyCanDelete(true);
}
for (final String id : snippet.getProcessors()) {