Java Code Examples for org.jboss.as.controller.operations.common.Util#getNameFromAddress()

The following examples show how to use org.jboss.as.controller.operations.common.Util#getNameFromAddress() . 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: ThreadPoolMetricsHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected ServiceController<?> getService(final OperationContext context, final ModelNode operation)
        throws OperationFailedException {
    final String name = Util.getNameFromAddress(operation.require(OP_ADDR));
    ServiceName serviceName = null;
    ServiceController<?> controller = null;
    if(capability != null) {
        serviceName = capability.getCapabilityServiceName(context.getCurrentAddress());
        controller = context.getServiceRegistry(false).getService(serviceName);
        if(controller != null) {
            return controller;
        }
    }
    if (serviceNameBase != null) {
        serviceName = serviceNameBase.append(name);
        controller = context.getServiceRegistry(false).getService(serviceName);
    }
    if (controller == null) {
        throw ThreadsLogger.ROOT_LOGGER.threadPoolServiceNotFoundForMetrics(serviceName);
    }
    return controller;
}
 
Example 2
Source File: JsonAuditLogFormatterResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void performRemove(OperationContext context, ModelNode operation, ModelNode model)
        throws OperationFailedException {
    final String name = Util.getNameFromAddress(operation.require(OP_ADDR));
    final Resource auditLog = context.readResourceFromRoot(PathAddress.pathAddress(CoreManagementResourceDefinition.PATH_ELEMENT, AccessAuditResourceDefinition.PATH_ELEMENT));
    checkFormatterNotReferenced(name, auditLog, HANDLER_TYPES);
    super.performRemove(context, operation, model);
}
 
Example 3
Source File: ServerUtil.java    From keycloak with Apache License 2.0 5 votes vote down vote up
static String getDeploymentName(ModelNode operation) {
    String deploymentName = Util.getNameFromAddress(operation.get(ADDRESS));
    if (!deploymentName.toLowerCase().endsWith(".war")) {
        deploymentName += ".war";
    }

    return deploymentName;
}
 
Example 4
Source File: ThreadFactoryWriteAttributeHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected ServiceController<?> getService(final OperationContext context, final ModelNode model) throws OperationFailedException {
    final String name = Util.getNameFromAddress(model.require(OP_ADDR));
    final ServiceName serviceName = ThreadsServices.threadFactoryName(name);
    ServiceController<?> controller = context.getServiceRegistry(true).getService(serviceName);
    if(controller == null) {
        throw ThreadsLogger.ROOT_LOGGER.threadFactoryServiceNotFound(serviceName);
    }
    return controller;
}
 
Example 5
Source File: SyslogAuditLogHandlerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void recoverServices(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    auditLogger.getUpdater().rollbackChanges();
    String name = Util.getNameFromAddress(operation.require(OP_ADDR));
    final Resource handlerResource = context.readResourceFromRoot(getAffectedHandlerAddress(context));
    SyslogAuditLogHandlerService.installService(context, SYSLOG_AUDIT_HANDLER.append(name), handlerResource);
}
 
Example 6
Source File: SyslogAuditLogHandlerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static SyslogAuditLogHandler createHandler(final PathManagerService pathManager,
                                           final OperationContext context,
                                           final EnvironmentNameReader environmentReader) throws OperationFailedException {
    final PathAddress pathAddress = getAffectedHandlerAddress(context);
    final String name = Util.getNameFromAddress(pathAddress);
    final Resource handlerResource = context.readResourceFromRoot(pathAddress);
    return createHandler(pathManager, context, name, handlerResource, environmentReader);
}
 
Example 7
Source File: AuditLogHandlerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    String attr = operation.require(ModelDescriptionConstants.NAME).asString();
    String handlerName = Util.getNameFromAddress(operation.require(OP_ADDR));
    if (attr.equals(FAILURE_COUNT.getName())) {
        context.getResult().set(auditLogger.getHandlerFailureCount(handlerName));
    } else if (attr.equals(DISABLED_DUE_TO_FAILURE.getName())) {
        context.getResult().set(auditLogger.getHandlerDisabledDueToFailure(handlerName));
    }
}
 
Example 8
Source File: PeriodicRotatingFileAuditLogHandlerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static PeriodicRotatingFileAuditLogHandler createPeriodicRotatingFileAuditLogHandler(final PathManagerService pathManager,
                                                                                             final OperationContext context, final ModelNode operation) throws OperationFailedException {
    final String name = Util.getNameFromAddress(operation.require(OP_ADDR));
    final ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();
    final String relativeTo = model.hasDefined(RELATIVE_TO.getName()) ? RELATIVE_TO.resolveModelAttribute(context, model).asString() : null;
    final String path = PATH.resolveModelAttribute(context, model).asString();
    final String formatterName = FORMATTER.resolveModelAttribute(context, model).asString();
    final int maxFailureCount = MAX_FAILURE_COUNT.resolveModelAttribute(context, model).asInt();
    final String suffix = SUFFIX.resolveModelAttribute(context, model).asString();
    return new PeriodicRotatingFileAuditLogHandler(name, formatterName, maxFailureCount, pathManager, path, relativeTo, suffix, /*default timeZone*/null);
}
 
