forked from apache/helix
-
Notifications
You must be signed in to change notification settings - Fork 11
Return current Evacuation status of isEvacuateFinished #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d11955e
Return remaining paritition count during isEvacuateFinished
LZD-PratyushBhatt fc50a57
Refactor
LZD-PratyushBhatt a2a090c
Add tests
LZD-PratyushBhatt 29847d8
ADdress review comments
LZD-PratyushBhatt 740cdf8
ADdress review comments 2
LZD-PratyushBhatt ae527df
Use Integer instead of primitive int
LZD-PratyushBhatt 8a73eb1
Add LastModifiedTime field for more visibility
LZD-PratyushBhatt 7c6b212
Use stream for getting the lastModifiedTime
LZD-PratyushBhatt 8517f72
Address review comments
LZD-PratyushBhatt fc6c165
Add diff reason code
LZD-PratyushBhatt 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 hidden or 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
157 changes: 157 additions & 0 deletions
157
helix-core/src/main/java/org/apache/helix/model/EvacuationInfo.java
This file contains hidden or 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,157 @@ | ||
| package org.apache.helix.model; | ||
|
|
||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
|
LZD-PratyushBhatt marked this conversation as resolved.
|
||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
|
||
| /** | ||
| * Data class representing the evacuation status of an instance. | ||
| * Used by the isEvacuateFinished REST API to return detailed information | ||
| * about the evacuation progress. | ||
| */ | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| public class EvacuationInfo { | ||
|
|
||
| /** | ||
| * Enum representing the current state of evacuation. | ||
| */ | ||
| public enum EvacuationState { | ||
| NOT_EVACUATING, // Instance is not in EVACUATE operation | ||
| IN_PROGRESS, // Evacuation is ongoing | ||
| COMPLETED // Evacuation finished successfully | ||
| } | ||
|
|
||
| /** | ||
| * Enum representing reasons why evacuation may be blocked or incomplete. | ||
| */ | ||
| public enum ReasonCode { | ||
| NOT_IN_EVACUATE_OPERATION("Instance is not in EVACUATE operation"), | ||
| MULTIPLE_SESSIONS("Instance has multiple sessions and is carrying over from previous session"); | ||
|
|
||
| private final String message; | ||
|
|
||
| ReasonCode(String message) { | ||
| this.message = message; | ||
| } | ||
|
|
||
| public String getMessage() { | ||
| return message; | ||
| } | ||
| } | ||
|
|
||
| private EvacuationState state; | ||
| private Integer remainingPartitionCount; | ||
| private Integer pendingMessageCount; | ||
| private String reason; | ||
| private Long lastActivityTimestamp; | ||
|
|
||
| /** | ||
| * Default constructor for Jackson deserialization. | ||
| * Fields are left as null so they won't be serialized when not applicable. | ||
| */ | ||
| public EvacuationInfo() { | ||
| this.state = EvacuationState.NOT_EVACUATING; | ||
| // remainingPartitionCount and pendingMessageCount are intentionally left null | ||
| // so they won't be serialized for NOT_EVACUATING state | ||
| } | ||
|
|
||
| /** | ||
| * Constructor with all fields. | ||
| */ | ||
| public EvacuationInfo(EvacuationState state, Integer remainingPartitionCount, Integer pendingMessageCount, String reason) { | ||
| this.state = state; | ||
| this.remainingPartitionCount = remainingPartitionCount; | ||
| this.pendingMessageCount = pendingMessageCount; | ||
| this.reason = reason; | ||
| } | ||
|
|
||
| public EvacuationState getState() { | ||
| return state; | ||
| } | ||
|
|
||
| public void setState(EvacuationState state) { | ||
| this.state = state; | ||
| } | ||
|
|
||
| /** | ||
| * Returns whether evacuation is complete. | ||
| * This is a derived field for backward compatibility with clients expecting a boolean "successful" field. | ||
| * | ||
| * @return true if state is COMPLETED, false otherwise | ||
| */ | ||
| public boolean isSuccessful() { | ||
| return state == EvacuationState.COMPLETED; | ||
| } | ||
|
|
||
| public Integer getRemainingPartitionCount() { | ||
| return remainingPartitionCount; | ||
| } | ||
|
|
||
| public void setRemainingPartitionCount(Integer remainingPartitionCount) { | ||
| this.remainingPartitionCount = remainingPartitionCount; | ||
| } | ||
|
|
||
| public Integer getPendingMessageCount() { | ||
| return pendingMessageCount; | ||
| } | ||
|
|
||
| public void setPendingMessageCount(Integer pendingMessageCount) { | ||
| this.pendingMessageCount = pendingMessageCount; | ||
| } | ||
|
|
||
| public String getReason() { | ||
| return reason; | ||
| } | ||
|
|
||
| public void setReason(String reason) { | ||
| this.reason = reason; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the reason using a predefined ReasonCode. | ||
| */ | ||
| public void setReason(ReasonCode reasonCode) { | ||
| this.reason = reasonCode.getMessage(); | ||
| } | ||
|
|
||
| public Long getLastActivityTimestamp() { | ||
| return lastActivityTimestamp; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the timestamp of the last activity during evacuation. | ||
| * This is the max modification time across all CurrentState ZNodes for the instance. | ||
| */ | ||
| public void setLastActivityTimestamp(Long lastActivityTimestamp) { | ||
| this.lastActivityTimestamp = lastActivityTimestamp; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "EvacuationInfo{" + | ||
| "successful=" + isSuccessful() + | ||
| ", state=" + state + | ||
| ", remainingPartitionCount=" + remainingPartitionCount + | ||
| ", pendingMessageCount=" + pendingMessageCount + | ||
| ", reason='" + reason + '\'' + | ||
| ", lastActivityTimestamp=" + lastActivityTimestamp + | ||
| '}'; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
I believe we should have different reason code for config as null vs no evacuate operation assigned.
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.
I dont think so it will add any value, even if instance config is not present, instance is technically not evacauting, and in both cases the user will anyways go to the cluster to check the instance config.
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.
At some point, we will propagate this to UI. For user facing things, we should be meticulous about what messages we show/return.
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.
I think no harm in adding it, added! Thanks for the suggestion!