Java源码示例:org.jboss.as.controller.client.helpers.ClientConstants
示例1
private static void executeReload(ModelControllerClient client, boolean adminOnly) {
ModelNode operation = new ModelNode();
operation.get(OP_ADDR).setEmptyList();
operation.get(OP).set("reload");
operation.get("admin-only").set(adminOnly);
try {
ModelNode result = client.execute(operation);
if (!"success".equals(result.get(ClientConstants.OUTCOME).asString())) {
fail("Reload operation didn't finished successfully: " + result.asString());
}
} catch(IOException e) {
final Throwable cause = e.getCause();
if (!(cause instanceof ExecutionException) && !(cause instanceof CancellationException)) {
throw new RuntimeException(e);
} // else ignore, this might happen if the channel gets closed before we got the response
}
}
示例2
@Test
public void testFailedRuntimeOperationWithClearTextAttributeOnly() throws Exception {
addKeyStore();
try {
ModelNode operation = new ModelNode();
operation.get(ClientConstants.OP_ADDR).add("subsystem", "elytron").add("key-store", KS_NAME);
operation.get(ClientConstants.OP).set(ElytronDescriptionConstants.GENERATE_KEY_PAIR);
operation.get(ElytronDescriptionConstants.ALIAS).set("bsmith");
operation.get(ElytronDescriptionConstants.ALGORITHM).set("Invalid");
operation.get(ElytronDescriptionConstants.DISTINGUISHED_NAME).set("CN=bob smith, OU=jboss, O=red hat, L=raleigh, ST=north carolina, C=us");
operation.get(CredentialReference.CREDENTIAL_REFERENCE).get(CLEAR_TEXT).set("secret");
assertFailed(services.executeOperation(operation)).get(RESULT);
} finally {
removeKeyStore(KS_NAME);
}
}
示例3
private String generateKeyPairWithCredentialStoreUpdate(String keyStoreName, String store, String alias, String secret, boolean exists) {
ModelNode operation = new ModelNode();
operation.get(ClientConstants.OP_ADDR).add("subsystem", "elytron").add("key-store", keyStoreName);
operation.get(ClientConstants.OP).set(ElytronDescriptionConstants.GENERATE_KEY_PAIR);
operation.get(ElytronDescriptionConstants.ALIAS).set("bsmith");
operation.get(ElytronDescriptionConstants.DISTINGUISHED_NAME).set("CN=bob smith");
operation.get(CredentialReference.CREDENTIAL_REFERENCE).get(CredentialReference.STORE).set(store);
boolean autoGeneratedAlias = false;
if (alias != null) {
operation.get(CredentialReference.CREDENTIAL_REFERENCE).get(CredentialReference.ALIAS).set(alias);
} else {
autoGeneratedAlias = true;
}
if (secret != null) {
operation.get(CredentialReference.CREDENTIAL_REFERENCE).get(CredentialReference.CLEAR_TEXT).set(secret);
}
ModelNode response = assertSuccess(services.executeOperation(operation)).get(RESULT);
return validateResponse(response, secret, autoGeneratedAlias, exists);
}
示例4
private void testDeployment(final Archive<?> archive) throws IOException {
final ModelControllerClient client = domainMasterLifecycleUtil.getDomainClient();
final ModelNode readServerSubsystems = Operations.createOperation(ClientConstants.READ_CHILDREN_NAMES_OPERATION,
Operations.createAddress("host", "master", "server", "main-one"));
readServerSubsystems.get(ClientConstants.CHILD_TYPE).set(ClientConstants.SUBSYSTEM);
final String name = archive.getName();
// Deploy the archive
execute(client, createDeployAddOperation(archive.as(ZipExporter.class).exportAsInputStream(), name, null));
Assert.assertTrue("Deployment " + name + " was not deployed.", hasDeployment(client, name));
// Validate the subsystem child names on a server
ModelNode result = execute(client, readServerSubsystems);
validateSubsystemModel("/host=master/server=main-one", result);
// Fully replace the deployment, but with the 'enabled' flag set to false, triggering undeploy
final Operation fullReplaceOp = createReplaceAndDisableOperation(archive.as(ZipExporter.class).exportAsInputStream(), name, null);
execute(client, fullReplaceOp);
// Below validates that WFCORE-1577 is fixed, the model should not be missing on the /host=master/server=main-one or main-two
// Validate the subsystem child names
result = execute(client, readServerSubsystems);
validateSubsystemModel("/host=master/server=main-one", result);
}
示例5
private static boolean hasDeployment(final ModelControllerClient client, final String name) throws IOException {
final ModelNode op = Operations.createOperation(ClientConstants.READ_CHILDREN_NAMES_OPERATION);
op.get(CHILD_TYPE).set(DEPLOYMENT);
final ModelNode listDeploymentsResult;
try {
listDeploymentsResult = client.execute(op);
// Check to make sure there is an outcome
if (Operations.isSuccessfulOutcome(listDeploymentsResult)) {
final List<ModelNode> deployments = Operations.readResult(listDeploymentsResult).asList();
for (ModelNode deployment : deployments) {
if (name.equals(deployment.asString())) {
return true;
}
}
} else {
throw new IllegalStateException(Operations.getFailureDescription(listDeploymentsResult).asString());
}
} catch (IOException e) {
throw new IllegalStateException(String.format("Could not execute operation '%s'", op), e);
}
return false;
}
示例6
@Override
public ServerDeploymentPlanResult get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException,
TimeoutException {
boolean cleanup = true;
ModelNode node;
try {
node = nodeFuture.get(timeout, unit);
} catch (InterruptedException ie) {
cleanup = false; // still may be in progress, so wait for finalize()
throw ie;
} catch (TimeoutException te) {
cleanup = false; // still may be in progress, so wait for finalize()
throw te;
} finally {
if (cleanup) {
plan.cleanup();
}
}
return getResultFromNode(node.get(ClientConstants.RESULT));
}
示例7
private ModelNode shouldRenewCertificate(ZonedDateTime notValidBeforeDate, ZonedDateTime notValidAfterDate, int expiration) throws Exception {
String expiryKeyStoreFileName = "expiry.keystore";
String alias = "expiry";
File expiryKeyStoreFile = new File(WORKING_DIRECTORY_LOCATION, expiryKeyStoreFileName);
KeyStore expiryKeyStore = KeyStore.getInstance("JKS");
expiryKeyStore.load(null, null);
addCertificate(expiryKeyStore, alias, notValidBeforeDate, notValidAfterDate);
try (FileOutputStream fos = new FileOutputStream(expiryKeyStoreFile)){
expiryKeyStore.store(fos, "Elytron".toCharArray());
}
addKeyStore(expiryKeyStoreFileName, KEYSTORE_NAME, "Elytron");
try {
ModelNode operation = new ModelNode();
operation.get(ClientConstants.OP_ADDR).add("subsystem", "elytron").add("key-store", KEYSTORE_NAME);
operation.get(ClientConstants.OP).set(ElytronDescriptionConstants.SHOULD_RENEW_CERTIFICATE);
operation.get(ElytronDescriptionConstants.ALIAS).set(alias);
operation.get(ElytronDescriptionConstants.EXPIRATION).set(expiration);
return assertSuccess(services.executeOperation(operation)).get(ClientConstants.RESULT);
} finally {
removeKeyStore(KEYSTORE_NAME);
}
}
示例8
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
resourceRegistration.registerReadOnlyAttribute(ServerRootResourceDefinition.LAUNCH_TYPE, (context,operation) -> {
readResourceServerConfig(context);
context.getResult().set(ServerEnvironment.LaunchType.DOMAIN.toString());
});
resourceRegistration.registerReadOnlyAttribute(ServerRootResourceDefinition.SERVER_STATE, (context, operation) -> {
readResourceServerConfig(context);
// note this is inconsistent with the other values, should be lower case, preserved for now.
context.getResult().set("STOPPED");
});
resourceRegistration.registerReadOnlyAttribute(ServerRootResourceDefinition.RUNTIME_CONFIGURATION_STATE,
(context, operation) -> {
readResourceServerConfig(context);
context.getResult().set(ClientConstants.CONTROLLER_PROCESS_STATE_STOPPED);
}
);
}
示例9
private ModelNode getAddKeyStoreUsingNonExistingFileOperation(boolean required, String nonExistentFileName) throws Exception {
Path resources = Paths.get(KeyStoresTestCase.class.getResource(".").toURI());
File file = new File(resources + nonExistentFileName);
assertTrue (! file.exists());
ModelNode operation = new ModelNode();
operation.get(ClientConstants.OPERATION_HEADERS).get("allow-resource-service-restart").set(Boolean.TRUE);
operation.get(ClientConstants.OP_ADDR).add("subsystem","elytron").add("key-store", KEYSTORE_NAME);
operation.get(ClientConstants.OP).set(ClientConstants.ADD);
operation.get(ElytronDescriptionConstants.PATH).set(resources + nonExistentFileName);
operation.get(ElytronDescriptionConstants.TYPE).set("JKS");
operation.get(CredentialReference.CREDENTIAL_REFERENCE).get(CredentialReference.CLEAR_TEXT).set("Elytron");
if (required) {
operation.get(ElytronDescriptionConstants.REQUIRED).set(true);
}
return operation;
}
示例10
@Test
public void testCreateAccount() throws Exception {
addKeyStore(ACCOUNTS_KEYSTORE_NAME);
addCertificateAuthorityWithoutStagingUrl();
addCertificateAuthorityAccountWithCustomCA("account1v2");
server = setupTestCreateAccount();
AcmeAccount acmeAccount = getAcmeAccount();
final String NEW_ACCT_LOCATION = "http://localhost:4001/acme/acct/384";
try {
assertNull(acmeAccount.getAccountUrl());
ModelNode operation = new ModelNode();
operation.get(ClientConstants.OP_ADDR).add("subsystem", "elytron").add("certificate-authority-account", CERTIFICATE_AUTHORITY_ACCOUNT_NAME);
operation.get(ClientConstants.OP).set(ElytronDescriptionConstants.CREATE_ACCOUNT);
operation.get(ElytronDescriptionConstants.AGREE_TO_TERMS_OF_SERVICE).set(true);
assertSuccess(services.executeOperation(operation));
assertEquals(NEW_ACCT_LOCATION, acmeAccount.getAccountUrl());
} finally {
removeCertificateAuthorityAccount();
removeCertificateAuthority();
removeKeyStore(ACCOUNTS_KEYSTORE_NAME);
}
}
示例11
@Test
public void testCreateAccountWithCustomCAWithoutStaging() throws Exception {
addKeyStore(ACCOUNTS_KEYSTORE_NAME);
addCertificateAuthorityWithStagingUrl();
addCertificateAuthorityAccountWithCustomCA("account1v2");
server = setupTestCreateAccount();
AcmeAccount acmeAccount = getAcmeAccount();
final String NEW_ACCT_LOCATION = "http://localhost:4001/acme/acct/384";
try {
assertNull(acmeAccount.getAccountUrl());
ModelNode operation = new ModelNode();
operation.get(ClientConstants.OP_ADDR).add("subsystem", "elytron").add("certificate-authority-account", CERTIFICATE_AUTHORITY_ACCOUNT_NAME);
operation.get(ClientConstants.OP).set(ElytronDescriptionConstants.CREATE_ACCOUNT);
operation.get(ElytronDescriptionConstants.AGREE_TO_TERMS_OF_SERVICE).set(true);
assertSuccess(services.executeOperation(operation));
assertEquals(NEW_ACCT_LOCATION, acmeAccount.getAccountUrl());
} finally {
removeCertificateAuthorityAccount();
removeCertificateAuthority();
removeKeyStore(ACCOUNTS_KEYSTORE_NAME);
}
}
示例12
@Test
public void testCreateAccountWithCustomCAWithStaging() throws Exception {
addKeyStore(ACCOUNTS_KEYSTORE_NAME);
addCertificateAuthorityWithStagingUrl();
addCertificateAuthorityAccountWithCustomCA("account1v2");
server = setupTestCreateAccount();
AcmeAccount acmeAccount = getAcmeAccount();
final String NEW_ACCT_LOCATION = "http://localhost:4001/acme/acct/384";
try {
assertNull(acmeAccount.getAccountUrl());
ModelNode operation = new ModelNode();
operation.get(ClientConstants.OP_ADDR).add("subsystem", "elytron").add("certificate-authority-account", CERTIFICATE_AUTHORITY_ACCOUNT_NAME);
operation.get(ClientConstants.OP).set(ElytronDescriptionConstants.CREATE_ACCOUNT);
operation.get(ElytronDescriptionConstants.AGREE_TO_TERMS_OF_SERVICE).set(true);
operation.get(ElytronDescriptionConstants.STAGING).set(true);
assertSuccess(services.executeOperation(operation));
assertEquals(NEW_ACCT_LOCATION, acmeAccount.getAccountUrl());
} finally {
removeCertificateAuthorityAccount();
removeCertificateAuthority();
removeKeyStore(ACCOUNTS_KEYSTORE_NAME);
}
}
示例13
@Test
public void testCreateAccountWithEmptyStagingUrlAndStagingValueTrue() throws Exception {
addKeyStore(ACCOUNTS_KEYSTORE_NAME);
addCertificateAuthorityWithoutStagingUrl();
addCertificateAuthorityAccountWithCustomCA("account1v2");
server = setupTestCreateAccount();
AcmeAccount acmeAccount = getAcmeAccount();
try {
assertNull(acmeAccount.getAccountUrl());
ModelNode operation = new ModelNode();
operation.get(ClientConstants.OP_ADDR).add("subsystem", "elytron").add("certificate-authority-account", CERTIFICATE_AUTHORITY_ACCOUNT_NAME);
operation.get(ClientConstants.OP).set(ElytronDescriptionConstants.CREATE_ACCOUNT);
operation.get(ElytronDescriptionConstants.AGREE_TO_TERMS_OF_SERVICE).set(true);
operation.get(ElytronDescriptionConstants.STAGING).set(true);
ModelNode result = services.executeOperation(operation);
assertFailed(result);
String failureDescription = result.get(FAILURE_DESCRIPTION).asString();
assertTrue(failureDescription.contains("WFLYELY01043") && failureDescription.contains("ELY10057"));
} finally {
removeCertificateAuthorityAccount();
removeCertificateAuthority();
removeKeyStore(ACCOUNTS_KEYSTORE_NAME);
}
}
示例14
@Test
public void testCreateAccountWithoutAgreeingToTermsOfService() throws Exception {
String alias = "invalid";
addKeyStore(ACCOUNTS_KEYSTORE_NAME);
addCertificateAuthorityWithoutStagingUrl();
addCertificateAuthorityAccountWithCustomCA(alias);
server = setupTestCreateAccountWithoutAgreeingToTermsOfService();
AcmeAccount acmeAccount = getAcmeAccount();
try {
assertNull(acmeAccount.getAccountUrl());
ModelNode operation = new ModelNode();
operation.get(ClientConstants.OP_ADDR).add("subsystem", "elytron").add("certificate-authority-account", CERTIFICATE_AUTHORITY_ACCOUNT_NAME);
operation.get(ClientConstants.OP).set(ElytronDescriptionConstants.CREATE_ACCOUNT);
operation.get(ElytronDescriptionConstants.AGREE_TO_TERMS_OF_SERVICE).set(false);
ModelNode result = services.executeOperation(operation);
assertFailed(result);
String failureDescription = result.get(FAILURE_DESCRIPTION).asString();
assertTrue(failureDescription.contains("WFLYELY01043") && failureDescription.contains("must agree to terms of service"));
} finally {
removeCertificateAuthorityAccount();
removeCertificateAuthority();
removeKeyStore(ACCOUNTS_KEYSTORE_NAME);
}
}
示例15
@Test
public void testUpdateAccount() throws Exception {
addKeyStore(ACCOUNTS_KEYSTORE_NAME);
addCertificateAuthorityWithoutStagingUrl();
addCertificateAuthorityAccountWithCustomCA("account1v2", new String[] { "mailto:[email protected]", "mailto:[email protected]" });
server = setupTestUpdateAccount();
try {
ModelNode operation = new ModelNode();
operation.get(ClientConstants.OP_ADDR).add("subsystem", "elytron").add("certificate-authority-account", CERTIFICATE_AUTHORITY_ACCOUNT_NAME);
operation.get(ClientConstants.OP).set(ElytronDescriptionConstants.UPDATE_ACCOUNT);
operation.get(ElytronDescriptionConstants.AGREE_TO_TERMS_OF_SERVICE).set(false);
assertSuccess(services.executeOperation(operation));
} finally {
removeCertificateAuthorityAccount();
removeCertificateAuthority();
removeKeyStore(ACCOUNTS_KEYSTORE_NAME);
}
}
示例16
@Test
public void testChangeAccountKey() throws Exception {
addKeyStore(ACCOUNTS_KEYSTORE_NAME);
addCertificateAuthorityWithoutStagingUrl();
addCertificateAuthorityAccountWithCustomCA("account6v2");
server = setupTestChangeAccountKey();
// old account
AcmeAccount acmeAccount = getAcmeAccount();
X509Certificate oldCertificate = acmeAccount.getCertificate();
X500Principal oldDn = acmeAccount.getDn();
try {
assertNull(acmeAccount.getAccountUrl());
ModelNode operation = new ModelNode();
operation.get(ClientConstants.OP_ADDR).add("subsystem", "elytron").add("certificate-authority-account", CERTIFICATE_AUTHORITY_ACCOUNT_NAME);
operation.get(ClientConstants.OP).set(ElytronDescriptionConstants.CHANGE_ACCOUNT_KEY);
assertSuccess(services.executeOperation(operation));
assertTrue(! oldCertificate.equals(acmeAccount.getCertificate()));
assertEquals(oldDn, acmeAccount.getDn());
} finally {
removeCertificateAuthorityAccount();
removeCertificateAuthority();
removeKeyStore(ACCOUNTS_KEYSTORE_NAME);
}
}
示例17
@Test
public void testDeactivateAccount() throws Exception {
addKeyStore(ACCOUNTS_KEYSTORE_NAME);
addCertificateAuthorityWithoutStagingUrl();
addCertificateAuthorityAccountWithCustomCA("account10v2");
final String ACCT_LOCATION = "http://localhost:4001/acme/acct/27";
server = setupTestDeactivateAccount();
AcmeAccount acmeAccount = getAcmeAccount();
acmeAccount.setAccountUrl(ACCT_LOCATION);
try {
ModelNode operation = new ModelNode();
operation.get(ClientConstants.OP_ADDR).add("subsystem", "elytron").add("certificate-authority-account", CERTIFICATE_AUTHORITY_ACCOUNT_NAME);
operation.get(ClientConstants.OP).set(ElytronDescriptionConstants.DEACTIVATE_ACCOUNT);
assertSuccess(services.executeOperation(operation));
} finally {
removeCertificateAuthorityAccount();
removeCertificateAuthority();
removeKeyStore(ACCOUNTS_KEYSTORE_NAME);
}
}
示例18
@Test
public void testGetMetadataAllValuesSet() throws Exception {
addKeyStore(ACCOUNTS_KEYSTORE_NAME);
addCertificateAuthorityWithoutStagingUrl();
addCertificateAuthorityAccountWithCustomCA("account8v2");
server = setupTestGetMetadataAllValuesSet();
AcmeAccount acmeAccount = getAcmeAccount();
try {
ModelNode operation = new ModelNode();
operation.get(ClientConstants.OP_ADDR).add("subsystem", "elytron").add("certificate-authority-account", CERTIFICATE_AUTHORITY_ACCOUNT_NAME);
operation.get(ClientConstants.OP).set(ElytronDescriptionConstants.GET_METADATA);
ModelNode result = assertSuccess(services.executeOperation(operation)).get(ClientConstants.RESULT);
assertEquals("https://boulder:4431/terms/v7", result.get(ElytronDescriptionConstants.TERMS_OF_SERVICE).asString());
assertEquals("https://github.com/letsencrypt/boulder", result.get(ElytronDescriptionConstants.WEBSITE).asString());
List<ModelNode> caaIdentities = result.get(ElytronDescriptionConstants.CAA_IDENTITIES).asList();
assertEquals("happy-hacker-ca.invalid", caaIdentities.get(0).asString());
assertEquals("happy-hacker2-ca.invalid", caaIdentities.get(1).asString());
assertTrue(result.get(ElytronDescriptionConstants.EXTERNAL_ACCOUNT_REQUIRED).asBoolean());
} finally {
removeCertificateAuthorityAccount();
removeCertificateAuthority();
removeKeyStore(ACCOUNTS_KEYSTORE_NAME);
}
}
示例19
@Test
public void testGetMetadataSomeValuesSet() throws Exception {
addKeyStore(ACCOUNTS_KEYSTORE_NAME);
addCertificateAuthorityWithoutStagingUrl();
addCertificateAuthorityAccountWithCustomCA("account8v2");
server = setupTestGetMetadataSomeValuesSet();
AcmeAccount acmeAccount = getAcmeAccount();
try {
ModelNode operation = new ModelNode();
operation.get(ClientConstants.OP_ADDR).add("subsystem", "elytron").add("certificate-authority-account", CERTIFICATE_AUTHORITY_ACCOUNT_NAME);
operation.get(ClientConstants.OP).set(ElytronDescriptionConstants.GET_METADATA);
ModelNode result = assertSuccess(services.executeOperation(operation)).get(ClientConstants.RESULT);
assertEquals("https://boulder:4431/terms/v7", result.get(ElytronDescriptionConstants.TERMS_OF_SERVICE).asString());
assertEquals(ModelType.UNDEFINED, result.get(ElytronDescriptionConstants.WEBSITE).getType());
assertEquals(ModelType.UNDEFINED, result.get(ElytronDescriptionConstants.CAA_IDENTITIES).getType());
assertFalse(result.get(ElytronDescriptionConstants.EXTERNAL_ACCOUNT_REQUIRED).asBoolean());
} finally {
removeCertificateAuthorityAccount();
removeCertificateAuthority();
removeKeyStore(ACCOUNTS_KEYSTORE_NAME);
}
}
示例20
@Test
public void testGetMetadataNoValuesSet() throws Exception {
addKeyStore(ACCOUNTS_KEYSTORE_NAME);
addCertificateAuthorityWithoutStagingUrl();
addCertificateAuthorityAccountWithCustomCA("account8v2");
server = setupTestGetMetadataNoValuesSet();
AcmeAccount acmeAccount = getAcmeAccount();
try {
ModelNode operation = new ModelNode();
operation.get(ClientConstants.OP_ADDR).add("subsystem", "elytron").add("certificate-authority-account", CERTIFICATE_AUTHORITY_ACCOUNT_NAME);
operation.get(ClientConstants.OP).set(ElytronDescriptionConstants.GET_METADATA);
ModelNode result = assertSuccess(services.executeOperation(operation)).get(ClientConstants.RESULT);
assertEquals(ModelType.UNDEFINED, result.get(ElytronDescriptionConstants.TERMS_OF_SERVICE).getType());
assertEquals(ModelType.UNDEFINED, result.get(ElytronDescriptionConstants.WEBSITE).getType());
assertEquals(ModelType.UNDEFINED, result.get(ElytronDescriptionConstants.CAA_IDENTITIES).getType());
assertEquals(ModelType.UNDEFINED, result.get(ElytronDescriptionConstants.EXTERNAL_ACCOUNT_REQUIRED).getType());
} finally {
removeCertificateAuthorityAccount();
removeCertificateAuthority();
removeKeyStore(ACCOUNTS_KEYSTORE_NAME);
}
}
示例21
@Test
public void testRemoveCertificateAuthorityUsedByCertificateAuthorityAccount() throws Exception {
addCertificateAuthorityWithoutStagingUrl();
addKeyStore(ACCOUNTS_KEYSTORE_NAME);
addCertificateAuthorityAccountWithCustomCA("account");
try {
ModelNode operation = new ModelNode();
operation.get(ClientConstants.OP_ADDR).add("subsystem", "elytron").add("certificate-authority", CERTIFICATE_AUTHORITY_NAME);
operation.get(ClientConstants.OP).set(ClientConstants.REMOVE_OPERATION);
assertFailed(services.executeOperation(operation));
} finally {
removeCertificateAuthorityAccount();
removeCertificateAuthority();
removeKeyStore(ACCOUNTS_KEYSTORE_NAME);
}
}
示例22
private void addCertificateAuthorityAccountWithCustomCA(String alias, String[] contactUrlsList) throws Exception {
ModelNode operation = new ModelNode();
operation.get(ClientConstants.OPERATION_HEADERS).get("allow-resource-service-restart").set(Boolean.TRUE);
operation.get(ClientConstants.OP_ADDR).add("subsystem","elytron").add("certificate-authority-account", CERTIFICATE_AUTHORITY_ACCOUNT_NAME);
operation.get(ClientConstants.OP).set(ClientConstants.ADD);
ModelNode contactUrls = new ModelNode();
for (String contactUrl : contactUrlsList) {
contactUrls = contactUrls.add(contactUrl);
}
operation.get(ElytronDescriptionConstants.CONTACT_URLS).set(contactUrls);
operation.get(ElytronDescriptionConstants.CERTIFICATE_AUTHORITY).set(CERTIFICATE_AUTHORITY_NAME);
operation.get(ElytronDescriptionConstants.KEY_STORE).set(ACCOUNTS_KEYSTORE_NAME);
operation.get(ElytronDescriptionConstants.ALIAS).set(alias);
operation.get(CredentialReference.CREDENTIAL_REFERENCE).get(CredentialReference.CLEAR_TEXT).set(KEYSTORE_PASSWORD);
assertSuccess(services.executeOperation(operation));
}
示例23
@Test
public void testEmptyRoot() throws Exception {
KernelServices kernelServices = createEmptyRoot();
ModelNode model = kernelServices.readWholeModel(false, true);
assertAttribute(model, ModelDescriptionConstants.NAMESPACES, new ModelNode().setEmptyList());
assertAttribute(model, ModelDescriptionConstants.SCHEMA_LOCATIONS, new ModelNode().setEmptyList());
assertAttribute(model, ModelDescriptionConstants.NAME, new ModelNode(getDefaultServerName()));
assertAttribute(model, ModelDescriptionConstants.PRODUCT_NAME, null);
assertAttribute(model, ModelDescriptionConstants.PRODUCT_VERSION, null);
assertAttribute(model, ModelDescriptionConstants.MANAGEMENT_MAJOR_VERSION, new ModelNode(Version.MANAGEMENT_MAJOR_VERSION));
assertAttribute(model, ModelDescriptionConstants.MANAGEMENT_MINOR_VERSION, new ModelNode(Version.MANAGEMENT_MINOR_VERSION));
assertAttribute(model, ModelDescriptionConstants.MANAGEMENT_MICRO_VERSION, new ModelNode(Version.MANAGEMENT_MICRO_VERSION));
assertAttribute(model, ServerDescriptionConstants.PROCESS_STATE, new ModelNode("running"));
assertAttribute(model, ServerDescriptionConstants.RUNTIME_CONFIGURATION_STATE, new ModelNode(ClientConstants.CONTROLLER_PROCESS_STATE_OK));
assertAttribute(model, ServerDescriptionConstants.PROCESS_TYPE, new ModelNode("Server"));
assertAttribute(model, ServerDescriptionConstants.LAUNCH_TYPE, new ModelNode("STANDALONE"));
//These two cannot work in tests - placeholder
assertAttribute(model, ModelDescriptionConstants.RELEASE_VERSION, new ModelNode("Unknown"));
assertAttribute(model, ModelDescriptionConstants.RELEASE_CODENAME, new ModelNode(""));
//Try changing namespaces, schema-locations and name
}
示例24
private void executeReload(StartMode startMode, String serverConfig) {
ModelNode operation = new ModelNode();
operation.get(OP_ADDR).setEmptyList();
operation.get(OP).set("reload");
if(startMode == StartMode.ADMIN_ONLY) {
operation.get("admin-only").set(true);
} else if(startMode == StartMode.SUSPEND) {
operation.get("start-mode").set("suspend");
}
if (serverConfig != null) {
operation.get(SERVER_CONFIG).set(serverConfig);
}
try {
ModelNode result = client.getControllerClient().execute(operation);
Assert.assertEquals("success", result.get(ClientConstants.OUTCOME).asString());
} catch (IOException e) {
final Throwable cause = e.getCause();
if (!(cause instanceof ExecutionException) && !(cause instanceof CancellationException) && !(cause instanceof SocketException) ) {
throw new RuntimeException(e);
} // else ignore, this might happen if the channel gets closed before we got the response
}
}
示例25
@Override
public Boolean apply(final EmbeddedManagedProcess server) {
try {
final ModelControllerClient client = server.getModelControllerClient();
final ModelNode hostAddress = determineHostAddress(client);
final ModelNode op = Operations.createReadAttributeOperation(hostAddress, "host-state");
final ModelNode result = client.execute(op);
if (Operations.isSuccessfulOutcome(result) &&
ClientConstants.CONTROLLER_PROCESS_STATE_RUNNING.equals(Operations.readResult(result).asString())) {
return true;
}
} catch (IllegalStateException | IOException ignore) {
}
return false;
}
示例26
@Override
public ServerDeploymentPlanResult get() throws InterruptedException, ExecutionException {
boolean cleanup = true;
ModelNode node;
try {
node = nodeFuture.get();
} catch (InterruptedException ie) {
cleanup = false; // still may be in progress, so wait for finalize()
throw ie;
} finally {
if (cleanup) {
plan.cleanup();
}
}
return getResultFromNode(node.get(ClientConstants.RESULT));
}
示例27
/**
* Deploys the archive to the running server.
*
* @param archive the archive to deploy
* @throws IOException if an error occurs deploying the archive
*/
public static void deploy(final Archive<?> archive, ManagementClient managementClient) throws IOException {
// Use an operation to allow overriding the runtime name
final ModelNode address = Operations.createAddress(DEPLOYMENT, archive.getName());
final ModelNode addOp = createAddOperation(address);
addOp.get("enabled").set(true);
// Create the content for the add operation
final ModelNode contentNode = addOp.get(CONTENT);
final ModelNode contentItem = contentNode.get(0);
contentItem.get(ClientConstants.INPUT_STREAM_INDEX).set(0);
// Create an operation and add the input archive
final OperationBuilder builder = OperationBuilder.create(addOp);
builder.addInputStream(archive.as(ZipExporter.class).exportAsInputStream());
// Deploy the content and check the results
final ModelNode result = managementClient.getControllerClient().execute(builder.build());
if (!Operations.isSuccessfulOutcome(result)) {
Assert.fail(String.format("Failed to deploy %s: %s", archive, Operations.getFailureDescription(result).asString()));
}
}
示例28
public static ModelNode executeOperation(final Operation op, final boolean reloadIfRequired) throws IOException {
ModelNode result = client.getControllerClient().execute(op);
if (!Operations.isSuccessfulOutcome(result)) {
Assert.fail(Operations.getFailureDescription(result).toString());
}
// Reload if required
if (reloadIfRequired && result.hasDefined(ClientConstants.RESPONSE_HEADERS)) {
final ModelNode responseHeaders = result.get(ClientConstants.RESPONSE_HEADERS);
if (responseHeaders.hasDefined("process-state")) {
if (ClientConstants.CONTROLLER_PROCESS_STATE_RELOAD_REQUIRED.equals(responseHeaders.get("process-state").asString())) {
ServerReload.executeReloadAndWaitForCompletion(client.getControllerClient());
}
}
}
return result;
}
示例29
/**
* Deploys the archive to the running server.
*
* @param archive the archive to deploy
* @param runtimeName the runtime name for the deployment
*
* @throws IOException if an error occurs deploying the archive
*/
public static void deploy(final Archive<?> archive, final String runtimeName) throws IOException {
// Use an operation to allow overriding the runtime name
final ModelNode address = Operations.createAddress(DEPLOYMENT, archive.getName());
final ModelNode addOp = createAddOperation(address);
if (runtimeName != null && !archive.getName().equals(runtimeName)) {
addOp.get(RUNTIME_NAME).set(runtimeName);
}
addOp.get("enabled").set(true);
// Create the content for the add operation
final ModelNode contentNode = addOp.get(CONTENT);
final ModelNode contentItem = contentNode.get(0);
contentItem.get(ClientConstants.INPUT_STREAM_INDEX).set(0);
// Create an operation and add the input archive
final OperationBuilder builder = OperationBuilder.create(addOp);
builder.addInputStream(archive.as(ZipExporter.class).exportAsInputStream());
// Deploy the content and check the results
final ModelNode result = client.getControllerClient().execute(builder.build());
if (!Operations.isSuccessfulOutcome(result)) {
Assert.fail(String.format("Failed to deploy %s: %s", archive, Operations.getFailureDescription(result).asString()));
}
}
示例30
/**
* Check if the server is in restart-required state, that means
* management operation return "response-headers" : {"process-state" : "restart-required"}
*
* @return true if the server is in "restart-required" state
* @throws Exception
*/
public static boolean doesServerRequireRestart() throws Exception {
try (CLIWrapper cli = new CLIWrapper(true)) {
cli.sendLine("patch info --json-output", true);
String response = cli.readOutput();
ModelNode responseNode = ModelNode.fromJSONString(response);
ModelNode respHeaders = responseNode.get("response-headers");
if (respHeaders != null && respHeaders.isDefined()) {
ModelNode processState = respHeaders.get("process-state");
return processState != null && processState.isDefined() && processState.asString()
.equals(ClientConstants.CONTROLLER_PROCESS_STATE_RESTART_REQUIRED);
} else {
return false;
}
}
}