-
Notifications
You must be signed in to change notification settings - Fork 461
/
ParallelBootOperationContext.java
494 lines (416 loc) · 18.3 KB
/
ParallelBootOperationContext.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.controller;
import java.io.InputStream;
import java.util.List;
import java.util.Set;
import org.jboss.as.controller.access.Action;
import org.jboss.as.controller.access.AuthorizationResult;
import org.jboss.as.controller.access.ResourceAuthorization;
import org.jboss.as.controller.audit.AuditLogger;
import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.controller.capability.RuntimeCapability;
import org.jboss.as.controller.client.MessageSeverity;
import org.jboss.as.controller.logging.ControllerLogger;
import org.jboss.as.controller.notification.Notification;
import org.jboss.as.controller.persistence.ConfigurationPersistenceException;
import org.jboss.as.controller.persistence.ConfigurationPersister;
import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.Resource;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceRegistry;
import org.jboss.msc.service.ServiceTarget;
/**
* {@link OperationContext} implementation for parallel handling of subsystem operations during boot.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
@SuppressWarnings("deprecation")
class ParallelBootOperationContext extends AbstractOperationContext {
private final OperationContextImpl primaryContext;
private final List<ParsedBootOp> runtimeOps;
private Step lockStep;
private final int operationId;
private final ModelControllerImpl controller;
ParallelBootOperationContext(final ModelController.OperationTransactionControl transactionControl,
final ControlledProcessState processState, final OperationContextImpl primaryContext,
final List<ParsedBootOp> runtimeOps, final Thread controllingThread,
final ModelControllerImpl controller, final int operationId, final AuditLogger auditLogger,
final Resource model, final OperationStepHandler extraValidationStepHandler) {
super(primaryContext.getProcessType(), primaryContext.getRunningMode(), transactionControl, processState, true, auditLogger,
controller.getNotificationSupport(), controller, true, extraValidationStepHandler);
this.primaryContext = primaryContext;
this.runtimeOps = runtimeOps;
AbstractOperationContext.controllingThread.set(controllingThread);
//
this.controller = controller;
this.operationId = operationId;
}
void close() {
AbstractOperationContext.controllingThread.remove();
}
@Override
public void addStep(OperationStepHandler step, Stage stage) throws IllegalArgumentException {
if (activeStep == null) {
throw ControllerLogger.ROOT_LOGGER.noActiveStep();
}
addStep(activeStep.response, activeStep.operation, step, stage);
}
@Override
public void addStep(ModelNode operation, OperationStepHandler step, Stage stage) throws IllegalArgumentException {
if (activeStep == null) {
throw ControllerLogger.ROOT_LOGGER.noActiveStep();
}
addStep(activeStep.response, operation, step, stage);
}
@Override
public void addStep(ModelNode operation, OperationStepHandler step, Stage stage, final boolean addFirst) throws IllegalArgumentException {
if (activeStep == null) {
throw ControllerLogger.ROOT_LOGGER.noActiveStep();
}
addStep(activeStep.response, operation, step, stage, addFirst);
}
@Override
public void addStep(ModelNode response, ModelNode operation, OperationStepHandler step, Stage stage) throws IllegalArgumentException {
switch (stage) {
case MODEL:
super.addStep(response, operation, step, stage);
break;
case RUNTIME:
if (runtimeOps != null) {
// Cache for use by the runtime step from ParallelBootOperationStepHandler
ParsedBootOp parsedOp = new ParsedBootOp(operation, step, response);
runtimeOps.add(parsedOp);
} else {
super.addStep(response, operation, step, stage);
}
break;
default:
// Handle VERIFY in the primary context, after parallel work is done
primaryContext.addStep(response, operation, step, stage);
}
}
// Methods unimplemented by superclass
@Override
ModelControllerImpl.ManagementModelImpl getManagementModel() {
throw new IllegalStateException(); // Wrong usage, we cannot guarantee thread safety
}
@Override
public InputStream getAttachmentStream(int index) {
return primaryContext.getAttachmentStream(index);
}
@Override
public int getAttachmentStreamCount() {
return primaryContext.getAttachmentStreamCount();
}
@Override
public boolean isRollbackOnRuntimeFailure() {
return primaryContext.isRollbackOnRuntimeFailure();
}
@Override
public boolean isResourceServiceRestartAllowed() {
return primaryContext.isResourceServiceRestartAllowed();
}
@Override
public ImmutableManagementResourceRegistration getResourceRegistration() {
ImmutableManagementResourceRegistration parent = primaryContext.getResourceRegistration();
return parent.getSubModel(activeStep.address);
}
@Override
public ManagementResourceRegistration getResourceRegistrationForUpdate() {
acquireControllerLock();
ManagementResourceRegistration parent = primaryContext.getResourceRegistrationForUpdate();
return parent.getSubModel(activeStep.address);
}
@Override
public ImmutableManagementResourceRegistration getRootResourceRegistration() {
return primaryContext.getRootResourceRegistration();
}
@Override
public ServiceRegistry getServiceRegistry(boolean modify) throws UnsupportedOperationException {
if(modify) {
acquireControllerLock();
}
return primaryContext.getServiceRegistry(modify, activeStep);
}
@Override
public ServiceController<?> removeService(ServiceName name) throws UnsupportedOperationException {
acquireControllerLock();
return primaryContext.removeService(name);
}
@Override
public void removeService(ServiceController<?> controller) throws UnsupportedOperationException {
acquireControllerLock();
primaryContext.removeService(controller);
}
@Override
public ServiceTarget getServiceTarget() throws UnsupportedOperationException {
acquireControllerLock();
return primaryContext.getServiceTarget(activeStep);
}
@Override
public void acquireControllerLock() {
if(lockStep == null) {
try {
controller.acquireLock(operationId, true);
lockStep = activeStep;
} catch (InterruptedException e) {
cancelled = true;
Thread.currentThread().interrupt();
throw ControllerLogger.ROOT_LOGGER.operationCancelledAsynchronously();
}
}
}
@Override
public Resource createResource(PathAddress address) throws UnsupportedOperationException {
acquireControllerLock();
PathAddress fullAddress = activeStep.address.append(address);
return primaryContext.createResource(fullAddress);
}
@Override
public void addResource(PathAddress address, Resource toAdd) {
acquireControllerLock();
PathAddress fullAddress = activeStep.address.append(address);
primaryContext.addResource(fullAddress, toAdd);
}
@Override
public void addResource(PathAddress address, int index, Resource toAdd) {
acquireControllerLock();
PathAddress fullAddress = activeStep.address.append(address);
primaryContext.addResource(fullAddress, index, toAdd);
}
@Override
public Resource readResource(PathAddress address) {
return readResource(address, true);
}
@Override
public Resource readResource(PathAddress address, boolean recursive) {
PathAddress fullAddress = activeStep.address.append(address);
return primaryContext.readResource(fullAddress, recursive);
}
@Override
public Resource readResourceFromRoot(PathAddress address) {
return readResourceFromRoot(address, true);
}
@Override
public Resource readResourceFromRoot(PathAddress address, boolean recursive) {
return primaryContext.readResourceFromRoot(address, recursive);
}
@Override
protected Resource readResourceFromRoot(ManagementModel model, PathAddress address, boolean recursive) {
return primaryContext.readResourceFromRoot(model, address, recursive);
}
@Override
public Resource readResourceForUpdate(PathAddress address) {
acquireControllerLock();
PathAddress fullAddress = activeStep.address.append(address);
return primaryContext.readResourceForUpdate(fullAddress);
}
@Override
public Resource removeResource(PathAddress address) throws UnsupportedOperationException {
acquireControllerLock();
PathAddress fullAddress = activeStep.address.append(address);
return primaryContext.removeResource(fullAddress);
}
@Override
public Resource getOriginalRootResource() {
return primaryContext.getOriginalRootResource();
}
@Override
public boolean isModelAffected() {
return primaryContext.isModelAffected();
}
@Override
public boolean isResourceRegistryAffected() {
return primaryContext.isResourceRegistryAffected();
}
@Override
public boolean isRuntimeAffected() {
return primaryContext.isRuntimeAffected();
}
@Override
public Stage getCurrentStage() {
return primaryContext.getCurrentStage();
}
@Override
public void report(MessageSeverity severity, String message) {
primaryContext.report(severity, message);
}
@Override
public boolean markResourceRestarted(PathAddress resource, Object owner) {
throw new UnsupportedOperationException("Resource restarting is not supported during boot");
}
@Override
public boolean revertResourceRestarted(PathAddress resource, Object owner) {
throw new UnsupportedOperationException("Resource restarting is not supported during boot");
}
@Override
void awaitServiceContainerStability() throws InterruptedException {
// ignored
}
@Override
ConfigurationPersister.PersistenceResource createPersistenceResource() throws ConfigurationPersistenceException {
// We don't persist
return null;
}
@Override
void operationRollingBack() {
// BES 2015/06/30 hmm. telling the primary context to discarding the management model
// here will screw up other parallel contexts that are still running. but if we don't,
// during rollback our OSHs will still see the changes made to the model.
// Oh well, I'm not going to worry about it as this runs in boot, and a rollback in
// boot should just result in the whole process going away anyway.
}
@Override
public void emit(Notification notification) {
primaryContext.emit(notification);
}
@Override
public void registerCapability(RuntimeCapability capability, String attribute) {
// pass in the step we are executing so it can be failed if there is problem resolving capabilities/requirements
primaryContext.registerCapability(capability, activeStep, attribute);
}
@Override
public void registerAdditionalCapabilityRequirement(String required, String dependent, String attribute) {
// pass in the step we are executing so it can be failed if there is problem resolving capabilities/requirements
primaryContext.registerAdditionalCapabilityRequirement(required, dependent, activeStep, attribute);
}
@Override
public boolean requestOptionalCapability(String required, String dependent, String attribute) {
// pass in the step we are executing so it can be failed if there is problem resolving capabilities/requirements
return primaryContext.requestOptionalCapability(required, dependent, false, activeStep, attribute);
}
@Override
public boolean hasOptionalCapability(String required, String dependent, String attribute) {
// pass in the step we are executing so it can be failed if there is problem resolving capabilities/requirements
return primaryContext.requestOptionalCapability(required, dependent, true, activeStep, attribute);
}
@Override
public void requireOptionalCapability(String required, String dependent, String attribute) throws OperationFailedException {
// pass in the step we are executing so it can be failed if there is problem resolving capabilities/requirements
primaryContext.requireOptionalCapability(required, dependent, activeStep, attribute);
}
@Override
public void deregisterCapabilityRequirement(String required, String dependent) {
// pass in the step we are executing so it can be failed if there is problem resolving capabilities/requirements
primaryContext.removeCapabilityRequirement(required, dependent, activeStep);
}
@Override
public void deregisterCapability(String capability) {
// pass in the step we are executing so it can be failed if there is problem resolving capabilities/requirements
primaryContext.removeCapability(capability, activeStep);
}
@Override
public <T> T getCapabilityRuntimeAPI(String capabilityName, Class<T> apiType) {
return primaryContext.getCapabilityRuntimeAPI(capabilityName, apiType, activeStep);
}
@Override
public <T> T getCapabilityRuntimeAPI(String capabilityBaseName, String dynamicPart, Class<T> apiType) {
return primaryContext.getCapabilityRuntimeAPI(RuntimeCapability.buildDynamicCapabilityName(capabilityBaseName, dynamicPart), apiType, activeStep);
}
@Override
public ServiceName getCapabilityServiceName(String capabilityName, Class<?> type) {
return primaryContext.getCapabilityServiceName(capabilityName, type, activeStep);
}
@Override
public ServiceName getCapabilityServiceName(String capabilityBaseName, String dynamicPart, Class<?> serviceType) {
return primaryContext.getCapabilityServiceName(RuntimeCapability.buildDynamicCapabilityName(capabilityBaseName, dynamicPart),
serviceType, activeStep);
}
@Override
public CapabilityServiceSupport getCapabilityServiceSupport() {
return primaryContext.getCapabilityServiceSupport();
}
@Override
void releaseStepLocks(Step step) {
if(lockStep == step) {
controller.releaseLock(operationId);
lockStep = null;
}
}
@Override
void waitForRemovals() {
// nothing to do
}
@Override
boolean isReadOnly() {
return primaryContext.isReadOnly();
}
@Override
ManagementResourceRegistration getRootResourceRegistrationForUpdate() {
return primaryContext.getRootResourceRegistrationForUpdate();
}
@Override
public ModelNode resolveExpressions(ModelNode node) throws OperationFailedException {
return primaryContext.resolveExpressions(node);
}
@Override
public <T> T getAttachment(final AttachmentKey<T> key) {
return primaryContext.getAttachment(key);
}
@Override
public <T> T attach(final AttachmentKey<T> key, final T value) {
return primaryContext.attach(key, value);
}
@Override
public <T> T attachIfAbsent(final AttachmentKey<T> key, final T value) {
return primaryContext.attachIfAbsent(key, value);
}
@Override
public <T> T detach(final AttachmentKey<T> key) {
return primaryContext.detach(key);
}
@Override
public AuthorizationResult authorize(ModelNode operation) {
return primaryContext.authorize(operation);
}
@Override
public AuthorizationResult authorize(ModelNode operation, Set<Action.ActionEffect> effects) {
return primaryContext.authorize(operation, effects);
}
@Override
public AuthorizationResult authorize(ModelNode operation, String attribute, ModelNode currentValue) {
return primaryContext.authorize(operation, attribute, currentValue);
}
@Override
public AuthorizationResult authorize(ModelNode operation, String attribute, ModelNode currentValue, Set<Action.ActionEffect> effects) {
return primaryContext.authorize(operation, attribute, currentValue, effects);
}
@Override
public AuthorizationResult authorizeOperation(ModelNode operation) {
return primaryContext.authorizeOperation(operation);
}
@Override
public ResourceAuthorization authorizeResource(boolean attributes, boolean isDefaultResource) {
return primaryContext.authorizeResource(attributes, isDefaultResource);
}
Resource getModel() {
return primaryContext.getModel();
}
@Override
void logAuditRecord() {
// handled by the primary context
}
}