Duplicate Repository Validation Message 51/6151/1
authorSumit Kaushik <sk00613223@TechMahindra.com>
Wed, 18 Dec 2019 13:27:16 +0000 (18:57 +0530)
committerSumit Kaushik <sk00613223@TechMahindra.com>
Wed, 18 Dec 2019 13:30:54 +0000 (19:00 +0530)
ISSUE-ID : ACUMOS-3564

Duplicate Repository Validation Message Provided

Change-Id: I128187e32123515a5e9946f4d56a6a8d54c0afef
Signed-off-by: Sumit Kaushik <sk00613223@TechMahindra.com>
elk-client/src/main/java/org/acumos/elk/client/controller/ElasticSearchServiceController.java
elk-client/src/main/java/org/acumos/elk/client/service/ISnapshotRepositoryService.java
elk-client/src/main/java/org/acumos/elk/client/service/SnapshotRepositoryServiceImpl.java

index a0f3e3e..bab1c78 100644 (file)
@@ -110,18 +110,12 @@ 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, ELKException {
+                       throws Exception {
                LogConfig.setEnteringMDCs("elk-client", ElkClientConstants.SNAPSHOT_CREATE_REPOSITORY);
                String repositoryStatus = null;
                logger.debug("Inside create elasticstack repository");
 
-               try {
-                       repositoryStatus = snapshotGetRepositoryService.createElkRepository(elkCreateRepositoriesRequest);
-               } catch (Exception ex) {
-                       logger.info(ex.getMessage());
-                       throw new ELKException("false | RepositoryName already exist");
-
-               }
+               repositoryStatus = snapshotGetRepositoryService.createElkRepository(elkCreateRepositoriesRequest);
 
                logger.debug("method call ended.");
                LogConfig.clearMDCDetails();
index 5938e31..aeda0f7 100644 (file)
@@ -45,7 +45,7 @@ public interface ISnapshotRepositoryService {
         *            takes as request parameter
         * @return created status.
         */
-       public String createElkRepository(ElkRepositoriesRequest elkCreateRepositoriesRequest);
+       public String createElkRepository(ElkRepositoriesRequest elkCreateRepositoriesRequest) throws Exception;
 
        /**
         * This method is used to delete repository.
index 3e036e0..18df590 100644 (file)
@@ -94,7 +94,7 @@ public class SnapshotRepositoryServiceImpl extends AbstractELKClientConnection i
                return elkRepositoriesResponse;
        }
 
-       public String createElkRepository(ElkRepositoriesRequest elkCreateRepositoriesRequest) {
+       public String createElkRepository(ElkRepositoriesRequest elkCreateRepositoriesRequest) throws Exception {
                logger.debug("Inside createElkRepository ");
                if (StringUtils.isEmpty(elkCreateRepositoriesRequest.getRepositoryName())) {
                        return "false | RepositoryName empty is not allowed";
@@ -105,21 +105,15 @@ public class SnapshotRepositoryServiceImpl extends AbstractELKClientConnection i
                for (ELkRepositoryMetaData eLkRepositoryMetaData : elkRepositoryMetaDataList) {
                        repositoryNameSet.add(eLkRepositoryMetaData.getName());
                }
-               
-               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);
+               boolean acknowledged = false;
+               if (repositoryNameSet.contains(elkCreateRepositoriesRequest.getRepositoryName())) {
+                       throw new ELKException("false | RepositoryName already exist");
+               } else {
+                       acknowledged = createRepo(elkCreateRepositoriesRequest, "backup");
+                       createRepo(elkCreateRepositoriesRequest, ElkClientConstants.ARCHIVE_ES_DATA);
 
-               logger.debug("Repository is created(true for created)  {}", acknowledged);
+                       logger.debug("Repository is created ", acknowledged);
+               }               
                return String.valueOf(acknowledged);
        }