Gracefully cleaning up the helix manager to avoid stale zookeeper connections
@@ -49,6 +49,17 @@ public class WorkflowCancellationTask extends AbstractTask {
} catch (Exception e) {
logger.error("Failed to build Helix Task driver in " + taskName, e);
throw new RuntimeException("Failed to build Helix Task driver in " + taskName, e);
+ } finally {
+
+ try {
+ if (helixManager != null) {
+ if (helixManager.isConnected()) {
+ helixManager.disconnect();
+ }
+ }
+ } catch (Exception e) {
+ logger.warn("Failed to disconnect helix manager", e);
+ }
}
}
@@ -56,6 +67,7 @@ public class WorkflowCancellationTask extends AbstractTask {
public TaskResult onRun(TaskHelper helper) {
logger.info("Cancelling workflow " + cancellingWorkflowName);
+ try {
if (taskDriver.getWorkflowConfig(cancellingWorkflowName) == null) {
// Workflow could be already deleted by cleanup agents
logger.warn("Can not find a workflow with name " + cancellingWorkflowName + " but continuing");
@@ -94,6 +106,8 @@ public class WorkflowCancellationTask extends AbstractTask {
logger.warn("Failed while watching workflow to stop " + cancellingWorkflowName, e);
return onSuccess("Failed while watching workflow to stop " + cancellingWorkflowName + ". But continuing");
+ }
+
} finally {
try {
