import org.osgi.framework.ServiceRegistration;
public class RestHealthcheckActivator implements BundleActivator {
-
/**
* 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);
/**
@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);
}
}
-
/**
* 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";
}
import java.net.InetAddress;
public class RestHealthcheckAdapterImpl implements RestHealthcheckAdapter {
+
/**
* The constant for the status code for a failed outcome
*/
*/
public RestHealthcheckAdapterImpl() {
initialize();
-
}
-
@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");
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();
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();
if (msg.contains("\n")) {
msg = msg.substring(msg.indexOf("\n"));
}
-
String status;
try {
status = Integer.toString(code.getStatusCode());
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
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);
-
}
-
-
/**
* initialize the provider adapter by building the context cache
*/
private void initialize() {
-
-
logger.info("init rest health check adapter!!!!!");
}
+
}
@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,
} else {
throw e;
}
- } catch (Exception e) {
- throw e;
- }
+ }
} while (retriesLeft > 0);
}
client.setOut(out);
client.setErr(err);
OpenFuture openFuture = client.open();
- int exitStatus = 0;
+ int exitStatus;
try {
client.waitFor(ClientChannel.CLOSED, timeout);
openFuture.verify();
return exitStatus;
} catch (RuntimeException e) {
throw e;
- } catch (Exception t) {
+ } catch (Exception e1) {
throw new SshException(
- "Error executing command [" + cmd + "] over SSH [" + username + "@" + host + ":" + port + "]", t);
+ "Error executing command [" + cmd + "] over SSH [" + username + "@" + host + ":" + port + "]", e1);
}
}