Search in sources :

Example 1 with Stat

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;
}
Also used : Stat(com.emc.storageos.db.client.model.Stat) ArrayList(java.util.ArrayList) URI(java.net.URI)

Example 2 with Stat

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);
}
Also used : Stat(com.emc.storageos.db.client.model.Stat) URISyntaxException(java.net.URISyntaxException) StatMarshaller(com.emc.storageos.api.service.impl.resource.utils.StatMarshaller) URISyntaxException(java.net.URISyntaxException)

Example 3 with Stat

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);
}
Also used : Stat(com.emc.storageos.db.client.model.Stat) 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) JSONStatMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONStatMarshaller) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 4 with Stat

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);
}
Also used : Stat(com.emc.storageos.db.client.model.Stat) OutputStream(java.io.OutputStream) FileWriter(java.io.FileWriter) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) AnnotationIntrospector(org.codehaus.jackson.map.AnnotationIntrospector) JSONStatMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONStatMarshaller) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 5 with Stat

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);
}
Also used : Stat(com.emc.storageos.db.client.model.Stat) OutputStream(java.io.OutputStream) URI(java.net.URI) XMLStatMarshaller(com.emc.storageos.api.service.impl.resource.utils.XMLStatMarshaller) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

Stat (com.emc.storageos.db.client.model.Stat)40 List (java.util.List)14 DbClient (com.emc.storageos.db.client.DbClient)13 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)12 URI (java.net.URI)12 AccessProfile (com.emc.storageos.plugins.AccessProfile)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)6 SMIPluginException (com.emc.storageos.plugins.metering.smis.SMIPluginException)6 PrintWriter (java.io.PrintWriter)6 FileShare (com.emc.storageos.db.client.model.FileShare)5 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)5 IOException (java.io.IOException)5 OutputStream (java.io.OutputStream)5 CIMInstance (javax.cim.CIMInstance)5 ResponsePacket (com.emc.nas.vnxfile.xmlapi.ResponsePacket)4 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)4 File (java.io.File)4