diff options
author | Eylon Malin <eylon.malin@intl.att.com> | 2019-08-05 23:38:18 +0300 |
---|---|---|
committer | Eylon Malin <eylon.malin@intl.att.com> | 2019-08-06 12:32:00 +0300 |
commit | 151d768e923994b3e81ade049d21bf65e931faac (patch) | |
tree | 797fe529428d0dc399992491acd584de58b3107d /vid-app-common/src/main | |
parent | 84d0b4b11a1ae178a6759ce423ce2bd62315ce15 (diff) |
handle errors in change management and tenant isolation
use more tolerance way for parsing responses from MSO so VID can handle
error responses with html body
Issue-ID: VID-378
Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
Change-Id: I72741ec1bf636a1200e8ecbd684ab1f3b2ab332a
Signed-off-by: Ittay Stern <ittay.stern@att.com>
Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
Diffstat (limited to 'vid-app-common/src/main')
4 files changed, 30 insertions, 20 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/OperationalEnvironmentController.java b/vid-app-common/src/main/java/org/onap/vid/controller/OperationalEnvironmentController.java index a6778ad0c..44bdc813b 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/OperationalEnvironmentController.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/OperationalEnvironmentController.java @@ -33,6 +33,7 @@ import org.onap.vid.model.RequestReferencesContainer; import org.onap.vid.mso.MsoBusinessLogic; import org.onap.vid.mso.MsoInterface; import org.onap.vid.mso.MsoResponseWrapper2; +import org.onap.vid.mso.MsoUtil; import org.onap.vid.mso.model.OperationalEnvironmentActivateInfo; import org.onap.vid.mso.model.OperationalEnvironmentDeactivateInfo; import org.onap.vid.mso.rest.OperationalEnvironment.OperationEnvironmentRequestDetails; @@ -80,9 +81,7 @@ public class OperationalEnvironmentController extends VidRestrictedBaseControlle RequestDetailsWrapper<OperationEnvironmentRequestDetails> requestDetailsWrapper = msoBusinessLogic.convertParametersToRequestDetails(operationalEnvironment, userId); String path = msoBusinessLogic.getOperationalEnvironmentCreationPath(); - HttpResponse<RequestReferencesContainer> msoResponse = restMso.post(path, requestDetailsWrapper, RequestReferencesContainer.class); - debugEnd(msoResponse); - return new MsoResponseWrapper2<>(msoResponse); + return MsoUtil.wrapResponse2(restMso.post(path, requestDetailsWrapper, String.class), RequestReferencesContainer.class); } @RequestMapping(value = "/activate", method = RequestMethod.POST) @@ -105,10 +104,7 @@ public class OperationalEnvironmentController extends VidRestrictedBaseControlle String path = msoBusinessLogic.getOperationalEnvironmentActivationPath(activateInfo); RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = msoBusinessLogic.createOperationalEnvironmentActivationRequestDetails(activateInfo); - HttpResponse<RequestReferencesContainer> msoResponse = restMso.post(path, requestDetailsWrapper, RequestReferencesContainer.class); - - debugEnd(msoResponse); - return new MsoResponseWrapper2<>(msoResponse); + return MsoUtil.wrapResponse2(restMso.post(path, requestDetailsWrapper, String.class), RequestReferencesContainer.class); } @RequestMapping(value = "/deactivate", method = RequestMethod.POST) @@ -126,10 +122,7 @@ public class OperationalEnvironmentController extends VidRestrictedBaseControlle String path = msoBusinessLogic.getOperationalEnvironmentDeactivationPath(deactivateInfo); RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = msoBusinessLogic.createOperationalEnvironmentDeactivationRequestDetails(deactivateInfo); - HttpResponse<RequestReferencesContainer> msoResponse = restMso.post(path, requestDetailsWrapper, RequestReferencesContainer.class); - - debugEnd(msoResponse); - return new MsoResponseWrapper2<>(msoResponse); + return MsoUtil.wrapResponse2(restMso.post(path, requestDetailsWrapper, String.class), RequestReferencesContainer.class); } @RequestMapping(value = "/requestStatus", method = RequestMethod.GET) @@ -140,10 +133,7 @@ public class OperationalEnvironmentController extends VidRestrictedBaseControlle verifyIsNotEmpty(requestId, "requestId"); String path = msoBusinessLogic.getCloudResourcesRequestsStatusPath(requestId); - HttpResponse<HashMap> msoResponse = restMso.get(path, HashMap.class); - - LOGGER.debug(EELFLoggerDelegate.debugLogger, "end {}() => {}", getMethodName(), msoResponse); - return new MsoResponseWrapper2<>(msoResponse); + return MsoUtil.wrapResponse2(restMso.get(path, String.class), HashMap.class); } @ExceptionHandler({ diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper2.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper2.java index 9b617189c..318aa6e23 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper2.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper2.java @@ -65,6 +65,12 @@ public class MsoResponseWrapper2<T> implements MsoResponseWrapperInterface { this.raw = null; } + public MsoResponseWrapper2(int status, T entity, String raw) { + this.status = status; + this.entity = entity; + this.raw = raw; + } + public int getStatus() { return status; } diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java index fcc20fafd..5171b7ac8 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java @@ -25,7 +25,6 @@ import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import io.joshworks.restclient.http.HttpResponse; import java.io.IOException; import org.apache.commons.lang3.StringUtils; @@ -34,7 +33,6 @@ import org.onap.vid.exceptions.GenericUncheckedException; public class MsoUtil { - static final ObjectMapper objectMapper = new ObjectMapper(); private MsoUtil() { } @@ -51,7 +49,7 @@ public class MsoUtil { if (httpResponse.getRawBody() != null) { try { T body = httpResponse.getBody(); - String entityStr = body instanceof String ? (String) body : objectMapper.writeValueAsString(httpResponse.getBody()); + String entityStr = body instanceof String ? (String) body : JACKSON_OBJECT_MAPPER.writeValueAsString(httpResponse.getBody()); msoResponseWrapper.setEntity(entityStr); } catch(JsonProcessingException e) { ExceptionUtils.rethrow(e); @@ -60,6 +58,22 @@ public class MsoUtil { return msoResponseWrapper; } + public static <T> MsoResponseWrapper2<T> wrapResponse2(HttpResponse<String> httpResponse, Class<T> clazz) { + String raw = httpResponse.getBody(); // As body's T is String, use getBody as a simple way to get raw + if (raw != null) { + try { + T entity = JACKSON_OBJECT_MAPPER.readValue(raw, clazz); + return new MsoResponseWrapper2<>(httpResponse.getStatus(), entity, raw); + } catch (JsonProcessingException exception) { + return new MsoResponseWrapper2<>(httpResponse.getStatus(), null, raw); + } catch (IOException exception) { + ExceptionUtils.rethrow(exception); + } + } + + return new MsoResponseWrapper2<>(httpResponse.getStatus(), null, null); + } + public static String formatExceptionAdditionalInfo(int statusCode, String msoResponse) { String errorMsg = "Http Code:" + statusCode; if (!StringUtils.isEmpty(msoResponse)) { diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java index 64182e088..df8034b22 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java @@ -330,8 +330,8 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf @Override public MsoResponseWrapperInterface changeManagementUpdate(RequestDetailsWrapper requestDetails, String endpoint) { String path = baseUrl + endpoint; - HttpResponse<RequestReferencesContainer> response = client.post(path, commonHeaders, requestDetails, RequestReferencesContainer.class); - return MsoUtil.wrapResponse(response); + HttpResponse<String> response = client.post(path, commonHeaders, requestDetails, String.class); + return MsoUtil.wrapResponse2(response, RequestReferencesContainer.class); } public MsoResponseWrapper replaceInstance(org.onap.vid.changeManagement.RequestDetails request, String path) { |