예제 #1
0
  /**
   * Register the transformers for transforming from 1.4.0 to 1.3.0 management api versions, in
   * which: - attributes INDEXING_PROPERTIES, SEGMENTS were added in 1.4 - attribute VIRTUAL_NODES
   * was deprecated in 1.4 - expression support was added to most attributes in 1.4, except for
   * CLUSTER, DEFAULT_CACHE and MODE for which it was already enabled in 1.3
   *
   * <p>Chaining of transformers is used in cases where two transformers are required for the same
   * operation.
   *
   * @param subsystem the subsystems registration
   */
  private static void registerTransformers(final SubsystemRegistration subsystem) {

    // define the resource and operation transformers
    final InfinispanOperationTransformer_1_3 removeSelectedCacheAttributes =
        new InfinispanOperationTransformer_1_3();

    final RejectExpressionValuesTransformer cacheContainerReject =
        new RejectExpressionValuesTransformer(
            InfinispanRejectedExpressions_1_3.REJECT_CONTAINER_ATTRIBUTES);
    final RejectExpressionValuesTransformer transportReject =
        new RejectExpressionValuesTransformer(
            InfinispanRejectedExpressions_1_3.REJECT_TRANSPORT_ATTRIBUTES);
    final RejectExpressionValuesTransformer cacheReject =
        new RejectExpressionValuesTransformer(
            InfinispanRejectedExpressions_1_3.REJECT_CACHE_ATTRIBUTES);
    final ChainedOperationTransformer chained =
        new ChainedOperationTransformer(removeSelectedCacheAttributes, cacheReject);

    // Register the model transformers
    TransformersSubRegistration registration =
        subsystem.registerModelTransformers(
            ModelVersion.create(1, 3), new InfinispanSubsystemTransformer_1_3());
    TransformersSubRegistration containerRegistration =
        registration.registerSubResource(
            CacheContainerResource.CONTAINER_PATH, (OperationTransformer) cacheContainerReject);
    containerRegistration.registerSubResource(
        TransportResource.TRANSPORT_PATH, (OperationTransformer) transportReject);

    PathElement[] cachePaths = {
      LocalCacheResource.LOCAL_CACHE_PATH,
      InvalidationCacheResource.INVALIDATION_CACHE_PATH,
      ReplicatedCacheResource.REPLICATED_CACHE_PATH,
      DistributedCacheResource.DISTRIBUTED_CACHE_PATH
    };
    for (int i = 0; i < cachePaths.length; i++) {
      // register chained operation transformers for cache ADD operations where we need to remove
      // and reject
      TransformersSubRegistration cacheRegistration =
          containerRegistration.registerSubResource(cachePaths[i], (OperationTransformer) chained);
      registerCacheChildrenTransformers(cacheRegistration);
    }
  }
