@@ -2,6 +2,7 @@ import isEmpty from 'lodash/isEmpty'
22import { ServiceConnection } from '@cloudgraph/sdk'
33import { RawGcpDataprocCluster } from './data'
44import services from '../../enums/services'
5+ import { RawGcpDataprocWorkflowTemplate } from '../dataprocWorkflowTemplate/data'
56
67export default ( {
78 service,
@@ -14,7 +15,7 @@ export default ({
1415} ) : {
1516 [ property : string ] : ServiceConnection [ ]
1617} => {
17- const { id } = service
18+ const { id, Labels } = service
1819 const connections : ServiceConnection [ ] = [ ]
1920
2021 /**
@@ -26,7 +27,6 @@ export default ({
2627 } = data . find ( ( { name } ) => name === services . dataprocJob )
2728
2829 if ( jobs ?. data ?. [ region ] ) {
29-
3030 const filtered = jobs . data [ region ] . filter (
3131 ( { placement } ) => placement . clusterUuid === id
3232 )
@@ -42,6 +42,35 @@ export default ({
4242 }
4343 }
4444
45+ /**
46+ * Find Dataproc Workflow Template
47+ */
48+ const flatClusterLabels = Object . keys ( Labels || { } ) . map ( key => `${ key } :${ Labels [ key ] } ` )
49+
50+ const templates : {
51+ name : string
52+ data : { [ property : string ] : any [ ] }
53+ } = data . find ( ( { name } ) => name === services . dataprocWorkflowTemplate )
54+
55+ if ( templates ?. data ?. [ region ] ) {
56+ const filtered = templates . data [ region ]
57+ . filter ( ( template : RawGcpDataprocWorkflowTemplate ) => ! isEmpty (
58+ Object . keys ( template ?. placement ?. clusterSelector ?. clusterLabels || { } )
59+ . map ( key => `${ key } :${ template . placement . clusterSelector . clusterLabels [ key ] } ` )
60+ . filter ( cluster => flatClusterLabels . includes ( cluster ) )
61+ )
62+ )
63+
64+ for ( const { id } of filtered ) {
65+ connections . push ( {
66+ id,
67+ resourceType : services . dataprocWorkflowTemplate ,
68+ relation : 'child' ,
69+ field : 'dataprocWorkflowTemplates' ,
70+ } )
71+ }
72+ }
73+
4574 const result = {
4675 [ id ] : connections ,
4776 }
0 commit comments