From a32bc41c9fdf97bfbbea28ffa0b7db80ca0852f3 Mon Sep 17 00:00:00 2001 From: manasvis Date: Fri, 10 Jun 2022 21:28:02 +0000 Subject: [PATCH] [Non-Inclusive Language] Deprecate isDevClusterMaster in favor of isDevClusterManager As part of the meta issue https://github.com/opensearch-project/OpenSearch/issues/2589 to track the plan and progress of applying inclusive naming across OpenSearch Repositories Every repository that uses non-inclusive words should replace all the non-inclusive usages in the code base. In this change we are deprecating the terminology "isDevClusterMaster" and adding "isDevClusterManager" for future usages. Signed-off-by: manasvis --- packages/osd-config/src/__mocks__/env.ts | 2 ++ .../osd-config/src/__snapshots__/env.test.ts.snap | 6 ++++++ packages/osd-config/src/env.test.ts | 1 + packages/osd-config/src/env.ts | 12 +++++++++++- src/core/server/bootstrap.ts | 5 +++-- src/core/server/http/http_service.test.ts | 8 +++++++- src/core/server/http/http_service.ts | 5 ++++- src/core/server/legacy/legacy_service.test.ts | 2 ++ src/core/server/legacy/legacy_service.ts | 2 +- src/core/server/plugins/plugins_service.ts | 4 +++- src/core/test_helpers/osd_server.ts | 1 + src/legacy/server/logging/rotate/index.ts | 4 ++-- src/legacy/server/logging/rotate/log_rotator.ts | 4 ++-- 13 files changed, 45 insertions(+), 11 deletions(-) diff --git a/packages/osd-config/src/__mocks__/env.ts b/packages/osd-config/src/__mocks__/env.ts index e74fdbe0792e..a9225b1e5989 100644 --- a/packages/osd-config/src/__mocks__/env.ts +++ b/packages/osd-config/src/__mocks__/env.ts @@ -54,5 +54,7 @@ export function getEnvOptions(options: DeepPartial = {}): EnvOptions }, isDevClusterMaster: options.isDevClusterMaster !== undefined ? options.isDevClusterMaster : false, + isDevClusterManager: + options.isDevClusterManager !== undefined ? options.isDevClusterManager : false, }; } diff --git a/packages/osd-config/src/__snapshots__/env.test.ts.snap b/packages/osd-config/src/__snapshots__/env.test.ts.snap index 74a59904411e..40dbfc4d4146 100644 --- a/packages/osd-config/src/__snapshots__/env.test.ts.snap +++ b/packages/osd-config/src/__snapshots__/env.test.ts.snap @@ -21,6 +21,7 @@ Env { "/some/other/path/some-opensearch-dashboards.yml", ], "homeDir": "/test/opensearchDashboardsRoot", + "isDevClusterManager": false, "isDevClusterMaster": false, "logDir": "/test/opensearchDashboardsRoot/log", "mode": Object { @@ -64,6 +65,7 @@ Env { "/some/other/path/some-opensearch-dashboards.yml", ], "homeDir": "/test/opensearchDashboardsRoot", + "isDevClusterManager": false, "isDevClusterMaster": false, "logDir": "/test/opensearchDashboardsRoot/log", "mode": Object { @@ -106,6 +108,7 @@ Env { "/test/cwd/config/opensearch_dashboards.yml", ], "homeDir": "/test/opensearchDashboardsRoot", + "isDevClusterManager": true, "isDevClusterMaster": true, "logDir": "/test/opensearchDashboardsRoot/log", "mode": Object { @@ -148,6 +151,7 @@ Env { "/some/other/path/some-opensearch-dashboards.yml", ], "homeDir": "/test/opensearchDashboardsRoot", + "isDevClusterManager": false, "isDevClusterMaster": false, "logDir": "/test/opensearchDashboardsRoot/log", "mode": Object { @@ -190,6 +194,7 @@ Env { "/some/other/path/some-opensearch-dashboards.yml", ], "homeDir": "/test/opensearchDashboardsRoot", + "isDevClusterManager": false, "isDevClusterMaster": false, "logDir": "/test/opensearchDashboardsRoot/log", "mode": Object { @@ -232,6 +237,7 @@ Env { "/some/other/path/some-opensearch-dashboards.yml", ], "homeDir": "/some/home/dir", + "isDevClusterManager": false, "isDevClusterMaster": false, "logDir": "/some/home/dir/log", "mode": Object { diff --git a/packages/osd-config/src/env.test.ts b/packages/osd-config/src/env.test.ts index 65f44fef1feb..2be3ba0c6fde 100644 --- a/packages/osd-config/src/env.test.ts +++ b/packages/osd-config/src/env.test.ts @@ -59,6 +59,7 @@ test('correctly creates default environment in dev mode.', () => { getEnvOptions({ configs: ['/test/cwd/config/opensearch_dashboards.yml'], isDevClusterMaster: true, + isDevClusterManager: true, }) ); diff --git a/packages/osd-config/src/env.ts b/packages/osd-config/src/env.ts index 913abe3b3c96..054e73e8d4c2 100644 --- a/packages/osd-config/src/env.ts +++ b/packages/osd-config/src/env.ts @@ -36,7 +36,9 @@ import { PackageInfo, EnvironmentMode } from './types'; export interface EnvOptions { configs: string[]; cliArgs: CliArgs; + /** @deprecated use isDevClusterManager */ isDevClusterMaster: boolean; + isDevClusterManager: boolean; } /** @internal */ @@ -110,11 +112,18 @@ export class Env { public readonly configs: readonly string[]; /** - * Indicates that this OpenSearch Dashboards instance is run as development Node Cluster master. + * Indicates that this OpenSearch Dashboards instance is run as development Node master. * @internal + * @deprecated use isDevClusterManager */ public readonly isDevClusterMaster: boolean; + /** + * Indicates that this OpenSearch Dashboards instance is run as development Node Cluster manager. + * @internal + */ + public readonly isDevClusterManager: boolean; + /** * @internal */ @@ -138,6 +147,7 @@ export class Env { this.cliArgs = Object.freeze(options.cliArgs); this.configs = Object.freeze(options.configs); this.isDevClusterMaster = options.isDevClusterMaster; + this.isDevClusterManager = options.isDevClusterManager; const isDevMode = this.cliArgs.dev || this.cliArgs.envName === 'development'; this.mode = Object.freeze({ diff --git a/src/core/server/bootstrap.ts b/src/core/server/bootstrap.ts index b16d59683043..8defb17d2030 100644 --- a/src/core/server/bootstrap.ts +++ b/src/core/server/bootstrap.ts @@ -29,7 +29,7 @@ */ import chalk from 'chalk'; -import { isMaster } from 'cluster'; +import { isMaster as isClusterManager } from 'cluster'; import { CliArgs, Env, RawConfigService } from './config'; import { Root } from './root'; import { CriticalError } from './errors'; @@ -82,7 +82,8 @@ export async function bootstrap({ const env = Env.createDefault(REPO_ROOT, { configs, cliArgs, - isDevClusterMaster: isMaster && cliArgs.dev && features.isClusterModeSupported, + isDevClusterMaster: isClusterManager && cliArgs.dev && features.isClusterModeSupported, + isDevClusterManager: isClusterManager && cliArgs.dev && features.isClusterModeSupported, }); const rawConfigService = new RawConfigService(env.configs, applyConfigOverrides); diff --git a/src/core/server/http/http_service.test.ts b/src/core/server/http/http_service.test.ts index a261cd7bd3de..bb572b2c2aaf 100644 --- a/src/core/server/http/http_service.test.ts +++ b/src/core/server/http/http_service.test.ts @@ -275,7 +275,13 @@ test('does not start http server if process is dev cluster master', async () => const service = new HttpService({ coreId, configService, - env: Env.createDefault(REPO_ROOT, getEnvOptions({ isDevClusterMaster: true })), + env: Env.createDefault( + REPO_ROOT, + getEnvOptions({ + isDevClusterManager: true, + isDevClusterMaster: true, + }) + ), logger, }); diff --git a/src/core/server/http/http_service.ts b/src/core/server/http/http_service.ts index 6fd900b51363..aa5c402cf197 100644 --- a/src/core/server/http/http_service.ts +++ b/src/core/server/http/http_service.ts @@ -169,7 +169,10 @@ export class HttpService * @internal * */ private shouldListen(config: HttpConfig) { - return !this.coreContext.env.isDevClusterMaster && config.autoListen; + return ( + !(this.coreContext.env.isDevClusterMaster || this.coreContext.env.isDevClusterManager) && + config.autoListen + ); } public async stop() { diff --git a/src/core/server/legacy/legacy_service.test.ts b/src/core/server/legacy/legacy_service.test.ts index 9b67542e5571..f3094a797734 100644 --- a/src/core/server/legacy/legacy_service.test.ts +++ b/src/core/server/legacy/legacy_service.test.ts @@ -374,6 +374,7 @@ describe('once LegacyService is set up in `devClusterMaster` mode', () => { getEnvOptions({ cliArgs: { silent: true, basePath: false }, isDevClusterMaster: true, + isDevClusterManager: true, }) ), logger, @@ -403,6 +404,7 @@ describe('once LegacyService is set up in `devClusterMaster` mode', () => { getEnvOptions({ cliArgs: { quiet: true, basePath: true }, isDevClusterMaster: true, + isDevClusterManager: true, }) ), logger, diff --git a/src/core/server/legacy/legacy_service.ts b/src/core/server/legacy/legacy_service.ts index 574734d18fef..e6bb580ed7af 100644 --- a/src/core/server/legacy/legacy_service.ts +++ b/src/core/server/legacy/legacy_service.ts @@ -155,7 +155,7 @@ export class LegacyService implements CoreService { this.log.debug('starting legacy service'); // Receive initial config and create osdServer/ClusterManager. - if (this.coreContext.env.isDevClusterMaster) { + if (this.coreContext.env.isDevClusterMaster || this.coreContext.env.isDevClusterManager) { await this.createClusterManager(this.legacyRawConfig!); } else { this.osdServer = await this.createOsdServer( diff --git a/src/core/server/plugins/plugins_service.ts b/src/core/server/plugins/plugins_service.ts index 3039cae7d9f7..845bfce4c17f 100644 --- a/src/core/server/plugins/plugins_service.ts +++ b/src/core/server/plugins/plugins_service.ts @@ -137,7 +137,9 @@ export class PluginsService implements CoreService(); - const initialize = config.initialize && !this.coreContext.env.isDevClusterMaster; + const initialize = + config.initialize && + !(this.coreContext.env.isDevClusterMaster || this.coreContext.env.isDevClusterManager); if (initialize) { contracts = await this.pluginsSystem.setupPlugins(deps); this.registerPluginStaticDirs(deps); diff --git a/src/core/test_helpers/osd_server.ts b/src/core/test_helpers/osd_server.ts index d8ffe3b0824d..5c062d76dcac 100644 --- a/src/core/test_helpers/osd_server.ts +++ b/src/core/test_helpers/osd_server.ts @@ -91,6 +91,7 @@ export function createRootWithSettings( ...cliArgs, }, isDevClusterMaster: false, + isDevClusterManager: false, }); return new Root( diff --git a/src/legacy/server/logging/rotate/index.ts b/src/legacy/server/logging/rotate/index.ts index b2820f1c8f85..f323d8c6b526 100644 --- a/src/legacy/server/logging/rotate/index.ts +++ b/src/legacy/server/logging/rotate/index.ts @@ -28,7 +28,7 @@ * under the License. */ -import { isMaster, isWorker } from 'cluster'; +import { isMaster as isClusterManager, isWorker } from 'cluster'; import { Server } from '@hapi/hapi'; import { LogRotator } from './log_rotator'; import { OpenSearchDashboardsConfig } from '../../osd_server'; @@ -43,7 +43,7 @@ export async function setupLoggingRotate(server: Server, config: OpenSearchDashb // We just want to start the logging rotate service once // and we choose to use the master (prod) or the worker server (dev) - if (!isMaster && isWorker && process.env.osdWorkerType !== 'server') { + if (!isClusterManager && isWorker && process.env.osdWorkerType !== 'server') { return; } diff --git a/src/legacy/server/logging/rotate/log_rotator.ts b/src/legacy/server/logging/rotate/log_rotator.ts index f1710cb5775e..7502631d22dd 100644 --- a/src/legacy/server/logging/rotate/log_rotator.ts +++ b/src/legacy/server/logging/rotate/log_rotator.ts @@ -29,7 +29,7 @@ */ import * as chokidar from 'chokidar'; -import { isMaster } from 'cluster'; +import { isMaster as isClusterManager } from 'cluster'; import fs from 'fs'; import { Server } from '@hapi/hapi'; import { throttle } from 'lodash'; @@ -359,7 +359,7 @@ export class LogRotator { } _sendReloadLogConfigSignal() { - if (isMaster) { + if (isClusterManager) { (process as NodeJS.EventEmitter).emit('SIGHUP'); return; }