Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFMP-231] Migrate to using the wildfly-plugin-tools. Remove the util… #447

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 1 addition & 105 deletions core/README.adoc
Original file line number Diff line number Diff line change
@@ -1,107 +1,3 @@
= WildFly Plugins Core API

The WildFly Plugins Core API offers some simple API's for deploying applications to http://wildfly.org[WildFly] or https://www.redhat.com/en/technologies/jboss-middleware/application-platform[JBoss EAP].

== Deployment Manager

The deployment manager can be used to deploy or redeploy content to a running server as well as undeploy content. It works with both standalone servers and managed domains.

A simple example is deploying a WAR from the file system.
[source,java]
----
final Path deploymentPath = Paths.get(System.getProperty("user.home"), "projects", "myapp", "target", "myapp.war");
try (final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getLocalHost(), 9990)) {
final DeploymentManager deploymentManager = DeploymentManager.Factory.create(client);
final Deployment deployment = Deployment.of(deploymentPath);
deploymentManager.forceDeploy(deployment).assertSuccess();
}
----

You can also deploy an input stream.
[source,java]
----
final String deploymentName = "example.war";
final WebArchive archive = ShrinkWrap.create(WebArchive.class, deploymentName);
archive.add(EmptyAsset.INSTANCE, "META-INF/beans.xml");
archive.addPackage("org.jboss.example");
try (final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getLocalHost(), 9990)) {
final DeploymentManager deploymentManager = DeploymentManager.Factory.create(client);
final Deployment deployment = Deployment.of(archive.as(ZipExporter.class).exportAsInputStream(), deploymentName);
deploymentManager.forceDeploy(deployment).assertSuccess();
}
----

[source,java]
.Managed Domain Example
----
final Path deploymentPath = Paths.get(System.getProperty("user.home"), "projects", "myapp", "target", "myapp.war");
try (final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getLocalHost(), 9990)) {
final DeploymentManager deploymentManager = DeploymentManager.Factory.create(client);
final Deployment deployment = Deployment.of(deploymentPath)
.addServerGroups("main-server-group", "other-server-group");
deploymentManager.deploy(deployment).assertSuccess();
}
----

[source,java]
.Redeploy Example
----
final Path deploymentPath = Paths.get(System.getProperty("user.home"), "projects", "myapp", "target", "myapp.war");
try (final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getLocalHost(), 9990)) {
final DeploymentManager deploymentManager = DeploymentManager.Factory.create(client);
if (deploymentManager.hasDeployment(deploymentPath.getFileName().toString())) {
deploymentManager.redeploy(Deployment.of(deploymentPath)).assertSuccess();
}
}
----

[source,java]
.Undeploy Example
----
try (final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getLocalHost(), 9990)) {
final DeploymentManager deploymentManager = DeploymentManager.Factory.create(client);
final DeploymentResult result = deploymentManager.undeploy(UndeployDescription.of("example.war").setFailOnMissing(true));
if (!result.successful()) {
logger.errorf("Failed to undeploy example.war. %s", result.getFailureMessage());
}
}
----

== Deployment Operation Helper

There is a helper if you'd rather execute operations on your own as well using the `org.wildfly.plugin.core.DeploymentOperations`.

[source,java]
----
final Path deploymentPath = Paths.get(System.getProperty("user.home"), "projects", "myapp", "target", "myapp.war");
try (final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getLocalHost(), 9990)) {
final Operation op = DeploymentOperations.createDeployOperation(Deployment.of(deploymentPath));
final ModelNode outcome = client.execute(op);
if (!Operations.isSuccessfulOutcome(outcome)) {
throw new DeploymentException(Operations.getFailureDescription(outcome).asString());
}
}
----

== Server Helper

You can also use the `org.wildfly.plugin.core.ServerHelper` to interact with a running server.

