Java Code Examples for org.jboss.dmr.ModelNode#asList()

The following examples show how to use org.jboss.dmr.ModelNode#asList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelTestModelDescriptionValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public String validate(ModelNode currentNode, String descriptor) {
    if (currentNode.hasDefined(descriptor)) {
        List<ModelNode> list;
        try {
            list = currentNode.asList();
        } catch (Exception e) {
            return "'" + descriptor + "' is not a list";
        }
        for (ModelNode entry : list) {
            if (!entry.hasDefined(NAME)) {
                return "'" + descriptor + "." + entry + "'.name is not defined";
            }
            if (entry.get(NAME).getType() != ModelType.STRING) {
                return "'" + descriptor + "." + entry + "'.name is not of type string";
            }
            if (!entry.hasDefined(DYNAMIC)) {
                return "'" + descriptor + "." + entry + "'.dynamic is not defined";
            }
            if (!entry.hasDefined(DYNAMIC) || entry.get(DYNAMIC).getType() != ModelType.BOOLEAN) {
                return "'" + descriptor + "." + entry + "'.dynamic is not of type boolean";
            }
        }
    }
    return null;
}
 
Example 2
Source File: SingletonResourceTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void readChildrenNames() throws Exception {
    ModelNode op = createOperation(READ_CHILDREN_NAMES_OPERATION);
    op.get(CHILD_TYPE).set(CORE);
    ModelNode result = executeForResult(op);
    List<ModelNode> list = result.asList();
    Assert.assertEquals(1, list.size());
    Assert.assertTrue(list.contains(new ModelNode(MODEL)));

    op.get(OP_ADDR).setEmptyList().add(CORE, MODEL);
    op.get(CHILD_TYPE).set(SERVICE);
    result = executeForResult(op);
    list = result.asList();
    Assert.assertEquals(0, list.size());

    op.get(OP_ADDR).setEmptyList().add(CORE, MODEL);
    op.get(CHILD_TYPE).set(SERVICE);
    op.get(INCLUDE_SINGLETONS).set(true);
    result = executeForResult(op);
    list = result.asList();
    Assert.assertEquals(2, list.size());

    Assert.assertTrue(list.contains(new ModelNode(ASYNC)));
    Assert.assertTrue(list.contains(new ModelNode(REMOTE)));
}
 
Example 3
Source File: AnalysisConfiguration.java    From revapi with Apache License 2.0 6 votes vote down vote up
private static Set<String> readUseReportingCodes(ModelNode analysisConfig) {
    Set<String> ret = new HashSet<>(5);
    ModelNode config = analysisConfig.get("reportUsesFor");
    if (config.isDefined()) {
        switch (config.getType()) {
            case LIST:
                for (ModelNode code : config.asList()) {
                    ret.add(code.asString());
                }
                break;
            case STRING:
                if ("all-differences".equals(config.asString())) {
                    ret = null;
                }
                break;
        }
    } else {
        ret.add("java.missing.oldClass");
        ret.add("java.missing.newClass");
        ret.add("java.class.nonPublicPartOfAPI");
        ret.add("java.class.externalClassExposedInAPI");
        ret.add("java.class.externalClassNoLongerExposedInAPI");
    }

    return ret;
}
 
Example 4
Source File: ArgumentValueParsingTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testNestedList() throws Exception {
    final ModelNode value = parse("[a,b,[c,d]]");
    assertNotNull(value);
    assertEquals(ModelType.LIST, value.getType());
    List<ModelNode> list = value.asList();
    assertEquals(3, list.size());
    assertNotNull(list.get(0));
    assertEquals("a", list.get(0).asString());
    assertNotNull(list.get(1));
    assertEquals("b", list.get(1).asString());
    final ModelNode c = list.get(2);
    assertNotNull(c);
    assertEquals(ModelType.LIST, c.getType());
    list = c.asList();
    assertEquals(2, list.size());
    assertEquals("c", c.get(0).asString());
    assertEquals("d", c.get(1).asString());
}
 
Example 5
Source File: HttpPostMgmtOpsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testReadChildrenTypes() throws Exception {

    ModelNode ret = httpMgmt.sendPostCommand("subsystem=logging", "read-children-types");
    assertTrue("success".equals(ret.get("outcome").asString()));
    ModelNode result = ret.get("result");

    Set<String> strNames = new TreeSet<String>();
    for (ModelNode n : result.asList()) {
        strNames.add(n.asString());
    }


    assertTrue(strNames.contains("logging-profile"));
    assertTrue(strNames.contains("logger"));
}
 
