use of org.opendaylight.infrautils.diagstatus.ServiceDescriptor in project openflowplugin by opendaylight.
the class OpenflowPluginDiagStatusProvider method reportStatus.
public void reportStatus(ServiceState serviceState, String description) {
LOG.debug("reporting status as {} for {}", serviceState, OPENFLOW_SERVICE_NAME);
serviceDescriptor = new ServiceDescriptor(OPENFLOW_SERVICE_NAME, serviceState, description);
diagStatusService.report(serviceDescriptor);
}
use of org.opendaylight.infrautils.diagstatus.ServiceDescriptor in project infrautils by opendaylight.
the class DiagStatusServiceMBeanImpl method acquireServiceStatusAsJSON.
@Override
public String acquireServiceStatusAsJSON(String formatType) {
try {
StringWriter strWrtr = new StringWriter();
JsonWriter writer = new JsonWriter(strWrtr);
writer.beginObject();
writer.name("timeStamp").value(new Date().toString());
writer.name("systemReadyState").value(systemReadyMonitor.getSystemState().name());
writer.name("statusSummary");
// [
writer.beginArray();
for (ServiceDescriptor status : diagStatusService.getAllServiceDescriptors()) {
// {
writer.beginObject();
switch(formatType) {
case DEBUG_OUTPUT_FORMAT:
writer.name("serviceName").value(status.getModuleServiceName());
writer.name("lastReportedStatus").value(status.getServiceState().name());
writer.name("effectiveStatus").value(status.getServiceState().name());
writer.name("reportedStatusDes").value(status.getStatusDesc());
writer.name("statusTimestamp").value(status.getTimestamp().toString());
break;
case VERBOSE_OUTPUT_FORMAT:
writer.name("serviceName").value(status.getModuleServiceName());
writer.name("effectiveStatus").value(status.getServiceState().name());
break;
default:
writer.name("statusBrief").value(acquireServiceStatusBrief());
break;
}
writer.endObject();
}
writer.endArray();
writer.endObject();
writer.flush();
writer.close();
return strWrtr.getBuffer().toString();
} catch (IOException e) {
LOG.error("Error while converting service status to JSON", e);
return "{}";
}
}
use of org.opendaylight.infrautils.diagstatus.ServiceDescriptor in project infrautils by opendaylight.
the class DiagStatusServiceMBeanImpl method acquireServiceStatusBrief.
@Override
public String acquireServiceStatusBrief() {
String errorState = "ERROR - ";
StringBuilder statusSummary = new StringBuilder();
statusSummary.append("System ready state: ").append(systemReadyMonitor.getSystemState()).append('\n');
for (ServiceDescriptor stat : diagStatusService.getAllServiceDescriptors()) {
ServiceState state = stat.getServiceState();
if (state.equals(ERROR) || state.equals(UNREGISTERED)) {
statusSummary.append(errorState).append(stat.getModuleServiceName()).append(" ");
}
}
return statusSummary.toString();
}
use of org.opendaylight.infrautils.diagstatus.ServiceDescriptor in project infrautils by opendaylight.
the class DiagStatusServiceMBeanImpl method acquireServiceStatus.
@Override
public String acquireServiceStatus() {
StringBuilder statusSummary = new StringBuilder();
statusSummary.append("System ready state: ").append(systemReadyMonitor.getSystemState()).append('\n');
for (ServiceDescriptor status : diagStatusService.getAllServiceDescriptors()) {
statusSummary.append("ServiceName : ").append(status.getModuleServiceName()).append("\n");
if (status.getServiceState() != null) {
statusSummary.append("Last Reported Status : ").append(status.getServiceState().name()).append("\n");
}
if (status.getStatusDesc() != null) {
statusSummary.append("Reported Status Desc : ").append(status.getStatusDesc()).append("\n");
}
if (status.getTimestamp() != null) {
statusSummary.append("Status Timestamp : ").append(status.getTimestamp().toString()).append("\n\n");
}
}
statusSummary.append("\n");
return statusSummary.toString();
}
use of org.opendaylight.infrautils.diagstatus.ServiceDescriptor in project infrautils by opendaylight.
the class DiagStatusTest method testDiagStatus.
@Test
public void testDiagStatus() {
String testService1 = "testService";
diagStatusService.register(testService1);
// Verify if "testService" got registered with STARTING state.
ServiceDescriptor serviceDescriptor1 = diagStatusService.getServiceDescriptor(testService1);
Assert.assertEquals(ServiceState.STARTING, serviceDescriptor1.getServiceState());
// Verify if "testService" status is updated as OPERATIONAL.
ServiceDescriptor reportStatus = new ServiceDescriptor(testService1, ServiceState.OPERATIONAL, "service is UP");
diagStatusService.report(reportStatus);
ServiceDescriptor serviceDescriptor2 = diagStatusService.getServiceDescriptor(testService1);
Assert.assertEquals(ServiceState.OPERATIONAL, serviceDescriptor2.getServiceState());
// Verify if "testService" status is updated as UNREGISTERED.
diagStatusService.report(new ServiceDescriptor(testService1, ServiceState.UNREGISTERED, "service is Unregistered"));
// JXM based Junits to see if the service state is getting retrieved properly.
Assert.assertEquals(ServiceState.UNREGISTERED.name(), diagStatusServiceMBean.acquireServiceStatusMap().get(testService1));
}
Aggregations