Skip to content

Commit

Permalink
Merge to latest
Browse files Browse the repository at this point in the history
Signed-off-by: pranikum <109206473+pranikum@users.noreply.github.com>
  • Loading branch information
pranikum committed Sep 25, 2022
1 parent 49916f8 commit 0157b11
Show file tree
Hide file tree
Showing 7 changed files with 324 additions and 474 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ public int hashCode() {
public String toString() {
return "DecommissionAttribute{" + "attributeName='" + attributeName + '\'' + ", attributeValue='" + attributeValue + '\'' + '}';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public DecommissionStatus status() {
*/
// synchronized is strictly speaking not needed (this is called by a single thread), but just to be safe
public synchronized DecommissionAttributeMetadata setUpdatedStatus(DecommissionStatus newStatus) {
// if the current status is the expected status already, we return the same instance
if (newStatus.equals(status)) {
return this;
}
// We don't expect that INIT will be new status, as it is registered only when starting the decommission action
switch (newStatus) {
case IN_PROGRESS:
Expand All @@ -97,23 +101,23 @@ public synchronized DecommissionAttributeMetadata setUpdatedStatus(DecommissionS
break;
default:
throw new IllegalArgumentException(
"illegal decommission status [" + newStatus.status() + "] requested for updating metadata"
"illegal decommission status [" + newStatus.status() + "] requested for updating metadata"
);
}
return this;
}

protected void validateAndSetStatus(DecommissionStatus expected, DecommissionStatus next) {
private void validateAndSetStatus(DecommissionStatus expected, DecommissionStatus next) {
if (status.equals(expected) == false) {
assert false : "can't move decommission status to ["
+ next
+ "]. current status: ["
+ status
+ "] (expected ["
+ expected
+ "])";
+ next
+ "]. current status: ["
+ status
+ "] (expected ["
+ expected
+ "])";
throw new IllegalStateException(
"can't move decommission status to [" + next + "]. current status: [" + status + "] (expected [" + expected + "])"
"can't move decommission status to [" + next + "]. current status: [" + status + "] (expected [" + expected + "])"
);
}
status = next;
Expand Down Expand Up @@ -176,8 +180,8 @@ public static DecommissionAttributeMetadata fromXContent(XContentParser parser)
if (attributeType.equals(currentFieldName)) {
if (parser.nextToken() != XContentParser.Token.START_OBJECT) {
throw new OpenSearchParseException(
"failed to parse decommission attribute type [{}], expected object",
attributeType
"failed to parse decommission attribute type [{}], expected object",
attributeType
);
}
token = parser.nextToken();
Expand All @@ -190,8 +194,8 @@ public static DecommissionAttributeMetadata fromXContent(XContentParser parser)
value = parser.text();
} else {
throw new OpenSearchParseException(
"failed to parse attribute [{}], expected string for attribute value",
fieldName
"failed to parse attribute [{}], expected string for attribute value",
fieldName
);
}
decommissionAttribute = new DecommissionAttribute(fieldName, value);
Expand All @@ -205,14 +209,14 @@ public static DecommissionAttributeMetadata fromXContent(XContentParser parser)
} else if ("status".equals(currentFieldName)) {
if (parser.nextToken() != XContentParser.Token.VALUE_STRING) {
throw new OpenSearchParseException(
"failed to parse status of decommissioning, expected string but found unknown type"
"failed to parse status of decommissioning, expected string but found unknown type"
);
}
status = DecommissionStatus.fromString(parser.text());
} else {
throw new OpenSearchParseException(
"unknown field found [{}], failed to parse the decommission attribute",
currentFieldName
"unknown field found [{}], failed to parse the decommission attribute",
currentFieldName
);
}
}
Expand Down Expand Up @@ -242,11 +246,11 @@ public EnumSet<Metadata.XContentContext> context() {
* @param params serialization parameters
*/
public static void toXContent(
DecommissionAttribute decommissionAttribute,
DecommissionStatus status,
String attributeType,
XContentBuilder builder,
ToXContent.Params params
DecommissionAttribute decommissionAttribute,
DecommissionStatus status,
String attributeType,
XContentBuilder builder,
ToXContent.Params params
) throws IOException {
builder.startObject(attributeType);
builder.field(decommissionAttribute.attributeName(), decommissionAttribute.attributeValue());
Expand All @@ -258,4 +262,4 @@ public static void toXContent(
public String toString() {
return Strings.toString(this);
}
}
}
Loading

0 comments on commit 0157b11

Please sign in to comment.