diff options
author | ys9693 <ys9693@att.com> | 2020-01-19 13:50:02 +0200 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2020-01-22 12:33:31 +0000 |
commit | 16a9fce0e104a38371a9e5a567ec611ae3fc7f33 (patch) | |
tree | 03a2aff3060ddb5bc26a90115805a04becbaffc9 /asdctool/src/main/resources/es-resources/index_ops.py | |
parent | aa83a2da4f911c3ac89318b8e9e8403b072942e1 (diff) |
Catalog alignment
Issue-ID: SDC-2724
Signed-off-by: ys9693 <ys9693@att.com>
Change-Id: I52b4aacb58cbd432ca0e1ff7ff1f7dd52099c6fe
Diffstat (limited to 'asdctool/src/main/resources/es-resources/index_ops.py')
-rw-r--r-- | asdctool/src/main/resources/es-resources/index_ops.py | 151 |
1 files changed, 0 insertions, 151 deletions
diff --git a/asdctool/src/main/resources/es-resources/index_ops.py b/asdctool/src/main/resources/es-resources/index_ops.py deleted file mode 100644 index d1f3bb0021..0000000000 --- a/asdctool/src/main/resources/es-resources/index_ops.py +++ /dev/null @@ -1,151 +0,0 @@ -import itertools -import string -import json -from datetime import datetime -from elasticsearch import Elasticsearch -import elasticsearch -import elasticsearch.helpers -from elasticsearch.client import IndicesClient, CatClient -import sys, os, getopt -from file_utils import readFileToJson -from config_properties import getGlobalVar - - - -def createIndex(client, indexName, createBody): - try: - print "start createIndex" - if (client == None): - client = Elasticsearch(['localhost']) - esIndexClient = IndicesClient(client) - res = deleteIndex(client, indexName) - if (res != 0): - print "operation failed" - return 2 - create_res=elasticsearch.client.IndicesClient.create(esIndexClient, index=indexName, body=createBody) - print "create index response: ", create_res - if (create_res['acknowledged'] != True): - print "failed to create index" - return 1 - else: - print "index ",indexName, " created successfully" - return 0 - except Exception, error: - print "An exception was thrown!" - print str(error) - return 2 - - -def deleteIndex(client, indexName): - try: - print "start deleteIndex" - if (client == None): - client = Elasticsearch(['localhost']) - esIndexClient = IndicesClient(client) - isExists=elasticsearch.client.IndicesClient.exists(esIndexClient, indexName) - if ( isExists == True ): - delete_res=elasticsearch.client.IndicesClient.delete(esIndexClient, index=indexName) - if (delete_res['acknowledged'] != True): - print "failed to delete index" - return 1 - else: - print "index ",indexName, " deleted" - return 0 - else: - print "index not found - assume already deleted" - return 0 - except Exception, error: - print "An exception was thrown!" - print str(error) - return 2 - -def copyIndex(client, fromIndex, toIndex): - try: - print "start copyIndex" - if (client == None): - client = Elasticsearch(['localhost']) - client.indices.refresh(index=fromIndex) - count=client.search(fromIndex, search_type='count') - print "original index count: ",count - docNum, docErrors = elasticsearch.helpers.reindex(client, fromIndex, toIndex) - print "copy result: ", docNum, docErrors - if (docNum != count['hits']['total']): - print "Failed to copy all documents. expected: ", count['hits']['total'], " actual: ", docNum - return 1 - # if (len(docErrors) != 0): - # print "copy returned with errors" - # print docErrors - # return 1 - return 0 - except Exception, error: - print "An exception was thrown!" - print str(error) - return 2 - - -def usage(): - print 'USAGE: ', sys.argv[0], '-o <operation : create | delete | move> -n <indexName> -a <address> -f <mappingFile (for create)> -t <toIndex (for move operation)>' - - - -def main(argv): - print "start script with ", len(sys.argv), 'arguments.' - print "==============================================" - - try: - opts, args = getopt.getopt(argv, "h:o:a:n:f:t:", ["operation","address","indexName","file","toIndex"]) - except getopt.GetoptError: - usage() - sys.exit(2) - - host = None - for opt, arg in opts: - print opt, arg - if opt == '-h': - usage() - sys.exit(2) - elif opt in ('-f', '--file'): - mapping=readFileToJson(arg) - elif opt in ('-a', '--address'): - host=arg - elif opt in ('-o', '--operation'): - operation=arg - elif opt in ('-n', '--indexName'): - indexName=arg - elif opt in ('-t', '--toIndex'): - destIndexName=arg - - if (operation == None): - usage() - sys.exit(2) - elif (host == None): - print "address is mandatory argument" - usage() - sys.exit(2) - elif operation == 'create': - print "create new index ", indexName - client = Elasticsearch([{'host': host, 'timeout':5}] ) - res = createIndex(client, indexName, mapping) - - elif operation == 'delete': - print "delete index ", indexName - client = Elasticsearch([{'host': host, 'timeout':5}] ) - res = deleteIndex(client, indexName) - - elif operation == 'move': - print "move index ", indexName, " to ", destIndexName - client = Elasticsearch([{'host': host, 'timeout':5}] ) - res = copyIndex(client, indexName, destIndexName) - else: - usage() - exit(2) - if res != 0: - print "ERROR: operation Failed" - exit(1) - - - -if __name__ == "__main__": - main(sys.argv[1:]) - - |