File

src/app/streams/stream/stream.component.ts

Description

Component that shows the details of a Stream Definition

Implements

OnInit

Example

Metadata

encapsulation ViewEncapsulation.None
selector app-stream
styleUrls styles.scss
templateUrl stream.component.html

Index

Properties
Methods

Constructor

constructor(route: ActivatedRoute, streamsService: StreamsService, loggerService: LoggerService, router: Router, modalService: BsModalService, notificationService: NotificationService, sharedAboutService: SharedAboutService, grafanaService: GrafanaService, routingStateService: RoutingStateService)
Parameters :
Name Type Optional Description
route ActivatedRoute
streamsService StreamsService
loggerService LoggerService
router Router
modalService BsModalService
notificationService NotificationService
sharedAboutService SharedAboutService
grafanaService GrafanaService
routingStateService RoutingStateService

Methods

cancel
cancel()

Back action Navigate to the previous URL or /streams/definitions

Returns : void
deploy
deploy(streamDefinition: StreamDefinition)

Deploy the stream, navigation to the dedicate page

Parameters :
Name Type Optional Description
streamDefinition StreamDefinition
Returns : void
destroy
destroy(streamDefinition: StreamDefinition)

Destroy the stream

Parameters :
Name Type Optional Description
streamDefinition StreamDefinition
Returns : void
grafanaDashboard
grafanaDashboard(streamDefinition: StreamDefinition)

Navigate to the grafana Dashboard

Parameters :
Name Type Optional Description
streamDefinition StreamDefinition
Returns : void
ngOnInit
ngOnInit()

Initialiaze component

Returns : void
undeploy
undeploy(streamDefinition: StreamDefinition)

Undeploy the stream

Parameters :
Name Type Optional Description
streamDefinition StreamDefinition
Returns : void

Properties

modal
modal: BsModalRef
Type : BsModalRef

Modal

streamDefinition$
streamDefinition$: Observable<any>
Type : Observable<any>

Observable of StreamDefinition

import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { RoutingStateService } from '../../shared/services/routing-state.service';
import { ActivatedRoute } from '@angular/router';
import { mergeMap, map, catchError } from 'rxjs/operators';
import { StreamsService } from '../streams.service';
import { Observable, EMPTY } from 'rxjs';
import { StreamDefinition } from '../model/stream-definition';
import { AppError, HttpAppError } from '../../shared/model/error.model';
import { Router } from '@angular/router';
import { LoggerService } from '../../shared/services/logger.service';
import { StreamsDestroyComponent } from '../streams-destroy/streams-destroy.component';
import { BsModalRef, BsModalService } from 'ngx-bootstrap';
import { NotificationService } from '../../shared/services/notification.service';
import { SharedAboutService } from '../../shared/services/shared-about.service';
import { GrafanaService } from '../../shared/grafana/grafana.service';

/**
 * Component that shows the details of a Stream Definition
 *
 * @author Janne Valkealahti
 * @author Gunnar Hillert
 * @author Glenn Renfro
 * @author Damien Vitrac
 */
@Component({
  selector: 'app-stream',
  templateUrl: 'stream.component.html',
  styleUrls: ['styles.scss'],
  encapsulation: ViewEncapsulation.None
})

export class StreamComponent implements OnInit {

  /**
   * Observable of StreamDefinition
   */
  streamDefinition$: Observable<any>;

  /**
   * Modal
   */
  modal: BsModalRef;

  constructor(private route: ActivatedRoute,
              private streamsService: StreamsService,
              private loggerService: LoggerService,
              private router: Router,
              private modalService: BsModalService,
              private notificationService: NotificationService,
              private sharedAboutService: SharedAboutService,
              private grafanaService: GrafanaService,
              private routingStateService: RoutingStateService) {
  }

  /**
   * Initialiaze component
   */
  ngOnInit() {
    this.streamDefinition$ = this.route.params
      .pipe(
        mergeMap(
          (val) => this.sharedAboutService.getFeatureInfo()
            .pipe(map((featureInfo) => {
              return {
                id: val.id,
                featureInfo: featureInfo
              };
            }))
        ),
        mergeMap(
          (val) => this.grafanaService.isAllowed()
            .pipe(map((active: boolean) => {
              return {
                id: val.id,
                featureInfo: val.featureInfo,
                grafanaEnabled: active
              };
            }))
        ),
        mergeMap(
          (val) => this.streamsService.getDefinition(val.id)
            .pipe(map((streamDefinition: StreamDefinition) => {
              return {
                id: val.id,
                featureInfo: val.featureInfo,
                grafanaEnabled: val.grafanaEnabled,
                streamDefinition: streamDefinition
              };
            }))
        ),
        catchError((error) => {
          if (HttpAppError.is404(error)) {
            this.cancel();
          }
          this.notificationService.error(AppError.is(error) ? error.getMessage() : error);
          return EMPTY;
        })
      );
  }

