Sumit Kaushik ACUMOS-3564 08/5908/1
authorSumit Kaushik <sk00613223@TechMahindra.com>
Thu, 14 Nov 2019 16:23:50 +0000 (21:53 +0530)
committerSumit Kaushik <sk00613223@TechMahindra.com>
Thu, 14 Nov 2019 16:26:21 +0000 (21:56 +0530)
Change-Id: I0780aa8fc2bfb581a66a93b4ccf6ff80943992e2
Signed-off-by: Sumit Kaushik <sk00613223@TechMahindra.com>
elk-client/pom.xml
elk-client/src/main/java/com/acumos/elk/exception/ELKException.java [new file with mode: 0644]
elk-client/src/main/java/org/acumos/elk/client/controller/ElasticSearchServiceController.java
elk-client/src/main/java/org/acumos/elk/client/service/SnapshotRepositoryServiceImpl.java

index 1c5c6ec..4982b92 100644 (file)
@@ -16,7 +16,7 @@
 
        <groupId>org.acumos.elk-client</groupId>
        <artifactId>elk-client</artifactId>
-       <version>3.0.4-SNAPSHOT</version>
+       <version>3.0.5-SNAPSHOT</version>
        <packaging>jar</packaging>
 
        <name>elk-client</name>
diff --git a/elk-client/src/main/java/com/acumos/elk/exception/ELKException.java b/elk-client/src/main/java/com/acumos/elk/exception/ELKException.java
new file mode 100644 (file)
index 0000000..8193930
--- /dev/null
@@ -0,0 +1,24 @@
+package com.acumos.elk.exception;
+
+public class ELKException extends Exception {
+        
+    private static final long serialVersionUID = 4664456874499611218L;
+    private String errorCode="Unknown_Exception";
+    
+    public ELKException(String s) 
+    { 
+        // Call constructor of parent Exception 
+        super(s); 
+    } 
+    public ELKException(String message, String errorCode){
+        super(message);
+        this.errorCode=errorCode;
+    }
+    public String getErrorCode(){
+        return this.errorCode;
+    }
+}
index 68da173..a0f3e3e 100644 (file)
@@ -53,6 +53,8 @@ import org.springframework.web.bind.annotation.ResponseStatus;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.context.request.WebRequest;
 
