Skip to content

Commit

Permalink
feat(policy):[TRI-1266] Fix Spring qualifier issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-jkreutzfeld committed Jun 19, 2023
1 parent d671fb8 commit 36d942b
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,23 @@
********************************************************************************/
package org.eclipse.tractusx.irs.aaswrapper.job;

import static org.eclipse.tractusx.irs.configuration.JobConfiguration.JOB_BLOB_PERSISTENCE;

import java.nio.charset.StandardCharsets;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.function.Consumer;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.irs.aaswrapper.job.delegate.AbstractDelegate;
import org.eclipse.tractusx.irs.common.persistence.BlobPersistence;
import org.eclipse.tractusx.irs.common.persistence.BlobPersistenceException;
import org.eclipse.tractusx.irs.component.JobParameter;
import org.eclipse.tractusx.irs.connector.job.ResponseStatus;
import org.eclipse.tractusx.irs.connector.job.TransferInitiateResponse;
import org.eclipse.tractusx.irs.connector.job.TransferProcessManager;
import org.eclipse.tractusx.irs.common.persistence.BlobPersistence;
import org.eclipse.tractusx.irs.common.persistence.BlobPersistenceException;
import org.eclipse.tractusx.irs.util.JsonUtil;
import org.springframework.beans.factory.annotation.Qualifier;

/**
* Process manager for AAS Object transfers.
Expand All @@ -51,7 +54,7 @@ public class AASTransferProcessManager implements TransferProcessManager<ItemDat
private final AbstractDelegate abstractDelegate;

public AASTransferProcessManager(final AbstractDelegate abstractDelegate, final ExecutorService executor,
final BlobPersistence blobStore) {
@Qualifier(JOB_BLOB_PERSISTENCE) final BlobPersistence blobStore) {
this.abstractDelegate = abstractDelegate;
this.executor = executor;
this.blobStore = blobStore;
Expand Down Expand Up @@ -80,7 +83,8 @@ private Runnable getRunnable(final ItemDataRequest dataRequest,
final String itemId = dataRequest.getItemId();

log.info("Starting processing Digital Twin Registry with itemId {}", itemId);
final ItemContainer itemContainer = abstractDelegate.process(ItemContainer.builder(), jobData, aasTransferProcess, itemId);
final ItemContainer itemContainer = abstractDelegate.process(ItemContainer.builder(), jobData,
aasTransferProcess, itemId);
storeItemContainer(processId, itemContainer);

transferProcessCompleted.accept(aasTransferProcess);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
********************************************************************************/
package org.eclipse.tractusx.irs.aaswrapper.job;

import static org.eclipse.tractusx.irs.configuration.JobConfiguration.JOB_BLOB_PERSISTENCE;

import java.nio.charset.StandardCharsets;
import java.util.List;

Expand All @@ -31,6 +33,7 @@
import org.eclipse.tractusx.irs.common.persistence.BlobPersistence;
import org.eclipse.tractusx.irs.common.persistence.BlobPersistenceException;
import org.eclipse.tractusx.irs.util.JsonUtil;
import org.springframework.beans.factory.annotation.Qualifier;

