org.jboss.as.controller.operations.common.Util Java Examples

The following examples show how to use org.jboss.as.controller.operations.common.Util. 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: ReadConfigAsFeaturesDomainTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void saveDefaultConfig() {
    if (defaultDomainConfig == null || defaultHostConfig == null) {
        ModelNode takeSnapshotOnDomain = Util.createEmptyOperation(TAKE_SNAPSHOT_OPERATION, PathAddress.EMPTY_ADDRESS);
        ModelNode takeSnapshotOnHost = Util.createEmptyOperation(TAKE_SNAPSHOT_OPERATION, PathAddress.pathAddress(HOST, MASTER));
        domainMasterLifecycleUtil.executeForResult(takeSnapshotOnDomain);
        domainMasterLifecycleUtil.executeForResult(takeSnapshotOnHost);
        ModelNode listDomainSnapshots = Util.createEmptyOperation(LIST_SNAPSHOTS_OPERATION, PathAddress.EMPTY_ADDRESS);
        ModelNode listHostSnapshots = Util.createEmptyOperation(LIST_SNAPSHOTS_OPERATION, PathAddress.pathAddress(HOST, MASTER));
        ModelNode domainSnapshots = domainMasterLifecycleUtil.executeForResult(listDomainSnapshots);
        ModelNode hostSnapshots = domainMasterLifecycleUtil.executeForResult(listHostSnapshots);

        defaultDomainConfig = domainSnapshots.get("names").get(0).asString();
        defaultHostConfig = hostSnapshots.get("names").get(0).asString();
    }
}
 
Example #2
Source File: RemoveResourceTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void testRemoveWithWriteAttributeSensitivity(StandardRole role, boolean success) throws Exception {
    ChildResourceDefinition def = new ChildResourceDefinition(ONE);
    def.addAttribute("test", WRITE_CONSTRAINT);
    rootRegistration.registerSubModel(def);

    Resource resourceA = Resource.Factory.create();
    resourceA.getModel().get("test").set("a");
    rootResource.registerChild(ONE_A, resourceA);

    Resource resourceB = Resource.Factory.create();
    resourceB.getModel().get("test").set("b");
    rootResource.registerChild(ONE_B, resourceB);

    ModelNode op = Util.createRemoveOperation(ONE_B_ADDR);
    op.get(OPERATION_HEADERS, "roles").set(role.toString());
    if (success) {
        executeForResult(op);
    } else {
        executeForFailure(op);
    }
}
 
Example #3
Source File: DeploymentScenario.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
void tearDownDomain(DomainTestSupport testSupport, DomainClient masterClient, DomainClient slaveClient) throws Exception {
    if (rolloutPlan) {
        DomainTestUtils.executeForResult(
                Util.createRemoveOperation(
                        PathAddress.pathAddress(MANAGEMENT_CLIENT_CONTENT, ROLLOUT_PLANS).append(ROLLOUT_PLAN, "test")),
                masterClient);
    }
    for (String qualifier : new HashSet<>(deployed)) {
        undeploy(masterClient, qualifier);
    }
    if (initialized >= 4) {
        stopServer(slaveClient, "server-affected");
    }
    if (initialized >= 3) {
        DomainTestUtils.executeForResult(
                Util.createRemoveOperation(SLAVE_ADDR.append(SERVER_CONFIG, "server-affected")), masterClient);
    }
    if (initialized >= 2) {
        DomainTestUtils.executeForResult(
                Util.createRemoveOperation(PathAddress.pathAddress(SERVER_GROUP, "deployment-group-affected")), masterClient);
    }
    if (initialized >= 1) {
        removeProfile(masterClient, "deployment-affected");
    }
}
 
