Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/i18n/src/locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2247,6 +2247,18 @@ const translations: Catalog = {
'Returns a document with an `enabled: <boolean>` field indicating whether the cluster is configured as embedded config server cluster. If it is, then the config shard host and tags are also returned.',
example: 'sh.isConfigShardEnabled()',
},
shardDrainingStatus: {
link: 'https://mongodb.com/docs/manual/reference/method/sh.shardDrainingStatus',
description:
'Returns the draining status of the given shard, or of all draining shards if no shard is specified. Uses the shardDrainingStatus admin command.',
example: 'sh.shardDrainingStatus(shardId?)',
},
getTransitionToDedicatedConfigServerStatus: {
link: 'https://mongodb.com/docs/manual/reference/method/sh.getTransitionToDedicatedConfigServerStatus',
description:
'Returns the draining status of the config shard while transitioning to a dedicated config server. Uses the getTransitionToDedicatedConfigServerStatus admin command.',
example: 'sh.getTransitionToDedicatedConfigServerStatus()',
},
Comment on lines +2250 to +2261

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes will require docs update as they do not exist today.

},
},
},
Expand Down
113 changes: 113 additions & 0 deletions packages/shell-api/src/shard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2392,6 +2392,119 @@ describe('Shard', function () {
expect(warnSpy.calledOnce).to.be.true;
});
});

describe('shardDrainingStatus', function () {
this.beforeEach(function () {
serviceProvider.runCommandWithCheck.resolves({
ok: 1,
msg: 'isdbgrid',
});
});

it('calls serviceProvider.runCommandWithCheck without a shardId', async function () {
await shard.shardDrainingStatus();

expect(serviceProvider.runCommandWithCheck).to.have.been.calledWith(
ADMIN_DB,
{
shardDrainingStatus: 1,
}
);
});

it('calls serviceProvider.runCommandWithCheck with a shardId', async function () {
await shard.shardDrainingStatus('shard1');

expect(serviceProvider.runCommandWithCheck).to.have.been.calledWith(
ADMIN_DB,
{
shardDrainingStatus: 'shard1',
}
);
});

it('returns whatever serviceProvider.runCommandWithCheck returns', async function () {
serviceProvider.runCommandWithCheck
.onCall(0)
.resolves({ ok: 1, msg: 'isdbgrid' });
const expectedResult = { ok: 1, state: 'started' };
serviceProvider.runCommandWithCheck.onCall(1).resolves(expectedResult);
const result = await shard.shardDrainingStatus('shard1');
expect(result).to.deep.equal(expectedResult);
});

it('throws if serviceProvider.runCommandWithCheck rejects', async function () {
serviceProvider.runCommandWithCheck
.onCall(0)
.resolves({ ok: 1, msg: 'isdbgrid' });
const expectedError = new Error('unreachable');
serviceProvider.runCommandWithCheck.onCall(1).rejects(expectedError);
const caughtError = await shard
.shardDrainingStatus('shard1')
.catch((e) => e);
expect(caughtError).to.equal(expectedError);
});

it('throws if not mongos', async function () {
serviceProvider.runCommandWithCheck.resolves({
ok: 1,
msg: 'not dbgrid',
});
await shard.shardDrainingStatus();
expect(warnSpy.calledOnce).to.be.true;
});
});

describe('getTransitionToDedicatedConfigServerStatus', function () {
this.beforeEach(function () {
serviceProvider.runCommandWithCheck.resolves({
ok: 1,
msg: 'isdbgrid',
});
});

it('calls serviceProvider.runCommandWithCheck', async function () {
await shard.getTransitionToDedicatedConfigServerStatus();

expect(serviceProvider.runCommandWithCheck).to.have.been.calledWith(
ADMIN_DB,
{
getTransitionToDedicatedConfigServerStatus: 1,
}
);
});

it('returns whatever serviceProvider.runCommandWithCheck returns', async function () {
serviceProvider.runCommandWithCheck
.onCall(0)
.resolves({ ok: 1, msg: 'isdbgrid' });
const expectedResult = { ok: 1, state: 'started' };
serviceProvider.runCommandWithCheck.onCall(1).resolves(expectedResult);
const result = await shard.getTransitionToDedicatedConfigServerStatus();
expect(result).to.deep.equal(expectedResult);
});

it('throws if serviceProvider.runCommandWithCheck rejects', async function () {
serviceProvider.runCommandWithCheck
.onCall(0)
.resolves({ ok: 1, msg: 'isdbgrid' });
const expectedError = new Error('unreachable');
serviceProvider.runCommandWithCheck.onCall(1).rejects(expectedError);
const caughtError = await shard
.getTransitionToDedicatedConfigServerStatus()
.catch((e) => e);
expect(caughtError).to.equal(expectedError);
});

it('throws if not mongos', async function () {
serviceProvider.runCommandWithCheck.resolves({
ok: 1,
msg: 'not dbgrid',
});
await shard.getTransitionToDedicatedConfigServerStatus();
expect(warnSpy.calledOnce).to.be.true;
});
});
});

describe('integration', function () {
Expand Down
29 changes: 29 additions & 0 deletions packages/shell-api/src/shard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,4 +893,33 @@ export default class Shard<
...(configShard.tags && { tags: configShard.tags }),
};
}

@serverVersions(['8.2.0', ServerVersions.latest])
@apiVersions([])
@returnsPromise
async shardDrainingStatus(shardId?: string): Promise<Document> {
assertArgsDefinedType(
[shardId],
[[undefined, 'string']],
'Shard.shardDrainingStatus'
);
this._emitShardApiCall('shardDrainingStatus', { shardId });
await getConfigDB(this._database);

return this._database._runAdminReadCommand({
shardDrainingStatus: shardId ?? 1,
});
}

@serverVersions(['8.3.0', ServerVersions.latest])
@apiVersions([])
@returnsPromise
async getTransitionToDedicatedConfigServerStatus(): Promise<Document> {
this._emitShardApiCall('getTransitionToDedicatedConfigServerStatus', {});
await getConfigDB(this._database);

return this._database._runAdminReadCommand({
getTransitionToDedicatedConfigServerStatus: 1,
});
}
}
Loading