Skip to content

Commit

Permalink
Revert "Fix SpotBug issues"
Browse files Browse the repository at this point in the history
This reverts commit 8f5f3aa.
  • Loading branch information
cizhang-amzn committed Aug 29, 2024
1 parent 8f5f3aa commit eaf2bee
Show file tree
Hide file tree
Showing 15 changed files with 15 additions and 91 deletions.
3 changes: 0 additions & 3 deletions aws-organizations-account/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<argLine>--add-opens java.base/java.util=ALL-UNNAMED</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public abstract class BaseHandlerStd extends BaseHandler<CallbackContext> {
protected static final String ACCOUNT_CREATION_STATUS_SUCCEEDED = "SUCCEEDED";
protected static final String ACCOUNT_CREATION_STATUS_FAILED = "FAILED";
// ExponentialBackoffJitter Constants
private static final Random RANDOM = new Random();
protected static final double RANDOMIZATION_FACTOR = 0.5;
protected static final double RANDOMIZATION_FACTOR_FOR_DESCRIBE_CREATE_ACCOUNT_STATUS = 0.2;
protected static final int BASE_DELAY = 15; // in second
Expand Down Expand Up @@ -163,8 +162,9 @@ public ProgressEvent<ResourceModel, CallbackContext> handleErrorTranslation(
}

public final int computeDelayBeforeNextRetry(int retryAttempt, int baseDelay, double randomizationFactor) {
Random random = new Random();
int exponentialBackoff = (int) Math.pow(2, retryAttempt) * baseDelay;
int jitter = RANDOM.nextInt((int) Math.ceil(exponentialBackoff * randomizationFactor));
int jitter = random.nextInt((int) Math.ceil(exponentialBackoff * randomizationFactor));
return exponentialBackoff + jitter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,17 @@
@lombok.Getter
@lombok.Setter
@lombok.ToString
@lombok.EqualsAndHashCode(callSuper = true, exclude = "actionToRetryAttemptMap")
@lombok.EqualsAndHashCode(callSuper = true)
public class CallbackContext extends StdCallbackContext {
private Map<String, Integer> actionToRetryAttemptMap = new HashMap<>();

// Manually implement the setter with a defensive copy
public void setActionToRetryAttemptMap(Map<String, Integer> actionToRetryAttemptMap) {
this.actionToRetryAttemptMap = new HashMap<>(actionToRetryAttemptMap);
}

// Manually implement the getter with a defensive copy
public Map<String, Integer> getActionToRetryAttemptMap() {
return new HashMap<>(actionToRetryAttemptMap);
}

public int getCurrentRetryAttempt(final AccountConstants.Action actionName, final AccountConstants.Handler handlerName) {
String key = actionName.toString() + handlerName.toString();
return this.actionToRetryAttemptMap.getOrDefault(key, 0);
}

public void setCurrentRetryAttempt(final AccountConstants.Action actionName, final AccountConstants.Handler handlerName) {
String key = actionName.toString() + handlerName.toString();
this.actionToRetryAttemptMap.put(key, getCurrentRetryAttempt(actionName, handlerName)+1);
}

// used in CREATE handler
private boolean isAccountCreated = false;
private String createAccountRequestId;
Expand Down
3 changes: 0 additions & 3 deletions aws-organizations-organization/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<argLine>--add-opens java.base/java.util=ALL-UNNAMED</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.Random;

public abstract class BaseHandlerStd extends BaseHandler<CallbackContext> {
private static final Random RANDOM = new Random();
private static final double RANDOMIZATION_FACTOR = 0.5;
private static final int BASE_DELAY = 15; //in seconds
private static final int MAX_RETRY_ATTEMPT_FOR_RETRIABLE_EXCEPTION = 2;
Expand Down Expand Up @@ -126,8 +125,9 @@ && isRetriableException(e)) {
}

public final int computeDelayBeforeNextRetry(int retryAttempt) {
Random random = new Random();
int exponentialBackoff = (int) Math.pow(2, retryAttempt) * BASE_DELAY;
int jitter = RANDOM.nextInt((int) Math.ceil(exponentialBackoff * RANDOMIZATION_FACTOR));
int jitter = random.nextInt((int) Math.ceil(exponentialBackoff * RANDOMIZATION_FACTOR));
return exponentialBackoff + jitter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,10 @@
@lombok.Getter
@lombok.Setter
@lombok.ToString
@lombok.EqualsAndHashCode(callSuper = true, exclude = "actionToRetryAttemptMap")
@lombok.EqualsAndHashCode(callSuper = true)
public class CallbackContext extends StdCallbackContext {
private Map<String, Integer> actionToRetryAttemptMap = new HashMap<>();

// Manually implement the setter with a defensive copy
public void setActionToRetryAttemptMap(Map<String, Integer> actionToRetryAttemptMap) {
this.actionToRetryAttemptMap = new HashMap<>(actionToRetryAttemptMap);
}

// Manually implement the getter with a defensive copy
public Map<String, Integer> getActionToRetryAttemptMap() {
return new HashMap<>(actionToRetryAttemptMap);
}

// Used to set Propagation Delay in the CreateHandler call chain.
public boolean propagationDelay = false;
// used in CREATE handler re-invoking
Expand All @@ -31,7 +21,6 @@ public int getCurrentRetryAttempt(final OrganizationConstants.Action actionName,
String key = actionName.toString() + handlerName.toString();
return this.actionToRetryAttemptMap.getOrDefault(key, 0);
}

public void setCurrentRetryAttempt(final OrganizationConstants.Action actionName, final OrganizationConstants.Handler handlerName) {
String key = actionName.toString() + handlerName.toString();
this.actionToRetryAttemptMap.put(key, getCurrentRetryAttempt(actionName, handlerName) + 1);
Expand Down
3 changes: 0 additions & 3 deletions aws-organizations-organizationalunit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<argLine>--add-opens java.base/java.util=ALL-UNNAMED</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

public abstract class BaseHandlerStd extends BaseHandler<CallbackContext> {
// ExponentialBackoffJitter Constants
private static final Random RANDOM = new Random();
private static final double RANDOMIZATION_FACTOR = 0.5;
private static final int BASE_DELAY = 15; // in seconds
private static final int MAX_RETRY_ATTEMPT_FOR_RETRIABLE_EXCEPTION = 2;
Expand Down Expand Up @@ -123,8 +122,9 @@ && isRetriableException(e)) {
}

public final int computeDelayBeforeNextRetry(int retryAttempt) {
Random random = new Random();
int exponentialBackoff = (int) Math.pow(2, retryAttempt) * BASE_DELAY;
int jitter = RANDOM.nextInt((int) Math.ceil(exponentialBackoff * RANDOMIZATION_FACTOR));
int jitter = random.nextInt((int) Math.ceil(exponentialBackoff * RANDOMIZATION_FACTOR));
return exponentialBackoff + jitter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,13 @@
@lombok.Getter
@lombok.Setter
@lombok.ToString
@lombok.EqualsAndHashCode(callSuper = true, exclude = "actionToRetryAttemptMap")
@lombok.EqualsAndHashCode(callSuper = true)
public class CallbackContext extends StdCallbackContext {
private Map<String, Integer> actionToRetryAttemptMap = new HashMap<>();

// Manually implement the setter with a defensive copy
public void setActionToRetryAttemptMap(Map<String, Integer> actionToRetryAttemptMap) {
this.actionToRetryAttemptMap = new HashMap<>(actionToRetryAttemptMap);
}

// Manually implement the getter with a defensive copy
public Map<String, Integer> getActionToRetryAttemptMap() {
return new HashMap<>(actionToRetryAttemptMap);
}

public int getCurrentRetryAttempt(final Constants.Action actionName, final Constants.Handler handlerName) {
String key = actionName.toString() + handlerName.toString();
return this.actionToRetryAttemptMap.getOrDefault(key, 0);
}

public void setCurrentRetryAttempt(final Constants.Action actionName, final Constants.Handler handlerName) {
String key = actionName.toString() + handlerName.toString();
this.actionToRetryAttemptMap.put(key, getCurrentRetryAttempt(actionName, handlerName)+1);
Expand Down
3 changes: 0 additions & 3 deletions aws-organizations-policy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<argLine>--add-opens java.base/java.util=ALL-UNNAMED</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

public abstract class BaseHandlerStd extends BaseHandler<CallbackContext> {
// ExponentialBackoffJitter Constants
private static final Random RANDOM = new Random();
private static final double RANDOMIZATION_FACTOR = 0.5;
private static final int BASE_DELAY = 15; // in seconds
private static final int MAX_RETRY_ATTEMPT_FOR_RETRIABLE_EXCEPTION = 2;
Expand Down Expand Up @@ -120,8 +119,9 @@ && isRetriableException(e)) {
}

public final int computeDelayBeforeNextRetry(int retryAttempt) {
Random random = new Random();
int exponentialBackoff = (int) Math.pow(2, retryAttempt) * BASE_DELAY;
int jitter = RANDOM.nextInt((int) Math.ceil(exponentialBackoff * RANDOMIZATION_FACTOR));
int jitter = random.nextInt((int) Math.ceil(exponentialBackoff * RANDOMIZATION_FACTOR));
return exponentialBackoff + jitter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,17 @@
@lombok.Getter
@lombok.Setter
@lombok.ToString
@lombok.EqualsAndHashCode(callSuper = true, exclude = "actionToRetryAttemptMap")
@lombok.EqualsAndHashCode(callSuper = true)
public class CallbackContext extends StdCallbackContext {
private Map<String, Integer> actionToRetryAttemptMap = new HashMap<>();

// Manually implement the setter with a defensive copy
public void setActionToRetryAttemptMap(Map<String, Integer> actionToRetryAttemptMap) {
this.actionToRetryAttemptMap = new HashMap<>(actionToRetryAttemptMap);
}

// Manually implement the getter with a defensive copy
public Map<String, Integer> getActionToRetryAttemptMap() {
return new HashMap<>(actionToRetryAttemptMap);
}

public int getCurrentRetryAttempt(final PolicyConstants.Action actionName, final PolicyConstants.Handler handlerName) {
String key = actionName.toString() + handlerName.toString();
return this.actionToRetryAttemptMap.getOrDefault(key, 0);
}

public void setCurrentRetryAttempt(final PolicyConstants.Action actionName, final PolicyConstants.Handler handlerName) {
String key = actionName.toString() + handlerName.toString();
this.actionToRetryAttemptMap.put(key, getCurrentRetryAttempt(actionName, handlerName)+1);
}

// used in CREATE handler re-invoking
private boolean isPolicyCreated = false;
// used in DELETE handler re-invoking
Expand Down
3 changes: 0 additions & 3 deletions aws-organizations-resourcepolicy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<argLine>--add-opens java.base/java.util=ALL-UNNAMED</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

public abstract class BaseHandlerStd extends BaseHandler<CallbackContext> {
// ExponentialBackoffJitter Constants
private static final Random RANDOM = new Random();
private static final double RANDOMIZATION_FACTOR = 0.5;
private static final int BASE_DELAY = 15; // in seconds
private static final int MAX_RETRY_ATTEMPT_FOR_RETRIABLE_EXCEPTION = 2;
Expand Down Expand Up @@ -115,8 +114,9 @@ && isRetriableException(e)) {
}

public final int computeDelayBeforeNextRetry(int retryAttempt) {
Random random = new Random();
int exponentialBackoff = (int) Math.pow(2, retryAttempt) * BASE_DELAY;
int jitter = RANDOM.nextInt((int) Math.ceil(exponentialBackoff * RANDOMIZATION_FACTOR));
int jitter = random.nextInt((int) Math.ceil(exponentialBackoff * RANDOMIZATION_FACTOR));
return exponentialBackoff + jitter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,13 @@
@lombok.Getter
@lombok.Setter
@lombok.ToString
@lombok.EqualsAndHashCode(callSuper = true, exclude = "actionToRetryAttemptMap")
@lombok.EqualsAndHashCode(callSuper = true)
public class CallbackContext extends StdCallbackContext {
private Map<String, Integer> actionToRetryAttemptMap = new HashMap<>();

// Manually implement the setter with a defensive copy
public void setActionToRetryAttemptMap(Map<String, Integer> actionToRetryAttemptMap) {
this.actionToRetryAttemptMap = new HashMap<>(actionToRetryAttemptMap);
}

// Manually implement the getter with a defensive copy
public Map<String, Integer> getActionToRetryAttemptMap() {
return new HashMap<>(actionToRetryAttemptMap);
}

public int getCurrentRetryAttempt(final ResourcePolicyConstants.Action actionName, final ResourcePolicyConstants.Handler handlerName) {
String key = actionName.toString() + handlerName.toString();
return this.actionToRetryAttemptMap.getOrDefault(key, 0);
}

public void setCurrentRetryAttempt(final ResourcePolicyConstants.Action actionName, final ResourcePolicyConstants.Handler handlerName) {
String key = actionName.toString() + handlerName.toString();
this.actionToRetryAttemptMap.put(key, getCurrentRetryAttempt(actionName, handlerName)+1);
Expand Down

0 comments on commit eaf2bee

Please sign in to comment.