35
35
import org .jboss .as .controller .client .helpers .ClientConstants ;
36
36
import org .jboss .as .controller .client .helpers .Operations ;
37
37
import org .jboss .dmr .ModelNode ;
38
+ import org .jboss .dmr .ModelType ;
38
39
import org .jboss .dmr .Property ;
39
40
import org .jboss .galleon .Errors ;
40
41
import org .jboss .galleon .ProvisioningException ;
@@ -77,9 +78,9 @@ public class FeatureSpecGenerator implements ForkCallback {
77
78
String getBranchId (String spec , int dots ) {
78
79
int i = 0 ;
79
80
int index = 0 ;
80
- while (i <= dots ) {
81
+ while (i <= dots ) {
81
82
index = spec .indexOf ('.' , index + 1 );
82
- if (index < 0 ) {
83
+ if (index < 0 ) {
83
84
return spec ;
84
85
}
85
86
++i ;
@@ -97,8 +98,8 @@ FeatureSpecNode getSpec(String name) {
97
98
98
99
void addReferencedSpec (String referencedSpecName , String referencingSpec , FeatureSpecNode referencingNode ) {
99
100
Map <String , FeatureSpecNode > specs = referencedSpecs .get (referencedSpecName );
100
- if (specs != null ) {
101
- if (specs .size () == 1 ) {
101
+ if (specs != null ) {
102
+ if (specs .size () == 1 ) {
102
103
specs = new HashMap <>(specs );
103
104
referencedSpecs .put (referencedSpecName , specs );
104
105
}
@@ -140,7 +141,7 @@ public FeatureSpecGenerator() {
140
141
}
141
142
142
143
public FeatureSpecGenerator (String installation , Path outputDir , Map <String , Path > inheritedSpecs ,
143
- String mimimumStability , boolean fork , boolean debug ) {
144
+ String mimimumStability , boolean fork , boolean debug ) {
144
145
this .installation = installation ;
145
146
this .outputDir = outputDir ;
146
147
this .fork = fork ;
@@ -155,24 +156,24 @@ public int generateSpecs() throws ProvisioningException {
155
156
doGenerate ();
156
157
} finally {
157
158
final List <String > toClear = new ArrayList <>();
158
- for (Map .Entry <Object , Object > prop : System .getProperties ().entrySet ()) {
159
+ for (Map .Entry <Object , Object > prop : System .getProperties ().entrySet ()) {
159
160
final Object value = originalProps .get (prop .getKey ());
160
161
if (value != null ) {
161
162
System .setProperty (prop .getKey ().toString (), value .toString ());
162
163
} else {
163
164
toClear .add (prop .getKey ().toString ());
164
165
}
165
166
}
166
- for (String prop : toClear ) {
167
+ for (String prop : toClear ) {
167
168
System .clearProperty (prop );
168
169
}
169
- if (systemProps != null ) {
170
+ if (systemProps != null ) {
170
171
IoUtils .recursiveDelete (systemProps );
171
172
}
172
- if (standaloneSpecsFile != null ) {
173
+ if (standaloneSpecsFile != null ) {
173
174
IoUtils .recursiveDelete (standaloneSpecsFile );
174
175
}
175
- if (domainSpecsFile != null ) {
176
+ if (domainSpecsFile != null ) {
176
177
IoUtils .recursiveDelete (domainSpecsFile );
177
178
}
178
179
}
@@ -182,7 +183,7 @@ public int generateSpecs() throws ProvisioningException {
182
183
private void doGenerate () throws ProvisioningException {
183
184
final ModelNode standaloneFeatures ;
184
185
ModelNode domainRoots = null ;
185
- if (fork ) {
186
+ if (fork ) {
186
187
String minStab = mimimumStability == null ? "" : mimimumStability ;
187
188
ForkedEmbeddedUtil .fork (this , getStoredSystemProps (), installation , getStandaloneSpecsFile ().toString (), getDomainSpecsFile ().toString (), minStab );
188
189
standaloneFeatures = readSpecsFile (getStandaloneSpecsFile ());
@@ -193,12 +194,12 @@ private void doGenerate() throws ProvisioningException {
193
194
} catch (IOException ex ) {
194
195
throw new ProvisioningException (ex );
195
196
}
196
- if (Files .exists (Paths .get (installation ).resolve (WfConstants .DOMAIN ).resolve (WfConstants .CONFIGURATION ))) {
197
+ if (Files .exists (Paths .get (installation ).resolve (WfConstants .DOMAIN ).resolve (WfConstants .CONFIGURATION ))) {
197
198
domainRoots = readSpecsFile (getDomainSpecsFile ());
198
199
}
199
200
} else {
200
201
final Path home = Paths .get (installation );
201
- if (Files .exists (home .resolve (WfConstants .STANDALONE ).resolve (WfConstants .CONFIGURATION ))) {
202
+ if (Files .exists (home .resolve (WfConstants .STANDALONE ).resolve (WfConstants .CONFIGURATION ))) {
202
203
standaloneFeatures = readFeatureSpecs (createStandaloneServer (installation , mimimumStability , null ));
203
204
ModelNode result = generateModel (createStandaloneServer (installation , mimimumStability , "standalone-local.xml" ));
204
205
try {
@@ -212,7 +213,7 @@ private void doGenerate() throws ProvisioningException {
212
213
} else {
213
214
throw new ProvisioningException ("The installation does not include standalone configuration" );
214
215
}
215
- if (Files .exists (home .resolve (WfConstants .DOMAIN ).resolve (WfConstants .CONFIGURATION ))) {
216
+ if (Files .exists (home .resolve (WfConstants .DOMAIN ).resolve (WfConstants .CONFIGURATION ))) {
216
217
domainRoots = readFeatureSpecs (createEmbeddedHc (installation , mimimumStability ));
217
218
}
218
219
}
@@ -235,7 +236,7 @@ private void doGenerate() throws ProvisioningException {
235
236
}
236
237
237
238
rootNode .processChildren (FeatureSpecNode .STANDALONE_MODEL );
238
- if (domainRoots != null ) {
239
+ if (domainRoots != null ) {
239
240
rootNode .processChildren (FeatureSpecNode .PROFILE_MODEL );
240
241
rootNode .processChildren (FeatureSpecNode .DOMAIN_MODEL );
241
242
rootNode .processChildren (FeatureSpecNode .HOST_MODEL );
@@ -246,7 +247,7 @@ private void doGenerate() throws ProvisioningException {
246
247
247
248
@ Override
248
249
public void forkedForEmbedded (String ... args ) throws ConfigGeneratorException {
249
- if (args .length != 3 && args .length != 4 ) {
250
+ if (args .length != 3 && args .length != 4 ) {
250
251
final StringBuilder buf = new StringBuilder ();
251
252
StringUtils .append (buf , Arrays .asList (args ));
252
253
throw new IllegalArgumentException ("Expected 3-4 arguments but got " + Arrays .asList (args ));
@@ -269,20 +270,20 @@ public void forkedForEmbedded(String... args) throws ConfigGeneratorException {
269
270
270
271
@ Override
271
272
public void forkedEmbeddedMessage (String msg ) {
272
- if (debug ) {
273
+ if (debug ) {
273
274
System .out .println (msg );
274
275
}
275
276
}
276
277
277
278
protected Path getStoredSystemProps () throws ProvisioningException {
278
- if (systemProps == null ) {
279
+ if (systemProps == null ) {
279
280
systemProps = ForkedEmbeddedUtil .storeSystemProps ();
280
281
}
281
282
return systemProps ;
282
283
}
283
284
284
285
protected Path getStandaloneSpecsFile () throws ProvisioningException {
285
- if (standaloneSpecsFile == null ) {
286
+ if (standaloneSpecsFile == null ) {
286
287
try {
287
288
standaloneSpecsFile = Files .createTempFile ("wfgp" , "standalone-specs" );
288
289
} catch (IOException e ) {
@@ -293,7 +294,7 @@ protected Path getStandaloneSpecsFile() throws ProvisioningException {
293
294
}
294
295
295
296
protected Path getDomainSpecsFile () throws ProvisioningException {
296
- if (domainSpecsFile == null ) {
297
+ if (domainSpecsFile == null ) {
297
298
try {
298
299
domainSpecsFile = Files .createTempFile ("wfgp" , "domain-specs" );
299
300
} catch (IOException e ) {
@@ -305,14 +306,14 @@ protected Path getDomainSpecsFile() throws ProvisioningException {
305
306
306
307
protected FeatureSpec getInheritedSpec (String name ) throws ProvisioningException {
307
308
FeatureSpec spec = parsedInheritedSpecs .get (name );
308
- if (spec != null ) {
309
+ if (spec != null ) {
309
310
return spec ;
310
311
}
311
312
final Path path = inheritedSpecs .get (name );
312
- if (path == null ) {
313
+ if (path == null ) {
313
314
return null ;
314
315
}
315
- try (BufferedReader reader = Files .newBufferedReader (path )) {
316
+ try (BufferedReader reader = Files .newBufferedReader (path )) {
316
317
spec = FeatureSpecXmlParser .getInstance ().parse (reader );
317
318
} catch (IOException | XMLStreamException e ) {
318
319
throw new ProvisioningException ("Failed to parse " + name + " spec " + path , e );
@@ -338,7 +339,7 @@ private static String[] getCmdArgs(String mimimumStability, String serverConfig)
338
339
args .add ("--stability=" + mimimumStability );
339
340
}
340
341
if (serverConfig != null ) {
341
- args .add ("--server-config=" + serverConfig );
342
+ args .add ("--server-config=" + serverConfig );
342
343
}
343
344
return args .toArray (String []::new );
344
345
}
@@ -347,29 +348,95 @@ private static ModelNode generateModel(final EmbeddedManagedProcess server) thro
347
348
try {
348
349
server .start ();
349
350
Boolean all = Boolean .getBoolean ("org.wildfly.galleon.complete.model" );
350
- ModelNode rootAddress = Operations .createAddress ().setEmptyList ();
351
- if (!all ) {
352
- rootAddress = Operations .createAddress ("subsystem" , "*" );
353
- }
354
- final ModelNode op = Operations .createOperation ("read-resource-description" , rootAddress );
355
- op .get (ClientConstants .RECURSIVE ).set (true );
356
- final ModelNode result ;
357
- try {
358
- result = server .getModelControllerClient ().execute (op );
359
- } catch (IOException e ) {
360
- throw new ProvisioningException ("Failed to read feature descriptions" , e );
351
+ if (!all ) {
352
+ return readModel (server );
361
353
}
362
- if (!Operations .isSuccessfulOutcome (result )) {
363
- throw new ProvisioningException (Operations .getFailureDescription (result ).asString ());
364
- }
365
- return result .get ("result" );
354
+ return readAll (server );
366
355
} catch (EmbeddedProcessStartException ex ) {
367
356
throw new ProvisioningException ("Failed to read feature spec descriptions" , ex );
368
357
} finally {
369
358
server .stop ();
370
359
}
371
360
}
372
361
362
+ private static ModelNode readModel (final EmbeddedManagedProcess server ) throws ProvisioningException {
363
+ List <String > subsystems = listSubsystems (server );
364
+ ModelNode result = new ModelNode ();
365
+ ModelNode subsystemNodes = result .get ("children" ).get (ClientConstants .SUBSYSTEM ).get ("model-description" );
366
+ for (String subsystem : subsystems ) {
367
+ ModelNode address = Operations .createAddress (ClientConstants .SUBSYSTEM , subsystem );
368
+ ModelNode subsystemDescription = readResourceDescription (server , address );
369
+ subsystemDescription .get (ClientConstants .ADDRESS ).add (address );
370
+ subsystemNodes .get (subsystem ).set (subsystemDescription );
371
+ }
372
+ ModelNode address = Operations .createAddress (ClientConstants .DEPLOYMENT );
373
+ result .get ("children" ).get (ClientConstants .DEPLOYMENT ).get ("model-description" ).get ("*" ).set (readResourceDescription (server , address ));
374
+ result .remove (ClientConstants .RESULT );
375
+ return result ;
376
+ }
377
+
378
+ private static ModelNode readAll (final EmbeddedManagedProcess server ) throws ProvisioningException {
379
+ ModelNode rootAddress = Operations .createAddress ().setEmptyList ();
380
+ final ModelNode op = Operations .createOperation ("read-resource-description" , rootAddress );
381
+ op .get (ClientConstants .RECURSIVE ).set (true );
382
+ final ModelNode result ;
383
+ try {
384
+ result = server .getModelControllerClient ().execute (op );
385
+ } catch (IOException e ) {
386
+ throw new ProvisioningException ("Failed to read feature descriptions" , e );
387
+ }
388
+ if (!Operations .isSuccessfulOutcome (result )) {
389
+ throw new ProvisioningException (Operations .getFailureDescription (result ).asString ());
390
+ }
391
+ return result .get (ClientConstants .RESULT );
392
+ }
393
+
394
+ private static List <String > listSubsystems (final EmbeddedManagedProcess server ) throws ProvisioningException {
395
+ ModelNode rootAddress = Operations .createAddress ().setEmptyList ();
396
+ final ModelNode op = Operations .createOperation (ClientConstants .READ_CHILDREN_NAMES_OPERATION , rootAddress );
397
+ op .get (ClientConstants .CHILD_TYPE ).set (ClientConstants .SUBSYSTEM );
398
+ op .get ("include-singletons" ).set (true );
399
+ final ModelNode result ;
400
+ try {
401
+ result = server .getModelControllerClient ().execute (op );
402
+ } catch (IOException e ) {
403
+ throw new ProvisioningException ("Failed to read feature descriptions" , e );
404
+ }
405
+ if (!Operations .isSuccessfulOutcome (result )) {
406
+ throw new ProvisioningException (Operations .getFailureDescription (result ).asString ());
407
+ }
408
+ List <String > names = new ArrayList <>();
409
+ for (ModelNode name : result .get (ClientConstants .RESULT ).asList ()) {
410
+ names .add (name .asString ());
411
+ }
412
+ return names ;
413
+ }
414
+
415
+ private static ModelNode readResourceDescription (final EmbeddedManagedProcess server , ModelNode address ) throws ProvisioningException {
416
+ final ModelNode op = Operations .createOperation ("read-resource-description" , address );
417
+ op .get (ClientConstants .RECURSIVE ).set (true );
418
+ final ModelNode opResult ;
419
+ try {
420
+ opResult = server .getModelControllerClient ().execute (op );
421
+ } catch (IOException e ) {
422
+ throw new ProvisioningException ("Failed to read feature descriptions" , e );
423
+ }
424
+ if (!Operations .isSuccessfulOutcome (opResult )) {
425
+ throw new ProvisioningException (Operations .getFailureDescription (opResult ).asString ());
426
+ }
427
+ final ModelNode result = opResult .get (ClientConstants .RESULT );
428
+ if (ModelType .LIST == result .getType ()) {
429
+ ModelNode finalResult = new ModelNode ().setEmptyList ();
430
+ for (ModelNode node : result .asList ()) {
431
+ if (node .hasDefined (ClientConstants .RESULT )) {
432
+ finalResult .add (node .get (ClientConstants .RESULT ));
433
+ }
434
+ }
435
+ return finalResult ;
436
+ }
437
+ return result ;
438
+ }
439
+
373
440
private static ModelNode readFeatureSpecs (final EmbeddedManagedProcess server ) throws ProvisioningException {
374
441
try {
375
442
server .start ();
@@ -381,7 +448,7 @@ private static ModelNode readFeatureSpecs(final EmbeddedManagedProcess server) t
381
448
} catch (IOException e ) {
382
449
throw new ProvisioningException ("Failed to read feature descriptions" , e );
383
450
}
384
- if (!Operations .isSuccessfulOutcome (result )) {
451
+ if (!Operations .isSuccessfulOutcome (result )) {
385
452
throw new ProvisioningException (Operations .getFailureDescription (result ).asString ());
386
453
}
387
454
return result .require (ClientConstants .RESULT ).require ("feature" );
@@ -401,15 +468,15 @@ private ModelNode readSpecsFile(Path specsFile) throws ProvisioningException {
401
468
}
402
469
403
470
private void writeSpecsFile (Path specsFile , ModelNode specs ) throws ProvisioningException {
404
- try (BufferedWriter writer = Files .newBufferedWriter (specsFile )) {
471
+ try (BufferedWriter writer = Files .newBufferedWriter (specsFile )) {
405
472
writer .write (specs .asString ());
406
473
} catch (IOException e ) {
407
474
throw new ProvisioningException (Errors .writeFile (specsFile ), e );
408
475
}
409
476
}
410
477
411
478
private void writeModelFile (Path specsFile , ModelNode specs ) throws ProvisioningException {
412
- try (BufferedWriter writer = Files .newBufferedWriter (specsFile )) {
479
+ try (BufferedWriter writer = Files .newBufferedWriter (specsFile )) {
413
480
writer .write (specs .toJSONString (false ));
414
481
} catch (IOException e ) {
415
482
throw new ProvisioningException (Errors .writeFile (specsFile ), e );
0 commit comments