Skip to content

Commit

Permalink
NAS-123274 / 23.10 / Remove usages of CoreService for getting disk te…
Browse files Browse the repository at this point in the history
…mperatures (#8503)

* NAS-123274: Remove usages of CoreService for getting disk temperatures

* NAS-123274: Fix remarks

* NAS-123274: Fix duplicate interval

---------

Co-authored-by: Boris Vasilenko <bvasilenko@ixsystems.com>
  • Loading branch information
bvasilenko and Boris Vasilenko authored Aug 11, 2023
1 parent 7af1be3 commit 3bc8ef3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 41 deletions.
7 changes: 0 additions & 7 deletions src/app/interfaces/events/disk-events.interface.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { EnclosureView } from 'app/interfaces/enclosure.interface';
import { DriveTray } from 'app/pages/system/view-enclosure/classes/drivetray';
import { Temperature } from 'app/services/disk-temperature.service';

export interface DiskTemperaturesEvent {
name: 'DiskTemperatures';
sender: unknown;
data: Temperature;
}

export interface DriveSelectedEvent {
name: 'DriveSelected';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
EnclosureDisksComponent,
} from 'app/pages/system/view-enclosure/components/enclosure-disks/enclosure-disks.component';
import { EnclosureStore } from 'app/pages/system/view-enclosure/stores/enclosure-store.service';
import { CoreService } from 'app/services/core-service/core.service';
import { DialogService } from 'app/services/dialog.service';
import { DiskTemperatureService } from 'app/services/disk-temperature.service';
import { ThemeService } from 'app/services/theme/theme.service';
Expand All @@ -38,7 +37,6 @@ export class EnclosureDisksMiniComponent extends EnclosureDisksComponent {
}

constructor(
protected core: CoreService,
public cdr: ChangeDetectorRef,
public dialogService: DialogService,
protected translate: TranslateService,
Expand All @@ -50,7 +48,6 @@ export class EnclosureDisksMiniComponent extends EnclosureDisksComponent {
protected enclosureStore: EnclosureStore,
) {
super(
core,
cdr,
dialogService,
translate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ import {
Enclosure, EnclosureElement, EnclosureSlot, EnclosureView,
} from 'app/interfaces/enclosure.interface';
import { CoreEvent } from 'app/interfaces/events';
import {
CanvasExtractEvent,
DiskTemperaturesEvent,
DriveSelectedEvent,
} from 'app/interfaces/events/disk-events.interface';
import { CanvasExtractEvent, DriveSelectedEvent } from 'app/interfaces/events/disk-events.interface';
import { LabelDrivesEvent } from 'app/interfaces/events/label-drives-event.interface';
import { Pool } from 'app/interfaces/pool.interface';
import { Disk, TopologyDisk } from 'app/interfaces/storage.interface';
Expand Down Expand Up @@ -58,7 +54,6 @@ import {
import { SystemProfile } from 'app/pages/system/view-enclosure/components/view-enclosure/view-enclosure.component';
import { ViewConfig } from 'app/pages/system/view-enclosure/interfaces/view.config';
import { EnclosureState, EnclosureStore } from 'app/pages/system/view-enclosure/stores/enclosure-store.service';
import { CoreService } from 'app/services/core-service/core.service';
import { DialogService } from 'app/services/dialog.service';
import { DiskTemperatureService, Temperature } from 'app/services/disk-temperature.service';
import { ThemeService } from 'app/services/theme/theme.service';
Expand Down Expand Up @@ -278,7 +273,6 @@ export class EnclosureDisksComponent implements AfterContentInit, OnDestroy {
readonly EnclosureLocation = EnclosureLocation;

constructor(
protected core: CoreService,
public cdr: ChangeDetectorRef,
public dialogService: DialogService,
protected translate: TranslateService,
Expand All @@ -292,11 +286,11 @@ export class EnclosureDisksComponent implements AfterContentInit, OnDestroy {
this.themeUtils = new ThemeUtils();
this.diskTemperatureService.listenForTemperatureUpdates();

core.register({ observerClass: this, eventName: 'DiskTemperatures' }).pipe(untilDestroyed(this)).subscribe((evt: DiskTemperaturesEvent) => {
this.diskTemperatureService.temperature$.pipe(untilDestroyed(this)).subscribe((data) => {
const chassisView: ChassisView = this.chassisView && this.view === 'rear' ? this.chassis?.rear : this.chassis?.front;
if (!this.chassis || !chassisView?.driveTrayObjects) { return; }

const clone: Temperature = { ...evt.data };
const clone: Temperature = { ...data };
clone.values = {};
clone.keys = [];

Expand All @@ -309,7 +303,7 @@ export class EnclosureDisksComponent implements AfterContentInit, OnDestroy {

if (disk) {
clone.keys.push(disk.name);
clone.values[disk.name] = evt.data.values[disk.name];
clone.values[disk.name] = data.values[disk.name];
}
});
} else {
Expand All @@ -322,7 +316,7 @@ export class EnclosureDisksComponent implements AfterContentInit, OnDestroy {

this.temperatures = clone;
});
core.emit({ name: 'DiskTemperaturesSubscribe', sender: this });
this.diskTemperatureService.diskTemperaturesSubscribe();

this.store$.select(selectTheme).pipe(
filter(Boolean),
Expand Down Expand Up @@ -438,8 +432,7 @@ export class EnclosureDisksComponent implements AfterContentInit, OnDestroy {

// Component Cleanup
ngOnDestroy(): void {
this.core.emit({ name: 'DiskTemperaturesUnsubscribe', sender: this });
this.core.unregister({ observerClass: this });
this.diskTemperatureService.diskTemperaturesUnsubscribe();
this.destroyAllEnclosures();
this.app.stage.destroy(true);
this.app.destroy(true);
Expand Down
47 changes: 29 additions & 18 deletions src/app/services/disk-temperature.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Injectable, OnDestroy } from '@angular/core';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { map, Subject } from 'rxjs';
import { map, Observable, Subject } from 'rxjs';
import { DiskType } from 'app/enums/disk-type.enum';
import { Disk, DiskTemperatures } from 'app/interfaces/storage.interface';
import { Interval } from 'app/interfaces/timeout.interface';
import { CoreService } from 'app/services/core-service/core.service';
import { DisksUpdateService } from 'app/services/disks-update.service';
import { WebSocketService } from 'app/services/ws.service';

Expand All @@ -26,27 +25,18 @@ export class DiskTemperatureService implements OnDestroy {

private disksUpdateSubscriptionId: string;

private _temperature$ = new Subject<Temperature>();

get temperature$(): Observable<Temperature> {
return this._temperature$.asObservable();
}

constructor(
protected core: CoreService,
protected websocket: WebSocketService,
private disksUpdateService: DisksUpdateService,
) { }

listenForTemperatureUpdates(): void {
this.core.register({ observerClass: this, eventName: 'DiskTemperaturesSubscribe' }).subscribe(() => {
this.subscribers++;
if (!this.broadcast) {
this.start();
}
});

this.core.register({ observerClass: this, eventName: 'DiskTemperaturesUnsubscribe' }).subscribe(() => {
this.subscribers--;
if (this.subscribers === 0) {
this.stop();
}
});

this.websocket.call('disk.query', [[], { select: ['name', 'type'] }]).subscribe((disks) => {
this.disks = disks;
if (this.subscribers > 0) this.start();
Expand All @@ -63,10 +53,31 @@ export class DiskTemperatureService implements OnDestroy {
this.disks = disks;
if (this.subscribers > 0) this.start();
});
if (this.disksUpdateSubscriptionId) {
this.disksUpdateService.removeSubscriber(this.disksUpdateSubscriptionId);
}
this.disksUpdateSubscriptionId = this.disksUpdateService.addSubscriber(disksUpdateTrigger$, true);
}

diskTemperaturesSubscribe(): void {
this.subscribers++;
if (!this.broadcast) {
this.start();
}
}

diskTemperaturesUnsubscribe(): void {
this.subscribers--;
if (this.subscribers === 0) {
this.stop();
}
}

start(): void {
if (this.broadcast) {
return;
}

this.fetch(this.disks.map((disk) => disk.name));
this.broadcast = setInterval(() => {
this.fetch(this.disks.map((disk) => disk.name));
Expand All @@ -86,7 +97,7 @@ export class DiskTemperatureService implements OnDestroy {
unit: 'Celsius',
symbolText: '°',
};
this.core.emit({ name: 'DiskTemperatures', data, sender: this });
this._temperature$.next(data);
});
}

Expand Down

0 comments on commit 3bc8ef3

Please sign in to comment.