diff options
Diffstat (limited to 'vid-app-common/src/main/java/org')
19 files changed, 194 insertions, 64 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java index 1710d984f..7b78f0712 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java @@ -744,7 +744,7 @@ public class AaiClient implements AaiClientInterface { } @Override - public ExternalComponentStatus probeAaiGetAllSubscribers(){ + public ExternalComponentStatus probeComponent(){ long startTime = System.currentTimeMillis(); try { AaiResponseWithRequestInfo<SubscriberList> responseWithRequestInfo = getAllSubscribers(true); diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java index 43be049a6..3f914649d 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java @@ -31,13 +31,12 @@ import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse; import org.onap.vid.aai.model.PortDetailsTranslator; import org.onap.vid.aai.model.Properties; import org.onap.vid.aai.model.ResourceType; +import org.onap.vid.controller.ProbeInterface; import org.onap.vid.model.SubscriberList; -import org.onap.vid.model.probes.ExternalComponentStatus; - /** * Created by Oren on 7/4/17. */ -public interface AaiClientInterface { +public interface AaiClientInterface extends ProbeInterface { boolean isNodeTypeExistsByName(String name, ResourceType type); @@ -87,8 +86,6 @@ public interface AaiClientInterface { AaiResponse getInstanceGroupsByVnfInstanceId(String vnfInstanceId); - ExternalComponentStatus probeAaiGetAllSubscribers(); - Response doAaiGet(String uri, boolean xml); String getCloudOwnerByCloudRegionId(String cloudRegionId); 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..6dc7b6860 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 probeComponent() { + 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..4cc95890d 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 @@ -23,9 +23,10 @@ package org.onap.vid.aai; import io.joshworks.restclient.http.HttpResponse; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.aai.model.ResourceType; +import org.onap.vid.controller.ProbeInterface; import org.onap.vid.model.SubscriberList; -public interface AaiOverTLSClientInterface { +public interface AaiOverTLSClientInterface extends ProbeInterface { class URIS { 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..fc04080d9 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,8 @@ public interface AsdcClient { */ Path getServiceToscaModel(UUID uuid) throws AsdcCatalogException; + + HttpResponse<String> checkSDCConnectivity(); + + String getBaseUrl(); } 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..7cfd094df 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,17 @@ public class LocalAsdcClient implements AsdcClient { } } + @Override + public HttpResponse<String> checkSDCConnectivity() { + return HttpResponse.fallback(""); + } + + + @Override + public String getBaseUrl(){ + return ""; + } + /** * 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..a82110744 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,19 @@ public class SdcRestClient implements AsdcClient { } + @Override + public HttpResponse<String> checkSDCConnectivity() { + String finalUrl = baseUrl + URIS.HEALTH_CHECK_ENDPOINT; + + return syncRestClient + .get(finalUrl, prepareHeaders(auth, APPLICATION_JSON), Collections.emptyMap(), String.class); + } + + @Override + public String getBaseUrl() { + return baseUrl; + } + 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..c181c6f30 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. @@ -21,42 +21,28 @@ package org.onap.vid.controller; import org.onap.portalsdk.core.controller.RestrictedBaseController; -import org.onap.vid.aai.AaiClient; 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; import java.util.List; +import java.util.stream.Collectors; @RestController @RequestMapping("probe") public class ProbeController extends RestrictedBaseController { - private final AaiClient aaiClient; - private final VidService vidService; - private final MsoBusinessLogic msoBusinessLogic; - private final SchedulerService schedulerService; + private final List<ProbeInterface> probes; @Autowired - public ProbeController(AaiClient aaiClient, VidService vidService, MsoBusinessLogic msoBusinessLogic, SchedulerService schedulerService) { - this.aaiClient = aaiClient; - this.vidService = vidService; - this.msoBusinessLogic = msoBusinessLogic; - this.schedulerService = schedulerService; + public ProbeController(List<ProbeInterface> probes) { + this.probes = probes; } - @RequestMapping(method= RequestMethod.GET) + @GetMapping public List<ExternalComponentStatus> getProbe() { - List<ExternalComponentStatus> componentStatuses = new ArrayList<>(); - componentStatuses.add(aaiClient.probeAaiGetAllSubscribers()); - componentStatuses.add(schedulerService.probeGetSchedulerChangeManagements()); - return componentStatuses; + return probes.stream().map(ProbeInterface::probeComponent).collect(Collectors.toList()); } - } diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/ProbeInterface.java b/vid-app-common/src/main/java/org/onap/vid/controller/ProbeInterface.java new file mode 100644 index 000000000..1b3265971 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/ProbeInterface.java @@ -0,0 +1,26 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2019 Nokia Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ +package org.onap.vid.controller; + +import org.onap.vid.model.probes.ExternalComponentStatus; + +public interface ProbeInterface { + ExternalComponentStatus probeComponent(); +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java b/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java index e00c2d7a5..fc656fc14 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java @@ -69,11 +69,6 @@ public class WebConfig { @Bean - public VidService vidService(AsdcClient asdcClient, FeatureManager featureManager) { - return new VidServiceImpl(asdcClient, featureManager); - } - - @Bean public SchedulerService schedulerService(ChangeManagementService changeManagementService) { return new SchedulerServiceImpl(changeManagementService); } 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..1638a376c 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; 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..ed64d2066 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 @@ -24,6 +24,7 @@ package org.onap.vid.mso; import org.onap.vid.changeManagement.RequestDetailsWrapper; import org.onap.vid.changeManagement.WorkflowRequestDetail; import org.onap.vid.controller.OperationalEnvironmentController; +import org.onap.vid.controller.ProbeInterface; import org.onap.vid.model.SOWorkflowList; import org.onap.vid.model.SoftDeleteRequest; import org.onap.vid.mso.model.OperationalEnvironmentActivateInfo; @@ -36,7 +37,7 @@ import org.onap.vid.mso.rest.Task; import java.util.List; import java.util.UUID; -public interface MsoBusinessLogic { +public interface MsoBusinessLogic extends ProbeInterface { // this function should get params from tosca and send them to instance at mso, then return success response. MsoResponseWrapper createSvcInstance(RequestDetails msoRequest); 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..dbeaa90cb 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,7 @@ 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.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.changeManagement.ChangeManagementRequest; @@ -37,6 +38,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 +56,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 +409,7 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { } catch (IOException e) { throw new GenericUncheckedException(e); } - return requestList.getRequestList(); + return ListUtils.emptyIfNull(requestList.getRequestList()); } @@ -858,6 +863,27 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { return msoClientInterface.addRelationshipToServiceInstance(requestDetails, addRelationshipsPath); } + + @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; + + try { + String rawBody = objectMapper.writeValueAsString(getOrchestrationRequestsForDashboard()); + StatusMetadata statusMetadata=new HttpRequestMetadata(HttpMethod.GET,200,url,rawBody,"VID-SO",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; + } + 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/scheduler/SchedulerService.java b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerService.java index 5a38bc08a..643cd22af 100644 --- a/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerService.java +++ b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerService.java @@ -20,8 +20,7 @@ package org.onap.vid.scheduler; -import org.onap.vid.model.probes.ExternalComponentStatus; +import org.onap.vid.controller.ProbeInterface; -public interface SchedulerService { - ExternalComponentStatus probeGetSchedulerChangeManagements(); +public interface SchedulerService extends ProbeInterface { } diff --git a/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerServiceImpl.java index d4f136a01..5513cf4a6 100644 --- a/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerServiceImpl.java @@ -40,7 +40,7 @@ public class SchedulerServiceImpl implements SchedulerService{ } @Override - public ExternalComponentStatus probeGetSchedulerChangeManagements() { + public ExternalComponentStatus probeComponent() { long startTime = System.currentTimeMillis(); try { RestObjectWithRequestInfo response = this.changeManagementService.getSchedulerChangeManagementsWithRequestInfo(); diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java index 83832bfd0..d01f0f7ad 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java @@ -88,17 +88,13 @@ public class AaiServiceImpl implements AaiService { private List<Service> convertModelToService(Model model) { List<Service> services = new ArrayList<>(); - String category = ""; if(validateModel(model)){ - if(model.getModelType() != null) { - category = model.getModelType(); - } - for (ModelVer modelVer: model.getModelVers().getModelVer()) { - Service service = new Service.ServiceBuilder().setUuid(modelVer.getModelVersionId()) + Service service = new Service.ServiceBuilder() + .setUuid(modelVer.getModelVersionId()) .setInvariantUUID(model.getModelInvariantId()) - .setCategory(category) + .setCategory(model.getModelType() != null ? model.getModelType() : "") .setVersion(modelVer.getModelVersion()) .setName( modelVer.getModelName()) .setDistributionStatus(modelVer.getDistributionStatus()) @@ -357,7 +353,7 @@ public class AaiServiceImpl implements AaiService { @Override public AaiResponse<AaiGetVnfResponse> getVNFData(String globalSubscriberId, String serviceType) { - AaiResponse response = aaiClient.getVNFData(globalSubscriberId, serviceType); + AaiResponse<AaiGetVnfResponse> response = aaiClient.getVNFData(globalSubscriberId, serviceType); return filterChangeManagementVNFCandidatesResponse(response); } @@ -375,7 +371,7 @@ public class AaiServiceImpl implements AaiService { return response; } - return new AaiResponse(); + return new AaiResponse<>(); } @Override @@ -474,9 +470,9 @@ public class AaiServiceImpl implements AaiService { public AaiResponse getInstanceGroupsByVnfInstanceId(String vnfInstanceId){ AaiResponse<AaiGetRelatedInstanceGroupsByVnfId> aaiResponse = aaiClient.getInstanceGroupsByVnfInstanceId(vnfInstanceId); if(aaiResponse.getHttpCode() == HttpStatus.SC_OK){ - return new AaiResponse(convertGetInstanceGroupsResponseToSimpleResponse(aaiResponse.getT()), aaiResponse.getErrorMessage(), aaiResponse.getHttpCode()); + return new AaiResponse<>(convertGetInstanceGroupsResponseToSimpleResponse(aaiResponse.getT()), aaiResponse.getErrorMessage(), aaiResponse.getHttpCode()); } - return aaiClient.getInstanceGroupsByVnfInstanceId(vnfInstanceId); + return aaiResponse; } @Override 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..18d8398a3 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. @@ -21,9 +22,10 @@ package org.onap.vid.services; import org.onap.vid.asdc.AsdcCatalogException; +import org.onap.vid.controller.ProbeInterface; import org.onap.vid.model.ServiceModel; -public interface VidService { +public interface VidService extends ProbeInterface { ServiceModel getService(String uuid) throws AsdcCatalogException; 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..9d6f74def 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; @@ -47,6 +52,7 @@ import static org.onap.vid.properties.Features.FLAG_SERVICE_MODEL_CACHE; * The Class VidController. */ +@org.springframework.stereotype.Service public class VidServiceImpl implements VidService { /** * The Constant LOG. @@ -56,7 +62,6 @@ public class VidServiceImpl implements VidService { protected final AsdcClient asdcClient; private final FeatureManager featureManager; - @Autowired private ToscaParserImpl2 toscaParser; private final LoadingCache<String, ServiceModel> serviceModelCache; @@ -67,10 +72,11 @@ public class VidServiceImpl implements VidService { } } - public VidServiceImpl(AsdcClient asdcClient, FeatureManager featureManager) { + @Autowired + public VidServiceImpl(AsdcClient asdcClient, ToscaParserImpl2 toscaParser, FeatureManager featureManager) { this.asdcClient = asdcClient; this.featureManager = featureManager; - + this.toscaParser=toscaParser; this.serviceModelCache = CacheBuilder.newBuilder() .maximumSize(1000) .expireAfterAccess(7, TimeUnit.DAYS) @@ -96,7 +102,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 +142,26 @@ public class VidServiceImpl implements VidService { return tosca.makeServiceModel(uuid, serviceCsar, asdcServiceMetadata); } } - + @Override - public void invalidateServiceCache(){ + public void invalidateServiceCache() { serviceModelCache.invalidateAll(); } + @Override + public ExternalComponentStatus probeComponent() { + long startTime = System.currentTimeMillis(); + ExternalComponentStatus externalComponentStatus; + try { + HttpResponse<String> stringHttpResponse = asdcClient.checkSDCConnectivity(); + HttpRequestMetadata httpRequestMetadata = new HttpRequestMetadata(HttpMethod.GET, stringHttpResponse.getStatus(), asdcClient.getBaseUrl() + AsdcClient.URIS.HEALTH_CHECK_ENDPOINT, stringHttpResponse.getBody(), "SDC healthCheck", + System.currentTimeMillis() - startTime); + 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; + } } |