use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.
the class IIOPRootDefinition method registerAttributes.
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
ReloadRequiredWriteAttributeHandler handler = new ReloadRequiredWriteAttributeHandler(ALL_ATTRIBUTES) {
@Override
protected void recordCapabilitiesAndRequirements(OperationContext context, AttributeDefinition attributeDefinition, ModelNode newValue, ModelNode oldValue) {
if (attributeDefinition != SECURITY) {
return;
}
boolean oldIsLegacy;
boolean newIsLegacy;
try {
// For historic reasons this attribute supports expressions so resolution is required.
oldIsLegacy = SecurityAllowedValues.IDENTITY.toString().equals(IIOPRootDefinition.SECURITY.resolveValue(context, oldValue).asStringOrNull());
newIsLegacy = SecurityAllowedValues.IDENTITY.toString().equals(IIOPRootDefinition.SECURITY.resolveValue(context, newValue).asStringOrNull());
} catch (OperationFailedException e) {
throw new RuntimeException(e);
}
if (oldIsLegacy && !newIsLegacy) {
// Capability was registered but no longer required.
context.deregisterCapabilityRequirement(LEGACY_SECURITY, Capabilities.IIOP_CAPABILITY, Constants.ORB_INIT_SECURITY);
} else if (!oldIsLegacy && newIsLegacy) {
// Capability wasn't required but now is.
context.registerAdditionalCapabilityRequirement(LEGACY_SECURITY, LEGACY_SECURITY, LEGACY_SECURITY);
}
// Other permutations mean no change in requirement.
}
};
for (AttributeDefinition attr : ALL_ATTRIBUTES) {
resourceRegistration.registerReadWriteAttribute(attr, null, handler);
}
}
use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.
the class WebMigrateOperation method execute.
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
if (!describe && context.getRunningMode() != RunningMode.ADMIN_ONLY) {
throw WebLogger.ROOT_LOGGER.migrateOperationAllowedOnlyInAdminOnly();
}
final List<String> warnings = new ArrayList<>();
// node containing the description (list of add operations) of the legacy subsystem
final ModelNode legacyModelAddOps = new ModelNode();
// we don't preserve order, instead we sort by address length
final Map<PathAddress, ModelNode> sortedMigrationOperations = new TreeMap<>(new Comparator<PathAddress>() {
@Override
public int compare(PathAddress o1, PathAddress o2) {
final int compare = Integer.compare(o1.size(), o2.size());
if (compare != 0) {
return compare;
}
return o1.toString().compareTo(o2.toString());
}
});
// invoke an OSH to describe the legacy messaging subsystem
describeLegacyWebResources(context, legacyModelAddOps);
// invoke an OSH to add the messaging-activemq extension
// FIXME: this does not work it the extension :add is added to the migrationOperations directly (https://issues.jboss.org/browse/WFCORE-323)
addExtension(context, sortedMigrationOperations, describe, UNDERTOW_EXTENSION);
addExtension(context, sortedMigrationOperations, describe, IO_EXTENSION);
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
addDefaultResources(sortedMigrationOperations, legacyModelAddOps, warnings);
// transform the legacy add operations and put them in migrationOperations
ProcessType processType = context.getCallEnvironment().getProcessType();
boolean domainMode = processType != ProcessType.STANDALONE_SERVER && processType != ProcessType.SELF_CONTAINED;
PathAddress baseAddres;
if (domainMode) {
baseAddres = pathAddress(operation.get(ADDRESS)).getParent();
} else {
baseAddres = pathAddress();
}
// create the new IO subsystem
createIoSubsystem(context, sortedMigrationOperations, baseAddres);
createWelcomeContentHandler(sortedMigrationOperations);
transformResources(context, legacyModelAddOps, sortedMigrationOperations, warnings, domainMode);
fixAddressesForDomainMode(pathAddress(operation.get(ADDRESS)), sortedMigrationOperations);
// put the /subsystem=web:remove operation as first
LinkedHashMap<PathAddress, ModelNode> orderedMigrationOperations = new LinkedHashMap<>();
removeWebSubsystem(orderedMigrationOperations, context.getProcessType() == ProcessType.STANDALONE_SERVER, pathAddress(operation.get(ADDRESS)));
orderedMigrationOperations.putAll(sortedMigrationOperations);
if (describe) {
// :describe-migration operation
// for describe-migration operation, do nothing and return the list of operations that would
// be executed in the composite operation
final Collection<ModelNode> values = orderedMigrationOperations.values();
ModelNode result = new ModelNode();
if (!warnings.isEmpty()) {
ModelNode rw = new ModelNode().setEmptyList();
for (String warning : warnings) {
rw.add(warning);
}
result.get(MIGRATION_WARNINGS).set(rw);
}
result.get(MIGRATION_OPERATIONS).set(values);
context.getResult().set(result);
} else {
// :migrate operation
// invoke an OSH on a composite operation with all the migration operations
final Map<PathAddress, ModelNode> migrateOpResponses = migrateSubsystems(context, orderedMigrationOperations);
context.completeStep(new OperationContext.ResultHandler() {
@Override
public void handleResult(OperationContext.ResultAction resultAction, OperationContext context, ModelNode operation) {
final ModelNode result = new ModelNode();
ModelNode rw = new ModelNode().setEmptyList();
for (String warning : warnings) {
rw.add(warning);
}
result.get(MIGRATION_WARNINGS).set(rw);
if (resultAction == OperationContext.ResultAction.ROLLBACK) {
for (Map.Entry<PathAddress, ModelNode> entry : migrateOpResponses.entrySet()) {
if (entry.getValue().hasDefined(FAILURE_DESCRIPTION)) {
// we check for failure description, as every node has 'failed', but one
// the real error has a failure description
// we break when we find the first one, as there will only ever be one failure
// as the op stops after the first failure
ModelNode desc = new ModelNode();
desc.get(OP).set(orderedMigrationOperations.get(entry.getKey()));
desc.get(RESULT).set(entry.getValue());
result.get(MIGRATION_ERROR).set(desc);
break;
}
}
context.getFailureDescription().set(new ModelNode(WebLogger.ROOT_LOGGER.migrationFailed()));
}
context.getResult().set(result);
}
});
}
}
}, MODEL);
}
use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.
the class JMSBridgeHandler method executeRuntimeStep.
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
final String bridgeName = context.getCurrentAddressValue();
final String operationName = operation.require(OP).asString();
if (null == operationName) {
throw MessagingLogger.ROOT_LOGGER.unsupportedOperation(operationName);
}
final boolean modify = !READ_ATTRIBUTE_OPERATION.equals(operationName);
final ServiceName bridgeServiceName = MessagingServices.getJMSBridgeServiceName(bridgeName);
final ServiceController<?> bridgeService = context.getServiceRegistry(modify).getService(bridgeServiceName);
if (bridgeService == null) {
if (!readOnly) {
throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(context.getCurrentAddress());
}
return;
}
final JMSBridge bridge = JMSBridge.class.cast(bridgeService.getValue());
switch(operationName) {
case READ_ATTRIBUTE_OPERATION:
readAttributeValidator.validate(operation);
final String name = operation.require(NAME).asString();
if (STARTED.equals(name)) {
context.getResult().set(bridge.isStarted());
} else if (PAUSED.getName().equals(name)) {
context.getResult().set(bridge.isPaused());
} else if (CommonAttributes.MESSAGE_COUNT.getName().equals(name)) {
context.getResult().set(bridge.getMessageCount());
} else if (ABORTED_MESSAGE_COUNT.getName().equals(name)) {
context.getResult().set(bridge.getAbortedMessageCount());
} else {
throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(name);
}
break;
case START:
try {
// we do not start the bridge directly but call startBridge() instead
// to ensure the class loader will be able to load any external resources
JMSBridgeService service = (JMSBridgeService) bridgeService.getService();
service.startBridge();
} catch (Exception e) {
throw new RuntimeException(e);
}
break;
case STOP:
try {
bridge.stop();
} catch (Exception e) {
throw new RuntimeException(e);
}
break;
case PAUSE:
try {
bridge.pause();
} catch (Exception e) {
throw new RuntimeException(e);
}
break;
case RESUME:
try {
bridge.resume();
} catch (Exception e) {
throw new RuntimeException(e);
}
break;
default:
throw MessagingLogger.ROOT_LOGGER.unsupportedOperation(operationName);
}
context.completeStep(new OperationContext.RollbackHandler() {
@Override
public void handleRollback(OperationContext context, ModelNode operation) {
try {
switch(operationName) {
case START:
bridge.stop();
break;
case STOP:
JMSBridgeService service = (JMSBridgeService) bridgeService.getService();
service.startBridge();
break;
case PAUSE:
bridge.resume();
break;
case RESUME:
bridge.pause();
break;
}
} catch (Exception e) {
MessagingLogger.ROOT_LOGGER.revertOperationFailed(e, getClass().getSimpleName(), operationName, context.getCurrentAddress());
}
}
});
}
use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.
the class ModClusterNodeDefinition method registerAttributes.
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
resourceRegistration.registerReadOnlyAttribute(LOAD, new AbstractNodeOperation() {
@Override
protected void handleNode(OperationContext context, ModClusterStatus.Node ctx, ModelNode operation) throws OperationFailedException {
context.getResult().set(new ModelNode(ctx.getLoad()));
}
});
resourceRegistration.registerReadOnlyAttribute(STATUS, new AbstractNodeOperation() {
@Override
protected void handleNode(OperationContext context, ModClusterStatus.Node ctx, ModelNode operation) throws OperationFailedException {
context.getResult().set(new ModelNode(ctx.getStatus().name()));
}
});
resourceRegistration.registerReadOnlyAttribute(LOAD_BALANCING_GROUP, new AbstractNodeOperation() {
@Override
protected void handleNode(OperationContext context, ModClusterStatus.Node ctx, ModelNode operation) throws OperationFailedException {
final String domain = ctx.getDomain();
if (domain == null) {
context.getResult().set(new ModelNode());
} else {
context.getResult().set(new ModelNode(domain));
}
}
});
resourceRegistration.registerReadOnlyAttribute(CACHE_CONNECTIONS, new AbstractNodeOperation() {
@Override
protected void handleNode(OperationContext context, ModClusterStatus.Node ctx, ModelNode operation) throws OperationFailedException {
context.getResult().set(new ModelNode(ctx.getCacheConnections()));
}
});
resourceRegistration.registerReadOnlyAttribute(MAX_CONNECTIONS, new AbstractNodeOperation() {
@Override
protected void handleNode(OperationContext context, ModClusterStatus.Node ctx, ModelNode operation) throws OperationFailedException {
context.getResult().set(new ModelNode(ctx.getMaxConnections()));
}
});
resourceRegistration.registerReadOnlyAttribute(OPEN_CONNECTIONS, new AbstractNodeOperation() {
@Override
protected void handleNode(OperationContext context, ModClusterStatus.Node ctx, ModelNode operation) throws OperationFailedException {
context.getResult().set(new ModelNode(ctx.getOpenConnections()));
}
});
resourceRegistration.registerReadOnlyAttribute(PING, new AbstractNodeOperation() {
@Override
protected void handleNode(OperationContext context, ModClusterStatus.Node ctx, ModelNode operation) throws OperationFailedException {
context.getResult().set(new ModelNode(ctx.getPing()));
}
});
resourceRegistration.registerReadOnlyAttribute(READ, new AbstractNodeOperation() {
@Override
protected void handleNode(OperationContext context, ModClusterStatus.Node ctx, ModelNode operation) throws OperationFailedException {
context.getResult().set(new ModelNode(ctx.getRead()));
}
});
resourceRegistration.registerReadOnlyAttribute(REQUEST_QUEUE_SIZE, new AbstractNodeOperation() {
@Override
protected void handleNode(OperationContext context, ModClusterStatus.Node ctx, ModelNode operation) throws OperationFailedException {
context.getResult().set(new ModelNode(ctx.getRequestQueueSize()));
}
});
resourceRegistration.registerReadOnlyAttribute(TIMEOUT, new AbstractNodeOperation() {
@Override
protected void handleNode(OperationContext context, ModClusterStatus.Node ctx, ModelNode operation) throws OperationFailedException {
context.getResult().set(new ModelNode(ctx.getTimeout()));
}
});
resourceRegistration.registerReadOnlyAttribute(WRITTEN, new AbstractNodeOperation() {
@Override
protected void handleNode(OperationContext context, ModClusterStatus.Node ctx, ModelNode operation) throws OperationFailedException {
context.getResult().set(new ModelNode(ctx.getTransferred()));
}
});
resourceRegistration.registerReadOnlyAttribute(TTL, new AbstractNodeOperation() {
@Override
protected void handleNode(OperationContext context, ModClusterStatus.Node ctx, ModelNode operation) throws OperationFailedException {
context.getResult().set(new ModelNode(ctx.getTtl()));
}
});
resourceRegistration.registerReadOnlyAttribute(FLUSH_PACKETS, new AbstractNodeOperation() {
@Override
protected void handleNode(OperationContext context, ModClusterStatus.Node ctx, ModelNode operation) throws OperationFailedException {
context.getResult().set(new ModelNode(ctx.isFlushPackets()));
}
});
resourceRegistration.registerReadOnlyAttribute(QUEUE_NEW_REQUESTS, new AbstractNodeOperation() {
@Override
protected void handleNode(OperationContext context, ModClusterStatus.Node ctx, ModelNode operation) throws OperationFailedException {
context.getResult().set(new ModelNode(ctx.isQueueNewRequests()));
}
});
resourceRegistration.registerReadOnlyAttribute(URI, new AbstractNodeOperation() {
@Override
protected void handleNode(OperationContext context, ModClusterStatus.Node ctx, ModelNode operation) throws OperationFailedException {
context.getResult().set(new ModelNode(ctx.getUri().toString()));
}
});
resourceRegistration.registerReadOnlyAttribute(ALIASES, new AbstractNodeOperation() {
@Override
protected void handleNode(OperationContext context, ModClusterStatus.Node ctx, ModelNode operation) throws OperationFailedException {
final ModelNode result = new ModelNode();
for (String alias : ctx.getAliases()) {
UndertowLogger.ROOT_LOGGER.tracef("Adding alias %s", alias);
result.add(alias);
}
context.getResult().set(result);
}
});
resourceRegistration.registerReadOnlyAttribute(ELECTED, new AbstractNodeOperation() {
@Override
protected void handleNode(OperationContext context, ModClusterStatus.Node ctx, ModelNode operation) throws OperationFailedException {
context.getResult().set(new ModelNode(ctx.getElected()));
}
});
}
use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.
the class XTSSubsystemAdd method performBoottime.
@Override
protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final String hostName = HOST_NAME.resolveModelAttribute(context, model).asString();
final ModelNode coordinatorURLAttribute = ENVIRONMENT_URL.resolveModelAttribute(context, model);
String coordinatorURL = coordinatorURLAttribute.isDefined() ? coordinatorURLAttribute.asString() : null;
// formatting possible IPv6 address to contain square brackets
if (coordinatorURL != null) {
// [1] http://, [2] ::1, [3] 8080, [4] /ws-c11/ActivationService
Pattern urlPattern = Pattern.compile("^([a-zA-Z]+://)(.*):([^/]*)(/.*)$");
Matcher urlMatcher = urlPattern.matcher(coordinatorURL);
if (urlMatcher.matches()) {
String address = NetworkUtils.formatPossibleIpv6Address(urlMatcher.group(2));
coordinatorURL = String.format("%s%s:%s%s", urlMatcher.group(1), address, urlMatcher.group(3), urlMatcher.group(4));
}
}
if (coordinatorURL != null) {
XtsAsLogger.ROOT_LOGGER.debugf("nodeIdentifier=%s%n", coordinatorURL);
}
// TODO WFLY-14350 make the 'false' the default value of DEFAULT_CONTEXT_PROPAGATION
final boolean isDefaultContextPropagation = DEFAULT_CONTEXT_PROPAGATION.resolveModelAttribute(context, model).asBoolean(false);
context.addStep(new AbstractDeploymentChainStep() {
protected void execute(DeploymentProcessorTarget processorTarget) {
processorTarget.addDeploymentProcessor(XTSExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_XTS_COMPONENT_INTERCEPTORS, new XTSInterceptorDeploymentProcessor());
processorTarget.addDeploymentProcessor(XTSExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_XTS_SOAP_HANDLERS, new XTSHandlerDeploymentProcessor());
processorTarget.addDeploymentProcessor(XTSExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_XTS, new XTSDependenciesDeploymentProcessor());
processorTarget.addDeploymentProcessor(XTSExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_XTS_PORTABLE_EXTENSIONS, new GracefulShutdownDeploymentProcessor());
processorTarget.addDeploymentProcessor(XTSExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_TRANSACTIONS, new CompensationsDependenciesDeploymentProcessor());
}
}, OperationContext.Stage.RUNTIME);
final ServiceTarget target = context.getServiceTarget();
// TODO eventually we should add a config service which manages the XTS configuration
// this will allow us to include a switch enabling or disabling deployment of
// endpoints specific to client, coordinator or participant and then deploy
// and redeploy the relevant endpoints as needed/ the same switches can be used
// byte the XTS service to decide whether to perfomr client, coordinator or
// participant initialisation. we should also provide config switches which
// decide whether to initialise classes and deploy services for AT, BA or both.
// for now we will just deploy all the endpoints and always do client, coordinator
// and participant init for both AT and BA.
// add an endpoint publisher service for each of the required endpoint contexts
// specifying all the relevant URL patterns and SEI classes
final ClassLoader loader = XTSService.class.getClassLoader();
ServiceBuilder<Context> endpointBuilder;
ArrayList<ServiceController<Context>> controllers = new ArrayList<ServiceController<Context>>();
Map<Class<?>, Object> attachments = new HashMap<>();
attachments.put(RejectionRule.class, new GracefulShutdownRejectionRule());
for (ContextInfo contextInfo : getContextDefinitions(context, model)) {
String contextName = contextInfo.contextPath;
Map<String, String> map = new HashMap<String, String>();
for (EndpointInfo endpointInfo : contextInfo.endpointInfo) {
map.put(endpointInfo.URLPattern, endpointInfo.SEIClassname);
}
endpointBuilder = EndpointPublishService.createServiceBuilder(target, contextName, loader, hostName, map, null, null, null, attachments, context.getCapabilityServiceSupport());
controllers.add(endpointBuilder.setInitialMode(Mode.ACTIVE).install());
}
XTSHandlersService.install(target, isDefaultContextPropagation);
// add an XTS service which depends on all the WS endpoints
final XTSManagerService xtsService = new XTSManagerService(coordinatorURL);
// this service needs to depend on the transaction recovery service
// because it can only initialise XTS recovery once the transaction recovery
// service has initialised the orb layer
ServiceBuilder<?> xtsServiceBuilder = target.addService(XTSServices.JBOSS_XTS_MAIN, xtsService);
xtsServiceBuilder.requires(TxnServices.JBOSS_TXN_ARJUNA_TRANSACTION_MANAGER);
// this service needs to depend on JBossWS Config Service to be notified of the JBoss WS config (bind address, port etc)
xtsServiceBuilder.addDependency(WSServices.CONFIG_SERVICE, ServerConfig.class, xtsService.getWSServerConfig());
xtsServiceBuilder.requires(WSServices.XTS_CLIENT_INTEGRATION_SERVICE);
// the service also needs to depend on the endpoint services
for (ServiceController<Context> controller : controllers) {
xtsServiceBuilder.requires(controller.getName());
}
xtsServiceBuilder.setInitialMode(Mode.ACTIVE).install();
// WS-AT / Jakarta Transactions Transaction bridge services:
final TxBridgeInboundRecoveryService txBridgeInboundRecoveryService = new TxBridgeInboundRecoveryService();
ServiceBuilder<?> txBridgeInboundRecoveryServiceBuilder = target.addService(XTSServices.JBOSS_XTS_TXBRIDGE_INBOUND_RECOVERY, txBridgeInboundRecoveryService);
txBridgeInboundRecoveryServiceBuilder.requires(XTSServices.JBOSS_XTS_MAIN);
txBridgeInboundRecoveryServiceBuilder.setInitialMode(Mode.ACTIVE).install();
final TxBridgeOutboundRecoveryService txBridgeOutboundRecoveryService = new TxBridgeOutboundRecoveryService();
ServiceBuilder<?> txBridgeOutboundRecoveryServiceBuilder = target.addService(XTSServices.JBOSS_XTS_TXBRIDGE_OUTBOUND_RECOVERY, txBridgeOutboundRecoveryService);
txBridgeOutboundRecoveryServiceBuilder.requires(XTSServices.JBOSS_XTS_MAIN);
txBridgeOutboundRecoveryServiceBuilder.setInitialMode(Mode.ACTIVE).install();
}
Aggregations