summaryrefslogtreecommitdiffstats
path: root/sliapi/provider
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2017-12-19 13:13:36 -0500
committerDan Timoney <dtimoney@att.com>2017-12-19 13:13:36 -0500
commita2a1997c4976499912dae2aadef52a73c764840b (patch)
tree92cc4a12bc5ead58552b008f3e2e221a79a62012 /sliapi/provider
parent5dcba2269e3a9a0be39f0093194ddeb0c70c20aa (diff)
Enhance health check
In HA environment, different types of health check are needed for load balancers (which care about state of each node in cluster) vs external applications (which case about state of entire cluster). So, separate APIs are needed for these 2 types of needs. Change-Id: I99cd21cef7a7e2b4b8c96c1f22c0d6210bb91e96 Issue-ID: CCSDK-157 Signed-off-by: Dan Timoney <dtimoney@att.com>
Diffstat (limited to 'sliapi/provider')
-rw-r--r--sliapi/provider/src/main/java/org/onap/ccsdk/sli/core/sliapi/sliapiProvider.java64
1 files changed, 59 insertions, 5 deletions
diff --git a/sliapi/provider/src/main/java/org/onap/ccsdk/sli/core/sliapi/sliapiProvider.java b/sliapi/provider/src/main/java/org/onap/ccsdk/sli/core/sliapi/sliapiProvider.java
index 88c475174..82e660083 100644
--- a/sliapi/provider/src/main/java/org/onap/ccsdk/sli/core/sliapi/sliapiProvider.java
+++ b/sliapi/provider/src/main/java/org/onap/ccsdk/sli/core/sliapi/sliapiProvider.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.
@@ -21,11 +21,14 @@
package org.onap.ccsdk.sli.core.sliapi;
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.Properties;
import java.util.concurrent.Future;
-
import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
@@ -47,11 +50,14 @@ import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.Hea
import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.HealthcheckOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.SLIAPIService;
import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.TestResults;
+import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.VlbcheckOutput;
+import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.VlbcheckOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.execute.graph.input.SliParameter;
import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.test.results.TestResult;
import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.test.results.TestResultBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -69,7 +75,6 @@ import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import com.google.common.util.concurrent.Futures;
@@ -120,6 +125,8 @@ public class sliapiProvider implements AutoCloseable, SLIAPIService{
private static String SLIAPI_NAMESPACE = "org:onap:ccsdk:sli:core:sliapi";
private static String SLIAPI_REVISION = "2016-11-10";
+ private static String SDNC_STATUS_FILE = "SDNC_STATUS_FILE";
+ private static String sdncStatusFile = null;
private static QName TEST_RESULTS_QNAME = null;
private static QName TEST_RESULT_QNAME = null;
@@ -142,7 +149,8 @@ public class sliapiProvider implements AutoCloseable, SLIAPIService{
public void initialize(){
LOG.info( "Initializing provider for " + appName );
//initialization code goes here.
-
+ sdncStatusFile = System.getenv(SDNC_STATUS_FILE);
+ LOG.info( "SDNC STATUS FILE = " + sdncStatusFile );
rpcRegistration = rpcRegistry.addRpcImplementation(SLIAPIService.class, this);
LOG.info( "Initialization complete for " + appName );
}
@@ -554,4 +562,50 @@ public class sliapiProvider implements AutoCloseable, SLIAPIService{
}
+ @Override
+ public Future<RpcResult<VlbcheckOutput>> vlbcheck() {
+ RpcResult<VlbcheckOutput> rpcResult = null;
+ VlbcheckOutputBuilder respBuilder = new VlbcheckOutputBuilder();
+ boolean suspended = false;
+ BufferedReader br = null;
+ String line = "";
+
+ // check the state based on the config file
+
+ if (sdncStatusFile != null) {
+ try {
+ br = new BufferedReader(new FileReader(sdncStatusFile));
+ while((line = br.readLine()) != null)
+ {
+ if ("ODL_STATE=SUSPENDED".equals(line)) {
+ suspended = true;
+ LOG.debug("vlbcheck: server is suspended");
+ }
+ }
+ br.close();
+ } catch (FileNotFoundException e) {
+ LOG.trace("Caught File not found exception " + sdncStatusFile +"\n",e);
+ } catch (Exception e) {
+ LOG.trace("Failed to read status file " + sdncStatusFile +"\n",e);
+ } finally {
+ if (br != null) {
+ try {
+ br.close();
+ } catch (IOException e) {
+ LOG.warn("Failed to close status file " + sdncStatusFile +"\n",e);
+ }
+ }
+ }
+ }
+
+ if (suspended) {
+ rpcResult = RpcResultBuilder.<VlbcheckOutput>failed().withError(ErrorType.APPLICATION,
+ "resource-denied", "Server Suspended").build();
+ } else {
+ respBuilder.setResponseMessage("server is normal");
+ rpcResult = RpcResultBuilder.<VlbcheckOutput> status(true)
+ .withResult(respBuilder.build()).build();
+ }
+ return (Futures.immediateFuture(rpcResult));
+ }
}