Search in sources :

Example 1 with DomainClient

use of org.jboss.as.controller.client.helpers.domain.DomainClient in project wildfly by wildfly.

the class ReadEnvironmentVariablesTestCase method testReadEnvironmentVariablesForServers.

@Test
public void testReadEnvironmentVariablesForServers() throws Exception {
    DomainClient client = domainMasterLifecycleUtil.createDomainClient();
    DomainDeploymentManager manager = client.getDeploymentManager();
    try {
        // Deploy the archive
        WebArchive archive = ShrinkWrap.create(WebArchive.class, "env-test.war").addClass(EnvironmentTestServlet.class);
        archive.addAsResource(new StringAsset("Manifest-Version: 1.0\nDependencies: org.jboss.dmr \n"), "META-INF/MANIFEST.MF");
        archive.addAsManifestResource(createPermissionsXmlAsset(new RuntimePermission("getenv.*")), "permissions.xml");
        final InputStream contents = archive.as(ZipExporter.class).exportAsInputStream();
        try {
            DeploymentPlan plan = manager.newDeploymentPlan().add("env-test.war", contents).deploy("env-test.war").toServerGroup("main-server-group").toServerGroup("other-server-group").build();
            DeploymentPlanResult result = manager.execute(plan).get();
            Assert.assertTrue(result.isValid());
        } finally {
            IoUtils.safeClose(contents);
        }
        Map<String, String> env = getEnvironmentVariables(client, "master", "main-one", "standard-sockets");
        checkEnvironmentVariable(env, "DOMAIN_TEST_MAIN_GROUP", "main_group");
        checkEnvironmentVariable(env, "DOMAIN_TEST_SERVER", "server");
        checkEnvironmentVariable(env, "DOMAIN_TEST_JVM", "jvm");
        env = getEnvironmentVariables(client, "slave", "main-three", "standard-sockets");
        checkEnvironmentVariable(env, "DOMAIN_TEST_MAIN_GROUP", "main_group");
        Assert.assertFalse(env.containsKey("DOMAIN_TEST_SERVER"));
        Assert.assertFalse(env.containsKey("DOMAIN_TEST_JVM"));
        env = getEnvironmentVariables(client, "slave", "other-two", "other-sockets");
        Assert.assertFalse(env.containsKey("DOMAIN_TEST_MAIN_GROUP"));
        Assert.assertFalse(env.containsKey("DOMAIN_TEST_SERVER"));
        Assert.assertFalse(env.containsKey("DOMAIN_TEST_JVM"));
    } finally {
        DeploymentPlanResult result = manager.execute(manager.newDeploymentPlan().undeploy("env-test.war").build()).get();
        Assert.assertTrue(result.isValid());
        IoUtils.safeClose(client);
    }
}
Also used : DomainClient(org.jboss.as.controller.client.helpers.domain.DomainClient) StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) InputStream(java.io.InputStream) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) DeploymentPlanResult(org.jboss.as.controller.client.helpers.domain.DeploymentPlanResult) DeploymentPlan(org.jboss.as.controller.client.helpers.domain.DeploymentPlan) DomainDeploymentManager(org.jboss.as.controller.client.helpers.domain.DomainDeploymentManager) Test(org.junit.Test)

Example 2 with DomainClient

use of org.jboss.as.controller.client.helpers.domain.DomainClient in project wildfly by wildfly.

the class DeploymentOverlayTestCase method testDeploymentOverlayInDomainMode.

/**
 * This test creates and links two deployment overlays, does a deployment, and then tests that the overlay has taken effect
 * @throws Exception
 */
