Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #21 from pagopa/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
galales authored Jul 28, 2023
2 parents 9e2b627 + d1b5463 commit 9861499
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package it.pagopa.interop.probing.eservice.registry.reader;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List;
import com.amazonaws.xray.AWSXRay;
import com.google.inject.Guice;
Expand All @@ -13,10 +15,13 @@
import it.pagopa.interop.probing.eservice.registry.reader.producer.ServicesSend;
import it.pagopa.interop.probing.eservice.registry.reader.service.BucketService;
import it.pagopa.interop.probing.eservice.registry.reader.util.ProjectConstants;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class InteropProbingApplication {

public static void main(String[] args) throws Exception {
log.info("Eservice-Registry-Reader started at: {}", LocalDateTime.now(ZoneOffset.UTC));
Injector injector = Guice.createInjector(new BaseModule(), new JacksonMapperConfig(),
new PropertiesLoader(), new SqsConfig(), new BucketConfig());
BucketService bucketService = injector.getInstance(BucketService.class);
Expand All @@ -28,7 +33,7 @@ public static void main(String[] args) throws Exception {
servicesSend.sendMessage(eservice);
AWSXRay.endSegment();
}

log.info("Eservice-Registry-Reader ended at: {}", LocalDateTime.now(ZoneOffset.UTC));
}

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

import java.io.IOException;
import java.util.List;
import java.util.Objects;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.S3Object;
Expand All @@ -11,6 +12,7 @@
import com.google.inject.Singleton;
import com.google.inject.name.Named;
import it.pagopa.interop.probing.eservice.registry.reader.dto.impl.EserviceDTO;
import it.pagopa.interop.probing.eservice.registry.reader.util.logging.Logger;

@Singleton
public class BucketService {
Expand All @@ -29,9 +31,16 @@ public class BucketService {
@Inject
private ObjectMapper mapper;

@Inject
private Logger logger;

public List<EserviceDTO> readObject() throws IOException {
logger.logS3BucketRead(bucketName, bucketKey);
S3Object s3Object = s3Client.getObject(new GetObjectRequest(bucketName, bucketKey));
return mapper.readValue(s3Object.getObjectContent(), new TypeReference<List<EserviceDTO>>() {});
List<EserviceDTO> services =
mapper.readValue(s3Object.getObjectContent(), new TypeReference<List<EserviceDTO>>() {});
logger.logNumberEserviceRetrieved(Objects.nonNull(services) ? services.size() : 0);
return services;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
public interface Logger {

void logMessagePushedToQueue(UUID eserviceId, UUID versionId, URI queueUrl, String queueGroupId);

void logS3BucketRead(String bucketName, String bucketKey);

void logNumberEserviceRetrieved(Integer numberEservicesRetrieved);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,15 @@ public void logMessagePushedToQueue(UUID eserviceId, UUID versionId, URI queueUr
AWSXRay.getCurrentSegment().getTraceId().toString(), eserviceId, versionId,
queueUrl.toString(), queueGroupId);
}

@Override
public void logS3BucketRead(String bucketName, String bucketKey) {
log.info("Reading from S3 bucket. bucketName={}, bucketKey={}", bucketName, bucketKey);
}

@Override
public void logNumberEserviceRetrieved(Integer numberEservicesRetrieved) {
log.info("Number of Eservices retrieved: {}", numberEservicesRetrieved);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import it.pagopa.interop.probing.eservice.registry.reader.service.BucketService;
import it.pagopa.interop.probing.eservice.registry.reader.util.EserviceState;
import it.pagopa.interop.probing.eservice.registry.reader.util.EserviceTechnology;
import it.pagopa.interop.probing.eservice.registry.reader.util.logging.Logger;

@ExtendWith(MockitoExtension.class)
class BucketServiceTest {
Expand All @@ -37,6 +38,8 @@ class BucketServiceTest {

private AmazonS3 s3Client = mock(AmazonS3.class);

private Logger loggerMock = mock(Logger.class);

private List<EserviceDTO> listEservices;

@BeforeEach
Expand All @@ -55,6 +58,7 @@ protected void configure() {
bind(AmazonS3.class).toInstance(s3Client);
bind(ObjectMapper.class).toInstance(mapperMock);
bind(BucketService.class);
bind(Logger.class).toInstance(loggerMock);
bind(String.class).annotatedWith(Names.named("amazon.bucketS3.name"))
.toInstance("mocked-name");
bind(String.class).annotatedWith(Names.named("amazon.bucketS3.key"))
Expand Down

0 comments on commit 9861499

Please sign in to comment.