Repository Name in the GET all archive API 46/5146/5
authorAMIT M <am00474504@techmahindra.com>
Tue, 3 Sep 2019 11:32:53 +0000 (17:02 +0530)
committerAMIT M <am00474504@techmahindra.com>
Tue, 3 Sep 2019 12:53:35 +0000 (18:23 +0530)
Issue-ID: ACUMOS-3378, ACUMOS-3379
-Update code to delete snapshot
-Update the logic to get the archive repository names

Change-Id: I22e97e1263252d68a282d5b485295dbd1234cdf9
Signed-off-by: AMIT M <am00474504@techmahindra.com>
12 files changed:
docs/release-notes.rst
elk-client/pom.xml
elk-client/script/archive_script.sh
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
elk-client/src/main/java/org/acumos/elk/client/service/SnapshotServiceImpl.java
elk-client/src/main/java/org/acumos/elk/client/transport/ArchiveInfo.java
elk-client/src/main/java/org/acumos/elk/client/transport/CreateSnapshot.java
elk-client/src/main/java/org/acumos/elk/client/transport/ElkArchiveRequest.java
elk-client/src/main/java/org/acumos/elk/client/transport/ElkArchiveResponse.java
elk-client/src/main/java/org/acumos/elk/client/utils/ElkClientConstants.java

index 510a55c..ebab865 100644 (file)
 Platform Operations, Administration, and Management (OA&M) Release Notes
 ========================================================================
 
