org.wso2.carbon.logging.view.stub.types.carbon.LogEvent Java Examples

The following examples show how to use org.wso2.carbon.logging.view.stub.types.carbon.LogEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RestResourceLCWithTwoActionsPointingToSameStateWithExecutor.java    From product-es with Apache License 2.0 6 votes vote down vote up
@Test(groups = {"wso2.greg", "wso2.greg.es"}, description = "PromoteLifeCycle with fault user",
      dependsOnMethods = {"testAddResources"})
public void PerformLCActionPublish()
        throws JSONException, InterruptedException, IOException, LogViewerLogViewerException {
    queryParamMap.put("type", "restservice");
    queryParamMap.put("lifecycle", lifeCycleName);
    ClientResponse response =
            genericRestClient.geneticRestRequestPost(publisherUrl + "/asset/" + assetId + "/change-state",
                                                     MediaType.APPLICATION_FORM_URLENCODED,
                                                     MediaType.APPLICATION_JSON,
                                                     "nextState=development&comment=Published&nextAction=Publish"
                    , queryParamMap, headerMap, cookieHeader);
    JSONObject obj2 = new JSONObject(response.getEntity(String.class));
    Assert.assertTrue(response.getStatusCode() == 200, "Fault user accepted");
    LogEvent[] logEvents = logViewerClient.getLogs("INFO", "@@@@@@@@@@@@@@@@@@@@@@ " +
                                                           "PromoteNotificationExecutor ACTION executed! " +
                                                           "---------------------------", "", "");
    Assert.assertEquals(logEvents.length, 1);
}
 
Example #2
Source File: RestResourceLCWithTwoActionsPointingToSameStateWithExecutor.java    From product-es with Apache License 2.0 6 votes vote down vote up
@Test(groups = {"wso2.greg", "wso2.greg.es"}, description = "PromoteLifeCycle with fault user",
      dependsOnMethods = {"PerformLCActionPublish"})
public void PerformLCActionUnpublish() throws LogViewerLogViewerException, RemoteException, JSONException {
    queryParamMap.put("type", "restservice");
    queryParamMap.put("lifecycle", lifeCycleName);
    ClientResponse response =
            genericRestClient.geneticRestRequestPost(publisherUrl + "/asset/" + assetId + "/change-state",
                                                     MediaType.APPLICATION_FORM_URLENCODED,
                                                     MediaType.APPLICATION_JSON,
                                                     "nextState=development&comment=Unpublished" +
                                                     "&nextAction=Unpublish"
                    , queryParamMap, headerMap, cookieHeader);
    JSONObject obj2 = new JSONObject(response.getEntity(String.class));
    Assert.assertTrue(response.getStatusCode() == 200, "Fault user accepted");
    LogEvent[] logEvents = logViewerClient.getLogs("INFO", "###################### " +
                                                           "DemoteNotificationExecutor ACTION executed! " +
                                                           "---------------------------", "", "");
    //TODO: Following assertion will fail on carbon-store release 2.3.9
    //Once this test is built with carbon-store version higher than 2.3.9, it passes
    //https://wso2.org/jira/browse/REGISTRY-3086
    Assert.assertEquals(logEvents.length, 1);
}
 
Example #3
Source File: ServerLogClient.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
private String[] getLogsAsStrings(LogEvent[] selectedLogs) {

        String [] logs = new String[selectedLogs.length];
        for (int i = 0 ; i < selectedLogs.length ; i++) {
            logs[i] = selectedLogs[i].getMessage();
        }
        return logs;
    }
 
Example #4
Source File: LogViewerClient.java    From product-es with Apache License 2.0 5 votes vote down vote up
public LogEvent[] getAllSystemLogs() throws RemoteException, LogViewerLogViewerException {
    try {
        return logViewerStub.getAllSystemLogs();
    } catch (LogViewerLogViewerException e) {
        log.error("Fail to get all logs ", e);
        throw new LogViewerLogViewerException("Fail to get all system logs ", e);
    }
}
 