@Test
public void testDeploymentOverlayInDomainMode() throws Exception {
    setupDeploymentOverride();
    ModelNode content = new ModelNode();
    content.get(INPUT_STREAM_INDEX).set(0);
    ModelNode composite = createDeploymentOperation(content, MAIN_SERVER_GROUP_DEPLOYMENT_ADDRESS);
    OperationBuilder builder = new OperationBuilder(composite, true);
    builder.addInputStream(webArchive.as(ZipExporter.class).exportAsInputStream());
    executeOnMaster(builder.build());
    DomainClient client = testSupport.getDomainMasterLifecycleUtil().createDomainClient();
    Assert.assertEquals("OVERRIDDEN", performHttpCall(client, "master", "main-one", "standard-sockets", "/test/servlet"));
    Assert.assertEquals("OVERRIDDEN", performHttpCall(client, "slave", "main-three", "standard-sockets", "/test/servlet"));
    Assert.assertEquals("new file", performHttpCall(client, "master", "main-one", "standard-sockets", "/test/wildcard-new-file.txt"));
    Assert.assertEquals("new file", performHttpCall(client, "slave", "main-three", "standard-sockets", "/test/wildcard-new-file.txt"));
    // Remove the wildcard overlay
    ModelNode op = Operations.createRemoveOperation(PathAddress.pathAddress(ModelDescriptionConstants.SERVER_GROUP, "main-server-group").append(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD).append(ModelDescriptionConstants.DEPLOYMENT, "*.war").toModelNode());
    op.get("redeploy-affected").set(true);
    executeOnMaster(op);
    Assert.assertEquals("OVERRIDDEN", performHttpCall(client, "master", "main-one", "standard-sockets", "/test/servlet"));
    Assert.assertEquals("OVERRIDDEN", performHttpCall(client, "slave", "main-three", "standard-sockets", "/test/servlet"));
    Assert.assertEquals("<html><head><title>Error</title></head><body>Not Found</body></html>", performHttpCall(client, "master", "main-one", "standard-sockets", "/test/wildcard-new-file.txt"));
    Assert.assertEquals("<html><head><title>Error</title></head><body>Not Found</body></html>", performHttpCall(client, "slave", "main-three", "standard-sockets", "/test/wildcard-new-file.txt"));
    op = Operations.createRemoveOperation(PathAddress.pathAddress(ModelDescriptionConstants.SERVER_GROUP, "main-server-group").append(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_OVERLAY).append(ModelDescriptionConstants.DEPLOYMENT, "test.war").toModelNode());
    op.get("redeploy-affected").set(true);
    executeOnMaster(op);
    Assert.assertEquals("NON OVERRIDDEN", performHttpCall(client, "master", "main-one", "standard-sockets", "/test/servlet"));
    Assert.assertEquals("NON OVERRIDDEN", performHttpCall(client, "slave", "main-three", "standard-sockets", "/test/servlet"));
    Assert.assertEquals("<html><head><title>Error</title></head><body>Not Found</body></html>", performHttpCall(client, "master", "main-one", "standard-sockets", "/test/wildcard-new-file.txt"));
    Assert.assertEquals("<html><head><title>Error</title></head><body>Not Found</body></html>", performHttpCall(client, "slave", "main-three", "standard-sockets", "/test/wildcard-new-file.txt"));
}
Also used : OperationBuilder(org.jboss.as.controller.client.OperationBuilder) DomainClient(org.jboss.as.controller.client.helpers.domain.DomainClient) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 3 with DomainClient

use of org.jboss.as.controller.client.helpers.domain.DomainClient in project wildfly by wildfly.

the class ModelPersistenceTestCase method testTakeAndDeleteSnapshot.

@Test
public void testTakeAndDeleteSnapshot() throws Exception {
    DomainClient client = domainMasterLifecycleUtil.getDomainClient();
    // take snapshot
    ModelNode op = ModelUtil.createOpNode(null, "take-snapshot");
    ModelNode result = executeOperation(client, op);
    // check that the snapshot file exists
    String snapshotFileName = result.asString();
    File snapshotFile = new File(snapshotFileName);
    Assert.assertTrue(snapshotFile.exists());
    // compare with current cfg
    long snapshotHash = FileUtils.checksumCRC32(snapshotFile);
    long lastHash = FileUtils.checksumCRC32(domainLastCfgFile);
    Assert.assertTrue(snapshotHash == lastHash);
    // delete snapshot
    op = ModelUtil.createOpNode(null, "delete-snapshot");
    op.get("name").set(snapshotFile.getName());
    executeOperation(client, op);
    // check that the file is deleted
    Assert.assertFalse("Snapshot file still exists.", snapshotFile.exists());
}
Also used : DomainClient(org.jboss.as.controller.client.helpers.domain.DomainClient) ModelNode(org.jboss.dmr.ModelNode) File(java.io.File) Test(org.junit.Test)

Example 4 with DomainClient

use of org.jboss.as.controller.client.helpers.domain.DomainClient in project wildfly by wildfly.

the class ModelPersistenceTestCase method testHostOperation.