  /**
   * Undeploy the stream
   *
   * @param {StreamDefinition} streamDefinition
   */
  undeploy(streamDefinition: StreamDefinition) {
    this.loggerService.log(`Undeploy ${streamDefinition.name} stream definition(s).`, streamDefinition);
    this.streamsService
      .undeployDefinition(streamDefinition)
      .subscribe(() => {
        this.notificationService.success(`Successfully undeployed stream definition "${streamDefinition.name}"`);
        this.ngOnInit();
      });
  }

  /**
   * Deploy the stream, navigation to the dedicate page
   *
   * @param {StreamDefinition} streamDefinition
   */
  deploy(streamDefinition: StreamDefinition) {
    this.router.navigate([`streams/definitions/${streamDefinition.name}/deploy`]);
  }

  /**
   * Destroy the stream
   *
   * @param {StreamDefinition} streamDefinition
   */
  destroy(streamDefinition: StreamDefinition) {
    this.loggerService.log(`Destroy ${name} stream definition.`, name);
    this.modal = this.modalService.show(StreamsDestroyComponent, { class: 'modal-md' });
    this.modal.content.open({ streamDefinitions: [streamDefinition] }).subscribe(() => {
      this.cancel();
    });
  }

  /**
   * Navigate to the grafana Dashboard
   * @param streamDefinition
   */
  grafanaDashboard(streamDefinition: StreamDefinition) {
    this.grafanaService.getDashboardStream(streamDefinition).subscribe((url: string) => {
      window.open(url);
    });
  }

  /**
   * Back action
   * Navigate to the previous URL or /streams/definitions
   */
  cancel() {
    this.routingStateService.back('/streams/definitions', /^(\/streams\/definitions\/)/);
  }


}
<app-page *ngIf="streamDefinition$ | async as streamDefinition; else loading">

  <app-page-head>
    <app-page-head-back [defaultUrl]="'/streams/definitions'"
                        [isNotRegex]="'^(\/streams\/definitions\/)'"></app-page-head-back>
    <app-page-head-title>Stream <strong>{{ streamDefinition.streamDefinition.name }}</strong></app-page-head-title>
    <app-page-head-subtitle>
      <app-stream-status [streamDefinition]="streamDefinition.streamDefinition"></app-stream-status>
    </app-page-head-subtitle>
    <app-page-head-actions [dataflowAppRoles]="['ROLE_CREATE']">
      <button name="stream-stop" type="button"
              *ngIf="!(streamDefinition.streamDefinition.status === 'undeployed'|| streamDefinition.streamDefinition.status === 'incomplete')"
              (click)="undeploy(streamDefinition.streamDefinition)" class="btn btn-primary btn-fa" title="Undeploy"
              [dataflowAppRoles]="['ROLE_CREATE']">
        <span class="fa fa-stop"></span>
        Undeploy stream
      </button>
      <button name="stream-deploy" type="button" (click)="deploy(streamDefinition.streamDefinition)"
              class="btn btn-primary btn-fa" title="Deploy" [dataflowAppRoles]="['ROLE_DEPLOY']"
              *ngIf="streamDefinition.streamDefinition.status === 'undeployed'">
        <span class="fa fa-play"></span>
        Deploy stream
      </button>
      <button name="stream-deploy" type="button" (click)="deploy(streamDefinition.streamDefinition)"
              class="btn btn-primary btn-fa" title="Deploy" [dataflowAppRoles]="['ROLE_MODIFY']"
              *ngIf="streamDefinition.streamDefinition.status === 'deployed'">
        <span class="fa fa-edit"></span>
        Update stream
      </button>
      <button name="stream-remove" type="button" (click)="destroy(streamDefinition.streamDefinition)"
              class="btn btn-danger btn-fa" title="Destroy" [dataflowAppRoles]="['ROLE_DESTROY']">
        <span class="fa fa-trash"></span>
        Destroy stream
      </button>
      <button name="stream-grafana" type="button" *ngIf="streamDefinition.grafanaEnabled"
              [disabled]="!(streamDefinition.streamDefinition.status === 'deployed')"
              (click)="grafanaDashboard(streamDefinition.streamDefinition)" class="btn btn-primary btn-fa" title="Grafana Dashboard">
        <span class="icon-custom icon-custom-grafana white"></span>
        Grafana Dashboard
      </button>
    </app-page-head-actions>
  </app-page-head>

  <div class="page-tab">
    <div class="page-tab-head">
      <ul class="nav nav-tabs">
        <li role="presentation" routerLinkActive="active"><a routerLink="summary">Summary</a></li>
        <li role="presentation" routerLinkActive="active"><a routerLink="graph">Graph</a></li>
        <li role="presentation" routerLinkActive="active"><a routerLink="history">History</a></li>
      </ul>
    </div>
    <div class="tab-content">
      <div class="tab-pane in active">
        <router-outlet></router-outlet>
      </div>
    </div>
  </div>

</app-page>

<ng-template #loading>
  <app-loader></app-loader>
</ng-template>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""