From 25082565839ea949b938eddb83d0670b3af8e536 Mon Sep 17 00:00:00 2001 From: Eylon Malin Date: Thu, 22 Aug 2019 12:26:41 +0300 Subject: probe mso by retrieving empty list of request status Mso probe component use getRawOrchestrationRequestsByFilter which return HttpResponseWithRequestInfo Issue-ID: VID-378 Signed-off-by: Eylon Malin Change-Id: Icee95af8dbe26296e9fc110170fb758e5133984c Signed-off-by: Eylon Malin --- .../onap/vid/model/probes/HttpRequestMetadata.java | 5 +- .../org/onap/vid/mso/MsoBusinessLogicImpl.java | 56 +++++++++++++++------- .../main/java/org/onap/vid/mso/MsoInterface.java | 3 +- .../org/onap/vid/mso/rest/MsoRestClientNew.java | 6 ++- 4 files changed, 47 insertions(+), 23 deletions(-) (limited to 'vid-app-common/src/main/java') diff --git a/vid-app-common/src/main/java/org/onap/vid/model/probes/HttpRequestMetadata.java b/vid-app-common/src/main/java/org/onap/vid/model/probes/HttpRequestMetadata.java index b284b01d9..984c0d766 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/probes/HttpRequestMetadata.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/probes/HttpRequestMetadata.java @@ -21,6 +21,8 @@ package org.onap.vid.model.probes; +import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; + import com.google.common.base.MoreObjects; import java.nio.charset.StandardCharsets; import org.apache.commons.io.IOUtils; @@ -32,8 +34,6 @@ import org.onap.vid.mso.RestObjectWithRequestInfo; import org.onap.vid.utils.Logging; import org.springframework.http.HttpMethod; -import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; - public class HttpRequestMetadata extends StatusMetadata { private final HttpMethod httpMethod; private final int httpCode; @@ -90,6 +90,7 @@ public class HttpRequestMetadata extends StatusMetadata { this.httpCode = response.getResponse().getStatus(); if (readRawData) { try { + response.getResponse().getRawBody().reset(); this.rawData = IOUtils.toString(response.getResponse().getRawBody(), StandardCharsets.UTF_8.name()); } catch (Exception e) { //Nothing to do here diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java index 9146e8f1b..4d0d4ee74 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java @@ -60,6 +60,8 @@ import javax.ws.rs.BadRequestException; import org.apache.commons.collections4.ListUtils; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.vid.aai.ExceptionWithRequestInfo; +import org.onap.vid.aai.HttpResponseWithRequestInfo; import org.onap.vid.changeManagement.ChangeManagementRequest; import org.onap.vid.changeManagement.RequestDetailsWrapper; import org.onap.vid.changeManagement.WorkflowRequestDetail; @@ -67,6 +69,7 @@ import org.onap.vid.controller.OperationalEnvironmentController; import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.model.SOWorkflowList; import org.onap.vid.model.SoftDeleteRequest; +import org.onap.vid.model.probes.ErrorMetadata; import org.onap.vid.model.probes.ExternalComponentStatus; import org.onap.vid.model.probes.HttpRequestMetadata; import org.onap.vid.model.probes.StatusMetadata; @@ -84,8 +87,8 @@ import org.onap.vid.mso.rest.RequestList; import org.onap.vid.mso.rest.RequestWrapper; import org.onap.vid.mso.rest.Task; import org.onap.vid.mso.rest.TaskList; +import org.onap.vid.utils.Logging; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; public class MsoBusinessLogicImpl implements MsoBusinessLogic { @@ -383,12 +386,13 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { } private List getOrchestrationRequestsByFilter(String filterName, String filterValue) { + HttpResponseWithRequestInfo msoResponseWrapper = getRawOrchestrationRequestsByFilter(filterName, filterValue); + return deserializeOrchestrationRequestsJson(msoResponseWrapper.getResponse().getBody()); + } + + private HttpResponseWithRequestInfo getRawOrchestrationRequestsByFilter(String filterName, String filterValue) { String orchestrationReqPath = constructOrchestrationRequestFilter(filterName, filterValue); - RestObject restObjStr = new RestObject<>(); - String str = new String(); - restObjStr.set(str); - MsoResponseWrapper msoResponseWrapper = msoClientInterface.getOrchestrationRequest(str, "", orchestrationReqPath, restObjStr, true); - return deserializeOrchestrationRequestsJson(msoResponseWrapper.getEntity()); + return msoClientInterface.getOrchestrationRequest(orchestrationReqPath, true); } private List deserializeOrchestrationRequestsJson(String orchestrationRequestsJson) { @@ -837,22 +841,38 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { @Override public ExternalComponentStatus probeComponent() { - String url = SystemProperties.getProperty( - MsoProperties.MSO_SERVER_URL) + "/" + SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS); - long startTime = System.currentTimeMillis(); - ExternalComponentStatus externalComponentStatus; - + final long startTime = System.currentTimeMillis(); + HttpResponseWithRequestInfo responseWithRequestInfo = null; try { - String rawBody = objectMapper.writeValueAsString(getOrchestrationRequestsForDashboard()); - StatusMetadata statusMetadata=new HttpRequestMetadata(HttpMethod.GET,200,url,rawBody,"VID-SO",System.currentTimeMillis() - startTime); + responseWithRequestInfo = getRawOrchestrationRequestsByFilter("requestExecutionDate", "01-01-2100" ); + int httpCode = responseWithRequestInfo.getResponse().getStatus(); + boolean isAvailable = httpCode == 200 || httpCode == 202; + if (isAvailable) { + //make sure response can be parsed to RequestList.class + JACKSON_OBJECT_MAPPER.readValue(responseWithRequestInfo.getResponse().getBody(), RequestList.class); + } + + HttpRequestMetadata metadata = new HttpRequestMetadata(responseWithRequestInfo, + isAvailable ? "OK" : "MSO returned no orchestration requests", + System.currentTimeMillis() - startTime, true); + return new ExternalComponentStatus(ExternalComponentStatus.Component.MSO, isAvailable, metadata); - externalComponentStatus = new ExternalComponentStatus(ExternalComponentStatus.Component.MSO, true, statusMetadata); + } catch (ExceptionWithRequestInfo e) { + long duration = System.currentTimeMillis() - startTime; + return new ExternalComponentStatus(ExternalComponentStatus.Component.MSO, false, + new HttpRequestMetadata(e, duration)); } catch (Exception e) { - StatusMetadata statusMetadata = new HttpRequestMetadata(HttpMethod.GET, HttpStatus.INTERNAL_SERVER_ERROR.value(), url, "", e.getMessage(), System.currentTimeMillis() - startTime); - externalComponentStatus = new ExternalComponentStatus(ExternalComponentStatus.Component.MSO, false, statusMetadata); - } + StatusMetadata metadata; + long duration = System.currentTimeMillis() - startTime; - return externalComponentStatus; + if (responseWithRequestInfo == null) { + metadata = new ErrorMetadata(Logging.exceptionToDescription(e), duration); + } else { + metadata = new HttpRequestMetadata(responseWithRequestInfo, Logging.exceptionToDescription(e), duration, true); + } + + return new ExternalComponentStatus(ExternalComponentStatus.Component.MSO, false, metadata); + } } private void validateUpdateVnfConfig(RequestDetails requestDetails) { diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoInterface.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoInterface.java index 46bd2731d..d1cb3a37b 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoInterface.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoInterface.java @@ -21,6 +21,7 @@ package org.onap.vid.mso; import io.joshworks.restclient.http.HttpResponse; +import org.onap.vid.aai.HttpResponseWithRequestInfo; import org.onap.vid.changeManagement.RequestDetailsWrapper; import org.onap.vid.model.SOWorkflowList; import org.onap.vid.changeManagement.WorkflowRequestDetail; @@ -89,7 +90,7 @@ public interface MsoInterface { MsoResponseWrapper deleteNwInstance(RequestDetails requestDetails, String endpoint); - MsoResponseWrapper getOrchestrationRequest(String t, String sourceId, String endpoint, RestObject restObject, boolean warpException); + HttpResponseWithRequestInfo getOrchestrationRequest(String endpoint, boolean warpException); MsoResponseWrapper getOrchestrationRequest(String endpoint); 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 df8034b22..cc6d6123d 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 @@ -35,6 +35,7 @@ import org.apache.commons.codec.binary.Base64; import org.eclipse.jetty.util.security.Password; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.vid.aai.HttpResponseWithRequestInfo; import org.onap.vid.aai.util.HttpsAuthClient; import org.onap.vid.changeManagement.MsoRequestDetails; import org.onap.vid.changeManagement.RequestDetailsWrapper; @@ -51,6 +52,7 @@ import org.onap.vid.mso.RestMsoImplementation; import org.onap.vid.mso.RestObject; import org.onap.vid.utils.Logging; import org.onap.vid.utils.SystemPropertiesWrapper; +import org.springframework.http.HttpMethod; /** @@ -216,11 +218,11 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf } @Override - public MsoResponseWrapper getOrchestrationRequest(String t, String sourceId, String endpoint, RestObject restObject, boolean warpException) { + public HttpResponseWithRequestInfo getOrchestrationRequest(String endpoint, boolean warpException) { String path = baseUrl + endpoint; HttpResponse response = client.get(path, commonHeaders, new HashMap<>(), String.class); - return MsoUtil.wrapResponse(response); + return new HttpResponseWithRequestInfo<>(response, path, HttpMethod.GET); } @Override -- cgit 1.2.3-korg