Ejemplo n.º 1
0
 /** {@inheritDoc} */
 @Override
 protected void populateModel(ModelNode operation, ModelNode model)
     throws OperationFailedException {
   // log.info("Populating the model");
   model.setEmptyObject();
   model.get(ModelKeys.MAIL_SESSION);
 }
Ejemplo n.º 2
0
 void updateModel(
     final OperationContext context,
     ModelNode model,
     AttributeDefinition attributeDefinition,
     ModelNode attribute)
     throws OperationFailedException {
   attribute.setEmptyObject();
 }
Ejemplo n.º 3
0
 static ModelNode parseSsl(XMLExtendedStreamReader reader) throws XMLStreamException {
   final ModelNode ssl = new ModelNode();
   ssl.setEmptyObject();
   final int count = reader.getAttributeCount();
   for (int i = 0; i < count; i++) {
     requireNoNamespaceAttribute(reader, i);
     final String value = reader.getAttributeValue(i);
     final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
     switch (attribute) {
       case NAME:
         ssl.get(NAME).set(value);
         break;
       case KEY_ALIAS:
         ssl.get(KEY_ALIAS).set(value);
         break;
       case PASSWORD:
         ssl.get(PASSWORD).set(value);
         break;
       case CERTIFICATE_KEY_FILE:
         ssl.get(CERTIFICATE_KEY_FILE).set(value);
         break;
       case CIPHER_SUITE:
         ssl.get(CIPHER_SUITE).set(value);
         break;
       case PROTOCOL:
         ssl.get(PROTOCOL).set(value);
         break;
       case VERIFY_CLIENT:
         ssl.get(VERIFY_CLIENT).set(value);
         break;
       case VERIFY_DEPTH:
         ssl.get(VERIFY_DEPTH).set(Integer.valueOf(value));
         break;
       case CERTIFICATE_FILE:
         ssl.get(CERTIFICATE_FILE).set(value);
         break;
       case CA_CERTIFICATE_FILE:
         ssl.get(CA_CERTIFICATE_FILE).set(value);
         break;
       case CA_REVOCATION_URL:
         ssl.get(CA_REVOCATION_URL).set(value);
         break;
       case SESSION_CACHE_SIZE:
         ssl.get(SESSION_CACHE_SIZE).set(value);
         break;
       case SESSION_TIMEOUT:
         ssl.get(SESSION_TIMEOUT).set(value);
         break;
       default:
         throw unexpectedAttribute(reader, i);
     }
   }
   requireNoContent(reader);
   return ssl;
 }
Ejemplo n.º 4
0
  @Override
  protected void populateModel(ModelNode operation, ModelNode model)
      throws OperationFailedException {

    model.setEmptyObject();

    for (final AttributeDefinition attributeDefinition :
        CommonAttributes.CONNECTOR_SERVICE_ATTRIBUTES) {
      attributeDefinition.validateAndSet(operation, model);
    }
  }
 static ModelNode parseSSL(XMLExtendedStreamReader reader) throws XMLStreamException {
   final ModelNode ssl = new ModelNode();
   ssl.setEmptyObject();
   final int count = reader.getAttributeCount();
   for (int i = 0; i < count; i++) {
     requireNoNamespaceAttribute(reader, i);
     final String value = reader.getAttributeValue(i);
     final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
     switch (attribute) {
       case KEY_ALIAS:
         ssl.get(KEY_ALIAS).set(value);
         break;
       case PASSWORD:
         ssl.get(PASSWORD).set(value);
         break;
       case CERTIFICATE_KEY_FILE:
         ssl.get(CERTIFICATE_KEY_FILE).set(value);
         break;
       case CIPHER_SUITE:
         ssl.get(CIPHER_SUITE).set(value);
         break;
       case PROTOCOL:
         ssl.get(PROTOCOL).set(value);
         break;
       case CA_CERTIFICATE_FILE:
         ssl.get(CA_CERTIFICATE_FILE).set(value);
         break;
       case CA_REVOCATION_URL:
         ssl.get(CA_REVOCATION_URL).set(value);
         break;
       default:
         throw unexpectedAttribute(reader, i);
     }
   }
   ParseUtils.requireNoContent(reader);
   return ssl;
 }