/**
* Retrieves item graph from potentially multiple calls to IRS API behind
Expand All @@ -49,6 +52,7 @@ public class TreeRecursiveLogic {
/**
* Blob store API.
*/
@Qualifier(JOB_BLOB_PERSISTENCE)
private final BlobPersistence blobStoreApi;
/**
* Json Converter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.eclipse.tractusx.irs.services.MeterRegistryService;
import org.eclipse.tractusx.irs.services.validation.JsonValidatorService;
import org.eclipse.tractusx.irs.util.JsonUtil;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
Expand All @@ -68,6 +69,7 @@
"PMD.TooManyMethods"
})
public class JobConfiguration {
public static final String JOB_BLOB_PERSISTENCE = "JobPersistence";
public static final int EXECUTOR_CORE_POOL_SIZE = 5;
private static final Integer EXPIRE_AFTER_DAYS = 7;

Expand All @@ -79,8 +81,9 @@ public OutboundMeterRegistryService outboundMeterRegistryService(final MeterRegi

@Bean
public JobOrchestrator<ItemDataRequest, AASTransferProcess> jobOrchestrator(
final DigitalTwinDelegate digitalTwinDelegate, final BlobPersistence blobStore, final JobStore jobStore,
final MeterRegistryService meterService, final ApplicationEventPublisher applicationEventPublisher,
final DigitalTwinDelegate digitalTwinDelegate, @Qualifier(JOB_BLOB_PERSISTENCE) final BlobPersistence blobStore,
final JobStore jobStore, final MeterRegistryService meterService,
final ApplicationEventPublisher applicationEventPublisher,
@Value("${irs.job.jobstore.ttl.failed:}") final Duration ttlFailedJobs,
@Value("${irs.job.jobstore.ttl.completed:}") final Duration ttlCompletedJobs) {

Expand All @@ -104,7 +107,7 @@ public Clock clock() {
}

@Profile("!test")
@Bean(name = "JobPersistence")
@Bean(JOB_BLOB_PERSISTENCE)
public BlobPersistence blobStore(final BlobstoreConfiguration config) throws BlobPersistenceException {
return new MinioBlobPersistence(config.getEndpoint(), config.getAccessKey(), config.getSecretKey(),
config.getBucketName(), EXPIRE_AFTER_DAYS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
********************************************************************************/
package org.eclipse.tractusx.irs.configuration;