Example #5
Source File: LoggerTestCase.java    From product-cep with Apache License 2.0 4 votes vote down vote up
@Test(groups = {"wso2.cep"}, description = "Testing Text Logger with mapping")
public void loggerTextWithMappingTestScenario() throws Exception {
    int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount();
    int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount();
    String samplePath = "outputflows" + File.separator + "sample0056";

    //Add StreamDefinition
    String streamDefinitionAsString = getJSONArtifactConfiguration(samplePath,
            "org.wso2.event.sensor.stream_1.0.0.json");
    eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString);
    Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1);

    //Add Text Logger
    String eventPublisherConfig = getXMLArtifactConfiguration(samplePath, "logger.xml");
    eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig);
    Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1);

    EventDto eventDto = new EventDto();
    eventDto.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
    eventDto.setAttributeValues(new String[]{"199008131245", "false", "200", "temperature", "23.45656", "7.12324",
            "100.34", "23.4545"});

    EventDto eventDto2 = new EventDto();
    eventDto2.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
    eventDto2.setAttributeValues(new String[]{"199008131245", "false", "201", "temperature", "23.45656", "7.12324",
            "100.34", "23.4545"});

    EventDto eventDto3 = new EventDto();
    eventDto3.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
    eventDto3.setAttributeValues(new String[]{"199008131245", "false", "203", "temperature", "23.45656", "7.12324",
            "100.34", "23.4545"});

    int beforeCount = logViewerClient.getAllRemoteSystemLogs().length;
    eventSimulatorAdminServiceClient.sendEvent(eventDto);
    Thread.sleep(1000);
    eventSimulatorAdminServiceClient.sendEvent(eventDto2);
    Thread.sleep(1000);
    eventSimulatorAdminServiceClient.sendEvent(eventDto3);
    Thread.sleep(1000);
    try {
        boolean mappingPortionFound = false;
        Thread.sleep(2000);
        LogEvent[] logs = logViewerClient.getAllRemoteSystemLogs();
        for (int i = 0; i < (logs.length - beforeCount); i++) {
            if (logs[i].getMessage().contains("temperature Sensor related data. \n- sensor id: 200\n- time-stamp: 199008131245\n- power saving enabled: false\nLocation \n- longitude: 23.45656\n- latitude: 7.12324\nValues\n- temperature: 23.4545\n- humidity: 100.34")) {
                mappingPortionFound = true;
                break;
            }
        }
        Assert.assertTrue(mappingPortionFound, "Incorrect mapping has occurred! ");
        Thread.sleep(2000);
    } catch (Throwable e) {
        log.error("Exception thrown: " + e.getMessage(), e);
        Assert.fail("Exception: " + e.getMessage());
    }

    eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0");
    eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("logger.xml");

    Thread.sleep(2000);

}
 