+Version 3.0.3, 03 September 2019
+--------------------------------
+* Repository Name in the GET all archive API (`ACUMOS-3378 <https://jira.acumos.org/browse/ACUMOS-3378>`_)
+* Delete snapshot API (`ACUMOS-3379 <https://jira.acumos.org/browse/ACUMOS-3379>`_
+
 Version 3.0.2, 21 August 2019
 -------------------------------
 * Create Snapshot API (`ACUMOS-3347 <https://jira.acumos.org/browse/ACUMOS-3347>`_)
index c906062..56653c9 100644 (file)
@@ -16,7 +16,7 @@
 
        <groupId>org.acumos.elk-client</groupId>
        <artifactId>elk-client</artifactId>
-       <version>3.0.2-SNAPSHOT</version>
+       <version>3.0.3-SNAPSHOT</version>
        <packaging>jar</packaging>
 
        <name>elk-client</name>
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-compiler-plugin</artifactId>
-                               <!-- <version>3.0</version> -->
-                               <configuration>
-                                       <source>1.8</source>
-                                       <target>1.8</target>
-                               </configuration>
+                               <version>3.8.1</version>
                        </plugin>
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                        <plugin>
                                <groupId>org.jacoco</groupId>
                                <artifactId>jacoco-maven-plugin</artifactId>
-                               <version>0.7.9</version>
+                               <version>0.8.1</version>
                                <executions>
                                        <execution>
                                                <id>default-prepare-agent</id>
                                                        <!-- Specify a tag to avoid default tag "latest" -->
                                                        <name>elk-client:${project.version}</name>
                                                        <build>
-                                                               <from>openjdk:8-jre-slim</from>
+                                                               <from>adoptopenjdk/openjdk11-openj9:alpine-jre</from>
                                                                <tags>
                                                                        <!-- Add tag with build number -->
                                                                        <tag>${project.version}-b${build.number}</tag>
index a47f2a2..ea56984 100644 (file)
@@ -56,19 +56,19 @@ function archive_esdata() {
     then
         if [ -e "../../elasticsearch/data/backup/$repo" ]
         then 
-                   if [ -e "../../elasticsearch/data/archive-es-data/$repo" ]
-                       then
-                          log DEBUG "Archiving is already done for $repo, deleting the $repo from $directory_name and recreating"
-                          rm -rf ../../elasticsearch/data/archive-es-data/$repo
-                       fi
+            if [ -e "$directory_name/$repo" ]
+            then
+               log DEBUG "Archiving is already done for $repo, deleting the $repo from $directory_name and recreating"
+               rm -rf $directory_name/$repo
+            fi
             log DEBUG "Archiving Eleasticserach data to $directory_name"
             log DEBUG "Archiving started: $repo"
-            mv -f ../../elasticsearch/data/backup/$repo/ ../../elasticsearch/data/archive-es-data/
+            mv -f ../../elasticsearch/data/backup/$repo/ $directory_name/
             log DEBUG "Archive Done:$repo"
-                       echo "$(date +%Y-%m-%d:%H:%M:%SZ),$repo"
+            echo "$(date +%Y-%m-%d:%H:%M:%SZ),$repo"
         else            
             log ERROR "$repo:Repository not present"
-                       echo "$repo:Repository not present | Back up is done"
+            echo "$repo:Repository not present | Back up is done"
         fi    
     else
         log ERROR "$PWD/$directory_name: Directory not present"
@@ -76,12 +76,12 @@ function archive_esdata() {
         log INFO "Created archive location directory: $directory_name"
         if [ -e "../../elasticsearch/data/backup/$repo" ]
         then 
-            mv ../../elasticsearch/data/backup/$repo/ ../../elasticsearch/data/archive-es-data/
+            mv ../../elasticsearch/data/backup/$repo/ $directory_name/
             log DEBUG "Archive Done:$repo"
-                       echo "$(date +%Y-%m-%d:%H:%M:%SZ),$repo"
+            echo "$(date +%Y-%m-%d:%H:%M:%SZ),$repo"
         else            
             log ERROR "$repo:Repository not present"
-                       echo "$repo:Repository not present | Back up is done"
+            echo "$repo:Repository not present | Back up is done"
         fi    
     fi
 }
@@ -96,7 +96,7 @@ log INFO "Inside restore_esdata:"
             cp -r --preserve=all $directory_name/$repo/ ../../elasticsearch/data/backup/$repo/
             chown '1000:1000' ../../elasticsearch/data/backup/$repo
             log INFO "Restore done:$(date +%Y-%m-%d:%H:%M:%SZ),$repo"
-                       echo "$(date +%Y-%m-%d:%H:%M:%SZ),$repo"
+            echo "$(date +%Y-%m-%d:%H:%M:%SZ),$repo"
         else
             log ERROR "$repo:Repository not found | No data available to restore"
             echo "No data present to restore"
@@ -111,21 +111,42 @@ function archive_info() {
 log INFO "Inside archive_info:" 
  if [ -e "$directory_name" ]
     then
-        fileExist=$(ls -l ../../elasticsearch/data/archive-es-data | head -1 | awk '{print $2}')
+        fileExist=$(ls -l $directory_name | head -1 | awk '{print $2}')
         if [ $fileExist -gt 0 ]
         then
             #Below command is used to get list of archival with archive date in csv format 
-            ls -l ../../elasticsearch/data/archive-es-data --time-style="+%Y-%m-%d:%H:%M:%SZ" | awk '{print $6, $7}' | sed 's/[ \t]/,/g' | sed 's/[ /]/,/g' | awk '{if(NR>1)print}'
+            ls -l $directory_name --time-style="+%Y-%m-%d:%H:%M:%SZ" | awk '{print $6, $7}' | sed 's/[ \t]/,/g' | sed 's/[ /]/,/g' | awk '{if(NR>1)print}'
         else
-            echo "No data present in archive location"
-            log ERROR "$directory_name: No data present in archive location"                   
+            log ERROR "$directory_name: No data present in archive location"
+                       echo "No data present in archive location"
         fi    
     else
+          log ERROR "$directory_name: No data present in archive location"
        echo "No data present in archive location"
-       log ERROR "$directory_name: No data present in archive location"           
     fi
 }
-directory_name=../../elasticsearch/data/archive-es-data
+
+function archive_delete() {
+log INFO "Inside archive_delete:" 
+ if [ -e "$directory_name" ]
+    then
+        fileExist=$(ls -l $directory_name | head -1 | awk '{print $2}')
+        if [ $fileExist -gt 0 ]
+        then
+            rm -rf $directory_name/$repo
+            log DEBUG "Deleted:$repo"
+            echo "$(date +%Y-%m-%d:%H:%M:%SZ),$repo"
+        else
+            log ERROR "$directory_name: No data present in archive location"
+                       echo "No data present in archive location"
+        fi    
+    else
+       log ERROR "$directory_name: No data present in archive location"
+          echo "No data present in archive location"
+    fi
+}
+
+directory_name=../../elasticsearch/data/backup/archive-es-data
 WORK_DIR=$(pwd)
 action=${1,,}
 repo=$2
@@ -139,6 +160,9 @@ then
 elif [ $action == 'info' ]
 then
   archive_info  
+elif [ $action == 'delete' ]
+then
+  archive_delete 
 else
-    log INFO "wrong action passed"  
+    log INFO "wrong action passed"
 fi
index 19c6dc9..68da173 100644 (file)
@@ -178,7 +178,7 @@ public class ElasticSearchServiceController extends AbstractController {
                return new ResponseEntity<ElasticStackIndiceResponse>(elasticStackIndiceResponse, null, HttpStatus.OK);
        }
 
-       @ApiOperation(value = "Ger all the archive snapshot.")
+       @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);
index 15d51d0..5938e31 100644 (file)
@@ -23,6 +23,7 @@ import org.acumos.elk.client.transport.ElkArchiveRequest;
 import org.acumos.elk.client.transport.ElkArchiveResponse;
 import org.acumos.elk.client.transport.ElkGetRepositoriesResponse;
 import org.acumos.elk.client.transport.ElkRepositoriesRequest;
+import org.acumos.elk.client.transport.ElkSnapshotsResponse;
 
 /** 
  * This interface defines method for elastic stack repository operation. 
index 508cf0f..a861d5c 100644 (file)
@@ -25,14 +25,19 @@ import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.function.BiPredicate;
 import java.util.function.Function;
+import java.util.function.Predicate;
 
 import org.acumos.elk.client.transport.ArchiveInfo;
 import org.acumos.elk.client.transport.ELkRepositoryMetaData;
+import org.acumos.elk.client.transport.ElasticsearchSnapshotsResponse;
 import org.acumos.elk.client.transport.ElkArchiveRequest;
 import org.acumos.elk.client.transport.ElkArchiveResponse;
 import org.acumos.elk.client.transport.ElkGetRepositoriesResponse;
+import org.acumos.elk.client.transport.ElkGetSnapshotMetaData;
 import org.acumos.elk.client.transport.ElkRepositoriesRequest;
+import org.acumos.elk.client.transport.ElkSnapshotsResponse;
 import org.acumos.elk.client.transport.ErrorTransport;
 import org.acumos.elk.client.utils.ElkClientConstants;
 import org.acumos.elk.client.utils.ElkServiceUtils;
@@ -49,10 +54,10 @@ import org.elasticsearch.repositories.fs.FsRepository;
 import org.json.simple.JSONObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
-
 /**
  * Implementation of operation related to elastic stack repository.
  *
@@ -61,44 +66,30 @@ import org.springframework.util.StringUtils;
 public class SnapshotRepositoryServiceImpl extends AbstractELKClientConnection implements ISnapshotRepositoryService {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-       
+       private Predicate<ELkRepositoryMetaData> chkRepositoryName = obj -> (obj.getName() != null
+                       && obj.getName().startsWith(ElkClientConstants.ARCHIVE_ES_DATA, 0));
+
+       @Autowired
+       SnapshotServiceImpl snapshotServiceImpl;
+
        @Override
        public ElkGetRepositoriesResponse getAllElkRepository() {
-
                logger.debug("Inside getAllElkRepository ");
-               RestHighLevelClient client = restHighLevelClientConnection();
-               GetRepositoriesRequest request1 = new GetRepositoriesRequest();
-               request1.repositories();
-               request1.local(true);
-
-               try {
-                       GetRepositoriesResponse response = client.snapshot().getRepository(request1, RequestOptions.DEFAULT);
-                       List<RepositoryMetaData> repositoryMetaDataResponse = response.repositories();
-                       logger.debug("Number of repositoryMetaDataResponse size {}", repositoryMetaDataResponse.size());
-
-                       ElkGetRepositoriesResponse elkRepositoriesResponse = new ElkGetRepositoriesResponse();
+               List<ELkRepositoryMetaData> elkRepositoryMetaDataList = getAllRepository();
+               Function<List<ELkRepositoryMetaData>, List<ELkRepositoryMetaData>> getArchiveRepository = list -> {
                        List<ELkRepositoryMetaData> repositories = new ArrayList<>();
-                       for (RepositoryMetaData snapshotStatusResponse : repositoryMetaDataResponse) {
-                               logger.debug("\nNAME: {} \n TYPE: {} \n SETTINGS: {}", snapshotStatusResponse.name(),
-                                               snapshotStatusResponse.type(), snapshotStatusResponse.settings());
-                               ELkRepositoryMetaData repositoryMetaData = new ELkRepositoryMetaData();
-                               repositoryMetaData.setName(snapshotStatusResponse.name());
-                               repositoryMetaData.setType(snapshotStatusResponse.type());
-                               JSONObject settings = new JSONObject();
-                               for (String key : snapshotStatusResponse.settings().keySet()) {
-                                       settings.put(key, snapshotStatusResponse.settings().get(key));
+                       for (ELkRepositoryMetaData eLkRepositoryMetaData : elkRepositoryMetaDataList) {
+                               if (!chkRepositoryName.test(eLkRepositoryMetaData)) {
+                                       repositories.add(eLkRepositoryMetaData);
                                }
-                               repositoryMetaData.setSettings(settings);
-                               repositories.add(repositoryMetaData);
                        }
-                       elkRepositoriesResponse.setRepositories(repositories);
-                       client.close();
-                       return elkRepositoriesResponse;
-               } catch (Exception ex) {
-                       logger.debug("Exception:", ex);
-                       throw new ErrorTransport("Unable to connect Elasticserach");
-               }
-
+                       return repositories;
+               };
+               List<ELkRepositoryMetaData> repositories = getArchiveRepository.apply(elkRepositoryMetaDataList);
+               logger.debug("getArchiveRepository count: {} ", repositories.size());
+               ElkGetRepositoriesResponse elkRepositoriesResponse = new ElkGetRepositoriesResponse();
+               elkRepositoriesResponse.setRepositories(repositories);
+               return elkRepositoriesResponse;
        }
 
        public String createElkRepository(ElkRepositoriesRequest elkCreateRepositoriesRequest) {
@@ -115,32 +106,8 @@ public class SnapshotRepositoryServiceImpl extends AbstractELKClientConnection i
                if (repositoryNameSet.contains(elkCreateRepositoriesRequest.getRepositoryName())) {
                        return "false | RepositoryName already exist";
                }
-               RestHighLevelClient client = restHighLevelClientConnection();
-               PutRepositoryRequest request = new PutRepositoryRequest();
-               String locationKey = FsRepository.LOCATION_SETTING.getKey();
-               String locationValue = elkCreateRepositoriesRequest.getRepositoryName().trim();
-               String compressKey = FsRepository.COMPRESS_SETTING.getKey();
-               boolean compressValue = true;
-               Settings settings = Settings.builder().put(locationKey, locationValue).put(compressKey, compressValue).build();
-               request.settings(settings);
-               request.name(elkCreateRepositoriesRequest.getRepositoryName().trim());
-               request.type(FsRepository.TYPE);
-               if (StringUtils.isEmpty(elkCreateRepositoriesRequest.getNodeTimeout())) {
-                       request.masterNodeTimeout(ElkClientConstants.TIME_ONE_MINT_OUT);
-               } else {
-                       request.masterNodeTimeout(elkCreateRepositoriesRequest.getNodeTimeout());
-               }
-               request.verify(true);
-               AcknowledgedResponse acknowledgedResponse;
-               boolean acknowledged = false;
-               try {
-                       acknowledgedResponse = client.snapshot().createRepository(request, RequestOptions.DEFAULT);
-                       acknowledged = acknowledgedResponse.isAcknowledged();
-                       client.close();
-               } catch (IOException ex) {
-                       logger.debug("Exception:", ex);
-                       throw new ErrorTransport("Unable to connect Elasticserach");
-               }
+               boolean acknowledged = createRepo(elkCreateRepositoriesRequest, "backup");
+               createRepo(elkCreateRepositoriesRequest, ElkClientConstants.ARCHIVE_ES_DATA);
 
                logger.debug("Repository is created(true for created)  {}", acknowledged);
                return String.valueOf(acknowledged);
@@ -148,13 +115,12 @@ public class SnapshotRepositoryServiceImpl extends AbstractELKClientConnection i
 
        @Override
        public String deleteElkRepository(ElkRepositoriesRequest elkDeleteRepositoriesRequest) {
-
                logger.debug("Inside deleteElkRepository");
                RestHighLevelClient client = restHighLevelClientConnection();
                DeleteRepositoryRequest deleteRepositoryRequest = new DeleteRepositoryRequest(
                                elkDeleteRepositoriesRequest.getRepositoryName());
                deleteRepositoryRequest.masterNodeTimeout(elkDeleteRepositoriesRequest.getNodeTimeout());
-               
+
                AcknowledgedResponse deleteAcknowledgedResponse;
                try {
                        deleteAcknowledgedResponse = client.snapshot().deleteRepository(deleteRepositoryRequest,
@@ -172,8 +138,72 @@ public class SnapshotRepositoryServiceImpl extends AbstractELKClientConnection i
 
        @Override
        public ElkArchiveResponse getArchiveElkRepository() throws Exception {
+               logger.debug("Inside getArchiveElkRepository");
                String action = ElkClientConstants.INFO;
+               Predicate<ElasticsearchSnapshotsResponse> chkSnapshots = obj -> (obj.getSnapshots() != null
+                               && obj.getSnapshots().size() > 0);
+               Function<List<ELkRepositoryMetaData>, List<ELkRepositoryMetaData>> filterArchiveRepository = list -> {
+                       List<ELkRepositoryMetaData> repositories = new ArrayList<>();
+                       for (ELkRepositoryMetaData eLkRepositoryMetaData : list) {
+                               if (chkRepositoryName.test(eLkRepositoryMetaData)) {
+                                       repositories.add(eLkRepositoryMetaData);
+                               }
+                       }
+                       return repositories;
+               };
+
+               Function<List<ArchiveInfo>, List<ArchiveInfo>> removeEmptyArchiveRepository = list -> {
+                       List<ArchiveInfo> archiveInfoList = new ArrayList<>();
+                       for (ArchiveInfo archiveInfo : list) {
+                               if (archiveInfo.getSnapshots() != null) {
+                                       archiveInfoList.add(archiveInfo);
+                               }
+                       }
+                       return archiveInfoList;
+               };
+
+               Function<ELkRepositoryMetaData, String> repoName = obj -> {
+                       JSONObject settingObj = obj.getSettings();
+                       String location = (String) settingObj.get("location");
+                       String[] p = location.split("/");
+                       return p[1];
+               };
+
+               BiPredicate<String, String> compareRepoName = (str1, str2) -> {
+                       if (str1 != null && str2 != null) {
+                               return str1.equalsIgnoreCase(str2);
+                       }
+                       return false;
+               };
+
+               List<ELkRepositoryMetaData> elkRepositoryMetaDataList = getAllRepository();
+               List<ELkRepositoryMetaData> archiveRepositories = filterArchiveRepository.apply(elkRepositoryMetaDataList);
+               logger.debug("repositories count: {} ", archiveRepositories.size());
                ElkArchiveResponse elkArchiveResponse = archiveOperation(null, action);
+               logger.debug("elkArchiveResponse.getMsg() {} elkArchiveResponse.getStatus() {}", elkArchiveResponse.getMsg(),
+                               elkArchiveResponse.getStatus());
+               if (elkArchiveResponse != null && elkArchiveResponse.getArchiveInfo() != null) {
+                       logger.debug("elkArchiveResponse.getArchiveInfo() count: {} ", elkArchiveResponse.getArchiveInfo().size());
+                       for (ArchiveInfo archiveInfo : elkArchiveResponse.getArchiveInfo()) {
+                               for (ELkRepositoryMetaData eLkRepositoryMetaData : archiveRepositories) {
+                                       ElasticsearchSnapshotsResponse elasticsearchSnapshotsResponse = snapshotServiceImpl
+                                                       .getElasticsearchSnapshotDetails(null, eLkRepositoryMetaData.getName());
+                                       String repoArchiveName = repoName.apply(eLkRepositoryMetaData);
+                                       logger.debug(
+                                                       "repoArchiveName: {} archiveInfo.getRepositoryName(): {}  elasticsearchSnapshotsResponse.getRepositoryName(): {} ",
+                                                       repoArchiveName, archiveInfo.getRepositoryName(),
+                                                       elasticsearchSnapshotsResponse.getRepositoryName());
+                                       if (chkSnapshots.test(elasticsearchSnapshotsResponse)) {
+                                               if (compareRepoName.test(archiveInfo.getRepositoryName(), repoArchiveName)) {
+                                                       archiveInfo.setSnapshots(elasticsearchSnapshotsResponse.getSnapshots());
+                                               }
+                                       }
+                               }
+                       }
+                       List<ArchiveInfo> filteredArchiveInfoList = removeEmptyArchiveRepository
+                                       .apply(elkArchiveResponse.getArchiveInfo());
+                       elkArchiveResponse.setArchiveInfo(filteredArchiveInfoList);
+               }
                return elkArchiveResponse;
        }
 
@@ -236,18 +266,91 @@ public class SnapshotRepositoryServiceImpl extends AbstractELKClientConnection i
                        if (action.equalsIgnoreCase("RESTORE")) {
                                for (ArchiveInfo archiveInfo : archiveInfoList) {
                                        ElkRepositoriesRequest elkCreateRepositoriesRequest = new ElkRepositoriesRequest();
-                                       elkCreateRepositoriesRequest.setRepositoryName(archiveInfo.getBackUpName());
+                                       elkCreateRepositoriesRequest.setRepositoryName(archiveInfo.getRepositoryName());
                                        elkCreateRepositoriesRequest.setNodeTimeout(ElkClientConstants.TIME_ONE_MINT_OUT);
                                        createElkRepository(elkCreateRepositoriesRequest);
                                }
                        }
 
                } else {
-                       result = result.replace("\n", "");
+                       logger.debug("result:" + result);
+                       if (result.contains("\n")) {
+                               result = result.replace("\n", "");
+                       }
                        elkArchiveResponse.setStatus(ElkClientConstants.FAIL);
-                       elkArchiveResponse.setMsg(result);
+                       elkArchiveResponse.setMsg(result.trim());
                }
                return elkArchiveResponse;
        }
 
+       private List<ELkRepositoryMetaData> getAllRepository() {
+               RestHighLevelClient client = restHighLevelClientConnection();
+               GetRepositoriesRequest request1 = new GetRepositoriesRequest();
+               request1.repositories();
+               request1.local(true);
+
+               try {
+                       GetRepositoriesResponse response = client.snapshot().getRepository(request1, RequestOptions.DEFAULT);
+                       List<RepositoryMetaData> repositoryMetaDataResponse = response.repositories();
+                       logger.debug("Number of repositoryMetaDataResponse size {}", repositoryMetaDataResponse.size());
+
+                       List<ELkRepositoryMetaData> repositories = new ArrayList<>();
+                       for (RepositoryMetaData snapshotStatusResponse : repositoryMetaDataResponse) {
+                               logger.debug("\nNAME: {} \n TYPE: {} \n SETTINGS: {}", snapshotStatusResponse.name(),
+                                               snapshotStatusResponse.type(), snapshotStatusResponse.settings());
+                               ELkRepositoryMetaData repositoryMetaData = new ELkRepositoryMetaData();
+                               repositoryMetaData.setName(snapshotStatusResponse.name());
+                               repositoryMetaData.setType(snapshotStatusResponse.type());
+                               JSONObject settings = new JSONObject();
+                               for (String key : snapshotStatusResponse.settings().keySet()) {
+                                       settings.put(key, snapshotStatusResponse.settings().get(key));
+                               }
+                               repositoryMetaData.setSettings(settings);
+                               repositories.add(repositoryMetaData);
+                       }
+                       client.close();
+                       return repositories;
+               } catch (Exception ex) {
+                       logger.debug("Exception:", ex);
+                       throw new ErrorTransport("Unable to connect Elasticserach");
+               }
+       }
+
+       private boolean createRepo(ElkRepositoriesRequest elkCreateRepositoriesRequest, String repoType) {
+               RestHighLevelClient client = restHighLevelClientConnection();
+               PutRepositoryRequest request = new PutRepositoryRequest();
+               String locationKey = FsRepository.LOCATION_SETTING.getKey();
+               String locationValue = elkCreateRepositoriesRequest.getRepositoryName().trim();
+               String compressKey = FsRepository.COMPRESS_SETTING.getKey();
+               boolean compressValue = true;
+               if (repoType == ElkClientConstants.ARCHIVE_ES_DATA) {
+                       request.name(
+                                       ElkClientConstants.ARCHIVE_ES_DATA + "-" + elkCreateRepositoriesRequest.getRepositoryName().trim());
+                       locationValue = ElkClientConstants.ARCHIVE_ES_DATA + "/"
+                                       + elkCreateRepositoriesRequest.getRepositoryName().trim();
+               } else {
+                       request.name(elkCreateRepositoriesRequest.getRepositoryName().trim());
+               }
+               Settings settings = Settings.builder().put(locationKey, locationValue).put(compressKey, compressValue).build();
+               request.settings(settings);
+               request.type(FsRepository.TYPE);
+               if (StringUtils.isEmpty(elkCreateRepositoriesRequest.getNodeTimeout())) {
+                       request.masterNodeTimeout(ElkClientConstants.TIME_ONE_MINT_OUT);
+               } else {
+                       request.masterNodeTimeout(elkCreateRepositoriesRequest.getNodeTimeout());
+               }
+               request.verify(true);
+               AcknowledgedResponse acknowledgedResponse;
+               boolean acknowledged = false;
+               try {
+                       acknowledgedResponse = client.snapshot().createRepository(request, RequestOptions.DEFAULT);
+                       acknowledged = acknowledgedResponse.isAcknowledged();
+                       client.close();
+               } catch (IOException ex) {
+                       logger.debug("Exception:", ex);
+                       throw new ErrorTransport("Unable to connect Elasticserach");
+               }
+               return acknowledged;
+       }
+
 }
index 24fae36..96de925 100644 (file)
@@ -338,12 +338,12 @@ public class SnapshotServiceImpl extends AbstractELKClientConnection implements
                return elasticStackIndiceResponse;
        }
 
-       private ElasticsearchSnapshotsResponse getElasticsearchSnapshotDetails(
+       protected ElasticsearchSnapshotsResponse getElasticsearchSnapshotDetails(
                        ElkRepositoriesRequest elkRepositoriesRequest, String repositoryName) {
 
                RestHighLevelClient client = restHighLevelClientConnection();
                GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest();
-               if (elkRepositoriesRequest.getRepositoryName() != null
+               if (elkRepositoriesRequest != null && elkRepositoriesRequest.getRepositoryName() != null
                                && !elkRepositoriesRequest.getRepositoryName().isEmpty()) {
                        getSnapshotsRequest.repository(elkRepositoriesRequest.getRepositoryName());
                } else {
index 4be078a..fb6c88b 100644 (file)
  */
 package org.acumos.elk.client.transport;
 
+import java.util.List;
+
 import io.swagger.annotations.ApiModelProperty;
 
 public class ArchiveInfo {
 
        @ApiModelProperty(required = true, value = "snapshot creation date")
-       String date;
+       private String date;
 
        @ApiModelProperty(required = true, value = "snapshot name.")
-       String backUpName;
+       private String repositoryName;
+
+       private List<ElkGetSnapshotMetaData> snapshots;
 
-       public ArchiveInfo(String date, String backUpName) {
+       public ArchiveInfo(String date, String repositoryName) {
                super();
                this.date = date;
-               this.backUpName = backUpName;
+               this.repositoryName = repositoryName;
        }
 
        public ArchiveInfo() {
@@ -43,20 +47,28 @@ public class ArchiveInfo {
                return date;
        }
 
-       public String getBackUpName() {
-               return backUpName;
+       public String getRepositoryName() {
+               return repositoryName;
+       }
+
+       public List<ElkGetSnapshotMetaData> getSnapshots() {
+               return snapshots;
+       }
+
+       public void setSnapshots(List<ElkGetSnapshotMetaData> snapshots) {
+               this.snapshots = snapshots;
        }
 
        @Override
        public String toString() {
-               return "ArchiveInfo [date=" + date + ", backUpName=" + backUpName + "]";
+               return "ArchiveInfo [date=" + date + ", repositoryName=" + repositoryName + "]";
        }
 
        @Override
        public int hashCode() {
                final int prime = 31;
                int result = 1;
-               result = prime * result + ((backUpName == null) ? 0 : backUpName.hashCode());
+               result = prime * result + ((repositoryName == null) ? 0 : repositoryName.hashCode());
                return result;
        }
 
@@ -69,10 +81,10 @@ public class ArchiveInfo {
                if (getClass() != obj.getClass())
                        return false;
                ArchiveInfo other = (ArchiveInfo) obj;
-               if (backUpName == null) {
-                       if (other.backUpName != null)
+               if (repositoryName == null) {
+                       if (other.repositoryName != null)
                                return false;
-               } else if (!backUpName.equals(other.backUpName))
+               } else if (!repositoryName.equals(other.repositoryName))
                        return false;
                return true;
        }
index f678e2c..7cd50ab 100644 (file)
@@ -21,17 +21,13 @@ package org.acumos.elk.client.transport;
 
 import java.util.List;
 
-import io.swagger.annotations.ApiModelProperty;
 
 public class CreateSnapshot {
 
-       @ApiModelProperty(required = true, value = "ElasticStack repository name", example = "logstashBackup")
        private String repositoryName;
        
-       @ApiModelProperty(required = true, value = "ElasticStack snapshot name, \"default\" for default snapshot name.", example = "default")
        private String snapshotName;
 
-       @ApiModelProperty(value = "indices names")
        private List<String> indices;
 
        public String getRepositoryName() {
index f4b9b12..d43c55a 100644 (file)
@@ -25,7 +25,7 @@ import io.swagger.annotations.ApiModelProperty;
 
 public class ElkArchiveRequest {
 
-       @ApiModelProperty(required = true, value = "String value archive/restore", example = "archive/restore")
+       @ApiModelProperty(required = true, value = "String value archive/restore/delete", example = "archive/restore/delete")
        private String action;
 
        @ApiModelProperty(required = true)
index 01417de..7886832 100644 (file)
@@ -29,24 +29,29 @@ public class ElkArchiveResponse {
        private List<ArchiveInfo> archiveInfo;
        private String msg;
        private String status;
-       
+
        public List<ArchiveInfo> getArchiveInfo() {
                return archiveInfo;
        }
+
        public void setArchiveInfo(List<ArchiveInfo> archiveInfo) {
                this.archiveInfo = archiveInfo;
        }
+
        public String getMsg() {
                return msg;
        }
+
        public void setMsg(String msg) {
                this.msg = msg;
        }
+
        public String getStatus() {
                return status;
        }
+
        public void setStatus(String status) {
                this.status = status;
        }
-       
+
 }
\ No newline at end of file
index cfa2803..064ade0 100644 (file)
@@ -43,5 +43,6 @@ public final class ElkClientConstants {
        public static final String SUCCESS = "success";
        public static final String FAIL = "fail";
        public static final String INFO = "INFO";
+       public static final String ARCHIVE_ES_DATA = "archive-es-data";
        
 }