diff options
author | Wojciech Sliwka <wojciech.sliwka@nokia.com> | 2019-06-19 11:06:54 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-06-19 11:06:54 +0000 |
commit | 7f0e6936709cc19e3e1e1ad035e5b7d00809d6c6 (patch) | |
tree | 163542e67746e7693daf12e7835f5b2f6c78255a /vid-app-common | |
parent | 46adb535d3af416773475b9aabb2ace8e1e9e1de (diff) | |
parent | 72b3fb69e548cf665204ec025d2778dcf3ce0216 (diff) |
Merge "Extend probe mechanism"
Diffstat (limited to 'vid-app-common')
16 files changed, 312 insertions, 32 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java index 86c6f4aca..46bb6cef4 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java @@ -23,6 +23,7 @@ package org.onap.vid.aai; import io.joshworks.restclient.http.HttpResponse; import io.joshworks.restclient.http.JsonNode; import io.vavr.collection.HashMap; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.aai.model.ResourceType; @@ -30,6 +31,10 @@ import org.onap.vid.aai.util.AAIProperties; import org.onap.vid.client.SyncRestClientInterface; import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.model.SubscriberList; +import org.onap.vid.model.probes.ExternalComponentStatus; +import org.onap.vid.model.probes.HttpRequestMetadata; +import org.onap.vid.utils.Logging; +import org.springframework.http.HttpMethod; import javax.ws.rs.core.MediaType; import java.nio.charset.StandardCharsets; @@ -37,7 +42,11 @@ import java.util.Base64; import java.util.Collections; import java.util.Map; -import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.*; +import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.ACCEPT; +import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.CONTENT_TYPE; +import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.FROM_APP_ID_HEADER; +import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.REQUEST_ID; +import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.TRANSACTION_ID_HEADER; public class AaiOverTLSClient implements AaiOverTLSClientInterface { @@ -88,6 +97,29 @@ public class AaiOverTLSClient implements AaiOverTLSClientInterface { return syncRestClient.get(uri, getRequestHeaders(), Collections.emptyMap(), SubscriberList.class); } + @Override + public ExternalComponentStatus probeGetAllSubscribers() { + String url = urlBase + String.format(URIS.SUBSCRIBERS, 0); + long startTime = System.currentTimeMillis(); + ExternalComponentStatus externalComponentStatus; + + try { + HttpResponse<SubscriberList> allSubscribers = getAllSubscribers(); + + HttpRequestMetadata httpRequestMetadata = new HttpRequestMetadata(HttpMethod.GET, allSubscribers.getStatus(), url, + IOUtils.toString(allSubscribers.getRawBody()), "VID-AAI connection using new client works", System.currentTimeMillis() - startTime); + externalComponentStatus = new ExternalComponentStatus(ExternalComponentStatus.Component.AAI, allSubscribers.isSuccessful(), httpRequestMetadata); + + } catch (Exception e) { + HttpRequestMetadata httpRequestMetadata = new HttpRequestMetadata(HttpMethod.GET, 0, + url, "", Logging.exceptionToDescription(e), System.currentTimeMillis() - startTime); + externalComponentStatus = new ExternalComponentStatus(ExternalComponentStatus.Component.AAI, false, httpRequestMetadata); + } + + return externalComponentStatus; + } + + private Map<String, String> getRequestHeaders() { Map<String, String> result = HashMap.of( TRANSACTION_ID_HEADER, propertySupplier.getRandomUUID(), diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java index 02f01e79e..c430b098e 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java @@ -24,6 +24,7 @@ import io.joshworks.restclient.http.HttpResponse; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.aai.model.ResourceType; import org.onap.vid.model.SubscriberList; +import org.onap.vid.model.probes.ExternalComponentStatus; public interface AaiOverTLSClientInterface { @@ -47,4 +48,7 @@ public interface AaiOverTLSClientInterface { HttpResponse<SubscriberList> getAllSubscribers(); + + ExternalComponentStatus probeGetAllSubscribers(); + } diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/AsdcClient.java b/vid-app-common/src/main/java/org/onap/vid/asdc/AsdcClient.java index 37d3d2e97..e264e4e3e 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/AsdcClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/AsdcClient.java @@ -3,6 +3,7 @@ * VID * ================================================================================ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nokia. 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. @@ -20,6 +21,7 @@ package org.onap.vid.asdc; +import io.joshworks.restclient.http.HttpResponse; import org.onap.vid.asdc.beans.Service; import java.nio.file.Path; @@ -32,6 +34,7 @@ public interface AsdcClient { class URIS{ public static final String METADATA_URL_TEMPLATE = "%s%s/%s/metadata"; public static final String TOSCA_MODEL_URL_TEMPLATE = "%s%s/%s/toscaModel"; + public static final String HEALTH_CHECK_ENDPOINT = "sdc2/rest/healthCheck"; } /** * Gets the service. @@ -51,4 +54,6 @@ public interface AsdcClient { */ Path getServiceToscaModel(UUID uuid) throws AsdcCatalogException; + + HttpResponse<String> checkSDCConnectivity(); } diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/local/LocalAsdcClient.java b/vid-app-common/src/main/java/org/onap/vid/asdc/local/LocalAsdcClient.java index 4e5574afd..0bd581abc 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/local/LocalAsdcClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/local/LocalAsdcClient.java @@ -3,6 +3,7 @@ * VID * ================================================================================ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nokia. 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. @@ -23,6 +24,7 @@ package org.onap.vid.asdc.local; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import io.joshworks.restclient.http.HttpResponse; import org.json.JSONArray; import org.json.JSONObject; import org.onap.vid.asdc.AsdcCatalogException; @@ -156,6 +158,11 @@ public class LocalAsdcClient implements AsdcClient { } } + @Override + public HttpResponse<String> checkSDCConnectivity() { + return HttpResponse.fallback(""); + } + /** * The Class Builder. */ diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/rest/SdcRestClient.java b/vid-app-common/src/main/java/org/onap/vid/asdc/rest/SdcRestClient.java index ab07aaeed..428083e7b 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/rest/SdcRestClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/rest/SdcRestClient.java @@ -22,6 +22,7 @@ package org.onap.vid.asdc.rest; import com.att.eelf.configuration.EELFLogger; import com.google.common.collect.ImmutableMap; +import io.joshworks.restclient.http.HttpResponse; import io.vavr.control.Try; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.asdc.AsdcCatalogException; @@ -97,6 +98,13 @@ public class SdcRestClient implements AsdcClient { } + public HttpResponse<String> checkSDCConnectivity() { + String finalUrl = baseUrl + URIS.HEALTH_CHECK_ENDPOINT; + + return syncRestClient + .get(finalUrl, prepareHeaders(auth, APPLICATION_JSON), Collections.emptyMap(), String.class); + } + private Map<String, String> prepareHeaders(String auth, String contentType) { return ImmutableMap.of( X_ECOMP_INSTANCE_ID, SystemProperties.getProperty(APP_DISPLAY_NAME), diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/ProbeController.java b/vid-app-common/src/main/java/org/onap/vid/controller/ProbeController.java index 7695e2435..0206af420 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/ProbeController.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/ProbeController.java @@ -7,9 +7,9 @@ * 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. @@ -22,13 +22,14 @@ package org.onap.vid.controller; import org.onap.portalsdk.core.controller.RestrictedBaseController; import org.onap.vid.aai.AaiClient; +import org.onap.vid.aai.AaiOverTLSClientInterface; import org.onap.vid.model.probes.ExternalComponentStatus; import org.onap.vid.mso.MsoBusinessLogic; import org.onap.vid.scheduler.SchedulerService; import org.onap.vid.services.VidService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; @@ -39,23 +40,29 @@ import java.util.List; public class ProbeController extends RestrictedBaseController { private final AaiClient aaiClient; + private final AaiOverTLSClientInterface newAaiClient; private final VidService vidService; private final MsoBusinessLogic msoBusinessLogic; private final SchedulerService schedulerService; + @Autowired - public ProbeController(AaiClient aaiClient, VidService vidService, MsoBusinessLogic msoBusinessLogic, SchedulerService schedulerService) { + public ProbeController(AaiClient aaiClient, VidService vidService, MsoBusinessLogic msoBusinessLogic, SchedulerService schedulerService, AaiOverTLSClientInterface newAaiClient) { this.aaiClient = aaiClient; this.vidService = vidService; this.msoBusinessLogic = msoBusinessLogic; this.schedulerService = schedulerService; + this.newAaiClient = newAaiClient; } - @RequestMapping(method= RequestMethod.GET) + @GetMapping public List<ExternalComponentStatus> getProbe() { List<ExternalComponentStatus> componentStatuses = new ArrayList<>(); componentStatuses.add(aaiClient.probeAaiGetAllSubscribers()); + componentStatuses.add(newAaiClient.probeGetAllSubscribers()); componentStatuses.add(schedulerService.probeGetSchedulerChangeManagements()); + componentStatuses.add(msoBusinessLogic.probeGetOrchestrationRequests()); + componentStatuses.add(vidService.probeSDCConnection()); return componentStatuses; } 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 bf2c3ec67..58d9e242f 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 @@ -3,6 +3,7 @@ * VID * ================================================================================ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nokia. 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. @@ -21,6 +22,7 @@ package org.onap.vid.model.probes; import com.google.common.base.MoreObjects; +import io.joshworks.restclient.http.HttpResponse; import org.apache.commons.lang3.StringUtils; import org.onap.vid.aai.ExceptionWithRequestInfo; import org.onap.vid.aai.ResponseWithRequestInfo; @@ -79,6 +81,10 @@ public class HttpRequestMetadata extends StatusMetadata { duration); } + public HttpRequestMetadata(HttpResponse<String> response, HttpMethod method, String description, long duration, String url) { + this(method, response.getStatus(), url, response.getBody(), description, duration); + } + public HttpMethod getHttpMethod() { diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogic.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogic.java index 3b2cdb1bf..23c891fbf 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogic.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogic.java @@ -26,6 +26,7 @@ import org.onap.vid.changeManagement.WorkflowRequestDetail; import org.onap.vid.controller.OperationalEnvironmentController; import org.onap.vid.model.SOWorkflowList; import org.onap.vid.model.SoftDeleteRequest; +import org.onap.vid.model.probes.ExternalComponentStatus; import org.onap.vid.mso.model.OperationalEnvironmentActivateInfo; import org.onap.vid.mso.model.OperationalEnvironmentDeactivateInfo; import org.onap.vid.mso.rest.OperationalEnvironment.OperationEnvironmentRequestDetails; @@ -141,4 +142,6 @@ public interface MsoBusinessLogic { MsoResponseWrapper2 activateFabricConfiguration(String serviceInstanceId, RequestDetails requestDetails); SOWorkflowList getWorkflowListByModelId(String modelVersionId); + + ExternalComponentStatus probeGetOrchestrationRequests(); } 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 64c405a39..c2ac51a40 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 @@ -27,6 +27,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import io.joshworks.restclient.http.HttpResponse; +import org.apache.commons.collections4.ListUtils; +import org.jetbrains.annotations.NotNull; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.changeManagement.ChangeManagementRequest; @@ -37,6 +39,9 @@ import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.model.RequestReferencesContainer; import org.onap.vid.model.SOWorkflowList; import org.onap.vid.model.SoftDeleteRequest; +import org.onap.vid.model.probes.ExternalComponentStatus; +import org.onap.vid.model.probes.HttpRequestMetadata; +import org.onap.vid.model.probes.StatusMetadata; import org.onap.vid.mso.model.CloudConfiguration; import org.onap.vid.mso.model.ModelInfo; import org.onap.vid.mso.model.OperationalEnvironmentActivateInfo; @@ -52,6 +57,7 @@ import org.onap.vid.mso.rest.RequestWrapper; import org.onap.vid.mso.rest.Task; import org.onap.vid.mso.rest.TaskList; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.togglz.core.manager.FeatureManager; @@ -404,7 +410,7 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { } catch (IOException e) { throw new GenericUncheckedException(e); } - return requestList.getRequestList(); + return ListUtils.emptyIfNull(requestList.getRequestList()); } @@ -858,6 +864,38 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { return msoClientInterface.addRelationshipToServiceInstance(requestDetails, addRelationshipsPath); } + + @Override + public ExternalComponentStatus probeGetOrchestrationRequests() { + String url = SystemProperties.getProperty( + MsoProperties.MSO_SERVER_URL) + "/" + SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS); + long startTime = System.currentTimeMillis(); + ExternalComponentStatus externalComponentStatus; + + try { + RestObject<List<Request>> restObject = createRequestsList(getOrchestrationRequestsForDashboard()); + + StatusMetadata statusMetadata = new HttpRequestMetadata(new RestObjectWithRequestInfo(HttpMethod.GET, url, restObject), + "VID-SO communication works", System.currentTimeMillis() - startTime); + + externalComponentStatus = new ExternalComponentStatus(ExternalComponentStatus.Component.MSO, true, statusMetadata); + } 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); + } + + return externalComponentStatus; + } + + @NotNull + private RestObject<List<Request>> createRequestsList(List<Request> orchestrationRequestsForDashboard) { + RestObject<List<Request>> restObject = new RestObject<>(); + restObject.set(orchestrationRequestsForDashboard); + restObject.setStatusCode(200); + return restObject; + } + + private void validateUpdateVnfConfig(RequestDetails requestDetails) { final String noValidPayloadMsg = "No valid payload in " + ChangeManagementRequest.CONFIG_UPDATE + " request"; diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/RestObjectWithRequestInfo.java b/vid-app-common/src/main/java/org/onap/vid/mso/RestObjectWithRequestInfo.java index 84f204c6e..ed41bf264 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/RestObjectWithRequestInfo.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/RestObjectWithRequestInfo.java @@ -3,13 +3,14 @@ * VID * ================================================================================ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nokia. 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. @@ -22,6 +23,8 @@ package org.onap.vid.mso; import org.springframework.http.HttpMethod; +import java.util.Objects; + public class RestObjectWithRequestInfo<T> { private final RestObject<T> restObject; @@ -38,6 +41,14 @@ public class RestObjectWithRequestInfo<T> { this.httpMethod = httpMethod; } + public RestObjectWithRequestInfo(HttpMethod httpMethod, String requestedUrl, RestObject<T> restObject) { + this.httpMethod = httpMethod; + this.requestedUrl = requestedUrl; + this.restObject = restObject; + this.httpCode = restObject.getStatusCode(); + this.rawData = restObject.getRaw(); + } + public RestObject<T> getRestObject() { return restObject; } diff --git a/vid-app-common/src/main/java/org/onap/vid/services/VidService.java b/vid-app-common/src/main/java/org/onap/vid/services/VidService.java index 75343080b..1143a8ec3 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/VidService.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/VidService.java @@ -3,6 +3,7 @@ * VID * ================================================================================ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nokia. 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. @@ -22,10 +23,13 @@ package org.onap.vid.services; import org.onap.vid.asdc.AsdcCatalogException; import org.onap.vid.model.ServiceModel; +import org.onap.vid.model.probes.ExternalComponentStatus; public interface VidService { ServiceModel getService(String uuid) throws AsdcCatalogException; void invalidateServiceCache(); + + ExternalComponentStatus probeSDCConnection(); } diff --git a/vid-app-common/src/main/java/org/onap/vid/services/VidServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/VidServiceImpl.java index d14c13ec1..5ff227f3c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/VidServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/VidServiceImpl.java @@ -8,9 +8,9 @@ * 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. @@ -23,6 +23,7 @@ package org.onap.vid.services; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; +import io.joshworks.restclient.http.HttpResponse; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.onap.vid.asdc.AsdcCatalogException; @@ -33,7 +34,11 @@ import org.onap.vid.asdc.parser.ToscaParserImpl; import org.onap.vid.asdc.parser.ToscaParserImpl2; import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.model.ServiceModel; +import org.onap.vid.model.probes.ExternalComponentStatus; +import org.onap.vid.model.probes.HttpRequestMetadata; +import org.onap.vid.utils.Logging; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpMethod; import org.togglz.core.manager.FeatureManager; import java.nio.file.Path; @@ -96,7 +101,7 @@ public class VidServiceImpl implements VidService { public ServiceModel getService(String uuid) throws AsdcCatalogException { if (featureManager.isActive(FLAG_SERVICE_MODEL_CACHE)) { return getServiceFromCache(uuid); - }else { + } else { return getServiceFromSdc(uuid); } } @@ -136,10 +141,26 @@ public class VidServiceImpl implements VidService { return tosca.makeServiceModel(uuid, serviceCsar, asdcServiceMetadata); } } - + @Override - public void invalidateServiceCache(){ + public void invalidateServiceCache() { serviceModelCache.invalidateAll(); } + @Override + public ExternalComponentStatus probeSDCConnection() { + long startTime = System.currentTimeMillis(); + ExternalComponentStatus externalComponentStatus; + try { + HttpResponse<String> stringHttpResponse = asdcClient.checkSDCConnectivity(); + HttpRequestMetadata httpRequestMetadata = new HttpRequestMetadata(stringHttpResponse, HttpMethod.GET, "SDC healthCheck", + System.currentTimeMillis() - startTime, AsdcClient.URIS.HEALTH_CHECK_ENDPOINT); + externalComponentStatus = new ExternalComponentStatus(ExternalComponentStatus.Component.SDC, stringHttpResponse.isSuccessful(), httpRequestMetadata); + } catch (Exception e) { + HttpRequestMetadata httpRequestMetadata = new HttpRequestMetadata(HttpMethod.GET, 0, + AsdcClient.URIS.HEALTH_CHECK_ENDPOINT, "", Logging.exceptionToDescription(e), System.currentTimeMillis() - startTime); + externalComponentStatus = new ExternalComponentStatus(ExternalComponentStatus.Component.SDC, false, httpRequestMetadata); + } + return externalComponentStatus; + } } diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java index 43fb5a3bb..da937cade 100644 --- a/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java @@ -21,21 +21,32 @@ package org.onap.vid.aai; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; +import com.google.gson.Gson; +import io.joshworks.restclient.http.HttpResponse; +import org.apache.commons.io.IOUtils; import org.mockito.Answers; import org.mockito.Mock; -import org.mockito.Mockito; import org.onap.vid.aai.model.ResourceType; import org.onap.vid.client.SyncRestClient; +import org.onap.vid.model.Subscriber; import org.onap.vid.model.SubscriberList; +import org.onap.vid.model.probes.ExternalComponentStatus; +import org.springframework.http.HttpStatus; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import java.io.InputStream; import java.util.Collections; +import java.util.List; import java.util.Map; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.contains; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; public class AaiOverTLSClientTest { @@ -49,6 +60,9 @@ public class AaiOverTLSClientTest { @Mock private AaiOverTLSPropertySupplier propertySupplier; + @Mock + private HttpResponse<SubscriberList> response; + @BeforeMethod public void setUp() { initMocks(this); @@ -60,7 +74,7 @@ public class AaiOverTLSClientTest { mockPropertyReader(); aaiRestClient.isNodeTypeExistsByName("name", ResourceType.GENERIC_VNF); - Mockito.verify(syncRestClient).get(contains(SEARCH_NODES_QUERY_SEARCH_NODE_TYPE), + verify(syncRestClient).get(contains(SEARCH_NODES_QUERY_SEARCH_NODE_TYPE), eq(getHeaders()), eq(Collections.emptyMap())); } @@ -69,15 +83,49 @@ public class AaiOverTLSClientTest { mockPropertyReader(); aaiRestClient.getAllSubscribers(); - Mockito.verify(syncRestClient).get(contains(SUBSCRIBERS), + verify(syncRestClient).get(contains(SUBSCRIBERS), eq(getHeaders()), eq(Collections.emptyMap()), eq(SubscriberList.class)); } + + @Test + public void probeMechanismShouldReturnAllSubscribers() { + mockPropertyReader(); + List<Subscriber> subscribers = Lists.newArrayList(new Subscriber()); + + SubscriberList subscriberList = new SubscriberList(subscribers); + InputStream json = IOUtils.toInputStream(new Gson().toJson(subscriberList)); + when(syncRestClient.get(contains(SUBSCRIBERS), eq(getHeaders()), eq(Collections.emptyMap()), + eq(SubscriberList.class))).thenReturn(response); + when(response.getStatus()).thenReturn(HttpStatus.OK.value()); + when(response.getRawBody()).thenReturn(json); + when(response.isSuccessful()).thenReturn(true); + + + ExternalComponentStatus externalComponentStatus = aaiRestClient.probeGetAllSubscribers(); + + assertThat(externalComponentStatus.isAvailable()).isTrue(); + assertThat(externalComponentStatus.getComponent()).isEqualTo(ExternalComponentStatus.Component.AAI); + } + + @Test + public void probeMechanismShouldHandleExceptionProperly(){ + mockPropertyReader(); + when(syncRestClient.get(contains(SUBSCRIBERS), eq(getHeaders()), eq(Collections.emptyMap()), + eq(SubscriberList.class))).thenThrow(new RuntimeException("call failed")); + + ExternalComponentStatus externalComponentStatus = aaiRestClient.probeGetAllSubscribers(); + + assertThat(externalComponentStatus.isAvailable()).isFalse(); + assertThat(externalComponentStatus.getComponent()).isEqualTo(ExternalComponentStatus.Component.AAI); + assertThat(externalComponentStatus.getMetadata().getDescription()).containsSequence("call failed"); + } + private void mockPropertyReader() { - Mockito.when(propertySupplier.getPassword()).thenReturn("Pass"); - Mockito.when(propertySupplier.getUsername()).thenReturn("User"); - Mockito.when(propertySupplier.getRequestId()).thenReturn("1"); - Mockito.when(propertySupplier.getRandomUUID()).thenReturn("2"); + when(propertySupplier.getPassword()).thenReturn("Pass"); + when(propertySupplier.getUsername()).thenReturn("User"); + when(propertySupplier.getRequestId()).thenReturn("1"); + when(propertySupplier.getRandomUUID()).thenReturn("2"); } private Map<String,String> getHeaders(){ @@ -85,5 +133,4 @@ public class AaiOverTLSClientTest { put("X-FromAppId", "VidAaiController").put("Accept", "application/json").put("X-ECOMP-RequestID", "1"). put("X-TransactionId", "2").put("Content-Type", "application/json").build(); } - } diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientTest.java b/vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientTest.java index 5202661da..a20571785 100644 --- a/vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientTest.java @@ -27,17 +27,23 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.vid.asdc.AsdcCatalogException; +import org.onap.vid.asdc.AsdcClient; import org.onap.vid.asdc.beans.Service; import org.onap.vid.client.SyncRestClient; import java.io.InputStream; import java.nio.file.Path; +import java.util.Collections; import java.util.UUID; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; -import static org.mockito.ArgumentMatchers.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.contains; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.matches; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @@ -60,6 +66,9 @@ public class SdcRestClientTest { private HttpResponse<InputStream> httpStreamResponse; @Mock + private HttpResponse<String> httpStringResponse; + + @Mock private InputStream inputStream; private UUID randomId; @@ -123,6 +132,16 @@ public class SdcRestClientTest { restClient.getServiceToscaModel(randomId); } + @Test + public void shouldCallSDCHealthCheck() { + when(mockedSyncRestClient.get(contains(AsdcClient.URIS.HEALTH_CHECK_ENDPOINT), anyMap(), + eq(Collections.emptyMap()), eq(String.class))).thenReturn(httpStringResponse); + + + HttpResponse<String> stringHttpResponse = restClient.checkSDCConnectivity(); + + assertThat(httpStringResponse, is(stringHttpResponse)); + } private Service createTestService() { Service service = new Service(); diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java index f54756e76..8681ecbce 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java @@ -23,12 +23,17 @@ package org.onap.vid.mso; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Lists; +import com.google.gson.Gson; import io.joshworks.restclient.http.HttpResponse; import org.apache.commons.io.IOUtils; import org.jetbrains.annotations.NotNull; import org.mockito.hamcrest.MockitoHamcrest; import org.onap.vid.changeManagement.WorkflowRequestDetail; import org.onap.vid.model.SOWorkflowList; +import org.onap.vid.model.probes.ExternalComponentStatus; +import org.onap.vid.mso.rest.RequestList; +import org.onap.vid.mso.rest.RequestWrapper; import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -84,8 +89,10 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.ArgumentMatchers.endsWith; import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import static org.onap.vid.controller.MsoController.CONFIGURATION_ID; import static org.onap.vid.controller.MsoController.REQUEST_TYPE; import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID; @@ -1384,6 +1391,31 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests { msoBusinessLogic.getWorkflowListByModelId("sampleModelId"); } + + @Test + public void probeShouldReturnOrchestrationRequestsAndConnectionStatus(){ + MsoResponseWrapper wrapper = getMsoResponseWrapper(); + given(msoInterface.getOrchestrationRequest(anyString(),anyString(), + anyString(),any(RestObject.class),anyBoolean())).willReturn(wrapper); + + ExternalComponentStatus externalComponentStatus = msoBusinessLogic.probeGetOrchestrationRequests(); + + assertThat(externalComponentStatus.isAvailable()).isTrue(); + assertThat(externalComponentStatus.getComponent()).isEqualTo(ExternalComponentStatus.Component.MSO); + } + + @NotNull + private MsoResponseWrapper getMsoResponseWrapper() { + MsoResponseWrapper wrapper=new MsoResponseWrapper(); + RequestWrapper requestWrapper = new RequestWrapper(); + requestWrapper.setRequest(new Request()); + RequestList requestList = new RequestList(); + List<RequestWrapper> response = Lists.newArrayList(requestWrapper); + requestList.setRequestList(response); + wrapper.setEntity(new Gson().toJson(requestList)); + return wrapper; + } + private WorkflowRequestDetail createWorkflowRequestDetail() { WorkflowRequestDetail workflowRequestDetail = new WorkflowRequestDetail(); org.onap.vid.changeManagement.RequestParameters requestParameters = new org.onap.vid.changeManagement.RequestParameters(); diff --git a/vid-app-common/src/test/java/org/onap/vid/services/VidServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/VidServiceImplTest.java index 5dd2bcd19..3cd3aa8a6 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/VidServiceImplTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/VidServiceImplTest.java @@ -7,9 +7,9 @@ * 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. @@ -21,6 +21,7 @@ package org.onap.vid.services; import com.google.common.collect.ImmutableMap; +import io.joshworks.restclient.http.HttpResponse; import org.apache.commons.lang3.reflect.FieldUtils; import org.mockito.Answers; import org.mockito.Mock; @@ -31,6 +32,8 @@ import org.onap.vid.asdc.AsdcClient; import org.onap.vid.asdc.beans.Service; import org.onap.vid.asdc.parser.ToscaParserImpl2; import org.onap.vid.model.ServiceModel; +import org.onap.vid.model.probes.ExternalComponentStatus; +import org.onap.vid.model.probes.HttpRequestMetadata; import org.onap.vid.properties.Features; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -40,22 +43,31 @@ import java.util.Map; import java.util.UUID; import static java.util.stream.Collectors.toMap; -import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.core.IsSame.sameInstance; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class VidServiceImplTest { @Mock(answer = Answers.RETURNS_MOCKS) - AsdcClient asdcClientMock; + private AsdcClient asdcClientMock; @Mock(answer = Answers.RETURNS_MOCKS) - ToscaParserImpl2 toscaParserMock; + private ToscaParserImpl2 toscaParserMock; @Mock - FeatureManager featureManager; + private FeatureManager featureManager; + + @Mock + private HttpResponse<String> httpResponse; private final UUID uuid1 = UUID.randomUUID(); private final UUID uuid2 = UUID.randomUUID(); @@ -86,8 +98,8 @@ public class VidServiceImplTest { when(featureManager.isActive(Features.FLAG_SERVICE_MODEL_CACHE)).thenReturn(true); - when(asdcClientMock.getService(any())).thenAnswer(invocation -> pseudoServiceByUuid.get(invocation.getArguments()[0])); - when(toscaParserMock.makeServiceModel(any(), any())).thenAnswer(invocation -> pseudoModelByService.get(invocation.getArguments()[1])); + when(asdcClientMock.getService(any())).thenAnswer(invocation -> pseudoServiceByUuid.get(invocation.getArguments()[0])); + when(toscaParserMock.makeServiceModel(any(), any())).thenAnswer(invocation -> pseudoModelByService.get(invocation.getArguments()[1])); } @Test @@ -138,5 +150,29 @@ public class VidServiceImplTest { vidService.getService(uuid1.toString()); } + @Test + public void shouldCheckConnectionToSdc() { + when(asdcClientMock.checkSDCConnectivity()).thenReturn(httpResponse); + when(httpResponse.isSuccessful()).thenReturn(true); + when(httpResponse.getBody()).thenReturn("sampleBody"); + + + ExternalComponentStatus externalComponentStatus = vidService.probeSDCConnection(); + + assertThat(externalComponentStatus.isAvailable(), is(true)); + assertThat(externalComponentStatus.getComponent(), is(ExternalComponentStatus.Component.SDC)); + HttpRequestMetadata metadata = (HttpRequestMetadata) externalComponentStatus.getMetadata(); + assertThat(metadata.getRawData(), is("sampleBody")); + } + + @Test + public void shouldProperlyHandleNotWorkingSDCConnection(){ + when(asdcClientMock.checkSDCConnectivity()).thenThrow(new RuntimeException("not working")); + + ExternalComponentStatus externalComponentStatus = vidService.probeSDCConnection(); + + assertThat(externalComponentStatus.isAvailable(), is(false)); + assertThat(externalComponentStatus.getMetadata().getDescription(),containsString("not working")); + } } |