+import com.acumos.elk.exception.ELKException;
+
 import io.swagger.annotations.ApiOperation;
 
 /**
@@ -80,7 +82,7 @@ public class ElasticSearchServiceController extends AbstractController {
                LogConfig.clearMDCDetails();
                return new ResponseEntity<ElasticStackIndices>(response, null, HttpStatus.OK);
        }
-       
+
        @ApiOperation(value = "Delete elasticstack Indices.")
        @RequestMapping(value = ElkClientConstants.DELETE_INDICES, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
        public ResponseEntity<ElasticStackIndiceResponse> deleteElkSnapshot(
@@ -108,10 +110,19 @@ public class ElasticSearchServiceController extends AbstractController {
        @ApiOperation(value = "Create Elasticstack repository.")
        @RequestMapping(value = ElkClientConstants.SNAPSHOT_CREATE_REPOSITORY, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
        public ResponseEntity<String> createElkRepository(@RequestBody ElkRepositoriesRequest elkCreateRepositoriesRequest)
-                       throws Exception {
+                       throws Exception, ELKException {
                LogConfig.setEnteringMDCs("elk-client", ElkClientConstants.SNAPSHOT_CREATE_REPOSITORY);
+               String repositoryStatus = null;
                logger.debug("Inside create elasticstack repository");
-               String repositoryStatus = snapshotGetRepositoryService.createElkRepository(elkCreateRepositoriesRequest);
+
+               try {
+                       repositoryStatus = snapshotGetRepositoryService.createElkRepository(elkCreateRepositoriesRequest);
+               } catch (Exception ex) {
+                       logger.info(ex.getMessage());
+                       throw new ELKException("false | RepositoryName already exist");
+
+               }
+
                logger.debug("method call ended.");
                LogConfig.clearMDCDetails();
                return new ResponseEntity<String>(repositoryStatus, null, HttpStatus.OK);
@@ -180,18 +191,19 @@ public class ElasticSearchServiceController extends AbstractController {
 
        @ApiOperation(value = "Get all the archive snapshot.")
        @RequestMapping(value = ElkClientConstants.GET_ALL_ARCHIVE_INFO, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-       public ResponseEntity<ElkArchiveResponse> getAllArchiveInfoElkSnapshot()throws Exception {
-               LogConfig.setEnteringMDCs("elk-client",ElkClientConstants.GET_ALL_ARCHIVE_INFO);
+       public ResponseEntity<ElkArchiveResponse> getAllArchiveInfoElkSnapshot() throws Exception {
+               LogConfig.setEnteringMDCs("elk-client", ElkClientConstants.GET_ALL_ARCHIVE_INFO);
                logger.debug("Inside getAllArchiveInfoElkSnapshot");
                ElkArchiveResponse archiveResponse = snapshotGetRepositoryService.getArchiveElkRepository();
                logger.debug("method call ended.");
                LogConfig.clearMDCDetails();
                return new ResponseEntity<ElkArchiveResponse>(archiveResponse, null, HttpStatus.OK);
        }
-       
+
        @ApiOperation(value = "Archive and Restore elasticstack snapshot.")
        @RequestMapping(value = ElkClientConstants.ARCHIVE_REQUEST, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
-       public ResponseEntity<ElkArchiveResponse> archiveElkSnapshot(@RequestBody ElkArchiveRequest archiveRequest)throws Exception {
+       public ResponseEntity<ElkArchiveResponse> archiveElkSnapshot(@RequestBody ElkArchiveRequest archiveRequest)
+                       throws Exception {
                LogConfig.setEnteringMDCs("elk-client", ElkClientConstants.ARCHIVE_REQUEST);
                logger.debug("Inside archiveElkSnapshot");
                ElkArchiveResponse archiveResponse = snapshotGetRepositoryService.archiveElkRepository(archiveRequest);
@@ -199,7 +211,7 @@ public class ElasticSearchServiceController extends AbstractController {
                LogConfig.clearMDCDetails();
                return new ResponseEntity<ElkArchiveResponse>(archiveResponse, null, HttpStatus.OK);
        }
-       
+
        @ResponseStatus(HttpStatus.NOT_FOUND)
        @ExceptionHandler(ErrorTransport.class)
        public ResponseEntity<ErrorDetails> handleTransportError(ErrorTransport ex, WebRequest request) {
index 3b09eb0..71d1d95 100644 (file)
@@ -58,6 +58,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
+import com.acumos.elk.exception.ELKException;
+
 /**
  * Implementation of operation related to elastic stack repository.
  *
@@ -103,9 +105,17 @@ public class SnapshotRepositoryServiceImpl extends AbstractELKClientConnection i
                for (ELkRepositoryMetaData eLkRepositoryMetaData : elkRepositoryMetaDataList) {
                        repositoryNameSet.add(eLkRepositoryMetaData.getName());
                }
-               if (repositoryNameSet.contains(elkCreateRepositoriesRequest.getRepositoryName())) {
-                       return "false | RepositoryName already exist";
+               
+               try {
+                       if (repositoryNameSet.contains(elkCreateRepositoriesRequest.getRepositoryName())) {
+                               throw new ELKException("false | RepositoryName already exist");
+                               
+                       }
+               } catch (ELKException e) {
+                       logger.debug(e.getMessage());
+                       logger.info(e.getMessage());
                }
+               
                boolean acknowledged = createRepo(elkCreateRepositoriesRequest, "backup");
                createRepo(elkCreateRepositoriesRequest, ElkClientConstants.ARCHIVE_ES_DATA);