Example #4
Source File: OrderedChildResourceTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testOrderedChildren() throws Exception {
    ModelNode add = Util.createAddOperation(PathAddress.pathAddress(PARENT_MAIN));
    executeForResult(add);
    assertChildren();

    executeAddChildOperation("tree", 0);
    assertChildren("tree");

    executeAddChildOperation("house", null);
    assertChildren("tree", "house");

    executeAddChildOperation("which", 0);
    assertChildren("which", "tree", "house");

    executeAddChildOperation("likes", 2);
    assertChildren("which", "tree", "likes", "house");

    executeAddChildOperation("mice", 1000000);
    assertChildren("which", "tree", "likes", "house", "mice");
}
 
Example #5
Source File: LegacyConfigurationChangesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testConfigurationChangesOnSlave() throws Exception {
    try {
        createConfigurationChanges(HOST_SLAVE);
        PathAddress systemPropertyAddress = PathAddress.pathAddress().append(HOST_SLAVE).append(SYSTEM_PROPERTY, "slave");
        ModelNode setSystemProperty = Util.createAddOperation(systemPropertyAddress);
        setSystemProperty.get(VALUE).set("slave-config");
        domainSlaveLifecycleUtil.getDomainClient().execute(setSystemProperty);
        systemPropertyAddress = PathAddress.pathAddress().append(SERVER_GROUP, "main-server-group").append(SYSTEM_PROPERTY, "main");
        setSystemProperty = Util.createAddOperation(systemPropertyAddress);
        setSystemProperty.get(VALUE).set("main-config");
        domainMasterLifecycleUtil.getDomainClient().execute(setSystemProperty);
        List<ModelNode> changesOnSlaveHC = readConfigurationChanges(domainSlaveLifecycleUtil.getDomainClient(), HOST_SLAVE);
        List<ModelNode> changesOnSlaveDC = readConfigurationChanges(domainMasterLifecycleUtil.getDomainClient(), HOST_SLAVE);
        checkSlaveConfigurationChanges(changesOnSlaveHC, 12);
        setConfigurationChangeMaxHistory(domainMasterLifecycleUtil.getDomainClient(), HOST_SLAVE, 20);
        checkMaxHistorySize(domainMasterLifecycleUtil.getDomainClient(), 20, HOST_SLAVE, PathElement.pathElement(SERVER, "other-three"));
        checkMaxHistorySize(domainSlaveLifecycleUtil.getDomainClient(), 20, HOST_SLAVE, PathElement.pathElement(SERVER, "other-three"));
        assertThat(changesOnSlaveHC.size(), is(changesOnSlaveDC.size()));
    } finally {
        clearConfigurationChanges(HOST_SLAVE);
    }
}
 
Example #6
Source File: RemotingEndpointAdd.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void populateModel(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {

    // For any attribute where the value in 'operation' differs from the model in the
    // parent resource, add an immediate 'write-attribute' step against the parent
    PathAddress parentAddress = context.getCurrentAddress().getParent();
    ModelNode parentModel = context.readResourceFromRoot(parentAddress, false).getModel();
    OperationStepHandler writeHandler = null;
    ModelNode baseWriteOp = null;
    for (AttributeDefinition ad : RemotingEndpointResource.ATTRIBUTES.values()) {
        String attr = ad.getName();
        ModelNode parentVal = parentModel.get(attr);
        ModelNode opVal = operation.has(attr) ? operation.get(attr) : new ModelNode();
        if (!parentVal.equals(opVal)) {
            if (writeHandler == null) {
                writeHandler = context.getRootResourceRegistration().getOperationHandler(parentAddress, WRITE_ATTRIBUTE_OPERATION);
                baseWriteOp = Util.createEmptyOperation(WRITE_ATTRIBUTE_OPERATION, parentAddress);
            }
            ModelNode writeOp = baseWriteOp.clone();
            writeOp.get(NAME).set(attr);
            writeOp.get(VALUE).set(opVal);
            context.addStep(writeOp, writeHandler, OperationContext.Stage.MODEL, true);
        }
    }
}
 
Example #7
Source File: StandaloneXml_13.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void parseNativeManagementInterface(XMLExtendedStreamReader reader, ModelNode address, List<ModelNode> list) throws XMLStreamException {
    final ModelNode operationAddress = address.clone();
    operationAddress.add(MANAGEMENT_INTERFACE, NATIVE_INTERFACE);
    final ModelNode addOp = Util.getEmptyOperation(ADD, operationAddress);

    // Handle attributes
    parseNativeManagementInterfaceAttributes(reader, addOp);

    // Handle elements
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        requireNamespace(reader, namespace);
        final Element element = Element.forName(reader.getLocalName());
        switch (element) {
            case SOCKET:
                throw ControllerLogger.ROOT_LOGGER.unsupportedElement(reader.getName(),reader.getLocation(), SOCKET_BINDING);
            case SOCKET_BINDING:
                parseNativeManagementSocketBinding(reader, addOp);
                break;
            default:
                throw unexpectedElement(reader);
        }
    }

    list.add(addOp);
}
 
