use of com.emc.storageos.db.client.model.Stat in project coprhd-controller by CoprHD.
the class DummyStatRetriever method getDummyStats.
private List<Stat> getDummyStats() throws URISyntaxException {
// Creates dummy stats for tests
List<Stat> stlist = new ArrayList<Stat>();
for (int i = 0; i < 100; i++) {
Stat st = new Stat();
st.setProject(new URI("http://mypoject"));
st.setTenant(new URI("http://mytenant"));
st.setUser(new URI("http://myuser"));
st.setVirtualPool(new URI("http://vpool.gold"));
st.setResourceId(new URI("http://resourceId"));
stlist.add(st);
}
return stlist;
}
use of com.emc.storageos.db.client.model.Stat in project coprhd-controller by CoprHD.
the class DummyStatRetriever method getBulkStats.
@Override
public void getBulkStats(DateTime timeBucket, TimeBucket granularity, MediaType mediaType, PrintWriter out) throws MarshallingExcetion {
StatMarshaller marshaller = StatMarshallerFactory.getMarshaller(mediaType);
marshaller.header(out);
List<Stat> stats = null;
try {
stats = getDummyStats();
} catch (URISyntaxException e) {
_logger.error("Error getting stats", e);
}
for (Stat stat : stats) {
if (mediaType == MediaType.APPLICATION_XML_TYPE) {
try {
marshaller.marshall(stat, out);
} catch (Exception e) {
_logger.error(e.getMessage(), e);
}
} else if (mediaType == MediaType.APPLICATION_JSON_TYPE) {
try {
marshaller.marshall(stat, out);
} catch (Exception e) {
_logger.error(e.getMessage(), e);
}
}
}
marshaller.tailer(out);
}
use of com.emc.storageos.db.client.model.Stat in project coprhd-controller by CoprHD.
the class JSONStatMarshallerTest method testJsonStatMarshallingForNullEvent.
@Test
public void testJsonStatMarshallingForNullEvent() throws URISyntaxException, IOException, MarshallingExcetion {
deleteIfExists(JsonTestOutputFile);
JSONStatMarshaller jm = new JSONStatMarshaller();
Stat st = 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();
}
};
PrintWriter writer = new PrintWriter(output);
jm.header(writer);
jm.marshall(st, 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") Stat stat = mapper.readValue(new File(JsonTestOutputFile), Stat.class);
} catch (UnrecognizedPropertyException e) {
Assert.assertTrue(e.toString().contains("Unrecognized"));
}
deleteIfExists(JsonTestOutputFile);
}
use of com.emc.storageos.db.client.model.Stat in project coprhd-controller by CoprHD.
the class JSONStatMarshallerTest method testJsonStatMarshalling.
@Test
public void testJsonStatMarshalling() throws JsonParseException, JsonMappingException, IOException {
deleteIfExists(JsonTestOutputFile);
JSONStatMarshaller jMarshaller = new JSONStatMarshaller();
Stat st = new Stat();
long smbSize = 10000000;
st.setSmdSize(smbSize);
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();
}
};
PrintWriter writer = new PrintWriter(output);
jMarshaller.marshall(st, 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);
Stat stat = mapper.readValue(new File(JsonTestOutputFile), Stat.class);
Assert.assertEquals("10000000", stat.getSmdSize().toString());
deleteIfExists(JsonTestOutputFile);
}
use of com.emc.storageos.db.client.model.Stat in project coprhd-controller by CoprHD.
the class XMLStatMarshallerTest method testXmlStatMarshallingForError.
@Test
public void testXmlStatMarshallingForError() throws URISyntaxException, IOException, MarshallingExcetion {
deleteIfExists(XmlTestOutputFile);
XMLStatMarshaller xm = new XMLStatMarshaller();
Stat stat = new Stat();
stat.setTenant(new URI("http://tenant.1"));
stat.setTenant(new URI("http://project.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();
}
};
PrintWriter writer = new PrintWriter(output);
String error = "someerror";
xm.error(writer, error);
writer.close();
Assert.assertTrue(output.toString().contains("<stats>" + "someerror" + "</stats>"));
deleteIfExists(XmlTestOutputFile);
}
Aggregations