Skip to content

Commit f1e983c

Browse files
Merge pull request #2851 from RedisInsight/feature/RI-5220_display_db_information
Feature/ri 5220 display db information
2 parents 56898dc + 8e547ae commit f1e983c

File tree

22 files changed

+327
-69
lines changed

22 files changed

+327
-69
lines changed

redisinsight/api/src/modules/cloud/job/dto/import-database.cloud-job.data.dto.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ApiProperty } from '@nestjs/swagger';
2-
import { IsNotEmpty, IsNumber } from 'class-validator';
2+
import { IsNotEmpty, IsNumber, IsString } from 'class-validator';
33

44
export class ImportDatabaseCloudJobDataDto {
55
@ApiProperty({
@@ -17,4 +17,20 @@ export class ImportDatabaseCloudJobDataDto {
1717
@IsNumber()
1818
@IsNotEmpty()
1919
databaseId: number;
20+
21+
@ApiProperty({
22+
description: 'Subscription region',
23+
type: String,
24+
})
25+
@IsString()
26+
@IsNotEmpty()
27+
region: string;
28+
29+
@ApiProperty({
30+
description: 'Subscription provider',
31+
type: String,
32+
})
33+
@IsString()
34+
@IsNotEmpty()
35+
provider: string;
2036
}

redisinsight/api/src/modules/cloud/job/exceptions/cloud-database-already-exists-free.exception.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CustomErrorCodes } from 'src/constants';
55
export class CloudDatabaseAlreadyExistsFreeException extends HttpException {
66
constructor(
77
message = ERROR_MESSAGES.CLOUD_DATABASE_ALREADY_EXISTS_FREE,
8-
options?: HttpExceptionOptions & { subscriptionId?: number, databaseId?: number },
8+
options?: HttpExceptionOptions & { subscriptionId?: number, databaseId?: number, region?: string, provider?: string },
99
) {
1010
const response = {
1111
message,
@@ -15,6 +15,8 @@ export class CloudDatabaseAlreadyExistsFreeException extends HttpException {
1515
resource: {
1616
subscriptionId: options?.subscriptionId,
1717
databaseId: options?.databaseId,
18+
region: options?.region,
19+
provider: options?.provider,
1820
},
1921
};
2022

redisinsight/api/src/modules/cloud/job/jobs/cloud-job.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export class CloudJobOptions {
2424
stateCallbacks?: ((self: CloudJob) => any)[] = [];
2525

2626
name?: CloudJobName;
27+
28+
child?: boolean;
2729
}
2830

2931
export abstract class CloudJob {
@@ -57,18 +59,22 @@ export abstract class CloudJob {
5759
}
5860

5961
this.debounce = debounce(() => {
60-
try {
61-
(this.options?.stateCallbacks || []).forEach((cb) => {
62-
cb?.(this)?.catch?.(() => {});
63-
});
64-
} catch (e) {
65-
// silently ignore callback
66-
}
62+
this.triggerChangeStateCallbacks();
6763
}, 1_000, {
6864
maxWait: 2_000,
6965
});
7066
}
7167

68+
private triggerChangeStateCallbacks() {
69+
try {
70+
(this.options?.stateCallbacks || []).forEach((cb) => {
71+
cb?.(this)?.catch?.(() => {});
72+
});
73+
} catch (e) {
74+
// silently ignore callback
75+
}
76+
}
77+
7278
public async run() {
7379
try {
7480
this.changeState({
@@ -127,8 +133,9 @@ export abstract class CloudJob {
127133
return new TargetJob(
128134
{
129135
...this.options,
130-
stateCallbacks: [() => this.changeState()],
131136
...options,
137+
stateCallbacks: [() => this.changeState()],
138+
child: true,
132139
},
133140
data,
134141
this.dependencies,
@@ -154,7 +161,11 @@ export abstract class CloudJob {
154161
protected changeState(state = {}) {
155162
Object.entries(state).forEach(([key, value]) => { this[key] = value; });
156163

157-
this.debounce();
164+
if (this.options.child) {
165+
this.triggerChangeStateCallbacks();
166+
} else {
167+
this.debounce();
168+
}
158169
}
159170

160171
protected checkSignal() {

redisinsight/api/src/modules/cloud/job/jobs/create-free-database.cloud-job.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ export class CreateFreeDatabaseCloudJob extends CloudJob {
128128
timeout: cloudConfig.cloudDatabaseConnectionTimeout,
129129
});
130130

131-
this.result = { resourceId: database.id };
131+
this.result = {
132+
resourceId: database.id,
133+
region: freeSubscription?.region,
134+
provider: freeSubscription?.provider,
135+
};
132136

133137
this.changeState({ status: CloudJobStatus.Finished });
134138

redisinsight/api/src/modules/cloud/job/jobs/create-free-subscription-and-database.cloud-job.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { CloudCapiKeyService } from 'src/modules/cloud/capi-key/cloud-capi-key.s
1212
import { CloudSubscription } from 'src/modules/cloud/subscription/models';
1313

1414
export class CreateFreeSubscriptionAndDatabaseCloudJob extends CloudJob {
15-
protected name = CloudJobName.CreateFreeDatabase;
15+
protected name = CloudJobName.CreateFreeSubscriptionAndDatabase;
1616

1717
constructor(
1818
readonly options: CloudJobOptions,
@@ -62,7 +62,11 @@ export class CreateFreeSubscriptionAndDatabaseCloudJob extends CloudJob {
6262
this.options,
6363
);
6464

65-
this.result = { resourceId: database.id };
65+
this.result = {
66+
resourceId: database.id,
67+
region: freeSubscription?.region,
68+
provider: freeSubscription?.provider,
69+
};
6670

6771
this.changeState({ status: CloudJobStatus.Finished });
6872

redisinsight/api/src/modules/cloud/job/jobs/create-free-subscription.cloud-job.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export class CreateFreeSubscriptionCloudJob extends CloudJob {
7070
throw new CloudDatabaseAlreadyExistsFreeException(undefined, {
7171
subscriptionId: freeSubscription.id,
7272
databaseId: databases[0].databaseId,
73+
region: freeSubscription?.region,
74+
provider: freeSubscription?.provider,
7375
});
7476
}
7577

redisinsight/api/src/modules/cloud/job/jobs/import-free-database.cloud-job.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ import { CloudCapiKeyService } from 'src/modules/cloud/capi-key/cloud-capi-key.s
1717
const cloudConfig = config.get('cloud');
1818

1919
export class ImportFreeDatabaseCloudJob extends CloudJob {
20-
protected name = CloudJobName.CreateFreeDatabase;
20+
protected name = CloudJobName.ImportFreeDatabase;
2121

2222
constructor(
2323
readonly options: CloudJobOptions,
2424
private readonly data: {
2525
subscriptionId: number,
2626
databaseId: number,
27+
region: string,
28+
provider: string,
2729
},
2830
protected readonly dependencies: {
2931
cloudDatabaseCapiService: CloudDatabaseCapiService,
@@ -84,7 +86,11 @@ export class ImportFreeDatabaseCloudJob extends CloudJob {
8486
timeout: cloudConfig.cloudDatabaseConnectionTimeout,
8587
});
8688

87-
this.result = { resourceId: database.id };
89+
this.result = {
90+
resourceId: database.id,
91+
region: this.data?.region,
92+
provider: this.data?.provider,
93+
};
8894

8995
this.changeState({ status: CloudJobStatus.Finished });
9096

Lines changed: 59 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)