Skip to content

Commit

Permalink
[#1113] Added buttons to start and stop all adapters (#1441)
Browse files Browse the repository at this point in the history
* Added buttons to start and stop all adapters

* Changed variable names, added filters and removed redundancy

* Added cypress tests for buttons

---------

Co-authored-by: Neetha Reddy <neethareddy@Neethas-MacBook-Pro.local>
  • Loading branch information
purplesmurf45 and Neetha Reddy committed Mar 28, 2023
1 parent 4351714 commit ce1d95f
Show file tree
Hide file tree
Showing 9 changed files with 337 additions and 4 deletions.
8 changes: 8 additions & 0 deletions ui/cypress/support/utils/connect/ConnectBtns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,13 @@ export class ConnectBtns {
return cy.dataCy('start-adapter-now-checkbox');
}

public static startAllAdapters() {
return cy.dataCy('start-all-adapters-btn');
}

public static stopAllAdapters() {
return cy.dataCy('stop-all-adapters-btn');
}

// ========================================================================
}
9 changes: 9 additions & 0 deletions ui/cypress/support/utils/connect/ConnectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,13 @@ export class ConnectUtils {
ignoreTime,
);
}

public static allAdapterActionsDialog() {
// Click next
cy.get('button').contains('Next').parent().click();
// Wait for the adapters to start/stop
cy.wait(2000);
// Close dialog
cy.get('button').contains('Close').parent().click();
}
}
40 changes: 40 additions & 0 deletions ui/cypress/tests/adapter/allAdapterActions.smoke.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import { ConnectUtils } from '../../support/utils/connect/ConnectUtils';
import { ConnectBtns } from '../../support/utils/connect/ConnectBtns';

