Search in sources :

Example 1 with ServiceDescriptor

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);
}
Also used : ServiceDescriptor(org.opendaylight.infrautils.diagstatus.ServiceDescriptor)

Example 2 with 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 "{}";
    }
}
Also used : StringWriter(java.io.StringWriter) ServiceDescriptor(org.opendaylight.infrautils.diagstatus.ServiceDescriptor) IOException(java.io.IOException) JsonWriter(com.google.gson.stream.JsonWriter) Date(java.util.Date)

Example 3 with ServiceDescriptor

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();
}
Also used : ServiceState(org.opendaylight.infrautils.diagstatus.ServiceState) ServiceDescriptor(org.opendaylight.infrautils.diagstatus.ServiceDescriptor)

Example 4 with ServiceDescriptor

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();
}
Also used : ServiceDescriptor(org.opendaylight.infrautils.diagstatus.ServiceDescriptor)

Example 5 with ServiceDescriptor

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));
}
Also used : ServiceDescriptor(org.opendaylight.infrautils.diagstatus.ServiceDescriptor) Test(org.junit.Test)

Aggregations

ServiceDescriptor (org.opendaylight.infrautils.diagstatus.ServiceDescriptor)14 PreDestroy (javax.annotation.PreDestroy)4 Test (org.junit.Test)2 ServiceState (org.opendaylight.infrautils.diagstatus.ServiceState)2 JsonWriter (com.google.gson.stream.JsonWriter)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Date (java.util.Date)1 ServiceStatusProvider (org.opendaylight.infrautils.diagstatus.ServiceStatusProvider)1 AbstractIntegrationTest (org.opendaylight.infrautils.itestutils.AbstractIntegrationTest)1