Search in sources :

Example 76 with ModelControllerClient

use of org.jboss.as.controller.client.ModelControllerClient in project wildfly by wildfly.

the class ResourceAdapterOperationsUnitTestCase method configureElytron.

@BeforeClass
public static void configureElytron() throws Exception {
    try (ModelControllerClient client = TestSuiteEnvironment.getModelControllerClient()) {
        addAuth(client, "AuthCtxt");
        addAuth(client, "AuthCtxtAndApp");
    }
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) BeforeClass(org.junit.BeforeClass)

Example 77 with ModelControllerClient

use of org.jboss.as.controller.client.ModelControllerClient in project wildfly by wildfly.

the class RankedAffinityTestCase method test.

/**
 * Test ranked routing by (1) creating a session on a node, (2) disabling the node that served the request using the load
 * balancer API and (3) verifying correct affinity on subsequent request.
 */
@Test
public void test(@ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL) throws Exception {
    URL lbURL = new URL(baseURL.getProtocol(), baseURL.getHost(), baseURL.getPort() + 500, baseURL.getFile());
    URI lbURI = SimpleServlet.createURI(lbURL);
    establishTopology(baseURL, THREE_NODES);
    try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) {
        String[] previousAffinities;
        int value = 1;
        // 1
        HttpResponse response = client.execute(new HttpGet(lbURI));
        try {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertEquals(value++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue()));
            Map.Entry<String, String> entry = parseSessionRoute(response);
            previousAffinities = entry.getValue().split("\\.");
            log.debugf("Response #1: %s", response);
            Assert.assertNotNull(entry);
            Assert.assertEquals(entry.getKey(), response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue());
        } finally {
            HttpClientUtils.closeQuietly(response);
        }
        // TODO remove workaround for "UNDERTOW-1585 mod_cluster nodes are added in ERROR state" for which we need to wait until first status for ranked affinity to work
        Thread.sleep(3_000);
        // 2
        ModelControllerClient lbModelControllerClient = TestSuiteEnvironment.getModelControllerClient(null, TestSuiteEnvironment.getServerAddress(), TestSuiteEnvironment.getServerPort() + 500);
        try (ManagementClient lbManagementClient = new ManagementClient(lbModelControllerClient, TestSuiteEnvironment.getServerAddress(), TestSuiteEnvironment.getServerPort() + 500, "remote+http")) {
            String node = previousAffinities[0];
            ModelNode operation = new ModelNode();
            operation.get(OP).set(ModelDescriptionConstants.STOP);
            PathAddress address = PathAddress.parseCLIStyleAddress(String.format("/subsystem=undertow/configuration=filter/mod-cluster=load-balancer/balancer=%s/node=%s", BALANCER_NAME, node));
            operation.get(OP_ADDR).set(address.toModelNode());
            ModelNode result = lbManagementClient.getControllerClient().execute(operation);
            log.debugf("Running operation: %s", operation.toJSONString(false));
            Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
            log.debugf("Operation result: %s", result.toJSONString(false));
            operation = new ModelNode();
            operation.get(OP).set(ModelDescriptionConstants.READ_RESOURCE_OPERATION);
            address = PathAddress.parseCLIStyleAddress("/subsystem=undertow/configuration=filter/mod-cluster=load-balancer");
            operation.get(OP_ADDR).set(address.toModelNode());
            operation.get(ModelDescriptionConstants.RECURSIVE).set(ModelNode.TRUE);
            operation.get(ModelDescriptionConstants.INCLUDE_RUNTIME).set(ModelNode.TRUE);
            result = lbManagementClient.getControllerClient().execute(operation);
            log.debugf("Running operation: %s", operation.toJSONString(false));
            Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
            log.debugf("Operation result: %s", result.toJSONString(false));
            Thread.sleep(GRACE_TIME_TOPOLOGY_CHANGE);
            // 3
            response = client.execute(new HttpGet(lbURI));
            try {
                Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
                Assert.assertEquals(value++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue()));
                Assert.assertEquals("The subsequent request should have been served by the 2nd node in the affinity list", previousAffinities[1], response.getFirstHeader(SimpleServlet.HEADER_NODE_NAME).getValue());
            } finally {
                HttpClientUtils.closeQuietly(response);
            }
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) URL(java.net.URL) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ManagementClient(org.jboss.as.arquillian.container.ManagementClient) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map) Test(org.junit.Test)

Example 78 with ModelControllerClient

use of org.jboss.as.controller.client.ModelControllerClient in project wildfly by wildfly.

the class HTTPSWebConnectorTestCase method serverSetup.

