Search in sources :

Example 1 with AuditLog

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

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

the class JSONAuditLogMarchallerTest method testJsonAuditLogMarshallingForNullLog.

@Test
public void testJsonAuditLogMarshallingForNullLog() throws URISyntaxException, IOException, MarshallingExcetion {
    deleteIfExists(JsonTestOutputFile);
    JSONAuditLogMarshaller jm = new JSONAuditLogMarshaller();
    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();
    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") AuditLog auditLog = mapper.readValue(new File(JsonTestOutputFile), AuditLog.class);
    } catch (UnrecognizedPropertyException e) {
        Assert.assertTrue(e.toString().contains("Unrecognized"));
    }
    deleteIfExists(JsonTestOutputFile);
}
Also used : JSONAuditLogMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONAuditLogMarshaller) 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) AuditLog(com.emc.storageos.db.client.model.AuditLog) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) BufferedWriter(java.io.BufferedWriter) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 3 with AuditLog

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

the class JSONAuditLogMarchallerTest method testJsonAuditLogMarshalling.

@Test
public void testJsonAuditLogMarshalling() throws URISyntaxException, IOException, MarshallingExcetion {
    deleteIfExists(JsonTestOutputFile);
    JSONAuditLogMarshaller jm = new JSONAuditLogMarshaller();
    AuditLog log = new AuditLog();
    log.setProductId("productId.1");
    log.setTenantId(new URI("http://tenant.1"));
    log.setUserId(new URI("http://user.1"));
    log.setServiceType("serviceType.1");
    log.setAuditType("auditType.1");
    log.setDescription("description.1");
    log.setOperationalStatus("operationalStatus.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(log, 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);
    AuditLog auditLog = mapper.readValue(new File(JsonTestOutputFile), AuditLog.class);
    Assert.assertEquals("productId.1", auditLog.getProductId().toString());
    Assert.assertEquals("http://tenant.1", auditLog.getTenantId().toString());
    Assert.assertEquals("http://user.1", auditLog.getUserId().toString());
    Assert.assertEquals("serviceType.1", auditLog.getServiceType().toString());
    Assert.assertEquals("auditType.1", auditLog.getAuditType().toString());
    Assert.assertEquals("description.1", auditLog.getDescription().toString());
    Assert.assertEquals("operationalStatus.1", auditLog.getOperationalStatus().toString());
    deleteIfExists(JsonTestOutputFile);
}
Also used : JSONAuditLogMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONAuditLogMarshaller) OutputStream(java.io.OutputStream) FileWriter(java.io.FileWriter) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) AnnotationIntrospector(org.codehaus.jackson.map.AnnotationIntrospector) OutputStreamWriter(java.io.OutputStreamWriter) URI(java.net.URI) File(java.io.File) AuditLog(com.emc.storageos.db.client.model.AuditLog) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 4 with AuditLog

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

the class XMLAuditLogMarshallerTest method testXmlAuditLogMarshalling.

@Test
public void testXmlAuditLogMarshalling() throws URISyntaxException, IOException, MarshallingExcetion, JAXBException {
    XMLAuditLogMarshaller xm = new XMLAuditLogMarshaller();
    AuditLog log = new AuditLog();
    log.setProductId("productId.1");
    log.setTenantId(new URI("http://tenant.1"));
    log.setUserId(new URI("http://user.1"));
    log.setServiceType("serviceType.1");
    log.setAuditType("auditType.1");
    log.setDescription("description.1");
    log.setOperationalStatus("operationalStatus.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));
    xm.marshal(log, writer);
    writer.close();
    FileWriter fileWriter = new FileWriter(XmlTestOutputFile);
    fileWriter.write(output.toString());
    fileWriter.close();
    JAXBContext context = null;
    Unmarshaller unmarshaller = null;
    context = JAXBContext.newInstance(AuditLog.class);
    unmarshaller = context.createUnmarshaller();
    File f = new File(XmlTestOutputFile);
    AuditLog auditLog = (AuditLog) unmarshaller.unmarshal(f);
    Assert.assertEquals("productId.1", auditLog.getProductId().toString());
    Assert.assertEquals("http://tenant.1", auditLog.getTenantId().toString());
    Assert.assertEquals("http://user.1", auditLog.getUserId().toString());
    Assert.assertEquals("serviceType.1", auditLog.getServiceType().toString());
    Assert.assertEquals("auditType.1", auditLog.getAuditType().toString());
    Assert.assertEquals("description.1", auditLog.getDescription().toString());
    Assert.assertEquals("operationalStatus.1", auditLog.getOperationalStatus().toString());
    deleteIfExists(XmlTestOutputFile);
}
Also used : OutputStream(java.io.OutputStream) FileWriter(java.io.FileWriter) OutputStreamWriter(java.io.OutputStreamWriter) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) XMLAuditLogMarshaller(com.emc.storageos.api.service.impl.resource.utils.XMLAuditLogMarshaller) URI(java.net.URI) File(java.io.File) AuditLog(com.emc.storageos.db.client.model.AuditLog) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 5 with AuditLog

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

the class AuditLogManager method recordAuditLogs.

/**
 * Called to record auditlogs in the database.
 *
 * @param events references to recordable auditlogs.
 */
public void recordAuditLogs(RecordableAuditLog... auditlogs) {
    if (!shouldRecordAuditLog()) {
        s_logger.info("Ignore audit log on standby site");
        return;
    }
    AuditLog[] dbAuditLogs = new AuditLog[auditlogs.length];
    int i = 0;
    for (RecordableAuditLog auditlog : auditlogs) {
        AuditLog dbAuditlog = AuditLogUtils.convertToAuditLog(auditlog);
        dbAuditLogs[i++] = dbAuditlog;
        AuditLog auditSyslog = dbAuditlog;
        PropertyInfo propInfo = _coordinator.getPropertyInfo();
        if (propInfo.getProperty(SYSLOG_ENALBE).equalsIgnoreCase("true")) {
            Locale locale = new Locale("en", "US");
            ResourceBundle resb = ResourceBundle.getBundle("SDSAuditlogRes", locale);
            AuditLogUtils.resetDesc(auditSyslog, resb);
            logger.info("audit log is " + dbAuditlog.getServiceType() + " " + dbAuditlog.getUserId() + " " + dbAuditlog.getOperationalStatus() + " " + dbAuditlog.getDescription());
        }
    }
    // Now insert the events into the database.
    try {
        _dbClient.start();
        String bucketId = _dbClient.insertTimeSeries(AuditLogTimeSeries.class, dbAuditLogs);
        s_logger.info("AuditLog(s) persisted into Cassandra with bucketId/rowId : {}", bucketId);
    } catch (DatabaseException e) {
        s_logger.error("Error inserting auditlogs into the database", e);
        throw e;
    }
}
Also used : Locale(java.util.Locale) ResourceBundle(java.util.ResourceBundle) PropertyInfo(com.emc.storageos.model.property.PropertyInfo) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) AuditLog(com.emc.storageos.db.client.model.AuditLog)

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