Example #8
Source File: StandaloneDeploymentTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private ModelNode createAddOperation(KernelServices kernelServices, String name, String runtimeName, Boolean enabled, Boolean persistent, ModelNode content) throws Exception {
    ModelNode operation = Util.createOperation(DeploymentAddHandler.OPERATION_NAME, getPathAddress(name));
    if (runtimeName != null) {
        operation.get(RUNTIME_NAME).set(runtimeName);
    }
    if (enabled != null) {
        operation.get(ENABLED).set(enabled);
    }
    operation.get(CONTENT).add(content);

    //PERSISTENT is not exposed to users, it is deployment scanner only - so don't try to validate the operation with PERSISTENT set
    kernelServices.validateOperation(operation);
    if (persistent != null) {
        operation.get(PERSISTENT).set(persistent);
    }

    return operation;
}
 
Example #9
Source File: DeploymentRolloutFailureTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private ModelNode getDeploymentCompositeOp() throws MalformedURLException {
    ModelNode op = new ModelNode();
    op.get(OP).set(COMPOSITE);
    ModelNode steps = op.get(STEPS);

    ModelNode depAdd = Util.createAddOperation(PathAddress.pathAddress(DEPLOYMENT_PATH));
    ModelNode content = new ModelNode();
    content.get(URL).set(deployment.toURI().toURL().toString());
    depAdd.get(CONTENT).add(content);

    steps.add(depAdd);

    ModelNode sgAdd = Util.createAddOperation(PathAddress.pathAddress(MAIN_SERVER_GROUP, DEPLOYMENT_PATH));
    sgAdd.get(ENABLED).set(true);
    steps.add(sgAdd);
    return op;
}
 
Example #10
Source File: NewExtension.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) throws OperationFailedException {
    ModelNode properties = operation.remove("properties");

    ModelNode composite = Util.createEmptyOperation("composite", PathAddress.EMPTY_ADDRESS);
    ModelNode steps = composite.get("steps");
    steps.add(operation);

    for (ModelNode property : properties.asList()) {
        Property prop = property.asProperty();
        ModelNode addProp = Util.createAddOperation(address.append("property", prop.getName()));
        addProp.get("value").set(prop.getValue());
        steps.add(addProp);
    }

    return new TransformedOperation(composite, TransformedOperation.ORIGINAL_RESULT);
}
 
Example #11
Source File: StandaloneXml_9.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void parseNativeManagementInterface(XMLExtendedStreamReader reader, ModelNode address, List<ModelNode> list) throws XMLStreamException {
    final ModelNode operationAddress = address.clone();
    operationAddress.add(MANAGEMENT_INTERFACE, NATIVE_INTERFACE);
    final ModelNode addOp = Util.getEmptyOperation(ADD, operationAddress);

    // Handle attributes
    parseNativeManagementInterfaceAttributes(reader, addOp);

    // Handle elements
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        requireNamespace(reader, namespace);
        final Element element = Element.forName(reader.getLocalName());
        switch (element) {
            case SOCKET:
                throw ControllerLogger.ROOT_LOGGER.unsupportedElement(reader.getName(),reader.getLocation(), SOCKET_BINDING);
            case SOCKET_BINDING:
                parseNativeManagementSocketBinding(reader, addOp);
                break;
            default:
                throw unexpectedElement(reader);
        }
    }

    list.add(addOp);
}
 
