Skip to content
Snippets Groups Projects
Commit c91d24dd authored by Wyatt Nielsen's avatar Wyatt Nielsen
Browse files

Testing logging updates

parent f5b4bbc8
No related branches found
No related tags found
1 merge request!6Trusted ibm
......@@ -81,6 +81,16 @@
<artifactId>log4j-api</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.29</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
......
......@@ -40,61 +40,61 @@ public class IndexerQueue {
public static void main(String[] args) {
// Logger log = LogManager.getLogger(IndexerQueue.class);
Logger log = LogManager.getLogger(IndexerQueue.class);
try {
// log.debug("Starting Indexer Queue and obtaining Arguments");
log.debug("Starting Indexer Queue and obtaining Arguments");
EnvironmentVariables environmentVariables = new EnvironmentVariables();
// log.debug("Retrieving indexer service account JWT");
log.debug("Retrieving indexer service account JWT");
AWSCognitoClient cognitoClient = new AWSCognitoClient(environmentVariables.cognitoClientId, environmentVariables.cognitoAuthFlow,
environmentVariables.cognitoUser, environmentVariables.cognitoPassword);
String indexerServiceAccountJWT = cognitoClient.getToken();
if(indexerServiceAccountJWT == null){
// log.error("Indexer service account not set up correctly");
log.error("Indexer service account not set up correctly");
}
// log.debug(String.format("Connecting to the SQS Queue: %s", environmentVariables.queueName));
log.debug(String.format("Connecting to the SQS Queue: %s", environmentVariables.queueName));
AmazonSQSConfig sqsConfig = new AmazonSQSConfig(environmentVariables.region);
AmazonSQS sqsClient = sqsConfig.AmazonSQS();
// log.debug(String.format("Creating a thread pool with %s threads", environmentVariables.maxIndexThreads));
log.debug(String.format("Creating a thread pool with %s threads", environmentVariables.maxIndexThreads));
ThreadPoolExecutor executorPool = (ThreadPoolExecutor) Executors.newFixedThreadPool(environmentVariables.maxIndexThreads);
final String deadLetterQueueUrl = sqsClient.getQueueUrl(environmentVariables.deadLetterQueueName).getQueueUrl();
List<Message> messages = IndexerQueueService.getMessages(sqsClient, environmentVariables.queueName, environmentVariables.maxBatchRequestCount, environmentVariables.maxMessagesAllowed);
// log.debug(String.format("Processing %s messages from storage queue", messages.size()));
log.debug(String.format("Processing %s messages from storage queue", messages.size()));
if (!messages.isEmpty()) {
List<IndexProcessor> indexProcessors = IndexerQueueService.processQueue(messages, environmentVariables.targetURL, executorPool, indexerServiceAccountJWT);
// log.debug(String.format("%s Messages Processed", indexProcessors.size()));
log.debug(String.format("%s Messages Processed", indexProcessors.size()));
List<IndexProcessor> failedProcessors = indexProcessors.stream().filter(indexProcessor -> indexProcessor.result == CallableResult.Fail || indexProcessor.exception != null).collect(Collectors.toList());
// log.debug(String.format("%s Messages Failed", failedProcessors.size()));
log.debug(String.format("%s Messages Failed", failedProcessors.size()));
List<SendMessageResult> deadLetterResults = IndexerQueueService.sendMsgsToDeadLetterQueue(deadLetterQueueUrl, failedProcessors, sqsClient);
// log.debug(String.format("%s Messages Dead Lettered", deadLetterResults.size()));
log.debug(String.format("%s Messages Dead Lettered", deadLetterResults.size()));
List<DeleteMessageBatchRequestEntry> deleteEntries = indexProcessors.stream().map(indexProcessor -> new DeleteMessageBatchRequestEntry(indexProcessor.messageId, indexProcessor.receiptHandle)).collect(Collectors.toList());
// log.debug(String.format("%s Messages Deleting", deleteEntries.size()));
log.debug(String.format("%s Messages Deleting", deleteEntries.size()));
final String sqsQueueUrl = sqsClient.getQueueUrl(environmentVariables.queueName).getQueueUrl();
List<DeleteMessageBatchRequest> deleteBatchRequests = IndexerQueueService.createMultipleBatchDeleteRequest(sqsQueueUrl, deleteEntries, environmentVariables.maxBatchRequestCount);
// log.debug(String.format("%s Delete Batch Request Created", deleteBatchRequests.size()));
log.debug(String.format("%s Delete Batch Request Created", deleteBatchRequests.size()));
List<DeleteMessageBatchResult> deleteMessageBatchResults = IndexerQueueService.deleteMessages(deleteBatchRequests, sqsClient);
// log.debug(String.format("%s Requests Deleted", deleteMessageBatchResults.size()));
log.debug(String.format("%s Requests Deleted", deleteMessageBatchResults.size()));
}
} catch (ExecutionException e) {
// log.error(e.getMessage(), e);
log.error(e.getMessage(), e);
} catch (InterruptedException e) {
// log.error(e.getMessage(), e);
log.error(e.getMessage(), e);
} catch (NullPointerException e) {
// log.error(e.getMessage(), e);
log.error(e.getMessage(), e);
}catch (Exception e) {
// log.error(e.getMessage(), e);
log.error(e.getMessage(), e);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment