Search in sources :

Example 1 with MarshallingExcetion

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

the class JSONAuditLogMarchallerTest method testJsonAuditLogMarshallingForIOExceptions.

@Test
public void testJsonAuditLogMarshallingForIOExceptions() throws URISyntaxException, IOException, MarshallingExcetion {
    deleteIfExists(JsonTestOutputFile);
    JSONAuditLogMarshaller jm = new JSONAuditLogMarshaller();
    AuditLog log = new AuditLog();
    log.setProductId("productId.2");
    log.setTenantId(new URI("http://tenant.2"));
    log.setUserId(new URI("http://user.2"));
    log.setServiceType("serviceType.2");
    log.setAuditType("auditType.2");
    log.setDescription("description.2");
    log.setOperationalStatus("operationalStatus.2");
    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(log, 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) JSONAuditLogMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONAuditLogMarshaller) OutputStream(java.io.OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) URI(java.net.URI) AuditLog(com.emc.storageos.db.client.model.AuditLog) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 2 with MarshallingExcetion

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

the class DbAuditLogRetrieverTest method auditServiceDBExceptionsTestJSON.

@Test
public void auditServiceDBExceptionsTestJSON() throws WebApplicationException, IOException, JAXBException {
    deleteIfExists(JsonTestOutputFile);
    DummyDBClient dbClient = new DummyDBClient();
    DbAuditLogRetriever dummyDbAuditLogRetriever = new DbAuditLogRetriever();
    dummyDbAuditLogRetriever.setDbClient(dbClient);
    String timeBucket = "2012-01-07T00";
    DateTime startTime = new DateTime(timeBucket, DateTimeZone.UTC);
    DateTime endTime = startTime.plusMinutes(59);
    AuditLogRequest auditLogRequest = new AuditLogRequest.Builder().timeBucket(timeBucket).start(startTime).end(endTime).lang("en_US").build();
    MediaType mediaType = MediaType.APPLICATION_JSON_TYPE;
    File of = new File(JsonTestOutputFile);
    OutputStream os = new FileOutputStream(of);
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(os));
    try {
        dummyDbAuditLogRetriever.getBulkAuditLogs(auditLogRequest, mediaType, out);
    } catch (MarshallingExcetion e) {
        Assert.fail(e.getMessage());
    }
    out.close();
    ObjectMapper mapper = null;
    mapper = new ObjectMapper();
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
    mapper.getDeserializationConfig().withAnnotationIntrospector(introspector);
    AuditLogs auditLogs = mapper.readValue(new File(JsonTestOutputFile), AuditLogs.class);
    Assert.assertEquals(10, auditLogs.auditLogs.size());
    deleteIfExists(JsonTestOutputFile);
}
Also used : AuditLogs(com.emc.storageos.api.service.utils.AuditLogs) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) AnnotationIntrospector(org.codehaus.jackson.map.AnnotationIntrospector) DummyDBClient(com.emc.storageos.api.service.utils.DummyDBClient) DateTime(org.joda.time.DateTime) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) MarshallingExcetion(com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion) DbAuditLogRetriever(com.emc.storageos.api.service.impl.resource.utils.DbAuditLogRetriever) MediaType(javax.ws.rs.core.MediaType) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) AuditLogRequest(com.emc.storageos.security.audit.AuditLogRequest) Test(org.junit.Test)

Example 3 with MarshallingExcetion

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

the class DbAuditLogRetrieverTest method auditServiceMarshallingExceptionsTestXML.

@Test
public void auditServiceMarshallingExceptionsTestXML() throws WebApplicationException, IOException, JAXBException {
    deleteIfExists(XmlTestOutputFile);
    DummyDBClient dbClient = new DummyDBClient();
    DbAuditLogRetriever dummyDbAuditLogRetriever = new DbAuditLogRetriever();
    dummyDbAuditLogRetriever.setDbClient(dbClient);
    String timeBucket = "2012-01-08T00";
    AuditLogRequest auditLogRequest = getAuditLogRequest(timeBucket);
    MediaType mediaType = MediaType.APPLICATION_XML_TYPE;
    File of = new File(XmlTestOutputFile);
    OutputStream os = new FileOutputStream(of);
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(os));
    try {
        dummyDbAuditLogRetriever.getBulkAuditLogs(auditLogRequest, mediaType, out);
    } catch (MarshallingExcetion e) {
        Assert.assertTrue(true);
    }
    out.close();
}
Also used : MarshallingExcetion(com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion) DbAuditLogRetriever(com.emc.storageos.api.service.impl.resource.utils.DbAuditLogRetriever) MediaType(javax.ws.rs.core.MediaType) DummyDBClient(com.emc.storageos.api.service.utils.DummyDBClient) AuditLogRequest(com.emc.storageos.security.audit.AuditLogRequest) Test(org.junit.Test)

