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");
}
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"));
}
}
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.");
}
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));
}
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));
}
Aggregations