private static ModelFixer createModelFixer(ModelVersion version) {
    return (ModelNode model) -> {
      if (InfinispanModel.VERSION_4_1_0.requiresTransformation(version)) {
        final ModelNode maximal = model.get("cache-container", "maximal");
        maximal
            .asPropertyList()
            .stream()
            .filter(
                caches ->
                    caches.getName().equals("distributed-cache")
                        || caches.getName().equals("replicated-cache"))
            .forEach(
                p -> {
                  ModelNode caches = maximal.get(p.getName());
                  final List<Property> cachesModel = caches.asPropertyList();
                  for (Property cacheName : cachesModel) {
                    final ModelNode cache = caches.get(cacheName.getName());
                    if (cache.hasDefined("component")) {
                      cache.get("component", "backups").set(new ModelNode());
                    }
                  }
                });
      }

      if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
        // Fix the legacy model to expect new default values applied in
        // StateTransferResourceDefinition#buildTransformation
        Arrays.asList("cache-with-string-keyed-store", "cache-with-binary-keyed-store")
            .forEach(
                cacheName -> {
                  ModelNode cache =
                      model.get("cache-container", "maximal", "replicated-cache", cacheName);
                  assertFalse(
                      cache.hasDefined(
                          StateTransferResourceDefinition.LEGACY_PATH.getKeyValuePair()));
                  ModelNode stateTransfer =
                      cache.get(StateTransferResourceDefinition.LEGACY_PATH.getKeyValuePair());
                  stateTransfer
                      .get(
                          StateTransferResourceDefinition.Attribute.CHUNK_SIZE
                              .getDefinition()
                              .getName())
                      .set(
                          StateTransferResourceDefinition.Attribute.CHUNK_SIZE
                              .getDefinition()
                              .getDefaultValue());
                  stateTransfer
                      .get(
                          StateTransferResourceDefinition.Attribute.TIMEOUT
                              .getDefinition()
                              .getName())
                      .set(
                          StateTransferResourceDefinition.Attribute.TIMEOUT
                              .getDefinition()
                              .getDefaultValue());
                });
      }
      return model;
    };
  }
  private void writeIndexProviders(XMLExtendedStreamWriter writer, ModelNode repository)
      throws XMLStreamException {
    if (has(repository, ModelKeys.INDEX_PROVIDER)) {
      writer.writeStartElement(Element.INDEX_PROVIDERS.getLocalName());
      ModelNode providerNode = repository.get(ModelKeys.INDEX_PROVIDER);
      for (Property provider : providerNode.asPropertyList()) {
        writer.writeStartElement(Element.INDEX_PROVIDER.getLocalName());
        writer.writeAttribute(Attribute.NAME.getLocalName(), provider.getName());
        ModelNode prop = provider.getValue();
        ModelAttributes.CLASSNAME.marshallAsAttribute(prop, writer);
        ModelAttributes.MODULE.marshallAsAttribute(prop, writer);
        ModelAttributes.RELATIVE_TO.marshallAsAttribute(prop, writer);
        ModelAttributes.PATH.marshallAsAttribute(prop, writer);

        // Write out the extra properties ...
        if (has(prop, ModelKeys.PROPERTIES)) {
          ModelNode properties = prop.get(ModelKeys.PROPERTIES);
          for (Property property : properties.asPropertyList()) {
            writer.writeAttribute(property.getName(), property.getValue().asString());
          }
        }
        writer.writeEndElement();
      }
      writer.writeEndElement();
    }
  }
  private void writeIndexes(XMLExtendedStreamWriter writer, ModelNode repository)
      throws XMLStreamException {
    if (has(repository, ModelKeys.INDEX)) {
      writer.writeStartElement(Element.INDEXES.getLocalName());
      ModelNode providerNode = repository.get(ModelKeys.INDEX);
      for (Property index : providerNode.asPropertyList()) {
        writer.writeStartElement(Element.INDEX.getLocalName());
        writer.writeAttribute(Attribute.NAME.getLocalName(), index.getName());
        ModelNode prop = index.getValue();
        ModelAttributes.PROVIDER_NAME.marshallAsAttribute(prop, writer);
        ModelAttributes.INDEX_KIND.marshallAsAttribute(prop, writer);
        ModelAttributes.SYNCHRONOUS.marshallAsAttribute(prop, writer);
        ModelAttributes.NODE_TYPE_NAME.marshallAsAttribute(prop, writer);
        ModelAttributes.INDEX_COLUMNS.marshallAsAttribute(prop, writer);

        // Write out the extra properties ...
        if (has(prop, ModelKeys.PROPERTIES)) {
          ModelNode properties = prop.get(ModelKeys.PROPERTIES);
          for (Property property : properties.asPropertyList()) {
            writer.writeAttribute(property.getName(), property.getValue().asString());
          }
        }
        writer.writeEndElement();
      }
      writer.writeEndElement();
    }
  }
  /*
   * Tests access to local cache attributes
   */
  @SuppressWarnings("deprecation")
  @Test
  public void testDistributedCacheMixedJDBCStoreReadWriteOperation() throws Exception {

    ModelNode stringKeyedTable = createStringKeyedTable();

    // Parse and install the XML into the controller
    String subsystemXml = getSubsystemXml();
    KernelServices servicesA =
        this.createKernelServicesBuilder().setSubsystemXml(subsystemXml).build();

    // read the distributed cache mixed-keyed-jdbc-store datasource attribute
    ModelNode result =
        servicesA.executeOperation(
            getMixedKeyedJDBCCacheStoreReadOperation(
                "maximal",
                DistributedCacheResourceDefinition.WILDCARD_PATH.getKey(),
                "dist",
                JDBCStoreResourceDefinition.Attribute.DATA_SOURCE));
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertEquals("ExampleDS", result.get(RESULT).asString());

    // write the batching attribute
    result =
        servicesA.executeOperation(
            getMixedKeyedJDBCCacheStoreWriteOperation(
                "maximal",
                DistributedCacheResourceDefinition.WILDCARD_PATH.getKey(),
                "dist",
                JDBCStoreResourceDefinition.Attribute.DATA_SOURCE,
                "new-datasource"));
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());

    // re-read the batching attribute
    result =
        servicesA.executeOperation(
            getMixedKeyedJDBCCacheStoreReadOperation(
                "maximal",
                DistributedCacheResourceDefinition.WILDCARD_PATH.getKey(),
                "dist",
                JDBCStoreResourceDefinition.Attribute.DATA_SOURCE));
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertEquals("new-datasource", result.get(RESULT).asString());

    // read the string-keyed-table attribute
    result =
        servicesA.executeOperation(
            getMixedKeyedJDBCCacheStoreReadOperation(
                "maximal",
                DistributedCacheResourceDefinition.WILDCARD_PATH.getKey(),
                "dist",
                MixedKeyedJDBCStoreResourceDefinition.DeprecatedAttribute.STRING_TABLE));
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertEquals(
        stringKeyedTable.asPropertyList().size(), result.get(RESULT).asPropertyList().size());
    for (Property property : stringKeyedTable.asPropertyList()) {
      Assert.assertTrue(result.get(RESULT).hasDefined(property.getName()));
      Assert.assertEquals(property.getValue(), result.get(RESULT).get(property.getName()));
    }
  }
Example #5
0
  @Override
  public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context)
      throws XMLStreamException {
    context.startSubsystemElement(CURRENT.getUriString(), false);
    final ModelNode node = context.getModelNode();

    if (node.hasDefined(HORNETQ_SERVER)) {
      final ModelNode servers = node.get(HORNETQ_SERVER);
      boolean first = true;
      for (Property prop : servers.asPropertyList()) {
        writeHornetQServer(writer, prop.getName(), prop.getValue());
        if (!first) {
          writeNewLine(writer);
        } else {
          first = false;
        }
      }
    }

    if (node.hasDefined(JMS_BRIDGE)) {
      final ModelNode jmsBridges = node.get(JMS_BRIDGE);
      boolean first = true;
      for (Property prop : jmsBridges.asPropertyList()) {
        writeJmsBridge(writer, prop.getName(), prop.getValue());
        if (!first) {
          writeNewLine(writer);
        } else {
          first = false;
        }
      }
    }
    writer.writeEndElement();
  }
Example #6
0
 private static void writeConnectorServices(XMLExtendedStreamWriter writer, ModelNode node)
     throws XMLStreamException {
   if (!node.isDefined()) {
     return;
   }
   List<Property> properties = node.asPropertyList();
   if (!properties.isEmpty()) {
     writer.writeStartElement(Element.CONNECTOR_SERVICES.getLocalName());
     for (final Property property : node.asPropertyList()) {
       writer.writeStartElement(Element.CONNECTOR_SERVICE.getLocalName());
       writer.writeAttribute(Attribute.NAME.getLocalName(), property.getName());
       final ModelNode service = property.getValue();
       for (AttributeDefinition attribute : ConnectorServiceDefinition.ATTRIBUTES) {
         attribute.marshallAsElement(property.getValue(), writer);
       }
       // TODO use a custom attribute marshaller
       if (service.hasDefined(CommonAttributes.PARAM)) {
         for (Property param : service.get(CommonAttributes.PARAM).asPropertyList()) {
           writer.writeEmptyElement(Element.PARAM.getLocalName());
           writer.writeAttribute(Attribute.KEY.getLocalName(), param.getName());
           writer.writeAttribute(
               Attribute.VALUE.getLocalName(),
               param.getValue().get(ConnectorServiceParamDefinition.VALUE.getName()).asString());
         }
       }
       writer.writeEndElement();
     }
     writer.writeEndElement();
     writeNewLine(writer);
   }
 }
  private void writeSequencing(XMLExtendedStreamWriter writer, ModelNode repository)
      throws XMLStreamException {
    if (has(repository, ModelKeys.SEQUENCER)) {
      writer.writeStartElement(Element.SEQUENCERS.getLocalName());
      if (repository.hasDefined(ModelKeys.SEQUENCERS_THREAD_POOL_NAME)) {
        writer.writeAttribute(
            Attribute.THREAD_POOL_NAME.getLocalName(),
            repository.get(ModelKeys.SEQUENCERS_THREAD_POOL_NAME).asString());
      }
      if (repository.hasDefined(ModelKeys.SEQUENCERS_MAX_POOL_SIZE)) {
        writer.writeAttribute(
            Attribute.MAX_POOL_SIZE.getLocalName(),
            repository.get(ModelKeys.SEQUENCERS_MAX_POOL_SIZE).asString());
      }

      ModelNode sequencerNode = repository.get(ModelKeys.SEQUENCER);

      for (Property sequencer : sequencerNode.asPropertyList()) {
        writer.writeStartElement(Element.SEQUENCER.getLocalName());
        writer.writeAttribute(Attribute.NAME.getLocalName(), sequencer.getName());
        ModelNode prop = sequencer.getValue();
        ModelAttributes.SEQUENCER_CLASSNAME.marshallAsAttribute(prop, writer);
        ModelAttributes.MODULE.marshallAsAttribute(prop, writer);

        // Write out the extra properties ...
        if (has(prop, ModelKeys.PROPERTIES)) {
          ModelNode properties = prop.get(ModelKeys.PROPERTIES);
          for (Property property : properties.asPropertyList()) {
            writer.writeAttribute(property.getName(), property.getValue().asString());
          }
        }
        if (has(prop, ModelKeys.PATH_EXPRESSIONS)) {
          List<ModelNode> pathExpressions = prop.get(ModelKeys.PATH_EXPRESSIONS).asList();
          switch (pathExpressions.size()) {
            case 0:
              break;
            case 1:
              ModelNode pathExpression = pathExpressions.iterator().next();
              writer.writeAttribute(
                  Attribute.PATH_EXPRESSION.getLocalName(), pathExpression.asString());
              break;
            default:
              for (ModelNode pathExpr : pathExpressions) {
                writer.writeStartElement(Element.PATH_EXPRESSION.getLocalName());
                writer.writeCharacters(pathExpr.asString());
                writer.writeEndElement();
              }
          }
        }
        writer.writeEndElement();
      }
      writer.writeEndElement();
    }
  }
    /** {@inheritDoc} */
    @Override
    public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context)
        throws XMLStreamException {
      context.startSubsystemElement(Namespace.CURRENT.getUriString(), false);
      ModelNode scanners = context.getModelNode();
      for (final Property list : scanners.asPropertyList()) {
        final ModelNode node = list.getValue();

        for (final Property scanner : node.asPropertyList()) {

          writer.writeEmptyElement(Element.DEPLOYMENT_SCANNER.getLocalName());
          writer.writeAttribute(Attribute.NAME.getLocalName(), scanner.getName());
          ModelNode configuration = scanner.getValue();
          if (configuration.hasDefined(CommonAttributes.PATH)) {
            writer.writeAttribute(
                Attribute.PATH.getLocalName(), configuration.get(CommonAttributes.PATH).asString());
          }
          if (configuration.hasDefined(CommonAttributes.SCAN_ENABLED)) {
            writer.writeAttribute(
                Attribute.SCAN_ENABLED.getLocalName(),
                configuration.get(CommonAttributes.SCAN_ENABLED).asString());
          }
          if (configuration.hasDefined(CommonAttributes.SCAN_INTERVAL)) {
            writer.writeAttribute(
                Attribute.SCAN_INTERVAL.getLocalName(),
                configuration.get(CommonAttributes.SCAN_INTERVAL).asString());
          }
          if (configuration.hasDefined(CommonAttributes.RELATIVE_TO)) {
            writer.writeAttribute(
                Attribute.RELATIVE_TO.getLocalName(),
                configuration.get(CommonAttributes.RELATIVE_TO).asString());
          }
          if (configuration.hasDefined(CommonAttributes.AUTO_DEPLOY_ZIPPED)) {
            if (!configuration.get(CommonAttributes.AUTO_DEPLOY_ZIPPED).asBoolean()) {
              writer.writeAttribute(
                  Attribute.AUTO_DEPLOY_ZIPPED.getLocalName(), Boolean.FALSE.toString());
            }
          }
          if (configuration.hasDefined(CommonAttributes.AUTO_DEPLOY_EXPLODED)) {
            if (configuration.get(CommonAttributes.AUTO_DEPLOY_EXPLODED).asBoolean()) {
              writer.writeAttribute(
                  Attribute.AUTO_DEPLOY_EXPLODED.getLocalName(), Boolean.TRUE.toString());
            }
          }
          if (configuration.hasDefined(CommonAttributes.DEPLOYMENT_TIMEOUT)) {
            writer.writeAttribute(
                Attribute.DEPLOYMENT_TIMEOUT.getLocalName(),
                configuration.get(CommonAttributes.DEPLOYMENT_TIMEOUT).asString());
          }
        }
        writer.writeEndElement();
      }
    }
 // For any request params that are of type BYTES, replace the file path with the bytes from the
 // file
 private boolean replaceFilePathsWithBytes(ModelNode request)
     throws CommandFormatException, IOException {
   boolean didReplacement = false;
   ModelNode opDesc = new ModelNode();
   opDesc.get("address").set(request.get("address"));
   opDesc.get("operation").set("read-operation-description");
   final String opName = request.get("operation").asString();
   opDesc.get("name").set(opName);
   ModelNode response = execute(opDesc, false).getResponseNode();
   if (response.hasDefined("result", "request-properties")) {
     final ModelNode requestProps = response.get("result", "request-properties");
     for (Property prop : requestProps.asPropertyList()) {
       ModelNode typeDesc = prop.getValue().get("type");
       if (typeDesc.getType() == ModelType.TYPE
           && typeDesc.asType() == ModelType.BYTES
           && request.hasDefined(prop.getName())) {
         String filePath = request.get(prop.getName()).asString();
         File localFile = new File(filePath);
         if (!localFile.exists()) continue;
         try {
           request.get(prop.getName()).set(Util.readBytes(localFile));
           didReplacement = true;
         } catch (OperationFormatException e) {
           throw new CommandFormatException(e);
         }
       }
     }
   }
   return didReplacement;
 }
 private void addInterfaces(Map<String, ModelNode> map, ModelNode iface) {
   if (iface.isDefined()) {
     for (Property prop : iface.asPropertyList()) {
       map.put(prop.getName(), prop.getValue());
     }
   }
 }
  private void writeTextExtraction(XMLExtendedStreamWriter writer, ModelNode repository)
      throws XMLStreamException {
    if (has(repository, ModelKeys.TEXT_EXTRACTOR)) {
      writer.writeStartElement(Element.TEXT_EXTRACTORS.getLocalName());
      if (repository.hasDefined(ModelKeys.TEXT_EXTRACTORS_THREAD_POOL_NAME)) {
        writer.writeAttribute(
            Attribute.THREAD_POOL_NAME.getLocalName(),
            repository.get(ModelKeys.TEXT_EXTRACTORS_THREAD_POOL_NAME).asString());
      }
      if (repository.hasDefined(ModelKeys.TEXT_EXTRACTORS_MAX_POOL_SIZE)) {
        writer.writeAttribute(
            Attribute.MAX_POOL_SIZE.getLocalName(),
            repository.get(ModelKeys.TEXT_EXTRACTORS_MAX_POOL_SIZE).asString());
      }
      for (Property extractor : repository.get(ModelKeys.TEXT_EXTRACTOR).asPropertyList()) {
        writer.writeStartElement(Element.TEXT_EXTRACTOR.getLocalName());
        writer.writeAttribute(Attribute.NAME.getLocalName(), extractor.getName());
        ModelNode prop = extractor.getValue();
        ModelAttributes.TEXT_EXTRACTOR_CLASSNAME.marshallAsAttribute(prop, writer);
        ModelAttributes.MODULE.marshallAsAttribute(prop, writer);

        // Write out the extra properties ...
        if (has(prop, ModelKeys.PROPERTIES)) {
          ModelNode properties = prop.get(ModelKeys.PROPERTIES);
          for (Property property : properties.asPropertyList()) {
            writer.writeAttribute(property.getName(), property.getValue().asString());
          }
        }
        writer.writeEndElement();
      }
      writer.writeEndElement();
    }
  }
Example #12
0
  private void setProps(ModelNode requestProperties) throws Exception {
    props = new TreeSet<RequestProp>();
    if (opName.equals("add")) {
      UserObject usrObj = (UserObject) node.getUserObject();
      props.add(
          new RequestProp(
              "/" + usrObj.getName() + "=<name>/",
              "Resource name for the new " + usrObj.getName(),
              true,
              ModelType.STRING));
    }

    if (opName.equals("write-attribute") && node.isLeaf()) {
      ModelNode nameNode = requestProperties.get("name");
      nameNode
          .get("type")
          .set(ModelType.UNDEFINED); // undefined type will display as uneditable String
      UserObject usrObj = (UserObject) node.getUserObject();
      ModelNode nameNodeValue = new ModelNode();
      nameNodeValue.set(usrObj.getName());
      props.add(new RequestProp("name", requestProperties.get("name"), nameNodeValue));

      ModelNode rscDesc =
          cliGuiCtx.getExecutor().doCommand(node.addressPath() + ":read-resource-description");
      ModelNode valueNode = rscDesc.get("result", "attributes", usrObj.getName());
      valueNode.get("required").set(false); // value is never required for write-attribute
      ModelNode valueNodeValue = usrObj.getBackingNode().get(usrObj.getName());
      props.add(new RequestProp("value", valueNode, valueNodeValue));
      return;
    }

    for (Property prop : requestProperties.asPropertyList()) {
      props.add(new RequestProp(prop.getName(), prop.getValue(), null));
    }
  }