Example #6
Source File: LoggerTestCase.java    From product-cep with Apache License 2.0 4 votes vote down vote up
@Test(groups = {"wso2.cep"}, description = "Testing JSON Mapping Logger")
public void loggerJSONWithMappingTestScenario() throws Exception {
    int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount();
    int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount();
    String samplePath = "outputflows" + File.separator + "sample0052";

    //Add StreamDefinition
    String streamDefinitionAsString = getJSONArtifactConfiguration(samplePath,
            "org.wso2.event.sensor.stream_1.0.0.json");
    eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString);
    Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1);

    //Add Text Logger
    String eventPublisherConfig = getXMLArtifactConfiguration(samplePath, "logger.xml");
    eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig);
    Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1);

    EventDto eventDto = new EventDto();
    eventDto.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
    eventDto.setAttributeValues(new String[]{"199008131245", "false", "400", "temperature", "23.45656", "7.12324",
            "100.34", "23.4545"});

    EventDto eventDto2 = new EventDto();
    eventDto2.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
    eventDto2.setAttributeValues(new String[]{"199008131245", "false", "401", "temperature", "23.45656", "7.12324",
            "100.34", "23.4545"});

    EventDto eventDto3 = new EventDto();
    eventDto3.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
    eventDto3.setAttributeValues(new String[]{"199008131245", "false", "403", "temperature", "23.45656", "7.12324",
            "100.34", "23.4545"});

    int beforeCount = logViewerClient.getAllRemoteSystemLogs().length;

    eventSimulatorAdminServiceClient.sendEvent(eventDto);
    Thread.sleep(1000);
    eventSimulatorAdminServiceClient.sendEvent(eventDto2);
    Thread.sleep(1000);
    eventSimulatorAdminServiceClient.sendEvent(eventDto3);

    try {
        boolean mappingPortionFound = false;
        Thread.sleep(2000);
        LogEvent[] logs = logViewerClient.getAllRemoteSystemLogs();
        for (int i = 0; i < (logs.length - beforeCount); i++) {
            if (logs[i].getMessage().contains("{\"Sensor Data\":{\"equipment related data\":" +
                    "{\"timestamp\":199008131245,\"isPowerSaverEnabled\":false,\"sensorId\":400," +
                    "\"sensorName\":\"temperature\"},\"location data\":{\"longitude\":23.45656,\"latitude\":7.12324}," +
                    "\"sensor data\":{\"humidity\":100.34,\"sensorValue\":23.4545}}}")) {
                mappingPortionFound = true;
                break;
            }
        }
        Assert.assertTrue(mappingPortionFound, "Incorrect mapping has occurred! ");
        Thread.sleep(2000);
    } catch (Throwable e) {
        log.error("Exception thrown: " + e.getMessage(), e);
        Assert.fail("Exception: " + e.getMessage());
    }

    eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0");
    eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("logger.xml");

    Thread.sleep(2000);

}
 
Example #7
Source File: LoggerTestCase.java    From product-cep with Apache License 2.0 4 votes vote down vote up
@Test(groups = {"wso2.cep"}, description = "Testing XML mapping Logger")
public void loggerXMLWithMappingTestScenario() throws Exception {
    int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount();
    int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount();
    String samplePath = "outputflows" + File.separator + "sample0054";

    //Add StreamDefinition
    String streamDefinitionAsString = getJSONArtifactConfiguration(samplePath,
            "org.wso2.event.sensor.stream_1.0.0.json");
    eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString);
    Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1);

    //Add Text Logger
    String eventPublisherConfig = getXMLArtifactConfiguration(samplePath, "logger.xml");
    eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig);
    Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1);

    EventDto eventDto = new EventDto();
    eventDto.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
    eventDto.setAttributeValues(new String[]{"199008131245", "false", "500", "temperature", "23.45656", "7.12324",
            "100.34", "23.4545"});

    EventDto eventDto2 = new EventDto();
    eventDto2.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
    eventDto2.setAttributeValues(new String[]{"199008131245", "false", "501", "temperature", "23.45656", "7.12324",
            "100.34", "23.4545"});

    EventDto eventDto3 = new EventDto();
    eventDto3.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
    eventDto3.setAttributeValues(new String[]{"199008131245", "false", "503", "temperature", "23.45656", "7.12324",
            "100.34", "23.4545"});

    int beforeCount = logViewerClient.getAllRemoteSystemLogs().length;

    eventSimulatorAdminServiceClient.sendEvent(eventDto);
    Thread.sleep(1000);
    eventSimulatorAdminServiceClient.sendEvent(eventDto2);
    Thread.sleep(1000);
    eventSimulatorAdminServiceClient.sendEvent(eventDto3);

    try {
        boolean mappingPortionFound = false;
        Thread.sleep(2000);
        LogEvent[] logs = logViewerClient.getAllRemoteSystemLogs();
        for (int i = 0; i < (logs.length - beforeCount); i++) {
            if (logs[i].getMessage().contains("<SensorData>\n" +
                    "        <equipmentRelatedData>\n" +
                    "          <timestamp>199008131245</timestamp>\n" +
                    "          <isPowerSaverEnabled>false</isPowerSaverEnabled>\n" +
                    "          <sensorId>503</sensorId>\n" +
                    "          <sensorName>temperature</sensorName>\n" +
                    "        </equipmentRelatedData>\n" +
                    "        <locationData>\n" +
                    "          <longitude>23.45656</longitude>\n" +
                    "          <latitude>7.12324</latitude>\n" +
                    "        </locationData>\n" +
                    "        <sensorData>\n" +
                    "          <humidity>100.34</humidity>\n" +
                    "          <sensorValue>23.4545</sensorValue>\n" +
                    "        </sensorData>\n" +
                    "      </SensorData>")) {
                mappingPortionFound = true;
                break;
            }
        }
        Assert.assertTrue(mappingPortionFound, "Incorrect mapping has occurred! ");
        Thread.sleep(2000);
    } catch (Throwable e) {
        log.error("Exception thrown: " + e.getMessage(), e);
        Assert.fail("Exception: " + e.getMessage());
    }

    eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0");
    eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("logger.xml");

    Thread.sleep(2000);

}
 
