From commits-return-4086-archive-asf-public=cust-asf.ponee.io@metron.apache.org Sun Nov 18 19:15:17 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 7DB69180771 for ; Sun, 18 Nov 2018 19:15:16 +0100 (CET) Received: (qmail 4958 invoked by uid 500); 18 Nov 2018 18:15:15 -0000 Mailing-List: contact commits-help@metron.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@metron.apache.org Delivered-To: mailing list commits@metron.apache.org Received: (qmail 4914 invoked by uid 99); 18 Nov 2018 18:15:15 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 Nov 2018 18:15:15 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C27A7E124E; Sun, 18 Nov 2018 18:15:14 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: otto@apache.org To: commits@metron.apache.org Date: Sun, 18 Nov 2018 18:15:19 -0000 Message-Id: <4b2eb104f4a64662b2cf9e99f60e7879@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [06/52] [abbrv] metron git commit: METRON-1790 Unsubscribe from every observable in the pcap panel UI component (ruffle via nickwallen) closes apache/metron#1208 METRON-1790 Unsubscribe from every observable in the pcap panel UI component (ruffle via nickwallen) closes apache/metron#1208 Project: http://git-wip-us.apache.org/repos/asf/metron/repo Commit: http://git-wip-us.apache.org/repos/asf/metron/commit/fdfca3b2 Tree: http://git-wip-us.apache.org/repos/asf/metron/tree/fdfca3b2 Diff: http://git-wip-us.apache.org/repos/asf/metron/diff/fdfca3b2 Branch: refs/heads/feature/METRON-1090-stellar-assignment Commit: fdfca3b2675d0dfcdf7960c5db789a8c9386b5db Parents: 9b6260f Author: ruffle Authored: Mon Nov 5 10:45:33 2018 -0500 Committer: nickallen Committed: Mon Nov 5 10:45:33 2018 -0500 ---------------------------------------------------------------------- .../app/pcap/pcap-panel/pcap-panel.component.ts | 68 +++++++++----------- 1 file changed, 32 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/metron/blob/fdfca3b2/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.ts b/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.ts index f767020..fdd75f7 100644 --- a/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.ts +++ b/metron-interface/metron-alerts/src/app/pcap/pcap-panel/pcap-panel.component.ts @@ -35,11 +35,6 @@ export class PcapPanelComponent implements OnInit, OnDestroy { pdml: Pdml = null; pcapRequest: PcapRequest; resetPaginationForSearch: boolean; - - statusSubscription: Subscription; - cancelSubscription: Subscription; - submitSubscription: Subscription; - getSubscription: Subscription; queryRunning = false; queryId: string; progressWidth = 0; @@ -47,28 +42,33 @@ export class PcapPanelComponent implements OnInit, OnDestroy { savedPcapRequest: {}; errorMsg: string; cancelConfirmMessage = 'Are you sure want to cancel the running query?'; + subscriptions: { + [key: string]: Subscription + } = {}; constructor(private pcapService: PcapService) { } ngOnInit() { this.pcapRequest = new PcapRequest(); - this.pcapService.getRunningJob().subscribe((statusResponses: PcapStatusResponse[]) => { + this.subscriptions['runningJobSubscription'] = this.pcapService.getRunningJob().subscribe((statusResponses: PcapStatusResponse[]) => { if (statusResponses.length > 0) { // Assume the first job in the list is the running job this.queryRunning = true; let statusResponse = statusResponses[0]; this.updateStatus(statusResponse); this.startPolling(statusResponse.jobId); - this.pcapService.getPcapRequest(statusResponse.jobId).subscribe((pcapRequest: PcapRequest) => { - this.pcapRequest = pcapRequest; - }); + this.subscriptions['pcapRequestSubscription'] = this.pcapService.getPcapRequest(statusResponse.jobId).subscribe( + (pcapRequest: PcapRequest) => { + this.pcapRequest = pcapRequest; + } + ); } }); } changePage(page) { this.pagination.selectedPage = page; - this.pcapService.getPackets(this.queryId, this.pagination.selectedPage).toPromise().then(pdml => { + this.subscriptions['packetSubscription'] = this.pcapService.getPackets(this.queryId, this.pagination.selectedPage).subscribe(pdml => { this.pdml = pdml; }); } @@ -81,26 +81,28 @@ export class PcapPanelComponent implements OnInit, OnDestroy { this.pdml = null; this.progressWidth = 0; this.errorMsg = null; - this.submitSubscription = this.pcapService.submitRequest(pcapRequest).subscribe((submitResponse: PcapStatusResponse) => { - let id = submitResponse.jobId; - if (!id) { - this.errorMsg = submitResponse.description; - this.queryRunning = false; - } else { - this.startPolling(id); + this.subscriptions['submitSubscription'] = this.pcapService.submitRequest(pcapRequest).subscribe( + (submitResponse: PcapStatusResponse) => { + let id = submitResponse.jobId; + if (!id) { + this.errorMsg = submitResponse.description; + this.queryRunning = false; + } else { + this.startPolling(id); + } + }, (error: any) => { + this.errorMsg = `Response message: ${error.message}. Something went wrong with your query submission!`; } - }, (error: any) => { - this.errorMsg = `Response message: ${error.message}. Something went wrong with your query submission!`; - }); + ); } startPolling(id: string) { this.queryId = id; this.errorMsg = null; - this.statusSubscription = this.pcapService.pollStatus(id).subscribe((statusResponse: PcapStatusResponse) => { + this.subscriptions['statusSubscription'] = this.pcapService.pollStatus(id).subscribe((statusResponse: PcapStatusResponse) => { this.updateStatus(statusResponse); }, (error: any) => { - this.statusSubscription.unsubscribe(); + this.subscriptions['statusSubscription'].unsubscribe(); this.queryRunning = false; this.errorMsg = `Response message: ${error.message}. Something went wrong with your status request!`; }); @@ -109,9 +111,9 @@ export class PcapPanelComponent implements OnInit, OnDestroy { updateStatus(statusResponse: PcapStatusResponse) { if ('SUCCEEDED' === statusResponse.jobStatus) { this.pagination.total = statusResponse.pageTotal; - this.statusSubscription.unsubscribe(); + this.subscriptions['statusSubscription'].unsubscribe(); this.queryRunning = false; - this.pcapService.getPackets(this.queryId, this.pagination.selectedPage).toPromise().then(pdml => { + this.subscriptions['packetSubscription'] = this.pcapService.getPackets(this.queryId, this.pagination.selectedPage).subscribe(pdml => { this.pdml = pdml; }, (error: RestError) => { if (error.status === 404) { @@ -121,7 +123,7 @@ export class PcapPanelComponent implements OnInit, OnDestroy { } }); } else if ('FAILED' === statusResponse.jobStatus) { - this.statusSubscription.unsubscribe(); + this.subscriptions['statusSubscription'].unsubscribe(); this.queryRunning = false; this.errorMsg = `Query status: ${statusResponse.jobStatus}. Check your filter criteria and try again!`; } else if (this.progressWidth < 100) { @@ -134,25 +136,19 @@ export class PcapPanelComponent implements OnInit, OnDestroy { } unsubscribeAll() { - if (this.cancelSubscription) { - this.cancelSubscription.unsubscribe(); - } - if (this.statusSubscription) { - this.statusSubscription.unsubscribe(); - } - if (this.submitSubscription) { - this.submitSubscription.unsubscribe(); - } + Object.keys(this.subscriptions).forEach((key) => { + this.subscriptions[key].unsubscribe(); + }); + this.subscriptions = {}; } cancelQuery() { - this.cancelSubscription = this.pcapService.cancelQuery(this.queryId) + this.subscriptions['cancelSubscription'] = this.pcapService.cancelQuery(this.queryId) .subscribe(() => { this.unsubscribeAll(); this.queryId = ''; this.queryRunning = false; }, (error: any) => { - this.cancelSubscription.unsubscribe(); this.queryId = ''; this.errorMsg = `Response message: ${error.message}. Something went wrong with the cancellation!`; this.queryRunning = false;