File

lib/services/aws.service.ts

Description

Service and state effects for AWS service calls.

Index

Methods

Constructor

constructor(dialog: MatDialog, spinnerService: SpinnerService, nshmpService: NshmpService)
Parameters :
Name Type Optional
dialog MatDialog No
spinnerService SpinnerService No
nshmpService NshmpService No

Methods

callJobHistoryService
callJobHistoryService(serviceUrl: string, idControl: FormControl)
Type parameters :
  • U

NGRX effect to call the AWS hazard job history service.

Parameters :
Name Type Optional Description
serviceUrl string No

The service URL to call

idControl FormControl<string> No

The id form control

callTerminateJobService
callTerminateJobService(serviceUrl: string, idControl: FormControl)

NGRX effect to call the AWS hazard terminate job service.

Parameters :
Name Type Optional Description
serviceUrl string No

The service URL to call

idControl FormControl<string> No

The id form control

Returns : any
openTerminateDialog
openTerminateDialog(jobInfo: Response<JobHistoryRequestData | DynamoDBItem>, onTerminateAction: () => void)

NGRX effect to open the terminate job dialog.

Parameters :
Name Type Optional Description
jobInfo Response<JobHistoryRequestData | DynamoDBItem> No

The job info

onTerminateAction function No

The callback funciton on terminate

Returns : void
openTerminateJobDialog
openTerminateJobDialog(data: TerminateJobDialogData)

Open the AWS hazard terminate job dialog.

Parameters :
Name Type Optional Description
data TerminateJobDialogData No

The terminate job dialog data

Returns : void
import {Injectable} from '@angular/core';
import {FormControl} from '@angular/forms';
import {MatDialog} from '@angular/material/dialog';
import {NshmpService} from '@ghsc/nshmp-lib-ng/nshmp';
import {SpinnerService} from '@ghsc/nshmp-template';
import {DynamoDBItem} from '@ghsc/nshmp-utils-ts/libs/aws/run-nshmp-haz';
import {Response} from '@ghsc/nshmp-utils-ts/libs/nshmp-ws-utils';
import {EC2} from 'aws-sdk';
import {Observable} from 'rxjs';
import {map} from 'rxjs/operators';

import {NshmpAwsTerminateJobDialogComponent} from '../components/terminate-job-dialog/terminate-job-dialog.component';
import {JobHistoryRequestData} from '../models/job-history-service.model';
import {TerminateJobRequestData} from '../models/terminate-job.model';
import {TerminateJobDialogData} from '../models/terminate-job-dialog-data.model';

/**
 * Service and state effects for AWS service calls.
 */
@Injectable({
  providedIn: 'root',
})
export class AwsService {
  constructor(
    private dialog: MatDialog,
    private spinnerService: SpinnerService,
    private nshmpService: NshmpService,
  ) {}

  /**
   * NGRX effect to call the AWS hazard job history service.
   *
   * @param serviceUrl The service URL to call
   * @param idControl The id form control
   */
  callJobHistoryService<U extends DynamoDBItem | DynamoDBItem[]>(
    serviceUrl: string,
    idControl: FormControl<string>,
  ): Observable<Response<JobHistoryRequestData, U>> {
    const spinnerRef = this.spinnerService.show('Getting job information');
    const url = `${serviceUrl}/${idControl.getRawValue()}`;

    return this.nshmpService.callService$<Response<JobHistoryRequestData, U>>(url).pipe(
      map(response => {
        spinnerRef.close();
        return response;
      }),
    );
  }

  /**
   * NGRX effect to open the terminate job dialog.
   *
   * @param jobInfo The job info
   * @param onTerminateAction The callback funciton on terminate
   */
  openTerminateDialog(
    jobInfo: Response<JobHistoryRequestData, DynamoDBItem>,
    onTerminateAction: () => unknown,
  ) {
    this.openTerminateJobDialog({
      jobInfo: jobInfo.response,
      onTerminateAction,
    });
  }

  /**
   * NGRX effect to call the AWS hazard terminate job service.
   *
   * @param serviceUrl The service URL to call
   * @param idControl The id form control
   */
  callTerminateJobService(serviceUrl: string, idControl: FormControl<string>) {
    const spinnerRef = this.spinnerService.show(`Terminating job ${idControl.getRawValue()}`);
    const url = `${serviceUrl}/${idControl.getRawValue()}`;

    return this.nshmpService
      .callService$<Response<TerminateJobRequestData, EC2.InstanceStateChangeList>>(url)
      .pipe(
        map(response => {
          spinnerRef.close();
          return response;
        }),
      );
  }

  /**
   * Open the AWS hazard terminate job dialog.
   *
   * @param data The terminate job dialog data
   */
  openTerminateJobDialog(data: TerminateJobDialogData) {
    this.dialog.open(NshmpAwsTerminateJobDialogComponent, {
      data,
    });
  }
}

results matching ""

    No results matching ""