Search in sources :

Example 1 with DeploymentResult

use of org.wildfly.plugin.core.DeploymentResult in project wildfly-maven-plugin by wildfly.

the class UndeployArtifactMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().debug(String.format("Skipping undeploy of artifact %s:%s", groupId, artifactId));
        return;
    }
    if (artifactId == null) {
        throw new MojoDeploymentException("undeploy-artifact must specify the artifactId");
    }
    if (groupId == null) {
        throw new MojoDeploymentException("undeploy-artifact must specify the groupId");
    }
    final String deploymentName;
    if (name == null) {
        final Set<Artifact> dependencies = project.getDependencyArtifacts();
        Artifact artifact = null;
        for (final Artifact a : dependencies) {
            if (Objects.equals(a.getArtifactId(), artifactId) && Objects.equals(a.getGroupId(), groupId) && Objects.equals(a.getClassifier(), classifier)) {
                artifact = a;
                break;
            }
        }
        if (artifact == null) {
            throw new MojoDeploymentException("Could not resolve artifact to deploy %s:%s", groupId, artifactId);
        }
        deploymentName = artifact.getFile().getName();
    } else {
        deploymentName = name;
    }
    final DeploymentResult result;
    try (ModelControllerClient client = createClient();
        MavenModelControllerClientConfiguration configuration = getClientConfiguration()) {
        final boolean failOnMissing = !ignoreMissingDeployment;
        final DeploymentManager deploymentManager = DeploymentManager.Factory.create(client);
        result = deploymentManager.undeploy(UndeployDescription.of(deploymentName).addServerGroups(getServerGroups()).setFailOnMissing(failOnMissing));
    } catch (IOException e) {
        throw new MojoFailureException(String.format("Failed to execute %s goal.", goal()), e);
    }
    if (!result.successful()) {
        throw new MojoDeploymentException("Failed to undeploy %s. Reason: %s", deploymentName, result.getFailureMessage());
    }
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) DeploymentManager(org.wildfly.plugin.core.DeploymentManager) MavenModelControllerClientConfiguration(org.wildfly.plugin.common.MavenModelControllerClientConfiguration) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DeploymentResult(org.wildfly.plugin.core.DeploymentResult) IOException(java.io.IOException) Artifact(org.apache.maven.artifact.Artifact)

Example 2 with DeploymentResult

use of org.wildfly.plugin.core.DeploymentResult in project wildfly-maven-plugin by wildfly.

the class UndeployMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().debug(String.format("Skipping undeploy of %s:%s", project.getGroupId(), project.getArtifactId()));
        return;
    }
    final PackageType packageType = PackageType.resolve(project);
    // Configure the name if it wasn't yet set
    if (name == null) {
        name = String.format("%s.%s", project.getBuild().getFinalName(), packageType.getFileExtension());
    }
    if (checkPackaging && packageType.isIgnored()) {
        getLog().debug(String.format("Ignoring packaging type %s.", packageType.getPackaging()));
    } else {
        final DeploymentResult result;
        try (ModelControllerClient client = createClient();
            MavenModelControllerClientConfiguration configuration = getClientConfiguration()) {
            final boolean failOnMissing = !ignoreMissingDeployment;
            final DeploymentManager deploymentManager = DeploymentManager.Factory.create(client);
            if (matchPattern == null) {
                result = deploymentManager.undeploy(UndeployDescription.of(name).addServerGroups(getServerGroups()).setFailOnMissing(failOnMissing));
            } else {
                final Set<UndeployDescription> matchedDeployments = findDeployments(deploymentManager, failOnMissing);
                if (matchedDeployments.isEmpty()) {
                    if (failOnMissing) {
                        throw new MojoDeploymentException("No deployments matched the match-pattern %s.", matchPattern);
                    }
                    // nothing to undeploy
                    return;
                }
                result = deploymentManager.undeploy(matchedDeployments);
            }
        } catch (IOException e) {
            throw new MojoFailureException("Failed to execute undeploy goal.", e);
        }
        if (!result.successful()) {
            throw new MojoDeploymentException("Failed to undeploy %s. Reason: %s", name, result.getFailureMessage());
        }
    }
}
Also used : UndeployDescription(org.wildfly.plugin.core.UndeployDescription) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) DeploymentManager(org.wildfly.plugin.core.DeploymentManager) MavenModelControllerClientConfiguration(org.wildfly.plugin.common.MavenModelControllerClientConfiguration) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DeploymentResult(org.wildfly.plugin.core.DeploymentResult) IOException(java.io.IOException)

Example 3 with DeploymentResult

