use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.
the class RemotingProfileRemove method recoverServices.
@Override
protected void recoverServices(final OperationContext context, final ModelNode operation, final ModelNode profileNode) throws OperationFailedException {
try {
final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
RemotingProfileAdd.INSTANCE.installServices(context, address, profileNode);
} catch (OperationFailedException e) {
throw ControllerLogger.ROOT_LOGGER.failedToRecoverServices(e);
}
}
use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.
the class AbstractEJBComponentRuntimeHandler method getComponent.
private T getComponent(final ServiceName serviceName, final PathAddress operationAddress, final OperationContext context, final boolean forWrite) throws OperationFailedException {
ServiceRegistry registry = context.getServiceRegistry(forWrite);
ServiceController<?> controller = registry.getService(serviceName);
if (controller == null) {
String exceptionMessage = EjbLogger.ROOT_LOGGER.noComponentAvailableForAddress(operationAddress);
throw new OperationFailedException(exceptionMessage);
}
ServiceController.State controllerState = controller.getState();
if (controllerState != ServiceController.State.UP) {
String exceptionMessage = EjbLogger.ROOT_LOGGER.invalidComponentState(operationAddress, controllerState, ServiceController.State.UP);
throw new OperationFailedException(exceptionMessage);
}
return componentClass.cast(controller.getValue());
}
use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.
the class AbstractEJBComponentRuntimeHandler method getComponentConfiguration.
private ServiceName getComponentConfiguration(final OperationContext context, final PathAddress operationAddress) throws OperationFailedException {
final List<PathElement> relativeAddress = new ArrayList<PathElement>();
final String typeKey = this.componentType.getResourceType();
boolean skip = true;
for (int i = operationAddress.size() - 1; i >= 0; i--) {
PathElement pe = operationAddress.getElement(i);
if (skip && !pe.getKey().equals(typeKey)) {
continue;
} else {
skip = false;
}
if (ModelDescriptionConstants.DEPLOYMENT.equals(pe.getKey())) {
final String runtimName = resolveRuntimeName(context, pe);
PathElement realPe = PathElement.pathElement(pe.getKey(), runtimName);
relativeAddress.add(0, realPe);
break;
} else {
relativeAddress.add(0, pe);
}
}
final PathAddress pa = PathAddress.pathAddress(relativeAddress);
final ServiceName config = componentConfigs.get(pa);
if (config == null) {
String exceptionMessage = EjbLogger.ROOT_LOGGER.noComponentRegisteredForAddress(operationAddress);
throw new OperationFailedException(exceptionMessage);
}
return config;
}
use of org.jboss.as.controller.OperationFailedException 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.OperationFailedException in project wildfly by wildfly.
the class JMSServerControlHandler method executeRuntimeStep.
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
if (rollbackOperationIfServerNotActive(context, operation)) {
return;
}
final String operationName = operation.require(OP).asString();
final JMSServerControl serverControl = getServerControl(context, operation);
if (serverControl == null) {
PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
}
try {
if (LIST_CONNECTIONS_AS_JSON.equals(operationName)) {
String json = serverControl.listConnectionsAsJSON();
context.getResult().set(json);
} else if (LIST_CONSUMERS_AS_JSON.equals(operationName)) {
String connectionID = CONNECTION_ID.resolveModelAttribute(context, operation).asString();
String json = serverControl.listConsumersAsJSON(connectionID);
context.getResult().set(json);
} else if (LIST_ALL_CONSUMERS_AS_JSON.equals(operationName)) {
String json = serverControl.listAllConsumersAsJSON();
context.getResult().set(json);
} else if (LIST_TARGET_DESTINATIONS.equals(operationName)) {
String sessionID = SESSION_ID.resolveModelAttribute(context, operation).asString();
String[] list = serverControl.listTargetDestinations(sessionID);
reportListOfStrings(context, list);
} else if (GET_LAST_SENT_MESSAGE_ID.equals(operationName)) {
String sessionID = SESSION_ID.resolveModelAttribute(context, operation).asString();
String addressName = ADDRESS_NAME.resolveModelAttribute(context, operation).asString();
String msgId = serverControl.getLastSentMessageID(sessionID, addressName);
context.getResult().set(msgId);
} else if (GET_SESSION_CREATION_TIME.equals(operationName)) {
String sessionID = SESSION_ID.resolveModelAttribute(context, operation).asString();
String time = serverControl.getSessionCreationTime(sessionID);
context.getResult().set(time);
} else if (LIST_SESSIONS_AS_JSON.equals(operationName)) {
String connectionID = CONNECTION_ID.resolveModelAttribute(context, operation).asString();
String json = serverControl.listSessionsAsJSON(connectionID);
context.getResult().set(json);
} else if (LIST_PREPARED_TRANSACTION_JMS_DETAILS_AS_JSON.equals(operationName)) {
String json = serverControl.listPreparedTransactionDetailsAsJSON();
context.getResult().set(json);
} else if (LIST_PREPARED_TRANSACTION_JMS_DETAILS_AS_HTML.equals(operationName)) {
String html = serverControl.listPreparedTransactionDetailsAsHTML();
context.getResult().set(html);
} else {
// Bug
throw MessagingLogger.ROOT_LOGGER.unsupportedOperation(operationName);
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
context.getFailureDescription().set(e.getLocalizedMessage());
}
}
Aggregations