Example 4 with MarshallingExcetion

use of com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion 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)

Example 5 with MarshallingExcetion

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

the class DbAuditLogRetrieverTest method auditServiceDBRetrieverTestXML.

@Test
public void auditServiceDBRetrieverTestXML() throws WebApplicationException, IOException, JAXBException {
    deleteIfExists(XmlTestOutputFile);
    DummyDBClient dbClient = new DummyDBClient();
    DbAuditLogRetriever dummyDbAuditLogRetriever = new DbAuditLogRetriever();
    dummyDbAuditLogRetriever.setDbClient(dbClient);
    String timeBucket = "2012-01-07T00";
    AuditLogRequest auditLogRequest = getAuditLogRequest(timeBucket);
    MediaType mediaType = MediaType.APPLICATION_XML_TYPE;
    File of = new File(XmlTestOutputFile);
    OutputStream os = new FileOutputStream(of);
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(os));
    try {
        dummyDbAuditLogRetriever.getBulkAuditLogs(auditLogRequest, mediaType, out);
    } catch (MarshallingExcetion e) {
        Assert.fail(e.getMessage());
    }
    out.close();
    JAXBContext context = null;
    Unmarshaller unmarshaller = null;
    context = JAXBContext.newInstance(AuditLogs.class);
    unmarshaller = context.createUnmarshaller();
    Object o = unmarshaller.unmarshal(new File(XmlTestOutputFile));
    Assert.assertTrue(o instanceof AuditLogs);
    AuditLogs auditLogs = (AuditLogs) o;
    // expected number of events unmarshaled
    Assert.assertEquals(10, auditLogs.auditLogs.size());
    deleteIfExists(XmlTestOutputFile);
}
Also used : AuditLogs(com.emc.storageos.api.service.utils.AuditLogs) JAXBContext(javax.xml.bind.JAXBContext) DummyDBClient(com.emc.storageos.api.service.utils.DummyDBClient) MarshallingExcetion(com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion) DbAuditLogRetriever(com.emc.storageos.api.service.impl.resource.utils.DbAuditLogRetriever) MediaType(javax.ws.rs.core.MediaType) Unmarshaller(javax.xml.bind.Unmarshaller) AuditLogRequest(com.emc.storageos.security.audit.AuditLogRequest) Test(org.junit.Test)

Aggregations

MarshallingExcetion (com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion)9 Test (org.junit.Test)8 URI (java.net.URI)5 DbAuditLogRetriever (com.emc.storageos.api.service.impl.resource.utils.DbAuditLogRetriever)4 DummyDBClient (com.emc.storageos.api.service.utils.DummyDBClient)4 AuditLogRequest (com.emc.storageos.security.audit.AuditLogRequest)4 BufferedWriter (java.io.BufferedWriter)4 OutputStream (java.io.OutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 MediaType (javax.ws.rs.core.MediaType)4 AuditLog (com.emc.storageos.db.client.model.AuditLog)3 Event (com.emc.storageos.db.client.model.Event)3 AuditLogs (com.emc.storageos.api.service.utils.AuditLogs)2 JSONAuditLogMarshaller (com.emc.storageos.api.service.impl.resource.utils.JSONAuditLogMarshaller)1 JSONEventMarshaller (com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller)1 XMLAuditLogMarshaller (com.emc.storageos.api.service.impl.resource.utils.XMLAuditLogMarshaller)1 XMLEventMarshaller (com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller)1 Constraint (com.emc.storageos.db.client.constraint.Constraint)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 Stat (com.emc.storageos.db.client.model.Stat)1