Example #13
0
    private void addUnboundedQueueThreadPools(final ModelNode result, final ModelNode model) {
      if (model.hasDefined(UNBOUNDED_QUEUE_THREAD_POOL)) {
        ModelNode pools = model.get(UNBOUNDED_QUEUE_THREAD_POOL);
        for (Property poolProp : pools.asPropertyList()) {
          final ModelNode operation =
              Util.getEmptyOperation(
                  ADD,
                  pathAddress(
                      PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME),
                      PathElement.pathElement(UNBOUNDED_QUEUE_THREAD_POOL, poolProp.getName())));
          final ModelNode pool = poolProp.getValue();

          operation.get(NAME).set(pool.require(NAME));
          if (pool.hasDefined(THREAD_FACTORY)) {
            operation.get(THREAD_FACTORY).set(pool.get(THREAD_FACTORY));
          }
          if (pool.hasDefined(PROPERTIES)) {
            operation.get(PROPERTIES).set(pool.get(PROPERTIES));
          }
          if (pool.hasDefined(MAX_THREADS)) {
            operation.get(MAX_THREADS).set(pool.get(MAX_THREADS));
          }
          if (pool.hasDefined(KEEPALIVE_TIME)) {
            operation.get(KEEPALIVE_TIME).set(pool.get(KEEPALIVE_TIME));
          }
          result.add(operation);
        }
      }
    }
 @Override
 public void persist(XMLExtendedStreamWriter writer, ModelNode model) throws XMLStreamException {
   boolean wildcard = getPathElement().isWildcard();
   model =
       wildcard
           ? model.get(getPathElement().getKey())
           : model.get(getPathElement().getKeyValuePair());
   if (!model.isDefined()) {
     return;
   }
   boolean writeWrapper = getXmlWrapperElement() != null;
   if (writeWrapper) {
     writer.writeStartElement(getXmlWrapperElement());
   }
   writer.writeStartElement(getXmlElementName());
   if (wildcard) {
     for (Property p : model.asPropertyList()) {
       writer.writeAttribute(NAME, p.getName());
       for (AttributeDefinition def : getAttributes()) {
         def.getAttributeMarshaller().marshallAsAttribute(def, p.getValue(), false, writer);
       }
       persistChildren(writer, p.getValue());
     }
   } else {
     for (AttributeDefinition def : getAttributes()) {
       def.getAttributeMarshaller().marshallAsAttribute(def, model, false, writer);
     }
     persistChildren(writer, model);
   }
   writer.writeEndElement();
   if (writeWrapper) {
     writer.writeEndElement();
   }
 }