Example 6
Source File: ConnectorUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Collection<SaslQop> asQopSet(final ModelNode node) {
    final Set<SaslQop> set = new HashSet<SaslQop>();
    for (final ModelNode element : node.asList()) {
        set.add(SaslQop.fromString(element.asString()));
    }
    return set;
}
 
Example 7
Source File: AliasResourceTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testDescribeHandler() throws Exception {
    addCore(CORE);
    addChild(CORE);

    ModelNode op = createOperation(DESCRIBE);
    ModelNode result = executeForResult(op);

    List<ModelNode> ops = result.asList();
    Assert.assertEquals(3, ops.size());

    op = ops.get(0);
    Assert.assertEquals(2, op.keys().size());
    Assert.assertEquals(ADD, op.get(OP).asString());
    Assert.assertEquals(new ModelNode().setEmptyList(), op.get(OP_ADDR));

    op = ops.get(1);
    Assert.assertEquals(4, op.keys().size());
    Assert.assertEquals(ADD, op.get(OP).asString());
    Assert.assertEquals(new ModelNode().add(CORE, MODEL), op.get(OP_ADDR));
    Assert.assertEquals("R/W", op.get("rw").asString());
    Assert.assertEquals("R/O", op.get("ro").asString());

    op = ops.get(2);
    Assert.assertEquals(3, op.keys().size());
    Assert.assertEquals(ADD, op.get(OP).asString());
    Assert.assertEquals(new ModelNode().add(CORE, MODEL).add(CHILD, KID_MODEL), op.get(OP_ADDR));
    Assert.assertEquals("R/W 2", op.get("rw").asString());
}
 
Example 8
Source File: AuthenticationFactoryDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static Set<String> getConfiguredMechanismNames(AttributeDefinition mechanismConfigurationAttribute, OperationContext context, ModelNode model) throws OperationFailedException {
    ModelNode mechanismConfiguration = mechanismConfigurationAttribute.resolveModelAttribute(context, model);
    if ( ! mechanismConfiguration.isDefined()) {
        return Collections.emptySet();
    }
    Set<String> mechanismNames = new LinkedHashSet<>();
    for (ModelNode current : mechanismConfiguration.asList()) {
        final String mechanismName = MECHANISM_NAME.resolveModelAttribute(context, current).asStringOrNull();
        if (mechanismName == null) {
            return Collections.emptySet();
        }
        mechanismNames.add(mechanismName);
    }
    return mechanismNames;
}
 
Example 9
Source File: ElytronUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void addAuthMechanism(CommandContext ctx, AuthFactory authFactory,
        AuthMechanism mechanism, ModelNode steps) throws OperationFormatException {
    ModelNode mechanisms = retrieveMechanisms(ctx, authFactory);
    ModelNode newMechanism = buildMechanismResource(mechanism);
    // check if a mechanism with the same name exists, replace it.
    int index = 0;
    boolean found = false;
    for (ModelNode m : mechanisms.asList()) {
        if (m.hasDefined(Util.MECHANISM_NAME)) {
            String name = m.get(Util.MECHANISM_NAME).asString();
            if (name.equals(mechanism.getType())) {
                // Already have the exact same mechanism, no need to add it.
                if (newMechanism.equals(m)) {
                    return;
                }
                found = true;
                break;
            }
        }
        index += 1;
    }

    if (found) {
        mechanisms.remove(index);
        mechanisms.insert(newMechanism, index);
    } else {
        mechanisms.add(newMechanism);
    }

    DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
    builder.setOperationName(Util.WRITE_ATTRIBUTE);
    builder.addNode(Util.SUBSYSTEM, Util.ELYTRON);
    builder.addNode(authFactory.getSpec().getResourceType(), authFactory.getName());
    builder.getModelNode().get(Util.VALUE).set(mechanisms);
    builder.getModelNode().get(Util.NAME).set(Util.MECHANISM_CONFIGURATIONS);
    steps.add(builder.buildRequest());
}
 
Example 10
Source File: ReadFeatureDescriptionTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testWildcardReadFeature() throws UnsuccessfulOperationException {
    ModelNode op = createOp(PathAddress.pathAddress(SOCKET_BINDING_GROUP, "*"));
    ModelNode result = executeForResult(op);
    Assert.assertEquals(result.toString(), ModelType.LIST, result.getType());
    for (ModelNode element : result.asList()) {
        Assert.assertTrue(element.toString(), element.hasDefined(OP_ADDR));
        Assert.assertEquals(element.toString(), SUCCESS, element.get(OUTCOME).asString());
        Assert.assertTrue(element.toString(), element.hasDefined(RESULT));
        validateBaseFeature(element.get(RESULT));
    }
}
 