Ejemplo n.º 6
0
 static ModelNode parseHostAccessLog(XMLExtendedStreamReader reader) throws XMLStreamException {
   final ModelNode log = new ModelNode();
   log.setEmptyObject();
   final int count = reader.getAttributeCount();
   for (int i = 0; i < count; i++) {
     requireNoNamespaceAttribute(reader, i);
     final String value = reader.getAttributeValue(i);
     final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
     switch (attribute) {
       case PATTERN:
         log.get(PATTERN).set(value);
         break;
       case RESOLVE_HOSTS:
         log.get(RESOLVE_HOSTS).set(value);
         break;
       case EXTENDED:
         log.get(EXTENDED).set(value);
         break;
       case PREFIX:
         log.get(PREFIX).set(value);
         break;
       case ROTATE:
         log.get(ROTATE).set(value);
         break;
       default:
         throw unexpectedAttribute(reader, i);
     }
   }
   while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
     switch (Namespace.forUri(reader.getNamespaceURI())) {
       case WEB_1_0:
       case WEB_1_1:
         {
           final Element element = Element.forName(reader.getLocalName());
           switch (element) {
             case DIRECTORY:
               final ModelNode directory = new ModelNode();
               final int count2 = reader.getAttributeCount();
               for (int i = 0; i < count2; i++) {
                 requireNoNamespaceAttribute(reader, i);
                 final String value = reader.getAttributeValue(i);
                 final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
                 switch (attribute) {
                   case PATH:
                     directory.get(PATH).set(value);
                     break;
                   case RELATIVE_TO:
                     directory.get(RELATIVE_TO).set(value);
                     break;
                   default:
                     throw unexpectedAttribute(reader, i);
                 }
               }
               requireNoContent(reader);
               log.get(DIRECTORY).set(directory);
               break;
             default:
               throw unexpectedElement(reader);
           }
           break;
         }
       default:
         throw unexpectedElement(reader);
     }
   }
   return log;
 }
Ejemplo n.º 7
0
 static ModelNode parseHostRewrite(XMLExtendedStreamReader reader) throws XMLStreamException {
   final ModelNode rewrite = new ModelNode();
   rewrite.setEmptyObject();
   final int count = reader.getAttributeCount();
   for (int i = 0; i < count; i++) {
     requireNoNamespaceAttribute(reader, i);
     final String value = reader.getAttributeValue(i);
     final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
     switch (attribute) {
       case PATTERN:
         rewrite.get(PATTERN).set(value);
         break;
       case SUBSTITUTION:
         rewrite.get(SUBSTITUTION).set(value);
         break;
       case FLAGS:
         rewrite.get(FLAGS).set(value);
         break;
       default:
         throw unexpectedAttribute(reader, i);
     }
   }
   while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
     switch (Namespace.forUri(reader.getNamespaceURI())) {
       case WEB_1_0:
       case WEB_1_1:
         {
           final Element element = Element.forName(reader.getLocalName());
           switch (element) {
             case CONDITION:
               final ModelNode condition = new ModelNode();
               condition.setEmptyObject();
               final int count2 = reader.getAttributeCount();
               for (int i = 0; i < count2; i++) {
                 requireNoNamespaceAttribute(reader, i);
                 final String value = reader.getAttributeValue(i);
                 final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
                 switch (attribute) {
                   case TEST:
                     condition.get(TEST).set(value);
                     break;
                   case PATTERN:
                     condition.get(PATTERN).set(value);
                     break;
                   case FLAGS:
                     condition.get(FLAGS).set(value);
                     break;
                   default:
                     throw unexpectedAttribute(reader, i);
                 }
               }
               requireNoContent(reader);
               rewrite.get(CONDITION).add(condition);
               break;
             default:
               throw unexpectedElement(reader);
           }
           break;
         }
       default:
         throw unexpectedElement(reader);
     }
   }
   return rewrite;
 }
