summaryrefslogtreecommitdiffstats
path: root/so-monitoring
diff options
context:
space:
mode:
Diffstat (limited to 'so-monitoring')
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/BasicAuthorizationHttpRequestInterceptor.java49
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/HttpClientConnectionConfiguration.java87
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/HttpServiceProviderConfiguration.java28
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/RestTemplateConfiguration.java85
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/db/service/DatabaseServiceProviderImpl.java4
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/exception/InvalidRestRequestException.java36
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/exception/RestProcessingException.java37
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderImpl.java37
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/HttpRestServiceProvider.java33
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/HttpRestServiceProviderImpl.java119
-rw-r--r--so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/HttpServiceProviderConfigurationTest.java2
-rw-r--r--so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/db/api/DatabaseServiceProviderTest.java12
-rw-r--r--so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderTest.java19
-rw-r--r--so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/SoMonitoringController.java41
-rw-r--r--so-monitoring/so-monitoring-service/src/test/java/org/onap/so/monitoring/rest/api/SoMonitoringControllerTest.java61
15 files changed, 92 insertions, 558 deletions
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/BasicAuthorizationHttpRequestInterceptor.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/BasicAuthorizationHttpRequestInterceptor.java
deleted file mode 100644
index 34afd825cb..0000000000
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/BasicAuthorizationHttpRequestInterceptor.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-package org.onap.so.monitoring.configuration.rest;
-
-import java.io.IOException;
-
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpRequest;
-import org.springframework.http.client.ClientHttpRequestExecution;
-import org.springframework.http.client.ClientHttpRequestInterceptor;
-import org.springframework.http.client.ClientHttpResponse;
-
-/**
- * @author waqas.ikram@ericsson.com
- *
- */
-public class BasicAuthorizationHttpRequestInterceptor implements ClientHttpRequestInterceptor {
-
- private final String authorization;
-
- public BasicAuthorizationHttpRequestInterceptor(final String authorization) {
- this.authorization = authorization;
- }
-
- @Override
- public ClientHttpResponse intercept(final HttpRequest request, final byte[] body,
- final ClientHttpRequestExecution execution) throws IOException {
- final HttpHeaders headers = request.getHeaders();
- headers.add("Authorization", authorization);
- return execution.execute(request, body);
- }
-}
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/HttpClientConnectionConfiguration.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/HttpClientConnectionConfiguration.java
deleted file mode 100644
index 1260e535a1..0000000000
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/HttpClientConnectionConfiguration.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-package org.onap.so.monitoring.configuration.rest;
-
-import java.util.concurrent.TimeUnit;
-
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-
-@Service
-public class HttpClientConnectionConfiguration {
-
- @Value(value = "${rest.http.client.configuration.connTimeOutInSec:10}")
- private int connectionTimeOutInSeconds;
-
- @Value(value = "${rest.http.client.configuration.socketTimeOutInSec:180}")
- private int socketTimeOutInSeconds;
-
- @Value(value = "${rest.http.client.configuration.socketTimeOutInSec:600}")
- private int timeToLiveInSeconds;
-
- @Value(value = "${rest.http.client.configuration.maxConnections:10}")
- private int maxConnections;
-
- @Value(value = "${rest.http.client.configuration.maxConnectionsPerRoute:2}")
- private int maxConnectionsPerRoute;
-
- /**
- * @return the socketTimeOut
- */
- public int getSocketTimeOutInMiliSeconds() {
- return (int) TimeUnit.SECONDS.toMillis(socketTimeOutInSeconds);
- }
-
- /**
- * @return the maxConnections
- */
- public int getMaxConnections() {
- return maxConnections;
- }
-
- /**
- * @return the maxConnectionsPerRoute
- */
- public int getMaxConnectionsPerRoute() {
- return maxConnectionsPerRoute;
- }
-
- /**
- * @return the connectionTimeOut
- */
- public int getConnectionTimeOutInMilliSeconds() {
- return (int) TimeUnit.SECONDS.toMillis(connectionTimeOutInSeconds);
- }
-
- /**
- * @return the timeToLive
- */
- public int getTimeToLiveInMins() {
- return (int) TimeUnit.SECONDS.toMinutes(timeToLiveInSeconds);
- }
-
- @Override
- public String toString() {
- return "HttpClientConnectionConfiguration [connectionTimeOutInSeconds=" + connectionTimeOutInSeconds
- + ", socketTimeOutInSeconds=" + socketTimeOutInSeconds + ", timeToLiveInSeconds=" + timeToLiveInSeconds
- + ", maxConnections=" + maxConnections + ", maxConnectionsPerRoute=" + maxConnectionsPerRoute + "]";
- }
-
-}
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/HttpServiceProviderConfiguration.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/HttpServiceProviderConfiguration.java
index a590d7908f..11c4d1b4f4 100644
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/HttpServiceProviderConfiguration.java
+++ b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/HttpServiceProviderConfiguration.java
@@ -19,17 +19,17 @@
*/
package org.onap.so.monitoring.configuration.rest;
-import static org.onap.so.monitoring.configuration.rest.RestTemplateConfiguration.CAMUNDA_REST_TEMPLATE;
-import static org.onap.so.monitoring.configuration.rest.RestTemplateConfiguration.DATABASE_REST_TEMPLATE;
+import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
-import org.onap.so.monitoring.rest.service.HttpRestServiceProvider;
-import org.onap.so.monitoring.rest.service.HttpRestServiceProviderImpl;
+import org.onap.so.configuration.rest.BasicHttpHeadersProvider;
+import org.onap.so.configuration.rest.HttpHeadersProvider;
+import org.onap.so.rest.service.HttpRestServiceProvider;
+import org.onap.so.rest.service.HttpRestServiceProviderImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.web.client.RestTemplate;
/**
@@ -45,28 +45,22 @@ public class HttpServiceProviderConfiguration {
@Bean
@Qualifier(CAMUNDA_HTTP_REST_SERVICE_PROVIDER)
public HttpRestServiceProvider camundaHttpRestServiceProvider(
- @Qualifier(CAMUNDA_REST_TEMPLATE) @Autowired final RestTemplate restTemplate,
+ @Qualifier(CONFIGURABLE_REST_TEMPLATE) @Autowired final RestTemplate restTemplate,
@Value(value = "${camunda.rest.api.auth:#{null}}") final String authorization) {
- return getHttpRestServiceProvider(restTemplate, authorization);
+ return getHttpRestServiceProvider(restTemplate, new BasicHttpHeadersProvider(authorization));
}
@Bean
@Qualifier(DATABASE_HTTP_REST_SERVICE_PROVIDER)
public HttpRestServiceProvider databaseHttpRestServiceProvider(
- @Qualifier(DATABASE_REST_TEMPLATE) @Autowired final RestTemplate restTemplate,
+ @Qualifier(CONFIGURABLE_REST_TEMPLATE) @Autowired final RestTemplate restTemplate,
@Value(value = "${mso.database.rest.api.auth:#{null}}") final String authorization) {
-
- return getHttpRestServiceProvider(restTemplate, authorization);
+ return getHttpRestServiceProvider(restTemplate, new BasicHttpHeadersProvider(authorization));
}
private HttpRestServiceProvider getHttpRestServiceProvider(final RestTemplate restTemplate,
- final String authorization) {
- if (authorization != null && !authorization.isEmpty()) {
- final ClientHttpRequestInterceptor authorizationInterceptor =
- new BasicAuthorizationHttpRequestInterceptor(authorization);
- restTemplate.getInterceptors().add(authorizationInterceptor);
- }
- return new HttpRestServiceProviderImpl(restTemplate);
+ final HttpHeadersProvider httpHeadersProvider) {
+ return new HttpRestServiceProviderImpl(restTemplate, httpHeadersProvider);
}
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/RestTemplateConfiguration.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/RestTemplateConfiguration.java
deleted file mode 100644
index f8f0f687cf..0000000000
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/RestTemplateConfiguration.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.so.monitoring.configuration.rest;
-
-import java.util.concurrent.TimeUnit;
-
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
-import org.springframework.web.client.RestTemplate;
-
-/**
- * @author waqas.ikram@ericsson.com
- */
-@Configuration
-public class RestTemplateConfiguration {
-
- public static final String DATABASE_REST_TEMPLATE = "databaseRestTemplate";
-
- public static final String CAMUNDA_REST_TEMPLATE = "camundaRestTemplate";
-
- @Autowired
- private HttpClientConnectionConfiguration clientConnectionConfiguration;
-
- @Bean
- @Qualifier(CAMUNDA_REST_TEMPLATE)
- public RestTemplate camundaRestTemplate() {
- return new RestTemplate(httpComponentsClientHttpRequestFactory());
- }
-
- @Bean
- @Qualifier(DATABASE_REST_TEMPLATE)
- public RestTemplate dataBasecamundaRestTemplate() {
- return new RestTemplate(httpComponentsClientHttpRequestFactory());
- }
-
- @Bean
- public HttpComponentsClientHttpRequestFactory httpComponentsClientHttpRequestFactory() {
- return new HttpComponentsClientHttpRequestFactory(httpClient());
- }
-
- @Bean
- public CloseableHttpClient httpClient() {
- return HttpClientBuilder.create().setConnectionManager(poolingHttpClientConnectionManager())
- .setMaxConnPerRoute(clientConnectionConfiguration.getMaxConnectionsPerRoute())
- .setMaxConnTotal(clientConnectionConfiguration.getMaxConnections())
- .setDefaultRequestConfig(requestConfig()).build();
- }
-
- @Bean
- public PoolingHttpClientConnectionManager poolingHttpClientConnectionManager() {
- return new PoolingHttpClientConnectionManager(clientConnectionConfiguration.getTimeToLiveInMins(),
- TimeUnit.MINUTES);
- }
-
- @Bean
- public RequestConfig requestConfig() {
- return RequestConfig.custom().setSocketTimeout(clientConnectionConfiguration.getSocketTimeOutInMiliSeconds())
- .setConnectTimeout(clientConnectionConfiguration.getConnectionTimeOutInMilliSeconds()).build();
- }
-}
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/db/service/DatabaseServiceProviderImpl.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/db/service/DatabaseServiceProviderImpl.java
index 6be6367302..49e3d4f92f 100644
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/db/service/DatabaseServiceProviderImpl.java
+++ b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/db/service/DatabaseServiceProviderImpl.java
@@ -30,7 +30,7 @@ import org.onap.so.monitoring.camunda.model.SoActiveInfraRequests;
import org.onap.so.monitoring.configuration.database.DatabaseUrlProvider;
import org.onap.so.monitoring.model.SoInfraRequest;
import org.onap.so.monitoring.model.SoInfraRequestBuilder;
-import org.onap.so.monitoring.rest.service.HttpRestServiceProvider;
+import org.onap.so.rest.service.HttpRestServiceProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
@@ -60,7 +60,7 @@ public class DatabaseServiceProviderImpl implements DatabaseServiceProvider {
final String url = urlProvider.getSearchUrl(startTime, endTime, maxResult);
final Optional<SoActiveInfraRequests[]> optionalRequests =
- httpRestServiceProvider.postHttpRequest(filters, url, SoActiveInfraRequests[].class);
+ httpRestServiceProvider.post(filters, url, SoActiveInfraRequests[].class);
if (optionalRequests.isPresent()) {
return getSoInfraRequest(optionalRequests.get());
}
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/exception/InvalidRestRequestException.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/exception/InvalidRestRequestException.java
deleted file mode 100644
index 4d3c489fa9..0000000000
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/exception/InvalidRestRequestException.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-package org.onap.so.monitoring.exception;
-
-/**
- * @author waqas.ikram@ericsson.com
- *
- */
-public class InvalidRestRequestException extends RuntimeException {
- private static final long serialVersionUID = -1158414939006977465L;
-
- public InvalidRestRequestException(final String message) {
- super(message);
- }
-
- public InvalidRestRequestException(final String message, final Throwable cause) {
- super(message, cause);
- }
-}
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/exception/RestProcessingException.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/exception/RestProcessingException.java
deleted file mode 100644
index ab25854542..0000000000
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/exception/RestProcessingException.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-package org.onap.so.monitoring.exception;
-
-/**
- * @author waqas.ikram@ericsson.com
- *
- */
-public class RestProcessingException extends RuntimeException {
-
- private static final long serialVersionUID = 16862313537198441L;
-
- public RestProcessingException(final String message) {
- super(message);
- }
-
- public RestProcessingException(final String message, final Throwable cause) {
- super(message, cause);
- }
-}
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderImpl.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderImpl.java
index e6fbb68456..b7a439fc28 100644
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderImpl.java
+++ b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderImpl.java
@@ -35,15 +35,15 @@ import org.onap.so.monitoring.model.ProcessDefinitionDetail;
import org.onap.so.monitoring.model.ProcessInstanceDetail;
import org.onap.so.monitoring.model.ProcessInstanceIdDetail;
import org.onap.so.monitoring.model.ProcessInstanceVariableDetail;
+import org.onap.so.rest.service.HttpRestServiceProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import com.google.common.base.Optional;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
* @author waqas.ikram@ericsson.com
*/
@@ -64,13 +64,12 @@ public class CamundaProcessDataServiceProviderImpl implements CamundaProcessData
@Override
public Optional<ProcessInstanceIdDetail> getProcessInstanceIdDetail(final String requestId) {
final String url = urlProvider.getHistoryProcessInstanceUrl(requestId);
- final Optional<ProcessInstance[]> processInstances =
- httpRestServiceProvider.getHttpResponse(url, ProcessInstance[].class);
+ final Optional<ProcessInstance[]> processInstances = httpRestServiceProvider.get(url, ProcessInstance[].class);
if (processInstances.isPresent()) {
final ProcessInstance[] instances = processInstances.get();
- final String message = "found process instance for request id: " + requestId +
- ", result size: " + instances.length;
+ final String message =
+ "found process instance for request id: " + requestId + ", result size: " + instances.length;
LOGGER.debug(message);
if (instances.length > 0) {
@@ -79,8 +78,8 @@ public class CamundaProcessDataServiceProviderImpl implements CamundaProcessData
if (processInstance.getSuperProcessInstanceId() == null) {
return Optional.of(new ProcessInstanceIdDetail(processInstance.getId()));
}
- LOGGER.debug("found sub process instance id with super process instanceId: " +
- processInstance.getSuperProcessInstanceId());
+ LOGGER.debug("found sub process instance id with super process instanceId: "
+ + processInstance.getSuperProcessInstanceId());
}
}
}
@@ -91,8 +90,7 @@ public class CamundaProcessDataServiceProviderImpl implements CamundaProcessData
@Override
public Optional<ProcessInstanceDetail> getSingleProcessInstanceDetail(final String processInstanceId) {
final String url = urlProvider.getSingleProcessInstanceUrl(processInstanceId);
- final Optional<ProcessInstance> processInstances =
- httpRestServiceProvider.getHttpResponse(url, ProcessInstance.class);
+ final Optional<ProcessInstance> processInstances = httpRestServiceProvider.get(url, ProcessInstance.class);
if (processInstances.isPresent()) {
final ProcessInstance processInstance = processInstances.get();
@@ -111,8 +109,7 @@ public class CamundaProcessDataServiceProviderImpl implements CamundaProcessData
@Override
public Optional<ProcessDefinitionDetail> getProcessDefinition(final String processDefinitionId) {
final String url = urlProvider.getProcessDefinitionUrl(processDefinitionId);
- final Optional<ProcessDefinition> response =
- httpRestServiceProvider.getHttpResponse(url, ProcessDefinition.class);
+ final Optional<ProcessDefinition> response = httpRestServiceProvider.get(url, ProcessDefinition.class);
if (response.isPresent()) {
final ProcessDefinition processDefinition = response.get();
final String xmlDefinition = processDefinition.getBpmn20Xml();
@@ -120,16 +117,14 @@ public class CamundaProcessDataServiceProviderImpl implements CamundaProcessData
return Optional.of(new ProcessDefinitionDetail(processDefinitionId, xmlDefinition));
}
}
- LOGGER.error("Unable to find process definition for processDefinitionId: " +
- processDefinitionId);
+ LOGGER.error("Unable to find process definition for processDefinitionId: " + processDefinitionId);
return Optional.absent();
}
@Override
public List<ActivityInstanceDetail> getActivityInstance(final String processInstanceId) {
final String url = urlProvider.getActivityInstanceUrl(processInstanceId);
- final Optional<ActivityInstance[]> response =
- httpRestServiceProvider.getHttpResponse(url, ActivityInstance[].class);
+ final Optional<ActivityInstance[]> response = httpRestServiceProvider.get(url, ActivityInstance[].class);
if (response.isPresent()) {
final ActivityInstance[] activityInstances = response.get();
final List<ActivityInstanceDetail> activityInstanceDetails = new ArrayList<>(activityInstances.length);
@@ -148,8 +143,7 @@ public class CamundaProcessDataServiceProviderImpl implements CamundaProcessData
}
return activityInstanceDetails;
}
- LOGGER.error("Unable to find activity intance detail for process instance id: " +
- processInstanceId);
+ LOGGER.error("Unable to find activity intance detail for process instance id: " + processInstanceId);
return Collections.emptyList();
}
@@ -157,7 +151,7 @@ public class CamundaProcessDataServiceProviderImpl implements CamundaProcessData
public List<ProcessInstanceVariableDetail> getProcessInstanceVariable(final String processInstanceId) {
final String url = urlProvider.getProcessInstanceVariablesUrl(processInstanceId);
final Optional<ProcessInstanceVariable[]> response =
- httpRestServiceProvider.getHttpResponse(url, ProcessInstanceVariable[].class);
+ httpRestServiceProvider.get(url, ProcessInstanceVariable[].class);
if (response.isPresent()) {
final ProcessInstanceVariable[] instanceVariables = response.get();
final List<ProcessInstanceVariableDetail> instanceVariableDetails =
@@ -171,8 +165,7 @@ public class CamundaProcessDataServiceProviderImpl implements CamundaProcessData
}
return instanceVariableDetails;
}
- LOGGER.error("Unable to find process intance variable details for process instance id: "
- + processInstanceId);
+ LOGGER.error("Unable to find process intance variable details for process instance id: " + processInstanceId);
return Collections.emptyList();
}
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/HttpRestServiceProvider.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/HttpRestServiceProvider.java
deleted file mode 100644
index 4606c04e05..0000000000
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/HttpRestServiceProvider.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-package org.onap.so.monitoring.rest.service;
-
-import com.google.common.base.Optional;
-
-/**
- * @author waqas.ikram@ericsson.com
- */
-public interface HttpRestServiceProvider {
-
- public <T> Optional<T> getHttpResponse(final String url, final Class<T> clazz);
-
- public <T> Optional<T> postHttpRequest(final Object object, final String url, final Class<T> clazz);
-
-}
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/HttpRestServiceProviderImpl.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/HttpRestServiceProviderImpl.java
deleted file mode 100644
index 82a54c10a2..0000000000
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/HttpRestServiceProviderImpl.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-package org.onap.so.monitoring.rest.service;
-
-import org.onap.so.monitoring.exception.InvalidRestRequestException;
-import org.onap.so.monitoring.exception.RestProcessingException;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.client.HttpClientErrorException;
-import org.springframework.web.client.RestClientException;
-import org.springframework.web.client.RestTemplate;
-
-import com.google.common.base.Optional;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @author waqas.ikram@ericsson.com
- */
-public class HttpRestServiceProviderImpl implements HttpRestServiceProvider {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(HttpRestServiceProviderImpl.class);
- private final RestTemplate restTemplate;
-
- public HttpRestServiceProviderImpl(final RestTemplate restTemplate) {
- this.restTemplate = restTemplate;
- }
-
- @Override
- public <T> Optional<T> getHttpResponse(final String url, final Class<T> clazz) {
- LOGGER.trace("Will invoke HTTP GET using URL: " + url);
- try {
- final ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.GET, null, clazz);
- if (!response.getStatusCode().equals(HttpStatus.OK)) {
- final String message = "Unable to invoke HTTP GET using URL: " + url +
- ", Response Code: " + response.getStatusCode();
- LOGGER.error(message);
- return Optional.absent();
- }
-
- if (response.hasBody()) {
- return Optional.of(response.getBody());
- }
- } catch (final HttpClientErrorException httpClientErrorException) {
- final String message = "Unable to invoke HTTP GET using url: " + url + ", Response: " +
- httpClientErrorException.getRawStatusCode();
- LOGGER.error(message, httpClientErrorException);
- final int rawStatusCode = httpClientErrorException.getRawStatusCode();
- if (rawStatusCode == HttpStatus.BAD_REQUEST.value() || rawStatusCode == HttpStatus.NOT_FOUND.value()) {
- throw new InvalidRestRequestException("No result found for given url: " + url);
- }
- throw new RestProcessingException("Unable to invoke HTTP GET using URL: " + url);
-
- } catch (final RestClientException restClientException) {
- LOGGER.error("Unable to invoke HTTP GET using url: " + url, restClientException);
- throw new RestProcessingException("Unable to invoke HTTP GET using URL: " +
- url, restClientException);
- }
-
- return Optional.absent();
- }
-
- @Override
- public <T> Optional<T> postHttpRequest(final Object object, final String url, final Class<T> clazz) {
- try {
- final HttpEntity<?> request = new HttpEntity<>(object);
- final ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.POST, request, clazz);
- if (!response.getStatusCode().equals(HttpStatus.OK)) {
- final String message = "Unable to invoke HTTP GET using URL: " + url +
- ", Response Code: " + response.getStatusCode();
- LOGGER.error(message);
- return Optional.absent();
- }
-
- if (response.hasBody()) {
- return Optional.of(response.getBody());
- }
-
- } catch (final HttpClientErrorException httpClientErrorException) {
- final String message = "Unable to invoke HTTP POST using url: " + url +
- ", Response: " + httpClientErrorException.getRawStatusCode();
- LOGGER.error(message, httpClientErrorException);
- final int rawStatusCode = httpClientErrorException.getRawStatusCode();
- if (rawStatusCode == HttpStatus.BAD_REQUEST.value() || rawStatusCode == HttpStatus.NOT_FOUND.value()) {
- throw new InvalidRestRequestException("No result found for given url: " + url);
- }
- throw new RestProcessingException("Unable to invoke HTTP POST using URL: " + url);
-
- } catch (final RestClientException restClientException) {
- LOGGER.error("Unable to invoke HTTP POST using url: " + url, restClientException);
- throw new RestProcessingException("Unable to invoke HTTP POST using URL: "
- + url, restClientException);
- }
-
- return Optional.absent();
- }
-
-
-}
diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/HttpServiceProviderConfigurationTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/HttpServiceProviderConfigurationTest.java
index 1b3e168c12..9df24c1921 100644
--- a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/HttpServiceProviderConfigurationTest.java
+++ b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/HttpServiceProviderConfigurationTest.java
@@ -23,7 +23,7 @@ import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.onap.so.monitoring.configuration.rest.HttpServiceProviderConfiguration;
-import org.onap.so.monitoring.rest.service.HttpRestServiceProvider;
+import org.onap.so.rest.service.HttpRestServiceProvider;
import org.springframework.web.client.RestTemplate;
/**
diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/db/api/DatabaseServiceProviderTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/db/api/DatabaseServiceProviderTest.java
index 58666671a7..3a7ce18bf7 100644
--- a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/db/api/DatabaseServiceProviderTest.java
+++ b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/db/api/DatabaseServiceProviderTest.java
@@ -38,7 +38,7 @@ import org.onap.so.monitoring.configuration.database.DatabaseUrlProvider;
import org.onap.so.monitoring.db.service.DatabaseServiceProvider;
import org.onap.so.monitoring.db.service.DatabaseServiceProviderImpl;
import org.onap.so.monitoring.model.SoInfraRequest;
-import org.onap.so.monitoring.rest.service.HttpRestServiceProvider;
+import org.onap.so.rest.service.HttpRestServiceProvider;
import com.google.common.base.Optional;
@@ -57,8 +57,8 @@ public class DatabaseServiceProviderTest {
final String searchUrl = URL_PROVIDER.getSearchUrl(0, 0, null);
final Optional<SoActiveInfraRequests[]> response = Optional.of(new SoActiveInfraRequests[] {});
- when(mockServiceProvider.postHttpRequest(eq(Collections.emptyMap()), eq(searchUrl),
- eq(SoActiveInfraRequests[].class))).thenReturn(response);
+ when(mockServiceProvider.post(eq(Collections.emptyMap()), eq(searchUrl), eq(SoActiveInfraRequests[].class)))
+ .thenReturn(response);
final DatabaseServiceProvider objUnderTest = new DatabaseServiceProviderImpl(URL_PROVIDER, mockServiceProvider);
@@ -71,8 +71,8 @@ public class DatabaseServiceProviderTest {
final String searchUrl = URL_PROVIDER.getSearchUrl(0, 0, null);
final Optional<SoActiveInfraRequests[]> response = Optional.absent();
- when(mockServiceProvider.postHttpRequest(eq(Collections.emptyMap()), eq(searchUrl),
- eq(SoActiveInfraRequests[].class))).thenReturn(response);
+ when(mockServiceProvider.post(eq(Collections.emptyMap()), eq(searchUrl), eq(SoActiveInfraRequests[].class)))
+ .thenReturn(response);
final DatabaseServiceProvider objUnderTest = new DatabaseServiceProviderImpl(URL_PROVIDER, mockServiceProvider);
@@ -94,7 +94,7 @@ public class DatabaseServiceProviderTest {
final HttpRestServiceProvider mockServiceProvider = mock(HttpRestServiceProvider.class);
- when(mockServiceProvider.postHttpRequest(eq(filters), eq(searchUrl), eq(SoActiveInfraRequests[].class)))
+ when(mockServiceProvider.post(eq(filters), eq(searchUrl), eq(SoActiveInfraRequests[].class)))
.thenReturn(response);
final DatabaseServiceProvider objUnderTest = new DatabaseServiceProviderImpl(URL_PROVIDER, mockServiceProvider);
diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderTest.java
index c3930df196..d21cf6d02b 100644
--- a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderTest.java
+++ b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderTest.java
@@ -38,6 +38,7 @@ import org.onap.so.monitoring.model.ActivityInstanceDetail;
import org.onap.so.monitoring.model.ProcessDefinitionDetail;
import org.onap.so.monitoring.model.ProcessInstanceIdDetail;
import org.onap.so.monitoring.model.ProcessInstanceVariableDetail;
+import org.onap.so.rest.service.HttpRestServiceProvider;
import com.google.common.base.Optional;
@@ -65,7 +66,7 @@ public class CamundaProcessDataServiceProviderTest {
public void test_GetProcessInstanceDetail_EmptyResponse() {
final Optional<ProcessInstance[]> response = Optional.<ProcessInstance[]>absent();
final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/process-instance?variables=requestId_eq_" + ID;
- when(httpRestServiceProvider.getHttpResponse(url, ProcessInstance[].class)).thenReturn(response);
+ when(httpRestServiceProvider.get(url, ProcessInstance[].class)).thenReturn(response);
final CamundaProcessDataServiceProvider objUnderTest =
new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider);
@@ -77,7 +78,7 @@ public class CamundaProcessDataServiceProviderTest {
public void test_GetProcessInstanceDetail_NonEmptyResponseWithSuperProcessIdNull() {
final Optional<ProcessInstance[]> response = Optional.of(getProcessInstance());
final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/process-instance?variables=requestId_eq_" + ID;
- when(httpRestServiceProvider.getHttpResponse(url, ProcessInstance[].class)).thenReturn(response);
+ when(httpRestServiceProvider.get(url, ProcessInstance[].class)).thenReturn(response);
final CamundaProcessDataServiceProvider objUnderTest =
new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider);
@@ -92,7 +93,7 @@ public class CamundaProcessDataServiceProviderTest {
public void test_GetProcessInstanceDetail_NonEmptyResponseWithSuperProcessIdNotNull() {
final Optional<ProcessInstance[]> response = Optional.of(getProcessInstance(SUPER_PROCESS_ID));
final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/process-instance?variables=requestId_eq_" + ID;
- when(httpRestServiceProvider.getHttpResponse(url, ProcessInstance[].class)).thenReturn(response);
+ when(httpRestServiceProvider.get(url, ProcessInstance[].class)).thenReturn(response);
final CamundaProcessDataServiceProvider objUnderTest =
new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider);
@@ -105,7 +106,7 @@ public class CamundaProcessDataServiceProviderTest {
public void test_GetProcessDefinition_EmptyResponse() {
final Optional<ProcessDefinition> response = Optional.<ProcessDefinition>absent();
final String url = CAMUNDA_REST_API_URL + DEFAULT + "/process-definition/" + ID + "/xml";
- when(httpRestServiceProvider.getHttpResponse(url, ProcessDefinition.class)).thenReturn(response);
+ when(httpRestServiceProvider.get(url, ProcessDefinition.class)).thenReturn(response);
final CamundaProcessDataServiceProvider objUnderTest =
new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider);
@@ -117,7 +118,7 @@ public class CamundaProcessDataServiceProviderTest {
public void test_GetProcessDefinition_NonEmptyResponse() {
final Optional<ProcessDefinition> response = getProcessDefinition();
final String url = CAMUNDA_REST_API_URL + DEFAULT + "/process-definition/" + PROCESS_ID + "/xml";
- when(httpRestServiceProvider.getHttpResponse(url, ProcessDefinition.class)).thenReturn(response);
+ when(httpRestServiceProvider.get(url, ProcessDefinition.class)).thenReturn(response);
final CamundaProcessDataServiceProvider objUnderTest =
new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider);
@@ -132,7 +133,7 @@ public class CamundaProcessDataServiceProviderTest {
final Optional<ActivityInstance[]> response = Optional.<ActivityInstance[]>absent();
final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/activity-instance?processInstanceId=" + PROCESS_ID
+ "&sortBy=startTime&sortOrder=asc";
- when(httpRestServiceProvider.getHttpResponse(url, ActivityInstance[].class)).thenReturn(response);
+ when(httpRestServiceProvider.get(url, ActivityInstance[].class)).thenReturn(response);
final CamundaProcessDataServiceProvider objUnderTest =
new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider);
@@ -146,7 +147,7 @@ public class CamundaProcessDataServiceProviderTest {
final Optional<ActivityInstance[]> response = getActivityInstance();
final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/activity-instance?processInstanceId=" + PROCESS_ID
+ "&sortBy=startTime&sortOrder=asc";
- when(httpRestServiceProvider.getHttpResponse(url, ActivityInstance[].class)).thenReturn(response);
+ when(httpRestServiceProvider.get(url, ActivityInstance[].class)).thenReturn(response);
final CamundaProcessDataServiceProvider objUnderTest =
new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider);
@@ -164,7 +165,7 @@ public class CamundaProcessDataServiceProviderTest {
final Optional<ProcessInstanceVariable[]> response = Optional.<ProcessInstanceVariable[]>absent();
final String url =
CAMUNDA_REST_API_URL + DEFAULT + "/history/variable-instance?processInstanceId=" + PROCESS_ID;
- when(httpRestServiceProvider.getHttpResponse(url, ProcessInstanceVariable[].class)).thenReturn(response);
+ when(httpRestServiceProvider.get(url, ProcessInstanceVariable[].class)).thenReturn(response);
final CamundaProcessDataServiceProvider objUnderTest =
new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider);
@@ -178,7 +179,7 @@ public class CamundaProcessDataServiceProviderTest {
final Optional<ProcessInstanceVariable[]> response = getProcessInstanceVariable();
final String url =
CAMUNDA_REST_API_URL + DEFAULT + "/history/variable-instance?processInstanceId=" + PROCESS_ID;
- when(httpRestServiceProvider.getHttpResponse(url, ProcessInstanceVariable[].class)).thenReturn(response);
+ when(httpRestServiceProvider.get(url, ProcessInstanceVariable[].class)).thenReturn(response);
final CamundaProcessDataServiceProvider objUnderTest =
new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider);
diff --git a/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/SoMonitoringController.java b/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/SoMonitoringController.java
index 155b4e65a4..d2fa08fdfd 100644
--- a/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/SoMonitoringController.java
+++ b/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/SoMonitoringController.java
@@ -33,8 +33,6 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.onap.so.monitoring.db.service.DatabaseServiceProvider;
-import org.onap.so.monitoring.exception.InvalidRestRequestException;
-import org.onap.so.monitoring.exception.RestProcessingException;
import org.onap.so.monitoring.model.ActivityInstanceDetail;
import org.onap.so.monitoring.model.ProcessDefinitionDetail;
import org.onap.so.monitoring.model.ProcessInstanceDetail;
@@ -42,14 +40,15 @@ import org.onap.so.monitoring.model.ProcessInstanceIdDetail;
import org.onap.so.monitoring.model.ProcessInstanceVariableDetail;
import org.onap.so.monitoring.model.SoInfraRequest;
import org.onap.so.monitoring.rest.service.CamundaProcessDataServiceProvider;
+import org.onap.so.rest.exceptions.InvalidRestRequestException;
+import org.onap.so.rest.exceptions.RestProcessingException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.google.common.base.Optional;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
* @author waqas.ikram@ericsson.com
*/
@@ -134,8 +133,7 @@ public class SoMonitoringController {
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response getProcessDefinitionXml(final @PathParam("processDefinitionId") String processDefinitionId) {
if (processDefinitionId == null || processDefinitionId.isEmpty()) {
- return Response.status(Status.BAD_REQUEST).entity("Invalid process definition id: " +
- processDefinitionId)
+ return Response.status(Status.BAD_REQUEST).entity("Invalid process definition id: " + processDefinitionId)
.build();
}
try {
@@ -145,18 +143,15 @@ public class SoMonitoringController {
final ProcessDefinitionDetail definitionDetail = response.get();
return Response.status(Status.OK).entity(definitionDetail).build();
}
- LOGGER.error("Unable to find process definition xml for processDefinitionId: " +
- processDefinitionId);
+ LOGGER.error("Unable to find process definition xml for processDefinitionId: " + processDefinitionId);
return Response.status(Status.NO_CONTENT).build();
} catch (final InvalidRestRequestException extensions) {
final String message =
- "Unable to find process definition xml for processDefinitionId: {}" +
- processDefinitionId;
+ "Unable to find process definition xml for processDefinitionId: {}" + processDefinitionId;
return Response.status(Status.BAD_REQUEST).entity(message).build();
} catch (final RestProcessingException restProcessingException) {
- final String message = "Unable to get process definition xml for id: " +
- processDefinitionId;
+ final String message = "Unable to get process definition xml for id: " + processDefinitionId;
LOGGER.error(message);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(message).build();
}
@@ -175,13 +170,11 @@ public class SoMonitoringController {
camundaProcessDataServiceProvider.getActivityInstance(processInstanceId);
return Response.status(Status.OK).entity(activityInstanceDetails).build();
} catch (final InvalidRestRequestException extensions) {
- final String message = "Unable to find activity instance for processInstanceId: " +
- processInstanceId;
+ final String message = "Unable to find activity instance for processInstanceId: " + processInstanceId;
LOGGER.error(message);
return Response.status(Status.BAD_REQUEST).entity(message).build();
} catch (final RestProcessingException restProcessingException) {
- final String message = "Unable to get activity instance detail for id: " +
- processInstanceId;
+ final String message = "Unable to get activity instance detail for id: " + processInstanceId;
LOGGER.error(message);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(message).build();
}
@@ -201,13 +194,11 @@ public class SoMonitoringController {
return Response.status(Status.OK).entity(processInstanceVariable).build();
} catch (final InvalidRestRequestException extensions) {
final String message =
- "Unable to find process instance variables for processInstanceId: " +
- processInstanceId;
+ "Unable to find process instance variables for processInstanceId: " + processInstanceId;
LOGGER.error(message);
return Response.status(Status.BAD_REQUEST).entity(message).build();
} catch (final RestProcessingException restProcessingException) {
- final String message = "Unable to get process instance variables for id: " +
- processInstanceId;
+ final String message = "Unable to get process instance variables for id: " + processInstanceId;
LOGGER.error(message);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(message).build();
}
@@ -230,13 +221,13 @@ public class SoMonitoringController {
return Response.status(Status.OK).entity(requests).build();
} catch (final InvalidRestRequestException extensions) {
- final String message = "Unable to search request for filters: " + filters + ", from: " +
- startTime + ", to: " + endTime + ", maxResult: " + maxResult;
+ final String message = "Unable to search request for filters: " + filters + ", from: " + startTime
+ + ", to: " + endTime + ", maxResult: " + maxResult;
LOGGER.error(message);
return Response.status(Status.BAD_REQUEST).entity(message).build();
} catch (final RestProcessingException restProcessingException) {
- final String message = "Unable to search request for filters: " + filters + ", from: " +
- startTime + ", to: " + endTime + ", maxResult: " + maxResult;
+ final String message = "Unable to search request for filters: " + filters + ", from: " + startTime
+ + ", to: " + endTime + ", maxResult: " + maxResult;
LOGGER.error(message);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(message).build();
}
diff --git a/so-monitoring/so-monitoring-service/src/test/java/org/onap/so/monitoring/rest/api/SoMonitoringControllerTest.java b/so-monitoring/so-monitoring-service/src/test/java/org/onap/so/monitoring/rest/api/SoMonitoringControllerTest.java
index 3ca184ebaa..2c4d036397 100644
--- a/so-monitoring/so-monitoring-service/src/test/java/org/onap/so/monitoring/rest/api/SoMonitoringControllerTest.java
+++ b/so-monitoring/so-monitoring-service/src/test/java/org/onap/so/monitoring/rest/api/SoMonitoringControllerTest.java
@@ -22,8 +22,8 @@ package org.onap.so.monitoring.rest.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import static org.onap.so.monitoring.configuration.rest.RestTemplateConfiguration.CAMUNDA_REST_TEMPLATE;
-import static org.onap.so.monitoring.configuration.rest.RestTemplateConfiguration.DATABASE_REST_TEMPLATE;
+import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
+import static org.onap.so.configuration.rest.BasicHttpHeadersProvider.AUTHORIZATION_HEADER;
import static org.onap.so.monitoring.rest.api.Constants.ACTIVITY_INSTANCE_RESPONSE_JSON_FILE;
import static org.onap.so.monitoring.rest.api.Constants.EMPTY_ARRAY_RESPONSE;
import static org.onap.so.monitoring.rest.api.Constants.EMPTY_STRING;
@@ -37,6 +37,7 @@ import static org.onap.so.monitoring.rest.api.Constants.PROCRESS_DEF_ID;
import static org.onap.so.monitoring.rest.api.Constants.SEARCH_RESULT_RESPONSE_JSON_FILE;
import static org.onap.so.monitoring.rest.api.Constants.SINGLE_PROCCESS_INSTANCE_RESPONSE_JSON_FILE;
import static org.onap.so.monitoring.rest.api.Constants.START_TIME_IN_MS;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.header;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withBadRequest;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
@@ -81,14 +82,14 @@ import org.springframework.web.client.RestTemplate;
@ActiveProfiles("test")
@SpringBootTest
public class SoMonitoringControllerTest {
+ private static final String CAMUNDA_BASIC_AUTH =
+ "Basic YWRtaW46S3A4Yko0U1hzek0wV1hsaGFrM2VIbGNzZTJnQXc4NHZhb0dHbUp2VXkyVQ==";
- @Autowired
- @Qualifier(CAMUNDA_REST_TEMPLATE)
- private RestTemplate restTemplate;
+ private static final String DATABASE_BASIC_AUTH = "Basic YnBlbDpwYXNzd29yZDEk";
@Autowired
- @Qualifier(DATABASE_REST_TEMPLATE)
- private RestTemplate dataBaseRestTemplate;
+ @Qualifier(CONFIGURABLE_REST_TEMPLATE)
+ private RestTemplate restTemplate;
@Autowired
private CamundaRestUrlProvider urlProvider;
@@ -96,23 +97,22 @@ public class SoMonitoringControllerTest {
@Autowired
private DatabaseUrlProvider databaseUrlProvider;
- private MockRestServiceServer camundaMockServer;
+ private MockRestServiceServer mockRestServiceServer;
- private MockRestServiceServer databaseMockServer;
@Autowired
private SoMonitoringController objUnderTest;
@Before
public void setUp() throws Exception {
- camundaMockServer = MockRestServiceServer.bindTo(restTemplate).build();
- databaseMockServer = MockRestServiceServer.bindTo(dataBaseRestTemplate).build();
+ mockRestServiceServer = MockRestServiceServer.bindTo(restTemplate).build();
}
@Test
public void test_GetProcessInstance_SuccessResponseWithDataFromCamunda() throws Exception {
final String jsonString = getJsonResponse(PROCCESS_INSTANCE_RESPONSE_JSON_FILE);
- this.camundaMockServer.expect(requestTo(urlProvider.getHistoryProcessInstanceUrl(ID)))
+ this.mockRestServiceServer.expect(requestTo(urlProvider.getHistoryProcessInstanceUrl(ID)))
+ .andExpect(header(AUTHORIZATION_HEADER, CAMUNDA_BASIC_AUTH))
.andRespond(withSuccess(jsonString, MediaType.APPLICATION_JSON));
final Response response = objUnderTest.getProcessInstanceId(ID);
@@ -125,7 +125,7 @@ public class SoMonitoringControllerTest {
@Test
public void test_GetProcessInstance_SuccessResponseWithEmptyDataFromCamunda() throws Exception {
final String jsonString = EMPTY_ARRAY_RESPONSE;
- this.camundaMockServer.expect(requestTo(urlProvider.getHistoryProcessInstanceUrl(ID)))
+ this.mockRestServiceServer.expect(requestTo(urlProvider.getHistoryProcessInstanceUrl(ID)))
.andRespond(withSuccess(jsonString, MediaType.APPLICATION_JSON));
final Response response = objUnderTest.getProcessInstanceId(ID);
@@ -135,7 +135,7 @@ public class SoMonitoringControllerTest {
@Test
public void test_GetProcessInstance_FailureResponseWithEmptyDataFromCamunda() throws Exception {
- this.camundaMockServer.expect(requestTo(urlProvider.getHistoryProcessInstanceUrl(ID)))
+ this.mockRestServiceServer.expect(requestTo(urlProvider.getHistoryProcessInstanceUrl(ID)))
.andRespond(withBadRequest());
final Response response = objUnderTest.getProcessInstanceId(ID);
@@ -144,7 +144,7 @@ public class SoMonitoringControllerTest {
@Test
public void test_GetProcessInstance_UnauthorizedRequestFromCamunda() throws Exception {
- this.camundaMockServer.expect(requestTo(urlProvider.getHistoryProcessInstanceUrl(ID)))
+ this.mockRestServiceServer.expect(requestTo(urlProvider.getHistoryProcessInstanceUrl(ID)))
.andRespond(withUnauthorizedRequest());
final Response response = objUnderTest.getProcessInstanceId(ID);
@@ -155,7 +155,7 @@ public class SoMonitoringControllerTest {
@Test
public void test_GetSinlgeProcessInstance_SuccessResponseWithDataFromCamunda() throws Exception {
final String jsonString = getJsonResponse(SINGLE_PROCCESS_INSTANCE_RESPONSE_JSON_FILE);
- this.camundaMockServer.expect(requestTo(urlProvider.getSingleProcessInstanceUrl(PROCESS_INSTACE_ID)))
+ this.mockRestServiceServer.expect(requestTo(urlProvider.getSingleProcessInstanceUrl(PROCESS_INSTACE_ID)))
.andRespond(withSuccess(jsonString, MediaType.APPLICATION_JSON));
final Response response = objUnderTest.getSingleProcessInstance(PROCESS_INSTACE_ID);
@@ -171,7 +171,7 @@ public class SoMonitoringControllerTest {
@Test
public void test_GetSingleProcessInstance_WithBadRequestResponseFromCamunda() throws Exception {
- this.camundaMockServer.expect(requestTo(urlProvider.getSingleProcessInstanceUrl(PROCESS_INSTACE_ID)))
+ this.mockRestServiceServer.expect(requestTo(urlProvider.getSingleProcessInstanceUrl(PROCESS_INSTACE_ID)))
.andRespond(withBadRequest());
final Response response = objUnderTest.getSingleProcessInstance(PROCESS_INSTACE_ID);
@@ -181,7 +181,7 @@ public class SoMonitoringControllerTest {
@Test
public void test_GetSingleProcessInstance_WithUnauthorizedRequestResponseFromCamunda() throws Exception {
- this.camundaMockServer.expect(requestTo(urlProvider.getSingleProcessInstanceUrl(PROCESS_INSTACE_ID)))
+ this.mockRestServiceServer.expect(requestTo(urlProvider.getSingleProcessInstanceUrl(PROCESS_INSTACE_ID)))
.andRespond(withUnauthorizedRequest());
final Response response = objUnderTest.getSingleProcessInstance(PROCESS_INSTACE_ID);
@@ -216,7 +216,7 @@ public class SoMonitoringControllerTest {
@Test
public void test_GetProcessDefinitionXml_SuccessResponseWithDataFromCamunda() throws Exception {
final String jsonString = getJsonResponse(PROCESS_DEF_RESPONSE_JSON_FILE);
- this.camundaMockServer.expect(requestTo(urlProvider.getProcessDefinitionUrl(PROCRESS_DEF_ID)))
+ this.mockRestServiceServer.expect(requestTo(urlProvider.getProcessDefinitionUrl(PROCRESS_DEF_ID)))
.andRespond(withSuccess(jsonString, MediaType.APPLICATION_JSON));
final Response response = objUnderTest.getProcessDefinitionXml(PROCRESS_DEF_ID);
@@ -228,7 +228,7 @@ public class SoMonitoringControllerTest {
@Test
public void test_GetProcessDefinitionXml_BadRequestResponseFromCamunda() throws Exception {
- this.camundaMockServer.expect(requestTo(urlProvider.getProcessDefinitionUrl(PROCRESS_DEF_ID)))
+ this.mockRestServiceServer.expect(requestTo(urlProvider.getProcessDefinitionUrl(PROCRESS_DEF_ID)))
.andRespond(withBadRequest());
final Response response = objUnderTest.getProcessDefinitionXml(PROCRESS_DEF_ID);
@@ -238,7 +238,7 @@ public class SoMonitoringControllerTest {
@Test
public void test_GetProcessDefinitionXml_UnauthorizedRequestFromCamunda() throws Exception {
- this.camundaMockServer.expect(requestTo(urlProvider.getProcessDefinitionUrl(PROCRESS_DEF_ID)))
+ this.mockRestServiceServer.expect(requestTo(urlProvider.getProcessDefinitionUrl(PROCRESS_DEF_ID)))
.andRespond(withUnauthorizedRequest());
final Response response = objUnderTest.getProcessDefinitionXml(PROCRESS_DEF_ID);
@@ -260,7 +260,7 @@ public class SoMonitoringControllerTest {
@Test
public void test_GetActivityInstanceDetail_SuccessResponseWithDataFromCamunda() throws Exception {
final String jsonString = getJsonResponse(ACTIVITY_INSTANCE_RESPONSE_JSON_FILE);
- this.camundaMockServer.expect(requestTo(urlProvider.getActivityInstanceUrl(PROCESS_INSTACE_ID)))
+ this.mockRestServiceServer.expect(requestTo(urlProvider.getActivityInstanceUrl(PROCESS_INSTACE_ID)))
.andRespond(withSuccess(jsonString, MediaType.APPLICATION_JSON));
final Response response = objUnderTest.getActivityInstanceDetail(PROCESS_INSTACE_ID);
@@ -287,7 +287,7 @@ public class SoMonitoringControllerTest {
@Test
public void test_GetActivityInstanceDetail_SuccessResponseWithEmptyDataFromCamunda() throws Exception {
- this.camundaMockServer.expect(requestTo(urlProvider.getActivityInstanceUrl(PROCESS_INSTACE_ID)))
+ this.mockRestServiceServer.expect(requestTo(urlProvider.getActivityInstanceUrl(PROCESS_INSTACE_ID)))
.andRespond(withSuccess(EMPTY_ARRAY_RESPONSE, MediaType.APPLICATION_JSON));
final Response response = objUnderTest.getActivityInstanceDetail(PROCESS_INSTACE_ID);
@@ -297,7 +297,7 @@ public class SoMonitoringControllerTest {
@Test
public void test_GetActivityInstanceDetail_UnauthorizedRequestFromCamunda() throws Exception {
- this.camundaMockServer.expect(requestTo(urlProvider.getActivityInstanceUrl(PROCESS_INSTACE_ID)))
+ this.mockRestServiceServer.expect(requestTo(urlProvider.getActivityInstanceUrl(PROCESS_INSTACE_ID)))
.andRespond(withUnauthorizedRequest());
final Response response = objUnderTest.getActivityInstanceDetail(PROCESS_INSTACE_ID);
@@ -307,7 +307,7 @@ public class SoMonitoringControllerTest {
@Test
public void test_GetActivityInstanceDetail_BadRequestFromCamunda() throws Exception {
- this.camundaMockServer.expect(requestTo(urlProvider.getActivityInstanceUrl(PROCESS_INSTACE_ID)))
+ this.mockRestServiceServer.expect(requestTo(urlProvider.getActivityInstanceUrl(PROCESS_INSTACE_ID)))
.andRespond(withBadRequest());
final Response response = objUnderTest.getActivityInstanceDetail(PROCESS_INSTACE_ID);
@@ -329,7 +329,7 @@ public class SoMonitoringControllerTest {
@Test
public void test_GetProcessInstanceVariables_SuccessResponseWithDataFromCamunda() throws Exception {
final String jsonString = getJsonResponse(PROCESS_INSTANCE_VARIABLES_RESPONSE_JSON_FILE);
- this.camundaMockServer.expect(requestTo(urlProvider.getProcessInstanceVariablesUrl(PROCESS_INSTACE_ID)))
+ this.mockRestServiceServer.expect(requestTo(urlProvider.getProcessInstanceVariablesUrl(PROCESS_INSTACE_ID)))
.andRespond(withSuccess(jsonString, MediaType.APPLICATION_JSON));
final Response response = objUnderTest.getProcessInstanceVariables(PROCESS_INSTACE_ID);
@@ -347,7 +347,7 @@ public class SoMonitoringControllerTest {
@Test
public void test_GetProcessInstanceVariables_SuccessResponseWithEmptyDataFromCamunda() throws Exception {
- this.camundaMockServer.expect(requestTo(urlProvider.getProcessInstanceVariablesUrl(PROCESS_INSTACE_ID)))
+ this.mockRestServiceServer.expect(requestTo(urlProvider.getProcessInstanceVariablesUrl(PROCESS_INSTACE_ID)))
.andRespond(withSuccess(EMPTY_ARRAY_RESPONSE, MediaType.APPLICATION_JSON));
final Response response = objUnderTest.getProcessInstanceVariables(PROCESS_INSTACE_ID);
@@ -358,7 +358,7 @@ public class SoMonitoringControllerTest {
@Test
public void test_GetProcessInstanceVariables_BadRequestFromCamunda() throws Exception {
- this.camundaMockServer.expect(requestTo(urlProvider.getProcessInstanceVariablesUrl(PROCESS_INSTACE_ID)))
+ this.mockRestServiceServer.expect(requestTo(urlProvider.getProcessInstanceVariablesUrl(PROCESS_INSTACE_ID)))
.andRespond(withBadRequest());
final Response response = objUnderTest.getProcessInstanceVariables(PROCESS_INSTACE_ID);
@@ -369,7 +369,7 @@ public class SoMonitoringControllerTest {
@Test
public void test_GetProcessInstanceVariables_UnauthorizedRequestFromCamunda() throws Exception {
- this.camundaMockServer.expect(requestTo(urlProvider.getProcessInstanceVariablesUrl(PROCESS_INSTACE_ID)))
+ this.mockRestServiceServer.expect(requestTo(urlProvider.getProcessInstanceVariablesUrl(PROCESS_INSTACE_ID)))
.andRespond(withUnauthorizedRequest());
final Response response = objUnderTest.getProcessInstanceVariables(PROCESS_INSTACE_ID);
@@ -396,8 +396,9 @@ public class SoMonitoringControllerTest {
@Test
public void test_GetInfraActiveRequests_SuccessResponseWithSoInfraRequestList() throws Exception {
final String jsonString = getJsonResponse(SEARCH_RESULT_RESPONSE_JSON_FILE);
- this.databaseMockServer
+ this.mockRestServiceServer
.expect(requestTo(databaseUrlProvider.getSearchUrl(START_TIME_IN_MS, END_TIME_IN_MS, null)))
+ .andExpect(header(AUTHORIZATION_HEADER, DATABASE_BASIC_AUTH))
.andRespond(withSuccess(jsonString, MediaType.APPLICATION_JSON));
final Response response =