Example 11
Source File: AbstractLoggingSubsystemTest.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static List<String> modelNodeAsStringList(final ModelNode node) {
    if (node.getType() == ModelType.LIST) {
        final List<String> result = new ArrayList<>();
        for (ModelNode n : node.asList()) result.add(n.asString());
        return result;
    }
    return Collections.emptyList();
}
 
Example 12
Source File: DeploymentOverlayScenario.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private String getServerProperty(DomainClient slaveClient, String propName) throws Exception {
    PathAddress addr = SLAVE_ADDR.append(SERVER, "server-affected")
            .append(CORE_SERVICE, PLATFORM_MBEAN).append(TYPE, "runtime");
    ModelNode op = Util.getReadAttributeOperation(addr, SYSTEM_PROPERTIES);
    ModelNode props = DomainTestUtils.executeForResult(op, slaveClient);
    for (ModelNode prop : props.asList()) {
        Property property = prop.asProperty();
        if (property.getName().equals(propName)) {
            return property.getValue().asString();
        }
    }
    return null;

}
 
Example 13
Source File: HostLifecycleWithRolloutPlanTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void cleanRolloutPlans() throws IOException {
    ModelNode params = new ModelNode();
    params.get("child-type").set("rollout-plan");
    ModelNode rcn = Util.getOperation("read-children-names", ROLLOUT_PLANS_ADDRESS, params);
    ModelNode returnVal = validateResponse(masterClient.execute(rcn));
    if (returnVal.isDefined()) {
        for (ModelNode plan : returnVal.asList()) {
            final PathAddress addr = ROLLOUT_PLANS_ADDRESS.append(ROLLOUT_PLAN, plan.asString());
            validateResponse(masterClient.execute(Util.createRemoveOperation(addr)));
        }
    }
}
 
Example 14
Source File: SimpleListAttributeDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void removeCapabilityRequirements(OperationContext context, Resource resource, ModelNode attributeValue) {
    if (attributeValue.isDefined()) {
        for (ModelNode element : attributeValue.asList()) {
            valueType.removeCapabilityRequirements(context, resource, element);
        }
    }
}
 
Example 15
Source File: IgnoreDomainResourceTypeResource.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
void setNames(ModelNode names) {
    synchronized (model) {
        model.clear();
        if (names.isDefined()) {
            for (ModelNode name : names.asList()) {
                String nameStr = name.asString();
                model.add(nameStr);
            }
        }
    }
}
 
Example 16
Source File: ReloadWithConfigTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private List<File> listSnapshots(DomainClient client, String host) throws Exception {
    final ModelNode op = Util.createEmptyOperation("list-snapshots", getRootAddress(host));
    final ModelNode result = DomainTestUtils.executeForResult(op, client);
    String dir = result.get(DIRECTORY).asString();
    ModelNode names = result.get(NAMES);
    List<File> snapshotFiles = new ArrayList<>();
    for (ModelNode nameNode : names.asList()) {
        snapshotFiles.add(new File(dir, nameNode.asString()));
    }
    return snapshotFiles;
}
 
Example 17
Source File: JdbcRealmDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
        throws OperationFailedException {
    ServiceTarget serviceTarget = context.getServiceTarget();
    RuntimeCapability<Void> runtimeCapability = SECURITY_REALM_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
    ServiceName realmName = runtimeCapability.getCapabilityServiceName(SecurityRealm.class);
    ModelNode principalQueries = PrincipalQueryAttributes.PRINCIPAL_QUERIES_7_0.resolveModelAttribute(context, operation);
    final JdbcSecurityRealmBuilder builder = JdbcSecurityRealm.builder();

    TrivialService<SecurityRealm> service = new TrivialService<SecurityRealm>(builder::build);
    ServiceBuilder<SecurityRealm> serviceBuilder = serviceTarget.addService(realmName, service);

    for (ModelNode query : principalQueries.asList()) {
        String authenticationQuerySql = PrincipalQueryAttributes.SQL.resolveModelAttribute(context, query).asString();
        QueryBuilder queryBuilder = builder.principalQuery(authenticationQuerySql)
                .withMapper(resolveAttributeMappers(context, query))
                .withMapper(resolveKeyMappers(context, query));

        String dataSourceName = PrincipalQueryAttributes.DATA_SOURCE.resolveModelAttribute(context, query).asString();
        String capabilityName = Capabilities.DATA_SOURCE_CAPABILITY_NAME + "." + dataSourceName;
        ServiceName dataSourceServiceName = context.getCapabilityServiceName(capabilityName, DataSource.class);

        serviceBuilder.addDependency(dataSourceServiceName, DataSource.class, new Injector<DataSource>() {

            @Override
            public void inject(DataSource value) throws InjectionException {
                queryBuilder.from(value);
            }

            @Override
            public void uninject() {
                // no-op
            }
        });
    }

    commonDependencies(serviceBuilder)
            .setInitialMode(context.getRunningMode() == RunningMode.ADMIN_ONLY ? ServiceController.Mode.LAZY : ServiceController.Mode.ACTIVE)
            .install();
}
 
