Issue-ID: APPC-362
Change-Id: I5dfcee3ea542b130916b055b408f89240e513bba
Signed-off-by: kusuma kumari M <km583p@att.com>
logger.info(Msg.COMPONENT_INITIALIZING, appName, "rest adapter");
adapter = new RestAdapterImpl();
if (registration == null) {
logger.info(Msg.COMPONENT_INITIALIZING, appName, "rest adapter");
adapter = new RestAdapterImpl();
if (registration == null) {
+ logger.info(Msg.REGISTERING_SERVICE, appName, adapter.getAdapterName(),RestAdapter.class.getSimpleName());
+
registration = context.registerService(RestAdapter.class, adapter, null);
}
registration = context.registerService(RestAdapter.class, adapter, null);
}
import org.osgi.framework.ServiceRegistration;
public class RestHealthcheckActivator implements BundleActivator {
import org.osgi.framework.ServiceRegistration;
public class RestHealthcheckActivator implements BundleActivator {
/**
* The bundle registration
*/
private ServiceRegistration registration = null;
/**
* The bundle registration
*/
private ServiceRegistration registration = null;
-
- /**
- * The reference to the actual implementation object that implements the services
- */
- private RestHealthcheckAdapter adapter;
-
private static final EELFLogger logger = EELFManager.getInstance().getLogger(RestHealthcheckActivator.class);
/**
private static final EELFLogger logger = EELFManager.getInstance().getLogger(RestHealthcheckActivator.class);
/**
@Override
public void start(BundleContext context) throws Exception {
logger.info("Starting bundle " + getName());
@Override
public void start(BundleContext context) throws Exception {
logger.info("Starting bundle " + getName());
+ /* The reference to the actual implementation object that implements the services */
+ RestHealthcheckAdapter adapter = new RestHealthcheckAdapterImpl();
- adapter = new RestHealthcheckAdapterImpl();
if (registration == null) {
registration = context.registerService(RestHealthcheckAdapter.class, adapter, null);
}
}
if (registration == null) {
registration = context.registerService(RestHealthcheckAdapter.class, adapter, null);
}
}
/**
* Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
* the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
/**
* Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
* the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
public String getName() {
return "APPC Rest Healthcheck adapter";
}
public String getName() {
return "APPC Rest Healthcheck adapter";
}
import java.net.InetAddress;
public class RestHealthcheckAdapterImpl implements RestHealthcheckAdapter {
import java.net.InetAddress;
public class RestHealthcheckAdapterImpl implements RestHealthcheckAdapter {
/**
* The constant for the status code for a failed outcome
*/
/**
* The constant for the status code for a failed outcome
*/
*/
public RestHealthcheckAdapterImpl() {
initialize();
*/
public RestHealthcheckAdapterImpl() {
initialize();
@Override
public String getAdapterName() {
return configuration.getProperty(Constants.PROPERTY_ADAPTER_NAME);
}
@Override
public String getAdapterName() {
return configuration.getProperty(Constants.PROPERTY_ADAPTER_NAME);
}
public void checkHealth(Map<String, String> params, SvcLogicContext ctx) {
logger.info("VNF rest health check");
String uri=params.get("VNF.URI");
public void checkHealth(Map<String, String> params, SvcLogicContext ctx) {
logger.info("VNF rest health check");
String uri=params.get("VNF.URI");
rc.isAlive();
try(CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpGet httpGet = new HttpGet(tUrl);
rc.isAlive();
try(CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpGet httpGet = new HttpGet(tUrl);
- HttpResponse response =null ;
+ HttpResponse response ;
response = httpClient.execute(httpGet);
int responseCode=response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
response = httpClient.execute(httpGet);
int responseCode=response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, ex.toString());
}
}
doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, ex.toString());
}
}
@SuppressWarnings("static-method")
private void doFailure(RequestContext rc, HttpStatus code, String message) {
SvcLogicContext svcLogic = rc.getSvcLogicContext();
@SuppressWarnings("static-method")
private void doFailure(RequestContext rc, HttpStatus code, String message) {
SvcLogicContext svcLogic = rc.getSvcLogicContext();
if (msg.contains("\n")) {
msg = msg.substring(msg.indexOf("\n"));
}
if (msg.contains("\n")) {
msg = msg.substring(msg.indexOf("\n"));
}
String status;
try {
status = Integer.toString(code.getStatusCode());
String status;
try {
status = Integer.toString(code.getStatusCode());
svcLogic.setAttribute("healthcheck.result.code", "200");
svcLogic.setAttribute("healthcheck.result.message", status+" "+msg);
}
svcLogic.setAttribute("healthcheck.result.code", "200");
svcLogic.setAttribute("healthcheck.result.message", status+" "+msg);
}
/**
* @param rc
* The request context that manages the state and recovery of the
/**
* @param rc
* The request context that manages the state and recovery of the
String msg = Integer.toString(code)+" "+message;
svcLogic.setAttribute("healthcheck.result.code", "200");
svcLogic.setAttribute("healthcheck.result.message", msg);
String msg = Integer.toString(code)+" "+message;
svcLogic.setAttribute("healthcheck.result.code", "200");
svcLogic.setAttribute("healthcheck.result.message", msg);
@SuppressWarnings("static-method")
private void doSuccess(RequestContext rc, int code, String message) {
SvcLogicContext svcLogic = rc.getSvcLogicContext();
String msg = Integer.toString(code)+" "+message;
svcLogic.setAttribute("healthcheck.result.code", "400");
svcLogic.setAttribute("healthcheck.result.message", msg);
@SuppressWarnings("static-method")
private void doSuccess(RequestContext rc, int code, String message) {
SvcLogicContext svcLogic = rc.getSvcLogicContext();
String msg = Integer.toString(code)+" "+message;
svcLogic.setAttribute("healthcheck.result.code", "400");
svcLogic.setAttribute("healthcheck.result.message", msg);
/**
* initialize the provider adapter by building the context cache
*/
private void initialize() {
/**
* initialize the provider adapter by building the context cache
*/
private void initialize() {
logger.info("init rest health check adapter!!!!!");
}
logger.info("init rest health check adapter!!!!!");
}
public static final String REQUEST_ID_FIELD_NAME = "REQUEST_ID";
public static final String CREATION_DATE_FIELD_NAME = "CREATION_DATE";
public static final String LOG_FIELD_NAME = "LOG";
public static final String REQUEST_ID_FIELD_NAME = "REQUEST_ID";
public static final String CREATION_DATE_FIELD_NAME = "CREATION_DATE";
public static final String LOG_FIELD_NAME = "LOG";
- public static final String ASDC_ARTIFACTS_TABLE_NAME = "ASDC_ARTIFACTS";
+ public static final String SDC_ARTIFACTS_TABLE_NAME = "ASDC_ARTIFACTS";
// input fields names
public static final String PAYLOAD = "payload";
// input fields names
public static final String PAYLOAD = "payload";
@Override
public void connectWithRetry() {
@Override
public void connectWithRetry() {
- int retryCount = 0;
- int retryDelay = 0;
- int retriesLeft = 0;
+ int retryCount ;
+ int retryDelay ;
+ int retriesLeft;
retryCount = configuration.getIntegerProperty(Constants.CONNECTION_RETRY_COUNT,
Constants.DEFAULT_CONNECTION_RETRY_COUNT);
retryDelay = configuration.getIntegerProperty(Constants.CONNECTION_RETRY_DELAY,
retryCount = configuration.getIntegerProperty(Constants.CONNECTION_RETRY_COUNT,
Constants.DEFAULT_CONNECTION_RETRY_COUNT);
retryDelay = configuration.getIntegerProperty(Constants.CONNECTION_RETRY_DELAY,
- } catch (Exception e) {
- throw e;
- }
} while (retriesLeft > 0);
}
} while (retriesLeft > 0);
}
client.setOut(out);
client.setErr(err);
OpenFuture openFuture = client.open();
client.setOut(out);
client.setErr(err);
OpenFuture openFuture = client.open();
try {
client.waitFor(ClientChannel.CLOSED, timeout);
openFuture.verify();
try {
client.waitFor(ClientChannel.CLOSED, timeout);
openFuture.verify();
return exitStatus;
} catch (RuntimeException e) {
throw e;
return exitStatus;
} catch (RuntimeException e) {
throw e;
- } catch (Exception t) {
+ } catch (Exception e1) {
- "Error executing command [" + cmd + "] over SSH [" + username + "@" + host + ":" + port + "]", t);
+ "Error executing command [" + cmd + "] over SSH [" + username + "@" + host + ":" + port + "]", e1);