Skip to content
Open
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
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@
<artifactId>poi-ooxml</artifactId>
<version>5.2.5</version>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.spoken_tutorial.health.elasticsearch.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.retry.annotation.EnableRetry;

@EnableRetry
@Configuration
public class RetryConfig {
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.spoken_tutorial.health.elasticsearch.config.Config;
import org.spoken_tutorial.health.elasticsearch.models.DocumentSearch;
import org.spoken_tutorial.health.elasticsearch.models.QueueManagement;
import org.spoken_tutorial.health.elasticsearch.repositories.DocumentSearchRepository;
import org.spoken_tutorial.health.elasticsearch.repositories.QueueManagementRepository;
import org.spoken_tutorial.health.elasticsearch.services.DocumentSearchService;
import org.spoken_tutorial.health.elasticsearch.services.QueueManagementService;
Expand All @@ -39,9 +38,6 @@ public class HomeController {

private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

@Autowired
private DocumentSearchRepository docuSearchRepo;

@Autowired
private QueueManagementRepository queRepo;

Expand Down Expand Up @@ -132,7 +128,7 @@ else if (status.equals(Config.STATUS_FAILED)) {
public Map<String, String> documentStatus(@PathVariable String documentId) {

Map<String, String> resultMap = new HashMap<>();
DocumentSearch documentSearch = docuSearchRepo.findByDocumentId(documentId);
DocumentSearch documentSearch = docuSearchService.findByDocumentId(documentId);

if (documentSearch == null) {
resultMap.put(Config.STATUS, Config.STATUS_NOTFOUND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import org.spoken_tutorial.health.elasticsearch.JsonService.JsonService;
import org.spoken_tutorial.health.elasticsearch.config.Config;
import org.spoken_tutorial.health.elasticsearch.contentfile.ContentsfromFile;
import org.spoken_tutorial.health.elasticsearch.repositories.DocumentSearchRepository;
import org.spoken_tutorial.health.elasticsearch.repositories.QueueManagementRepository;
import org.spoken_tutorial.health.elasticsearch.services.DocumentSearchService;
import org.spoken_tutorial.health.elasticsearch.threadpool.TaskProcessingService;
import org.springframework.beans.factory.annotation.Autowired;

Expand All @@ -29,7 +29,7 @@ public class QueueManagement implements Runnable {

@Autowired
@Transient
private DocumentSearchRepository docRepo;
private DocumentSearchService docSearchService;

@Autowired
@Transient
Expand Down Expand Up @@ -413,7 +413,7 @@ public void run() {
logger.info("{}", getStatusLog());
setStartTime(System.currentTimeMillis());

documentSearch = docRepo.findByDocumentId(getDocumentId());
documentSearch = docSearchService.findByDocumentId(getDocumentId());
if (getRequestType().equals(Config.ADD_DOCUMENT)) {

if (documentSearch != null) {
Expand Down Expand Up @@ -480,7 +480,7 @@ public void run() {

documentSearch.setRank(getRank());
documentSearch.setViewUrl(getViewUrl());
docRepo.save(documentSearch);
docSearchService.save(documentSearch);
setStatus(Config.STATUS_DONE);
logger.info("{}", getStatusLog());

Expand Down Expand Up @@ -578,7 +578,7 @@ else if (getLanguageId() != documentSearch.getLanguageId()) {
if (getOrderValue() != 0)
documentSearch.setOrderValue(getOrderValue());

docRepo.save(documentSearch);
docSearchService.save(documentSearch);
setStatus(Config.STATUS_DONE);
logger.info("{}", getStatusLog());

Expand All @@ -591,14 +591,14 @@ else if (getRequestType().equals(Config.UPDATE_DOCUMENT_RANK)) {
documentSearch.setChangeTime(System.currentTimeMillis());
}

docRepo.save(documentSearch);
docSearchService.save(documentSearch);
setStatus(Config.STATUS_DONE);
logger.info("{}", getStatusLog());

}

else if (getRequestType().equals(Config.DELETE_DOCUMENT)) {
docRepo.delete(documentSearch);
docSearchService.delete(documentSearch);
setStatus(Config.STATUS_DONE);
logger.info("{}", getStatusLog());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.spoken_tutorial.health.elasticsearch.services;

import java.io.IOException;

import org.apache.tika.parser.AutoDetectParser;
import org.apache.tika.parser.Parser;
import org.slf4j.Logger;
Expand All @@ -10,6 +12,9 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

Expand Down Expand Up @@ -45,4 +50,25 @@ public ResponseEntity<DocumentSearch> addContent(@PathVariable String path, @Pat

return new ResponseEntity<>(tut, HttpStatus.OK);
}

public DocumentSearch findByDocumentId(String documentId) {
return repo.findByDocumentId(documentId);
}

public void delete(DocumentSearch documentSearch) {
repo.delete(documentSearch);
}

@Retryable(retryFor = { IOException.class,
RuntimeException.class }, maxAttempts = 5, backoff = @Backoff(delay = 5000))
public void save(DocumentSearch documentSearch) {
repo.save(documentSearch);
}

@Recover
public void recover(Exception e, DocumentSearch documentSearch) {
// Handle failure after retries
logger.error("Failed to save document after retries", e);
}

}
15 changes: 12 additions & 3 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@
<pattern>%d %p %c{1} [%t] %X{queueId} %m%n</pattern>
</encoder>
</appender>

<!-- Elasticsearch and HTTP Logging -->
<logger name="org.elasticsearch.client" level="DEBUG" />
<logger name="org.elasticsearch" level="DEBUG" />
<logger name="org.apache.http" level="WARN" />
<logger name="org.apache.http.wire" level="ERROR" />
<logger name="org.apache.http.impl.execchain.RetryExec" level="ERROR" />

<logger name="org.spoken_tutorial.health.elasticsearch" level="debug" additivity="false">
<appender-ref ref="FILE-ROLLING"/>
</logger>
<!-- Application-specific logging -->

<logger name="org.spoken_tutorial.health.elasticsearch" level="debug" additivity="false">
<appender-ref ref="FILE-ROLLING"/>
</logger>


<root level="info">
Expand Down