private void serverSetup(ManagementClient managementClient) throws Exception {
    FileUtils.deleteDirectory(WORK_DIR);
    WORK_DIR.mkdirs();
    Utils.createKeyMaterial(WORK_DIR);
    // Uncomment if TRACE logging is necessary. Don't leave it on all the time; CI resources aren't free.
    // TRACE_SECURITY.setup(managementClient, null);
    SecurityDomainsSetup.INSTANCE.setup(managementClient, null);
    final ModelControllerClient client = managementClient.getControllerClient();
    // add new SSLContext
    ModelNode addSSLContexts = createAddSSLContexts();
    Utils.applyUpdate(addSSLContexts, client);
    LOGGER.trace("*** restarting server");
    containerController.stop(CONTAINER);
    containerController.start(CONTAINER);
    addHttpsConnector(SSL_CONTEXT_DEFAULT, HTTPS_NAME_VERIFY_NOT_REQUESTED, HTTPS_PORT_VERIFY_FALSE, client);
    addHttpsConnector(SSL_CONTEXT_WANT, HTTPS_NAME_VERIFY_REQUESTED, HTTPS_PORT_VERIFY_WANT, client);
    addHttpsConnector(SSL_CONTEXT_NEED, HTTPS_NAME_VERIFY_REQUIRED, HTTPS_PORT_VERIFY_TRUE, client);
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ModelNode(org.jboss.dmr.ModelNode)

Example 79 with ModelControllerClient

use of org.jboss.as.controller.client.ModelControllerClient in project wildfly by wildfly.

the class HTTPSWebConnectorTestCase method stopContainer.

@Test
@InSequence(3)
public void stopContainer() throws Exception {
    deployer.undeploy(APP_CONTEXT);
    final ModelControllerClient client = TestSuiteEnvironment.getModelControllerClient();
    final ManagementClient managementClient = new ManagementClient(client, TestSuiteEnvironment.getServerAddress(), TestSuiteEnvironment.getServerPort(), "remote+http");
    LOGGER.trace("*** reseting test configuration");
    serverTearDown(managementClient);
    LOGGER.trace("*** stopping container");
    containerController.stop(CONTAINER);
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ManagementClient(org.jboss.as.arquillian.container.ManagementClient) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 80 with ModelControllerClient

use of org.jboss.as.controller.client.ModelControllerClient in project wildfly by wildfly.

the class WSAttributesChangesTestCase method performWsdlHostAttributeTest.

private void performWsdlHostAttributeTest(boolean checkUpdateWithDeployedEndpoint) throws Exception {
    Assert.assertTrue(containerController.isStarted(DEFAULT_JBOSSAS));
    ManagementClient managementClient = new ManagementClient(TestSuiteEnvironment.getModelControllerClient(), TestSuiteEnvironment.getServerAddress(), TestSuiteEnvironment.getServerPort(), "remote+http");
    ModelControllerClient client = managementClient.getControllerClient();
    String initialWsdlHost = null;
    try {
        initialWsdlHost = getAttribute("wsdl-host", client);
        final String hostnameA = "foo-host-a";
        ModelNode op = createOpNode("subsystem=webservices/", WRITE_ATTRIBUTE_OPERATION);
        op.get(NAME).set("wsdl-host");
        op.get(VALUE).set(hostnameA);
        // update successful, no need to reload
        applyUpdate(client, op, false);
        // now we deploy an endpoint...
        deployer.deploy(DEP_1);
        // verify the updated wsdl host is used...
        URL wsdlURL = new URL(managementClient.getWebUri().toURL(), '/' + DEP_1 + "/POJOService?wsdl");
        checkWsdl(wsdlURL, hostnameA);
        if (checkUpdateWithDeployedEndpoint) {
            final String hostnameB = "foo-host-b";
            ModelNode opB = createOpNode("subsystem=webservices/", WRITE_ATTRIBUTE_OPERATION);
            opB.get(NAME).set("wsdl-host");
            opB.get(VALUE).set(hostnameB);
            // update again, but we'll need to reload, as there's an active deployment
            applyUpdate(client, opB, true);
            // check the wsdl host is still the one we updated to before
            checkWsdl(wsdlURL, hostnameA);
            // and check that still applies even if we undeploy and redeploy the endpoint
            deployer.undeploy(DEP_1);
            deployer.deploy(DEP_1);
            checkWsdl(wsdlURL, hostnameA);
        }
    } finally {
        try {
            deployer.undeploy(DEP_1);
        } catch (Throwable t) {
        // ignore
        }
        try {
            if (initialWsdlHost != null) {
                ModelNode op = createOpNode("subsystem=webservices/", WRITE_ATTRIBUTE_OPERATION);
                op.get(NAME).set("wsdl-host");
                op.get(VALUE).set(initialWsdlHost);
                applyUpdate(client, op, checkUpdateWithDeployedEndpoint);
            }
        } finally {
            managementClient.close();
        }
    }
}
Also used : ManagementClient(org.jboss.as.arquillian.container.ManagementClient) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ModelNode(org.jboss.dmr.ModelNode) URL(java.net.URL)

Aggregations

ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)106 ModelNode (org.jboss.dmr.ModelNode)61 Test (org.junit.Test)30 IOException (java.io.IOException)20 ManagementClient (org.jboss.as.arquillian.container.ManagementClient)19 PathAddress (org.jboss.as.controller.PathAddress)10 ArrayList (java.util.ArrayList)9 InSequence (org.jboss.arquillian.junit.InSequence)8 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)7 URL (java.net.URL)6 UnknownHostException (java.net.UnknownHostException)6 JMSOperations (org.jboss.as.test.integration.common.jms.JMSOperations)6 Before (org.junit.Before)6 WildFlyElytronProvider (org.wildfly.security.WildFlyElytronProvider)4 NamingException (javax.naming.NamingException)3 CommandContext (org.jboss.as.cli.CommandContext)3 OperationBuilder (org.jboss.as.controller.client.OperationBuilder)3 After (org.junit.After)3 File (java.io.File)2 InitialContext (javax.naming.InitialContext)2