diff options
author | Ittay Stern <ittay.stern@att.com> | 2018-12-31 17:21:27 +0200 |
---|---|---|
committer | Ittay Stern <ittay.stern@att.com> | 2019-01-09 20:19:55 +0200 |
commit | 6ad41e3ccd398a2721f41ad61c80b7bb03f7d127 (patch) | |
tree | 3bd672dff83e3218232cd8665680416b7fc26a5d /vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java | |
parent | 5ec29ff5e3864f1ba6ecac71f8bffbefa400cf27 (diff) |
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 <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java')
-rw-r--r-- | vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java | 62 |
1 files changed, 40 insertions, 22 deletions
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 a4c5b00a..c986f225 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<String, String> propertyGetter; private Map<String, String> commonHeaders; @@ -50,30 +55,43 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc { logger.info("\t<== Client Initialized \n"); } - public <T> void Get(T t, String sourceId, String path, org.onap.vid.scheduler.RestObject<T> 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<String, String> requestHeaders = ImmutableMap.<String, String>builder() - .putAll(commonHeaders) - .put(REQUEST_ID_HEADER_KEY, Logging.extractOrGenerateRequestId()).build(); - final HttpResponse<T> response = ((HttpResponse<T>) 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 <T> RestObjectWithRequestInfo<T> Get(T t, String path, RestObject<T> 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<String, String> requestHeaders = ImmutableMap.<String, String>builder() + .putAll(commonHeaders) + .put(REQUEST_ID_HEADER_KEY, Logging.extractOrGenerateRequestId()) + .build(); + final HttpResponse<T> response = ((HttpResponse<T>) 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 <T> void Delete(T t, String sourceID, String path, org.onap.vid.scheduler.RestObject<T> restObject) { + public <T> void Delete(T t, String sourceID, String path, RestObject<T> restObject) { initRestClient(); String url = String.format("%s%s", propertyGetter.apply(SchedulerProperties.SCHEDULER_SERVER_URL_VAL), path); Logging.logRequest(outgoingRequestsLogger, HttpMethod.DELETE, url); |