use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.
the class ProxyConfigurationResourceDefinition method register.
@SuppressWarnings("deprecation")
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
ManagementResourceRegistration registration = parent.registerSubModel(this);
ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()).addAttributes(EnumSet.complementOf(EnumSet.of(Attribute.SSL_CONTEXT))).addExtraParameters(Attribute.SSL_CONTEXT).addAttributeTranslation(DeprecatedAttribute.SIMPLE_LOAD_PROVIDER, SIMPLE_LOAD_PROVIDER_TRANSLATION).addAlias(DeprecatedAttribute.CONNECTOR, Attribute.LISTENER).addRequiredSingletonChildren(SimpleLoadProviderResourceDefinition.PATH).addCapabilities(Capability.class);
registration.registerReadWriteAttribute(Attribute.SSL_CONTEXT.getDefinition(), null, new ReloadRequiredWriteAttributeHandler() {
@Override
protected void validateUpdatedModel(OperationContext context, Resource model) {
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext ctx, ModelNode op) throws OperationFailedException {
if (model.hasChild(SSLResourceDefinition.PATH)) {
throw new OperationFailedException(ROOT_LOGGER.bothElytronAndLegacySslContextDefined());
}
}
}, OperationContext.Stage.MODEL);
}
});
parent.registerAlias(LEGACY_PATH, new AliasEntry(registration) {
@Override
public PathAddress convertToTargetAddress(PathAddress aliasAddress, AliasContext aliasContext) {
PathAddress rebuiltAddress = PathAddress.EMPTY_ADDRESS;
for (PathElement pathElement : aliasAddress) {
if (pathElement.equals(LEGACY_PATH)) {
try {
if (aliasContext.readResourceFromRoot(rebuiltAddress, false).hasChildren(ProxyConfigurationResourceDefinition.WILDCARD_PATH.getKey())) {
Set<Resource.ResourceEntry> children = aliasContext.readResourceFromRoot(rebuiltAddress, false).getChildren(ProxyConfigurationResourceDefinition.WILDCARD_PATH.getKey());
if (children.size() > 1 && !Operations.getOperationName(aliasContext.getOperation()).equals(AliasContext.RECURSIVE_GLOBAL_OP)) {
throw new IllegalStateException(ModClusterLogger.ROOT_LOGGER.legacyOperationsWithMultipleProxies());
}
PathAddress proxyPath = PathAddress.pathAddress(ProxyConfigurationResourceDefinition.pathElement(children.iterator().next().getName()));
rebuiltAddress = rebuiltAddress.append(proxyPath);
} else {
// handle :add
rebuiltAddress = rebuiltAddress.append(ProxyConfigurationResourceDefinition.pathElement("default"));
}
} catch (Resource.NoSuchResourceException ignore) {
// handle recursive-global-op
rebuiltAddress = rebuiltAddress.append(ProxyConfigurationResourceDefinition.WILDCARD_PATH);
}
} else {
rebuiltAddress = rebuiltAddress.append(pathElement);
}
}
return rebuiltAddress;
}
});
if (registration.isRuntimeOnlyRegistrationValid()) {
new OperationHandler<>(new ProxyOperationExecutor(this.executors), ProxyOperation.class).register(registration);
}
new ReloadRequiredResourceRegistration(descriptor).register(registration);
new LegacyMetricOperationsRegistration().register(registration);
new SimpleLoadProviderResourceDefinition().register(registration);
new DynamicLoadProviderResourceDefinition().register(registration);
new SSLResourceDefinition().register(registration);
return registration;
}
use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.
the class SecuritySubsystemRootResourceDefinition method registerAttributes.
@Override
public void registerAttributes(final ManagementResourceRegistration resourceRegistration) {
resourceRegistration.registerReadWriteAttribute(DEEP_COPY_SUBJECT_MODE, null, new ReloadRequiredWriteAttributeHandler(DEEP_COPY_SUBJECT_MODE));
resourceRegistration.registerReadWriteAttribute(INITIALIZE_JACC, null, new ReloadRequiredWriteAttributeHandler(INITIALIZE_JACC) {
@Override
protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<Void> voidHandback) throws OperationFailedException {
// As the PolicyConfigurationFactory is a singleton, once it's initialized any changes will require a restart
CapabilityServiceSupport capabilitySupport = context.getCapabilityServiceSupport();
final boolean elytronJacc = capabilitySupport.hasCapability("org.wildfly.security.jacc-policy");
if (resolvedValue.asBoolean() == true && elytronJacc) {
throw SecurityLogger.ROOT_LOGGER.unableToEnableJaccSupport();
}
return super.applyUpdateToRuntime(context, operation, attributeName, resolvedValue, currentValue, voidHandback);
}
@Override
protected void recordCapabilitiesAndRequirements(OperationContext context, AttributeDefinition attributeDefinition, ModelNode newValue, ModelNode oldValue) {
super.recordCapabilitiesAndRequirements(context, attributeDefinition, newValue, oldValue);
boolean shouldRegister = resolveValue(context, attributeDefinition, newValue);
boolean registered = resolveValue(context, attributeDefinition, oldValue);
if (!shouldRegister) {
context.deregisterCapability(JACC_CAPABILITY.getName());
}
if (!registered && shouldRegister) {
context.registerCapability(JACC_CAPABILITY);
// do not register the JACC_CAPABILITY_TOMBSTONE at this point - it will be registered on restart
}
}
private boolean resolveValue(OperationContext context, AttributeDefinition attributeDefinition, ModelNode node) {
try {
return attributeDefinition.resolveValue(context, node).asBoolean();
} catch (OperationFailedException e) {
throw new IllegalStateException(e);
}
}
});
}
use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.
the class AbstractActiveMQComponentControlHandler method executeRuntimeStep.
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
final String operationName = operation.require(OP).asString();
if (READ_ATTRIBUTE_OPERATION.equals(operationName)) {
if (ActiveMQActivationService.ignoreOperationIfServerNotActive(context, operation)) {
return;
}
readAttributeValidator.validate(operation);
final String name = operation.require(NAME).asString();
if (STARTED.getName().equals(name)) {
ActiveMQComponentControl control = getActiveMQComponentControl(context, operation, false);
context.getResult().set(control.isStarted());
} else {
handleReadAttribute(name, context, operation);
}
return;
}
if (ActiveMQActivationService.rollbackOperationIfServerNotActive(context, operation)) {
return;
}
ActiveMQComponentControl control = null;
boolean appliedToRuntime = false;
Object handback = null;
if (START.equals(operationName)) {
control = getActiveMQComponentControl(context, operation, true);
try {
control.start();
appliedToRuntime = true;
context.getResult();
} catch (Exception e) {
context.getFailureDescription().set(e.getLocalizedMessage());
}
} else if (STOP.equals(operationName)) {
control = getActiveMQComponentControl(context, operation, true);
try {
control.stop();
appliedToRuntime = true;
context.getResult();
} catch (Exception e) {
context.getFailureDescription().set(e.getLocalizedMessage());
}
} else {
handback = handleOperation(operationName, context, operation);
appliedToRuntime = handback != null;
}
OperationContext.RollbackHandler rh;
if (appliedToRuntime) {
final ActiveMQComponentControl rhControl = control;
final Object rhHandback = handback;
rh = new OperationContext.RollbackHandler() {
@Override
public void handleRollback(OperationContext context, ModelNode operation) {
try {
if (START.equals(operationName)) {
rhControl.stop();
} else if (STOP.equals(operationName)) {
rhControl.start();
} else {
handleRevertOperation(operationName, context, operation, rhHandback);
}
} catch (Exception e) {
ROOT_LOGGER.revertOperationFailed(e, getClass().getSimpleName(), operation.require(ModelDescriptionConstants.OP).asString(), PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)));
}
}
};
} else {
rh = OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER;
}
context.completeStep(rh);
}
use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.
the class AbstractQueueControlHandler method executeRuntimeStep.
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
if (rollbackOperationIfServerNotActive(context, operation)) {
return;
}
final String operationName = operation.require(ModelDescriptionConstants.OP).asString();
final String queueName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
final ServiceName activeMQServiceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
boolean readOnly = context.getResourceRegistration().getOperationFlags(PathAddress.EMPTY_ADDRESS, operationName).contains(OperationEntry.Flag.READ_ONLY);
ServiceController<?> activeMQService = context.getServiceRegistry(!readOnly).getService(activeMQServiceName);
ActiveMQServer server = ActiveMQServer.class.cast(activeMQService.getValue());
final DelegatingQueueControl<T> control = getQueueControl(server, queueName);
if (control == null) {
PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
}
boolean reversible = false;
Object handback = null;
try {
if (LIST_MESSAGES.equals(operationName)) {
String filter = resolveFilter(context, operation);
String json = control.listMessagesAsJSON(filter);
context.getResult().set(ModelNode.fromJSONString(json));
} else if (LIST_MESSAGES_AS_JSON.equals(operationName)) {
String filter = resolveFilter(context, operation);
context.getResult().set(control.listMessagesAsJSON(filter));
} else if (LIST_DELIVERING_MESSAGES.equals(operationName)) {
String json = control.listDeliveringMessagesAsJSON();
context.getResult().set(ModelNode.fromJSONString(json));
} else if (LIST_DELIVERING_MESSAGES_AS_JSON.equals(operationName)) {
context.getResult().set(control.listDeliveringMessagesAsJSON());
} else if (LIST_SCHEDULED_MESSAGES.equals(operationName)) {
String json = control.listScheduledMessagesAsJSON();
context.getResult().set(ModelNode.fromJSONString(json));
} else if (LIST_SCHEDULED_MESSAGES_AS_JSON.equals(operationName)) {
context.getResult().set(control.listScheduledMessagesAsJSON());
} else if (COUNT_MESSAGES.equals(operationName)) {
String filter = resolveFilter(context, operation);
context.getResult().set(control.countMessages(filter));
} else if (REMOVE_MESSAGE.equals(operationName)) {
ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
context.getResult().set(control.removeMessage(id));
} else if (REMOVE_MESSAGES.equals(operationName)) {
String filter = resolveFilter(context, operation);
context.getResult().set(control.removeMessages(filter));
} else if (EXPIRE_MESSAGES.equals(operationName)) {
String filter = resolveFilter(context, operation);
context.getResult().set(control.expireMessages(filter));
} else if (EXPIRE_MESSAGE.equals(operationName)) {
ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
context.getResult().set(control.expireMessage(id));
} else if (SEND_MESSAGE_TO_DEAD_LETTER_ADDRESS.equals(operationName)) {
ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
context.getResult().set(control.sendMessageToDeadLetterAddress(id));
} else if (SEND_MESSAGES_TO_DEAD_LETTER_ADDRESS.equals(operationName)) {
String filter = resolveFilter(context, operation);
context.getResult().set(control.sendMessagesToDeadLetterAddress(filter));
} else if (CHANGE_MESSAGE_PRIORITY.equals(operationName)) {
ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
int priority = NEW_PRIORITY.resolveModelAttribute(context, operation).asInt();
context.getResult().set(control.changeMessagePriority(id, priority));
} else if (CHANGE_MESSAGES_PRIORITY.equals(operationName)) {
String filter = resolveFilter(context, operation);
int priority = NEW_PRIORITY.resolveModelAttribute(context, operation).asInt();
context.getResult().set(control.changeMessagesPriority(filter, priority));
} else if (MOVE_MESSAGE.equals(operationName)) {
ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
String otherQueue = OTHER_QUEUE_NAME.resolveModelAttribute(context, operation).asString();
ModelNode rejectDuplicates = REJECT_DUPLICATES.resolveModelAttribute(context, operation);
if (rejectDuplicates.isDefined()) {
context.getResult().set(control.moveMessage(id, otherQueue, rejectDuplicates.asBoolean()));
} else {
context.getResult().set(control.moveMessage(id, otherQueue));
}
} else if (MOVE_MESSAGES.equals(operationName)) {
String filter = resolveFilter(context, operation);
String otherQueue = OTHER_QUEUE_NAME.resolveModelAttribute(context, operation).asString();
ModelNode rejectDuplicates = REJECT_DUPLICATES.resolveModelAttribute(context, operation);
if (rejectDuplicates.isDefined()) {
context.getResult().set(control.moveMessages(filter, otherQueue, rejectDuplicates.asBoolean()));
} else {
context.getResult().set(control.moveMessages(filter, otherQueue));
}
} else if (LIST_MESSAGE_COUNTER_AS_JSON.equals(operationName)) {
context.getResult().set(control.listMessageCounter());
} else if (LIST_MESSAGE_COUNTER_AS_HTML.equals(operationName)) {
context.getResult().set(control.listMessageCounterAsHTML());
} else if (LIST_MESSAGE_COUNTER_HISTORY_AS_JSON.equals(operationName)) {
context.getResult().set(control.listMessageCounterHistory());
} else if (LIST_MESSAGE_COUNTER_HISTORY_AS_HTML.equals(operationName)) {
context.getResult().set(control.listMessageCounterHistoryAsHTML());
} else if (RESET_MESSAGE_COUNTER.equals(operationName)) {
control.resetMessageCounter();
// undefined
context.getResult();
} else if (PAUSE.equals(operationName)) {
control.pause();
reversible = true;
// undefined
context.getResult();
} else if (RESUME.equals(operationName)) {
control.resume();
reversible = true;
// undefined
context.getResult();
} else if (LIST_CONSUMERS_AS_JSON.equals(operationName)) {
context.getResult().set(control.listConsumersAsJSON());
} else {
// TODO dmr-based LIST_MESSAGE_COUNTER, LIST_MESSAGE_COUNTER_HISTORY, LIST_CONSUMERS
handback = handleAdditionalOperation(operationName, operation, context, control.getDelegate());
reversible = handback == null;
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
context.getFailureDescription().set(e.getLocalizedMessage());
}
OperationContext.RollbackHandler rh;
if (reversible) {
final Object rhHandback = handback;
rh = new OperationContext.RollbackHandler() {
@Override
public void handleRollback(OperationContext context, ModelNode operation) {
try {
if (PAUSE.equals(operationName)) {
control.resume();
} else if (RESUME.equals(operationName)) {
control.pause();
} else {
revertAdditionalOperation(operationName, operation, context, control.getDelegate(), rhHandback);
}
} catch (Exception e) {
ROOT_LOGGER.revertOperationFailed(e, getClass().getSimpleName(), operation.require(ModelDescriptionConstants.OP).asString(), PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)));
}
}
};
} else {
rh = OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER;
}
context.completeStep(rh);
}
use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.
the class MicroProfileMetricsSubsystemAdd method performBoottime.
@Override
protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
super.performBoottime(context, operation, model);
final List<String> exposedSubsystems = MicroProfileMetricsSubsystemDefinition.EXPOSED_SUBSYSTEMS.unwrap(context, model);
final boolean exposeAnySubsystem = exposedSubsystems.remove("*");
final String prefix = MicroProfileMetricsSubsystemDefinition.PREFIX.resolveModelAttribute(context, model).asStringOrNull();
final boolean securityEnabled = MicroProfileMetricsSubsystemDefinition.SECURITY_ENABLED.resolveModelAttribute(context, model).asBoolean();
context.addStep(new AbstractDeploymentChainStep() {
public void execute(DeploymentProcessorTarget processorTarget) {
processorTarget.addDeploymentProcessor(SUBSYSTEM_NAME, DEPENDENCIES, DEPENDENCIES_MICROPROFILE_METRICS, new DependencyProcessor());
processorTarget.addDeploymentProcessor(SUBSYSTEM_NAME, INSTALL, POST_MODULE_MICROPROFILE_METRICS, new DeploymentMetricProcessor(exposeAnySubsystem, exposedSubsystems, prefix));
}
}, RUNTIME);
MetricsHTTTPSecurityService.install(context, securityEnabled);
final MicroProfileVendorMetricRegistry vendorMetricRegistry = new MicroProfileVendorMetricRegistry();
MicroProfileMetricsContextService.install(context, vendorMetricRegistry);
// 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());
ImmutableManagementResourceRegistration rootResourceRegistration = context.getRootResourceRegistration();
Resource rootResource = context.readResourceFromRoot(EMPTY_ADDRESS);
MetricRegistration registration = new MetricRegistration(vendorMetricRegistry);
metricCollector.collectResourceMetrics(rootResource, rootResourceRegistration, Function.identity(), exposeAnySubsystem, exposedSubsystems, prefix, registration);
JmxRegistrar jmxRegistrar = new JmxRegistrar();
try {
jmxRegistrar.init();
} catch (IOException e) {
throw LOGGER.failedInitializeJMXRegistrar(e);
}
}
}, VERIFY);
MicroProfileMetricsLogger.LOGGER.activatingSubsystem();
}
Aggregations