Java Code Examples for org.jboss.as.controller.OperationContext#getProcessType()

The following examples show how to use org.jboss.as.controller.OperationContext#getProcessType() . 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: ManagedDeploymentReadContentHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (context.getProcessType() == ProcessType.SELF_CONTAINED) {
        throw ServerLogger.ROOT_LOGGER.cannotReadContentFromSelfContainedServer();
    }
    final Resource deploymentResource = context.readResource(PathAddress.EMPTY_ADDRESS);
    ModelNode contentItemNode = getContentItem(deploymentResource);
    // Validate this op is available
    if (!isManaged(contentItemNode)) {
        throw ServerLogger.ROOT_LOGGER.cannotReadContentFromUnmanagedDeployment();
    }
    final byte[] deploymentHash = CONTENT_HASH.resolveModelAttribute(context, contentItemNode).asBytes();
    final ModelNode contentPath = CONTENT_PATH.resolveModelAttribute(context, operation);
    final String path = contentPath.isDefined() ? contentPath.asString() : "";
    try {
        TypedInputStream inputStream = contentRepository.readContent(deploymentHash, path);
        String uuid = context.attachResultStream(inputStream.getContentType(), inputStream);
        context.getResult().get(UUID).set(uuid);
    } catch (ExplodedContentException ex) {
        throw createFailureException(ex.toString());
    }
}
 
Example 2
Source File: ReadOperationDescriptionHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {

    String operationName = NAME.resolveModelAttribute(context, operation).asString();
    boolean accessControl = ACCESS_CONTROL.resolveModelAttribute(context, operation).asBoolean();

    final DescribedOp describedOp = getDescribedOp(context, operationName, operation, !accessControl);
    if (describedOp == null || (context.getProcessType() == ProcessType.DOMAIN_SERVER &&
            !(describedOp.flags.contains(OperationEntry.Flag.RUNTIME_ONLY) || describedOp.flags.contains(OperationEntry.Flag.READ_ONLY)))) {
        throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.operationNotRegistered(operationName, context.getCurrentAddress()));
    } else {
        ModelNode result = describedOp.getDescription();

        if (accessControl) {
            final PathAddress address = context.getCurrentAddress();
            ModelNode operationToCheck = Util.createOperation(operationName, address);
            operationToCheck.get(OPERATION_HEADERS).set(operation.get(OPERATION_HEADERS));
            AuthorizationResult authorizationResult = context.authorizeOperation(operationToCheck);
            result.get(ACCESS_CONTROL.getName(), EXECUTE).set(authorizationResult.getDecision() == Decision.PERMIT);

        }

        context.getResult().set(result);
    }
}
 
Example 3
Source File: ManagedDeploymentReadContentHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (context.getProcessType() == ProcessType.SELF_CONTAINED) {
        throw DomainControllerLogger.ROOT_LOGGER.cannotReadContentFromSelfContainedServer();
    }
    final Resource deploymentResource = context.readResource(PathAddress.EMPTY_ADDRESS);
    ModelNode contentItemNode = getContentItem(deploymentResource);
    // Validate this op is available
    if (!isManaged(contentItemNode)) {
        throw DomainControllerLogger.ROOT_LOGGER.cannotReadContentFromUnmanagedDeployment();
    }
    final byte[] deploymentHash = CONTENT_HASH.resolveModelAttribute(context, contentItemNode).asBytes();
    final ModelNode contentPath = CONTENT_PATH.resolveModelAttribute(context, operation);
    final String path = contentPath.isDefined() ? contentPath.asString() : "";
    try {
        TypedInputStream inputStream = contentRepository.readContent(deploymentHash, path);
        String uuid = context.attachResultStream(inputStream.getContentType(), inputStream);
        context.getResult().get(UUID).set(uuid);
    } catch (ExplodedContentException ex) {
        throw new OperationFailedException(ex.getMessage());
    }
}
 
