Search in sources :

Example 11 with Event

use of com.emc.storageos.db.client.model.Event 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 12 with Event

use of com.emc.storageos.db.client.model.Event 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 13 with Event

use of com.emc.storageos.db.client.model.Event 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 14 with Event

use of com.emc.storageos.db.client.model.Event in project coprhd-controller by CoprHD.

the class DummyDBClient method queryTimeSeries.

@Override
public <T extends DataPoint> void queryTimeSeries(Class<? extends TimeSeries> tsType, DateTime timeBucket, TimeBucket bucket, TimeSeriesQueryResult<T> callback, ExecutorService workerThreads) throws DatabaseException {
    if (timeBucket != null) {
        MicrosecondsClock clock = new MicrosecondsClock();
        UUID uuid = TimeUUIDUtils.getTimeUUID(clock);
        // For timeBucket 2012-01-04T00:00 we return 10 events
        if (timeBucket.toString().contains("2012-01-01T00:00")) {
            try {
                for (int i = 0; i < 10; i++) {
                    Stat st = new Stat();
                    st.setProject(new URI("http://project" + i));
                    st.setTenant(new URI("http://t." + i));
                    st.setUser(new URI("http://u." + i));
                    st.setVirtualPool(new URI("http://vpool.gold" + i));
                    callback.data((T) st, TimeUUIDUtils.getTimeFromUUID(uuid));
                }
            } catch (URISyntaxException e) {
                _logger.error(e.getMessage(), e);
            }
            callback.done();
        } else if (timeBucket.toString().contains("2012-01-02T00:00")) {
            throw DatabaseException.retryables.dummyClientFailed();
        } else if (timeBucket.toString().contains("2012-01-03T00:00")) {
            callback.error(null);
        } else if (timeBucket.toString().contains("2012-01-04T00:00")) {
            try {
                // TODO Auto-generated method stub
                for (int i = 0; i < 10; i++) {
                    Event evt = new Event();
                    evt.setProjectId(new URI("http://project" + i));
                    evt.setEventId(String.valueOf(i));
                    evt.setTenantId(new URI("http://t." + i));
                    evt.setUserId(new URI("http://u." + i));
                    evt.setVirtualPool(new URI("http://vpool.gold" + i));
                    callback.data((T) evt, TimeUUIDUtils.getTimeFromUUID(uuid));
                }
            } catch (URISyntaxException e) {
                _logger.error(e.getMessage(), e);
            }
            callback.done();
        } else if (timeBucket.toString().contains("2012-01-05T00:00")) {
            try {
                throw new MarshallingExcetion("marshalling Exception", null);
            } catch (MarshallingExcetion e) {
                _logger.error(e.getMessage(), e);
            }
        } else if (timeBucket.toString().contains("2012-01-06T00:00")) {
            callback.error(null);
        } else if (timeBucket.toString().contains("2012-01-07T00:00")) {
            try {
                // TODO Auto-generated method stub
                for (int i = 0; i < 10; i++) {
                    AuditLog log = new AuditLog();
                    log.setProductId("productId." + i);
                    log.setTenantId(new URI("http://tenant." + i));
                    log.setUserId(new URI("http://user." + i));
                    log.setServiceType("serviceType" + i);
                    log.setAuditType("auditType" + i);
                    log.setDescription("description" + i);
                    callback.data((T) log, TimeUUIDUtils.getTimeFromUUID(uuid));
                }
            } catch (URISyntaxException e) {
                _logger.error(e.getMessage(), e);
            }
            callback.done();
        } else if (timeBucket.toString().contains("2012-01-08T00:00")) {
            try {
                throw new MarshallingExcetion("marshalling Exception", null);
            } catch (MarshallingExcetion e) {
                _logger.error(e.getMessage(), e);
            }
        }
    }
}
Also used : MarshallingExcetion(com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion) Stat(com.emc.storageos.db.client.model.Stat) MicrosecondsClock(com.netflix.astyanax.clock.MicrosecondsClock) Event(com.emc.storageos.db.client.model.Event) URISyntaxException(java.net.URISyntaxException) UUID(java.util.UUID) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Constraint(com.emc.storageos.db.client.constraint.Constraint) DataPoint(com.emc.storageos.db.client.model.TimeSeriesSerializer.DataPoint) AuditLog(com.emc.storageos.db.client.model.AuditLog)

Aggregations

Event (com.emc.storageos.db.client.model.Event)14 Test (org.junit.Test)9 BufferedWriter (java.io.BufferedWriter)7 OutputStream (java.io.OutputStream)7 OutputStreamWriter (java.io.OutputStreamWriter)7 URI (java.net.URI)6 XMLEventMarshaller (com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller)5 File (java.io.File)5 JSONEventMarshaller (com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller)4 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)4 MarshallingExcetion (com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion)3 Constraint (com.emc.storageos.db.client.constraint.Constraint)3 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)3 FileWriter (java.io.FileWriter)3 JAXBContext (javax.xml.bind.JAXBContext)3 Unmarshaller (javax.xml.bind.Unmarshaller)3 DbClient (com.emc.storageos.db.client.DbClient)2 AggregatedConstraint (com.emc.storageos.db.client.constraint.AggregatedConstraint)2 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)2