예제 #1
0
 private ManagedServer createManagedServer(final String serverName, final byte[] authKey) {
   final String hostControllerName = domainController.getLocalHostInfo().getLocalHostName();
   // final ManagedServerBootConfiguration configuration = combiner.createConfiguration();
   final Map<PathAddress, ModelVersion> subsystems =
       TransformerRegistry.resolveVersions(extensionRegistry);
   final ModelVersion modelVersion =
       ModelVersion.create(
           Version.MANAGEMENT_MAJOR_VERSION,
           Version.MANAGEMENT_MINOR_VERSION,
           Version.MANAGEMENT_MICRO_VERSION);
   // We don't need any transformation between host and server
   final TransformationTarget target =
       TransformationTargetImpl.create(
           extensionRegistry.getTransformerRegistry(),
           modelVersion,
           subsystems,
           null,
           TransformationTarget.TransformationTargetType.SERVER,
           null);
   return new ManagedServer(
       hostControllerName,
       serverName,
       authKey,
       processControllerClient,
       managementAddress,
       target);
 }
  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);
            }
          }
        });
  }