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 --- .../java/org/onap/vid/scheduler/RestObject.java | 44 --------------- .../onap/vid/scheduler/RestObjects/RestObject.java | 39 -------------- .../onap/vid/scheduler/SchedulerRestInterface.java | 62 ++++++++++++++-------- .../vid/scheduler/SchedulerRestInterfaceIfc.java | 7 +-- .../org/onap/vid/scheduler/SchedulerService.java | 7 +++ .../onap/vid/scheduler/SchedulerServiceImpl.java | 43 +++++++++++++++ 6 files changed, 94 insertions(+), 108 deletions(-) delete mode 100644 vid-app-common/src/main/java/org/onap/vid/scheduler/RestObject.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/scheduler/RestObjects/RestObject.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerService.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerServiceImpl.java (limited to 'vid-app-common/src/main/java/org/onap/vid/scheduler') diff --git a/vid-app-common/src/main/java/org/onap/vid/scheduler/RestObject.java b/vid-app-common/src/main/java/org/onap/vid/scheduler/RestObject.java deleted file mode 100644 index 4accb55da..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/scheduler/RestObject.java +++ /dev/null @@ -1,44 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T 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.scheduler; - - -public class RestObject { - - private T t; - - private int statusCode= 0; - - public String uuid; - - public void set(T t) { this.t = t; } - - public T get() { return t; } - - public void setStatusCode(int v) { this.statusCode = v; } - - public int getStatusCode() { return this.statusCode; } - - public void setUUID(String uuid) { this.uuid = uuid; } - - public String getUUID() { return this.uuid; } -} - diff --git a/vid-app-common/src/main/java/org/onap/vid/scheduler/RestObjects/RestObject.java b/vid-app-common/src/main/java/org/onap/vid/scheduler/RestObjects/RestObject.java deleted file mode 100644 index ff1ffb4c5..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/scheduler/RestObjects/RestObject.java +++ /dev/null @@ -1,39 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T 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.scheduler.RestObjects; - - -public class RestObject { - - private T t; - - private int statusCode= 0; - - public void set(T t) { this.t = t; } - - public T get() { return t; } - - public void setStatusCode(int v) { this.statusCode = v; } - - public int getStatusCode() { return this.statusCode; } - -} - 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); diff --git a/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterfaceIfc.java b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterfaceIfc.java index d39e938b4..ca5c02651 100644 --- a/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterfaceIfc.java +++ b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterfaceIfc.java @@ -1,6 +1,8 @@ package org.onap.vid.scheduler; +import org.onap.vid.mso.RestObject; +import org.onap.vid.mso.RestObjectWithRequestInfo; import org.springframework.stereotype.Service; @Service @@ -8,10 +10,9 @@ public interface SchedulerRestInterfaceIfc { void initRestClient(); - void Get(T t, String sourceId, String path, org.onap.vid.scheduler.RestObject restObject); + RestObjectWithRequestInfo Get(T t, String path, RestObject restObject); - void Delete(T t, String sourceID, String path, org.onap.vid.scheduler.RestObject restObject) - throws Exception; + void Delete(T t, String sourceID, String path, RestObject 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 new file mode 100644 index 000000000..b4246d5c0 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerService.java @@ -0,0 +1,7 @@ +package org.onap.vid.scheduler; + +import org.onap.vid.model.probes.ExternalComponentStatus; + +public interface SchedulerService { + ExternalComponentStatus probeGetSchedulerChangeManagements(); +} 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 new file mode 100644 index 000000000..99754fcde --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerServiceImpl.java @@ -0,0 +1,43 @@ +package org.onap.vid.scheduler; + +import org.onap.vid.aai.ExceptionWithRequestInfo; +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.mso.RestObjectWithRequestInfo; +import org.onap.vid.services.ChangeManagementService; +import org.onap.vid.utils.Logging; +import org.springframework.beans.factory.annotation.Autowired; + +public class SchedulerServiceImpl implements SchedulerService{ + + private final ChangeManagementService changeManagementService; + + + @Autowired + public SchedulerServiceImpl(ChangeManagementService changeManagementService) { + this.changeManagementService = changeManagementService; + } + + @Override + public ExternalComponentStatus probeGetSchedulerChangeManagements() { + long startTime = System.currentTimeMillis(); + try { + RestObjectWithRequestInfo response = this.changeManagementService.getSchedulerChangeManagementsWithRequestInfo(); + return new ExternalComponentStatus( + ExternalComponentStatus.Component.SCHEDULER, + true, + new HttpRequestMetadata(response, "OK", startTime) + ); + } catch (ExceptionWithRequestInfo e) { + long duration = System.currentTimeMillis() - startTime; + return new ExternalComponentStatus(ExternalComponentStatus.Component.SCHEDULER, + false, + new HttpRequestMetadata(e, duration)); + } catch (Exception e) { + long duration = System.currentTimeMillis() - startTime; + return new ExternalComponentStatus(ExternalComponentStatus.Component.SCHEDULER, false, + new ErrorMetadata(Logging.exceptionToDescription(e), duration)); + } + } +} -- cgit 1.2.3-korg