Ejemplo n.º 8
0
 @Override
 protected void populateModel(ModelNode operation, ModelNode model) {
   model.setEmptyObject();
 }
Ejemplo n.º 9
0
 /** {@inheritDoc} */
 @Override
 protected void populateModel(ModelNode operation, ModelNode model)
     throws OperationFailedException {
   log.info("Populating the model");
   model.setEmptyObject();
 }
Ejemplo n.º 10
0
 @Override
 protected void populateModel(ModelNode operation, ModelNode model)
     throws OperationFailedException {
   validator.validate(operation);
   model.setEmptyObject();
 }
Ejemplo n.º 11
0
    @Override
    public void execute(OperationContext context, ModelNode operation)
        throws OperationFailedException {

      Map<String, ModelNode> sortedAttributes = new TreeMap<String, ModelNode>();
      Map<String, ModelNode> sortedChildren = new TreeMap<String, ModelNode>();
      boolean failed = false;
      for (Map.Entry<String, ModelNode> entry : otherAttributes.entrySet()) {
        ModelNode value = entry.getValue();
        if (!value.has(FAILURE_DESCRIPTION)) {
          sortedAttributes.put(entry.getKey(), value.get(RESULT));
        } else if (!failed && value.hasDefined(FAILURE_DESCRIPTION)) {
          context.getFailureDescription().set(value.get(FAILURE_DESCRIPTION));
          failed = true;
          break;
        }
      }
      if (!failed) {
        for (Map.Entry<PathElement, ModelNode> entry : childResources.entrySet()) {
          PathElement path = entry.getKey();
          ModelNode value = entry.getValue();
          if (!value.has(FAILURE_DESCRIPTION)) {
            ModelNode childTypeNode = sortedChildren.get(path.getKey());
            if (childTypeNode == null) {
              childTypeNode = new ModelNode();
              sortedChildren.put(path.getKey(), childTypeNode);
            }
            childTypeNode.get(path.getValue()).set(value.get(RESULT));
          } else if (!failed && value.hasDefined(FAILURE_DESCRIPTION)) {
            context.getFailureDescription().set(value.get(FAILURE_DESCRIPTION));
            failed = true;
          }
        }
      }
      if (!failed) {
        for (Map.Entry<String, ModelNode> simpleAttribute : directAttributes.entrySet()) {
          sortedAttributes.put(simpleAttribute.getKey(), simpleAttribute.getValue());
        }
        for (Map.Entry<String, ModelNode> directChild : directChildren.entrySet()) {
          sortedChildren.put(directChild.getKey(), directChild.getValue());
        }
        for (Map.Entry<String, ModelNode> metric : metrics.entrySet()) {
          ModelNode value = metric.getValue();
          if (!value.has(FAILURE_DESCRIPTION)) {
            sortedAttributes.put(metric.getKey(), value.get(RESULT));
          }
          // we ignore metric failures
          // TODO how to prevent the metric failure screwing up the overall context?
        }

        final ModelNode result = context.getResult();
        result.setEmptyObject();
        for (Map.Entry<String, ModelNode> entry : sortedAttributes.entrySet()) {
          result.get(entry.getKey()).set(entry.getValue());
        }

        for (Map.Entry<String, ModelNode> entry : sortedChildren.entrySet()) {
          result.get(entry.getKey()).set(entry.getValue());
        }
      }

      context.stepCompleted();
    }
