Skip to content

Commit

Permalink
separate component Gov OffChain run on separate application
Browse files Browse the repository at this point in the history
  • Loading branch information
Sotatek-QuanLeA committed Dec 17, 2024
1 parent a175341 commit 388057f
Show file tree
Hide file tree
Showing 79 changed files with 920 additions and 249 deletions.
1 change: 1 addition & 0 deletions application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {

implementation project(':components:common')
implementation project(':components:consumer-common')
implementation project(':components:govoffchain-scheduler')
implementation project(':components:scheduler')
implementation project(':components:healthcheck')

Expand Down
25 changes: 25 additions & 0 deletions components/govoffchain-scheduler/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
dependencies {
implementation project(":components:common")
implementation project(':components:consumer-common')
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation(libs.cardano.client.lib)
implementation(libs.yaci.store.governance)
implementation(libs.jsonld.java)

compileOnly(libs.lombok)
annotationProcessor(libs.lombok)

testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

publishing {
publications {
mavenJava(MavenPublication) {
pom {
name = 'Ledger Sync Scheduler OffChain'
description = 'Ledger Sync Scheduler OffChain Module'
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.cardanofoundation.ledgersync.govoffchainscheduler;

import org.cardanofoundation.ledgersync.govoffchainscheduler.jobs.OffChainDataScheduler;

import lombok.extern.slf4j.Slf4j;

import org.cardanofoundation.ledgersync.govoffchainscheduler.service.OffChainPersistService;
import org.cardanofoundation.ledgersync.govoffchainscheduler.service.OffChainRetryDataErrorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@ConditionalOnProperty(
prefix = "ledger-sync.scheduler",
name = "enabled",
havingValue = "true",
matchIfMissing = true
)
@Configuration
@EnableConfigurationProperties(GovOffChainSchedulerProperties.class)
@ComponentScan(basePackages = {"org.cardanofoundation.ledgersync.govoffchainscheduler"})
@EnableJpaRepositories(basePackages = {"org.cardanofoundation.ledgersync.govoffchainscheduler"})
@EntityScan(basePackages = {"org.cardanofoundation.ledgersync.govoffchainscheduler",
"com.bloxbean.cardano.yaci.store.core",
"com.bloxbean.cardano.yaci.store.governance"})
@EnableTransactionManagement
@EnableScheduling
@EnableAsync
@Slf4j
public class GovOffChainSchedulerConfiguration {

@Autowired
GovOffChainSchedulerProperties properties;

// @Bean
// public PoolOfflineDataScheduler poolOfflineDataScheduler(PoolOfflineDataStoringService poolOfflineDataStoringService,
// PoolOfflineDataFetchingService poolOfflineDataFetchingService,
// PoolOfflineDataProperties poolOfflineDataProperties) {
// log.info("<<< Enable PoolOfflineDataScheduler >>>");
// log.info("PoolOfflineDataScheduler: fixed delay time {} sec", poolOfflineDataProperties.getFixedDelay());
// return new PoolOfflineDataScheduler(poolOfflineDataStoringService, poolOfflineDataFetchingService, poolOfflineDataProperties);
// }

@Bean
public OffChainDataScheduler offChainVotingDataScheduler(
OffChainPersistService offChainPersistService,
OffChainRetryDataErrorService offChainDataFetchingErrorService,
OffChainDataProperties offChainDataProperties) {
log.info("<<< Enable OffChainDataScheduler >>>");
log.info("OffChainDataScheduler: fixed delay time {} sec", offChainDataProperties.getFixedDelay());
return new OffChainDataScheduler(offChainPersistService, offChainDataFetchingErrorService, offChainDataProperties);
}

// @Bean
// PoolOfflineDataProperties poolOfflineDataProperties() {
// PoolOfflineDataProperties poolOfflineDataProperties = new PoolOfflineDataProperties();
// poolOfflineDataProperties.setFixedDelay(properties.getPoolOfflineData().getFixedDelay());
// poolOfflineDataProperties.setInitialDelay(properties.getPoolOfflineData().getInitialDelay());
// return poolOfflineDataProperties;
// }

@Bean
OffChainDataProperties offChainDataProperties() {
OffChainDataProperties offChainDataProperties = new OffChainDataProperties();
offChainDataProperties.setFixedDelay(properties.getOffChainData().getFixedDelay());
offChainDataProperties.setInitialDelay(properties.getOffChainData().getInitialDelay());
offChainDataProperties.setFixedDelayFetchError(properties.getOffChainData().getFixedDelayFetchError());
offChainDataProperties.setInitialDelayFetchError(properties.getOffChainData().getInitialDelayFetchError());
offChainDataProperties.setRetryCount(properties.getOffChainData().getRetryCount());
return offChainDataProperties;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.cardanofoundation.ledgersync.govoffchainscheduler;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

@Getter
@Setter
@ConfigurationProperties(prefix = "ledger-sync.scheduler", ignoreUnknownFields = true)
public class GovOffChainSchedulerProperties {
private boolean enabled = true;
private PoolOfflineData poolOfflineData = new PoolOfflineData();
private OffChainData offChainData = new OffChainData();
private AsyncConfig asyncConfig = new AsyncConfig();

@Getter
@Setter
public static final class PoolOfflineData {
private long fixedDelay = 172800L;
private long initialDelay = 20000L;
}

@Getter
@Setter
public static final class OffChainData {
private long fixedDelay = 300000L;
private long initialDelay = 20000L;
private long fixedDelayFetchError = 2000000L;
private long initialDelayFetchError = 2000000L;
private int retryCount = 10;
}

@Getter
@Setter
public static final class AsyncConfig {
private int core = 10;
private int max = 12;
private String name = "Scheduler-Executorxx-";
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cardanofoundation.ledgersync.scheduler;
package org.cardanofoundation.ledgersync.govoffchainscheduler;

import lombok.Getter;
import lombok.Setter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.cardanofoundation.ledgersync.scheduler.config;
package org.cardanofoundation.ledgersync.govoffchainscheduler.config;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import jakarta.annotation.PreDestroy;

@Configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// package org.cardanofoundation.ledgersync.scheduler.constant;

// public final class JobConstants {
// private JobConstants() {}

// public static final int DEFAULT_BATCH = 20;
// public static final char END_LINE = '\n';
// }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cardanofoundation.ledgersync.scheduler.dto.anchor;
package org.cardanofoundation.ledgersync.govoffchainscheduler.dto.anchor;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cardanofoundation.ledgersync.scheduler.dto.anchor;
package org.cardanofoundation.ledgersync.govoffchainscheduler.dto.anchor;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cardanofoundation.ledgersync.scheduler.dto.anchor;
package org.cardanofoundation.ledgersync.govoffchainscheduler.dto.anchor;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cardanofoundation.ledgersync.scheduler.dto.anchor;
package org.cardanofoundation.ledgersync.govoffchainscheduler.dto.anchor;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cardanofoundation.ledgersync.scheduler.dto.anchor;
package org.cardanofoundation.ledgersync.govoffchainscheduler.dto.anchor;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cardanofoundation.ledgersync.scheduler.dto.anchor;
package org.cardanofoundation.ledgersync.govoffchainscheduler.dto.anchor;

import java.util.UUID;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cardanofoundation.ledgersync.scheduler.dto.offchain;
package org.cardanofoundation.ledgersync.govoffchainscheduler.dto.offchain;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cardanofoundation.ledgersync.scheduler.dto.offchain;
package org.cardanofoundation.ledgersync.govoffchainscheduler.dto.offchain;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cardanofoundation.ledgersync.scheduler.dto.offchain;
package org.cardanofoundation.ledgersync.govoffchainscheduler.dto.offchain;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cardanofoundation.ledgersync.scheduler.dto.offchain;
package org.cardanofoundation.ledgersync.govoffchainscheduler.dto.offchain;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cardanofoundation.ledgersync.scheduler.dto.offchain;
package org.cardanofoundation.ledgersync.govoffchainscheduler.dto.offchain;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cardanofoundation.ledgersync.scheduler.dto.offchain;
package org.cardanofoundation.ledgersync.govoffchainscheduler.dto.offchain;

import java.util.UUID;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.cardanofoundation.ledgersync.scheduler.jobs;
package org.cardanofoundation.ledgersync.govoffchainscheduler.jobs;

import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
import org.cardanofoundation.ledgersync.scheduler.service.OffChainPersistService;
import org.cardanofoundation.ledgersync.scheduler.OffChainDataProperties;
import org.cardanofoundation.ledgersync.scheduler.service.OffChainRetryDataErrorService;
import org.cardanofoundation.ledgersync.govoffchainscheduler.service.OffChainPersistService;
import org.cardanofoundation.ledgersync.govoffchainscheduler.OffChainDataProperties;
import org.cardanofoundation.ledgersync.govoffchainscheduler.service.OffChainRetryDataErrorService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -23,11 +23,11 @@ public class OffChainDataScheduler {
@Scheduled(initialDelayString = "#{offChainDataProperties.getInitialDelay() * 1000}",
fixedDelayString = "#{offChainDataProperties.getFixedDelay() * 1000}")
public void fetchOffChain() {
log.info("-----------Start job fetch pool offline data-----------");
log.info("-----------Start job fetch offchain data-----------");
final var startTime = System.currentTimeMillis();
offChainPersistService.validateAndPersistData();
log.info(
"----------End job fetch pool offline data, time taken: {} ms----------",
"----------End job fetch offchain data, time taken: {} ms----------",
(System.currentTimeMillis() - startTime));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// package org.cardanofoundation.ledgersync.scheduler.projection;

// public interface PoolHashUrlProjection {
// Long getPoolId();

// String getUrl();

// Long getMetadataId();
// }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cardanofoundation.ledgersync.scheduler.service;
package org.cardanofoundation.ledgersync.govoffchainscheduler.service;

public interface OffChainPersistService {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cardanofoundation.ledgersync.scheduler.service;
package org.cardanofoundation.ledgersync.govoffchainscheduler.service;

public interface OffChainRetryDataErrorService {
void retryOffChainErrorData();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cardanofoundation.ledgersync.scheduler.service.impl;
package org.cardanofoundation.ledgersync.govoffchainscheduler.service.impl;

import java.time.LocalTime;
import java.util.Arrays;
Expand All @@ -9,8 +9,8 @@

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import org.cardanofoundation.ledgersync.scheduler.service.OffChainPersistService;
import org.cardanofoundation.ledgersync.scheduler.service.offchain.OffChainProcessPersistDataService;
import org.cardanofoundation.ledgersync.govoffchainscheduler.service.OffChainPersistService;
import org.cardanofoundation.ledgersync.govoffchainscheduler.service.offchain.OffChainProcessPersistDataService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cardanofoundation.ledgersync.scheduler.service.impl;
package org.cardanofoundation.ledgersync.govoffchainscheduler.service.impl;

import java.time.LocalTime;
import java.util.Arrays;
Expand All @@ -9,8 +9,8 @@

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import org.cardanofoundation.ledgersync.scheduler.service.OffChainRetryDataErrorService;
import org.cardanofoundation.ledgersync.scheduler.service.offchain.OffChainProcessRetryDataService;
import org.cardanofoundation.ledgersync.govoffchainscheduler.service.OffChainRetryDataErrorService;
import org.cardanofoundation.ledgersync.govoffchainscheduler.service.offchain.OffChainProcessRetryDataService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cardanofoundation.ledgersync.scheduler.service.offchain;
package org.cardanofoundation.ledgersync.govoffchainscheduler.service.offchain;

import static com.bloxbean.cardano.client.util.JsonFieldWriter.mapper;

Expand Down Expand Up @@ -29,8 +29,8 @@

import org.cardanofoundation.ledgersync.common.util.HexUtil;
import org.cardanofoundation.ledgersync.common.util.UrlUtil;
import org.cardanofoundation.ledgersync.scheduler.dto.anchor.AnchorDTO;
import org.cardanofoundation.ledgersync.scheduler.dto.offchain.OffChainFetchResultDTO;
import org.cardanofoundation.ledgersync.govoffchainscheduler.dto.anchor.AnchorDTO;
import org.cardanofoundation.ledgersync.govoffchainscheduler.dto.offchain.OffChainFetchResultDTO;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.MediaType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.cardanofoundation.ledgersync.scheduler.service.offchain;
package org.cardanofoundation.ledgersync.govoffchainscheduler.service.offchain;

import java.util.Optional;

import org.cardanofoundation.ledgersync.common.common.Era;
import org.cardanofoundation.ledgersync.consumercommon.entity.OffChainDataCheckpoint;
import org.cardanofoundation.ledgersync.consumercommon.enumeration.OffChainCheckpointType;
import org.cardanofoundation.ledgersync.scheduler.storage.EraRepo;
import org.cardanofoundation.ledgersync.scheduler.storage.offchain.OffChainDataCheckpointStorage;
import org.cardanofoundation.ledgersync.govoffchainscheduler.storage.EraRepo;
import org.cardanofoundation.ledgersync.govoffchainscheduler.storage.offchain.OffChainDataCheckpointStorage;

public interface OffChainProcessPersistDataService {
void process();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.cardanofoundation.ledgersync.govoffchainscheduler.service.offchain;


public interface OffChainProcessRetryDataService {
void process();

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cardanofoundation.ledgersync.scheduler.service.offchain;
package org.cardanofoundation.ledgersync.govoffchainscheduler.service.offchain;

import java.util.Collection;
import java.util.Set;
Expand Down
Loading

0 comments on commit 388057f

Please sign in to comment.