@cumulus/es-client 12.0.0 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bootstrap.js CHANGED
@@ -56,7 +56,7 @@ async function findMissingMappings(esClient, index, newMappings) {
56
56
  });
57
57
  }
58
58
 
59
- async function removeIndexAsAlias(esClient, alias) {
59
+ async function removeIndexAsAlias(esClient, alias, removeAliasConflict) {
60
60
  // If the alias already exists as an index, remove it
61
61
  // We can't do a simple exists check here, because it'll return true if the alias
62
62
  // is actually an alias assigned to an index. We do a get and check that the alias
@@ -67,7 +67,11 @@ async function removeIndexAsAlias(esClient, alias) {
67
67
  );
68
68
 
69
69
  if (existingIndex && existingIndex[alias]) {
70
- logger.info(`Deleting alias as index: ${alias}`);
70
+ logger.warn(`Conflicting index for alias ${alias} detected!`);
71
+ if (!removeAliasConflict) {
72
+ throw new Error('Aborting ES recreation as configuration does not allow removal of index');
73
+ }
74
+ logger.warn(`Deleting alias as index: ${alias}`);
71
75
  await esClient.indices.delete({ index: alias });
72
76
  }
73
77
  }
@@ -76,12 +80,21 @@ async function removeIndexAsAlias(esClient, alias) {
76
80
  * Initialize elastic search. If the index does not exist, create it with an alias.
77
81
  * If an index exists but is not aliased, alias the index.
78
82
  *
79
- * @param {string} host - elastic search host
80
- * @param {string} index - name of the index to create if does not exist, defaults to 'cumulus'
81
- * @param {string} alias - alias name for the index, defaults to 'cumulus'
83
+ * @param {Object} params
84
+ * @param {string} params.host - elastic search host
85
+ * @param {string} params.index - name of the index to create if does not exist,
86
+ * defaults to 'cumulus'
87
+ * @param {string} params.alias - alias name for the index, defaults to 'cumulus'
88
+ * @param {boolean} params.removeAliasConflict - Flag to allow/disallow deletion of conflicting
89
+ * 'cumulus-alias' index
82
90
  * @returns {Promise} undefined
83
91
  */
84
- async function bootstrapElasticSearch(host, index = 'cumulus', alias = defaultIndexAlias) {
92
+ async function bootstrapElasticSearch({
93
+ host,
94
+ index = 'cumulus',
95
+ alias = defaultIndexAlias,
96
+ removeAliasConflict = true,
97
+ }) {
85
98
  if (!host) return;
86
99
 
87
100
  const esClient = await Search.es(host);
@@ -93,7 +106,7 @@ async function bootstrapElasticSearch(host, index = 'cumulus', alias = defaultIn
93
106
  },
94
107
  });
95
108
 
96
- await removeIndexAsAlias(esClient, alias);
109
+ await removeIndexAsAlias(esClient, alias, removeAliasConflict);
97
110
 
98
111
  let aliasedIndex = index;
99
112
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cumulus/es-client",
3
- "version": "12.0.0",
3
+ "version": "13.0.0",
4
4
  "description": "Utilities for working with Elasticsearch",
5
5
  "keywords": [
6
6
  "CUMULUS",
@@ -30,10 +30,10 @@
30
30
  "author": "Cumulus Authors",
31
31
  "license": "Apache-2.0",
32
32
  "dependencies": {
33
- "@cumulus/common": "12.0.0",
34
- "@cumulus/errors": "12.0.0",
35
- "@cumulus/logger": "12.0.0",
36
- "@cumulus/message": "12.0.0",
33
+ "@cumulus/common": "13.0.0",
34
+ "@cumulus/errors": "13.0.0",
35
+ "@cumulus/logger": "13.0.0",
36
+ "@cumulus/message": "13.0.0",
37
37
  "@elastic/elasticsearch": "^5.6.20",
38
38
  "aws-elasticsearch-connector": "8.2.0",
39
39
  "aws-sdk": "^2.585.0",
@@ -42,9 +42,9 @@
42
42
  "p-limit": "^1.2.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@cumulus/aws-client": "12.0.0",
46
- "@cumulus/test-data": "12.0.0",
45
+ "@cumulus/aws-client": "13.0.0",
46
+ "@cumulus/test-data": "13.0.0",
47
47
  "p-each-series": "^2.1.0"
48
48
  },
49
- "gitHead": "2d84198510f37d64444715736b8b08360f61c766"
49
+ "gitHead": "ba43ea3bfdfcacfff052770ed2fd357eb9dadb58"
50
50
  }
package/testUtils.js CHANGED
@@ -8,7 +8,11 @@ const createTestIndex = async () => {
8
8
  const esIndex = randomString();
9
9
  const esAlias = randomString();
10
10
  process.env.ES_INDEX = esIndex;
11
- await bootstrap.bootstrapElasticSearch('fakehost', esIndex, esAlias);
11
+ await bootstrap.bootstrapElasticSearch({
12
+ host: 'fakehost',
13
+ index: esIndex,
14
+ alias: esAlias,
15
+ });
12
16
  const esClient = await Search.es('fakehost');
13
17
  return { esIndex, esClient };
14
18
  };