Example #12
Source File: StandaloneDeploymentTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testDeploymentReplaceHandlerNoDeployment() throws Exception {
    KernelServices kernelServices = createKernelServices();

    ModelNode op = Util.createOperation(DeploymentReplaceHandler.OPERATION_NAME, PathAddress.EMPTY_ADDRESS);
    op.get(NAME).set("Test2");
    op.get(TO_REPLACE).set("Test1");
    kernelServices.executeForFailure(op);

    ModelTestUtils.checkOutcome(kernelServices.executeOperation(createAddOperation(kernelServices, "Test1", getByteContent(1, 2, 3, 4, 5))));
    kernelServices.executeForFailure(op);
    removeDeployment(kernelServices, "Test1");

    ModelTestUtils.checkOutcome(kernelServices.executeOperation(createAddOperation(kernelServices, "Test2", getByteContent(1, 2, 3, 4, 5))));
    kernelServices.executeForFailure(op);
}
 
Example #13
Source File: OperationCancellationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void cancel(DomainClient client, String host, String server, String opName,
                       OperationContext.ExecutionStatus targetStatus, long executionStart, boolean serverOpOnly) throws Exception {
    PathAddress address = PathAddress.pathAddress(PathElement.pathElement(HOST, host));
    if (server != null) {
        address = address.append(PathElement.pathElement(SERVER, server));
    }
    address = address.append(MGMT_CONTROLLER);

    final String opToCancel = findActiveOperation(client, address, opName, targetStatus, executionStart, serverOpOnly);
    address = address.append(PathElement.pathElement(ACTIVE_OPERATION, opToCancel));

    ModelNode result = executeForResult(Util.createEmptyOperation("cancel", address), client);

    boolean retVal = result.asBoolean();
    assertTrue(result.asString(), retVal);
}
 
Example #14
Source File: DomainDeploymentTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testRedeploy() throws Exception {
    KernelServices kernelServices = createKernelServices();

    ModelNode content = getInputStreamIndexContent();
    ModelNode op = createAddOperation(kernelServices, "Test1", content);
    op.get(ENABLED).set(true);
    ModelTestUtils.checkOutcome(kernelServices.executeOperation(op, new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5})));
    checkSingleDeployment(kernelServices, "Test1");

    op = Util.createOperation(DeploymentRedeployHandler.OPERATION_NAME, getPathAddress("Test1"));
    kernelServices.executeForFailure(op);

    op = Util.createOperation(DeploymentRemoveHandler.OPERATION_NAME, getPathAddress("Test1"));
    kernelServices.validateOperation(op);
    ModelTestUtils.checkOutcome(kernelServices.executeOperation(op));
    checkNoDeployments(kernelServices);
}
 
Example #15
Source File: SyslogAuditLogHandlerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<Void> handbackHolder) throws OperationFailedException {
    if (super.handleApplyAttributeRuntime(context, operation, attributeName, resolvedValue, currentValue, handbackHolder)) {
        return false;
    }

    if (attributeName.equals(APP_NAME.getName())) {
        auditLogger.updateSyslogHandlerAppName(Util.getNameFromAddress(operation.require(OP_ADDR)), resolveAppName(context, operation.get(VALUE), environmentReader));
    } else if (attributeName.equals(FACILITY.getName())) {
        auditLogger.updateSyslogHandlerFacility(Util.getNameFromAddress(operation.require(OP_ADDR)), Facility.valueOf(resolvedValue.asString()));
    } else if (attributeName.equals(RECONNECT_TIMEOUT)) {
        PathAddress addr = PathAddress.pathAddress(operation.require(OP_ADDR));
        addr = addr.subAddress(0, addr.size() - 1);
        auditLogger.updateSyslogHandlerReconnectTimeout(Util.getNameFromAddress(addr), resolvedValue.asInt());
    } else if (attributeName.equals(KEYSTORE_PASSWORD_CREDENTIAL_REFERENCE_NAME) || attributeName.equals(KEY_PASSWORD_CREDENTIAL_REFERENCE_NAME)) {
        return applyCredentialReferenceUpdateToRuntime(context, operation, resolvedValue, currentValue, attributeName);
    } else {
        auditLogger.getUpdater().updateHandler(createHandler(pathManager, context, environmentReader));
    }
    return false;
}
 
