-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a processor group state change API
- Loading branch information
1 parent
4312d99
commit ca7a5e3
Showing
6 changed files
with
134 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
src/specifications/service/processor-group-state/processor-group-state.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { ProcessorGroupStateService } from './processor-group-state.service'; | ||
|
||
describe('ProcessorGroupStateService', () => { | ||
let service: ProcessorGroupStateService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ProcessorGroupStateService], | ||
}).compile(); | ||
|
||
service = module.get<ProcessorGroupStateService>(ProcessorGroupStateService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
70 changes: 70 additions & 0 deletions
70
src/specifications/service/processor-group-state/processor-group-state.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { ScheduleService } from "../schedule/schedule.service"; | ||
import { HttpCustomService } from "../HttpCustomService"; | ||
import { ProcessorDto } from "src/specifications/dto/specData.dto"; | ||
import { GenericFunction } from "../genericFunction"; | ||
|
||
@Injectable() | ||
export class ProcessorGroupStateService { | ||
scheduleSchema = { | ||
type: "object", | ||
properties: { | ||
processor_group_name: { | ||
type: "string", | ||
shouldnotnull: true, | ||
}, | ||
state: { | ||
type: "string", | ||
shouldnotnull: true, | ||
enum: ["RUNNING", "STOPPED"], | ||
}, | ||
}, | ||
required: ["processor_group_name", "state"], | ||
}; | ||
nifiUrl: string = `${process.env.NIFI_HOST}:${process.env.NIFI_PORT}`; | ||
constructor( | ||
private scheduleService: ScheduleService, | ||
private http: HttpCustomService, | ||
private specService: GenericFunction | ||
) {} | ||
async changeProcessorGroupState(inputProcessorData: ProcessorDto) { | ||
let isValidSchema: any; | ||
isValidSchema = await this.specService.ajvValidator( | ||
this.scheduleSchema, | ||
inputProcessorData | ||
); | ||
if (isValidSchema.errors) { | ||
return { code: 400, error: isValidSchema.errors }; | ||
} else { | ||
try { | ||
const processorGroups = await this.scheduleService.getRootDetails(); | ||
let pg_list = processorGroups.data; | ||
let processorGroupName = inputProcessorData.processor_group_name; | ||
let counter = 0; | ||
let data = {}; | ||
let pg_group = pg_list["processGroupFlow"]["flow"]["processGroups"]; | ||
for (let pg of pg_group) { | ||
if (pg.component.name == processorGroupName) { | ||
let pg_source = pg; | ||
counter = counter + 1; | ||
data = { | ||
id: pg_source["component"]["id"], | ||
state: inputProcessorData.state, // RUNNING or STOP | ||
disconnectedNodeAcknowledged: false, | ||
}; | ||
const result = await this.http.put( | ||
`${this.nifiUrl}/nifi-api/flow/process-groups/${pg_source["component"]["id"]}`, | ||
data | ||
); | ||
console.log("the result is:",result.data); | ||
return {code: 200,message:`changed the state of ${processorGroupName}`} | ||
} | ||
} | ||
return {code:400,error:"Could not find the processor group"} | ||
} catch (error) { | ||
return {code:400,error:error?.message} | ||
|
||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,35 @@ | ||
import {HttpCustomService} from './service/HttpCustomService'; | ||
import {EventService} from './service/event/event.service'; | ||
import {Dimension} from './../typeorm/dimension.entity'; | ||
import {Module} from '@nestjs/common'; | ||
import {SpecificationController} from './controller/specification.controller'; | ||
import {TypeOrmModule} from '@nestjs/typeorm'; | ||
import {DimensionService} from './service/dimension/dimension.service'; | ||
import {GenericFunction} from './service/genericFunction'; | ||
import {TransformerService} from './service/transformer/transformer.service'; | ||
import {DatasetService} from './service/dataset/dataset.service'; | ||
import {HttpModule} from '@nestjs/axios'; | ||
import { PipelineService } from '../specifications/service/pipeline-old/pipeline.service'; | ||
import {ScheduleService} from './service/schedule/schedule.service'; | ||
import { PipelineGenericService } from './service/pipeline-generic/pipeline-generic.service'; | ||
import {Grammar} from "./service/grammar/grammar.service"; | ||
import { ReadSchemaService } from './service/read-schema/read-schema.service'; | ||
import { HttpCustomService } from "./service/HttpCustomService"; | ||
import { EventService } from "./service/event/event.service"; | ||
import { Dimension } from "./../typeorm/dimension.entity"; | ||
import { Module } from "@nestjs/common"; | ||
import { SpecificationController } from "./controller/specification.controller"; | ||
import { TypeOrmModule } from "@nestjs/typeorm"; | ||
import { DimensionService } from "./service/dimension/dimension.service"; | ||
import { GenericFunction } from "./service/genericFunction"; | ||
import { TransformerService } from "./service/transformer/transformer.service"; | ||
import { DatasetService } from "./service/dataset/dataset.service"; | ||
import { HttpModule } from "@nestjs/axios"; | ||
import { PipelineService } from "../specifications/service/pipeline-old/pipeline.service"; | ||
import { ScheduleService } from "./service/schedule/schedule.service"; | ||
import { PipelineGenericService } from "./service/pipeline-generic/pipeline-generic.service"; | ||
import { ReadSchemaService } from "./service/read-schema/read-schema.service"; | ||
import { ProcessorGroupStateService } from "./service/processor-group-state/processor-group-state.service"; | ||
|
||
@Module({ | ||
imports: [HttpModule], | ||
controllers: [SpecificationController], | ||
providers: [DimensionService, EventService, GenericFunction, TransformerService, DatasetService, PipelineService, HttpCustomService, ScheduleService, Grammar, PipelineGenericService,ReadSchemaService], | ||
|
||
imports: [HttpModule], | ||
controllers: [SpecificationController], | ||
providers: [ | ||
DimensionService, | ||
EventService, | ||
GenericFunction, | ||
TransformerService, | ||
DatasetService, | ||
PipelineService, | ||
HttpCustomService, | ||
ScheduleService, | ||
PipelineGenericService, | ||
ReadSchemaService, | ||
ProcessorGroupStateService | ||
], | ||
}) | ||
export class SpecificationsModule { | ||
} | ||
export class SpecificationsModule {} |