@Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    ModelNode model = context.createResource(PathAddress.EMPTY_ADDRESS).getModel();
    SecurityRealmResourceDefinition.MAP_GROUPS_TO_ROLES.validateAndSet(operation, model);

    // Add a step validating that we have the correct authentication and authorization child
    // resources
    ModelNode validationOp = AuthenticationValidatingHandler.createOperation(operation);
    context.addStep(
        validationOp, AuthenticationValidatingHandler.INSTANCE, OperationContext.Stage.MODEL);
    validationOp = AuthorizationValidatingHandler.createOperation(operation);
    context.addStep(
        validationOp, AuthorizationValidatingHandler.INSTANCE, OperationContext.Stage.MODEL);

    context.addStep(
        new OperationStepHandler() {
          @Override
          public void execute(OperationContext context, ModelNode operation)
              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
            context.addStep(ServiceInstallStepHandler.INSTANCE, OperationContext.Stage.RUNTIME);
            context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
          }
        },
        OperationContext.Stage.RUNTIME);

    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
  }
示例#2
0
        @Override
        public void execute(final OperationContext context, final ModelNode operation)
            throws OperationFailedException {
          final Resource resource = context.createResource(PathAddress.EMPTY_ADDRESS);
          final ModelNode model = resource.getModel();
          final String path =
              PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement().getValue();

          for (AttributeDefinition attribute : getAttributes(path)) {
            attribute.validateAndSet(operation, model);
          }
          reloadRequiredStep(context);
          context.stepCompleted();
        }
示例#3
0
  @Override
  public void execute(final OperationContext context, final ModelNode operation)
      throws OperationFailedException {

    // read /subsystem=jgroups/stack=* for update
    final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
    final ModelNode subModel = resource.getModel();

    // validate the protocol type to be added
    ModelNode type = ProtocolResource.TYPE.validateOperation(operation);
    PathElement protocolRelativePath = PathElement.pathElement(ModelKeys.PROTOCOL, type.asString());

    // if child resource already exists, throw OFE
    if (resource.hasChild(protocolRelativePath)) {
      throw JGroupsMessages.MESSAGES.protocolAlreadyDefined(protocolRelativePath.toString());
    }

    // now get the created model
    Resource childResource = context.createResource(PathAddress.pathAddress(protocolRelativePath));
    final ModelNode protocol = childResource.getModel();

    // Process attributes
    for (final AttributeDefinition attribute : attributes) {
      // we use PROPERTIES only to allow the user to pass in a list of properties on store add
      // commands
      // don't copy these into the model
      if (attribute.getName().equals(ModelKeys.PROPERTIES)) continue;

      attribute.validateAndSet(operation, protocol);
    }

    // get the current list of protocol names and add the new protocol
    // this list is used to maintain order
    ModelNode protocols = subModel.get(ModelKeys.PROTOCOLS);
    if (!protocols.isDefined()) {
      protocols.setEmptyList();
    }
    protocols.add(type);

    // Process type specific properties if required
    process(subModel, operation);

    // The protocol parameters  <property name=>value</property>
    if (operation.hasDefined(ModelKeys.PROPERTIES)) {
      for (Property property : operation.get(ModelKeys.PROPERTIES).asPropertyList()) {
        // create a new property=name resource
        final Resource param =
            context.createResource(
                PathAddress.pathAddress(
                    protocolRelativePath,
                    PathElement.pathElement(ModelKeys.PROPERTY, property.getName())));
        final ModelNode value = property.getValue();
        if (!value.isDefined()) {
          throw JGroupsMessages.MESSAGES.propertyNotDefined(
              property.getName(), protocolRelativePath.toString());
        }
        // set the value of the property
        param.getModel().get(ModelDescriptionConstants.VALUE).set(value);
      }
    }
    // This needs a reload
    reloadRequiredStep(context);
    context.completeStep();
  }
  /** {@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();
              }
            }
          }
        });
  }