use of org.jboss.as.controller.PathAddress in project wildfly by wildfly.
the class LogStoreTransactionDeleteHandler method execute.
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
MBeanServer mbs = TransactionExtension.getMBeanServer(context);
final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
try {
final ObjectName on = LogStoreResource.getObjectName(resource);
// Invoke operation
Object res = mbs.invoke(on, "remove", null, null);
try {
// validate that the MBean was removed:
mbs.getObjectInstance(on);
String reason = res != null ? res.toString() : LOG_DELETE_FAILURE_MESSAGE;
throw new OperationFailedException(reason);
} catch (InstanceNotFoundException e) {
// success, the MBean was deleted
final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
final PathElement element = address.getLastElement();
logStoreResource.removeChild(element);
}
} catch (OperationFailedException e) {
throw e;
} catch (Exception e) {
throw new OperationFailedException(e.getMessage());
}
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
use of org.jboss.as.controller.PathAddress in project wildfly by wildfly.
the class UndertowService method getFilterRefServiceName.
public static ServiceName getFilterRefServiceName(final PathAddress address, String name) {
final PathAddress oneUp = address.subAddress(0, address.size() - 1);
final PathAddress twoUp = oneUp.subAddress(0, oneUp.size() - 1);
final PathAddress threeUp = twoUp.subAddress(0, twoUp.size() - 1);
ServiceName serviceName;
if (address.getLastElement().getKey().equals(Constants.FILTER_REF)) {
if (oneUp.getLastElement().getKey().equals(Constants.HOST)) {
//adding reference
String host = oneUp.getLastElement().getValue();
String server = twoUp.getLastElement().getValue();
serviceName = UndertowService.filterRefName(server, host, name);
} else {
String location = oneUp.getLastElement().getValue();
String host = twoUp.getLastElement().getValue();
String server = threeUp.getLastElement().getValue();
serviceName = UndertowService.filterRefName(server, host, location, name);
}
} else if (address.getLastElement().getKey().equals(Constants.HOST)) {
String host = address.getLastElement().getValue();
String server = oneUp.getLastElement().getValue();
serviceName = UndertowService.filterRefName(server, host, name);
} else {
String location = address.getLastElement().getValue();
String host = oneUp.getLastElement().getValue();
String server = twoUp.getLastElement().getValue();
serviceName = UndertowService.filterRefName(server, host, location, name);
}
return serviceName;
}
use of org.jboss.as.controller.PathAddress in project wildfly by wildfly.
the class LocationAdd method performRuntime.
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
final PathAddress hostAddress = address.subAddress(0, address.size() - 1);
final PathAddress serverAddress = hostAddress.subAddress(0, hostAddress.size() - 1);
final String name = address.getLastElement().getValue();
final String handler = LocationDefinition.HANDLER.resolveModelAttribute(context, model).asString();
final LocationService service = new LocationService(name);
final String serverName = serverAddress.getLastElement().getValue();
final String hostName = hostAddress.getLastElement().getValue();
final ServiceName hostServiceName = UndertowService.virtualHostName(serverName, hostName);
final ServiceName serviceName = UndertowService.locationServiceName(serverName, hostName, name);
final ServiceBuilder<LocationService> builder = context.getServiceTarget().addService(serviceName, service).addDependency(hostServiceName, Host.class, service.getHost()).addDependency(UndertowService.HANDLER.append(handler), HttpHandler.class, service.getHttpHandler());
builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
}
use of org.jboss.as.controller.PathAddress in project wildfly by wildfly.
the class HostAdd method performRuntime.
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final PathAddress address = context.getCurrentAddress();
final PathAddress serverAddress = address.getParent();
final PathAddress subsystemAddress = serverAddress.getParent();
final ModelNode subsystemModel = Resource.Tools.readModel(context.readResourceFromRoot(subsystemAddress, false), 0);
final ModelNode serverModel = Resource.Tools.readModel(context.readResourceFromRoot(serverAddress, false), 0);
final String name = address.getLastElement().getValue();
final List<String> aliases = HostDefinition.ALIAS.unwrap(context, model);
final String defaultWebModule = HostDefinition.DEFAULT_WEB_MODULE.resolveModelAttribute(context, model).asString();
final String defaultServerName = UndertowRootDefinition.DEFAULT_SERVER.resolveModelAttribute(context, subsystemModel).asString();
final String defaultHostName = ServerDefinition.DEFAULT_HOST.resolveModelAttribute(context, serverModel).asString();
final String serverName = serverAddress.getLastElement().getValue();
final boolean isDefaultHost = defaultServerName.equals(serverName) && name.equals(defaultHostName);
final int defaultResponseCode = HostDefinition.DEFAULT_RESPONSE_CODE.resolveModelAttribute(context, model).asInt();
final boolean enableConsoleRedirect = !HostDefinition.DISABLE_CONSOLE_REDIRECT.resolveModelAttribute(context, model).asBoolean();
DefaultDeploymentMappingProvider.instance().addMapping(defaultWebModule, serverName, name);
final ServiceName virtualHostServiceName = UndertowService.virtualHostName(serverName, name);
final Host service = new Host(name, aliases == null ? new LinkedList<>() : aliases, defaultWebModule, defaultResponseCode);
final ServiceBuilder<Host> builder = context.getServiceTarget().addService(virtualHostServiceName, service).addDependency(UndertowService.SERVER.append(serverName), Server.class, service.getServerInjection()).addDependency(UndertowService.UNDERTOW, UndertowService.class, service.getUndertowService()).addDependency(ControlledProcessStateService.SERVICE_NAME, ControlledProcessStateService.class, service.getControlledProcessStateServiceInjectedValue());
builder.setInitialMode(Mode.ON_DEMAND);
if (isDefaultHost) {
addCommonHost(context, name, aliases, serverName, virtualHostServiceName);
//add alias for default host of default server service
builder.addAliases(UndertowService.DEFAULT_HOST);
}
builder.install();
if (enableConsoleRedirect) {
// Setup the web console redirect
final ServiceName consoleRedirectName = UndertowService.consoleRedirectServiceName(serverName, name);
// A standalone server is the only process type with a console redirect
if (context.getProcessType() == ProcessType.STANDALONE_SERVER) {
final ConsoleRedirectService redirectService = new ConsoleRedirectService();
final ServiceBuilder<ConsoleRedirectService> redirectBuilder = context.getServiceTarget().addService(consoleRedirectName, redirectService).addDependency(UndertowHttpManagementService.SERVICE_NAME, HttpManagement.class, redirectService.getHttpManagementInjector()).addDependency(virtualHostServiceName, Host.class, redirectService.getHostInjector()).setInitialMode(Mode.PASSIVE);
redirectBuilder.install();
} else {
// Other process types don't have a console, not depending on the UndertowHttpManagementService should
// result in a null dependency in the service and redirect accordingly
final ConsoleRedirectService redirectService = new ConsoleRedirectService();
final ServiceBuilder<ConsoleRedirectService> redirectBuilder = context.getServiceTarget().addService(consoleRedirectName, redirectService).addDependency(virtualHostServiceName, Host.class, redirectService.getHostInjector()).setInitialMode(Mode.PASSIVE);
redirectBuilder.install();
}
}
}
use of org.jboss.as.controller.PathAddress in project wildfly by wildfly.
the class HostRemove method performRuntime.
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final PathAddress address = context.getCurrentAddress();
final PathAddress parent = address.getParent();
final String name = address.getLastElement().getValue();
final String serverName = parent.getLastElement().getValue();
final ServiceName virtualHostServiceName = UndertowService.virtualHostName(serverName, name);
context.removeService(virtualHostServiceName);
final ServiceName consoleRedirectName = UndertowService.consoleRedirectServiceName(serverName, name);
context.removeService(consoleRedirectName);
final ServiceName commonHostName = WebHost.SERVICE_NAME.append(name);
context.removeService(commonHostName);
final String defaultWebModule = HostDefinition.DEFAULT_WEB_MODULE.resolveModelAttribute(context, model).asString();
DefaultDeploymentMappingProvider.instance().removeMapping(defaultWebModule);
}
Aggregations