Java Code Examples for org.jboss.as.controller.PathAddress#getLastElement()
The following examples show how to use
org.jboss.as.controller.PathAddress#getLastElement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HandlerUtil.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
static void checkNoOtherHandlerWithTheSameName(OperationContext context) throws OperationFailedException { final PathAddress address = context.getCurrentAddress(); final PathAddress parentAddress = address.subAddress(0, address.size() - 1); final Resource resource = context.readResourceFromRoot(parentAddress); final PathElement element = address.getLastElement(); final String handlerType = element.getKey(); final String handlerName = element.getValue(); for (String otherHandler: HANDLER_TYPES) { if (handlerType.equals(otherHandler)) { // we need to check other handler types for the same name continue; } final PathElement check = PathElement.pathElement(otherHandler, handlerName); if (resource.hasChild(check)) { throw DomainManagementLogger.ROOT_LOGGER.handlerAlreadyExists(check.getValue(), parentAddress.append(check)); } } }
Example 2
Source File: ServerStatusHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); final PathElement element = address.getLastElement(); final String serverName = element.getValue(); final ModelNode subModel = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel(); final boolean isStart = ServerConfigResourceDefinition.AUTO_START.resolveModelAttribute(context, subModel).asBoolean(); ServerStatus status = serverInventory.determineServerStatus(serverName); if (status == ServerStatus.STOPPED) { status = isStart ? status : ServerStatus.DISABLED; } if(status != null) { context.getResult().set(status.toString()); } else { throw new OperationFailedException(HostControllerLogger.ROOT_LOGGER.failedToGetServerStatus()); } }
Example 3
Source File: RemotingSubsystemTransformersTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private void checkRejectOutboundConnectionProtocolNotRemote(KernelServices mainServices, ModelVersion version, String type, String name) throws OperationFailedException { ModelNode operation = new ModelNode(); operation.get(OP).set(WRITE_ATTRIBUTE_OPERATION); ModelNode address = new ModelNode(); address.add(SUBSYSTEM, RemotingExtension.SUBSYSTEM_NAME); address.add(type, name); operation.get(OP_ADDR).set(address); operation.get(NAME).set(CommonAttributes.PROTOCOL); operation.get(VALUE).set(Protocol.HTTP_REMOTING.toString()); checkReject(operation, mainServices, version); PathAddress addr = PathAddress.pathAddress(operation.get(OP_ADDR)); PathElement element = addr.getLastElement(); addr = addr.subAddress(0, addr.size() - 1); addr = addr.append(PathElement.pathElement(element.getKey(), "remoting-outbound2")); operation = Util.createAddOperation(addr); operation.get(CommonAttributes.OUTBOUND_SOCKET_BINDING_REF).set("dummy-outbound-socket"); operation.get(CommonAttributes.USERNAME).set("myuser"); operation.get(CommonAttributes.PROTOCOL).set(Protocol.HTTP_REMOTING.toString()); checkReject(operation, mainServices, version); }
Example 4
Source File: GlobalOperationHandlers.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override protected boolean authorize(OperationContext context, PathAddress base, ModelNode operation) { if (base.size() > 0) { PathElement element = base.getLastElement(); if (!element.isWildcard() && (element.getKey().equals(HOST)/* || element.getKey().equals(RUNNING_SERVER)*/)) { //Only do this for host resources. The rest of r-r-d does filtering itself. However, without //this: // - a slave host scoped role doing a /host=*:r-r-d will not get rid of the host=master resource // - a master host scoped role doing a /host=*/server=*/subsystem=thing:r-r-d will not get rid of the host=slave resource ModelNode toAuthorize = operation.clone(); toAuthorize.get(OP).set(READ_RESOURCE_DESCRIPTION_OPERATION); toAuthorize.get(OP_ADDR).set(base.toModelNode()); AuthorizationResult.Decision decision = context.authorize(toAuthorize, EnumSet.of(Action.ActionEffect.ADDRESS)).getDecision(); return decision == AuthorizationResult.Decision.PERMIT; } } return true; }
Example 5
Source File: AbstractBindingWriteHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode resolvedValue, final ModelNode currentValue, final HandbackHolder<RollbackInfo> handbackHolder) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)); final PathElement element = address.getLastElement(); final String bindingName = element.getValue(); final ModelNode bindingModel = context.readResource(PathAddress.EMPTY_ADDRESS).getModel(); final ServiceName serviceName = SOCKET_BINDING_CAPABILITY.getCapabilityServiceName(bindingName, SocketBinding.class); final ServiceController<?> controller = context.getServiceRegistry(true).getRequiredService(serviceName); final SocketBinding binding = controller.getState() == ServiceController.State.UP ? SocketBinding.class.cast(controller.getValue()) : null; final boolean bound = binding != null && binding.isBound(); if (binding == null) { // existing is not started, so can't update it. Instead reinstall the service handleBindingReinstall(context, bindingName, bindingModel, serviceName); } else if (bound) { // Cannot edit bound sockets return true; } else { handleRuntimeChange(context, operation, attributeName, resolvedValue, binding); } handbackHolder.setHandback(new RollbackInfo(bindingName, bindingModel, binding)); return requiresRestart(); }
Example 6
Source File: ThemeResourceAddHandler.java From keycloak with Apache License 2.0 | 6 votes |
@Override protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { // TODO: localize exception. get id number if (!operation.get(OP).asString().equals(ADD)) { throw new OperationFailedException("Unexpected operation for add Theme. operation=" + operation.toString()); } PathAddress address = PathAddress.pathAddress(operation.get(ADDRESS)); PathElement last = address.getLastElement(); if (!last.getValue().equals(ThemeResourceDefinition.RESOURCE_NAME)) { throw new OperationFailedException("Theme resource with name " + last.getValue() + " not allowed."); } for (AttributeDefinition def : ALL_ATTRIBUTES) { def.validateAndSet(operation, model); } KeycloakAdapterConfigService.INSTANCE.updateConfig(operation, model); }
Example 7
Source File: AuditLogToSyslogSetup.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void removeResource(ManagementClient managementClient, PathAddress address) throws Exception { PathElement element = address.getLastElement(); PathAddress parentAddress = address.subAddress(0, address.size() - 1); ModelNode op = Util.createOperation(READ_CHILDREN_NAMES_OPERATION, parentAddress); op.get(CHILD_TYPE).set(element.getKey()); ModelNode result = managementClient.getControllerClient().execute(op); if (result.hasDefined("result") && result.get("result").asList().contains(new ModelNode(element.getValue()))) { // It exists so remove it op = Util.createRemoveOperation(address); op.get(OPERATION_HEADERS, ROLLBACK_ON_RUNTIME_FAILURE).set(false); op.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true); CoreUtils.applyUpdate(op, managementClient.getControllerClient()); } }
Example 8
Source File: DomainTestUtils.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Check if a path address exists. * * @param address the path address * @param client the controller client * @return whether the child exists or not * @throws IOException * @throws MgmtOperationException */ public static boolean exists(PathAddress address, ModelControllerClient client) throws IOException, MgmtOperationException { final PathElement element = address.getLastElement(); final PathAddress subAddress = address.subAddress(0, address.size() -1); final boolean checkType = element.isWildcard(); final ModelNode e; final ModelNode operation; if(checkType) { e = new ModelNode().set(element.getKey()); operation = createOperation(READ_CHILDREN_TYPES_OPERATION, subAddress); } else { e = new ModelNode().set(element.getValue()); operation = createOperation(READ_CHILDREN_NAMES_OPERATION, subAddress); operation.get(CHILD_TYPE).set(element.getKey()); } try { final ModelNode result = executeForResult(operation, client); return result.asList().contains(e); } catch (MgmtOperationException ex) { if(! checkType) { final String failureDescription = ex.getResult().get(FAILURE_DESCRIPTION).asString(); if(failureDescription.contains("WFLYCTL0202") && failureDescription.contains(element.getKey())) { return false; } } throw ex; } }
Example 9
Source File: SyslogAuditLogProtocolResourceDefinition.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void checkNoOtherProtocol(OperationContext context, ModelNode operation) throws OperationFailedException { PathAddress opAddr = PathAddress.pathAddress(operation.require(OP_ADDR)); PathAddress addr = opAddr.subAddress(0, opAddr.size() - 1); Resource resource = context.readResourceFromRoot(addr); Set<ResourceEntry> existing = resource.getChildren(PROTOCOL); if (existing.size() > 1) { for (ResourceEntry entry : existing) { PathElement mine = addr.getLastElement(); if (!entry.getPathElement().equals(mine)) { throw DomainManagementLogger.ROOT_LOGGER.sysLogProtocolAlreadyConfigured(addr.append(mine)); } } } }
Example 10
Source File: StoppedServerResource.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void readResourceServerConfig(OperationContext context) { final PathAddress address = context.getCurrentAddress(); final String hostName = address.getElement(0).getValue(); final PathElement element = address.getLastElement(); final String serverName = element.getValue(); final ModelNode addr = new ModelNode(); addr.add(HOST, hostName); addr.add(SERVER_CONFIG, serverName); context.readResourceFromRoot(PathAddress.pathAddress(addr), false); }
Example 11
Source File: ChainedTransformingDescription.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void copy(Resource src, Resource dest, PathAddress address) { PathAddress parentAddress = address.size() > 1 ? address.subAddress(0, address.size() - 1) : PathAddress.EMPTY_ADDRESS; PathElement childElement = address.getLastElement(); Resource source = src.navigate(parentAddress); Resource destination = dest.navigate(parentAddress); Resource sourceChild = source.getChild(childElement); if (sourceChild != null) { Resource destChild = Resource.Factory.create(); destination.registerChild(childElement, destChild); copy(sourceChild, destChild); } //copy(src, dest); }
Example 12
Source File: ElementProviderAttributeReadHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected void execute(final OperationContext context, final ModelNode operation, final InstalledIdentity installedIdentity) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)); final PathElement element = address.getLastElement(); final String name = element.getValue(); PatchableTarget target = getProvider(name, installedIdentity); final ModelNode result = context.getResult(); handle(result, target); context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); }
Example 13
Source File: SubsystemTestDelegate.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void removeIgnoredChildren(final Collection<PathAddress> ignoredChildAddresses, final Collection<PathAddress> addresses) { // Remove all known ignored children addresses.removeAll(ignoredChildAddresses); // Checked for wildcards removals for (PathAddress ignoredChildAddress : ignoredChildAddresses) { final PathElement lastIgnoredElement = ignoredChildAddress.getLastElement(); if (lastIgnoredElement.isWildcard()) { // Check each address for (final Iterator<PathAddress> iterator = addresses.iterator(); iterator.hasNext(); ) { final PathAddress childAddress = iterator.next(); if (childAddress.size() == ignoredChildAddress.size()) { // Check the last element key for a match if (lastIgnoredElement.getKey().equals(childAddress.getLastElement().getKey())) { boolean match = true; // Check for matches on previous elements for (int i = 0; i < ignoredChildAddress.size() - 1; i++) { final PathElement e1 = ignoredChildAddress.getElement(i); final PathElement e2 = childAddress.getElement(i); if (!e1.equals(e2)) { match = false; break; } } if (match) { iterator.remove(); } } } } } } }
Example 14
Source File: LoggingResource.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public boolean accepts(final PathAddress address, final Resource resource) { final PathElement last = address.getLastElement(); return last == null || FILE_RESOURCE_NAMES.contains(last.getKey()); }
Example 15
Source File: AddNameFromAddressResourceTransformer.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private void transformResourceInternal(final PathAddress address, final Resource resource) throws OperationFailedException { final PathElement element = address.getLastElement(); resource.getModel().get(NAME).set(element.getValue()); }
Example 16
Source File: AttributeConverter.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void convertAttribute(PathAddress address, String name, ModelNode attributeValue, TransformationContext context) { PathElement element = address.getLastElement(); attributeValue.set(element.getValue()); }