@Override public void setup(ManagementClient fakemanagementClient, String s) throws Exception { // Set path for users.properties and roles.properties setConfigurationPath(); // Create and initialize management client managementClient = TestUtil.clientInit(); administration = new Administration(managementClient); ops = new Operations(managementClient); if (subsystem.equals("elytron")) { configureElytron(); } else { configurePicketBox(); } }
/** * Reverts all configuration done for Elytron * @throws Exception */ private void cleanUpElytron() throws Exception { try { ops.removeIfExists(UNDERTOW_APPLICATION_SECURITY_DOMAIN_ADDRESS); ops.removeIfExists(ELYTRON_PROP_HTTP_AUTHENTICATION_FACTORY_ADDRESS); ops.removeIfExists(ELYTRON_SECURITY_DOMAIN_ADDRESS); ops.removeIfExists(ELYTRON_PROPERTIES_REALM_ADDRESS); administration.reloadIfRequired(); } finally { managementClient.close(); } }
ops.add(ELYTRON_PROPERTIES_REALM_ADDRESS, Values.empty() .andObject("users-properties", Values.empty() .and("path", USERS_FILE.getAbsolutePath()) assertTrue("The elytron/properties-realm should be created", ops.exists(ELYTRON_PROPERTIES_REALM_ADDRESS)); assertTrue("The elytron/security-domain should be created", ops.exists(ELYTRON_SECURITY_DOMAIN_ADDRESS)); assertTrue("The elytron/http-authentication-factory should be created", ops.exists(ELYTRON_PROP_HTTP_AUTHENTICATION_FACTORY_ADDRESS)); assertTrue("The undertow/application-security-domain should be created", ops.exists(UNDERTOW_APPLICATION_SECURITY_DOMAIN_ADDRESS));
public void addConfigurations(String cacheContainer) throws Exception { ops.add(Address.subsystem("datagrid-infinispan") .and("cache-container", cacheContainer) .and("configurations", "CONFIGURATIONS"), Values.empty()); }
private void enableTransactionConfiguration(String configurationName, String containerName, Map<String, String> txAttr, CacheTemplate template) throws IOException { //Adding transaction conf to created cache configuration ops.add(Address.subsystem("datagrid-infinispan") .and("cache-container", containerName) .and("configurations", "CONFIGURATIONS") .and(template.getType(), configurationName) .and("transaction", "TRANSACTION")); //Adding attributes to transaction for (Map.Entry<String, String> attr : txAttr.entrySet()) { ops.writeAttribute(Address.subsystem("datagrid-infinispan") .and("cache-container", containerName) .and("configurations", "CONFIGURATIONS") .and(template.getType(), configurationName) .and("transaction", "TRANSACTION"), attr.getKey(), attr.getValue()); } }
/** * Returns the Java command the server / host controller was started with. It's read from the platform MBean * server via the management interface. * * @param host should be {@code null} for standalone server or for default host in managed domain; * should only be non-{@code null} if a specific host in managed domain is checked */ private static String commandUsedToStartTheServer(OnlineManagementClient client, String host) throws IOException { Address baseAddress = Address.root(); if (host != null) { baseAddress = Address.host(host); } ModelNodeResult systemProperties = new Operations(client).readAttribute( baseAddress.and(Constants.CORE_SERVICE, Constants.PLATFORM_MBEAN).and("type", "runtime"), "system-properties" ); systemProperties.assertDefinedValue(); // the "sun.java.command" system property exists at least on OpenJDK, Oracle Java and IBM Java return systemProperties.value().get("sun.java.command").asString(); }
@Override public ModelNodeResult perform(Operations ops, Address address) throws IOException { return ops.invoke(Constants.RELOAD, address); } },
List<String> allRunningServers(String host) throws IOException { ModelNodeResult result = ops.readChildrenNames(Address.host(host), Constants.SERVER); result.assertDefinedValue(); List<String> servers = result.stringListValue(); List<String> startedServers = new ArrayList<String>(); for (String server : servers) { ModelNodeResult serverStatus = ops.readAttribute(Address.host(host).and(Constants.SERVER_CONFIG, server), Constants.STATUS); serverStatus.assertDefinedValue(); if ("STARTED".equals(serverStatus.stringValue())) { startedServers.add(server); } } return startedServers; }
/** * @return {@code true} if the resource specified by {@code address} was actually removed (i.e., it used to exist), * {@code false} if it didn't exist and therefore wasn't actually removed * @throws OperationException if the underlying {@code remove} operation fails with something else than "not found" */ public boolean removeIfExists(Address address) throws IOException, OperationException { FailuresAllowedBlock expectedFailures = client.allowFailures(); try { ModelNodeResult result = remove(address); if (result.isSuccess()) { return true; } if (isResultUnknownOrNotFound(result)) { return false; } throw new OperationException("removeIfExists failed: " + result.asString()); } finally { expectedFailures.close(); } }
/** * @return {@code true} if the resource specified by {@code address} exists, {@code false} otherwise * @throws OperationException if the underlying {@code read-resource} operation fails */ public boolean exists(Address address) throws IOException, OperationException { FailuresAllowedBlock expectedFailures = client.allowFailures(); try { ModelNodeResult result = readResource(address); if (result.isSuccess()) { return result.hasDefinedValue(); // should always be true } if (isResultUnknownOrNotFound(result)) { return false; } throw new OperationException("exists failed: " + result.asString()); } finally { expectedFailures.close(); } }
void shutdown(String host, int timeoutInSeconds) throws IOException { if (timeoutInSeconds == 0) { // older versions don't understand the "timeout" parameter ops.invoke(Constants.SHUTDOWN, Address.host(host)); } else { Batch batch = new Batch(); for (String server : allRunningServers(host)) { batch.invoke(Constants.STOP, Address.host(host).and(Constants.SERVER_CONFIG, server), Values.of(Constants.TIMEOUT, timeoutInSeconds)); } batch.invoke(Constants.SHUTDOWN, Address.host(host)); ops.batch(batch); } }
void shutdownServers(String host, List<String> servers) throws IOException, InterruptedException, TimeoutException { Batch batch = new Batch(); for (String server : servers) { batch.invoke(Constants.STOP, Address.host(host).and(Constants.SERVER_CONFIG, server)); } ops.batch(batch); }
private boolean isRestartOperationRequired(CommonRestartOperation restartOperation) throws IOException { return restartOperation.isRequired(ops.readAttribute(Address.root(), Constants.SERVER_STATE), false); }
/** * Creates PicketBox security domain * @throws Exception */ private void configurePicketBox() throws Exception { // Create security domain AddSecurityDomain addSecurityDomain = new AddSecurityDomain.Builder(securityDomainName).build(); managementClient.apply(addSecurityDomain); // Create login module AddLoginModule addLoginModule = new AddLoginModule.Builder("org.jboss.security.auth.spi.UsersRolesLoginModule", PICKETBOX_LOGIN_MODULE_NAME) .securityDomainName(securityDomainName) .flag("required") .module("org.picketbox") .addModuleOption("usersProperties", USERS_FILE.getAbsolutePath()) .addModuleOption("rolesProperties", ROLES_FILE.getAbsolutePath()) .build(); managementClient.apply(addLoginModule); administration.reloadIfRequired(); assertTrue("The login module should be created", ops.exists(PICKETBOX_LOGIN_MODULE_ADDRESS)); }
static boolean isResultUnknownOrNotFound(ModelNodeResult result) { result.assertFailed(); ModelNode failureDescription = result.get(Constants.FAILURE_DESCRIPTION); if (failureDescription.hasDefined(Constants.HOST_FAILURE_DESCRIPTIONS)) { List<Property> hostFailures = failureDescription.get(Constants.HOST_FAILURE_DESCRIPTIONS).asPropertyList(); for (Property hostFailure : hostFailures) { if (isFailureDesriptionUnknownOrNotFound(hostFailure.getValue().asString())) { return true; } } return false; } else { if (failureDescription.hasDefined(Constants.DOMAIN_FAILURE_DESCRIPTION)) { failureDescription = failureDescription.get(Constants.DOMAIN_FAILURE_DESCRIPTION); } return isFailureDesriptionUnknownOrNotFound(failureDescription.asString()); } }
public void addSocketBinding(String name, String socketBindingGroup, int port) throws Exception { ops.add(Address.of("socket-binding-group", socketBindingGroup) .and("socket-binding", name), Values.empty() .and("port", port)); }
private void enableCompatibilityForConfiguration(String configurationName, String containerName, CacheTemplate template) throws Exception { //Adding compatibility conf to created cache configuration ops.add(Address.subsystem("datagrid-infinispan") .and("cache-container", containerName) .and("configurations", "CONFIGURATIONS") .and(template.getType(), configurationName) .and("compatibility", "COMPATIBILITY")); //Enabling compatibility ops.writeAttribute(Address.subsystem("datagrid-infinispan") .and("cache-container", containerName) .and("configurations", "CONFIGURATIONS") .and(template.getType(), configurationName) .and("compatibility", "COMPATIBILITY"), "enabled", true); }
@Override public ModelNodeResult perform(Operations ops, Address address) throws IOException { return ops.invoke(Constants.RELOAD, address, Values.of(Constants.DOMAIN_CONFIG, snapshot)); } }
void restartServers(String host, List<String> servers) throws IOException, InterruptedException, TimeoutException { Batch batch = new Batch(); for (String server : servers) { batch.invoke(Constants.RESTART, Address.host(host).and(Constants.SERVER_CONFIG, server)); } boolean needsToReconnect = false; try { ops.batch(batch); } catch (Throwable e) { // server went down before we received the response, this can happen needsToReconnect = true; } domainOps.waitUntilServersAreRunning(host, servers, needsToReconnect); }
private boolean isServerRunning() throws IOException { ModelNodeResult result = ops.readAttribute(Address.root(), Constants.SERVER_STATE); result.assertDefinedValue(); return ServerState.isRunning(result.stringValue()); } }