Example 4
Source File: JMXSubsystemAdd.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static void launchServices(OperationContext context, ModelNode model, ManagedAuditLogger auditLoggerInfo,
                           JmxAuthorizer authorizer, Supplier<SecurityIdentity> securityIdentitySupplier, RuntimeHostControllerInfoAccessor hostInfoAccessor) throws OperationFailedException {

    // Add the MBean service
    String resolvedDomain = getDomainName(context, model, CommonAttributes.RESOLVED);
    String expressionsDomain = getDomainName(context, model, CommonAttributes.EXPRESSION);
    boolean legacyWithProperPropertyFormat = false;
    if (model.hasDefined(CommonAttributes.PROPER_PROPERTY_FORMAT)) {
        legacyWithProperPropertyFormat = ExposeModelResourceExpression.DOMAIN_NAME.resolveModelAttribute(context, model).asBoolean();
    }
    boolean coreMBeanSensitivity = JMXSubsystemRootResource.CORE_MBEAN_SENSITIVITY.resolveModelAttribute(context, model).asBoolean();
    final boolean isMasterHc;
    if (context.getProcessType().isHostController()) {
        isMasterHc = hostInfoAccessor.getHostControllerInfo(context).isMasterHc();
    } else {
        isMasterHc = false;
    }
    JmxEffect jmxEffect = null;
    if (context.getProcessType() == ProcessType.DOMAIN_SERVER) {
        ModelNode rootModel = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, false).getModel();
        String hostName = null;
        if(rootModel.hasDefined(HOST)) {
            hostName = rootModel.get(HOST).asString();
        }
        String serverGroup = null;
        if(rootModel.hasDefined(SERVER_GROUP)) {
            serverGroup = rootModel.get(SERVER_GROUP).asString();
        }
        jmxEffect = new JmxEffect(hostName, serverGroup);
    }
    MBeanServerService.addService(context, resolvedDomain, expressionsDomain, legacyWithProperPropertyFormat,
                        coreMBeanSensitivity, auditLoggerInfo, authorizer, securityIdentitySupplier, jmxEffect, context.getProcessType(), isMasterHc);
}
 
Example 5
Source File: ManagedDeploymentBrowseContentHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (context.getProcessType() == ProcessType.SELF_CONTAINED) {
        throw ServerLogger.ROOT_LOGGER.cannotReadContentFromSelfContainedServer();
    }
    final Resource deploymentResource = context.readResource(PathAddress.EMPTY_ADDRESS);
    ModelNode contentItemNode = getContentItem(deploymentResource);
    // Validate this op is available
    if (!isManaged(contentItemNode)) {
        throw ServerLogger.ROOT_LOGGER.cannotReadContentFromUnmanagedDeployment();
    }
    final byte[] deploymentHash = CONTENT_HASH.resolveModelAttribute(context, contentItemNode).asBytes();
    final ModelNode pathNode = DEPLOYMENT_CONTENT_PATH.resolveModelAttribute(context, operation);
    final String path;
    if(pathNode.isDefined()) {
        path = pathNode.asString();
    } else {
        path = "";
    }
    int depth = DEPTH.resolveModelAttribute(context, operation).asInt();
    boolean explodable = ARCHIVE.resolveModelAttribute(context, operation).asBoolean();
    try {
        for (ContentRepositoryElement content : contentRepository.listContent(deploymentHash, path, ContentFilter.Factory.createContentFilter(depth, explodable))) {
            ModelNode contentNode = new ModelNode();
            contentNode.get(PATH).set(content.getPath());
            contentNode.get(DIRECTORY).set(content.isFolder());
            if(!content.isFolder()) {
                contentNode.get(FILE_SIZE).set(content.getSize());
            }
            context.getResult().add(contentNode);
        }
    } catch (ExplodedContentException ex) {
        throw createFailureException(ex.toString());
    }
}
 
