From 6ad41e3ccd398a2721f41ad61c80b7bb03f7d127 Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Mon, 31 Dec 2018 17:21:27 +0200 Subject: Merge from ECOMP's repository Main Features -------------- - Async-Instantiation jobs mechanism major update; still WIP (package `org.onap.vid.job`) - New features in View/Edit: Activate fabric configuration; show related networks; soft delete - Support AAI service-tree traversal (`AAIServiceTree`) - In-memory cache for SDC models and certain A&AI queries (`CacheProviderWithLoadingCache`) - Upgrade TOSCA Parser and add parsing options; fix malformed TOSCA models - Resolve Cloud-Owner values for MSO - Pass X-ONAP headers to MSO Infrastructure -------------- - Remove codehaus' jackson mapper; use soley fasterxml 2.9.7 - Surefire invokes both TestNG and JUnit tests - Support Kotlin source files - AaiController2 which handles errors in a "Spring manner" - Inline generated-sources and remove jsonschema2pojo Quality -------- - Cumulative bug fixes (A&AI API, UI timeouts, and many more) - Many Sonar issues cleaned-up - Some unused classes removed - Minor changes in vid-automation project, allowing some API verification to run Hard Merges ------------ - HTTP Clients (MSO, A&AI, WebConfig, OutgoingRequestHeadersTest) - Moved `package org.onap.vid.controllers` to `controller`, without plural -- just to keep semantic sync with ECOMP. Reference commit in ECOMP: 3d1141625 Issue-ID: VID-378 Change-Id: I9c8d1e74caa41815891d441fc0760bb5f29c5788 Signed-off-by: Ittay Stern --- .../onap/vid/scheduler/SchedulerRestInterface.java | 62 ++++++++++++++-------- 1 file changed, 40 insertions(+), 22 deletions(-) (limited to 'vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java') diff --git a/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java index a4c5b00a8..c986f2256 100644 --- a/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java +++ b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java @@ -4,12 +4,16 @@ import com.att.eelf.configuration.EELFLogger; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import io.joshworks.restclient.http.HttpResponse; +import org.apache.http.HttpException; 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.ExceptionWithRequestInfo; import org.onap.vid.client.SyncRestClient; import org.onap.vid.client.SyncRestClientInterface; import org.onap.vid.exceptions.GenericUncheckedException; +import org.onap.vid.mso.RestObject; +import org.onap.vid.mso.RestObjectWithRequestInfo; import org.onap.vid.utils.Logging; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Service; @@ -24,8 +28,9 @@ import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY; @Service public class SchedulerRestInterface implements SchedulerRestInterfaceIfc { - final private static EELFLogger outgoingRequestsLogger = Logging.getRequestsLogger("scheduler"); + private static final EELFLogger outgoingRequestsLogger = Logging.getRequestsLogger("scheduler"); private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SchedulerRestInterface.class); + private static final String SUCCESSFUL_API_MESSAGE=" REST api GET was successful!"; private SyncRestClientInterface syncRestClient; private Function propertyGetter; private Map commonHeaders; @@ -50,30 +55,43 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc { logger.info("\t<== Client Initialized \n"); } - public void Get(T t, String sourceId, String path, org.onap.vid.scheduler.RestObject restObject) { - initRestClient(); - String methodName = "Get"; - String url = String.format("%s%s", propertyGetter.apply(SchedulerProperties.SCHEDULER_SERVER_URL_VAL), path); - Logging.logRequest(outgoingRequestsLogger, HttpMethod.GET, url); - Map requestHeaders = ImmutableMap.builder() - .putAll(commonHeaders) - .put(REQUEST_ID_HEADER_KEY, Logging.extractOrGenerateRequestId()).build(); - final HttpResponse response = ((HttpResponse) syncRestClient.get(url, requestHeaders, - Collections.emptyMap(), t.getClass())); - Logging.logResponse(outgoingRequestsLogger, HttpMethod.GET, url, response); - int status = response.getStatus(); - restObject.setStatusCode(status); - - if (status == 200) { - t = response.getBody(); - restObject.set(t); - - } else { - throw new GenericUncheckedException(String.format("%s with status=%d, url=%s", methodName, status, url)); + public RestObjectWithRequestInfo Get(T t, String path, RestObject restObject) { + + String url = null; + String rawData = null; + Integer status = null; + + try { + String methodName = "Get"; + url = String.format("%s%s", propertyGetter.apply(SchedulerProperties.SCHEDULER_SERVER_URL_VAL), path); + initRestClient(); + Logging.logRequest(outgoingRequestsLogger, HttpMethod.GET, url); + Map requestHeaders = ImmutableMap.builder() + .putAll(commonHeaders) + .put(REQUEST_ID_HEADER_KEY, Logging.extractOrGenerateRequestId()) + .build(); + final HttpResponse response = ((HttpResponse) syncRestClient.get(url, requestHeaders, + Collections.emptyMap(), t.getClass())); + Logging.logResponse(outgoingRequestsLogger, HttpMethod.GET, url, response); + status = response.getStatus(); + restObject.setStatusCode(status); + + if (status == 200) { + t = response.getBody(); + restObject.set(t); + logger.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + SUCCESSFUL_API_MESSAGE); + logger.info(EELFLoggerDelegate.errorLogger, "<== " + methodName + SUCCESSFUL_API_MESSAGE); + } else { + throw new GenericUncheckedException(new HttpException(String.format("%s with status=%d, url=%s", methodName, status, url))); + } + return new RestObjectWithRequestInfo<>(HttpMethod.GET, url, restObject, status, rawData); + } + catch (RuntimeException e) { + throw new ExceptionWithRequestInfo(HttpMethod.GET, url, rawData, status, e); } } - public void Delete(T t, String sourceID, String path, org.onap.vid.scheduler.RestObject restObject) { + public void Delete(T t, String sourceID, String path, RestObject restObject) { initRestClient(); String url = String.format("%s%s", propertyGetter.apply(SchedulerProperties.SCHEDULER_SERVER_URL_VAL), path); Logging.logRequest(outgoingRequestsLogger, HttpMethod.DELETE, url); -- cgit 1.2.3-korg