Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FOGL-6720: Add new developer feature to deprecate assets #193

Merged
merged 4 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/app/components/core/south/south.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,20 @@

.readings-count {
vertical-align: middle;
max-width: max-content;
}

.service-name {
padding-top: 0;
}

#deprecate_event_div {
padding-right: 10px;
color: #363636;
}

.tooltip {
opacity: 1.0 !important;
}


22 changes: 22 additions & 0 deletions src/app/components/core/south/south.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<table class="table is-responsive">
<tr>
<td class="border-fix">Assets</td>
<td *ngIf="developerFeaturesService.getDeveloperFeatureControl()" class="border-fix"></td>
<td class="border-fix align-right">Readings</td>
</tr>
</table>
Expand Down Expand Up @@ -70,8 +71,16 @@
<table class="table is-narrow is-responsive">
<tr *ngFor='let data of svc.assets' [ngClass]="{'fade': (svc.schedule_enabled === false)}">
<td>
<a *ngIf="developerFeaturesService.getDeveloperFeatureControl()" id="deprecate_event_div"
(click)="selectAsset(svc.name, data?.asset);openModal('asset-tracking-dialog')">
<span class="icon is-small tooltip is-tooltip-right" data-tooltip="Deprecate asset">
<i class="fa fa-sm fa-eraser" aria-hidden="true"></i>
</span>
</a>
<small>{{data.asset}}</small>
</td>
<td>
</td>
<td class="readings-count">
<small class="level-right">{{data.count | number}}</small>
</td>
Expand All @@ -89,3 +98,16 @@
</div>
<app-south-service-modal (notify)='onNotify()' [service]="service"></app-south-service-modal>
<app-view-logs></app-view-logs>
<app-confirmation-dialog id="asset-tracking-dialog">
<header class="modal-card-head">
<span class="modal-card-title is-size-6">Deprecate</span>
<button class="delete" aria-label="close" (click)="closeModal('asset-tracking-dialog')"></button>
</header>
<section class="modal-card-body">
Are you sure,<b>{{selectedAsset}}</b> will be deprecated if this action is continued?
</section>
<footer class="modal-card-foot">
<button class="button is-small" (click)="closeModal('asset-tracking-dialog')">Cancel</button>
<button class="button is-small is-danger" (click)="deprecateAsset(selectedAsset)">Yes</button>
</footer>
</app-confirmation-dialog>
47 changes: 46 additions & 1 deletion src/app/components/core/south/south.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import { orderBy } from 'lodash';
import { takeWhile, takeUntil } from 'rxjs/operators';
import { interval, Subscription, Subject } from 'rxjs';

import { PingService, ServicesApiService, ProgressBarService, SharedService } from '../../../services';
import { PingService, ServicesApiService, ProgressBarService, SharedService, AssetsService } from '../../../services';
import { AlertService } from '../../../services/alert.service';
import { POLLING_INTERVAL } from '../../../utils';
import { SouthServiceModalComponent } from './south-service-modal/south-service-modal.component';
import { ViewLogsComponent } from '../packages-log/view-logs/view-logs.component';
import { DeveloperFeaturesService } from '../../../services/developer-features.service';
import { DialogService } from '../../common/confirmation-dialog/dialog.service';


@Component({
selector: 'app-south',
Expand All @@ -24,6 +27,9 @@ export class SouthComponent implements OnInit, OnDestroy {
private subscription: Subscription;
private viewPortSubscription: Subscription;
viewPort: any = '';
selectedAsset = '';
selectedService = '';
eventsTrack = [];

@ViewChild(SouthServiceModalComponent, { static: true }) southServiceModal: SouthServiceModalComponent;
@ViewChild(ViewLogsComponent) viewLogsComponent: ViewLogsComponent;
Expand All @@ -32,9 +38,12 @@ export class SouthComponent implements OnInit, OnDestroy {

constructor(private servicesApiService: ServicesApiService,
private alertService: AlertService,
private assetService: AssetsService,
public ngProgress: ProgressBarService,
public developerFeaturesService: DeveloperFeaturesService,
private router: Router,
private ping: PingService,
private dialogService: DialogService,
private sharedService: SharedService) {
this.isAlive = true;
this.ping.pingIntervalChanged
Expand Down Expand Up @@ -126,6 +135,42 @@ export class SouthComponent implements OnInit, OnDestroy {
this.showSpinner = false;
}

openModal(id: string) {
this.dialogService.open(id);
}

closeModal(id: string) {
this.dialogService.close(id);
}

selectAsset(serviceName: string, assetName: string) {
this.selectedAsset = assetName;
this.selectedService = serviceName;
}

deprecateAsset(assetName: string) {
/** request started */
this.ngProgress.start();
this.assetService.deprecateAssetTrackEntry(this.selectedService, assetName, 'Ingest')
.pipe(takeUntil(this.destroy$))
.subscribe(
(data: any) => {
/** request completed */
this.ngProgress.done();
this.alertService.success(data.success);
this.closeModal('asset-tracking-dialog');
this.getSouthboundServices(false);
}, error => {
/** request completed but error */
this.ngProgress.done();
if (error.status === 0) {
console.log('service down ', error);
} else {
this.alertService.error(error.statusText);
}
});
}

public ngOnDestroy(): void {
this.isAlive = false;
this.subscription.unsubscribe();
Expand Down
6 changes: 6 additions & 0 deletions src/app/services/assets.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { environment } from '../../environments/environment';
@Injectable()
export class AssetsService {
private GET_ASSET = environment.BASE_URL + 'asset';
private TRACK_SERVICE_URL = environment.BASE_URL + 'track';
constructor(private http: HttpClient) { }

/**
Expand Down Expand Up @@ -118,4 +119,9 @@ export class AssetsService {
catchError(error => throwError(error)));
}

public deprecateAssetTrackEntry(serviceName: string, assetName: string, event: string) {
return this.http.put(`${this.TRACK_SERVICE_URL}/service/${encodeURIComponent(serviceName)}/asset/${encodeURIComponent(assetName)}/event/${encodeURIComponent(event)}`, null).pipe(
map(response => response),
catchError(error => throwError(error)));
}
}