@@ -23,16 +23,16 @@ module.exports = class MtaTransformer {
2323
2424 async readMtaExtensions ( ) {
2525 let mtaExtensions = [ ]
26- for ( let file of this . mtaExtensionPaths ) {
27- let mtaExt = cds . parse . yaml ( await cds . utils . read ( cds . utils . path . join ( cds . root , file ) ) )
28- if ( mtaExt && mtaExt [ "_schema-version" ] . split ( "." ) [ 0 ] === this . mta [ "_schema-version" ] . split ( "." ) [ 0 ] && mtaExt [ "extends" ] === this . mta [ "ID" ] ) {
29- mtaExtensions . push ( mtaExt )
30- } else {
31- console . log ( `⚠️ ${ file } is not a valid mta extension file. _schema major version or extends doesn't match. Skipping...` )
32- }
26+ for ( let file of this . mtaExtensionPaths ) {
27+ let mtaExt = cds . parse . yaml ( await cds . utils . read ( cds . utils . path . join ( cds . root , file ) ) )
28+ if ( mtaExt && mtaExt [ "_schema-version" ] . split ( "." ) [ 0 ] === this . mta [ "_schema-version" ] . split ( "." ) [ 0 ] && mtaExt [ "extends" ] === this . mta [ "ID" ] ) {
29+ mtaExtensions . push ( mtaExt )
30+ } else {
31+ console . log ( `⚠️ ${ file } is not a valid mta extension file. _schema major version or extends doesn't match. Skipping...` )
32+ }
3333 }
3434 return mtaExtensions
35- }
35+ }
3636
3737 async getMta ( ) {
3838 this . mta = cds . parse . yaml ( await cds . utils . read ( join ( cds . root , this . mtaFilePath ) ) )
@@ -41,7 +41,7 @@ module.exports = class MtaTransformer {
4141
4242 this . mergedMta = this . merge ( this . mta , this . mtaExtensions )
4343
44- if ( this . mergedMta . parameters ) {
44+ if ( this . mergedMta . parameters ) {
4545 this . mergedMta . modules = replacePlaceholders ( this . mergedMta . modules , this . mergedMta . parameters )
4646 this . mergedMta . resources = replacePlaceholders ( this . mergedMta . resources , this . mergedMta . parameters )
4747 }
@@ -78,7 +78,7 @@ module.exports = class MtaTransformer {
7878 merge ( mta , mtaExtensions ) {
7979 let mergedMta = mta
8080
81- for ( let mtaExtension of mtaExtensions ) {
81+ for ( let mtaExtension of mtaExtensions ) {
8282 // Merge parameters
8383 mergedMta . parameters = mergeObj ( mergedMta . parameters , mtaExtension . parameters )
8484
@@ -94,21 +94,26 @@ module.exports = class MtaTransformer {
9494 }
9595
9696 async getServiceInstances ( ) {
97- if ( this . serviceInstances . size !== 0 ) return this . serviceInstances
97+ if ( this . serviceInstances . size !== 0 ) return this . serviceInstances
9898
99- if ( ! this . mergedMta ) await this . getMta ( )
99+ if ( ! this . mergedMta ) await this . getMta ( )
100100
101101 let managedSvcs = this . mergedMta ?. resources . filter ( r => r . type === 'org.cloudfoundry.managed-service' ) || [ ]
102- for ( let svc of managedSvcs ) {
103- this . serviceInstances . set (
104- svc . parameters [ "service" ] && svc . parameters [ "service-plan" ] ? convertHypenNameToCamelcase ( svc . parameters [ "service" ] + "-" + svc . parameters [ "service-plan" ] ) : null ,
105- {
106- name : svc . name ,
107- serviceOfferingName : svc . parameters [ "service" ] ? svc . parameters [ "service" ] : null ,
108- servicePlanName : svc . parameters [ "service-plan" ] ? svc . parameters [ "service-plan" ] : null ,
109- parameters : svc . parameters [ "config" ] ? svc . parameters [ "config" ] : { }
110- }
111- )
102+ for ( let svc of managedSvcs ) {
103+ try {
104+ this . serviceInstances . set (
105+ convertHypenNameToCamelcase ( svc . parameters [ "service" ] + "-" + svc . parameters [ "service-plan" ] ) ,
106+ {
107+ name : svc . name ,
108+ serviceOfferingName : svc . parameters [ "service" ] ,
109+ servicePlanName : svc . parameters [ "service-plan" ] ,
110+ parameters : svc . parameters [ "config" ] || { }
111+ }
112+ )
113+ } catch ( err ) {
114+ console . warn ( `⚠️ Error processing service instance ${ svc . name } - ${ err . message } . Skipping...` )
115+ continue
116+ }
112117 }
113118
114119 // for xsuaa service instance, remove oauth2-configuration -> redirect-uris as it is filled by service-instance.yaml template
@@ -151,7 +156,7 @@ module.exports = class MtaTransformer {
151156 async getServiceBindings ( ) {
152157 if ( this . serviceBindings . size !== 0 ) return this . serviceBindings
153158
154- if ( this . workloads . size === 0 ) await this . getWorkloads ( )
159+ if ( this . workloads . size === 0 ) await this . getWorkloads ( )
155160
156161 return this . serviceBindings
157162 }
@@ -181,9 +186,9 @@ module.exports = class MtaTransformer {
181186 serviceInstanceName : consumedBTPService . name ,
182187 }
183188 if ( this . serviceBindings . has ( serviceBindingNameKey ) &&
184- md5 ( JSON . stringify ( this . serviceBindings . get ( serviceBindingNameKey ) ) ) !== md5 ( JSON . stringify ( serviceBindingValue ) ) ) {
189+ md5 ( JSON . stringify ( this . serviceBindings . get ( serviceBindingNameKey ) ) ) !== md5 ( JSON . stringify ( serviceBindingValue ) ) ) {
185190
186- let serviceBindingNewName = consumedBTPService . name + "-" + module . name + this . serviceBindingNameSuffix
191+ let serviceBindingNewName = consumedBTPService . name + "-" + module . name + this . serviceBindingNameSuffix
187192 let serviceBindingNewNameKey = convertHypenNameToCamelcase ( serviceBindingNewName )
188193 this . serviceBindings . set ( serviceBindingNewNameKey , {
189194 name : serviceBindingNewName ,
@@ -194,14 +199,14 @@ module.exports = class MtaTransformer {
194199 } )
195200 workloadServiceBindings . push ( serviceBindingNewName )
196201 } else if ( this . serviceBindings . has ( serviceBindingNameKey ) &&
197- md5 ( JSON . stringify ( this . serviceBindings . get ( serviceBindingNameKey ) ) ) === md5 ( JSON . stringify ( serviceBindingValue ) ) ) {
202+ md5 ( JSON . stringify ( this . serviceBindings . get ( serviceBindingNameKey ) ) ) === md5 ( JSON . stringify ( serviceBindingValue ) ) ) {
198203
199204 workloadServiceBindings . push ( serviceBindingName )
200205 continue
201206 }
202207 else {
203208 workloadServiceBindings . push ( serviceBindingName )
204- this . serviceBindings . set ( serviceBindingNameKey , serviceBindingValue )
209+ this . serviceBindings . set ( serviceBindingNameKey , serviceBindingValue )
205210 }
206211 }
207212 return workloadServiceBindings
@@ -212,7 +217,7 @@ module.exports = class MtaTransformer {
212217 for ( const [ key , value ] of Object . entries ( properties ) ) {
213218 env . push ( {
214219 name : key ,
215- value : typeof value === 'string' ? value : JSON . stringify ( value )
220+ value : typeof value === 'string' ? value : JSON . stringify ( value )
216221 } )
217222 }
218223 return env
@@ -231,7 +236,7 @@ module.exports = class MtaTransformer {
231236 }
232237 if ( module . path ?. includes ( "gen/mtx/sidecar" ) || module . type === 'com.sap.application.content' ) {
233238 workload . jobDefinition = {
234- type : module . type === 'com.sap.application.content' ? "Content" : "TenantOperation" ,
239+ type : module . type === 'com.sap.application.content' ? "Content" : "TenantOperation" ,
235240 image : null
236241 }
237242 } else if ( module . path ?. includes ( "gen/srv" ) ) {
@@ -255,9 +260,9 @@ module.exports = class MtaTransformer {
255260 // delete existing TENANT_HOST_PATTERN if any; Handled in cap-operator-cro.yaml template
256261 if ( workload . deploymentDefinition ?. type == "Router" ) {
257262 if ( workload . deploymentDefinition . env ) {
258- const index = workload . deploymentDefinition . env . findIndex ( e => e . name === "TENANT_HOST_PATTERN" )
259- if ( index != - 1 )
260- workload . deploymentDefinition . env . splice ( index , 1 )
263+ const index = workload . deploymentDefinition . env . findIndex ( e => e . name === "TENANT_HOST_PATTERN" )
264+ if ( index != - 1 )
265+ workload . deploymentDefinition . env . splice ( index , 1 )
261266 }
262267 }
263268
0 commit comments