|
|
@@ -65,6 +65,38 @@ class ElasticsearchDelegator {
|
|
|
this.indexName = indexName;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * return information object to connect to ES
|
|
|
+ * @return {object} { host, httpAuth, indexName}
|
|
|
+ */
|
|
|
+ getConnectionInfo() {
|
|
|
+ let indexName = 'crowi';
|
|
|
+ let host = this.esUri;
|
|
|
+ let httpAuth = '';
|
|
|
+
|
|
|
+ const elasticsearchUri = this.configManager.getConfig('crowi', 'app:elasticsearchUri');
|
|
|
+
|
|
|
+ const url = new URL(elasticsearchUri);
|
|
|
+ if (url.pathname !== '/') {
|
|
|
+ host = `${url.protocol}//${url.host}`;
|
|
|
+ indexName = url.pathname.substring(1); // omit heading slash
|
|
|
+
|
|
|
+ if (url.username != null && url.password != null) {
|
|
|
+ httpAuth = `${url.username}:${url.password}`;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ host,
|
|
|
+ httpAuth,
|
|
|
+ indexName,
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ async init() {
|
|
|
+ return this.initIndices();
|
|
|
+ }
|
|
|
+
|
|
|
async getInfo() {
|
|
|
const info = await this.client.nodes.info();
|
|
|
if (!info._nodes || !info.nodes) {
|
|
|
@@ -94,38 +126,28 @@ class ElasticsearchDelegator {
|
|
|
return { esVersion, esNodeInfos };
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * return information object to connect to ES
|
|
|
- * @return {object} { host, httpAuth, indexName}
|
|
|
- */
|
|
|
- getConnectionInfo() {
|
|
|
- let indexName = 'crowi';
|
|
|
- let host = this.esUri;
|
|
|
- let httpAuth = '';
|
|
|
+ async getInfoForAdmin() {
|
|
|
+ const { client, indexName, aliasName } = this;
|
|
|
|
|
|
- const elasticsearchUri = this.configManager.getConfig('crowi', 'app:elasticsearchUri');
|
|
|
+ const tmpIndexName = `${indexName}-tmp`;
|
|
|
|
|
|
- const url = new URL(elasticsearchUri);
|
|
|
- if (url.pathname !== '/') {
|
|
|
- host = `${url.protocol}//${url.host}`;
|
|
|
- indexName = url.pathname.substring(1); // omit heading slash
|
|
|
+ const isExistsMainIndex = await client.indices.exists({ index: indexName });
|
|
|
+ const isMainIndexHasAlias = isExistsMainIndex && await client.indices.existsAlias({ name: aliasName, index: indexName });
|
|
|
|
|
|
- if (url.username != null && url.password != null) {
|
|
|
- httpAuth = `${url.username}:${url.password}`;
|
|
|
- }
|
|
|
- }
|
|
|
+ const isExistsTmpIndex = await client.indices.exists({ index: tmpIndexName });
|
|
|
+ const isTmpIndexHasAlias = isExistsTmpIndex && await client.indices.existsAlias({ name: aliasName, index: tmpIndexName });
|
|
|
+
|
|
|
+ const isNormalized = isExistsMainIndex && isMainIndexHasAlias && !isExistsTmpIndex && !isTmpIndexHasAlias;
|
|
|
|
|
|
return {
|
|
|
- host,
|
|
|
- httpAuth,
|
|
|
- indexName,
|
|
|
+ isExistsMainIndex,
|
|
|
+ isExistsTmpIndex,
|
|
|
+ isMainIndexHasAlias,
|
|
|
+ isTmpIndexHasAlias,
|
|
|
+ isNormalized,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- async init() {
|
|
|
- return this.initIndices();
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* build index
|
|
|
*/
|