NIFI-8430: Close Atlas client in order to free up resources

This closes #5002

Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
Peter Turcsanyi 2021-04-14 21:23:14 +02:00 committed by exceptionfactory
parent 8c66049d1d
commit 2fb05cd8dc
No known key found for this signature in database
GPG Key ID: 29B6A52D2AAE8DBA
2 changed files with 37 additions and 32 deletions

View File

@ -74,7 +74,7 @@ import static org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_INPUT_PORT;
import static org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_OUTPUT_PORT;
import static org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_QUEUE;
public class NiFiAtlasClient {
public class NiFiAtlasClient implements AutoCloseable {
private static final Logger logger = LoggerFactory.getLogger(NiFiAtlasClient.class);
@ -84,6 +84,11 @@ public class NiFiAtlasClient {
this.atlasClient = atlasClient;
}
@Override
public void close() {
atlasClient.close();
}
/**
* This is an utility method to delete unused types.
* Should be used during development or testing only.

View File

@ -814,7 +814,7 @@ public class ReportLineageToAtlas extends AbstractReportingTask {
// If standalone or being primary node in a NiFi cluster, this node is responsible for doing primary tasks.
final boolean isResponsibleForPrimaryTasks = !isClustered || getNodeTypeProvider().isPrimary();
final NiFiAtlasClient atlasClient = createNiFiAtlasClient(context);
try (final NiFiAtlasClient atlasClient = createNiFiAtlasClient(context)) {
// Create Entity defs in Atlas if there's none yet.
if (!isTypeDefCreated) {
@ -853,7 +853,7 @@ public class ReportLineageToAtlas extends AbstractReportingTask {
// then the notification message will fail due to having a reference to a non-existing entity.
nifiAtlasHook.setAtlasClient(atlasClient);
consumeNiFiProvenanceEvents(context, nifiFlow);
}
}
private NiFiFlow createNiFiFlow(ReportingContext context, NiFiAtlasClient atlasClient) {