Example #15
0
    private void addThreadFactories(final ModelNode result, final ModelNode model) {
      if (model.hasDefined(THREAD_FACTORY)) {
        ModelNode pools = model.get(THREAD_FACTORY);
        for (Property poolProp : pools.asPropertyList()) {
          final ModelNode operation =
              Util.getEmptyOperation(
                  ADD,
                  pathAddress(
                      PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME),
                      PathElement.pathElement(THREAD_FACTORY, poolProp.getName())));
          final ModelNode pool = poolProp.getValue();

          operation.get(NAME).set(pool.require(NAME));
          if (pool.hasDefined(GROUP_NAME)) {
            operation.get(GROUP_NAME).set(pool.get(GROUP_NAME));
          }
          if (pool.hasDefined(THREAD_NAME_PATTERN)) {
            operation.get(THREAD_NAME_PATTERN).set(pool.get(THREAD_NAME_PATTERN));
          }
          if (pool.hasDefined(PRIORITY)) {
            operation.get(PRIORITY).set(pool.get(PRIORITY));
          }
          if (pool.hasDefined(PROPERTIES)) {
            operation.get(PROPERTIES).set(pool.get(PROPERTIES));
          }
          result.add(operation);
        }
      }
    }
 private void addPaths(Map<String, ModelNode> map, ModelNode path) {
   if (path.isDefined()) {
     for (Property prop : path.asPropertyList()) {
       // TODO merge rather than replace existing?
       map.put(prop.getName(), prop.getValue());
     }
   }
 }
 /**
  * Obtains a list of all caches in the model of a particular type, as a property list.
  *
  * @param model
  * @param containerName
  * @param cacheType LOCAL_CACHE, INVALIDATION_CACHE, REPLICATED_CACHE, DISTRIBUTED_CACHE
  * @return
  */
 public static List<Property> getCachesAsPropertyList(
     ModelNode model, String containerName, String cacheType) {
   ModelNode caches = model.get(ModelKeys.CACHE_CONTAINER, containerName, cacheType);
   if (caches.isDefined() && caches.getType() == ModelType.OBJECT) {
     return caches.asPropertyList();
   }
   return null;
 }
 private Map<String, ModelNode> createMapIndexedByKey(ModelNode node) {
   Map<String, ModelNode> map = new HashMap<String, ModelNode>();
   if (!node.isDefined()) {
     return map;
   }
   for (Property prop : node.asPropertyList()) {
     map.put(prop.getName(), prop.getValue());
   }
   return map;
 }
 private void addSchemaLocations(Map<String, ModelNode> map, ModelNode namespaces) {
   if (namespaces.isDefined()) {
     for (Property prop : namespaces.asPropertyList()) {
       map.put(
           prop.getName(),
           SchemaLocationAddHandler.getAddSchemaLocationOperation(
               EMPTY, prop.getName(), prop.getValue().asString()));
     }
   }
 }
 private void writeProperties(final XMLExtendedStreamWriter writer, final ModelNode node)
     throws XMLStreamException {
   writer.writeStartElement(Element.PROPERTIES.getLocalName());
   for (Property prop : node.asPropertyList()) {
     writer.writeStartElement(Element.PROPERTY.getLocalName());
     writer.writeAttribute(Attribute.NAME.getLocalName(), prop.getName());
     PropertyResource.VALUE.marshallAsAttribute(prop.getValue(), writer);
     writer.writeEndElement();
   }
   writer.writeEndElement();
 }
 public Map<String, String> unwrap(final OperationContext context, final ModelNode model)
     throws OperationFailedException {
   if (!model.hasDefined(getName())) {
     return new HashMap<String, String>();
   }
   ModelNode modelProps = model.get(getName());
   Map<String, String> props = new HashMap<String, String>();
   for (Property p : modelProps.asPropertyList()) {
     props.put(p.getName(), context.resolveExpressions(p.getValue()).asString());
   }
   return props;
 }
