Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added SLALogging for export

  • Loading branch information...
commit 15f66eee8bb4ff111c8778e6d322bfcc13c8bab4 1 parent f354dc4
@krpiatkowski krpiatkowski authored
View
15 minlog-export/src/main/java/dk/nsi/minlog/export/config/SLALoggerConfig.java
@@ -0,0 +1,15 @@
+package dk.nsi.minlog.export.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import dk.sdsd.nsp.slalog.api.SLALogger;
+import dk.sdsd.nsp.slalog.api.SLALogConfig;
+
+@Configuration
+public class SLALoggerConfig {
+ @Bean
+ public SLALogger slaLogger(){
+ return new SLALogConfig("minlog","minlog").getSLALogger();
+ }
+}
View
1  minlog-export/src/main/java/dk/nsi/minlog/export/config/SplunkConfig.java
@@ -33,6 +33,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
import com.splunk.Service;
View
1  minlog-export/src/main/java/dk/nsi/minlog/export/dao/ebean/StatusDaoEBean.java
@@ -31,7 +31,6 @@
import org.joda.time.DateTime;
import org.springframework.stereotype.Repository;
-import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.avaje.ebean.EbeanServer;
View
1  minlog-export/src/main/java/dk/nsi/minlog/export/dao/splunk/LogEntrySearchDaoSplunk.java
@@ -58,6 +58,7 @@
Service splunkService;
+
Map<String, String> resultOptions;
static final String FIELDS = "_indextime, _time, EventDateTime, PersonCivilRegistrationIdentifier, UserIdentifier, UserIdentifierOnBehalfOf, HealthcareProfessionalOrganization, SourceSystemIdentifier, Activity, SessionId";
View
11 minlog-export/src/main/java/dk/nsi/minlog/export/job/MinLogCleanupJob.java
@@ -33,6 +33,8 @@
import org.springframework.transaction.annotation.Transactional;
import dk.nsi.minlog.export.dao.LogEntryDao;
+import dk.sdsd.nsp.slalog.api.SLALogItem;
+import dk.sdsd.nsp.slalog.api.SLALogger;
/**
* A job which cleans the database by deleting entries that are older then 2 years.
*/
@@ -43,6 +45,9 @@
@Inject
private LogEntryDao logEntryDao;
+ @Inject
+ private SLALogger slaLogger;
+
private boolean running;
@Transactional
@@ -53,8 +58,14 @@ public void cleanup() throws Exception{
running = true;
try{
DateTime date = DateTime.now().minusYears(2);
+ SLALogItem slaLogCleanup = slaLogger.createLogItem("Database cleanup", "clean up entries before " + date);
logger.info("Running cleanup job for entries before " + date);
+
long entries = logEntryDao.removeBefore(date);
+
+ slaLogCleanup.setCallResultOk();
+ slaLogCleanup.store();
+
logger.info("Deleted " + entries + " entries");
} catch(Exception e){
logger.warn("Failed to execute cleanup job", e);
View
13 minlog-export/src/main/java/dk/nsi/minlog/export/job/MinLogImportJob.java
@@ -39,6 +39,8 @@
import dk.nsi.minlog.export.dao.LogEntryDao;
import dk.nsi.minlog.export.dao.LogEntrySearchDao;
import dk.nsi.minlog.export.dao.StatusDao;
+import dk.sdsd.nsp.slalog.api.SLALogItem;
+import dk.sdsd.nsp.slalog.api.SLALogger;
/**
* Imports log entries from splunk into a database.
@@ -60,6 +62,9 @@
@Inject
private StatusDao statusDao;
+ @Inject
+ private SLALogger slaLogger;
+
@Value("${minlog.import.delay}")
public Integer delay;
@@ -82,11 +87,19 @@ public void startImport(){
logger.debug("Fetching data from " + from + " to " + to);
}
+ SLALogItem slaLogImport = slaLogger.createLogItem("Splunk import", "Fetching data from " + from + " to " + to);
List<LogEntry> logEntries = logEntrySearchDao.findLogEntries(from, to);
+ slaLogImport.setCallResultOk();
+ slaLogImport.store();
+
if (logEntries.size() > 0) {
+ SLALogItem slaLogSave = slaLogger.createLogItem("Database save", "Saving " + logEntries.size() + " items");
//save also updates the status in same transaction
logEntryDao.save(logEntries);
+ slaLogSave.setCallResultOk();
+ slaLogImport.store();
+
}
} catch (Exception e) {
logger.error("Import failed, setting running to false for next iteration", e);
View
15 minlog-export/src/test/java/dk/nsi/minlog/export/config/ConfigTest.java
@@ -29,11 +29,9 @@
import javax.sql.DataSource;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -43,6 +41,8 @@
import com.avaje.ebean.springsupport.factory.EbeanServerFactoryBean;
import com.splunk.Service;
+import dk.sdsd.nsp.slalog.api.SLALogger;
+
/**
* Simple test to see if spring is correctly setup, and all dependecies are met.
*
@@ -53,7 +53,7 @@
*/
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes={ApplicationRootConfig.class, ConfigTest.DatabaseConfigConfigTest.class, ConfigTest.SplunkConfigTest.class})
+@ContextConfiguration(classes={ApplicationRootConfig.class, ConfigTest.DatabaseConfigConfigTest.class, ConfigTest.SplunkConfigTest.class, ConfigTest.SLALooggerConfigTest.class})
public class ConfigTest {
@Test
@@ -90,4 +90,13 @@ public Service splunkService(){
}
}
+ @Configuration
+ public static class SLALooggerConfigTest extends SLALoggerConfig{
+
+ @Bean
+ public SLALogger slaLogger(){
+ return mock(SLALogger.class);
+ }
+ }
+
}
View
4 minlog-export/src/test/java/dk/nsi/minlog/export/dao/splunk/LogEntrySearchDaoSplunkTest.java
@@ -49,6 +49,7 @@
import com.splunk.Service;
import dk.nsi.minlog.domain.LogEntry;
+import dk.sdsd.nsp.slalog.api.SLALogger;
@RunWith(MockitoJUnitRunner.class)
public class LogEntrySearchDaoSplunkTest {
@@ -56,6 +57,9 @@
@Mock(answer=Answers.RETURNS_DEEP_STUBS)
Service splunkService;
+ @Mock(answer=Answers.RETURNS_DEEP_STUBS)
+ SLALogger slaLogger;
+
@InjectMocks
LogEntrySearchDaoSplunk logEntrySearchDao;
View
11 minlog-export/src/test/java/dk/nsi/minlog/export/job/MinLogCleanupJobTest.java
@@ -25,7 +25,9 @@
*/
package dk.nsi.minlog.export.job;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow;
@@ -34,6 +36,7 @@
import org.joda.time.DateTime;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Answers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
@@ -41,13 +44,17 @@
import org.mockito.stubbing.Answer;
import dk.nsi.minlog.export.dao.LogEntryDao;
+import dk.sdsd.nsp.slalog.api.SLALogger;
@RunWith(MockitoJUnitRunner.class)
public class MinLogCleanupJobTest {
@Mock
LogEntryDao logEntryDao;
-
+
+ @Mock(answer=Answers.RETURNS_DEEP_STUBS)
+ SLALogger slaLogger;
+
@InjectMocks
MinLogCleanupJob job;
View
7 minlog-export/src/test/java/dk/nsi/minlog/export/job/MinLogImportJobTest.java
@@ -36,6 +36,7 @@
import org.joda.time.DateTime;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Answers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
@@ -44,6 +45,7 @@
import dk.nsi.minlog.export.dao.LogEntryDao;
import dk.nsi.minlog.export.dao.StatusDao;
import dk.nsi.minlog.export.dao.splunk.LogEntrySearchDaoSplunk;
+import dk.sdsd.nsp.slalog.api.SLALogger;
@RunWith(MockitoJUnitRunner.class)
public class MinLogImportJobTest {
@@ -56,7 +58,10 @@
@Mock
StatusDao statusDao;
-
+
+ @Mock(answer=Answers.RETURNS_DEEP_STUBS)
+ SLALogger slaLogger;
+
@InjectMocks
MinLogImportJob minLogImportJob;
Please sign in to comment.
Something went wrong with that request. Please try again.