Example #8
Source File: CustomMappingTestCase.java    From product-cep with Apache License 2.0 4 votes vote down vote up
private void executeArbitraryMappingTest(String loggerName, String expectedOutput) throws Exception {
    int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount();

    //Add Logger
    String eventPublisherConfig = getXMLArtifactConfiguration(samplePath, loggerName);
    eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig);
    Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1);

    EventDto eventDto = new EventDto();
    eventDto.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
    eventDto.setAttributeValues(new String[]{"199008131245", "false", "203", "temperature", "23.45656", "7.12324",
            "100.34", "23.4545"});

    EventDto eventDto2 = new EventDto();
    eventDto2.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
    eventDto2.setAttributeValues(new String[]{"199008131245", "false", "203", "temperature", "23.45656", "7.12324",
            "100.34", "23.4545"});

    EventDto eventDto3 = new EventDto();
    eventDto3.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
    eventDto3.setAttributeValues(new String[]{"199008131245", "false", "203", "temperature", "23.45656", "7.12324",
            "100.34", "23.4545"});

    int beforeCount = logViewerClient.getAllRemoteSystemLogs().length;
    eventSimulatorAdminServiceClient.sendEvent(eventDto);
    Thread.sleep(1000);
    eventSimulatorAdminServiceClient.sendEvent(eventDto2);
    Thread.sleep(1000);
    eventSimulatorAdminServiceClient.sendEvent(eventDto3);
    Thread.sleep(1000);
    try {
        boolean mappingPortionFound = false;
        Thread.sleep(2000);
        LogEvent[] logs = logViewerClient.getAllRemoteSystemLogs();
        for (int i = 0; i < (logs.length - beforeCount); i++) {
            System.out.println(logs[i].getMessage());
            if (logs[i].getMessage().contains(expectedOutput)) {
                mappingPortionFound = true;
                break;
            }
        }
        Assert.assertTrue(mappingPortionFound, "Incorrect mapping has occurred! ");
        Thread.sleep(2000);
    } catch (Throwable e) {
        log.error("Exception thrown: " + e.getMessage(), e);
        Assert.fail("Exception: " + e.getMessage());
    }

    eventPublisherAdminServiceClient.removeActiveEventPublisherConfiguration("logger");

    Thread.sleep(2000);
}
 
Example #9
Source File: LogViewerClient.java    From product-es with Apache License 2.0 3 votes vote down vote up
/**
 * Getting system logs
 *
 * @param logType   Log type (INFO,WARN,ERROR,DEBUG)
 * @param searchKey searching keyword
 * @param domain    - tenant domain
 * @param serverKey - server key defined at carbon.xml
 * @return logMessage array
 * @throws RemoteException Exception
 */
public LogEvent[] getLogs(String logType, String searchKey, String domain, String serverKey)
        throws RemoteException, LogViewerLogViewerException {
    try {
        return logViewerStub.getLogs(logType, searchKey, domain, serverKey);
    } catch (LogViewerLogViewerException e) {
        log.error("Unable to get system logs", e);
        throw new LogViewerLogViewerException("Unable to get system logs", e);
    }
}