Skip to content

Commit

Permalink
MB-49189 Take "storageTotals" from a new "pools/default" request.
Browse files Browse the repository at this point in the history
By applying this patch the memory quota used in Bucket Dialog
is synced with the latest add/edit bucket.

Change-Id: Icf37fa9dd8cead52028886f5615e64f5635a007f
Reviewed-on: https://review.couchbase.org/c/ns_server/+/165535
Tested-by: Raluca Lupu <raluca.lupu@couchbase.com>
Reviewed-by: Pavel Blagodov <stochmail@gmail.com>
  • Loading branch information
lukaisthewolf committed Nov 16, 2021
1 parent 893837b commit e3430f0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
3 changes: 0 additions & 3 deletions priv/public/ui/app/mn.admin.service.js
Expand Up @@ -103,9 +103,6 @@ class MnAdminService {
this.stream.maxBucketCount =
this.stream.getPoolsDefault.pipe(pluck("maxBucketCount"), distinctUntilChanged());

this.stream.storageTotals =
this.stream.getPoolsDefault.pipe(pluck("storageTotals"), distinctUntilChanged());

this.stream.uiSessionTimeout =
this.stream.getPoolsDefault.pipe(pluck("uiSessionTimeout"), distinctUntilChanged());

Expand Down
2 changes: 1 addition & 1 deletion priv/public/ui/app/mn.bucket.dialog.component.js
Expand Up @@ -90,7 +90,7 @@ class MnBucketDialogComponent extends MnLifeCycleHooksToStream {

let formData = this.bucket ?
this.mnBucketsService.createBucketFormData(this.bucket) :
this.mnBucketsService.stream.initialFormData;
this.mnBucketsService.createInitialFormData(this.storageTotals);

this.form = this.mnFormService.create(this)
.setFormGroup(this.formBuilder.group({
Expand Down
12 changes: 6 additions & 6 deletions priv/public/ui/app/mn.buckets.component.js
Expand Up @@ -10,7 +10,7 @@ licenses/APL2.txt.

import {Component, ChangeDetectionStrategy} from '@angular/core';
import {Subject, BehaviorSubject, combineLatest} from 'rxjs';
import {map, takeUntil, withLatestFrom} from 'rxjs/operators';
import {map, takeUntil, switchMap} from 'rxjs/operators';
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';

import {MnLifeCycleHooksToStream} from "./mn.core.js";
Expand Down Expand Up @@ -62,14 +62,15 @@ class MnBucketsComponent extends MnLifeCycleHooksToStream {

this.onAddBucketClick = new Subject();
this.onAddBucketClick
.pipe(withLatestFrom(mnAdminService.stream.storageTotals),
.pipe(switchMap(() => mnAdminService.getPoolsDefault()),
takeUntil(this.mnOnDestroy))
.subscribe(([,storageTotals]) => {
let ram = storageTotals.ram;
.subscribe((resp) => {
let ram = resp.storageTotals.ram;
if (!ram || ram.quotaTotal === ram.quotaUsed) {
this.modalService.open(MnBucketFullDialogComponent);
} else {
this.modalService.open(MnBucketDialogComponent);
let ref = this.modalService.open(MnBucketDialogComponent);
ref.componentInstance.storageTotals = resp.storageTotals;
}
});

Expand All @@ -94,5 +95,4 @@ class MnBucketsComponent extends MnLifeCycleHooksToStream {
trackBy(index, bucket) {
return bucket.name;
}

}
18 changes: 11 additions & 7 deletions priv/public/ui/app/mn.buckets.service.js
Expand Up @@ -46,6 +46,7 @@ class MnBucketsService {
this.http = http;
this.modalService = modalService;
this.mnHelperService = mnHelperService;
this.mnAdminService = mnAdminService;
this.mnSettingsAutoCompactionService = mnSettingsAutoCompactionService;

this.stream.bucketsUri = mnAdminService.stream.getPoolsDefault
Expand Down Expand Up @@ -85,10 +86,6 @@ class MnBucketsService {
shareReplay({refCount: true, bufferSize: 1}));

this.stream.defaultAutoCompactionData = mnSettingsAutoCompactionService.stream.settingsSource;
this.stream.initialFormData = this.stream.defaultAutoCompactionData
.pipe(withLatestFrom(mnAdminService.stream.storageTotals,
mnAdminService.stream.reallyActiveKVNodes),
map(this.unpackData.bind(this)));

this.stream.deleteBucket =
new MnHttpRequest(this.deleteBucket.bind(this))
Expand Down Expand Up @@ -362,11 +359,12 @@ class MnBucketsService {
permissions.cluster.bucket[bucketName].flush;
}

unpackData([autoCompactionSettings, totals, reallyActiveKVNodes]) {
unpackData([autoCompactionSettings, reallyActiveKVNodes], storageTotals) {
let ramQuota = 0;
if (totals.ram) {
let ram = storageTotals.ram;
if (ram) {
ramQuota = Math.floor(
(totals.ram.quotaTotal - totals.ram.quotaUsed) / reallyActiveKVNodes.length);
(ram.quotaTotal - ram.quotaUsed) / reallyActiveKVNodes.length);
}

return {
Expand Down Expand Up @@ -428,6 +426,12 @@ class MnBucketsService {
.pipe(map(v => this.getBucketFormData(v, bucket)));
}

createInitialFormData(storageTotals) {
return this.stream.defaultAutoCompactionData
.pipe(withLatestFrom(this.mnAdminService.stream.reallyActiveKVNodes),
map(v => this.unpackData(v, storageTotals)));
}

get(url) {
return this.http.get(
url,
Expand Down

0 comments on commit e3430f0

Please sign in to comment.