Search in sources :

Example 21 with OperationBuilder

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

the class BasicVaultServerSetupTask method setup.

@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
    // clean directory and keystore
    VaultHandler.cleanFilesystem(RESOURCE_LOCATION, false, KEY_STORE_FILE);
    // create vault keystore
    vaultHandler = new VaultHandler(KEY_STORE_FILE, VAULT_PASSWORD, null, RESOURCE_LOCATION, 128, VAULT_ALIAS, "87654321", 20);
    ModelNode op = new ModelNode();
    // save original vault setting
    LOGGER.trace("Saving original vault setting");
    op = Util.getReadAttributeOperation(VAULT_PATH, VAULT_OPTIONS);
    originalVault = (managementClient.getControllerClient().execute(new OperationBuilder(op).build())).get(RESULT);
    // remove original vault
    if (originalVault.get("KEYSTORE_URL") != null && originalVault.hasDefined("KEYSTORE_URL")) {
        op = Util.createRemoveOperation(VAULT_PATH);
        CoreUtils.applyUpdate(op, managementClient.getControllerClient());
    }
    // create new vault
    LOGGER.trace("Creating new vault");
    String keystoreURL = vaultHandler.getKeyStore();
    String encryptionDirectory = new File(RESOURCE_LOCATION).getAbsolutePath();
    String salt = "87654321";
    int iterationCount = 20;
    nonInteractiveSession = new VaultSession(keystoreURL, VAULT_PASSWORD, encryptionDirectory, salt, iterationCount);
    nonInteractiveSession.startVaultSession(VAULT_ALIAS);
    // create security attributes
    LOGGER.trace("Inserting attribute " + VAULT_ATTRIBUTE + " to vault");
    nonInteractiveSession.addSecuredAttribute(VAULT_BLOCK, ATTRIBUTE_NAME, VAULT_ATTRIBUTE.toCharArray());
    // create new vault setting in standalone
    op = Util.createAddOperation(VAULT_PATH);
    ModelNode vaultOption = op.get(VAULT_OPTIONS);
    vaultOption.get("KEYSTORE_URL").set(keystoreURL);
    if (externalVaultPassword != null) {
        vaultOption.get("KEYSTORE_PASSWORD").set(externalVaultPassword);
    } else {
        vaultOption.get("KEYSTORE_PASSWORD").set(nonInteractiveSession.getKeystoreMaskedPassword());
    }
    vaultOption.get("KEYSTORE_ALIAS").set(VAULT_ALIAS);
    vaultOption.get("SALT").set(salt);
    vaultOption.get("ITERATION_COUNT").set(Integer.toString(iterationCount));
    vaultOption.get("ENC_FILE_DIR").set(encryptionDirectory);
    CoreUtils.applyUpdate(op, managementClient.getControllerClient());
    LOGGER.debug("Vault created in server configuration");
}
Also used : OperationBuilder(org.jboss.as.controller.client.OperationBuilder) VaultSession(org.jboss.as.security.vault.VaultSession) ModelNode(org.jboss.dmr.ModelNode) File(java.io.File)

Example 22 with OperationBuilder

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

the class Utils method applyUpdate.

public static void applyUpdate(ModelNode update, final ModelControllerClient client) throws Exception {
    ModelNode result = client.execute(new OperationBuilder(update).build());
    if (LOGGER.isInfoEnabled()) {
        LOGGER.trace("Client update: " + update);
        LOGGER.trace("Client update result: " + result);
    }
    if (result.hasDefined("outcome") && "success".equals(result.get("outcome").asString())) {
        LOGGER.debug("Operation succeeded.");
    } else if (result.hasDefined("failure-description")) {
        throw new RuntimeException(result.get("failure-description").toString());
    } else {
        throw new RuntimeException("Operation not successful; outcome = " + result.get("outcome"));
    }
}
Also used : OperationBuilder(org.jboss.as.controller.client.OperationBuilder) ModelNode(org.jboss.dmr.ModelNode)

Example 23 with OperationBuilder

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

the class SSOTestBase method restartServer.

