|
|
|
|
@@ -35,17 +35,19 @@ public class ShadowPlanningEngine {
|
|
|
|
|
private final SchedulingFacade schedulingFacade;
|
|
|
|
|
private final ShadowInputMapper inputMapper;
|
|
|
|
|
private final ShadowObservationProperties properties;
|
|
|
|
|
private final TransactionTemplate transactions;
|
|
|
|
|
private final TransactionTemplate planningTransactions;
|
|
|
|
|
private final TransactionTemplate refreshTransactions;
|
|
|
|
|
|
|
|
|
|
public ShadowPlanningEngine(SchedulingFacade schedulingFacade, ShadowInputMapper inputMapper,
|
|
|
|
|
ShadowObservationProperties properties, PlatformTransactionManager transactionManager) {
|
|
|
|
|
this.schedulingFacade = Objects.requireNonNull(schedulingFacade, "schedulingFacade");
|
|
|
|
|
this.inputMapper = Objects.requireNonNull(inputMapper, "inputMapper");
|
|
|
|
|
this.properties = Objects.requireNonNull(properties, "properties");
|
|
|
|
|
this.transactions = new TransactionTemplate(Objects.requireNonNull(transactionManager, "transactionManager"));
|
|
|
|
|
this.transactions.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
|
|
|
|
this.transactions.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
|
|
|
|
|
this.transactions.setTimeout(properties.getTimeoutSeconds());
|
|
|
|
|
PlatformTransactionManager requiredTransactionManager =
|
|
|
|
|
Objects.requireNonNull(transactionManager, "transactionManager");
|
|
|
|
|
this.planningTransactions = transactionTemplate(requiredTransactionManager, properties.getTimeoutSeconds());
|
|
|
|
|
this.refreshTransactions = transactionTemplate(
|
|
|
|
|
requiredTransactionManager, properties.getRefreshTimeoutSeconds());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public InboundShadowObservation planInbound(String taskNo, String trayNo) {
|
|
|
|
|
@@ -68,7 +70,7 @@ public class ShadowPlanningEngine {
|
|
|
|
|
throw new IllegalArgumentException("shadow snapshot instanceId is required");
|
|
|
|
|
}
|
|
|
|
|
String warehouseId = configuredWarehouseId();
|
|
|
|
|
return transactions.execute(status -> {
|
|
|
|
|
return refreshTransactions.execute(status -> {
|
|
|
|
|
if (!inputMapper.claimInstance(warehouseId, instanceId, INSTANCE_STALE_SECONDS)) {
|
|
|
|
|
throw new IllegalStateException("could not claim shadow snapshot refresh for warehouse " + warehouseId);
|
|
|
|
|
}
|
|
|
|
|
@@ -215,7 +217,7 @@ public class ShadowPlanningEngine {
|
|
|
|
|
public void compareInbound(InboundShadowObservation observation, String legacyResultCode,
|
|
|
|
|
String legacySpaceId) {
|
|
|
|
|
Objects.requireNonNull(observation, "observation");
|
|
|
|
|
transactions.executeWithoutResult(status -> {
|
|
|
|
|
planningTransactions.executeWithoutResult(status -> {
|
|
|
|
|
validateComparisonSnapshot(observation.snapshotGeneration(), observation.warehouseId(),
|
|
|
|
|
observation.snapshotSynchronizedAt(), observation.sourceSignature());
|
|
|
|
|
int inserted = inputMapper.insertComparison(
|
|
|
|
|
@@ -230,7 +232,7 @@ public class ShadowPlanningEngine {
|
|
|
|
|
|
|
|
|
|
public void compareOutbound(OutboundShadowObservation observation, String legacyResultCode) {
|
|
|
|
|
Objects.requireNonNull(observation, "observation");
|
|
|
|
|
transactions.executeWithoutResult(status -> {
|
|
|
|
|
planningTransactions.executeWithoutResult(status -> {
|
|
|
|
|
validateComparisonSnapshot(observation.snapshotGeneration(), observation.warehouseId(),
|
|
|
|
|
observation.snapshotSynchronizedAt(), observation.sourceSignature());
|
|
|
|
|
int inserted = inputMapper.insertComparison(
|
|
|
|
|
@@ -349,7 +351,7 @@ public class ShadowPlanningEngine {
|
|
|
|
|
|
|
|
|
|
private <T> T planWithStableSnapshot(PublishedShadowSnapshot snapshot, Supplier<T> planner) {
|
|
|
|
|
validateLeasedSnapshot(snapshot);
|
|
|
|
|
return transactions.execute(status -> {
|
|
|
|
|
return planningTransactions.execute(status -> {
|
|
|
|
|
requirePublishedSnapshot(snapshot, "published snapshot changed during planning");
|
|
|
|
|
T result = planner.get();
|
|
|
|
|
requirePublishedSnapshot(snapshot, "published snapshot changed during planning");
|
|
|
|
|
@@ -357,6 +359,15 @@ public class ShadowPlanningEngine {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TransactionTemplate transactionTemplate(
|
|
|
|
|
PlatformTransactionManager transactionManager, int timeoutSeconds) {
|
|
|
|
|
TransactionTemplate template = new TransactionTemplate(transactionManager);
|
|
|
|
|
template.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
|
|
|
|
template.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
|
|
|
|
|
template.setTimeout(timeoutSeconds);
|
|
|
|
|
return template;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void validateLeasedSnapshot(PublishedShadowSnapshot snapshot) {
|
|
|
|
|
Objects.requireNonNull(snapshot, "snapshot");
|
|
|
|
|
if (snapshot.generation() <= 0) {
|
|
|
|
|
|