コード例 #1
0
 @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());
   }
 }
コード例 #2
0
  /** {@inheritDoc */
  public void execute(final OperationContext context, final ModelNode operation)
      throws OperationFailedException {

    final Resource resource = context.createResource(PathAddress.EMPTY_ADDRESS);
    final ModelNode model = resource.getModel();

    for (AttributeDefinition attr : ServerGroupResourceDefinition.ADD_ATTRIBUTES) {
      attr.validateAndSet(operation, model);
    }

    // Validate the profile reference.

    // Future proofing: We resolve the profile in Stage.MODEL even though system properties may not
    // be available yet
    // solely because currently the attribute doesn't support expressions. In the future if system
    // properties
    // can safely be resolved in stage model, this profile attribute can be changed and this will
    // still work.
    boolean reloadRequired = false;
    final String profile = PROFILE.resolveModelAttribute(context, model).asString();
    try {
      context.readResourceFromRoot(
          PathAddress.pathAddress(PathElement.pathElement(PROFILE.getName(), profile)));
    } catch (Exception e) {
      if (master) {
        throw DomainControllerLogger.ROOT_LOGGER.noProfileCalled(profile);
      } else {
        // We are a slave HC and we don't have the socket-binding-group required, so put the slave
        // into reload-required
        reloadRequired = true;
        context.reloadRequired();
      }
    }

    final String socketBindingGroup;
    if (operation.hasDefined(SOCKET_BINDING_GROUP.getName())) {
      socketBindingGroup = SOCKET_BINDING_GROUP.resolveModelAttribute(context, model).asString();
      try {
        context.readResourceFromRoot(
            PathAddress.pathAddress(
                PathElement.pathElement(SOCKET_BINDING_GROUP.getName(), socketBindingGroup)));
      } catch (NoSuchElementException e) {
        if (master) {
          throw new OperationFailedException(
              DomainControllerLogger.ROOT_LOGGER.unknown(
                  SOCKET_BINDING_GROUP.getName(), socketBindingGroup));
        } else {
          // We are a slave HC and we don't have the socket-binding-group required, so put the slave
          // into reload-required
          reloadRequired = true;
          context.reloadRequired();
        }
      }
    } else {
      socketBindingGroup = null;
    }

    final boolean revertReloadRequiredOnRollback = reloadRequired;
    context.completeStep(
        new OperationContext.ResultHandler() {
          @Override
          public void handleResult(
              ResultAction resultAction, OperationContext context, ModelNode operation) {
            if (resultAction == ResultAction.ROLLBACK) {
              if (revertReloadRequiredOnRollback) {
                context.revertReloadRequired();
              }
            }
          }
        });
  }