Example 18
Source File: DeploymentTransformers.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void convertAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) {
    if (attributeValue.isDefined()) {
        for (ModelNode content : attributeValue.asList()) {
            if (!isUnmanagedContent(content)) {
                if (content.hasDefined(ARCHIVE) && content.get(ARCHIVE).asBoolean(true)) {
                    content.remove(ARCHIVE);
                }
            }
        }
    }
}
 
Example 19
Source File: ArgumentValueConverterTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testList_NoBracketsOneItem() throws Exception {
    final ModelNode value = parseList("a");
    assertNotNull(value);
    assertEquals(ModelType.LIST, value.getType());
    final List<ModelNode> list = value.asList();
    assertEquals(1, list.size());
    assertNotNull(list.get(0));
    assertEquals("a", list.get(0).asString());
}
 
Example 20
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Supplier<KeytabIdentityFactoryService> addKerberosIdentityServices(OperationContext context, ModelNode kerberos, String realmName, ServiceTarget serviceTarget,
    ServiceBuilder<?> realmBuilder) throws OperationFailedException {
    ServiceName keyIdentityName = KeytabIdentityFactoryService.ServiceUtil.createServiceName(realmName);
    final ServiceBuilder<?> kifsBuilder = serviceTarget.addService(keyIdentityName);
    final Consumer<KeytabIdentityFactoryService> kifsConsumer = kifsBuilder.provides(keyIdentityName);
    final KeytabIdentityFactoryService kifs = new KeytabIdentityFactoryService(kifsConsumer);
    kifsBuilder.setInstance(kifs);
    kifsBuilder.setInitialMode(ON_DEMAND);

    if (kerberos.hasDefined(KEYTAB)) {
        List<Property> keytabList = kerberos.get(KEYTAB).asPropertyList();
        for (Property current : keytabList) {
            String principal = current.getName();
            ModelNode keytab = current.getValue();
            String path = KeytabResourceDefinition.PATH.resolveModelAttribute(context, keytab).asString();
            ModelNode relativeToNode = KeytabResourceDefinition.RELATIVE_TO.resolveModelAttribute(context, keytab);
            String relativeTo = relativeToNode.isDefined() ? relativeToNode.asString() : null;
            boolean debug = KeytabResourceDefinition.DEBUG.resolveModelAttribute(context, keytab).asBoolean();
            final String[] forHostsValues;
            ModelNode forHosts = KeytabResourceDefinition.FOR_HOSTS.resolveModelAttribute(context, keytab);
            if (forHosts.isDefined()) {
                List<ModelNode> list = forHosts.asList();
                forHostsValues = new String[list.size()];
                for (int i=0;i<list.size();i++) {
                    forHostsValues[i] = list.get(i).asString();
                }
            } else {
                forHostsValues = new String[0];
            }

            ServiceName keytabName = KeytabService.ServiceUtil.createServiceName(realmName, principal);

            final ServiceBuilder<?> keytabBuilder = serviceTarget.addService(keytabName);
            final Consumer<KeytabService> ksConsumer = keytabBuilder.provides(keytabName);
            Supplier<PathManager> pathManagerSupplier = null;

            if (relativeTo != null) {
                pathManagerSupplier = keytabBuilder.requires(context.getCapabilityServiceName(PATH_MANAGER_CAPABILITY, PathManager.class));
                keytabBuilder.requires(pathName(relativeTo));
            }
            keytabBuilder.setInstance(new KeytabService(ksConsumer, pathManagerSupplier, principal, path, relativeTo, forHostsValues, debug));
            keytabBuilder.setInitialMode(ON_DEMAND);
            keytabBuilder.install();
            kifs.addKeytabSupplier(KeytabService.ServiceUtil.requires(kifsBuilder, realmName, principal));
         }
     }

     kifsBuilder.install();

     return KeytabIdentityFactoryService.ServiceUtil.requires(realmBuilder, realmName);
}