Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODINREACH-457 Making systemUserService class as optional in TenantSc… #416

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.folio.innreach.domain.entity.OngoingContributionStatus;
import org.folio.innreach.domain.service.impl.InnReachFolioExecutionContextBuilder;
import org.folio.spring.scope.FolioExecutionContextSetter;
import org.folio.innreach.external.exception.InnReachConnectionException;
import org.folio.innreach.external.exception.ServiceSuspendedException;
import org.folio.innreach.batch.contribution.InitialContributionJobConsumerContainer;
Expand Down Expand Up @@ -72,8 +70,6 @@ public class ContributionJobRunner {
private final Statistics stats = new Statistics();

private static final List<UUID> runningInitialContributions = Collections.synchronizedList(new ArrayList<>());
private final InnReachFolioExecutionContextBuilder folioExecutionContextBuilder;

private static Map<String,Integer> totalRecords = new HashMap<>();
private static ConcurrentHashMap<String, Integer> recordsProcessed = new ConcurrentHashMap<>();
private final OngoingContributionStatusService ongoingContributionStatusService;
Expand Down Expand Up @@ -388,13 +384,6 @@ public void runItemDeContribution(UUID centralServerId, Instance instance, Item
}
}

public void cancelJobs() {
log.debug("cancelJobs:: Cancelling unfinished contributions");
try (var context = new FolioExecutionContextSetter(folioExecutionContextBuilder.withUserId(folioContext,null))) {
contributionService.cancelAll();
runningInitialContributions.clear();
}
}

public void cancelInitialContribution(UUID contributionId) {
log.info("Cancelling initial contribution job {}", contributionId);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.folio.spring.FolioExecutionContext;
import org.folio.spring.context.ExecutionContextBuilder;
import org.folio.spring.scope.FolioExecutionContextSetter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.folio.spring.service.SystemUserService;

@Service
@RequiredArgsConstructor
public class TenantScopedExecutionService {

private final InnReachFolioExecutionContextBuilder contextBuilder;
private final SystemUserService systemUserService;
private final ExecutionContextBuilder contextBuilder;
private SystemUserService systemUserService;

@Autowired(required = false)
public void setSystemUserService(SystemUserService systemUserService) {
this.systemUserService = systemUserService;
}

@SneakyThrows
public void runTenantScoped(String tenantId, Runnable job) {
Expand All @@ -28,7 +35,8 @@ public void executeAsyncTenantScoped(String tenantId, Runnable job) {
}

private FolioExecutionContext folioExecutionContext(String tenant) {
return contextBuilder.forSystemUser(systemUserService.getAuthedSystemUser(tenant));
return systemUserService != null
? contextBuilder.forSystemUser(systemUserService.getAuthedSystemUser(tenant))
: contextBuilder.buildContext(tenant);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import org.folio.innreach.domain.entity.ContributionStatus;
import org.folio.innreach.domain.entity.OngoingContributionStatus;
import org.folio.innreach.domain.service.impl.InnReachFolioExecutionContextBuilder;
import feign.FeignException;
import org.folio.innreach.batch.contribution.InitialContributionJobConsumerContainer;
import org.folio.innreach.external.exception.InnReachConnectionException;
Expand Down Expand Up @@ -109,8 +108,6 @@ class ContributionJobRunnerTest {
@InjectMocks
private ContributionJobRunner jobRunner;

@Mock
private InnReachFolioExecutionContextBuilder folioExecutionContextBuilder;

@Mock
private InitialContributionJobConsumerContainer initialContributionJobConsumerContainer;
Expand Down Expand Up @@ -248,13 +245,6 @@ void shouldRunJob_noEvents() {
verifyNoInteractions(recordContributor);
}

@Test
void shouldCancelJobs() {
when(folioExecutionContextBuilder.withUserId(any(), any())).thenReturn(folioContext);
jobRunner.cancelJobs();
verify(contributionService).cancelAll();
}

@Test
void runOngoingInstanceContribution_shouldContribute() throws SocketTimeoutException {
var instance = createInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private KafkaTemplate<String, DomainEvent> buildKafkaTemplate() {
@Profile("test")
static class TestTenantScopedExecutionService extends TenantScopedExecutionService {
public TestTenantScopedExecutionService() {
super(null, null);
super(null);
}

@SneakyThrows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import org.folio.innreach.batch.contribution.service.ContributionJobRunner;
import org.folio.innreach.config.props.TestTenant;
import org.folio.spring.FolioExecutionContext;
import org.folio.spring.FolioModuleMetadata;
Expand All @@ -37,8 +36,6 @@ class CustomTenantServiceTest {
@Mock
private FolioExecutionContext context;
@Mock
private ContributionJobRunner contributionJobRunner;
@Mock
private ReferenceDataLoader referenceDataLoader;
@Mock
private TestTenant testTenant;
Expand Down Expand Up @@ -71,7 +68,6 @@ void should_not_prepareSystemUser_and_cancelContribJobs_for_testTenant() {
service.createOrUpdateTenant(new TenantAttributes());

verify(systemUserService, never()).setupSystemUser();
verify(contributionJobRunner, never()).cancelJobs();
}

@Test
Expand All @@ -83,7 +79,6 @@ void shouldNotInitializeTenantIfSystemUserInitFailed() throws LiquibaseException
assertThrows(TenantUpgradeException.class, () -> service.createOrUpdateTenant(attributes));

verify(systemUserService, never()).setupSystemUser();
verify(contributionJobRunner, never()).cancelJobs();
}

@Test
Expand Down

This file was deleted.

Loading