Search in sources :

Example 86 with ModelControllerClient

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

the class DomainHostExcludesTest method test003PostBootUpdates.

@Test
public void test003PostBootUpdates() throws IOException, MgmtOperationException {
    ModelControllerClient masterClient = testSupport.getDomainMasterLifecycleUtil().getDomainClient();
    ModelControllerClient slaveClient = testSupport.getDomainSlaveLifecycleUtil().getDomainClient();
    // Tweak an ignored profile and socket-binding-group to prove slave doesn't see it
    updateExcludedProfile(masterClient);
    updateExcludedSocketBindingGroup(masterClient);
    // Verify profile cloning is ignored when the cloned profile is excluded
    testProfileCloning(masterClient, slaveClient);
    // Add more ignored extensions to verify slave doesn't see the ops
    addExtensions(false, masterClient);
    checkExtensions(slaveClient);
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) Test(org.junit.Test)

Example 87 with ModelControllerClient

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

the class ServerHelper method readLogFileFromModel.

public static List<JsonObject> readLogFileFromModel(final String logFileName, final String... addressPrefix) throws IOException {
    final Collection<String> addr = new ArrayList<>();
    if (addressPrefix != null) {
        Collections.addAll(addr, addressPrefix);
    }
    addr.add("subsystem");
    addr.add("logging");
    addr.add("log-file");
    addr.add(logFileName);
    final ModelNode address = Operations.createAddress(addr);
    final ModelNode op = Operations.createReadAttributeOperation(address, "stream");
    try (ModelControllerClient client = TestSuiteEnvironment.getModelControllerClient()) {
        final OperationResponse response = client.executeOperation(Operation.Factory.create(op), OperationMessageHandler.logging);
        final ModelNode result = response.getResponseNode();
        if (Operations.isSuccessfulOutcome(result)) {
            final OperationResponse.StreamEntry entry = response.getInputStream(Operations.readResult(result).asString());
            if (entry == null) {
                throw new RuntimeException(String.format("Failed to find entry with UUID %s for log file %s", Operations.readResult(result).asString(), logFileName));
            }
            final List<JsonObject> lines = new ArrayList<>();
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(entry.getStream(), StandardCharsets.UTF_8))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    try (JsonReader jsonReader = Json.createReader(new StringReader(line))) {
                        lines.add(jsonReader.readObject());
                    }
                }
            }
            return lines;
        }
        throw new RuntimeException(String.format("Failed to read log file %s: %s", logFileName, Operations.getFailureDescription(result).asString()));
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) JsonObject(javax.json.JsonObject) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader) ModelNode(org.jboss.dmr.ModelNode) OperationResponse(org.jboss.as.controller.client.OperationResponse)

Example 88 with ModelControllerClient

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

the class ScriptProcess method waitFor.

private void waitFor(final Process process, final Function<ModelControllerClient, Boolean> check) throws TimeoutException, InterruptedException {
    @SuppressWarnings("Convert2Lambda") final Callable<Boolean> callable = new Callable<Boolean>() {

        @Override
        public Boolean call() throws InterruptedException, IOException {
            long timeout = (ScriptProcess.this.timeout * 1000);
            final long sleep = 100L;
            try (ModelControllerClient client = TestSuiteEnvironment.getModelControllerClient()) {
                while (timeout > 0) {
                    if (!process.isAlive()) {
                        return false;
                    }
                    long before = System.currentTimeMillis();
                    if (check.apply(client)) {
                        return true;
                    }
                    timeout -= (System.currentTimeMillis() - before);
                    TimeUnit.MILLISECONDS.sleep(sleep);
                    timeout -= sleep;
                }
            }
            return false;
        }
    };
    final ExecutorService service = Executors.newSingleThreadExecutor();
    try {
        final Future<Boolean> future = service.submit(callable);
        if (!future.get()) {
            destroy(process);
            throw new TimeoutException(getErrorMessage(String.format("The %s did not start within %d seconds.", script.getFileName(), this.timeout)));
        }
    } catch (ExecutionException e) {
        throw new RuntimeException(getErrorMessage(String.format("Failed to determine if the %s server is running.", script.getFileName())), e);
    } finally {
        service.shutdownNow();
    }
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ExecutorService(java.util.concurrent.ExecutorService) ExecutionException(java.util.concurrent.ExecutionException) Callable(java.util.concurrent.Callable) TimeoutException(java.util.concurrent.TimeoutException)

Example 89 with ModelControllerClient

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

the class StatelessBean method getJBossProperty.

public String getJBossProperty(String name) {
    ModelControllerClient client = getClient();
    String result = Utils.getProperty(name, client);
    log.debug("JBoss system property " + name + " was resolved to be " + result);
    return result;
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient)

Example 90 with ModelControllerClient

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

the class GlobalDirectoryBasicTestCase method init.

@Before
public void init() throws Exception {
    prepareGlobalDirectory();
    controller.start(DEFAULT_JBOSSAS);
    final ModelControllerClient client = TestSuiteEnvironment.getModelControllerClient();
    managementClient = new ManagementClient(client, TestSuiteEnvironment.getServerAddress(), TestSuiteEnvironment.getServerPort(), "remote+http");
    setupServer(managementClient);
    deployer.deploy(DEPLOYMENT_WAR);
    deployer.deploy(DEPLOYMENT_EAR);
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ManagementClient(org.jboss.as.arquillian.container.ManagementClient) Before(org.junit.Before)

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