Search in sources :

Example 6 with AuditLog

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

the class DummyAuditLogRetriever method getDummyAuditLogs.

private List<AuditLog> getDummyAuditLogs() throws URISyntaxException {
    // @TODO - dummy logs at the moment.
    List<AuditLog> loglist = new ArrayList<AuditLog>();
    for (int i = 0; i < 100; i++) {
        AuditLog log = new AuditLog();
        log.setProductId("productId." + String.valueOf(i));
        log.setTenantId(new URI("http://tenant." + String.valueOf(i)));
        log.setUserId(new URI("http://user." + String.valueOf(i)));
        log.setServiceType("serviceType." + String.valueOf(i));
        log.setAuditType("auditType." + String.valueOf(i));
        log.setDescription("description." + String.valueOf(i));
        log.setOperationalStatus("operationalStatus." + String.valueOf(i));
        loglist.add(log);
    }
    return loglist;
}
Also used : ArrayList(java.util.ArrayList) URI(java.net.URI) AuditLog(com.emc.storageos.db.client.model.AuditLog)

Example 7 with AuditLog

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

the class DummyAuditLogRetriever method getBulkAuditLogs.

@Override
public void getBulkAuditLogs(AuditLogRequest auditLogRequest, MediaType type, Writer writer) throws MarshallingExcetion {
    AuditLogMarshaller marshaller = null;
    if (type == MediaType.APPLICATION_XML_TYPE) {
        marshaller = new XMLAuditLogMarshaller();
    } else if (type == MediaType.APPLICATION_JSON_TYPE) {
        marshaller = new JSONAuditLogMarshaller();
    }
    marshaller.header(writer);
    List<AuditLog> auditLogs = null;
    try {
        auditLogs = getDummyAuditLogs();
    } catch (URISyntaxException e) {
        _logger.error("Error getting logs", e);
    }
    for (AuditLog log : auditLogs) {
        if (type == MediaType.APPLICATION_XML_TYPE) {
            marshaller.marshal(log, writer);
        } else if (type == MediaType.APPLICATION_JSON_TYPE) {
            marshaller.marshal(log, writer);
        }
    }
    marshaller.tailer(writer);
}
Also used : JSONAuditLogMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONAuditLogMarshaller) JSONAuditLogMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONAuditLogMarshaller) XMLAuditLogMarshaller(com.emc.storageos.api.service.impl.resource.utils.XMLAuditLogMarshaller) AuditLogMarshaller(com.emc.storageos.api.service.impl.resource.utils.AuditLogMarshaller) URISyntaxException(java.net.URISyntaxException) XMLAuditLogMarshaller(com.emc.storageos.api.service.impl.resource.utils.XMLAuditLogMarshaller) AuditLog(com.emc.storageos.db.client.model.AuditLog)

Example 8 with AuditLog

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

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

the class XMLAuditLogMarshallerTest method testXmlAuditLogMarshallingForNullLog.

@Test
public void testXmlAuditLogMarshallingForNullLog() throws URISyntaxException, IOException, MarshallingExcetion, JAXBException {
    deleteIfExists(XmlTestOutputFile);
    XMLAuditLogMarshaller jm = new XMLAuditLogMarshaller();
    AuditLog log = 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(log, writer);
    jm.tailer(writer);
    writer.close();
    JAXBContext context = null;
    Unmarshaller unmarshaller = null;
    context = JAXBContext.newInstance(AuditLog.class);
    unmarshaller = context.createUnmarshaller();
    File f = new File(XmlTestOutputFile);
    try {
        @SuppressWarnings("unused") AuditLog auditLog = (AuditLog) unmarshaller.unmarshal(f);
    } catch (Exception e) {
        Assert.assertTrue(e.toString().contains("java.io.FileNotFoundException"));
    }
    deleteIfExists(XmlTestOutputFile);
}
Also used : OutputStream(java.io.OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) XMLAuditLogMarshaller(com.emc.storageos.api.service.impl.resource.utils.XMLAuditLogMarshaller) File(java.io.File) AuditLog(com.emc.storageos.db.client.model.AuditLog) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 10 with AuditLog

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

the class XMLAuditLogMarshallerTest method testXmlAuditLogMarshallingForIOExceptions.

@Test
public void testXmlAuditLogMarshallingForIOExceptions() throws URISyntaxException, IOException, MarshallingExcetion {
    deleteIfExists(XmlTestOutputFile);
    XMLAuditLogMarshaller jm = new XMLAuditLogMarshaller();
    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("XML 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("XML Streaming Error"));
    }
    try {
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output));
        writer.close();
        jm.tailer(writer);
    } catch (MarshallingExcetion e) {
        Assert.assertTrue(e.toString().contains("XML tail Streaming failed"));
    }
    deleteIfExists(XmlTestOutputFile);
}
Also used : MarshallingExcetion(com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion) OutputStream(java.io.OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) XMLAuditLogMarshaller(com.emc.storageos.api.service.impl.resource.utils.XMLAuditLogMarshaller) URI(java.net.URI) AuditLog(com.emc.storageos.db.client.model.AuditLog) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Aggregations

AuditLog (com.emc.storageos.db.client.model.AuditLog)10 BufferedWriter (java.io.BufferedWriter)6 OutputStream (java.io.OutputStream)6 OutputStreamWriter (java.io.OutputStreamWriter)6 URI (java.net.URI)6 Test (org.junit.Test)6 JSONAuditLogMarshaller (com.emc.storageos.api.service.impl.resource.utils.JSONAuditLogMarshaller)4 XMLAuditLogMarshaller (com.emc.storageos.api.service.impl.resource.utils.XMLAuditLogMarshaller)4 File (java.io.File)4 MarshallingExcetion (com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion)3 FileWriter (java.io.FileWriter)3 URISyntaxException (java.net.URISyntaxException)3 JAXBContext (javax.xml.bind.JAXBContext)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 AnnotationIntrospector (org.codehaus.jackson.map.AnnotationIntrospector)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 JaxbAnnotationIntrospector (org.codehaus.jackson.xc.JaxbAnnotationIntrospector)2 AuditLogMarshaller (com.emc.storageos.api.service.impl.resource.utils.AuditLogMarshaller)1 Constraint (com.emc.storageos.db.client.constraint.Constraint)1 Event (com.emc.storageos.db.client.model.Event)1