Commit cb41053f authored by Alok Joshi's avatar Alok Joshi
Browse files

Merge branch 'master' of...

Merge branch 'master' of https://community.opengroup.org/osdu/platform/system/lib/cloud/azure/os-core-lib-azure into use_debug_log
parents 4e467807 9c273dcc
Pipeline #46763 failed with stages
in 10 seconds
......@@ -87,3 +87,11 @@ Enabled transaction logger and slf4jlogger
| --- | --- | --- |
| `azure.blobStore.required` | `true` | - |
| `azure.storage.account-name` | ex `testStorage` | storage account name |
# Default retry and timeout values for service-to-service communication
| name | default value |
| --- | --- |
| `maxRetry` | `3` |
| `connectTimeout` | `60000` |
| `requestTimeout` | `60000` |
| `socketTimeout` | `60000` |
// 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 lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* Configuration bean for setting up retry and timeouts variables.
*/
@Data
@Component
@ConfigurationProperties(prefix = "azure.service.retry.config")
public class RetryAndTimeoutConfiguration {
private int maxRetry = 3;
private int connectTimeout = 60000;
private int requestTimeout = 60000;
private int socketTimeout = 60000;
}
// 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.entitlements;
import lombok.Data;
import org.opengroup.osdu.core.common.entitlements.EntitlementsAPIConfig;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* Creates bean of EntitlementsAPIConfig.
*/
@Data
@Component
@ConfigurationProperties
public class EntilementsAPIConfigBean extends AbstractFactoryBean<EntitlementsAPIConfig> {
private String authorizeAPI;
private String authorizeAPIKey;
/**
* Abstract method of AbstractBeanFactory<T>.
*
* @return class type
*/
@Override
public Class<?> getObjectType() {
return EntitlementsAPIConfig.class;
}
/**
* Abstract method of AbstractBeanFactory<T> type.
*
* @return EntitlementsAPIConfig
* @throws Exception
*/
@Override
protected EntitlementsAPIConfig createInstance() throws Exception {
return EntitlementsAPIConfig
.builder()
.rootUrl(authorizeAPI)
.apiKey(authorizeAPIKey)
.build();
}
}
// 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.entitlements;
import org.opengroup.osdu.core.common.entitlements.EntitlementsAPIConfig;
import org.opengroup.osdu.core.common.entitlements.EntitlementsService;
import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory;
import org.opengroup.osdu.core.common.entitlements.IEntitlementsService;
import org.opengroup.osdu.core.common.http.IHttpClient;
import org.opengroup.osdu.core.common.http.json.HttpResponseBodyMapper;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import java.util.Objects;
/**
* Implements IEntitlementsFactory.
*/
@Component
@Primary
@ConditionalOnProperty(value = "azure.entitlements.factory.enabled", havingValue = "true", matchIfMissing = true)
public class EntitlementsFactoryAzure implements IEntitlementsFactory {
private final EntitlementsAPIConfig config;
private final HttpResponseBodyMapper mapper;
private final IHttpClient client;
/**
* Constructor Injection for above 3 fields.
*
* @param entitlementsConfig EntitlementsAPIConfig
* @param httpMapper HttpResponseBodyMapper
* @param httpClient IHttpClient
*/
@Autowired
public EntitlementsFactoryAzure(final EntitlementsAPIConfig entitlementsConfig, final HttpResponseBodyMapper httpMapper, final IHttpClient httpClient) {
this.config = entitlementsConfig;
this.mapper = httpMapper;
this.client = httpClient;
}
/**
* returns instance of EntitlementsService.
*
* @param headers DpsHeaders
* @return IEntitlementsService
*/
@Override
public IEntitlementsService create(final DpsHeaders headers) {
Objects.requireNonNull(headers, "headers cannot be null");
return new EntitlementsService(this.config,
this.client,
headers,
this.mapper);
}
}
// 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.httpconfig;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.http.FetchServiceHttpRequest;
import org.opengroup.osdu.core.common.http.HttpRequest;
import org.opengroup.osdu.core.common.http.IHttpClient;
import org.opengroup.osdu.core.common.http.HttpResponse;
import org.opengroup.osdu.core.common.http.UrlFetchServiceImpl;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import java.net.URISyntaxException;
/**
* Extends URlFetchService and implements IHttpClient to send requests.
*/
@Primary
@Component
public class HttpClientAzure extends UrlFetchServiceImpl implements IHttpClient {
/**
* calls urlfetchservice's send request.
*
* @param httpRequest made by user class
* @return HttpResponse
*/
@Override
public HttpResponse send(final HttpRequest httpRequest) {
org.opengroup.osdu.core.common.model.http.HttpResponse response = null;
try {
response = super.sendRequest(FetchServiceHttpRequest.builder()
.body(httpRequest.getBody())
.httpMethod(httpRequest.getHttpMethod())
.queryParams(httpRequest.getQueryParams())
.url(httpRequest.getUrl())
.headers(httpRequest.getHeaders())
.build());
} catch (URISyntaxException e) {
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getReason(), "URI Syntax is not correct", e);
}
HttpResponse httpResponse = new HttpResponse();
httpResponse.setBody(response.getBody());
httpResponse.setResponseCode(response.getResponseCode());
httpResponse.setContentType(response.getContentType());
httpResponse.setRequest(httpRequest);
return httpResponse;
}
}
// 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.httpconfig;
import org.apache.http.client.config.RequestConfig;
import org.opengroup.osdu.azure.di.RetryAndTimeoutConfiguration;
import org.opengroup.osdu.core.common.http.HttpClientHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
/**
* Extends HttpClientHandler.
*/
@Primary
@Component
public class HttpClientHandlerAzure extends HttpClientHandler {
private RetryAndTimeoutConfiguration configuration;
/**
* Constuctor injection for RetryAndTimeoutConfiguration.
*
* @param retryAndTimeoutConfiguration of type RetryAndTimeoutConfiguration
*/
@Autowired
public HttpClientHandlerAzure(final RetryAndTimeoutConfiguration retryAndTimeoutConfiguration) {
this.configuration = retryAndTimeoutConfiguration;
super.REQUEST_CONFIG = RequestConfig.custom()
.setConnectTimeout(configuration.getConnectTimeout())
.setConnectionRequestTimeout(configuration.getRequestTimeout())
.setSocketTimeout(configuration.getSocketTimeout()).build();
super.RETRY_COUNT = configuration.getMaxRetry();
}
}
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