import static org.eclipse.tractusx.irs.configuration.JobConfiguration.JOB_BLOB_PERSISTENCE;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
Expand All @@ -36,6 +38,7 @@
import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.irs.common.persistence.BlobPersistence;
import org.eclipse.tractusx.irs.common.persistence.MinioBlobPersistence;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
Expand All @@ -47,16 +50,14 @@
@RequiredArgsConstructor
@Slf4j
class MinioHealthIndicator implements HealthIndicator {

@Qualifier(JOB_BLOB_PERSISTENCE)
private final BlobPersistence blobPersistence;
private final BlobstoreConfiguration blobstoreConfiguration;

@Override
public Health health() {
if (thereIsMinioConnection()) {
return Health.up()
.withDetail("bucketName", blobstoreConfiguration.getBucketName())
.build();
return Health.up().withDetail("bucketName", blobstoreConfiguration.getBucketName()).build();
} else {
return Health.down().build();
}
Expand All @@ -66,6 +67,7 @@ public Health health() {
* Verifies if blobPersistence is instance of {@link MinioBlobPersistence} and if bucket exists.
* If yes it means that there is Minio connection.
* If bucket does not exist, method tries to recreate it.
*
* @return true if bucket exists, false otherwise
*/
private boolean thereIsMinioConnection() {
Expand All @@ -76,7 +78,9 @@ private boolean thereIsMinioConnection() {
if (minioBlobPersistence.bucketExists(blobstoreConfiguration.getBucketName())) {
return true;
}
} catch (ServerException | InsufficientDataException | ErrorResponseException | IOException | NoSuchAlgorithmException | InvalidKeyException | InvalidResponseException | XmlParserException | InternalException e) {
} catch (ServerException | InsufficientDataException | ErrorResponseException | IOException |
NoSuchAlgorithmException | InvalidKeyException | InvalidResponseException | XmlParserException |
InternalException e) {
log.error("Lost connection to Minio", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
********************************************************************************/
package org.eclipse.tractusx.irs.connector.batch;

import static org.eclipse.tractusx.irs.configuration.JobConfiguration.JOB_BLOB_PERSISTENCE;

import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -35,6 +37,7 @@
import org.eclipse.tractusx.irs.common.persistence.BlobPersistence;
import org.eclipse.tractusx.irs.common.persistence.BlobPersistenceException;
import org.eclipse.tractusx.irs.util.JsonUtil;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
Expand All @@ -49,6 +52,7 @@ public class PersistentBatchOrderStore implements BatchOrderStore {

private final JsonUtil json = new JsonUtil();

@Qualifier(JOB_BLOB_PERSISTENCE)
private final BlobPersistence blobStore;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
********************************************************************************/
package org.eclipse.tractusx.irs.connector.batch;

import static org.eclipse.tractusx.irs.configuration.JobConfiguration.JOB_BLOB_PERSISTENCE;

import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -35,6 +37,7 @@
import org.eclipse.tractusx.irs.common.persistence.BlobPersistence;
import org.eclipse.tractusx.irs.common.persistence.BlobPersistenceException;
import org.eclipse.tractusx.irs.util.JsonUtil;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
Expand All @@ -49,6 +52,7 @@ public class PersistentBatchStore implements BatchStore {

private final JsonUtil json = new JsonUtil();

@Qualifier(JOB_BLOB_PERSISTENCE)
private final BlobPersistence blobStore;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
********************************************************************************/
package org.eclipse.tractusx.irs.connector.job;

import static org.eclipse.tractusx.irs.configuration.JobConfiguration.JOB_BLOB_PERSISTENCE;

import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -38,6 +40,7 @@
import org.eclipse.tractusx.irs.common.persistence.BlobPersistenceException;
import org.eclipse.tractusx.irs.services.MeterRegistryService;
import org.eclipse.tractusx.irs.util.JsonUtil;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
Expand All @@ -53,6 +56,7 @@ public class PersistentJobStore extends BaseJobStore {
*/
private static final String JOB_PREFIX = "job:";

@Qualifier(JOB_BLOB_PERSISTENCE)
private final BlobPersistence blobStore;

private final JsonUtil json = new JsonUtil();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
********************************************************************************/
package org.eclipse.tractusx.irs.services;

import static org.eclipse.tractusx.irs.configuration.JobConfiguration.JOB_BLOB_PERSISTENCE;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -72,6 +74,7 @@
import org.eclipse.tractusx.irs.semanticshub.SemanticsHubFacade;
import org.eclipse.tractusx.irs.services.validation.SchemaNotFoundException;
import org.eclipse.tractusx.irs.util.JsonUtil;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.support.MutableSortDefinition;
import org.springframework.beans.support.PagedListHolder;
Expand All @@ -98,6 +101,7 @@ public class IrsItemGraphQueryService implements IIrsItemGraphQueryService {

private final JobStore jobStore;

@Qualifier(JOB_BLOB_PERSISTENCE)
private final BlobPersistence blobStore;

private final MeterRegistryService meterRegistryService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ public void initialize(ConfigurableApplicationContext applicationContext) {
final String hostAddress = minioContainer.getHostAddress();
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(applicationContext,
"blobstore.endpoint=http://" + hostAddress, "blobstore.accessKey=" + ACCESS_KEY,
"blobstore.secretKey=" + SECRET_KEY);
"blobstore.secretKey=" + SECRET_KEY, "policystore.persistence.endpoint=http://" + hostAddress,
"policystore.persistence.accessKey=" + ACCESS_KEY,
"policystore.persistence.secretKey=" + SECRET_KEY,
"policystore.persistence.bucketName=policy-test");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
@Configuration
public class PolicyConfiguration {

public static final String POLICY_BLOB_PERSISTENCE = "PolicyStorePersistence";

@Profile("!test")
@Bean(name = "PolicyStorePersistence")
@Bean(POLICY_BLOB_PERSISTENCE)
public BlobPersistence blobStore(final PolicyBlobstoreConfiguration config) throws BlobPersistenceException {
return new MinioBlobPersistence(config.getEndpoint(), config.getAccessKey(), config.getSecretKey(),
config.getBucketName(), config.getDaysToLive());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
********************************************************************************/
package org.eclipse.tractusx.irs.policystore.persistence;

import static org.eclipse.tractusx.irs.policystore.config.PolicyConfiguration.POLICY_BLOB_PERSISTENCE;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -35,6 +37,7 @@
import org.eclipse.tractusx.irs.common.persistence.BlobPersistenceException;
import org.eclipse.tractusx.irs.policystore.exceptions.PolicyStoreException;
import org.eclipse.tractusx.irs.policystore.models.Policy;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
Expand All @@ -43,6 +46,8 @@
@Service
@RequiredArgsConstructor
public class PolicyPersistence {

@Qualifier(POLICY_BLOB_PERSISTENCE)
private final BlobPersistence persistence;

private final ObjectMapper mapper;
Expand Down
3 changes: 3 additions & 0 deletions lombok.config
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Add @Generated annotation to generated code, so that it is skipped by JaCoCo
lombok.addLombokGeneratedAnnotation = true

lombok.copyableAnnotations += org.springframework.beans.factory.annotation.Qualifier
lombok.copyableAnnotations += org.springframework.beans.factory.annotation.Value

0 comments on commit 36d942b

Please sign in to comment.