Skip to content

Commit

Permalink
Fixes to salt generator job for Spring Batch 5 migration
Browse files Browse the repository at this point in the history
Signed-off-by: Loganathan Sekar <[email protected]>
  • Loading branch information
Loganathan Sekar authored and Loganathan Sekar committed Apr 12, 2024
1 parent d1c9926 commit 6e7bfec
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 24 deletions.
4 changes: 4 additions & 0 deletions kernel/kernel-salt-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
<artifactId>lombok</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
</dependencies>

<distributionManagement>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.mosip.kernel.saltgenerator;

import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.scheduling.ScheduledTasksEndpointAutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
Expand All @@ -15,7 +14,6 @@
* @author Manoj SP
*/
@SpringBootApplication
@EnableBatchProcessing
@EnableAutoConfiguration(exclude = { JmxAutoConfiguration.class, ScheduledTasksEndpointAutoConfiguration.class })
public class SaltGeneratorBootApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static io.mosip.kernel.saltgenerator.constant.SaltGeneratorConstant.DATASOURCE_PASSWORD;
import static io.mosip.kernel.saltgenerator.constant.SaltGeneratorConstant.DATASOURCE_URL;
import static io.mosip.kernel.saltgenerator.constant.SaltGeneratorConstant.DATASOURCE_USERNAME;
import static io.mosip.kernel.saltgenerator.constant.SaltGeneratorConstant.DB_SCHEMA_NAME;
import static io.mosip.kernel.saltgenerator.constant.SaltGeneratorConstant.PACKAGE_TO_SCAN;

import java.util.HashMap;
Expand All @@ -18,10 +19,12 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import jakarta.persistence.EntityManagerFactory;
Expand Down Expand Up @@ -73,6 +76,7 @@ public DataSource dataSource() {
dataSource.setUrl(env.getProperty(String.format(DATASOURCE_URL.getValue(), alias)));
dataSource.setUsername(env.getProperty(String.format(DATASOURCE_USERNAME.getValue(), alias)));
dataSource.setPassword(env.getProperty(String.format(DATASOURCE_PASSWORD.getValue(), alias)));
dataSource.setSchema(env.getProperty(DB_SCHEMA_NAME.getValue()));
dataSource.setDriverClassName(env.getProperty(String.format(DATASOURCE_DRIVERCLASSNAME.getValue(), alias)));
return dataSource;
}
Expand All @@ -98,8 +102,13 @@ private Map<String, Object> additionalProperties() {
Map<String, Object> jpaProperties = new HashMap<>();
jpaProperties.put("hibernate.implicit_naming_strategy", SpringImplicitNamingStrategy.class.getName());
jpaProperties.put("hibernate.physical_naming_strategy", namingResolver);
jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQL92Dialect");
jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
return jpaProperties;
}

@Bean
public PlatformTransactionManager transactionManager() {
return new DataSourceTransactionManager(dataSource());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.core.env.Environment;
import org.springframework.transaction.PlatformTransactionManager;

import io.mosip.kernel.saltgenerator.entity.SaltEntity;

Expand All @@ -30,13 +32,6 @@ public class SaltGeneratorJobConfig {
@Autowired
private Environment env;

/** The job builder factory. */
@Autowired
private JobBuilderFactory jobBuilderFactory;

/** The step builder factory. */
@Autowired
private StepBuilderFactory stepBuilderFactory;

/** The listener. */
@Autowired
Expand All @@ -57,9 +52,8 @@ public class SaltGeneratorJobConfig {
* @return the job
*/
@Bean
public Job job(Step step) {
return jobBuilderFactory
.get("job")
public Job job(JobRepository jobRepository,Step step) {
return new JobBuilder("job", jobRepository)
.incrementer(new RunIdIncrementer())
.listener(listener)
.flow(step)
Expand All @@ -74,10 +68,10 @@ public Job job(Step step) {
* @return the step
*/
@Bean
public Step step() {
return stepBuilderFactory
.get("step")
.<SaltEntity, SaltEntity> chunk(env.getProperty(CHUNK_SIZE.getValue(), Integer.class))
public Step step(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new StepBuilder("step", jobRepository)
.<SaltEntity, SaltEntity>chunk(env.getProperty(CHUNK_SIZE.getValue(), Integer.class),
transactionManager)
.reader(reader)
.writer(writer)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.listener.JobExecutionListenerSupport;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.stereotype.Component;

import io.mosip.kernel.core.logger.spi.Logger;
Expand All @@ -23,15 +23,14 @@
* @author Manoj SP
*/
@Component
public class BatchJobListener extends JobExecutionListenerSupport {
public class BatchJobListener implements JobExecutionListener {

/** The mosip logger. */
Logger mosipLogger = SaltGeneratorLogger.getLogger(BatchJobListener.class);

/* (non-Javadoc)
* @see org.springframework.batch.core.listener.JobExecutionListenerSupport#beforeJob(org.springframework.batch.core.JobExecution)
*/
@Override
public void beforeJob(JobExecution jobExecution) {
mosipLogger.debug("SALT_GENERATOR", "BatchJobListener", "BATCH JOB STARTED WITH STATUS : ",
jobExecution.getStatus().name());
Expand All @@ -40,7 +39,6 @@ public void beforeJob(JobExecution jobExecution) {
/* (non-Javadoc)
* @see org.springframework.batch.core.listener.JobExecutionListenerSupport#afterJob(org.springframework.batch.core.JobExecution)
*/
@Override
public void afterJob(JobExecution jobExecution) {
mosipLogger.debug("SALT_GENERATOR", "BatchJobListener", "BATCH JOB COMPLETED WITH STATUS : ",
jobExecution.getStatus().name());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
mosip.kernel.salt-generator.db.key-alias=mosip
spring.datasource.driver-class-name=org.postgresql.Driver
mosip.url=jdbc:postgresql://localhost:5432/postgres
mosip.username=postgres
mosip.password=postgres
mosip.driverClassName=org.postgresql.Driver
mosip.kernel.salt-generator.schemaName=mosip
mosip.kernel.salt-generator.tableName=uin_hash_salt
mosip.kernel.salt-generator.chunk-size=10
mosip.kernel.salt-generator.start-sequence=0
mosip.kernel.salt-generator.end-sequence=999
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
spring.hibernate.hbm2ddl.auto=create
hibernate.hbm2ddl.auto=create
hibernate.show_sql=true
spring.batch.jdbc.initialize-schema=always
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ spring.cloud.config.uri=localhost
spring.cloud.config.label=master
spring.cloud.config.name=kernel
spring.application.name=kernel
spring.profiles.active=dev
spring.profiles.active=local

#management.security.enabled=false
#management.endpoint.health.show-details=when-authorized
Expand Down

0 comments on commit 6e7bfec

Please sign in to comment.