Example 9
Source File: SyslogAuditLogProtocolResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    PathAddress handlerAddress = SyslogAuditLogHandlerResourceDefinition.getAffectedHandlerAddress(context);
    try {
        Resource handleResource = context.readResourceFromRoot(handlerAddress);
        String name = Util.getNameFromAddress(handlerAddress);
        auditLogger.getUpdater().updateHandler(SyslogAuditLogHandlerResourceDefinition.createHandler(pathManager, context, name, handleResource, environmentReader));
    } catch (Resource.NoSuchResourceException ignored) {
        // WFCORE-810 handler resource has been removed in this same op, so we do nothing
    }
}
 
Example 10
Source File: JsonAuditLogFormatterResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static JsonAuditLogItemFormatter createFormatter(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    return new JsonAuditLogItemFormatter(
            Util.getNameFromAddress(operation.require(OP_ADDR)),
            INCLUDE_DATE.resolveModelAttribute(context, model).asBoolean(),
            DATE_SEPARATOR.resolveModelAttribute(context, model).asString(),
            DATE_FORMAT.resolveModelAttribute(context, model).asString(),
            COMPACT.resolveModelAttribute(context, model).asBoolean(),
            ESCAPE_NEW_LINE.resolveModelAttribute(context, model).asBoolean(),
            ESCAPE_CONTROL_CHARACTERS.resolveModelAttribute(context, model).asBoolean());
}
 
Example 11
Source File: InMemoryAuditLogHandlerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<Void> handbackHolder) throws OperationFailedException {
    if (MAX_HISTORY.equals(attributeName)) {
       final String name = Util.getNameFromAddress(operation.require(OP_ADDR));
       auditLogger.updateInMemoryHandlerMaxHistory(name, resolvedValue.asInt());
   }
   return false;
}
 
Example 12
Source File: InMemoryAuditLogHandlerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Void handback) throws OperationFailedException {
    if (MAX_HISTORY.equals(attributeName)) {
        final String name = Util.getNameFromAddress(operation.require(OP_ADDR));
        auditLogger.updateInMemoryHandlerMaxHistory(name, valueToRevert.asInt());
    }
}
 
Example 13
Source File: InMemoryAuditLogHandlerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    final String name = Util.getNameFromAddress(operation.require(OP_ADDR));
    ModelNode result = context.getResult().setEmptyList();
    List<ModelNode> items = this.auditLogger.listLastEntries(name);
    for (int i = (items.size() - 1); i >= 0; i--) {
        ModelNode entry = items.get(i);
        ModelNode configurationChange = entry.clone();
        result.add(configurationChange);
    }
}
 
Example 14
Source File: FileAuditLogHandlerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static FileAuditLogHandler createFileAuditLogHandler(final PathManagerService pathManager,
                                                             final OperationContext context, final ModelNode operation) throws OperationFailedException {
    final String name = Util.getNameFromAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
    final ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();
    final String relativeTo = model.hasDefined(RELATIVE_TO.getName()) ? RELATIVE_TO.resolveModelAttribute(context, model).asString() : null;
    final String path = PATH.resolveModelAttribute(context, model).asString();
    final String formatterName = FORMATTER.resolveModelAttribute(context, model).asString();
    final int maxFailureCount = MAX_FAILURE_COUNT.resolveModelAttribute(context, model).asInt();
    final boolean rotateAtStartup = ROTATE_AT_STARTUP.resolveModelAttribute(context, model).asBoolean();
    return new FileAuditLogHandler(name, formatterName, maxFailureCount, pathManager, path, relativeTo, rotateAtStartup);
}
 
Example 15
Source File: SizeRotatingFileAuditLogHandlerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static SizeRotatingFileAuditLogHandler createSizeRotatingFileAuditLogHandler(final PathManagerService pathManager,
                                           final OperationContext context, final ModelNode operation) throws OperationFailedException {
    final String name = Util.getNameFromAddress(operation.require(OP_ADDR));
    final ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();
    final String relativeTo = model.hasDefined(RELATIVE_TO.getName()) ? RELATIVE_TO.resolveModelAttribute(context, model).asString() : null;
    final String path = PATH.resolveModelAttribute(context, model).asString();
    final String formatterName = FORMATTER.resolveModelAttribute(context, model).asString();
    final int maxFailureCount = MAX_FAILURE_COUNT.resolveModelAttribute(context, model).asInt();
    final long rotateSize = SizeValidator.parseSize(ROTATE_SIZE.resolveModelAttribute(context, model));
    final int maxBackupIndex = MAX_BACKUP_INDEX.resolveModelAttribute(context, model).asInt();
    return new SizeRotatingFileAuditLogHandler(name, formatterName, maxFailureCount, pathManager, path, relativeTo, rotateSize, maxBackupIndex);
}
 
Example 16
Source File: SyslogAuditLogHandlerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    String name = Util.getNameFromAddress(operation.require(OP_ADDR));
    auditLogger.getUpdater().removeHandler(name);
    context.removeService(SYSLOG_AUDIT_HANDLER.append(name));
}
 
Example 17
Source File: InMemoryAuditLogHandlerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected InMemoryAuditLogHander createHandler(final OperationContext context, final ModelNode operation) throws OperationFailedException {
    final String name = Util.getNameFromAddress(operation.require(OP_ADDR));
    final int maxHistory = MAX_OPERATION_COUNT.resolveModelAttribute(context, operation).asInt();
    return new InMemoryAuditLogHander(name, maxHistory);
}