Example #16
Source File: AbstractAuditLogHandlerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected ModelNode createAddSyslogHandlerTcpOperation(String handlerName, String formatterName, InetAddress addr, int port, SyslogHandler.SyslogType syslogFormat, SyslogAuditLogHandler.MessageTransfer transfer){
    ModelNode composite = new ModelNode();
    composite.get(OP).set(COMPOSITE);
    composite.get(OP_ADDR).setEmptyList();
    composite.get(STEPS).setEmptyList();

    ModelNode handler = Util.createAddOperation(createSyslogHandlerAddress(handlerName));
    if (syslogFormat != null){
        handler.get(SYSLOG_FORMAT).set(syslogFormat.toString());
    }
    handler.get(ModelDescriptionConstants.FORMATTER).set(formatterName);
    composite.get(STEPS).add(handler);

    ModelNode protocol = Util.createAddOperation(createSyslogHandlerProtocolAddress(handlerName, SyslogAuditLogHandler.Transport.TCP));
    protocol.get(HOST).set(InetAddressUtil.canonize(addr.getHostName()));
    protocol.get(PORT).set(port);
    if (transfer != null) {
        protocol.get(MESSAGE_TRANSFER).set(transfer.name());
    }
    composite.get(STEPS).add(protocol);

    return composite;
}
 
Example #17
Source File: ReadConfigAsFeaturesDomainTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void hostSubsystemTest() {
    ModelNode redefineJmxAttribute = Util.getWriteAttributeOperation(
            PathAddress.pathAddress(HOST, MASTER).append(SUBSYSTEM, "jmx").append("expose-model", "resolved"),
            "domain-name", "customDomainName");

    ModelNode expectedHostConfigAsFeatures = defaultHostConfigAsFeatures.clone();

    ModelNode jmxSubsystem = getFeatureNodeChild(expectedHostConfigAsFeatures.get(0), "host.subsystem.jmx");
    ModelNode exposeModelResolved = getFeatureNodeChild(jmxSubsystem, "host.subsystem.jmx.expose-model.resolved");
    ModelNode exposeModelResolvedParams = new ModelNode();
    exposeModelResolvedParams.get("domain-name").set("customDomainName");
    exposeModelResolved.get(PARAMS).set(exposeModelResolvedParams);

    doTest(Collections.singletonList(redefineJmxAttribute), expectedHostConfigAsFeatures, PathAddress.pathAddress(HOST, MASTER));
}
 
Example #18
Source File: ProcessStateListenerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@AfterClass
public static void tearDown() throws Exception {
    try {
        controller.startInAdminMode();
        // cleanup resources added for reload-required tests
        cleanupAfterReloadRequired();
        // remove listener
        controller.getClient().executeForResult(Util.createRemoveOperation(LISTENER_ADDRESS));
    } finally {
        controller.stop();
    }
    module.remove();
    PathUtil.deleteSilentlyRecursively(data);
}
 
Example #19
Source File: AutoIgnoredResourcesDomainTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void test12_AddServerGroupAndServerConfigPullsDownDataFromDcWithDcLockTaken() throws Exception {
    ModelNode addGroupOp = Util.createAddOperation(PathAddress.pathAddress(PathElement.pathElement(SERVER_GROUP, "testgroup")));
    addGroupOp.get(PROFILE).set(PROFILE3);
    addGroupOp.get(SOCKET_BINDING_GROUP).set(SOCKETS3);
    validateResponse(masterClient.execute(createDcLockTakenComposite(addGroupOp)), false);

    //New data should not be pushed yet since nothing on the slave uses it
    checkSlaveProfiles(PROFILE2, ROOT_PROFILE2);
    checkSlaveExtensions(EXTENSION_LOGGING);
    checkSlaveServerGroups(GROUP2);
    checkSlaveSocketBindingGroups(SOCKETSA, SOCKETS2, ROOT_SOCKETS2);
    checkSystemProperties(3); //Composite added a property
    Assert.assertEquals("running", getSlaveServerStatus(SERVER1));

    ModelNode addConfigOp = Util.createAddOperation(PathAddress.pathAddress(getSlaveServerConfigAddress("testserver")));
    addConfigOp.get(GROUP).set("testgroup");
    validateResponse(slaveClient.execute(createDcLockTakenComposite(addConfigOp)), false);

    //Now that we have a group using the new data it should be pulled down
    checkSlaveProfiles(PROFILE2, ROOT_PROFILE2, PROFILE3);
    checkSlaveExtensions(EXTENSION_LOGGING, EXTENSION_JMX);
    checkSlaveServerGroups(GROUP2, "testgroup");
    checkSlaveSocketBindingGroups(SOCKETSA, SOCKETS2, SOCKETS3, ROOT_SOCKETS2);
    checkSystemProperties(4); //Composite added a property
    Assert.assertEquals("running", getSlaveServerStatus(SERVER1));
}
 
Example #20
Source File: StandaloneXml_13.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void parseHttpManagementInterface(XMLExtendedStreamReader reader, ModelNode address, List<ModelNode> list) throws XMLStreamException {
    final ModelNode operationAddress = address.clone();
    operationAddress.add(MANAGEMENT_INTERFACE, HTTP_INTERFACE);
    final ModelNode addOp = Util.getEmptyOperation(ADD, operationAddress);

    // Handle attributes
    parseHttpManagementInterfaceAttributes(reader, addOp);

    // Handle elements
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        requireNamespace(reader, namespace);
        final Element element = Element.forName(reader.getLocalName());
        switch (element) {
            case SOCKET:
                throw ControllerLogger.ROOT_LOGGER.unsupportedElement(reader.getName(),reader.getLocation(), SOCKET_BINDING);
            case SOCKET_BINDING:
                parseHttpManagementSocketBinding(reader, addOp);
                break;
            case HTTP_UPGRADE:
                parseHttpUpgrade(reader, addOp);
                break;
            case CONSTANT_HEADERS:
                parseConstantHeaders(reader, addOp);
                break;
            default:
                throw unexpectedElement(reader);
        }
    }

    list.add(addOp);
}
 
Example #21
Source File: RbacUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void removeHostScopedRole(ModelControllerClient client, String roleName) throws IOException {
    ModelNode operation = Util.createOperation(REMOVE, pathAddress(
            pathElement(CORE_SERVICE, MANAGEMENT),
            pathElement(ACCESS, ModelDescriptionConstants.AUTHORIZATION),
            pathElement(HOST_SCOPED_ROLE, roleName)
    ));
    executeOperation(client, operation, Outcome.SUCCESS);
}
 
Example #22
Source File: HcExtensionAndSubsystemManagementTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private boolean reloadHostsIfReloadRequired(DomainLifecycleUtil util, PathAddress address) throws Exception {
    DomainClient client = util.getDomainClient();
    String state = DomainTestUtils.executeForResult(Util.getReadAttributeOperation(address, HOST_STATE), client).asString();
    if (!state.equals("running")) {
        ModelNode reload = Util.createEmptyOperation("reload", address);
        reload.get(RESTART_SERVERS).set(false);
        util.executeAwaitConnectionClosed(reload);
        util.connect();
        util.awaitHostController(System.currentTimeMillis());
        awaitServers(util, address.getLastElement().getValue());
        return true;
    }
    return false;
}
 
Example #23
Source File: AbstractMgmtTestBase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected ModelNode executeAndRollbackOperation(final ModelNode op) throws IOException {

        ModelNode broken = Util.createOperation("read-attribute", PathAddress.EMPTY_ADDRESS);
        broken.get("no-such-attribute").set("fail");

        /*ModelNode addDeploymentOp = createOpNode("deployment=malformedDeployment.war", "add");
        addDeploymentOp.get("content").get(0).get("input-stream-index").set(0);

        DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
        builder.setOperationName("deploy");
        builder.addNode("deployment", "malformedDeployment.war");


        ModelNode[] steps = new ModelNode[3];
        steps[0] = op;
        steps[1] = addDeploymentOp;
        steps[2] = builder.buildRequest();
        ModelNode compositeOp = ModelUtil.createCompositeNode(steps);

        OperationBuilder ob = new OperationBuilder(compositeOp, true);
        ob.addInputStream(new FileInputStream(getBrokenWar()));*/

        ModelNode[] steps = new ModelNode[2];
        steps[0] = op;
        steps[1] = broken;
        ModelNode compositeOp = ModelUtil.createCompositeNode(steps);
        OperationBuilder ob = new OperationBuilder(compositeOp, true);

        return getModelControllerClient().execute(ob.build());
    }
 
Example #24
Source File: ConfigurationChangesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testEnablingConfigurationChangesOnHC() throws Exception {
    DomainClient client = domainMasterLifecycleUtil.getDomainClient();
    try {
        final ModelNode add = Util.createAddOperation(PathAddress.pathAddress().append(HOST_SLAVE).append(getAddress()));
        add.get("max-history").set(MAX_HISTORY_SIZE);
        executeForResult(client, add);
    } finally {
        clearConfigurationChanges(HOST_SLAVE);
    }
}
 
Example #25
Source File: ExtensionSetup.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void removeExtensionAndSubsystem(final ManagementClient client) throws IOException, MgmtOperationException {
    //removeResources(client);
    ModelNode removeSubsystem = Util.createRemoveOperation(PathAddress.pathAddress(SUBSYSTEM, "rbac"));
    removeSubsystem.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true);
    executeForResult(client.getControllerClient(), removeSubsystem);
    ModelNode removeExtension = Util.createRemoveOperation(PathAddress.pathAddress(EXTENSION, TestExtension.MODULE_NAME));
    removeExtension.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true);
    executeForResult(client.getControllerClient(), removeExtension);
}
 
Example #26
Source File: OperationTimeoutTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private String findActiveOperation(DomainClient client, PathAddress address, String opName, OperationContext.ExecutionStatus targetStatus, long executionStart, boolean serverOpOnly) throws Exception {
    ModelNode op = Util.createEmptyOperation(READ_CHILDREN_RESOURCES_OPERATION, address);
    op.get(CHILD_TYPE).set(ACTIVE_OPERATION);
    long maxTime = TimeoutUtil.adjust(5000);
    long timeout = executionStart + maxTime;
    List<String> activeOps = new ArrayList<String>();
    String opToCancel = null;
    do {
        activeOps.clear();
        ModelNode result = executeForResult(op, client);
        if (result.isDefined()) {
            assertEquals(result.asString(), ModelType.OBJECT, result.getType());
            for (Property prop : result.asPropertyList()) {
                if (prop.getValue().get(OP).asString().equals(opName)) {
                    PathAddress pa = PathAddress.pathAddress(prop.getValue().get(OP_ADDR));
                    if (!serverOpOnly || pa.size() > 2 && pa.getElement(1).getKey().equals(SERVER)) {
                        activeOps.add(prop.getName() + " -- " + prop.getValue().toString());
                        if (targetStatus == null || prop.getValue().get(EXECUTION_STATUS).asString().equals(targetStatus.toString())) {
                            opToCancel = prop.getName();
                        }
                    }
                }
            }
        }
        if (opToCancel == null) {
            Thread.sleep(50);
        }

    } while ((opToCancel == null || activeOps.size() > 1) && System.currentTimeMillis() <= timeout);

    assertTrue(opName + " not present after " + maxTime + " ms", activeOps.size() > 0);
    assertEquals("Multiple instances of " + opName + " present: " + activeOps, 1, activeOps.size());
    assertNotNull(opName + " not in status " + targetStatus + " after " + maxTime + " ms", opToCancel);

    return opToCancel;
}
 
