Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Open Subsurface Data Universe Software
Platform
System
Lib
cloud
azure
OS Core Lib Azure
Commits
efbac6ca
Commit
efbac6ca
authored
May 24, 2021
by
Ronak Sakhuja
Browse files
Added retry config to blobstorage
parent
c398b41a
Pipeline
#42003
failed with stage
in 11 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/opengroup/osdu/azure/blobstorage/BlobContainerClientFactoryImpl.java
View file @
efbac6ca
...
...
@@ -17,7 +17,9 @@ package org.opengroup.osdu.azure.blobstorage;
import
com.azure.identity.DefaultAzureCredential
;
import
com.azure.storage.blob.BlobContainerClient
;
import
com.azure.storage.blob.BlobContainerClientBuilder
;
import
com.azure.storage.common.policy.RequestRetryOptions
;
import
org.opengroup.osdu.azure.cache.BlobContainerClientCache
;
import
org.opengroup.osdu.azure.di.BlobStorageRetryConfiguration
;
import
org.opengroup.osdu.azure.partition.PartitionInfoAzure
;
import
org.opengroup.osdu.azure.partition.PartitionServiceClient
;
import
org.opengroup.osdu.common.Validators
;
...
...
@@ -41,6 +43,9 @@ public class BlobContainerClientFactoryImpl implements IBlobContainerClientFacto
@Autowired
private
BlobContainerClientCache
clientCache
;
@Autowired
private
BlobStorageRetryConfiguration
blobStorageRetryConfiguration
;
/**
* @param dataPartitionId Data partition id
* @param containerName Blob container name
...
...
@@ -60,10 +65,13 @@ public class BlobContainerClientFactoryImpl implements IBlobContainerClientFacto
PartitionInfoAzure
pi
=
this
.
partitionService
.
getPartition
(
dataPartitionId
);
String
endpoint
=
String
.
format
(
"https://%s.blob.core.windows.net"
,
pi
.
getStorageAccountName
());
RequestRetryOptions
requestRetryOptions
=
blobStorageRetryConfiguration
.
getRequestRetryOptions
();
BlobContainerClient
blobContainerClient
=
new
BlobContainerClientBuilder
()
.
endpoint
(
endpoint
)
.
credential
(
defaultAzureCredential
)
.
containerName
(
containerName
)
.
retryOptions
(
requestRetryOptions
)
.
buildClient
();
this
.
clientCache
.
put
(
cacheKey
,
blobContainerClient
);
...
...
src/main/java/org/opengroup/osdu/azure/di/BlobStorageRetryConfiguration.java
0 → 100644
View file @
efbac6ca
// Copyright © Microsoft Corporation
//
// Licensed 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.
package
org.opengroup.osdu.azure.di
;
import
com.azure.storage.common.policy.RequestRetryOptions
;
import
com.azure.storage.common.policy.RetryPolicyType
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.opengroup.osdu.azure.logging.CoreLoggerFactory
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Configuration
;
import
java.time.Duration
;
@Configuration
@ConfigurationProperties
(
"azure.blobstorage"
)
@Getter
@Setter
public
class
BlobStorageRetryConfiguration
{
private
final
String
LOGGER_NAME
=
BlobStorageRetryConfiguration
.
class
.
getName
();
private
int
maxTries
=
-
1
;
private
int
tryTimeoutInSeconds
=
-
1
;
private
int
retryDelayInMs
=
-
1
;
private
int
maxRetryDelayInMs
=
-
1
;
private
String
retryPolicyType
=
""
;
private
String
secondaryHost
=
""
;
/**
* Checks whether an int variable value is configured or not
* @param val integer value to be checked
* @return true if value is configured in app.properties
*/
private
boolean
valueConfigured
(
int
val
)
{
if
(
val
!=
-
1
)
{
return
true
;
}
return
false
;
}
/**
* Checks whether an string variable value is configured or not
* @param val string value to be checked
* @return true if value is configured in app.properties
*/
private
boolean
valueConfigured
(
String
val
)
{
if
(
val
==
null
||
val
.
isEmpty
())
{
return
false
;
}
return
true
;
}
/**
* Method to get RequestRetryOptions object based on configuration set in applicaiton.properties
* @return RequestRetryOption object with appropriate configurations.
*/
public
RequestRetryOptions
getRequestRetryOptions
()
{
// Check whether the variables have been set, else keep them as null.
// Value has to be sent as null incase where they are not configured to use the default configurations (As specified in RequestRetryOptions.class)
// https://azure.github.io/azure-storage-java-async/com/microsoft/azure/storage/blob/RequestRetryOptions.html
RetryPolicyType
rpt
=
valueConfigured
(
retryPolicyType
)?
RetryPolicyType
.
valueOf
(
retryPolicyType
)
:
RetryPolicyType
.
EXPONENTIAL
;
int
maxTries
=
valueConfigured
(
this
.
maxTries
)
?
this
.
maxTries
:
(
Integer
)
null
;
Duration
tryTimeout
=
valueConfigured
(
tryTimeoutInSeconds
)?
Duration
.
ofSeconds
((
long
)
tryTimeoutInSeconds
)
:
null
;
Duration
retryDelay
=
valueConfigured
(
retryDelayInMs
)?
Duration
.
ofMillis
(
retryDelayInMs
):
null
;
Duration
maxRetryDelay
=
valueConfigured
(
maxRetryDelayInMs
)?
Duration
.
ofMillis
(
maxRetryDelayInMs
):
null
;
String
secondaryHost
=
valueConfigured
(
this
.
secondaryHost
)
?
this
.
secondaryHost
:
null
;
RequestRetryOptions
requestRetryOptions
=
new
RequestRetryOptions
(
rpt
,
maxTries
,
tryTimeout
,
retryDelay
,
maxRetryDelay
,
secondaryHost
);
CoreLoggerFactory
.
getInstance
().
getLogger
(
LOGGER_NAME
)
.
info
(
"Retry Options on BlobStorage with RetryPolicyType = {} , maxTries = {} , tryTimeout = {} , retryDelay = {} , maxRetryDelay = {} , secondaryHost = {}."
,
rpt
.
toString
(),
requestRetryOptions
.
getMaxTries
(),
requestRetryOptions
.
getTryTimeoutDuration
().
getSeconds
(),
requestRetryOptions
.
getRetryDelay
().
toMillis
(),
requestRetryOptions
.
getMaxRetryDelay
().
toMillis
(),
requestRetryOptions
.
getSecondaryHost
());
return
requestRetryOptions
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment