Search in sources :

Example 1 with JSONEventMarshaller

use of com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller in project coprhd-controller by CoprHD.

the class DummyEventRetriever method getBulkEvents.

@Override
public void getBulkEvents(DateTime time, TimeSeriesMetadata.TimeBucket bucket, MediaType type, Writer writer) throws MarshallingExcetion {
    EventMarshaller marshaller = null;
    if (type == MediaType.APPLICATION_XML_TYPE) {
        marshaller = new XMLEventMarshaller();
    } else if (type == MediaType.APPLICATION_JSON_TYPE) {
        marshaller = new JSONEventMarshaller();
    }
    marshaller.header(writer);
    List<Event> events = null;
    try {
        events = getDummyEvents();
    } catch (URISyntaxException e) {
        _logger.error("Error getting events", e);
    }
    for (Event event : events) {
        if (type == MediaType.APPLICATION_XML_TYPE) {
            marshaller.marshal(event, writer);
        } else if (type == MediaType.APPLICATION_JSON_TYPE) {
            marshaller.marshal(event, writer);
        }
    }
    marshaller.tailer(writer);
}
Also used : XMLEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller) JSONEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller) Event(com.emc.storageos.db.client.model.Event) JSONEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller) XMLEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller) EventMarshaller(com.emc.storageos.api.service.impl.resource.utils.EventMarshaller) URISyntaxException(java.net.URISyntaxException)

Example 2 with JSONEventMarshaller

use of com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller in project coprhd-controller by CoprHD.

the class JSONEventMarchallerTest method testJsonEventMarshalling.

@Test
public void testJsonEventMarshalling() throws URISyntaxException, IOException, MarshallingExcetion {
    deleteIfExists(JsonTestOutputFile);
    JSONEventMarshaller jm = new JSONEventMarshaller();
    Event e = new Event();
    e.setEventId("eid1");
    e.setTenantId(new URI("http://tenant.1"));
    OutputStream output = new OutputStream() {

        private StringBuilder string = new StringBuilder();

        @Override
        public void write(int b) throws IOException {
            this.string.append((char) b);
        }

        public String toString() {
            return this.string.toString();
        }
    };
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output));
    jm.marshal(e, writer);
    writer.close();
    FileWriter fileWriter = new FileWriter(JsonTestOutputFile);
    fileWriter.write(output.toString());
    fileWriter.close();
    ObjectMapper mapper = null;
    mapper = new ObjectMapper();
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
    mapper.getDeserializationConfig().withAnnotationIntrospector(introspector);
    Event event = mapper.readValue(new File(JsonTestOutputFile), Event.class);
    Assert.assertEquals("eid1", event.getEventId().toString());
    Assert.assertEquals("http://tenant.1", event.getTenantId().toString());
    deleteIfExists(JsonTestOutputFile);
}
Also used : JSONEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller) OutputStream(java.io.OutputStream) FileWriter(java.io.FileWriter) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) AnnotationIntrospector(org.codehaus.jackson.map.AnnotationIntrospector) Event(com.emc.storageos.db.client.model.Event) OutputStreamWriter(java.io.OutputStreamWriter) URI(java.net.URI) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 3 with JSONEventMarshaller

use of com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller in project coprhd-controller by CoprHD.

the class JSONEventMarchallerTest method testJsonEventMarshallingForIOExceptions.

@Test
public void testJsonEventMarshallingForIOExceptions() throws URISyntaxException, IOException, MarshallingExcetion {
    deleteIfExists(JsonTestOutputFile);
    JSONEventMarshaller jm = new JSONEventMarshaller();
    Event evt = new Event();
    evt.setEventId("eid1");
    evt.setTenantId(new URI("http://tenant.1"));
    OutputStream output = new OutputStream() {

        private StringBuilder string = new StringBuilder();

        @Override
        public void write(int b) throws IOException {
            this.string.append((char) b);
        }

        public String toString() {
            return this.string.toString();
        }
    };
    try {
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output));
        writer.close();
        jm.header(writer);
    } catch (MarshallingExcetion e) {
        Assert.assertTrue(e.toString().contains("JSON head Streaming failed"));
    }
    try {
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output));
        writer.close();
        jm.marshal(evt, writer);
    } catch (MarshallingExcetion e) {
        Assert.assertTrue(e.toString().contains("JSON streaming failed"));
    }
    try {
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output));
        writer.close();
        jm.tailer(writer);
    } catch (MarshallingExcetion e) {
        Assert.assertTrue(e.toString().contains("JSON tail Streaming failed"));
    }
    deleteIfExists(JsonTestOutputFile);
}
Also used : MarshallingExcetion(com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion) JSONEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller) OutputStream(java.io.OutputStream) Event(com.emc.storageos.db.client.model.Event) OutputStreamWriter(java.io.OutputStreamWriter) URI(java.net.URI) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 4 with JSONEventMarshaller

use of com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller in project coprhd-controller by CoprHD.

the class JSONEventMarchallerTest method testJsonEventMarshallingForNullEvent.

@Test
public void testJsonEventMarshallingForNullEvent() throws URISyntaxException, IOException, MarshallingExcetion {
    deleteIfExists(JsonTestOutputFile);
    JSONEventMarshaller jm = new JSONEventMarshaller();
    Event evt = null;
    OutputStream output = new OutputStream() {

        private StringBuilder string = new StringBuilder();

        @Override
        public void write(int b) throws IOException {
            this.string.append((char) b);
        }

        public String toString() {
            return this.string.toString();
        }
    };
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output));
    jm.header(writer);
    jm.marshal(evt, writer);
    jm.tailer(writer);
    writer.close();
    FileWriter fileWriter = new FileWriter(JsonTestOutputFile);
    fileWriter.write(output.toString());
    fileWriter.close();
    ObjectMapper mapper = null;
    mapper = new ObjectMapper();
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
    mapper.getDeserializationConfig().withAnnotationIntrospector(introspector);
    try {
        @SuppressWarnings("unused") Event event = mapper.readValue(new File(JsonTestOutputFile), Event.class);
    } catch (UnrecognizedPropertyException e) {
        Assert.assertTrue(e.toString().contains("Unrecognized"));
    }
    deleteIfExists(JsonTestOutputFile);
}
Also used : JSONEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller) OutputStream(java.io.OutputStream) FileWriter(java.io.FileWriter) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) AnnotationIntrospector(org.codehaus.jackson.map.AnnotationIntrospector) UnrecognizedPropertyException(org.codehaus.jackson.map.exc.UnrecognizedPropertyException) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) BufferedWriter(java.io.BufferedWriter) Event(com.emc.storageos.db.client.model.Event) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 5 with JSONEventMarshaller

use of com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller in project coprhd-controller by CoprHD.

the class DbEventRetriever method getBulkEvents.

@Override
public void getBulkEvents(DateTime time, TimeSeriesMetadata.TimeBucket bucket, MediaType type, Writer writer) throws MarshallingExcetion {
    if (dbClient == null) {
        throw APIException.internalServerErrors.noDBClient();
    }
    EventMarshaller marshaller = null;
    if (type.equals(MediaType.APPLICATION_XML_TYPE)) {
        marshaller = new XMLEventMarshaller();
        log.debug("Parser type: {}", type.toString());
    } else if (type.equals(MediaType.APPLICATION_JSON_TYPE)) {
        marshaller = new JSONEventMarshaller();
        log.debug("Parser type: {}", type.toString());
    } else {
        log.warn("unsupported type: {}, use XML", type.toString());
        marshaller = new XMLEventMarshaller();
    }
    MonitoringEventQueryResult result = new MonitoringEventQueryResult(marshaller, writer);
    marshaller.header(writer);
    log.info("Query time bucket {}", time.toString());
    dbClient.queryTimeSeries(EventTimeSeries.class, time, bucket, result, getThreadPool());
    marshaller.tailer(writer);
}
Also used : MonitoringEventQueryResult(com.emc.storageos.api.service.impl.resource.utils.MonitoringEventQueryResult) XMLEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller) JSONEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller) JSONEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller) XMLEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller)

Aggregations

JSONEventMarshaller (com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller)5 Event (com.emc.storageos.db.client.model.Event)4 BufferedWriter (java.io.BufferedWriter)3 OutputStream (java.io.OutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 Test (org.junit.Test)3 XMLEventMarshaller (com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller)2 File (java.io.File)2 FileWriter (java.io.FileWriter)2 URI (java.net.URI)2 AnnotationIntrospector (org.codehaus.jackson.map.AnnotationIntrospector)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 JaxbAnnotationIntrospector (org.codehaus.jackson.xc.JaxbAnnotationIntrospector)2 EventMarshaller (com.emc.storageos.api.service.impl.resource.utils.EventMarshaller)1 MarshallingExcetion (com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion)1 MonitoringEventQueryResult (com.emc.storageos.api.service.impl.resource.utils.MonitoringEventQueryResult)1 URISyntaxException (java.net.URISyntaxException)1 UnrecognizedPropertyException (org.codehaus.jackson.map.exc.UnrecognizedPropertyException)1