Example #27
Source File: PathAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static ModelNode getAddPathOperation(PathAddress address, ModelNode path, ModelNode relativeTo) {
    ModelNode op = Util.createAddOperation(address);
    if (path.isDefined()) {
        op.get(PATH_SPECIFIED.getName()).set(path);
    }
    if (relativeTo.isDefined()) {
        op.get(RELATIVE_TO.getName()).set(relativeTo);
    }
    return op;
}
 
Example #28
Source File: DisappearingResourceTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testReadChildrenResourcesAllDisappearing() throws Exception {
    discardC = true;
    attributeOutLatch.countDown();

    ModelNode op = Util.createOperation(READ_CHILDREN_RESOURCES_OPERATION, PARENT_ADDRESS);
    op.get(CHILD_TYPE).set(CHILD);
    op.get(INCLUDE_RUNTIME).set(true);
    ModelNode result = executeForResult(op);
    assertEquals(result.toString(), ModelType.OBJECT, result.getType());
    assertEquals(result.toString(), 0, result.asInt());
}
 
Example #29
Source File: AdminOnlyPolicyTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void validateProfiles(String... expectedNames) throws IOException {
    Set<String> set = new HashSet<String>(Arrays.asList(expectedNames));
    ModelNode op = Util.createEmptyOperation(ModelDescriptionConstants.READ_CHILDREN_NAMES_OPERATION, PathAddress.EMPTY_ADDRESS);
    op.get(ModelDescriptionConstants.CHILD_TYPE).set(ModelDescriptionConstants.PROFILE);
    ModelNode result = executeForResult(domainSlaveLifecycleUtil.getDomainClient(), op);
    Assert.assertEquals(result.toString(), ModelType.LIST, result.getType());
    Assert.assertEquals(result.toString(), set.size(), result.asInt());
    for (ModelNode profile : result.asList()) {
        String name = profile.asString();
        Assert.assertTrue(name, set.remove(name));
    }
    Assert.assertTrue(set.toString(), set.isEmpty());
}
 
Example #30
Source File: AuditLogXml_Legacy.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void parseFileAuditLogHandler(final XMLExtendedStreamReader reader, final ModelNode address, final List<ModelNode> list) throws XMLStreamException {
    final ModelNode add = Util.createAddOperation();
    list.add(add);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        }
        final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
        switch (attribute) {
            case NAME: {
                add.get(OP_ADDR).set(address).add(ModelDescriptionConstants.FILE_HANDLER, value);
                break;
            }
            case MAX_FAILURE_COUNT: {
                FileAuditLogHandlerResourceDefinition.MAX_FAILURE_COUNT.parseAndSetParameter(value, add, reader);
                break;
            }
            case FORMATTER:{
                FileAuditLogHandlerResourceDefinition.FORMATTER.parseAndSetParameter(value, add, reader);
                break;
            }
            case PATH: {
                FileAuditLogHandlerResourceDefinition.PATH.parseAndSetParameter(value, add, reader);
                break;
            }
            case RELATIVE_TO: {
                FileAuditLogHandlerResourceDefinition.RELATIVE_TO.parseAndSetParameter(value, add, reader);
                break;
            }
            default: {
                throw unexpectedAttribute(reader, i);
            }
        }
    }

    requireNoContent(reader);
}