use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.
the class JMSConnectionFactoryDefinitionInjectionSource method getResourceValue.
@Override
public void getResourceValue(ResolutionContext context, ServiceBuilder<?> serviceBuilder, DeploymentPhaseContext phaseContext, Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (targetsPooledConnectionFactory(getActiveMQServerName(properties), resourceAdapter, phaseContext.getServiceRegistry())) {
try {
startedPooledConnectionFactory(context, jndiName, serviceBuilder, phaseContext.getServiceTarget(), deploymentUnit, injector);
} catch (OperationFailedException e) {
throw new DeploymentUnitProcessingException(e);
}
} else {
// delegate to the resource-adapter subsystem to create a generic JCA connection factory.
ConnectionFactoryDefinitionInjectionSource cfdis = new ConnectionFactoryDefinitionInjectionSource(jndiName, interfaceName, resourceAdapter);
cfdis.setMaxPoolSize(maxPoolSize);
cfdis.setMinPoolSize(minPoolSize);
cfdis.setTransactionSupportLevel(transactional ? TransactionSupport.TransactionSupportLevel.XATransaction : TransactionSupport.TransactionSupportLevel.NoTransaction);
// transfer all the generic properties + the additional properties specific to the JMSConnectionFactoryDefinition
for (Map.Entry<String, String> property : properties.entrySet()) {
cfdis.addProperty(property.getKey(), property.getValue());
}
if (!user.isEmpty()) {
cfdis.addProperty("user", user);
}
if (!password.isEmpty()) {
cfdis.addProperty("password", password);
}
if (!clientId.isEmpty()) {
cfdis.addProperty("clientId", clientId);
}
cfdis.getResourceValue(context, serviceBuilder, phaseContext, injector);
}
}
use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.
the class QueueReadAttributeHandler method executeRuntimeStep.
@Override
public void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
if (ignoreOperationIfServerNotActive(context, operation)) {
return;
}
validator.validate(operation);
final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString();
PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
String queueName = address.getLastElement().getValue();
if (forwardToRuntimeQueue(context, operation, RUNTIME_INSTANCE)) {
return;
}
final ServiceName serviceName = MessagingServices.getActiveMQServiceName(address);
ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
QueueControl control = QueueControl.class.cast(server.getManagementService().getResource(ResourceNames.CORE_QUEUE + queueName));
if (control == null) {
throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
}
if (MESSAGE_COUNT.getName().equals(attributeName)) {
context.getResult().set(control.getMessageCount());
} else if (SCHEDULED_COUNT.getName().equals(attributeName)) {
context.getResult().set(control.getScheduledCount());
} else if (CONSUMER_COUNT.getName().equals(attributeName)) {
context.getResult().set(control.getConsumerCount());
} else if (DELIVERING_COUNT.getName().equals(attributeName)) {
context.getResult().set(control.getDeliveringCount());
} else if (MESSAGES_ADDED.getName().equals(attributeName)) {
context.getResult().set(control.getMessagesAdded());
} else if (ID.getName().equals(attributeName)) {
context.getResult().set(control.getID());
} else if (PAUSED.getName().equals(attributeName)) {
try {
context.getResult().set(control.isPaused());
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
} else if (TEMPORARY.getName().equals(attributeName)) {
context.getResult().set(control.isTemporary());
} else if (EXPIRY_ADDRESS.getName().equals(attributeName)) {
if (control.getExpiryAddress() != null) {
context.getResult().set(control.getExpiryAddress());
}
} else if (DEAD_LETTER_ADDRESS.getName().equals(attributeName)) {
if (control.getDeadLetterAddress() != null) {
context.getResult().set(control.getDeadLetterAddress());
}
} else if (readStorageAttributes && getStorageAttributeNames().contains(attributeName)) {
if (ADDRESS.getName().equals(attributeName)) {
context.getResult().set(control.getAddress());
} else if (DURABLE.getName().equals(attributeName)) {
context.getResult().set(control.isDurable());
} else if (FILTER.getName().equals(attributeName)) {
ModelNode result = context.getResult();
String filter = control.getFilter();
if (filter != null) {
result.set(filter);
}
}
} else {
throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(attributeName);
}
}
use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.
the class GroupingHandlerAdd method performRuntime.
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
ServiceRegistry registry = context.getServiceRegistry(true);
final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
ServiceController<?> service = registry.getService(serviceName);
if (service != null) {
final ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
if (server.getGroupingHandler() != null) {
throw new OperationFailedException(MessagingLogger.ROOT_LOGGER.childResourceAlreadyExists(CommonAttributes.GROUPING_HANDLER));
}
// the groupingHandler is added as a child of the server resource. Requires a reload to restart the server with the grouping-handler
if (context.isNormalServer()) {
context.addStep(new OperationStepHandler() {
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
context.reloadRequired();
context.completeStep(OperationContext.RollbackHandler.REVERT_RELOAD_REQUIRED_ROLLBACK_HANDLER);
}
}, OperationContext.Stage.RUNTIME);
}
}
// else the initial subsystem install is not complete and the grouping handler will be added in ServerAdd
}
use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.
the class BridgeRemove method performRuntime.
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final String name = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
final ServiceRegistry registry = context.getServiceRegistry(true);
final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
final ServiceController<?> service = registry.getService(serviceName);
if (service != null && service.getState() == ServiceController.State.UP) {
ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
try {
server.getActiveMQServerControl().destroyBridge(name);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
// TODO should this be an OFE instead?
throw new RuntimeException(e);
}
}
}
use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.
the class PoolOperations method execute.
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
final String jndiName;
ModelNode model;
if (!address.getElement(0).getKey().equals(ModelDescriptionConstants.DEPLOYMENT) && (model = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel()).isDefined()) {
jndiName = Util.getJndiName(context, model);
} else {
jndiName = address.getLastElement().getValue();
}
final Object[] parameters = getParameters(context, operation);
if (context.isNormalServer()) {
context.addStep(new OperationStepHandler() {
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final ServiceController<?> managementRepoService = context.getServiceRegistry(disallowMonitor).getService(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE);
if (managementRepoService != null) {
ModelNode operationResult = null;
try {
final ManagementRepository repository = (ManagementRepository) managementRepoService.getValue();
final List<Pool> pools = matcher.match(jndiName, repository);
if (pools.isEmpty()) {
throw ConnectorLogger.ROOT_LOGGER.failedToMatchPool(jndiName);
}
for (Pool pool : pools) {
operationResult = invokeCommandOn(pool, parameters);
}
} catch (Exception e) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToInvokeOperation(e.getLocalizedMessage()));
}
if (operationResult != null) {
context.getResult().set(operationResult);
}
}
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
}, OperationContext.Stage.RUNTIME);
}
context.stepCompleted();
}
Aggregations