use of org.wildfly.plugin.core.DeploymentResult in project wildfly-maven-plugin by wildfly.

the class AbstractDeployment method execute.

@Override
public final void execute() throws MojoExecutionException, MojoFailureException {
    if (skipExecution()) {
        getLog().debug(String.format("Skipping deployment of %s:%s", project.getGroupId(), project.getArtifactId()));
        return;
    }
    try (ModelControllerClient client = createClient();
        MavenModelControllerClientConfiguration configuration = getClientConfiguration()) {
        final boolean isDomain = ServerHelper.getContainerDescription(client).isDomain();
        validate(isDomain);
        // Deploy the deployment
        getLog().debug("Executing deployment");
        final Deployment deployment = configureDeployment(createDeployment());
        final DeploymentResult result = executeDeployment(DeploymentManager.Factory.create(client), deployment);
        if (!result.successful()) {
            throw new MojoExecutionException(String.format("Failed to execute goal %s: %s", goal(), result.getFailureMessage()));
        }
    } catch (IOException e) {
        throw new MojoFailureException(String.format("Failed to execute goal %s.", goal()), e);
    }
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenModelControllerClientConfiguration(org.wildfly.plugin.common.MavenModelControllerClientConfiguration) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Deployment(org.wildfly.plugin.core.Deployment) DeploymentResult(org.wildfly.plugin.core.DeploymentResult) IOException(java.io.IOException)

Example 4 with DeploymentResult

use of org.wildfly.plugin.core.DeploymentResult in project wildfly-maven-plugin by wildfly.

the class UndeploymentMatchTest method undeployFirstMultiServerGroup.

@Test
public void undeployFirstMultiServerGroup() throws Exception {
    final String serverGroup = "other-server-group";
    if (!deploymentManager.hasDeployment(DEPLOYMENT_NAME_1, serverGroup)) {
        final DeploymentResult result = deploymentManager.forceDeploy(getDeployment().setName(DEPLOYMENT_NAME_1).addServerGroup(serverGroup));
        Assert.assertTrue(result.getFailureMessage(), result.successful());
    }
    if (!deploymentManager.hasDeployment(DEPLOYMENT_NAME_2, serverGroup)) {
        final DeploymentResult result = deploymentManager.forceDeploy(getDeployment().setName(DEPLOYMENT_NAME_2).addServerGroup(serverGroup));
        Assert.assertTrue(result.getFailureMessage(), result.successful());
    }
    // Set up the other-server-group servers to ensure the full deployment process works correctly
    final ModelNode op = Operations.createOperation("start-servers", new ModelNode().setEmptyList().add(ClientConstants.SERVER_GROUP, "other-server-group"));
    op.get("blocking").set(true);
    executeOperation(op);
    undeploy(MatchPatternStrategy.FIRST, "undeploy-multi-server-group-match-pom.xml", Arrays.asList("main-server-group", "other-server-group"));
    final Set<DeploymentDescription> deployments = deploymentManager.getDeployments();
    assertEquals(1, deployments.size());
    assertTrue("Deployment " + DEPLOYMENT_NAME_2 + " was not found on main-server-group", deploymentManager.hasDeployment(DEPLOYMENT_NAME_2, "main-server-group"));
    assertTrue("Deployment " + DEPLOYMENT_NAME_2 + " was not found on other-server-group", deploymentManager.hasDeployment(DEPLOYMENT_NAME_2, "other-server-group"));
}
Also used : DeploymentDescription(org.wildfly.plugin.core.DeploymentDescription) DeploymentResult(org.wildfly.plugin.core.DeploymentResult) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test) AbstractWildFlyServerMojoTest(org.wildfly.plugin.tests.AbstractWildFlyServerMojoTest)

Aggregations

DeploymentResult (org.wildfly.plugin.core.DeploymentResult)4 IOException (java.io.IOException)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)3 MavenModelControllerClientConfiguration (org.wildfly.plugin.common.MavenModelControllerClientConfiguration)3 DeploymentManager (org.wildfly.plugin.core.DeploymentManager)2 Artifact (org.apache.maven.artifact.Artifact)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 ModelNode (org.jboss.dmr.ModelNode)1 Test (org.junit.Test)1 Deployment (org.wildfly.plugin.core.Deployment)1 DeploymentDescription (org.wildfly.plugin.core.DeploymentDescription)1 UndeployDescription (org.wildfly.plugin.core.UndeployDescription)1 AbstractWildFlyServerMojoTest (org.wildfly.plugin.tests.AbstractWildFlyServerMojoTest)1