use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class ServerAdd method populateModel.
@Override
protected void populateModel(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
super.populateModel(context, operation, resource);
if (SECURITY_ENABLED.resolveModelAttribute(context, operation).asBoolean()) {
context.addStep(SecurityDomainCheckHandler.INSTANCE, OperationContext.Stage.MODEL);
}
handleCredentialReferenceUpdate(context, resource.getModel().get(CREDENTIAL_REFERENCE.getName()), CREDENTIAL_REFERENCE.getName());
// add an operation to create all the messaging paths resources that have not been already been created
// prior to adding the ActiveMQ server
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final ModelNode model = Resource.Tools.readModel(resource);
for (String path : PathDefinition.PATHS.keySet()) {
if (!model.get(ModelDescriptionConstants.PATH).hasDefined(path)) {
PathAddress pathAddress = PathAddress.pathAddress(PathElement.pathElement(ModelDescriptionConstants.PATH, path));
context.createResource(pathAddress);
}
}
}
}, OperationContext.Stage.MODEL);
context.addStep((operationContext, model) -> {
// check that if journal-datasource is defined, no other attributes related to file-system journal are set.
if (ServerDefinition.JOURNAL_DATASOURCE.resolveModelAttribute(context, model).isDefined()) {
checkNoAttributesIsDefined(ServerDefinition.JOURNAL_DATASOURCE.getName(), operationContext.getCurrentAddress(), model, ServerDefinition.JOURNAL_TYPE, ServerDefinition.JOURNAL_BUFFER_TIMEOUT, ServerDefinition.JOURNAL_BUFFER_SIZE, ServerDefinition.JOURNAL_SYNC_TRANSACTIONAL, ServerDefinition.JOURNAL_SYNC_NON_TRANSACTIONAL, ServerDefinition.LOG_JOURNAL_WRITE_RATE, ServerDefinition.JOURNAL_FILE_SIZE, ServerDefinition.JOURNAL_MIN_FILES, ServerDefinition.JOURNAL_POOL_FILES, ServerDefinition.JOURNAL_FILE_OPEN_TIMEOUT, ServerDefinition.JOURNAL_COMPACT_PERCENTAGE, ServerDefinition.JOURNAL_COMPACT_MIN_FILES, ServerDefinition.JOURNAL_MAX_IO, ServerDefinition.CREATE_BINDINGS_DIR, ServerDefinition.CREATE_JOURNAL_DIR);
}
}, OperationContext.Stage.MODEL);
}
use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class ManagementHelper method checkNoOtherSibling.
static OperationStepHandler checkNoOtherSibling(final String childType) {
return new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
PathAddress parentAddress = context.getCurrentAddress().getParent();
Resource parent = context.readResourceFromRoot(parentAddress, false);
Set<String> children = parent.getChildrenNames(childType);
if (children.size() > 1) {
throw MessagingLogger.ROOT_LOGGER.onlyOneChildIsAllowed(childType, children);
}
}
};
}
use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class AbstractUpdateJndiHandler method execute.
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
JNDI_BINDING.validateOperation(operation);
final String jndiName = JNDI_BINDING.resolveModelAttribute(context, operation).asString();
final ModelNode entries = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel().get(CommonAttributes.DESTINATION_ENTRIES.getName());
if (addOperation) {
for (ModelNode entry : entries.asList()) {
if (jndiName.equals(entry.asString())) {
throw new OperationFailedException(ROOT_LOGGER.jndiNameAlreadyRegistered(jndiName));
}
}
entries.add(jndiName);
} else {
ModelNode updatedEntries = new ModelNode();
boolean updated = false;
for (ModelNode entry : entries.asList()) {
if (jndiName.equals(entry.asString())) {
if (entries.asList().size() == 1) {
throw new OperationFailedException(ROOT_LOGGER.canNotRemoveLastJNDIName(jndiName));
}
updated = true;
} else {
updatedEntries.add(entry);
}
}
if (!updated) {
throw MessagingLogger.ROOT_LOGGER.canNotRemoveUnknownEntry(jndiName);
}
context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel().get(CommonAttributes.DESTINATION_ENTRIES.getName()).set(updatedEntries);
}
if (context.isNormalServer()) {
if (rollbackOperationIfServerNotActive(context, operation)) {
return;
}
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final String resourceName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
final ServiceName jmsManagerServiceName = JMSServices.getJmsManagerBaseServiceName(serviceName);
final ServiceController<?> jmsServerService = context.getServiceRegistry(false).getService(jmsManagerServiceName);
if (jmsServerService != null) {
JMSServerManager jmsServerManager = JMSServerManager.class.cast(jmsServerService.getValue());
if (jmsServerManager == null) {
PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
}
try {
if (addOperation) {
addJndiName(jmsServerManager, resourceName, jndiName);
} else {
removeJndiName(jmsServerManager, resourceName, jndiName);
}
} catch (Exception e) {
context.getFailureDescription().set(e.getLocalizedMessage());
}
}
if (!context.hasFailureDescription()) {
context.getResult();
}
context.completeStep(new OperationContext.RollbackHandler() {
@Override
public void handleRollback(OperationContext context, ModelNode operation) {
if (jmsServerService != null) {
JMSServerManager jmsServerManager = JMSServerManager.class.cast(jmsServerService.getValue());
try {
if (addOperation) {
removeJndiName(jmsServerManager, resourceName, jndiName);
} else {
addJndiName(jmsServerManager, resourceName, jndiName);
}
} catch (Exception e) {
context.getFailureDescription().set(e.getLocalizedMessage());
}
}
}
});
}
}, OperationContext.Stage.RUNTIME);
}
}
use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class TranslatedOperationHandler method execute.
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
PathAddress targetAddress = converter.convert(context, operation);
ModelNode op = operation.clone();
op.get(OP_ADDR).set(targetAddress.toModelNode());
String operationName = op.require(OP).asString();
OperationStepHandler operationHandler = context.getRootResourceRegistration().getOperationHandler(targetAddress, operationName);
context.addStep(op, operationHandler, context.getCurrentStage(), true);
}
use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class MetricsSubsystemAdd method performBoottime.
@Override
protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
super.performBoottime(context, operation, model);
List<String> exposedSubsystems = MetricsSubsystemDefinition.EXPOSED_SUBSYSTEMS.unwrap(context, model);
boolean exposeAnySubsystem = exposedSubsystems.remove("*");
String prefix = MetricsSubsystemDefinition.PREFIX.resolveModelAttribute(context, model).asStringOrNull();
boolean securityEnabled = MetricsSubsystemDefinition.SECURITY_ENABLED.resolveModelAttribute(context, model).asBoolean();
WildFlyMetricRegistryService.install(context);
MetricsCollectorService.install(context);
MetricsContextService.install(context, securityEnabled);
// handles that instead.
if (!context.getCapabilityServiceSupport().hasCapability(MetricsSubsystemDefinition.METRICS_SCAN_CAPABILITY)) {
context.addStep(new AbstractDeploymentChainStep() {
public void execute(DeploymentProcessorTarget processorTarget) {
processorTarget.addDeploymentProcessor(SUBSYSTEM_NAME, INSTALL, POST_MODULE_METRICS, new DeploymentMetricProcessor(exposeAnySubsystem, exposedSubsystems, prefix));
}
}, RUNTIME);
// delay the registration of the metrics in the VERIFY stage so that all resources
// created during the RUNTIME phase will have been registered in the MRR.
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext operationContext, ModelNode modelNode) {
ServiceController<?> serviceController = context.getServiceRegistry(false).getService(WILDFLY_COLLECTOR);
MetricCollector metricCollector = MetricCollector.class.cast(serviceController.getValue());
ServiceController<?> wildflyRegistryController = context.getServiceRegistry(false).getService(METRICS_REGISTRY_RUNTIME_CAPABILITY.getCapabilityServiceName());
WildFlyMetricRegistry metricRegistry = WildFlyMetricRegistry.class.cast(wildflyRegistryController.getValue());
ImmutableManagementResourceRegistration rootResourceRegistration = context.getRootResourceRegistration();
Resource rootResource = context.readResourceFromRoot(EMPTY_ADDRESS);
MetricRegistration registration = new MetricRegistration(metricRegistry);
metricCollector.collectResourceMetrics(rootResource, rootResourceRegistration, Function.identity(), exposeAnySubsystem, exposedSubsystems, prefix, registration);
}
}, VERIFY);
}
LOGGER.activatingSubsystem();
}
Aggregations