Commit 10c738e7 authored by Ronak Sakhuja's avatar Ronak Sakhuja
Browse files

Replaced if else

parent b4b24da7
Pipeline #47036 failed with stage
in 1 minute and 39 seconds
...@@ -20,15 +20,13 @@ import com.azure.core.http.policy.RetryPolicy; ...@@ -20,15 +20,13 @@ import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.RetryStrategy; import com.azure.core.http.policy.RetryStrategy;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.opengroup.osdu.core.common.logging.ILogger; import org.opengroup.osdu.azure.logging.CoreLoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import java.time.Duration; import java.time.Duration;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.Collections; import java.util.Collections;
import java.util.MissingFormatArgumentException;
/** /**
* More details about RetryPolicy being used can be found at https://docs.microsoft.com/en-us/java/api/com.azure.core.http.policy.retrypolicy?view=azure-java-stable . * More details about RetryPolicy being used can be found at https://docs.microsoft.com/en-us/java/api/com.azure.core.http.policy.retrypolicy?view=azure-java-stable .
...@@ -38,8 +36,9 @@ import java.util.MissingFormatArgumentException; ...@@ -38,8 +36,9 @@ import java.util.MissingFormatArgumentException;
@Getter @Getter
@Setter @Setter
public class CryptographyRetryConfiguration { public class CryptographyRetryConfiguration {
@Autowired
private ILogger logger; public static final String LOGGER_NAME = CryptographyRetryConfiguration.class.getName();
private static final int DEFAULT_INT_VALUE = -1; private static final int DEFAULT_INT_VALUE = -1;
private static final String DEFAULT_STRING_VALUE = ""; private static final String DEFAULT_STRING_VALUE = "";
...@@ -108,21 +107,20 @@ public class CryptographyRetryConfiguration { ...@@ -108,21 +107,20 @@ public class CryptographyRetryConfiguration {
* @return RetryStrategy object to configure in RetryPolicy. * @return RetryStrategy object to configure in RetryPolicy.
*/ */
private RetryStrategy configureRetryStrategy() { private RetryStrategy configureRetryStrategy() {
if (valueConfigured(retryStrategyValue)) { if (valueConfigured(retryStrategyValue) && retryStrategyValue.equals("FixedDelay")) {
if (retryStrategyValue.equals("FixedDelay")) { if (!valueConfigured(fixedDelayConfiguration.getMaxRetries()) || !valueConfigured(fixedDelayConfiguration.getDelay())) {
if (!valueConfigured(fixedDelayConfiguration.getMaxRetries()) || !valueConfigured(fixedDelayConfiguration.getDelay())) { throw new IllegalArgumentException("Cryptography Retry Configuration for Fixed Delay cannot be configured with MaxRetries or Delay values as null.");
throw new IllegalArgumentException("Cryptography Retry Configuration for Fixed Delay cannot be configured with MaxRetries or Delay values as null."); }
} return new FixedDelay(fixedDelayConfiguration.getMaxRetries(), Duration.ofSeconds(fixedDelayConfiguration.getDelay()));
return new FixedDelay(fixedDelayConfiguration.getMaxRetries(), Duration.ofSeconds(fixedDelayConfiguration.getDelay())); } else if (valueConfigured(retryStrategyValue) && retryStrategyValue.equals("ExponentialBackoff")) {
if (exponentialBackoffConfiguration.areAllValuesConfigured()) {
return new ExponentialBackoff(exponentialBackoffConfiguration.getMaxRetries(), Duration.ofMillis(exponentialBackoffConfiguration.getBaseDelayInMillis()), Duration.ofSeconds(exponentialBackoffConfiguration.getMaxDelayInSeconds()));
} else { } else {
if (exponentialBackoffConfiguration.areAllValuesConfigured()) { CoreLoggerFactory.getInstance().getLogger(LOGGER_NAME).info("CryptographyRetryConfiguration", "All values for Exponential Backoff are not configured. Applying default values", Collections.emptyMap());
return new ExponentialBackoff(exponentialBackoffConfiguration.getMaxRetries(), Duration.ofMillis(exponentialBackoffConfiguration.getBaseDelayInMillis()), Duration.ofSeconds(exponentialBackoffConfiguration.getMaxDelayInSeconds())); return new ExponentialBackoff();
} else {
logger.info("CryptographyRetryConfiguration", "All values for Exponential Backoff are not configured. Applying default values", Collections.emptyMap());
return new ExponentialBackoff();
}
} }
} }
// Default configuration
return new ExponentialBackoff(); return new ExponentialBackoff();
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment