This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 292
instance termination plugin support #1134
Open
adyach
wants to merge
3
commits into
master
Choose a base branch
from
termination-notification
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/org/zalando/nakadi/plugin/DefaultTerminationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.zalando.nakadi.plugin; | ||
|
||
import org.zalando.nakadi.plugin.api.exceptions.PluginException; | ||
|
||
public class DefaultTerminationService implements TerminationService { | ||
|
||
public void register(final TerminationListener terminationRunnable) { | ||
// skip implementation for the local setup | ||
} | ||
|
||
boolean isTerminating() throws PluginException { | ||
return false; | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/zalando/nakadi/plugin/DefaultTerminationServiceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.zalando.nakadi.plugin; | ||
|
||
import org.zalando.nakadi.plugin.api.SystemProperties; | ||
|
||
public class DefaultTerminationServiceFactory { | ||
|
||
public DefaultTerminationService init(final SystemProperties systemProperties) { | ||
return new DefaultTerminationService(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
import org.zalando.nakadi.domain.Subscription; | ||
import org.zalando.nakadi.exceptions.runtime.AccessDeniedException; | ||
import org.zalando.nakadi.exceptions.runtime.NakadiRuntimeException; | ||
import org.zalando.nakadi.plugin.api.exceptions.PluginException; | ||
import org.zalando.nakadi.service.AuthorizationValidator; | ||
import org.zalando.nakadi.service.BlacklistService; | ||
import org.zalando.nakadi.service.CursorConverter; | ||
|
@@ -68,6 +69,7 @@ public class StreamingContext implements SubscriptionStreamer { | |
private final NakadiKpiPublisher kpiPublisher; | ||
private final Span currentSpan; | ||
private final String kpiDataStreamedEventType; | ||
private final TerminationService terminationService; | ||
|
||
private final long kpiCollectionFrequencyMs; | ||
|
||
|
@@ -105,6 +107,7 @@ private StreamingContext(final Builder builder) { | |
this.kpiCollectionFrequencyMs = builder.kpiCollectionFrequencyMs; | ||
this.streamMemoryLimitBytes = builder.streamMemoryLimitBytes; | ||
this.currentSpan = builder.currentSpan; | ||
this.terminationService = builder.terminationService; | ||
} | ||
|
||
public Span getCurrentSpan() { | ||
|
@@ -166,7 +169,10 @@ public long getKpiCollectionFrequencyMs() { | |
@Override | ||
public void stream() throws InterruptedException { | ||
try (Closeable ignore = ShutdownHooks.addHook(this::onNodeShutdown)) { // bugfix ARUHA-485 | ||
terminationService.register(this::onInstanceTermination); | ||
streamInternal(new StartingState()); | ||
} catch (final PluginException pe) { | ||
log.error("Failed to register instance termination callback for subscription {}", getSubscription(), pe); | ||
} catch (final IOException ex) { | ||
log.error( | ||
"Failed to delete shutdown hook for subscription {}. This method should not throw any exception", | ||
|
@@ -175,6 +181,11 @@ public void stream() throws InterruptedException { | |
} | ||
} | ||
|
||
void onInstanceTermination() { | ||
log.info("Instance is about to be terminated. Trying to terminate subscription gracefully"); | ||
switchState(new CleanupState(null)); | ||
} | ||
|
||
void onNodeShutdown() { | ||
log.info("Shutdown hook called. Trying to terminate subscription gracefully"); | ||
switchState(new CleanupState(null)); | ||
|
@@ -372,6 +383,7 @@ public static final class Builder { | |
private long kpiCollectionFrequencyMs; | ||
private long streamMemoryLimitBytes; | ||
private Span currentSpan; | ||
private TerminationService terminationService; | ||
|
||
public Builder setCurrentSpan(final Span span) { | ||
this.currentSpan = span; | ||
|
@@ -493,11 +505,15 @@ public Builder setKpiCollectionFrequencyMs(final long kpiCollectionFrequencyMs) | |
return this; | ||
} | ||
|
||
public Builder setTerminationService(final TerminationService terminationService) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that this is set also in the constructor. Is this used or needed? |
||
this.terminationService = terminationService; | ||
return this; | ||
} | ||
|
||
public StreamingContext build() { | ||
return new StreamingContext(this); | ||
} | ||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this meant to be used by Nakadi Proxy? When maintaining the list of healthy Nakadi instances, those who report 418 during health check will not be added to the final result but at the same time not marked as unhealthy?