[source,java]
----
final Path wildflyHome = Paths.get(System.getProperty("user.home"), "servers", "wildfly-10.0.0.Final");
final Process process = Launcher.of(StandaloneCommandBuilder.of(wildflyHome)).launch();
try (final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getLocalHost(), 9990)) {
// Wait at the maximum 30 seconds for the server to start
ServerHelper.waitForStandalone(client, 30);
final Path deploymentPath = Paths.get(System.getProperty("user.home"), "projects", "myapp", "target", "myapp.war");
final DeploymentManager deploymentManager = DeploymentManager.Factory.create(client);
final Deployment deployment = Deployment.of(deploymentPath);
deploymentManager.forceDeploy(deployment).assertSuccess();

// Shutdown the standalone server
ServerHelper.shutdownStandalone(client);
} finally {
process.destroy();
}
----
The WildFly Plugins Core API offers some simple API's for deploying applications to http://wildfly.org[WildFly] or https://www.redhat.com/en/technologies/jboss-middleware/application-platform[JBoss EAP].
139 changes: 1 addition & 138 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,9 @@
<name>WildFly Plugin Core Utilities</name>

<description>
Utilities a plugin can use to interact with WildFly container.
Utilities for Maven plugins to interact with WildFly.
</description>

<properties>
<version.org.jboss.shrinkwrap.shrinkwrap>1.2.6</version.org.jboss.shrinkwrap.shrinkwrap>

<jboss.home>${project.build.directory}${file.separator}wildfly</jboss.home>
<test.class.path>${project.build.testOutputDirectory}</test.class.path>
<test.jvm.args>-Dmaven.repo.local=${settings.localRepository}</test.jvm.args>
</properties>

<licenses>
<license>
<name>Apache License Version 2.0</name>
<url>https://repository.jboss.org/licenses/apache-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
Expand All @@ -45,68 +29,13 @@
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.common</groupId>
<artifactId>wildfly-common</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-controller-client</artifactId>
</dependency>
<!-- Seems to be needed as the controller client is transitively bringing it in -->
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-protocol</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.galleon</groupId>
<artifactId>galleon-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-artifact-transfer</artifactId>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-api</artifactId>
<version>${version.org.jboss.shrinkwrap.shrinkwrap}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-impl-base</artifactId>
<version>${version.org.jboss.shrinkwrap.shrinkwrap}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<testResources>
<!-- Process default resources -->
<testResource>
<directory>src/test/resources</directory>
<targetPath>${project.build.testOutputDirectory}</targetPath>
</testResource>
<!-- Copy the custom modules to the WildFly module directory -->
<testResource>
<directory>src/test/modules</directory>
<filtering>true</filtering>
<targetPath>${jboss.home}/modules</targetPath>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
Expand All @@ -118,72 +47,6 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.jboss.galleon</groupId>
<artifactId>galleon-maven-plugin</artifactId>
<executions>
<execution>
<id>provision-wildfly</id>
<phase>pre-integration-test</phase>
<goals>
<goal>provision</goal>
</goals>
<configuration>
<feature-packs>
<feature-pack>
<location>wildfly@maven(org.jboss.universe:community-universe)#${version.org.wildfly}</location>
</feature-pack>
</feature-packs>
<record-state>false</record-state>
<install-dir>${project.build.directory}/wildfly</install-dir>
<plugin-options>
<jboss-fork-embedded>${plugin.fork.embedded}</jboss-fork-embedded>
</plugin-options>
</configuration>
</execution>
</executions>
</plugin>
<!-- We need to bind a new execution of this to run after provisioning is done so the module.xml file
required for testing is not deleted.
-->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-module</id>
<phase>pre-integration-test</phase>
<goals>
<goal>testResources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<test.deployment.dir>${project.build.testOutputDirectory}</test.deployment.dir>
</systemProperties>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<redirectTestOutputToFile>${maven.test.redirectTestOutputToFile}</redirectTestOutputToFile>
<systemPropertyVariables>
<jboss.home>${jboss.home}</jboss.home>
<test.jvm.args>${test.jvm.args}</test.jvm.args>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
49 changes: 0 additions & 49 deletions core/src/main/java/org/wildfly/plugin/core/Assertions.java

This file was deleted.

Loading