Example #22
0
 private static void writeTransportParam(
     final XMLExtendedStreamWriter writer, final ModelNode param) throws XMLStreamException {
   if (param.isDefined()) {
     for (final Property parameter : param.asPropertyList()) {
       writer.writeStartElement(Element.PARAM.getLocalName());
       writer.writeAttribute(Attribute.KEY.getLocalName(), parameter.getName());
       writer.writeAttribute(
           Attribute.VALUE.getLocalName(),
           parameter.getValue().get(TransportParamDefinition.VALUE.getName()).asString());
       writer.writeEndElement();
     }
   }
 }
  private void writeExternalSources(XMLExtendedStreamWriter writer, ModelNode repository)
      throws XMLStreamException {
    if (has(repository, ModelKeys.SOURCE)) {
      writer.writeStartElement(Element.EXTERNAL_SOURCES.getLocalName());
      ModelNode externalSourceNode = repository.get(ModelKeys.SOURCE);
      for (Property externalSource : externalSourceNode.asPropertyList()) {
        writer.writeStartElement(Element.SOURCE.getLocalName());
        writer.writeAttribute(Attribute.NAME.getLocalName(), externalSource.getName());

        ModelNode prop = externalSource.getValue();
        ModelAttributes.CONNECTOR_CLASSNAME.marshallAsAttribute(prop, writer);
        ModelAttributes.MODULE.marshallAsAttribute(prop, writer);
        ModelAttributes.CACHE_TTL_SECONDS.marshallAsAttribute(prop, writer);
        ModelAttributes.QUERYABLE.marshallAsAttribute(prop, writer);
        ModelAttributes.READONLY.marshallAsAttribute(prop, writer);
        ModelAttributes.EXPOSE_AS_WORKSPACE.marshallAsAttribute(prop, writer);

        // Write out the extra properties ...
        if (has(prop, ModelKeys.PROPERTIES)) {
          ModelNode properties = prop.get(ModelKeys.PROPERTIES);
          for (Property property : properties.asPropertyList()) {
            writer.writeAttribute(property.getName(), property.getValue().asString());
          }
        }

        if (has(prop, ModelKeys.PROJECTIONS)) {
          List<ModelNode> projections = prop.get(ModelKeys.PROJECTIONS).asList();
          for (ModelNode projection : projections) {
            writer.writeStartElement(Element.PROJECTION.getLocalName());
            writer.writeCharacters(projection.asString());
            writer.writeEndElement();
          }
        }
        writer.writeEndElement();
      }
      writer.writeEndElement();
    }
  }
  public void persist(XMLExtendedStreamWriter writer, ModelNode model, String namespaceURI)
      throws XMLStreamException {
    boolean wildcard = getPathElement().isWildcard();
    model =
        wildcard
            ? model.get(getPathElement().getKey())
            : model.get(getPathElement().getKeyValuePair());
    if (!model.isDefined() && !useValueAsElementName()) {
      return;
    }
    boolean isSubsystem = getPathElement().getKey().equals(ModelDescriptionConstants.SUBSYSTEM);

    boolean writeWrapper = getXmlWrapperElement() != null;
    if (writeWrapper) {
      writeStartElement(writer, namespaceURI, getXmlWrapperElement());
    }

    if (wildcard) {
      for (Property p : model.asPropertyList()) {
        if (useValueAsElementName()) {
          writeStartElement(writer, namespaceURI, p.getName());
        } else {
          writeStartElement(writer, namespaceURI, getXmlElementName());
          writer.writeAttribute(NAME, p.getName());
        }
        for (AttributeDefinition def : getAttributes()) {
          def.getAttributeMarshaller().marshallAsAttribute(def, p.getValue(), false, writer);
        }
        persistChildren(writer, p.getValue());
        writer.writeEndElement();
      }
    } else {
      if (useValueAsElementName()) {
        writeStartElement(writer, namespaceURI, getPathElement().getValue());
      } else if (isSubsystem) {
        startSubsystemElement(writer, namespaceURI, getChildren().isEmpty());
      } else {
        writeStartElement(writer, namespaceURI, getXmlElementName());
      }
      for (AttributeDefinition def : getAttributes()) {
        def.getAttributeMarshaller().marshallAsAttribute(def, model, false, writer);
      }
      persistChildren(writer, model);
      writer.writeEndElement();
    }

    if (writeWrapper) {
      writer.writeEndElement();
    }
  }
Example #25
0
 private static void writeClusterConnections(XMLExtendedStreamWriter writer, ModelNode node)
     throws XMLStreamException {
   if (!node.isDefined()) {
     return;
   }
   List<Property> properties = node.asPropertyList();
   if (!properties.isEmpty()) {
     writer.writeStartElement(Element.CLUSTER_CONNECTIONS.getLocalName());
     for (final Property property : node.asPropertyList()) {
       writer.writeStartElement(Element.CLUSTER_CONNECTION.getLocalName());
       writer.writeAttribute(Attribute.NAME.getLocalName(), property.getName());
       final ModelNode cluster = property.getValue();
       for (AttributeDefinition attribute : ClusterConnectionDefinition.ATTRIBUTES) {
         if (attribute == ClusterConnectionDefinition.ALLOW_DIRECT_CONNECTIONS_ONLY) {
           // we nest it in static-connectors
           continue;
         }
         if (attribute == CONNECTOR_REFS) {
           if (attribute.isMarshallable(cluster)) {
             writer.writeStartElement(Element.STATIC_CONNECTORS.getLocalName());
             ALLOW_DIRECT_CONNECTIONS_ONLY.marshallAsAttribute(cluster, writer);
             CONNECTOR_REFS.marshallAsElement(cluster, writer);
             writer.writeEndElement();
           } else if (ALLOW_DIRECT_CONNECTIONS_ONLY.isMarshallable(cluster)) {
             writer.writeEmptyElement(Element.STATIC_CONNECTORS.getLocalName());
             ALLOW_DIRECT_CONNECTIONS_ONLY.marshallAsAttribute(cluster, writer);
           }
         } else {
           attribute.marshallAsElement(property.getValue(), writer);
         }
       }
       writer.writeEndElement();
     }
     writer.writeEndElement();
     writeNewLine(writer);
   }
 }
Example #26
0
 private static void writeBridges(XMLExtendedStreamWriter writer, ModelNode node)
     throws XMLStreamException {
   if (!node.isDefined()) {
     return;
   }
   List<Property> properties = node.asPropertyList();
   if (!properties.isEmpty()) {
     writer.writeStartElement(Element.BRIDGES.getLocalName());
     for (final Property property : node.asPropertyList()) {
       writer.writeStartElement(Element.BRIDGE.getLocalName());
       writer.writeAttribute(Attribute.NAME.getLocalName(), property.getName());
       for (AttributeDefinition attribute : BridgeDefinition.ATTRIBUTES) {
         if (CommonAttributes.FILTER == attribute) {
           writeFilter(writer, property.getValue());
         } else {
           attribute.marshallAsElement(property.getValue(), writer);
         }
       }
       writer.writeEndElement();
     }
     writer.writeEndElement();
     writeNewLine(writer);
   }
 }
Example #27
0
    public void execute(OperationContext context, ModelNode operation)
        throws OperationFailedException {
      final ModelNode add = createEmptyAddOperation();
      final ModelNode model = context.readModel(PathAddress.EMPTY_ADDRESS);

      if (model.hasDefined(BEAN_VALIDATION_ENABLED)) {
        add.get(BEAN_VALIDATION_ENABLED).set(model.get(BEAN_VALIDATION_ENABLED));
      }
      if (model.hasDefined(ARCHIVE_VALIDATION_ENABLED)) {
        add.get(ARCHIVE_VALIDATION_ENABLED).set(model.get(ARCHIVE_VALIDATION_ENABLED));
      }
      if (model.hasDefined(ARCHIVE_VALIDATION_FAIL_ON_ERROR)) {
        add.get(ARCHIVE_VALIDATION_FAIL_ON_ERROR).set(model.get(ARCHIVE_VALIDATION_FAIL_ON_ERROR));
      }
      if (model.hasDefined(ARCHIVE_VALIDATION_FAIL_ON_WARN)) {
        add.get(ARCHIVE_VALIDATION_FAIL_ON_WARN).set(model.get(ARCHIVE_VALIDATION_FAIL_ON_WARN));
      }
      if (model.hasDefined(CACHED_CONNECTION_MANAGER_DEBUG)) {
        add.get(CACHED_CONNECTION_MANAGER_DEBUG).set(model.get(CACHED_CONNECTION_MANAGER_DEBUG));
      }
      if (model.hasDefined(CACHED_CONNECTION_MANAGER_ERROR)) {
        add.get(CACHED_CONNECTION_MANAGER_ERROR).set(model.get(CACHED_CONNECTION_MANAGER_ERROR));
      }

      final ModelNode result = context.getResult();
      result.add(add);

      if (model.hasDefined(THREAD_POOL)) {
        ModelNode pools = model.get(THREAD_POOL);
        for (Property poolProp : pools.asPropertyList()) {
          if (poolProp.getName().equals(LONG_RUNNING_THREADS)) {
            addBoundedQueueThreadPool(
                result,
                poolProp.getValue(),
                PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, SUBSYSTEM_NAME),
                PathElement.pathElement(THREAD_POOL, LONG_RUNNING_THREADS));
          } else if (poolProp.getName().equals(SHORT_RUNNING_THREADS)) {
            addBoundedQueueThreadPool(
                result,
                poolProp.getValue(),
                PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, SUBSYSTEM_NAME),
                PathElement.pathElement(THREAD_POOL, SHORT_RUNNING_THREADS));
          }
        }
      }

      context.completeStep();
    }
 Set<String> getServersForGroup(final ModelNode model, final String groupName) {
   if (groupName == null) {
     return Collections.emptySet();
   }
   final String hostName = model.get(HOST).keys().iterator().next();
   final ModelNode serverConfig = model.get(HOST, hostName).get(SERVER_CONFIG);
   if (!serverConfig.isDefined()) {
     return Collections.emptySet();
   }
   final Set<String> servers = new HashSet<String>();
   for (Property config : serverConfig.asPropertyList()) {
     if (groupName.equals(config.getValue().get(GROUP).asString())) {
       servers.add(config.getName());
     }
   }
   return servers;
 }
  protected ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException {
    final ModelNode req = super.buildRequestWithoutHeaders(ctx);
    final ModelNode steps = req.get(Util.STEPS);

    final ModelNode conPropsNode = conProps.toModelNode(ctx);
    if (conPropsNode != null) {
      final List<Property> propsList = conPropsNode.asPropertyList();
      for (Property prop : propsList) {
        final ModelNode address = this.buildOperationAddress(ctx);
        address.add(CONNECTION_PROPERTIES, prop.getName());
        final ModelNode addProp = new ModelNode();
        addProp.get(Util.ADDRESS).set(address);
        addProp.get(Util.OPERATION).set(Util.ADD);
        addProp.get(Util.VALUE).set(prop.getValue());
        steps.add(addProp);
      }
    }
    return req;
  }
 @Override
 public void marshallAsElement(
     AttributeDefinition attribute,
     ModelNode resourceModel,
     boolean marshallDefault,
     XMLStreamWriter writer)
     throws XMLStreamException {
   ModelNode properties = resourceModel.get(attribute.getName());
   if (properties.isDefined()) {
     for (Property property : properties.asPropertyList()) {
       writer.writeStartElement(
           org.jboss.as.controller.parsing.Element.PROPERTY.getLocalName());
       writer.writeAttribute(
           org.jboss.as.controller.parsing.Element.NAME.getLocalName(), property.getName());
       writer.writeCharacters(property.getValue().asString());
       writer.writeEndElement();
     }
   }
 }