private void testHostOperation(ModelNode operation, Host controller, Host target) throws Exception {
    DomainClient client = controller.equals(Host.MASTER) ? domainMasterLifecycleUtil.getDomainClient() : domainSlaveLifecycleUtil.getDomainClient();
    CfgFileDescription lastDomainBackupDesc = getLatestBackup(domainCurrentCfgDir);
    CfgFileDescription lastMasterBackupDesc = getLatestBackup(masterCurrentCfgDir);
    CfgFileDescription lastSlaveBackupDesc = getLatestBackup(slaveCurrentCfgDir);
    long lastDomainFileHash = domainLastCfgFile.exists() ? FileUtils.checksumCRC32(domainLastCfgFile) : -1;
    long lastMasterFileHash = masterLastCfgFile.exists() ? FileUtils.checksumCRC32(masterLastCfgFile) : -1;
    long lastSlaveFileHash = slaveLastCfgFile.exists() ? FileUtils.checksumCRC32(slaveLastCfgFile) : -1;
    // execute operation so the model gets updated
    executeOperation(client, operation);
    // check that the automated snapshot of the domain has not been generated
    CfgFileDescription newDomainBackupDesc = getLatestBackup(domainCurrentCfgDir);
    Assert.assertTrue(lastDomainBackupDesc.version == newDomainBackupDesc.version);
    // check that only the appropriate host snapshot has been generated
    CfgFileDescription newMasterBackupDesc = getLatestBackup(masterCurrentCfgDir);
    CfgFileDescription newSlaveBackupDesc = getLatestBackup(slaveCurrentCfgDir);
    if (target == Host.MASTER) {
        Assert.assertTrue(lastMasterBackupDesc.version == newMasterBackupDesc.version - 1);
        Assert.assertTrue(lastSlaveBackupDesc.version == newSlaveBackupDesc.version);
        Assert.assertTrue(lastMasterFileHash != FileUtils.checksumCRC32(masterLastCfgFile));
        Assert.assertTrue(lastSlaveFileHash == FileUtils.checksumCRC32(slaveLastCfgFile));
    } else {
        Assert.assertTrue(lastMasterBackupDesc.version == newMasterBackupDesc.version);
        Assert.assertTrue(lastSlaveBackupDesc.version == newSlaveBackupDesc.version - 1);
        Assert.assertTrue(lastMasterFileHash == FileUtils.checksumCRC32(masterLastCfgFile));
        Assert.assertTrue(lastSlaveFileHash != FileUtils.checksumCRC32(slaveLastCfgFile));
    }
    Assert.assertTrue(lastDomainBackupDesc.version == newDomainBackupDesc.version);
    Assert.assertTrue(lastDomainFileHash == FileUtils.checksumCRC32(domainLastCfgFile));
}
Also used : DomainClient(org.jboss.as.controller.client.helpers.domain.DomainClient)

Example 5 with DomainClient

use of org.jboss.as.controller.client.helpers.domain.DomainClient in project wildfly by wildfly.

the class SimpleMixedDomainTest method test00002_Versioning.

@Test
public void test00002_Versioning() throws Exception {
    DomainClient masterClient = support.getDomainMasterLifecycleUtil().createDomainClient();
    ModelNode masterModel;
    try {
        masterModel = readDomainModelForVersions(masterClient);
    } finally {
        IoUtils.safeClose(masterClient);
    }
    DomainClient slaveClient = support.getDomainSlaveLifecycleUtil().createDomainClient();
    ModelNode slaveModel;
    try {
        slaveModel = readDomainModelForVersions(slaveClient);
    } finally {
        IoUtils.safeClose(slaveClient);
    }
    cleanupKnownDifferencesInModelsForVersioningCheck(masterModel, slaveModel);
    // The version fields should be the same
    assertEquals(masterModel, slaveModel);
}
Also used : DomainClient(org.jboss.as.controller.client.helpers.domain.DomainClient) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Aggregations

DomainClient (org.jboss.as.controller.client.helpers.domain.DomainClient)24 ModelNode (org.jboss.dmr.ModelNode)17 Test (org.junit.Test)16 PathAddress (org.jboss.as.controller.PathAddress)5 File (java.io.File)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 OperationBuilder (org.jboss.as.controller.client.OperationBuilder)2 DeploymentPlan (org.jboss.as.controller.client.helpers.domain.DeploymentPlan)2 DeploymentPlanResult (org.jboss.as.controller.client.helpers.domain.DeploymentPlanResult)2 DomainDeploymentManager (org.jboss.as.controller.client.helpers.domain.DomainDeploymentManager)2 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)2 ZipExporter (org.jboss.shrinkwrap.api.exporter.ZipExporter)2 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)2 Map (java.util.Map)1 PathElement (org.jboss.as.controller.PathElement)1 Operations (org.jboss.as.controller.client.helpers.Operations)1 ServerIdentity (org.jboss.as.controller.client.helpers.domain.ServerIdentity)1 ServerStatus (org.jboss.as.controller.client.helpers.domain.ServerStatus)1