// Reload operation is not handled well by Arquillian
// See ARQ-791: JMX: Arquillian is unable to reconnect to JMX server if the connection is lost
public static void restartServer(final ModelControllerClient client) {
    try {
        applyUpdates(Arrays.asList(createOpNode(null, "reload")), client);
    } catch (Exception e) {
        throw new RuntimeException("Restart operation not successful. " + e.getMessage());
    }
    try {
        RetryTaskExecutor<Boolean> rte = new RetryTaskExecutor<>();
        rte.retryTask(new Callable<Boolean>() {

            public Boolean call() throws Exception {
                ModelNode readOp = createOpNode(null, READ_ATTRIBUTE_OPERATION);
                readOp.get("name").set("server-state");
                ModelNode result = client.execute(new OperationBuilder(readOp).build());
                if (result.hasDefined("outcome") && "success".equals(result.get("outcome").asString())) {
                    if ((result.hasDefined("result")) && (result.get("result").asString().equals("running")))
                        return true;
                }
                log.trace("Server is down.");
                throw new Exception("Connector not available.");
            }
        });
    } catch (TimeoutException e) {
        throw new RuntimeException("Timeout on restart operation. " + e.getMessage());
    }
    log.trace("Server is up.");
}
Also used : OperationBuilder(org.jboss.as.controller.client.OperationBuilder) ModelNode(org.jboss.dmr.ModelNode) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) RetryTaskExecutor(org.jboss.as.test.shared.RetryTaskExecutor) TimeoutException(java.util.concurrent.TimeoutException)

Example 24 with OperationBuilder

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

the class BadResourceTestCase method createDeployment.

@Before
public void createDeployment() throws Exception {
    final ModelNode addDeploymentOp = new ModelNode();
    addDeploymentOp.get(ModelDescriptionConstants.ADDRESS).add(ModelDescriptionConstants.DEPLOYMENT, Constants.TESTED_DU_NAME);
    addDeploymentOp.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD);
    addDeploymentOp.get(ModelDescriptionConstants.CONTENT).get(0).get(ModelDescriptionConstants.INPUT_STREAM_INDEX).set(0);
    final OperationBuilder ob = new OperationBuilder(addDeploymentOp, true);
    ob.addInputStream(getTestedArchive().as(ZipExporter.class).exportAsInputStream());
    final ModelNode result = controllerClient.execute(ob.build());
    // just to blow up
    Assert.assertTrue("Failed to deploy: " + result, Operations.isSuccessfulOutcome(result));
}
Also used : OperationBuilder(org.jboss.as.controller.client.OperationBuilder) ModelNode(org.jboss.dmr.ModelNode) Before(org.junit.Before)

Example 25 with OperationBuilder

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

the class BadResourceTestCase method removeDeployment.

@After
public void removeDeployment() throws Exception {
    final ModelNode remove = Util.getEmptyOperation(ModelDescriptionConstants.REMOVE, new ModelNode().add(ModelDescriptionConstants.DEPLOYMENT, Constants.TESTED_DU_NAME));
    final OperationBuilder ob = new OperationBuilder(remove, true);
    final ModelNode result = controllerClient.execute(ob.build());
    // just to blow up
    Assert.assertTrue("Failed to deploy: " + result, Operations.isSuccessfulOutcome(result));
}
Also used : OperationBuilder(org.jboss.as.controller.client.OperationBuilder) ModelNode(org.jboss.dmr.ModelNode) After(org.junit.After)

Aggregations

OperationBuilder (org.jboss.as.controller.client.OperationBuilder)43 ModelNode (org.jboss.dmr.ModelNode)42 Test (org.junit.Test)17 IOException (java.io.IOException)7 EnterpriseArchive (org.jboss.shrinkwrap.api.spec.EnterpriseArchive)7 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)6 BeforeClass (org.junit.BeforeClass)6 Before (org.junit.Before)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 DefaultOperationRequestBuilder (org.jboss.as.cli.operation.impl.DefaultOperationRequestBuilder)1 DomainClient (org.jboss.as.controller.client.helpers.domain.DomainClient)1 VaultSession (org.jboss.as.security.vault.VaultSession)1 VaultHandler (org.jboss.as.test.integration.security.common.VaultHandler)1 RetryTaskExecutor (org.jboss.as.test.shared.RetryTaskExecutor)1 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)1