Example 6
Source File: ReadOperationNamesHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static boolean isVisible(OperationEntry operationEntry, OperationContext context) {
    Set<OperationEntry.Flag> flags = operationEntry.getFlags();
    return operationEntry.getType() == OperationEntry.EntryType.PUBLIC
            && !flags.contains(OperationEntry.Flag.HIDDEN)
            && (context.getProcessType() != ProcessType.DOMAIN_SERVER || flags.contains(OperationEntry.Flag.RUNTIME_ONLY)
            || flags.contains(OperationEntry.Flag.READ_ONLY));

}
 
Example 7
Source File: RemotingSubsystemAdd.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, Resource resource) throws OperationFailedException {

    // WFCORE-4510 -- the effective endpoint configuration is from the root subsystem resource,
    // not from the placeholder configuration=endpoint child resource.
    ModelNode endpointModel = resource.getModel();
    String workerName = WORKER.resolveModelAttribute(context, endpointModel).asString();

    final OptionMap map = EndpointConfigFactory.populate(context, endpointModel);

    // create endpoint
    final String nodeName = WildFlySecurityManager.getPropertyPrivileged(RemotingExtension.NODE_NAME_PROPERTY, null);

    // In case of a managed server the subsystem endpoint might already be installed {@see DomainServerCommunicationServices}
    if (context.getProcessType() == ProcessType.DOMAIN_SERVER) {
        final ServiceController<?> controller = context.getServiceRegistry(false).getService(RemotingServices.SUBSYSTEM_ENDPOINT);
        if (controller != null) {
            // if installed, just skip the rest
            return;
        }
    }

    final CapabilityServiceBuilder<?> builder = context.getCapabilityServiceTarget().addCapability(REMOTING_ENDPOINT_CAPABILITY);
    final Consumer<Endpoint> endpointConsumer = builder.provides(REMOTING_ENDPOINT_CAPABILITY);
    final Supplier<XnioWorker> workerSupplier = builder.requiresCapability(IO_WORKER_CAPABILITY_NAME, XnioWorker.class, workerName);
    builder.setInstance(new EndpointService(endpointConsumer, workerSupplier, nodeName, EndpointService.EndpointType.SUBSYSTEM, map));
    builder.install();
}
 
Example 8
Source File: ManagedDeploymentBrowseContentHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (context.getProcessType() == ProcessType.SELF_CONTAINED) {
        throw DomainControllerLogger.ROOT_LOGGER.cannotReadContentFromSelfContainedServer();
    }
    final Resource deploymentResource = context.readResource(PathAddress.EMPTY_ADDRESS);
    ModelNode contentItemNode = getContentItem(deploymentResource);
    // Validate this op is available
    if (!isManaged(contentItemNode)) {
        throw DomainControllerLogger.ROOT_LOGGER.cannotReadContentFromUnmanagedDeployment();
    }
    final byte[] deploymentHash = CONTENT_HASH.resolveModelAttribute(context, contentItemNode).asBytes();
    final ModelNode pathNode = DEPLOYMENT_CONTENT_PATH.resolveModelAttribute(context, operation);
    final String path;
    if(pathNode.isDefined()) {
        path = pathNode.asString();
    } else {
        path = "";
    }
    int depth = DEPTH.resolveModelAttribute(context, operation).asInt();
    boolean explodable = ARCHIVE.resolveModelAttribute(context, operation).asBoolean();
    try {
        for (ContentRepositoryElement content : contentRepository.listContent(deploymentHash, path, ContentFilter.Factory.createContentFilter(depth, explodable))) {
            ModelNode contentNode = new ModelNode();
            contentNode.get(PATH).set(content.getPath());
            contentNode.get(DIRECTORY).set(content.isFolder());
            if(!content.isFolder()) {
                contentNode.get(FILE_SIZE).set(content.getSize());
            }
            context.getResult().add(contentNode);
        }
    } catch (ExplodedContentException ex) {
        throw new OperationFailedException(ex.getMessage());
    }
}
 
