ReadOnlyContext( final ProcessType processType, final RunningMode runningMode, final ModelController.OperationTransactionControl transactionControl, final ControlledProcessState processState, final boolean booting, final ModelControllerImpl.ManagementModelImpl managementModel, final AbstractOperationContext primaryContext, final ModelControllerImpl controller, final int operationId, final Supplier<SecurityIdentity> securityIdentitySupplier) { super( processType, runningMode, transactionControl, processState, booting, controller.getAuditLogger(), controller.getNotificationSupport(), controller, true, null, securityIdentitySupplier); this.primaryContext = primaryContext; this.controller = controller; this.operationId = operationId; this.managementModel = managementModel; }
@Override void releaseStepLocks(AbstractOperationContext.Step step) { if (this.lockStep == step) { modelController.releaseLock(); lockStep = null; } if (this.containerMonitorStep == step) { awaitContainerMonitor(); modelController.releaseContainerMonitor(); containerMonitorStep = null; } }
@Override void awaitModelControllerContainerMonitor() throws InterruptedException { if (affectsRuntime) { MGMT_OP_LOGGER.debugf("Entered VERIFY stage; waiting for service container to settle"); // First wait until any removals we've initiated have begun processing, otherwise // the ContainerStateMonitor may not have gotten the notification causing it to untick final Map<ServiceName, ServiceController<?>> map = realRemovingControllers; synchronized (map) { while (!map.isEmpty()) { map.wait(); } } ContainerStateMonitor.ContainerStateChangeReport changeReport = modelController.awaitContainerStateChangeReport(1); // If any services are missing, add a verification handler to see if we caused it if (changeReport != null && !changeReport.getMissingServices().isEmpty()) { ServiceRemovalVerificationHandler removalVerificationHandler = new ServiceRemovalVerificationHandler(changeReport); addStep( new ModelNode(), new ModelNode(), PathAddress.EMPTY_ADDRESS, removalVerificationHandler, Stage.VERIFY); } } }
@Override void releaseStepLocks(Step step) { if (step == lockStep) { lockStep = null; controller.releaseWriteLock(operationId); } }
private void awaitContainerMonitor() { try { modelController.awaitContainerMonitor(respectInterruption, 1); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw MESSAGES.operationCancelledAsynchronously(); } }
protected boolean boot(List<ModelNode> bootOperations, boolean rollbackOnRuntimeFailure) throws ConfigurationPersistenceException { return controller.boot( bootOperations, OperationMessageHandler.logging, ModelController.OperationTransactionControl.COMMIT, rollbackOnRuntimeFailure); }
protected ModelNode internalExecute( final ModelNode operation, final OperationMessageHandler handler, final ModelController.OperationTransactionControl control, final OperationAttachments attachments, final OperationStepHandler prepareStep) { return controller.internalExecute(operation, handler, control, attachments, prepareStep, false); }
private void acquireContainerMonitor() { if (containerMonitorStep == null) { if (currentStage == Stage.DONE) { throw MESSAGES.invalidModificationAfterCompletedStep(); } modelController.acquireContainerMonitor(); containerMonitorStep = activeStep; } }
public void addResource(PathAddress relativeAddress, Resource toAdd) { final PathAddress absoluteAddress = activeStep.address.append(relativeAddress); assert isControllingThread(); Stage currentStage = this.currentStage; if (currentStage == null) { throw MESSAGES.operationAlreadyComplete(); } if (currentStage != Stage.MODEL) { throw MESSAGES.stageAlreadyComplete(Stage.MODEL); } if (absoluteAddress.size() == 0) { throw MESSAGES.duplicateResourceAddress(absoluteAddress); } if (!isModelAffected()) { takeWriteLock(); model = model.clone(); } affectsModel.put(absoluteAddress, NULL); Resource model = this.model; final Iterator<PathElement> i = absoluteAddress.iterator(); while (i.hasNext()) { final PathElement element = i.next(); if (element.isMultiTarget()) { throw MESSAGES.cannotWriteTo("*"); } if (!i.hasNext()) { final String key = element.getKey(); if (model.hasChild(element)) { throw MESSAGES.duplicateResourceAddress(absoluteAddress); } else { final PathAddress parent = absoluteAddress.subAddress(0, absoluteAddress.size() - 1); final Set<String> childrenNames = modelController.getRootRegistration().getChildNames(parent); if (!childrenNames.contains(key)) { throw MESSAGES.noChildType(key); } model.registerChild(element, toAdd); model = toAdd; } } else { model = model.getChild(element); if (model == null) { PathAddress ancestor = PathAddress.EMPTY_ADDRESS; for (PathElement pe : absoluteAddress) { ancestor = ancestor.append(pe); if (element.equals(pe)) { break; } } throw MESSAGES.resourceNotFound(ancestor, absoluteAddress); } } } }
/** @deprecated internal use only */ @Deprecated protected ModelNode executeReadOnlyOperation( final ModelNode operation, final OperationMessageHandler handler, final ModelController.OperationTransactionControl control, final OperationAttachments attachments, final OperationStepHandler prepareStep, int lockPermit) { return controller.executeReadOnlyOperation( operation, handler, control, attachments, prepareStep, lockPermit); }
ReadOnlyContext( final ProcessType processType, final RunningMode runningMode, final ModelController.OperationTransactionControl transactionControl, final ControlledProcessState processState, final boolean booting, final AbstractOperationContext primaryContext, final ModelControllerImpl controller, final int operationId) { super( processType, runningMode, transactionControl, processState, booting, controller.getAuditLogger(), controller.getNotificationSupport()); this.primaryContext = primaryContext; this.controller = controller; this.operationId = operationId; }
public ImmutableManagementResourceRegistration getResourceRegistration() { final PathAddress address = activeStep.address; assert isControllingThread(); Stage currentStage = this.currentStage; if (currentStage == null || currentStage == Stage.DONE) { throw MESSAGES.operationAlreadyComplete(); } ImmutableManagementResourceRegistration delegate = modelController.getRootRegistration().getSubModel(address); return delegate == null ? null : new DelegatingImmutableManagementResourceRegistration(delegate); }
@Override public void acquireControllerLock() { if (lockStep == null) { try { controller.acquireWriteLock(operationId, true); lockStep = activeStep; } catch (InterruptedException e) { cancelled = true; Thread.currentThread().interrupt(); throw ControllerLogger.ROOT_LOGGER.operationCancelledAsynchronously(); } } }
private void takeWriteLock() { if (lockStep == null) { if (currentStage == Stage.DONE) { throw MESSAGES.invalidModificationAfterCompletedStep(); } try { modelController.acquireLock(respectInterruption); lockStep = activeStep; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw MESSAGES.operationCancelledAsynchronously(); } } }
public ManagementResourceRegistration getResourceRegistrationForUpdate() { final PathAddress address = activeStep.address; assert isControllingThread(); Stage currentStage = this.currentStage; if (currentStage == null) { throw MESSAGES.operationAlreadyComplete(); } // if (currentStage != Stage.MODEL) { // throw MESSAGES.stageAlreadyComplete(Stage.MODEL); // } if (!affectsResourceRegistration) { takeWriteLock(); affectsResourceRegistration = true; } return modelController.getRootRegistration().getSubModel(address); }
public ModelNode readModelForUpdate(final PathAddress requestAddress) { final PathAddress address = activeStep.address.append(requestAddress); assert isControllingThread(); Stage currentStage = this.currentStage; if (currentStage == null) { throw MESSAGES.operationAlreadyComplete(); } if (currentStage != Stage.MODEL) { throw MESSAGES.stageAlreadyComplete(Stage.MODEL); } if (!isModelAffected()) { takeWriteLock(); model = model.clone(); } affectsModel.put(address, NULL); Resource model = this.model; final Iterator<PathElement> i = address.iterator(); while (i.hasNext()) { final PathElement element = i.next(); if (element.isMultiTarget()) { throw MESSAGES.cannotWriteTo("*"); } if (!i.hasNext()) { final String key = element.getKey(); if (!model.hasChild(element)) { final PathAddress parent = address.subAddress(0, address.size() - 1); final Set<String> childrenNames = modelController.getRootRegistration().getChildNames(parent); if (!childrenNames.contains(key)) { throw MESSAGES.noChildType(key); } final Resource newModel = Resource.Factory.create(); model.registerChild(element, newModel); model = newModel; } else { model = requireChild(model, element, address); } } else { model = requireChild(model, element, address); } } if (model == null) { throw new IllegalStateException(); } return model.getModel(); }
public ServiceController<?> removeService(final ServiceName name) throws UnsupportedOperationException { assert isControllingThread(); Stage currentStage = this.currentStage; if (currentStage == null) { throw MESSAGES.operationAlreadyComplete(); } if (currentStage != Stage.RUNTIME && currentStage != Stage.VERIFY && !isRollingBack()) { throw MESSAGES.serviceRemovalRuntimeOperationsOnly(); } if (!affectsRuntime) { takeWriteLock(); affectsRuntime = true; acquireContainerMonitor(); awaitContainerMonitor(); } ServiceController<?> controller = modelController.getServiceRegistry().getService(name); if (controller != null) { doRemove(controller); } return controller; }
public ServiceRegistry getServiceRegistry(final boolean modify) throws UnsupportedOperationException { assert isControllingThread(); Stage currentStage = this.currentStage; if (currentStage == null) { throw MESSAGES.operationAlreadyComplete(); } if (!(!modify || currentStage == Stage.RUNTIME || currentStage == Stage.MODEL || currentStage == Stage.VERIFY || isRollingBack())) { throw MESSAGES.serviceRegistryRuntimeOperationsOnly(); } if (modify && !affectsRuntime) { takeWriteLock(); affectsRuntime = true; acquireContainerMonitor(); awaitContainerMonitor(); } return modelController.getServiceRegistry(); }
@Override ConfigurationPersister.PersistenceResource createPersistenceResource() throws ConfigurationPersistenceException { return modelController.writeModel(model, affectsModel.keySet()); }
public void start(final StartContext context) throws StartException { if (configurationPersister == null) { throw MESSAGES.persisterNotInjected(); } final ServiceController<?> serviceController = context.getController(); final ServiceContainer container = serviceController.getServiceContainer(); final ServiceTarget target = context.getChildTarget(); final ExecutorService executorService = injectedExecutorService.getOptionalValue(); ManagementResourceRegistration rootResourceRegistration = rootDescriptionProvider != null ? ManagementResourceRegistration.Factory.create(rootDescriptionProvider) : ManagementResourceRegistration.Factory.create(rootResourceDefinition); final ModelControllerImpl controller = new ModelControllerImpl( container, target, rootResourceRegistration, new ContainerStateMonitor(container), configurationPersister, processType, runningModeControl, prepareStep, processState, executorService, expressionResolver, authorizer, auditLogger); // Initialize the model initModel(controller.getRootResource(), controller.getRootRegistration()); this.controller = controller; final long bootStackSize = getBootStackSize(); final Thread bootThread = new Thread( null, new Runnable() { public void run() { try { try { boot( new BootContext() { public ServiceTarget getServiceTarget() { return target; } }); } finally { processState.setRunning(); } } catch (Throwable t) { container.shutdown(); if (t instanceof StackOverflowError) { ROOT_LOGGER.errorBootingContainer(t, bootStackSize, BOOT_STACK_SIZE_PROPERTY); } else { ROOT_LOGGER.errorBootingContainer(t); } } finally { bootThreadDone(); } } }, "Controller Boot Thread", bootStackSize); bootThread.start(); }
protected void finishBoot() throws ConfigurationPersistenceException { controller.finishBoot(); configurationPersister.successfulBoot(); }
public <T> ServiceBuilder<T> addServiceValue( final ServiceName name, final Value<? extends Service<T>> value) { final ServiceBuilder<T> realBuilder = modelController.getServiceTarget().addServiceValue(name, value); return new ContextServiceBuilder<T>(realBuilder, name); }
protected void runPerformControllerInitialization(BootContext context) { performControllerInitialization( context.getServiceTarget(), controller.getRootResource(), controller.getRootRegistration()); }
@Override public ModelNode resolveExpressions(ModelNode node) throws OperationFailedException { return modelController.resolveExpressions(node); }