Ejemplo n.º 12
0
  @Override
  void doExecute(OperationContext context, ModelNode operation) throws OperationFailedException {

    validator.validate(operation);

    final String opName = operation.require(OP).asString();
    final ModelNode opAddr = operation.get(OP_ADDR);
    final PathAddress address = PathAddress.pathAddress(opAddr);
    final int recursiveDepth = operation.get(ModelDescriptionConstants.RECURSIVE_DEPTH).asInt(0);
    final boolean recursive =
        recursiveDepth > 0
            ? true
            : operation.get(ModelDescriptionConstants.RECURSIVE).asBoolean(false);
    final boolean queryRuntime =
        operation.get(ModelDescriptionConstants.INCLUDE_RUNTIME).asBoolean(false);
    final boolean proxies = operation.get(ModelDescriptionConstants.PROXIES).asBoolean(false);
    final boolean aliases =
        operation.get(ModelDescriptionConstants.INCLUDE_ALIASES).asBoolean(false);
    final boolean defaults =
        operation.get(ModelDescriptionConstants.INCLUDE_DEFAULTS).asBoolean(true);
    final boolean attributesOnly =
        operation.get(ModelDescriptionConstants.ATTRIBUTES_ONLY).asBoolean(false);

    // Attributes read directly from the model with no special read handler step in the middle
    final Map<String, ModelNode> directAttributes = new HashMap<String, ModelNode>();
    // Children names read directly from the model with no special read handler step in the middle
    final Map<String, ModelNode> directChildren = new HashMap<String, ModelNode>();
    // Attributes of AccessType.METRIC
    final Map<String, ModelNode> metrics =
        queryRuntime ? new HashMap<String, ModelNode>() : Collections.<String, ModelNode>emptyMap();
    // Non-AccessType.METRIC attributes with a special read handler registered
    final Map<String, ModelNode> otherAttributes = new HashMap<String, ModelNode>();
    // Child resources recursively read
    final Map<PathElement, ModelNode> childResources =
        recursive
            ? new LinkedHashMap<PathElement, ModelNode>()
            : Collections.<PathElement, ModelNode>emptyMap();

    // We're going to add a bunch of steps that should immediately follow this one. We are going to
    // add them
    // in reverse order of how they should execute, as that is the way adding a Stage.IMMEDIATE step
    // works

    // Last to execute is the handler that assembles the overall response from the pieces created by
    // all the other steps
    final ReadResourceAssemblyHandler assemblyHandler =
        new ReadResourceAssemblyHandler(
            directAttributes, metrics, otherAttributes, directChildren, childResources);
    context.addStep(
        assemblyHandler,
        queryRuntime ? OperationContext.Stage.VERIFY : OperationContext.Stage.MODEL,
        true);
    final ImmutableManagementResourceRegistration registry = context.getResourceRegistration();

    // Get the model for this resource.
    final Resource resource = nullSafeReadResource(context, registry);

    final Map<String, Set<String>> childrenByType =
        registry != null
            ? GlobalOperationHandlers.getChildAddresses(context, address, registry, resource, null)
            : Collections.<String, Set<String>>emptyMap();
    final ModelNode model = resource.getModel();

    if (model.isDefined()) {
      // Store direct attributes first
      for (String key : model.keys()) {
        // In case someone put some garbage in it
        if (!childrenByType.containsKey(key)) {
          directAttributes.put(key, model.get(key));
        }
      }
    }

    if (defaults) {
      // get the model description
      final DescriptionProvider descriptionProvider =
          registry.getModelDescription(PathAddress.EMPTY_ADDRESS);
      final Locale locale = GlobalOperationHandlers.getLocale(context, operation);
      final ModelNode nodeDescription = descriptionProvider.getModelDescription(locale);

      if (nodeDescription.isDefined() && nodeDescription.hasDefined(ATTRIBUTES)) {
        for (String key : nodeDescription.get(ATTRIBUTES).keys()) {
          if ((!childrenByType.containsKey(key))
              && (!directAttributes.containsKey(key) || !directAttributes.get(key).isDefined())
              && nodeDescription.get(ATTRIBUTES).hasDefined(key)
              && nodeDescription.get(ATTRIBUTES, key).hasDefined(DEFAULT)) {
            directAttributes.put(key, nodeDescription.get(ATTRIBUTES, key, DEFAULT));
          }
        }
      }
    }

    if (!attributesOnly) {
      // Next, process child resources
      for (Map.Entry<String, Set<String>> entry : childrenByType.entrySet()) {
        String childType = entry.getKey();
        Set<String> children = entry.getValue();
        if (children.isEmpty()) {
          // Just treat it like an undefined attribute
          directAttributes.put(childType, new ModelNode());
        } else {
          for (String child : children) {
            if (recursive) {
              PathElement childPE = PathElement.pathElement(childType, child);
              PathAddress relativeAddr = PathAddress.pathAddress(childPE);
              ImmutableManagementResourceRegistration childReg = registry.getSubModel(relativeAddr);
              if (childReg == null) {
                throw new OperationFailedException(
                    new ModelNode().set(MESSAGES.noChildRegistry(childType, child)));
              }
              // Decide if we want to invoke on this child resource
              boolean proxy = childReg.isRemote();
              boolean runtimeResource = childReg.isRuntimeOnly();
              boolean getChild = !runtimeResource || (queryRuntime && !proxy) || (proxies && proxy);
              if (!aliases && childReg.isAlias()) {
                getChild = false;
              }
              if (getChild) {
                final int newDepth = recursiveDepth > 0 ? recursiveDepth - 1 : 0;
                // Add a step to read the child resource
                ModelNode rrOp = new ModelNode();
                rrOp.get(OP).set(opName);
                rrOp.get(OP_ADDR).set(PathAddress.pathAddress(address, childPE).toModelNode());
                rrOp.get(ModelDescriptionConstants.RECURSIVE)
                    .set(operation.get(ModelDescriptionConstants.RECURSIVE));
                rrOp.get(ModelDescriptionConstants.RECURSIVE_DEPTH).set(newDepth);
                rrOp.get(ModelDescriptionConstants.PROXIES).set(proxies);
                rrOp.get(ModelDescriptionConstants.INCLUDE_RUNTIME).set(queryRuntime);
                rrOp.get(ModelDescriptionConstants.INCLUDE_ALIASES).set(aliases);
                rrOp.get(ModelDescriptionConstants.INCLUDE_DEFAULTS).set(defaults);
                ModelNode rrRsp = new ModelNode();
                childResources.put(childPE, rrRsp);

                OperationStepHandler rrHandler =
                    childReg.getOperationHandler(PathAddress.EMPTY_ADDRESS, opName);
                context.addStep(rrRsp, rrOp, rrHandler, OperationContext.Stage.MODEL, true);
              }
            } else {
              ModelNode childMap = directChildren.get(childType);
              if (childMap == null) {
                childMap = new ModelNode();
                childMap.setEmptyObject();
                directChildren.put(childType, childMap);
              }
              // Add a "child" => undefined
              childMap.get(child);
            }
          }
        }
      }
    }

    // Last, handle attributes with read handlers registered
    final Set<String> attributeNames =
        registry != null
            ? registry.getAttributeNames(PathAddress.EMPTY_ADDRESS)
            : Collections.<String>emptySet();
    for (final String attributeName : attributeNames) {
      final AttributeAccess access =
          registry.getAttributeAccess(PathAddress.EMPTY_ADDRESS, attributeName);
      if (access == null || access.getFlags().contains(AttributeAccess.Flag.ALIAS) && !aliases) {
        continue;
      } else {
        final AttributeAccess.Storage storage = access.getStorageType();

        if (!queryRuntime && storage != AttributeAccess.Storage.CONFIGURATION) {
          continue;
        }
        final AttributeAccess.AccessType type = access.getAccessType();
        final OperationStepHandler handler = access.getReadHandler();
        if (handler != null) {
          // Discard any directAttribute map entry for this, as the read handler takes precedence
          directAttributes.remove(attributeName);
          // Create the attribute operation
          final ModelNode attributeOperation = new ModelNode();
          attributeOperation.get(OP_ADDR).set(opAddr);
          attributeOperation.get(OP).set(READ_ATTRIBUTE_OPERATION);
          attributeOperation.get(GlobalOperationHandlers.NAME.getName()).set(attributeName);

          final ModelNode attrResponse = new ModelNode();
          if (type == AttributeAccess.AccessType.METRIC) {
            metrics.put(attributeName, attrResponse);
          } else {
            otherAttributes.put(attributeName, attrResponse);
          }
          context.addStep(
              attrResponse, attributeOperation, handler, OperationContext.Stage.MODEL, true);
        }
      }
    }
    context.stepCompleted();
  }