describe('Testing Start/Stop All Adapters', () => {
beforeEach('Setup Test', () => {
// To set up test, we are adding 2 stream adapters that can be futher configured
cy.initStreamPipesTest();
ConnectUtils.addMachineDataSimulator('simulator-1');
ConnectUtils.addMachineDataSimulator('simulator-2');
});

it('Test start/stop all adapters', () => {
// Clicking the stop all adapters button
ConnectBtns.stopAllAdapters().click();
// Navigating through the stop all adapters dialog box
ConnectUtils.allAdapterActionsDialog();
// Clicking the start all adapters button
ConnectBtns.startAllAdapters().click();
// Navigating through the start all adapters dialog box
ConnectUtils.allAdapterActionsDialog();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,32 @@
>
<i class="material-icons">add</i>&nbsp;New adapter
</button>
<sp-connect-filter-toolbar
class="filter-bar-margin"
(filterChangedEmitter)="applyFilter($event)"
<button
class="mr-10"
mat-button
color="accent"
data-cy="start-all-adapters-btn"
[disabled]="checkCurrentSelectionStatus(false)"
(click)="startAllAdapters(true)"
>
<mat-icon>play_arrow</mat-icon><span>Start all adapters</span>
</button>
<button
mat-button
color="accent"
data-cy="stop-all-adapters-btn"
[disabled]="checkCurrentSelectionStatus(true)"
(click)="startAllAdapters(false)"
>
</sp-connect-filter-toolbar>
<mat-icon>stop</mat-icon>
<span>Stop all adapters</span>
</button>
<div fxFlex fxLayout="row" fxLayoutAlign="end center">
<sp-connect-filter-toolbar
class="filter-bar-margin"
(filterChangedEmitter)="applyFilter($event)"
>
</sp-connect-filter-toolbar>
<button
mat-button
mat-icon-button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
SpMetricsEntry,
StreamPipesErrorMessage,
PipelineService,
AdapterStreamDescription,
} from '@streampipes/platform-services';
import { MatTableDataSource } from '@angular/material/table';
import { ConnectService } from '../../services/connect.service';
Expand All @@ -36,6 +37,7 @@ import {
SpExceptionDetailsDialogComponent,
} from '@streampipes/shared-ui';
import { DeleteAdapterDialogComponent } from '../../dialog/delete-adapter-dialog/delete-adapter-dialog.component';
import { AllAdapterActionsComponent } from '../../dialog/start-all-adapters/all-adapter-actions-dialog.component';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { ObjectPermissionDialogComponent } from '../../../core-ui/object-permission-dialog/object-permission-dialog.component';
Expand Down Expand Up @@ -131,6 +133,38 @@ export class ExistingAdaptersComponent implements OnInit {
);
}

checkCurrentSelectionStatus(status) {
let active = true;
this.existingAdapters.forEach(adapter => {
if (
adapter instanceof AdapterStreamDescription &&
adapter.running == status
) {
active = false;
}
});
return active;
}

startAllAdapters(action: boolean) {
const dialogRef: DialogRef<AllAdapterActionsComponent> =
this.dialogService.open(AllAdapterActionsComponent, {
panelType: PanelType.STANDARD_PANEL,
title: (action ? 'Start' : 'Stop') + ' all adapters',
width: '70vw',
data: {
adapters: this.existingAdapters,
action: action,
},
});

dialogRef.afterClosed().subscribe(data => {
if (data) {
this.getAdaptersRunning();
}
});
}

openAdapterStatusErrorDialog(
message: StreamPipesErrorMessage,
title: string,
Expand Down
2 changes: 2 additions & 0 deletions ui/src/app/connect/connect.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import { SpAdapterDetailsLogsComponent } from './components/adapter-details/adap
import { SpAdapterDetailsMetricsComponent } from './components/adapter-details/adapter-details-metrics/adapter-details-metrics.component';
import { SpecificAdapterConfigurationComponent } from './components/adapter-configuration/specific-adapter-configuration/specific-adapter-configuration.component';
import { CanNotEditAdapterDialog } from './dialog/can-not-edit-adapter-dialog/can-not-edit-adapter-dialog.component';
import { AllAdapterActionsComponent } from './dialog/start-all-adapters/all-adapter-actions-dialog.component';

@NgModule({
imports: [
Expand Down Expand Up @@ -191,6 +192,7 @@ import { CanNotEditAdapterDialog } from './dialog/can-not-edit-adapter-dialog/ca
EditAdapterComponent,
EventSchemaErrorHintsComponent,
CanNotEditAdapterDialog,
AllAdapterActionsComponent,
],
providers: [
RestService,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->

<div class="sp-dialog-container">
<div class="sp-dialog-content p-15">
<div>
<div
fxFlex="100"
class="md-dialog-content"
style="padding: 20px"
*ngIf="page === 'preview'"
>
<h4>
You are about to {{ action ? 'start' : 'stop' }} the
following adapters:
</h4>
<div *ngFor="let adapter of adaptersToModify">
<h5>{{ adapter.name }}</h5>
</div>
<h5><b>Press 'Next' to start the process.</b></h5>
</div>
<div
fxFlex="100"
class="md-dialog-content"
style="padding: 20px"
*ngIf="page === 'running'"
>
<div *ngFor="let status of actionStatus">
<h4>
{{ action ? 'Starting adapter ' : 'Stopping adapter' }}
{{ status.id + 1 }} of {{ adaptersToModify.length }} ({{
status.name
}})...{{ status.status }}
</h4>
</div>
<div *ngIf="adaptersToModify.length === 0">
<h4>
Sorry, there are no adapters that are currently
{{ action ? 'idle.' : 'running.' }}
</h4>
</div>
</div>
</div>
</div>
<mat-divider></mat-divider>
<div class="sp-dialog-actions actions-align-right">
<button
mat-button
mat-raised-button
class="mat-basic"
(click)="close(false)"
style="margin-right: 10px"
>
Cancel
</button>
<button
mat-button
mat-raised-button
color="accent"
[disabled]="actionRunning"
(click)="next()"
>
{{ nextButton }}
</button>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

@import '../../../../scss/sp/sp-dialog.scss';
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import { Component, Input, OnInit } from '@angular/core';
import { DialogRef } from '@streampipes/shared-ui';
import {
AdapterDescriptionUnion,
AdapterService,
AdapterStreamDescription,
} from '@streampipes/platform-services';

@Component({
selector: 'sp-start-all-adapters-dialog',
templateUrl: './all-adapter-actions-dialog.component.html',
styleUrls: ['./all-adapter-actions-dialog.component.scss'],
})
export class AllAdapterActionsComponent implements OnInit {
@Input()
adapters: AdapterDescriptionUnion[];

adaptersToModify: AdapterDescriptionUnion[];
actionStatus: any;
actionFinished: boolean;
page: string;
nextButton: string;
actionRunning: boolean;

@Input()
action: boolean;

constructor(
private dialogRef: DialogRef<AllAdapterActionsComponent>,
private adapterService: AdapterService,
) {
this.adaptersToModify = [];
this.actionStatus = [];
this.actionFinished = false;
this.page = 'preview';
this.nextButton = 'Next';
this.actionRunning = false;
}

ngOnInit() {
this.getAdaptersToModify();
if (this.adaptersToModify.length === 0) {
this.nextButton = 'Close';
this.page = 'running';
}
}

close(refreshAdapters: boolean) {
this.dialogRef.close(refreshAdapters);
}

next() {
if (this.page === 'running') {
this.close(true);
} else {
this.page = 'running';
this.initiateAction(this.adaptersToModify[0], 0);
}
}

getAdaptersToModify() {
this.adapters.forEach(adapter => {
if (
adapter instanceof AdapterStreamDescription &&
adapter.running != this.action
) {
this.adaptersToModify.push(adapter);
}
});
}

initiateAction(adapter: AdapterDescriptionUnion, index) {
this.actionRunning = true;
this.actionStatus.push({
name: adapter.name,
id: index,
status: 'waiting',
});
this.runAdapterAction(adapter, index);
}

runAdapterAction(adapter: AdapterDescriptionUnion, index) {
const observable = this.action
? this.adapterService.startAdapter(adapter)
: this.adapterService.stopAdapter(adapter);
observable
.subscribe(data => {
this.actionStatus[index].status = data.success
? 'success'
: 'error';
})
.add(() => {
if (index < this.adaptersToModify.length - 1) {
index++;
this.initiateAction(this.adaptersToModify[index], index);
} else {
this.nextButton = 'Close';
this.actionRunning = false;
}
});
}
}

0 comments on commit ce1d95f

Please sign in to comment.