@@ -132,7 +132,31 @@ public WebsiteStatus initNewWebsite(Website website, boolean redeploy) {
132
132
if (redeploy ) {
133
133
contentController .redeploy (env , website );
134
134
}
135
+
136
+ //IMPLEMENTATION OF ISSUE 59 Start
137
+ String eventPayloadEnd = Utils .buildEventPayload (EventAttribute .CR_NAME .concat (website .getMetadata ().getName ()),
138
+ EventAttribute .NAMESPACE .concat (website .getMetadata ().getNamespace ()),
139
+ EventAttribute .CODE .concat (EventAttribute .EventCode .WEBSITE_CREATE .name ()),
140
+ EventAttribute .TRACE_ID .concat (traceId ),
141
+ EventAttribute .TIMESTAMP .concat (LocalDateTime .now ().toString ()),
142
+ EventAttribute .MESSAGE .concat (website .toString ()),
143
+ EventAttribute .ENVIRONMENT .concat (env )
144
+ );
145
+ eventSourcingEngine .publishMessage (eventPayloadEnd );
146
+ //IMPLEMENTATION OF ISSUE 59 End
147
+
135
148
} catch (RuntimeException ex ) {
149
+ //IMPLEMENTATION OF ISSUE 59 Start
150
+ String eventPayloadEnd = Utils .buildEventPayload (EventAttribute .CR_NAME .concat (website .getMetadata ().getName ()),
151
+ EventAttribute .NAMESPACE .concat (website .getMetadata ().getNamespace ()),
152
+ EventAttribute .CODE .concat (EventAttribute .EventCode .WEBSITE_INIT_FAILED .name ()),
153
+ EventAttribute .TRACE_ID .concat (traceId ),
154
+ EventAttribute .TIMESTAMP .concat (LocalDateTime .now ().toString ()),
155
+ EventAttribute .MESSAGE .concat (website .toString ()),
156
+ EventAttribute .ENVIRONMENT .concat (env )
157
+ );
158
+ eventSourcingEngine .publishMessage (eventPayloadEnd );
159
+ //IMPLEMENTATION OF ISSUE 59 End
136
160
log .error ("Error processing env=" + env , ex );
137
161
exception = ex ;
138
162
// continue with processing other environments and throw exception after loop ends
@@ -142,21 +166,98 @@ public WebsiteStatus initNewWebsite(Website website, boolean redeploy) {
142
166
throw exception ;
143
167
}
144
168
145
- //IMPLEMENTATION OF ISSUE 59 Start
146
- String eventPayloadEnd = Utils .buildEventPayload (EventAttribute .CR_NAME .concat (website .getMetadata ().getName ()),
147
- EventAttribute .NAMESPACE .concat (website .getMetadata ().getNamespace ()),
148
- EventAttribute .CODE .concat (EventAttribute .EventCode .WEBSITE_CREATE .name ()),
149
- EventAttribute .TRACE_ID .concat (traceId ),
150
- EventAttribute .TIMESTAMP .concat (LocalDateTime .now ().toString ()),
151
- EventAttribute .MESSAGE .concat (website .toString ())
152
- );
153
- eventSourcingEngine .publishMessage (eventPayloadEnd );
154
- //IMPLEMENTATION OF ISSUE 59 End
169
+ log .debugf ("Infrastructure initialized. status=%s" , status );
170
+ return status ;
171
+ }
172
+
173
+
174
+
175
+ public WebsiteStatus initNewWebsite (Website website , boolean redeploy ,String traceId ) {
176
+
177
+ if (Objects .isNull (website .getConfig ()))
178
+ System .exit (1 );
179
+
180
+ Set <String > enabledEnvs = website .getEnabledEnvs ();
181
+ log .infof ("Init infrastructure for websiteId=%s, enabledEnvs=%s redeploy=%s" , website .getId (), enabledEnvs , redeploy );
182
+ websiteRepository .addWebsite (website );
183
+
184
+ RuntimeException exception = null ;
185
+ WebsiteStatus status = website .getStatus ();
186
+ if (status == null ) {
187
+ status = new WebsiteStatus ();
188
+ }
189
+ for (String env : enabledEnvs ) {
190
+ try {
191
+ log .debugf ("Processing env=%s" , env );
192
+
193
+ setupCoreServices (env , website );
194
+
195
+ String apiHost = null ;
196
+ Integer port = null ;
197
+ if (ingressController .isEnabled ()) {
198
+ Ingress ingress = ingressController .updateIngress (env , website );
199
+ if (ingress != null ) {
200
+ String contentHost = ingress .getSpec ().getRules ().get (0 ).getHost ();
201
+ status .addEnvHost (env , contentHost );
202
+ }
203
+ } else if (routerController .isEnabled ()) {
204
+ List <Route > contentRoutes = routerController .updateWebsiteRoutes (env , website );
205
+ if (contentRoutes != null && contentRoutes .size () > 0 ) {
206
+ String contentHost = contentRoutes .get (0 ).getSpec ().getHost ();
207
+ status .addEnvHost (env , contentHost );
208
+ }
209
+ routerController .updateApiRoute (env , website );
210
+ } else {
211
+ log .infof ("No routing created" );
212
+ }
213
+
214
+ if (redeploy ) {
215
+ contentController .redeploy (env , website );
216
+ }
217
+
218
+ //IMPLEMENTATION OF ISSUE 59 Start
219
+ String eventPayloadEnd = Utils .buildEventPayload (EventAttribute .CR_NAME .concat (website .getMetadata ().getName ()),
220
+ EventAttribute .NAMESPACE .concat (website .getMetadata ().getNamespace ()),
221
+ EventAttribute .CODE .concat (EventAttribute .EventCode .WEBSITE_CREATE .name ()),
222
+ EventAttribute .TRACE_ID .concat (traceId ),
223
+ EventAttribute .TIMESTAMP .concat (LocalDateTime .now ().toString ()),
224
+ EventAttribute .MESSAGE .concat (website .toString ()),
225
+ EventAttribute .ENVIRONMENT .concat (env )
226
+ );
227
+ eventSourcingEngine .publishMessage (eventPayloadEnd );
228
+ //IMPLEMENTATION OF ISSUE 59 End
229
+
230
+ } catch (RuntimeException ex ) {
231
+ //IMPLEMENTATION OF ISSUE 59 Start
232
+ String eventPayloadEnd = Utils .buildEventPayload (EventAttribute .CR_NAME .concat (website .getMetadata ().getName ()),
233
+ EventAttribute .NAMESPACE .concat (website .getMetadata ().getNamespace ()),
234
+ EventAttribute .CODE .concat (EventAttribute .EventCode .WEBSITE_INIT_FAILED .name ()),
235
+ EventAttribute .TRACE_ID .concat (traceId ),
236
+ EventAttribute .TIMESTAMP .concat (LocalDateTime .now ().toString ()),
237
+ EventAttribute .MESSAGE .concat (website .toString ()),
238
+ EventAttribute .ENVIRONMENT .concat (env )
239
+ );
240
+ eventSourcingEngine .publishMessage (eventPayloadEnd );
241
+ //IMPLEMENTATION OF ISSUE 59 End
242
+ log .error ("Error processing env=" + env , ex );
243
+ exception = ex ;
244
+ // continue with processing other environments and throw exception after loop ends
245
+ }
246
+ }
247
+ if (exception != null ) {
248
+ throw exception ;
249
+ }
155
250
156
251
log .debugf ("Infrastructure initialized. status=%s" , status );
157
252
return status ;
158
253
}
159
254
255
+
256
+
257
+
258
+
259
+
260
+
160
261
private void setupCoreServices (String env , Website website ) {
161
262
String namespace = website .getMetadata ().getNamespace ();
162
263
final String websiteName = Utils .getWebsiteName (website );
@@ -189,6 +290,40 @@ public void deleteInfrastructure(Website website) {
189
290
}
190
291
}
191
292
293
+
294
+
295
+ public void deleteInfrastructure (Website website ,String traceId ) {
296
+ log .infof ("Delete infrastructure for websiteId=%s" , website .getId ());
297
+
298
+ String namespace = website .getMetadata ().getNamespace ();
299
+ final String websiteName = Utils .getWebsiteName (website );
300
+
301
+ for (String env : website .getEnabledEnvs ()) {
302
+ contentController .deleteDeployment (env , namespace , websiteName );
303
+ contentController .deleteConfigs (env , namespace , website );
304
+
305
+ if (ingressController .isEnabled ()) {
306
+ ingressController .deleteIngress (env , website );
307
+ } else if (routerController .isEnabled ()) {
308
+ routerController .deleteWebsiteRoutes (env , website );
309
+ } else {
310
+ log .infof ("No routing deleted" );
311
+ }
312
+
313
+ String eventPayload = Utils .buildEventPayload (EventAttribute .CR_NAME .concat (website .getMetadata ().getName ()),
314
+ EventAttribute .NAMESPACE .concat (website .getMetadata ().getNamespace ()),
315
+ EventAttribute .CODE .concat (EventAttribute .EventCode .WEBSITE_DELETED .name ()),
316
+ EventAttribute .TRACE_ID .concat (traceId ),
317
+ EventAttribute .TIMESTAMP .concat (LocalDateTime .now ().toString ()),
318
+ EventAttribute .MESSAGE .concat (website .toString ()),
319
+ EventAttribute .ENVIRONMENT .concat (env )
320
+ );
321
+ eventSourcingEngine .publishMessage (eventPayload );
322
+
323
+ }
324
+ }
325
+
326
+
192
327
public List <Future > updateRelatedComponents (List <Website > authorizedWebsites , String gitUrl , String ref , Set <String > updatedWebsites ) {
193
328
List <Future > updates = new ArrayList <>();
194
329
// Iterate over authorized websites
@@ -327,16 +462,6 @@ public static Website createWebsiteCopy(Website website, String previewId, Strin
327
462
public void createOrUpdateWebsite (Website website , boolean redeploy ) throws GitAPIException , IOException {
328
463
log .infof ("Create/Update website website_id=%s redeploy=%s" , website .getId (), redeploy );
329
464
330
- String traceId = UUID .randomUUID ().toString ();
331
- String eventPayloadStart = Utils .buildEventPayload (EventAttribute .CR_NAME .concat (website .getMetadata ().getName ()),
332
- EventAttribute .NAMESPACE .concat (website .getMetadata ().getNamespace ()),
333
- EventAttribute .CODE .concat (EventAttribute .EventCode .WEBSITE_CREATE_OR_UPDATE_INIT .name ()),
334
- EventAttribute .TRACE_ID .concat (traceId ),
335
- EventAttribute .TIMESTAMP .concat (LocalDateTime .now ().toString ()),
336
- EventAttribute .MESSAGE .concat (website .toString ())
337
- );
338
- eventSourcingEngine .publishMessage (eventPayloadStart );
339
-
340
465
if (!websiteController .isCrdEnabled ()) {
341
466
deployNewWebsite (website , true , redeploy );
342
467
return ;
@@ -349,40 +474,29 @@ public void createOrUpdateWebsite(Website website, boolean redeploy) throws GitA
349
474
if (existingWebsite != null ) {
350
475
websiteController .updateStatus (existingWebsite , WebsiteStatus .STATUS .FORCE_UPDATE );
351
476
352
- //IMPLEMENTATION OF ISSUE 59 Start
353
- String eventPayload = Utils .buildEventPayload (EventAttribute .CR_NAME .concat (website .getMetadata ().getName ()),
354
- EventAttribute .NAMESPACE .concat (website .getMetadata ().getNamespace ()),
355
- EventAttribute .CODE .concat (EventAttribute .EventCode .PREVIEW_UPDATE .name ()),
356
- EventAttribute .TRACE_ID .concat (traceId ),
357
- EventAttribute .TIMESTAMP .concat (LocalDateTime .now ().toString ()),
358
- EventAttribute .MESSAGE .concat (existingWebsite .toString ())
359
- );
360
- eventSourcingEngine .publishMessage (eventPayload );
361
- //IMPLEMENTATION OF ISSUE 59 End
362
-
363
477
} else { // This is basically creation of new website
364
478
websiteController .getWebsiteClient ()
365
479
.inNamespace (website .getMetadata ().getNamespace ())
366
480
.withName (website .getMetadata ().getName ())
367
481
.createOrReplace (website );
368
-
369
- //IMPLEMENTATION OF ISSUE 59 Start
370
- String eventPayload = Utils .buildEventPayload (EventAttribute .CR_NAME .concat (website .getMetadata ().getName ()),
371
- EventAttribute .NAMESPACE .concat (website .getMetadata ().getNamespace ()),
372
- EventAttribute .CODE .concat (EventAttribute .EventCode .PREVIEW_CREATE .name ()),
373
- EventAttribute .TRACE_ID .concat (traceId ),
374
- EventAttribute .TIMESTAMP .concat (LocalDateTime .now ().toString ()),
375
- EventAttribute .MESSAGE .concat (website .toString ())
376
- );
377
- eventSourcingEngine .publishMessage (eventPayload );
378
- //IMPLEMENTATION OF ISSUE 59 End
379
-
380
482
}
381
483
}
382
484
383
485
public void deleteWebsite (Website website ) {
384
486
log .infof ("Deleting website website_id=%s" , website .getId ());
385
487
488
+ String traceId = UUID .randomUUID ().toString ();
489
+ //IMPLEMENTATION OF ISSUE 59 Start
490
+ String eventPayload = Utils .buildEventPayload (EventAttribute .CR_NAME .concat (website .getMetadata ().getName ()),
491
+ EventAttribute .NAMESPACE .concat (website .getMetadata ().getNamespace ()),
492
+ EventAttribute .CODE .concat (EventAttribute .EventCode .WEBSITE_DELETE_INIT .name ()),
493
+ EventAttribute .TRACE_ID .concat (traceId ),
494
+ EventAttribute .TIMESTAMP .concat (LocalDateTime .now ().toString ()),
495
+ EventAttribute .MESSAGE .concat (website .toString ())
496
+ );
497
+ eventSourcingEngine .publishMessage (eventPayload );
498
+ //IMPLEMENTATION OF ISSUE 59 End
499
+
386
500
if (websiteController .isCrdEnabled ()) {
387
501
websiteController .getWebsiteClient ().inNamespace (website .getMetadata ().getNamespace ()).delete (website );
388
502
} else {
@@ -391,22 +505,27 @@ public void deleteWebsite(Website website) {
391
505
log .error ("website doesn't exists in memory" );
392
506
return ;
393
507
}
394
- deleteInfrastructure (websiteToDelete );
508
+ deleteInfrastructure (websiteToDelete , traceId );
395
509
}
396
- //IMPLEMENTATION OF ISSUE 59 Start
397
- String eventPayload = Utils .buildEventPayload (EventAttribute .CR_NAME .concat (website .getMetadata ().getName ()),
398
- EventAttribute .NAMESPACE .concat (website .getMetadata ().getNamespace ()),
399
- EventAttribute .CODE .concat (EventAttribute .EventCode .PREVIEW_DELETE .name ()),
400
- EventAttribute .MESSAGE .concat ("website preview deleted" )
401
- );
402
- eventSourcingEngine .publishMessage (eventPayload );
403
- //IMPLEMENTATION OF ISSUE 59 End
510
+
404
511
}
405
512
406
513
public WebsiteStatus deployNewWebsite (Website website , boolean updateGitIfExists , boolean redeploy ) throws IOException , GitAPIException {
514
+
515
+ String traceId = UUID .randomUUID ().toString ();
516
+
517
+ String eventPayloadStart = Utils .buildEventPayload (EventAttribute .CR_NAME .concat (website .getMetadata ().getName ()),
518
+ EventAttribute .NAMESPACE .concat (website .getMetadata ().getNamespace ()),
519
+ EventAttribute .CODE .concat (EventAttribute .EventCode .WEBSITE_CREATE_OR_UPDATE_INIT .name ()),
520
+ EventAttribute .TRACE_ID .concat (traceId ),
521
+ EventAttribute .TIMESTAMP .concat (LocalDateTime .now ().toString ()),
522
+ EventAttribute .MESSAGE .concat (website .toString ())
523
+ );
524
+ eventSourcingEngine .publishMessage (eventPayloadStart );
525
+
407
526
WebsiteConfig websiteConfig = gitWebsiteConfigService .cloneRepo (website , updateGitIfExists );
408
527
website .setConfig (websiteConfig );
409
- return initNewWebsite (website , redeploy );
528
+ return initNewWebsite (website , redeploy , traceId );
410
529
}
411
530
412
531
public void updateAndRegisterWebsite (Website website , boolean updateGitIfExists ) throws GitAPIException , IOException {
0 commit comments