use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.
the class JMSQueueRemove method performRuntime.
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
final String name = address.getLastElement().getValue();
ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
JMSServerControl control = JMSServerControl.class.cast(server.getManagementService().getResource(ResourceNames.JMS_SERVER));
if (control != null) {
try {
control.destroyQueue(name, true);
} catch (Exception e) {
throw new OperationFailedException(e);
}
}
context.removeService(JMSServices.getJmsQueueBaseServiceName(serviceName).append(name));
for (String entry : CommonAttributes.DESTINATION_ENTRIES.unwrap(context, model)) {
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(entry);
ServiceName binderServiceName = bindInfo.getBinderServiceName();
context.removeService(binderServiceName);
}
for (String legacyEntry : CommonAttributes.LEGACY_ENTRIES.unwrap(context, model)) {
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(legacyEntry);
ServiceName binderServiceName = bindInfo.getBinderServiceName();
context.removeService(binderServiceName);
}
}
use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.
the class SecurityRoleReadAttributeHandler method executeRuntimeStep.
@Override
public void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString();
PathAddress pathAddress = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
String addressName = pathAddress.getElement(pathAddress.size() - 2).getValue();
String roleName = pathAddress.getLastElement().getValue();
final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
AddressControl control = AddressControl.class.cast(server.getManagementService().getResource(ResourceNames.CORE_ADDRESS + addressName));
if (control == null) {
PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
}
try {
String rolesAsJSON = control.getRolesAsJSON();
ModelNode res = ModelNode.fromJSONString(rolesAsJSON);
ModelNode roles = ManagementUtil.convertSecurityRole(res);
ModelNode matchedRole = findRole(roleName, roles);
if (matchedRole == null || !matchedRole.hasDefined(attributeName)) {
throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(attributeName);
}
boolean value = matchedRole.get(attributeName).asBoolean();
context.getResult().set(value);
} catch (Exception e) {
context.getFailureDescription().set(e.getLocalizedMessage());
}
}
use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.
the class AbstractPicketLinkMetricsOperationHandler method execute.
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
final String name = address.getLastElement().getValue();
final String attributeName = operation.require(NAME).asString();
final ServiceController<?> controller = context.getServiceRegistry(false).getRequiredService(createServiceName(name));
try {
PicketLinkFederationService<?> service = (PicketLinkFederationService<?>) controller.getValue();
doPopulateResult(service.getMetrics(), context.getResult(), attributeName);
} catch (Exception e) {
throw PicketLinkLogger.ROOT_LOGGER.failedToGetMetrics(e.getMessage());
}
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
}, OperationContext.Stage.RUNTIME);
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.
the class IDMConfigWriteAttributeHandler method execute.
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final PathAddress address = getParentAddress(PathAddress.pathAddress(operation.require(OP_ADDR)));
Resource resource = context.readResourceFromRoot(address);
final ModelNode parentModel = Resource.Tools.readModel(resource);
PartitionManagerAddHandler.INSTANCE.validateModel(context, address.getLastElement().getValue(), parentModel);
context.stepCompleted();
}
}, OperationContext.Stage.MODEL);
super.execute(context, operation);
}
use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.
the class IdentityConfigurationRemoveStepHandler method updateModel.
@Override
protected void updateModel(OperationContext context, ModelNode operation) throws OperationFailedException {
PathAddress partitionManagerAddress = getParentAddress(context.getCurrentAddress());
Resource partitionManagerResource = context.readResourceFromRoot(partitionManagerAddress);
checkIfLastConfiguration(partitionManagerResource);
ModelNode originalParentModel = Resource.Tools.readModel(partitionManagerResource);
super.updateModel(context, operation);
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
PartitionManagerRemoveHandler.INSTANCE.removeIdentityStoreServices(context, originalParentModel, partitionManagerAddress.getLastElement().getValue(), context.getCurrentAddressValue());
context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER);
}
}, OperationContext.Stage.RUNTIME);
}
Aggregations