Example 9
Source File: SecurityRealmAddHandler.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, Resource resource) throws OperationFailedException {
    // Install another RUNTIME handler to actually install the services. This will run after the
    // RUNTIME handler for any child resources. Doing this will ensure that child resource handlers don't
    // see the installed services and can just ignore doing any RUNTIME stage work
    if(!context.isBooting() && context.getProcessType() == ProcessType.EMBEDDED_SERVER && context.getRunningMode() == RunningMode.ADMIN_ONLY) {
        context.reloadRequired();
    } else {
        context.addStep(ServiceInstallStepHandler.INSTANCE, OperationContext.Stage.RUNTIME);
    }
}
 
Example 10
Source File: OpTypesExtension.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    boolean forMe = context.getProcessType() == ProcessType.DOMAIN_SERVER;
    if (!forMe) {
        String targetHost = TARGET_HOST.resolveModelAttribute(context, operation).asStringOrNull();
        if (targetHost != null) {
            Set<String> hosts = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, false).getChildrenNames(HOST);
            String name = hosts.size() > 1 ? "master": hosts.iterator().next();
            forMe = targetHost.equals(name);
        }
    }
    if (forMe) {
        context.addStep((ctx, op) -> ctx.getResult().set(true), OperationContext.Stage.RUNTIME);
    }
}
 
Example 11
Source File: HttpManagementRemoveHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected boolean requiresRuntime(OperationContext context) {
    return (context.getProcessType() != ProcessType.EMBEDDED_HOST_CONTROLLER);
}
 
Example 12
Source File: NativeManagementAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected boolean requiresRuntime(OperationContext context) {
    return super.requiresRuntime(context)
            && (context.getProcessType() != ProcessType.EMBEDDED_HOST_CONTROLLER);
}
 
Example 13
Source File: NativeManagementRemoveHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected boolean requiresRuntime(OperationContext context) {
    return (context.getProcessType() != ProcessType.EMBEDDED_HOST_CONTROLLER);
}
 
Example 14
Source File: HttpManagementAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected boolean requiresRuntime(OperationContext context) {
    return super.requiresRuntime(context)
            && (context.getProcessType() != ProcessType.EMBEDDED_HOST_CONTROLLER);
}
 
Example 15
Source File: LegacyConfigurationChangeResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected boolean requiresRuntime(OperationContext context) {
    return context.getProcessType() != ProcessType.EMBEDDED_HOST_CONTROLLER
            && (context.getProcessType() != ProcessType.EMBEDDED_SERVER
            && context.getRunningMode() != RunningMode.ADMIN_ONLY);
}
 
Example 16
Source File: LegacyConfigurationChangeResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected boolean requiresRuntime(OperationContext context) {
    return context.getProcessType() != ProcessType.EMBEDDED_HOST_CONTROLLER
            && (context.getProcessType() != ProcessType.EMBEDDED_SERVER
            && context.getRunningMode() != RunningMode.ADMIN_ONLY);
}
 
Example 17
Source File: NativeRemotingManagementAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected boolean requiresRuntime(OperationContext context) {
    return context.getProcessType() != ProcessType.EMBEDDED_SERVER || context.getRunningMode() != RunningMode.ADMIN_ONLY;
}
 
Example 18
Source File: NativeManagementAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected boolean requiresRuntime(OperationContext context) {
    return super.requiresRuntime(context)
            && (context.getProcessType() != ProcessType.EMBEDDED_SERVER || context.getRunningMode() != RunningMode.ADMIN_ONLY);
}
 
Example 19
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected void rollbackRuntime(OperationContext context, ModelNode operation, Resource resource) {
    if (!context.isBooting() && context.getProcessType() == ProcessType.EMBEDDED_SERVER && context.getRunningMode() == RunningMode.ADMIN_ONLY) {
        context.revertReloadRequired();
    }
}
 
Example 20
Source File: RemotingConnectorAdd.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected boolean requiresRuntime(OperationContext context) {
   return super.requiresRuntime(context) && (context.getProcessType() != ProcessType.EMBEDDED_HOST_CONTROLLER);
}