aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/scheduler
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/scheduler')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/scheduler/RestObject.java44
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/scheduler/RestObjects/RestObject.java39
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java62
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterfaceIfc.java7
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerService.java7
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerServiceImpl.java43
6 files changed, 94 insertions, 108 deletions
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<T> {
-
- 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<T> {
-
- 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<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);
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();
- <T> void Get(T t, String sourceId, String path, org.onap.vid.scheduler.RestObject<T> restObject);
+ <T> RestObjectWithRequestInfo Get(T t, String path, RestObject<T> restObject);
- <T> void Delete(T t, String sourceID, String path, org.onap.vid.scheduler.RestObject<T> restObject)
- throws Exception;
+ <T> void Delete(T t, String sourceID, String path, RestObject<T> 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));
+ }
+ }
+}