예제 #2
0
  private static void registerCacheChildrenTransformers(TransformersSubRegistration cacheReg) {

    final RejectExpressionValuesTransformer childReject =
        new RejectExpressionValuesTransformer(
            InfinispanRejectedExpressions_1_3.REJECT_CHILD_ATTRIBUTES);

    PathElement[] childPaths = {
      LockingResource.LOCKING_PATH,
      TransactionResource.TRANSACTION_PATH,
      ExpirationResource.EXPIRATION_PATH,
      EvictionResource.EVICTION_PATH,
      StateTransferResource.STATE_TRANSFER_PATH
    };

    for (int i = 0; i < childPaths.length; i++) {
      // reject expressions on operations in children
      cacheReg.registerSubResource(childPaths[i], (OperationTransformer) childReject);
    }

    final RejectExpressionValuesTransformer storeReject =
        new RejectExpressionValuesTransformer(
            InfinispanRejectedExpressions_1_3.REJECT_STORE_ATTRIBUTES);
    PathElement[] storePaths = {
      StoreResource.STORE_PATH,
      FileStoreResource.FILE_STORE_PATH,
      StringKeyedJDBCStoreResource.STRING_KEYED_JDBC_STORE_PATH,
      BinaryKeyedJDBCStoreResource.BINARY_KEYED_JDBC_STORE_PATH,
      MixedKeyedJDBCStoreResource.MIXED_KEYED_JDBC_STORE_PATH,
      RemoteStoreResource.REMOTE_STORE_PATH
    };

    for (int i = 0; i < storePaths.length; i++) {
      // reject expressions on operations on stores and store properties
      TransformersSubRegistration storeReg =
          cacheReg.registerSubResource(storePaths[i], (OperationTransformer) storeReject);
      storeReg.registerSubResource(
          StoreWriteBehindResource.STORE_WRITE_BEHIND_PATH, (OperationTransformer) storeReject);
      storeReg.registerSubResource(
          StorePropertyResource.STORE_PROPERTY_PATH, (OperationTransformer) storeReject);
    }
  }
  static void registerTransformers120(
      TransformerRegistry registry, TransformersSubRegistration parent) {
    registry.registerSubsystemTransformers(
        JSF_SUBSYSTEM,
        IGNORED_SUBSYSTEMS,
        new ResourceTransformer() {
          @Override
          public void transformResource(
              ResourceTransformationContext context, PathAddress address, Resource resource)
              throws OperationFailedException {
            ModelNode model = resource.getModel();
            if (model.hasDefined(SLOT_ATTRIBUTE_NAME)) {
              ModelNode slot = model.get(SLOT_ATTRIBUTE_NAME);
              if (!SLOT_DEFAULT_VALUE.equals(slot.asString())) {
                context
                    .getLogger()
                    .logWarning(
                        address,
                        SLOT_ATTRIBUTE_NAME,
                        MESSAGES.invalidJSFSlotValue(slot.asString()));
              }
            }
            Set<String> attributes = new HashSet<String>();
            for (Property prop : resource.getModel().asPropertyList()) {
              attributes.add(prop.getName());
            }
            attributes.remove(SLOT_ATTRIBUTE_NAME);
            if (!attributes.isEmpty()) {
              context
                  .getLogger()
                  .logWarning(
                      address,
                      ControllerMessages.MESSAGES.attributesAreNotUnderstoodAndMustBeIgnored(),
                      attributes);
            }
          }
        });

    TransformersSubRegistration jsfSubsystem =
        parent.registerSubResource(PathElement.pathElement(SUBSYSTEM, JSF_SUBSYSTEM));
    jsfSubsystem.registerOperationTransformer(
        ADD,
        new OperationTransformer() {

          @Override
          public TransformedOperation transformOperation(
              TransformationContext context, PathAddress address, ModelNode operation)
              throws OperationFailedException {
            if (operation.hasDefined(SLOT_ATTRIBUTE_NAME)) {
              ModelNode slot = operation.get(SLOT_ATTRIBUTE_NAME);
              if (!SLOT_DEFAULT_VALUE.equals(slot.asString())) {
                return new TransformedOperation(
                    operation,
                    new RejectionWithFailurePolicy(MESSAGES.invalidJSFSlotValue(slot.asString())),
                    OperationResultTransformer.ORIGINAL_RESULT);
              }
            }
            Set<String> attributes = new HashSet<String>();
            for (Property prop : operation.asPropertyList()) {
              attributes.add(prop.getName());
            }
            attributes.remove(SLOT_ATTRIBUTE_NAME);
            if (!attributes.isEmpty()) {
              return new TransformedOperation(
                  operation,
                  new RejectionWithFailurePolicy(
                      MESSAGES.unknownAttributesFromSubsystemVersion(
                          ADD,
                          JSF_SUBSYSTEM,
                          context.getTarget().getSubsystemVersion(JSF_SUBSYSTEM),
                          attributes)),
                  OperationResultTransformer.ORIGINAL_RESULT);
            }
            return DISCARD.transformOperation(context, address, operation);
          }
        });

    jsfSubsystem.registerOperationTransformer(
        WRITE_ATTRIBUTE_OPERATION,
        new OperationTransformer() {
          @Override
          public TransformedOperation transformOperation(
              TransformationContext context, PathAddress address, ModelNode operation)
              throws OperationFailedException {
            final String name = operation.require(NAME).asString();
            final ModelNode value = operation.get(ModelDescriptionConstants.VALUE);
            if (SLOT_ATTRIBUTE_NAME.equals(name)) {
              if (value.isDefined() && value.equals(SLOT_DEFAULT_VALUE)) {
                return DISCARD.transformOperation(context, address, operation);
              } else {
                return new TransformedOperation(
                    operation,
                    new RejectionWithFailurePolicy(MESSAGES.invalidJSFSlotValue(value.asString())),
                    OperationResultTransformer.ORIGINAL_RESULT);
              }
            }
            // reject the operation for any other attribute
            return new TransformedOperation(
                operation,
                new RejectionWithFailurePolicy(
                    MESSAGES.unknownAttributesFromSubsystemVersion(
                        ADD,
                        JSF_SUBSYSTEM,
                        context.getTarget().getSubsystemVersion(JSF_SUBSYSTEM),
                        Arrays.asList(name))),
                OperationResultTransformer.ORIGINAL_RESULT);
          }
        });
    jsfSubsystem.registerOperationTransformer(
        UNDEFINE_ATTRIBUTE_OPERATION,
        new OperationTransformer() {
          @Override
          public TransformedOperation transformOperation(
              TransformationContext context, PathAddress address, ModelNode operation)
              throws OperationFailedException {
            String attributeName = operation.require(NAME).asString();
            if (!SLOT_ATTRIBUTE_NAME.equals(attributeName)) {
              return DEFAULT.transformOperation(context, address, operation);
            } else {
              context
                  .getLogger()
                  .logWarning(
                      address,
                      ControllerMessages.MESSAGES.attributesAreNotUnderstoodAndMustBeIgnored(),
                      attributeName);
              return DISCARD.transformOperation(context, address, operation);
            }
          }
        });
  }