@@ -15,6 +15,7 @@ import {ToolsService} from '../../../flo/task/tools.service';
1515import get from 'lodash.get' ;
1616import set from 'lodash.set' ;
1717import { Platform } from '../../../shared/model/platform.model' ;
18+ import { TaskExecutionPage } from 'src/app/shared/model/task-execution.model' ;
1819
1920@Injectable ( )
2021export class TaskLaunchService {
@@ -77,141 +78,145 @@ export class TaskLaunchService {
7778 constructor ( private taskService : TaskService , private appService : AppService , private toolsService : ToolsService ) { }
7879
7980 config ( id : string ) : Observable < TaskLaunchConfig > {
80- return this . taskService
81- . getTask ( id , true )
82- . pipe (
83- mergeMap ( ( task : Task ) => {
84- const taskConversion = this . toolsService . parseTaskTextToGraph ( task . dslText ) ;
85- const platforms = this . taskService . getPlatforms ( ) ;
86- return zip ( of ( task ) , taskConversion , platforms ) ;
87- } )
88- )
89- . pipe (
90- mergeMap ( ( [ task , taskConversion , platforms ] ) => {
91- const appNames = taskConversion . graph . nodes
92- . filter ( node => node . name !== 'START' && node . name !== 'END' )
93- . map ( node => get ( node , 'name' ) as string ) ;
94- const appVersions = from ( appNames )
95- . pipe ( distinct ( ) )
96- . pipe (
97- mergeMap ( appName =>
98- this . appService . getAppVersions ( appName + '' , 'task' as any ) . pipe (
99- map ( apps =>
100- apps . reduce ( ( mapAccumulator , app ) => {
101- const a = mapAccumulator . get ( app . name ) ;
102- if ( a ) {
103- if ( app . defaultVersion ) {
104- a . version = app . version ;
105- }
106- a . versions = [ ...a . versions , ...[ app ] ] ;
107- } else {
108- mapAccumulator . set ( app . name , {
109- version : app . defaultVersion ? app . version : null ,
110- versions : [ app ]
111- } ) ;
81+ return this . taskService . getTask ( id , true ) . pipe (
82+ mergeMap ( ( task : Task ) => {
83+ const taskConversion = this . toolsService . parseTaskTextToGraph ( task . dslText ) ;
84+ const platforms = this . taskService . getPlatforms ( ) ;
85+ return zip ( of ( task ) , taskConversion , platforms ) ;
86+ } ) ,
87+ mergeMap ( ( [ task , taskConversion , platforms ] ) => {
88+ const appNames = taskConversion . graph . nodes
89+ . filter ( node => node . name !== 'START' && node . name !== 'END' )
90+ . map ( node => get ( node , 'name' ) as string ) ;
91+ const appVersions = from ( appNames )
92+ . pipe ( distinct ( ) )
93+ . pipe (
94+ mergeMap ( appName =>
95+ this . appService . getAppVersions ( appName + '' , 'task' as any ) . pipe (
96+ map ( apps =>
97+ apps . reduce ( ( mapAccumulator , app ) => {
98+ const a = mapAccumulator . get ( app . name ) ;
99+ if ( a ) {
100+ if ( app . defaultVersion ) {
101+ a . version = app . version ;
112102 }
113- return mapAccumulator ;
114- } , new Map < string , { version : string ; versions : App [ ] } > ( ) )
115- )
103+ a . versions = [ ...a . versions , ...[ app ] ] ;
104+ } else {
105+ mapAccumulator . set ( app . name , {
106+ version : app . defaultVersion ? app . version : null ,
107+ versions : [ app ]
108+ } ) ;
109+ }
110+ return mapAccumulator ;
111+ } , new Map < string , { version : string ; versions : App [ ] } > ( ) )
116112 )
117113 )
118114 )
119- // we should have distinct maps for all apps so
120- // its safe to just blindly combine maps and get one final
121- . pipe ( reduce ( ( acc , val ) => new Map ( [ ...acc , ...val ] ) ) ) ;
122- return zip ( of ( task ) , of ( taskConversion ) , of ( platforms ) , appVersions ) ;
123- } )
124- )
125- . pipe (
126- map ( ( [ task , taskConversion , platforms , appVersions ] ) => {
127- const c = new TaskLaunchConfig ( ) ;
128- if ( task . lastTaskExecution ) {
129- c . deploymentProperties = task . lastTaskExecution
130- . getDeploymentPropertiesToArray ( )
131- . filter ( tuple => tuple [ 1 ] !== '******' )
132- . map ( tuple => `${ tuple [ 0 ] } =${ tuple [ 1 ] } ` ) ;
133- } else {
134- c . deploymentProperties = [ ] ;
135- }
115+ )
116+ // we should have distinct maps for all apps so
117+ // its safe to just blindly combine maps and get one final
118+ . pipe ( reduce ( ( acc , val ) => new Map ( [ ...acc , ...val ] ) ) ) ;
119+ const lastExecution = this . taskService . getExecutions ( 0 , 1 , task . name , '' , '' ) . pipe (
120+ map ( ( res : TaskExecutionPage ) => {
121+ if ( res . items ?. length > 0 ) {
122+ return res . items [ 0 ] ;
123+ }
124+ return null ;
125+ } )
126+ ) ;
127+ return zip ( of ( task ) , of ( taskConversion ) , of ( platforms ) , appVersions , lastExecution ) ;
128+ } ) ,
129+ map ( ( [ task , taskConversion , platforms , appVersions , lastExecution ] ) => {
130+ const c = new TaskLaunchConfig ( ) ;
131+ if ( task . lastTaskExecution ) {
132+ c . deploymentProperties = task . lastTaskExecution
133+ . getDeploymentPropertiesToArray ( )
134+ . filter ( tuple => tuple [ 1 ] !== '******' )
135+ . map ( tuple => `${ tuple [ 0 ] } =${ tuple [ 1 ] } ` ) ;
136+ } else {
137+ c . deploymentProperties = [ ] ;
138+ }
136139
137- c . id = id ;
140+ c . id = id ;
138141
139- c . apps = taskConversion . graph . nodes
140- . filter ( node => node . name !== 'START' && node . name !== 'END' )
141- . map ( node => {
142- const n = get ( node , 'name' ) as string ;
142+ c . apps = taskConversion . graph . nodes
143+ . filter ( node => node . name !== 'START' && node . name !== 'END' )
144+ . map ( node => {
145+ const n = get ( node , 'name' ) as string ;
143146
144- return {
145- origin : get ( node , 'name' ) ,
146- name : get ( node . metadata , 'label' ) || get ( node , 'name' ) ,
147- type : 'task' ,
148- version : appVersions . get ( n ) . version ,
149- versions : appVersions . get ( n ) . versions ,
150- options : null ,
151- optionsState : {
152- isLoading : false ,
153- isOnError : false ,
154- isInvalid : false
155- }
156- } ;
157- } ) ;
147+ return {
148+ origin : get ( node , 'name' ) ,
149+ name : get ( node . metadata , 'label' ) || get ( node , 'name' ) ,
150+ type : 'task' ,
151+ version : appVersions . get ( n ) . version ,
152+ versions : appVersions . get ( n ) . versions ,
153+ options : null ,
154+ optionsState : {
155+ isLoading : false ,
156+ isOnError : false ,
157+ isInvalid : false
158+ }
159+ } ;
160+ } ) ;
158161
159- c . deployers = [
160- {
161- id : 'memory' ,
162- name : 'memory' ,
163- form : 'autocomplete' ,
164- type : 'java.lang.Integer' ,
165- value : null ,
166- defaultValue : null ,
167- suffix : 'MB'
168- } ,
169- {
170- id : 'cpu' ,
171- name : 'cpu' ,
172- form : 'autocomplete' ,
173- type : 'java.lang.Integer' ,
174- value : null ,
175- defaultValue : null ,
176- suffix : 'Core(s)'
177- } ,
178- {
179- id : 'disk' ,
180- name : 'disk' ,
181- form : 'autocomplete' ,
182- type : 'java.lang.Integer' ,
183- value : null ,
184- defaultValue : null ,
185- suffix : 'MB'
186- }
187- ] ;
162+ c . deployers = [
163+ {
164+ id : 'memory' ,
165+ name : 'memory' ,
166+ form : 'autocomplete' ,
167+ type : 'java.lang.Integer' ,
168+ value : null ,
169+ defaultValue : null ,
170+ suffix : 'MB'
171+ } ,
172+ {
173+ id : 'cpu' ,
174+ name : 'cpu' ,
175+ form : 'autocomplete' ,
176+ type : 'java.lang.Integer' ,
177+ value : null ,
178+ defaultValue : null ,
179+ suffix : 'Core(s)'
180+ } ,
181+ {
182+ id : 'disk' ,
183+ name : 'disk' ,
184+ form : 'autocomplete' ,
185+ type : 'java.lang.Integer' ,
186+ value : null ,
187+ defaultValue : null ,
188+ suffix : 'MB'
189+ }
190+ ] ;
188191
189- c . platform = {
190- id : 'platform' ,
191- name : 'platform' ,
192- form : 'select' ,
193- type : 'java.lang.String' ,
194- defaultValue : '' ,
195- values : ( platforms as Array < Platform > ) . map ( ( platform : Platform ) => ( {
196- key : platform . name ,
197- name : platform . name ,
198- type : platform . type ,
199- options : platform . options
200- } ) )
201- } ;
192+ c . platform = {
193+ id : 'platform' ,
194+ name : 'platform' ,
195+ form : 'select' ,
196+ type : 'java.lang.String' ,
197+ defaultValue : '' ,
198+ values : ( platforms as Array < Platform > ) . map ( ( platform : Platform ) => ( {
199+ key : platform . name ,
200+ name : platform . name ,
201+ type : platform . type ,
202+ options : platform . options
203+ } ) )
204+ } ;
202205
203- // just set empty options and loading state,
204- // will get loaded later
205- c . ctr = {
206- options : [ ] ,
207- optionsState : {
208- isLoading : true ,
209- isOnError : false
210- }
211- } ;
212- return c ;
213- } )
214- ) ;
206+ // just set empty options and loading state,
207+ // will get loaded later
208+ c . ctr = {
209+ options : [ ] ,
210+ optionsState : {
211+ isLoading : true ,
212+ isOnError : false
213+ }
214+ } ;
215+
216+ c . lastExecution = lastExecution ;
217+ return c ;
218+ } )
219+ ) ;
215220 }
216221
217222 ctrOptions ( ) : Observable < ValuedConfigurationMetadataProperty [ ] | unknown > {
0 commit comments