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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations