From 87ffca501cf3dca8dfb050b56f5c3bf9b742b651 Mon Sep 17 00:00:00 2001 From: elinuxhenrik Date: Tue, 2 Feb 2021 18:07:07 +0100 Subject: [PATCH] Move Enrichment Job Logic from backend Change-Id: Ib64fa7bfed5454bcae695f9364aeb0cf879071c0 Signed-off-by: elinuxhenrik Issue-ID: NONRTRIC-408 --- .../ei-coordinator.component.spec.ts | 2 +- .../app/ei-coordinator/ei-coordinator.component.ts | 4 +- .../app/ei-coordinator/ei-job.datasource.spec.ts | 61 ++++++++++++++++++++++ .../src/app/ei-coordinator/ei-job.datasource.ts | 31 ++++++++--- webapp-frontend/src/app/interceptor.mock.ts | 21 +++++--- .../mock/{ei-jobs.json => ei-jobs-producer1.json} | 3 +- .../src/app/mock/ei-jobs-producer2.json | 13 +++++ webapp-frontend/src/app/mock/ei-producerids.json | 4 ++ .../src/app/services/ei/ei.service.spec.ts | 25 ++++----- webapp-frontend/src/app/services/ei/ei.service.ts | 21 ++++---- 10 files changed, 144 insertions(+), 41 deletions(-) create mode 100644 webapp-frontend/src/app/ei-coordinator/ei-job.datasource.spec.ts rename webapp-frontend/src/app/mock/{ei-jobs.json => ei-jobs-producer1.json} (89%) create mode 100644 webapp-frontend/src/app/mock/ei-jobs-producer2.json create mode 100644 webapp-frontend/src/app/mock/ei-producerids.json diff --git a/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.spec.ts b/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.spec.ts index 50127a3..b9c2e0f 100644 --- a/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.spec.ts +++ b/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.spec.ts @@ -35,7 +35,7 @@ describe('EICoordinatorComponent', () => { let fixture: ComponentFixture; beforeEach(async(() => { - const jobDataSourceSpy = jasmine.createSpyObj('EIJobDataSource', [ 'connect', 'loadTable', 'disconnect' ]); + const jobDataSourceSpy = jasmine.createSpyObj('EIJobDataSource', [ 'connect', 'getJobs', 'disconnect' ]); const producerDataSourceSpy = jasmine.createSpyObj('EIProducerDataSource', [ 'connect', 'loadTable', 'getProducers', 'disconnect' ]); jobDataSourceSpy.connect.and.returnValue(of([])); diff --git a/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.ts b/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.ts index 90dfef1..bd3f946 100644 --- a/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.ts +++ b/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.ts @@ -71,7 +71,7 @@ export class EICoordinatorComponent implements OnInit { } ngOnInit() { - this.eiJobsDataSource.loadTable(); + this.eiJobsDataSource.getJobs(); this.producers$= this.eiProducersDataSource.getProducers(); this.filteredProducers$ = defer(() => this.formGroup.get("filter") @@ -148,7 +148,7 @@ export class EICoordinatorComponent implements OnInit { } refreshTables() { - this.eiJobsDataSource.loadTable(); + this.eiJobsDataSource.getJobs(); this.eiProducersDataSource.loadTable(); } } diff --git a/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.spec.ts b/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.spec.ts new file mode 100644 index 0000000..cb530a6 --- /dev/null +++ b/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.spec.ts @@ -0,0 +1,61 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2021 Nordix Foundation + * %% + * Licensed 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. + * ========================LICENSE_END=================================== + */ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { BehaviorSubject, of } from 'rxjs'; + +import { EIJobDataSource } from './ei-job.datasource'; +import { EIService } from '../services/ei/ei.service'; +import { NotificationService } from '../services/ui/notification.service'; +import { ToastrModule } from 'ngx-toastr'; +import { EIJob } from '../interfaces/ei.types'; + +describe('EIJobDataSource', () => { + let dataSource: EIJobDataSource; + let eiServiceSpy: any; + + let job = { ei_job_identity: '1', ei_job_data: 'data', ei_type_identity: 'Type ID 1', target_uri: 'hhtp://url', owner: 'owner'}; + + beforeEach(() => { + eiServiceSpy = jasmine.createSpyObj('EIService', ['getProducerIds', 'getJobsForProducer']); + + eiServiceSpy.getProducerIds.and.returnValue(of([ 'producer1', 'producer2'])); + eiServiceSpy.getJobsForProducer.and.returnValue(of([job])); + TestBed.configureTestingModule({ + imports: [ToastrModule.forRoot()], + providers: [ + { provide: EIService, useValue: eiServiceSpy }, + NotificationService + ] + }); + }); + + it('should create', () => { + dataSource = TestBed.get(EIJobDataSource); + expect(dataSource).toBeTruthy(); + }); + + it('#getJobs and connect', () => { + dataSource.getJobs(); + const jobsSubject: BehaviorSubject = dataSource.eiJobsSubject; + const value = jobsSubject.getValue(); + expect(value).toEqual([ job, job ]); + expect(dataSource.rowCount).toEqual(2); + }); +}); diff --git a/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.ts b/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.ts index 9e048b6..2e0e0c8 100644 --- a/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.ts +++ b/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.ts @@ -36,7 +36,7 @@ import { NotificationService } from '../services/ui/notification.service'; export class EIJobDataSource extends MatTableDataSource { - private eiJobSubject = new BehaviorSubject([]); + eiJobsSubject = new BehaviorSubject([]); private loadingSubject = new BehaviorSubject(false); @@ -50,9 +50,9 @@ export class EIJobDataSource extends MatTableDataSource { super(); } - loadTable() { + getJobs() { this.loadingSubject.next(true); - this.eiSvc.getEIJobs() + this.eiSvc.getProducerIds() .pipe( catchError((her: HttpErrorResponse) => { this.notificationService.error('Failed to get EI jobs: ' + her.error); @@ -60,18 +60,33 @@ export class EIJobDataSource extends MatTableDataSource { }), finalize(() => this.loadingSubject.next(false)) ) - .subscribe((instances: EIJob[]) => { - this.rowCount = instances.length; - this.eiJobSubject.next(instances); + .subscribe((producerIds: String[]) => { + producerIds.forEach(id => { + this.getJobsForProducer(id); + }); }); } + private getJobsForProducer(id: String) { + console.log('Getting jobs for producer ID: ', id); + this.eiSvc.getJobsForProducer(id).subscribe(jobs => { + this.addJobsToSubject(jobs); + this.rowCount = this.eiJobsSubject.getValue().length; + }); + } + + private addJobsToSubject(jobs: EIJob[]) { + const currentValue = this.eiJobsSubject.value; + const updatedValue = [...currentValue, ...jobs]; + this.eiJobsSubject.next(updatedValue); + } + connect(): BehaviorSubject { - return this.eiJobSubject; + return this.eiJobsSubject; } disconnect(): void { - this.eiJobSubject.complete(); + this.eiJobsSubject.complete(); this.loadingSubject.complete(); } } diff --git a/webapp-frontend/src/app/interceptor.mock.ts b/webapp-frontend/src/app/interceptor.mock.ts index 05e1a4e..66807d7 100644 --- a/webapp-frontend/src/app/interceptor.mock.ts +++ b/webapp-frontend/src/app/interceptor.mock.ts @@ -26,9 +26,10 @@ import * as policies from './mock/policies.json'; import * as policyinstances2 from './mock/policy-instance-2.json'; import * as policyinstances1Status from './mock/policy-instance-1-status.json'; import * as policyinstances2Status from './mock/policy-instance-2-status.json'; -import * as eijobs from './mock/ei-jobs.json'; +import * as eijobsProd1 from './mock/ei-jobs-producer1.json'; +import * as eijobsProd2 from './mock/ei-jobs-producer2.json'; +import * as eiProducerIds from './mock/ei-producerids.json'; import * as eiproducers from './mock/ei-producers.json'; -import * as policyinstanceNoType from './mock/policy-instance-notype.json'; import * as policytypesList from './mock/policy-types.json'; import * as policytypes1 from './mock/policy-type1.json'; import * as policyinstanceedit from './mock/policy-instance-edit.json'; @@ -101,10 +102,6 @@ const urls = [ url: '/a1-policy/v2/rics?policytype_id=', json: ric2 }, - { - url: 'api/enrichment/eijobs', - json: eijobs - }, { url: 'api/enrichment/eiproducers', json: eiproducers @@ -116,6 +113,18 @@ const urls = [ { url: 'api/policy/rics?policyType=2', json: rics + }, + { + url: '/ei-producer/v1/eiproducers', + json: eiProducerIds + }, + { + url: '/ei-producer/v1/eiproducers/producer1/eijobs', + json: eijobsProd1 + }, + { + url: '/ei-producer/v1/eiproducers/producer2/eijobs', + json: eijobsProd2 } ]; diff --git a/webapp-frontend/src/app/mock/ei-jobs.json b/webapp-frontend/src/app/mock/ei-jobs-producer1.json similarity index 89% rename from webapp-frontend/src/app/mock/ei-jobs.json rename to webapp-frontend/src/app/mock/ei-jobs-producer1.json index 79b4c44..488e194 100644 --- a/webapp-frontend/src/app/mock/ei-jobs.json +++ b/webapp-frontend/src/app/mock/ei-jobs-producer1.json @@ -12,7 +12,8 @@ }, { "ei_job_identity": "job2", - "ei_type_identity": "type2", + "ei_type_identity": "type1", + "owner": "owner1", "ei_job_data": { "jobparam2": "value2_job2", "jobparam3": "value3_job2", diff --git a/webapp-frontend/src/app/mock/ei-jobs-producer2.json b/webapp-frontend/src/app/mock/ei-jobs-producer2.json new file mode 100644 index 0000000..07220a9 --- /dev/null +++ b/webapp-frontend/src/app/mock/ei-jobs-producer2.json @@ -0,0 +1,13 @@ +[ + { + "ei_job_identity": "job3", + "ei_type_identity": "type2", + "owner": "owner1", + "ei_job_data": { + "jobparam2": "value2_job3", + "jobparam3": "value3_job3", + "jobparam1": "value1_job3" + }, + "target_uri": "https://ricsim_g3_1:8185/datadelivery" + } + ] \ No newline at end of file diff --git a/webapp-frontend/src/app/mock/ei-producerids.json b/webapp-frontend/src/app/mock/ei-producerids.json new file mode 100644 index 0000000..c6789c0 --- /dev/null +++ b/webapp-frontend/src/app/mock/ei-producerids.json @@ -0,0 +1,4 @@ +[ + "producer1", + "producer2" +] \ No newline at end of file diff --git a/webapp-frontend/src/app/services/ei/ei.service.spec.ts b/webapp-frontend/src/app/services/ei/ei.service.spec.ts index 9e2584b..ca77d0c 100644 --- a/webapp-frontend/src/app/services/ei/ei.service.spec.ts +++ b/webapp-frontend/src/app/services/ei/ei.service.spec.ts @@ -20,11 +20,11 @@ import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing' import { TestBed } from '@angular/core/testing'; -import { EIJob, EIProducer } from '../../interfaces/ei.types'; +import { EIJob } from '../../interfaces/ei.types'; import { EIService } from './ei.service'; describe('EIService', () => { - let basePath = 'api/enrichment'; + let basePath = '/ei-producer/v1'; let service: EIService; let httpTestingController: HttpTestingController; @@ -43,27 +43,24 @@ describe('EIService', () => { }); describe('#getEIProducers', () => { - let expectedEIProducers: EIProducer[]; + let expectedEIProducerIds: String[]; beforeEach(() => { service = TestBed.get(EIService); httpTestingController = TestBed.get(HttpTestingController); - expectedEIProducers = [ - { ei_producer_id: '1', ei_producer_types: ['EI Type 1'], status: 'ENABLED' }, - { ei_producer_id: '1', ei_producer_types: ['EI Type 1'], status: 'ENABLED' } - ] as EIProducer[]; + expectedEIProducerIds = [ 'producer1', 'producer2' ] as String[]; }); - it('should return all producers', () => { - service.getEIProducers().subscribe( - producers => expect(producers).toEqual(expectedEIProducers, 'should return expected EIProducers'), + it('should return all producer IDs', () => { + service.getProducerIds().subscribe( + producers => expect(producers).toEqual(expectedEIProducerIds, 'should return expected EIProducer IDs'), fail ); - const req = httpTestingController.expectOne(basePath + '/' + service.eiProducerPath); + const req = httpTestingController.expectOne(basePath + '/' + service.eiProducersPath); expect(req.request.method).toEqual('GET'); - req.flush(expectedEIProducers); //Return expectedEITypes + req.flush(expectedEIProducerIds); //Return expected producer IDs httpTestingController.verify(); }); @@ -82,12 +79,12 @@ describe('EIService', () => { }); it('should return all jobs', () => { - service.getEIJobs().subscribe( + service.getJobsForProducer('producer1').subscribe( jobs => expect(jobs).toEqual(expectedEIJobs, 'should return expected Jobs'), fail ); - const req = httpTestingController.expectOne(basePath + '/' + service.eiJobPath); + const req = httpTestingController.expectOne(basePath + '/' + service.eiProducersPath + '/producer1/' + service.eiJobsPath); expect(req.request.method).toEqual('GET'); req.flush(expectedEIJobs); //Return expectedEIJobs diff --git a/webapp-frontend/src/app/services/ei/ei.service.ts b/webapp-frontend/src/app/services/ei/ei.service.ts index d09b5ef..3be9b8b 100644 --- a/webapp-frontend/src/app/services/ei/ei.service.ts +++ b/webapp-frontend/src/app/services/ei/ei.service.ts @@ -20,10 +20,8 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; -import { Observable } from 'rxjs'; -import { map } from 'rxjs/operators'; +import { Observable, of } from 'rxjs'; import { EIJob, EIProducer } from '../../interfaces/ei.types'; -import { ControlpanelSuccessTransport } from '../../interfaces/controlpanel.types'; /** * Services for calling the EI endpoints. @@ -33,9 +31,9 @@ import { ControlpanelSuccessTransport } from '../../interfaces/controlpanel.type }) export class EIService { - private basePath = 'api/enrichment'; - eiJobPath = 'eijobs'; - eiProducerPath = 'eiproducers'; + private basePath = '/ei-producer/v1'; + eiJobsPath = 'eijobs'; + eiProducersPath = 'eiproducers'; private buildPath(...args: any[]) { let result = this.basePath; @@ -49,13 +47,18 @@ export class EIService { // injects to variable httpClient } - getEIJobs(): Observable { - const url = this.buildPath(this.eiJobPath); + getProducerIds(): Observable { + const url = this.buildPath(this.eiProducersPath); + return this.httpClient.get(url); + } + + getJobsForProducer(producerId: String): Observable { + const url = this.buildPath(this.eiProducersPath, producerId, this.eiJobsPath); return this.httpClient.get(url); } getEIProducers(): Observable { - const url = this.buildPath(this.eiProducerPath); + const url = this.buildPath(this.eiProducersPath); return this.httpClient.get(url); } } -- 2.16.6