Skip to content

Commit

Permalink
Merge pull request #5 from jamezp/issue4
Browse files Browse the repository at this point in the history
[4] Add a ModelVersion to the container description. Add a lookup opt…
  • Loading branch information
jamezp authored Jan 9, 2024
2 parents 9fa4806 + 209f370 commit 5756a44
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 5 deletions.
110 changes: 109 additions & 1 deletion src/main/java/org/wildfly/plugin/tools/ContainerDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@

package org.wildfly.plugin.tools;

import java.io.IOException;

import org.jboss.as.controller.client.ModelControllerClient;
import org.wildfly.common.Assert;

/**
* Information about the running container.
*
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
@SuppressWarnings({ "WeakerAccess", "unused" })
@SuppressWarnings({"WeakerAccess", "unused"})
public interface ContainerDescription {

/**
Expand All @@ -37,6 +42,15 @@ public interface ContainerDescription {
*/
String getReleaseVersion();

/**
* Returns the root model version.
*
* @return the model version
*/
default ModelVersion getModelVersion() {
return ModelVersion.DEFAULT;
}

/**
* Returns the type of the server that was launched.
*
Expand All @@ -50,4 +64,98 @@ public interface ContainerDescription {
* @return {@code true} if this is a managed domain, otherwise {@code false}
*/
boolean isDomain();


/**
* Queries the running container and attempts to lookup the information from the running container.
*
* @param client the client used to execute the management operation
*
* @return the container description
*
* @throws IOException if an error occurs communicating with the server
* @throws OperationExecutionException if the operation used to query the container fails
*/
static ContainerDescription lookup(final ModelControllerClient client)
throws IOException, OperationExecutionException {
return DefaultContainerDescription.lookup(Assert.checkNotNullParam("client", client));
}

/**
* Describes the model version.
*/
final class ModelVersion implements Comparable<ModelVersion> {
static final ModelVersion DEFAULT = new ModelVersion(0, 0, 0);

private final int major;
private final int minor;
private final int micro;

ModelVersion(final int major, final int minor, final int micro) {
this.major = major;
this.minor = minor;
this.micro = micro;
}

/**
* The major version of the model.
*
* @return the major version
*/
public int major() {
return major;
}

/**
* The minor version of the model.
*
* @return the minor version
*/
public int minor() {
return minor;
}

/**
* THe micro version of the model.
*
* @return the micro version
*/
public int micro() {
return micro;
}

@Override
public int hashCode() {
final int prime = 31;
int result = major;
result = prime * result + minor;
result = prime * result + micro;
return result;
}

@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof ModelVersion)) {
return false;
}
final ModelVersion other = (ModelVersion) obj;
return major == other.major && minor == other.minor && micro == other.micro;
}

@Override
public String toString() {
return major + "." + minor + "." + micro;
}

@Override
public int compareTo(final ModelVersion o) {
int result = Integer.compare(major, o.major);
result = (result == 0) ? Integer.compare(minor, o.major) : result;
result = (result == 0) ? Integer.compare(micro, o.micro) : result;
return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.wildfly.plugin.tools;

import java.io.IOException;
import java.util.Optional;

import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.controller.client.helpers.ClientConstants;
Expand All @@ -24,14 +25,16 @@ class DefaultContainerDescription implements ContainerDescription {
private final String releaseVersion;
private final String launchType;
private final boolean isDomain;
private final ModelVersion modelVersion;

private DefaultContainerDescription(final String productName, final String productVersion,
final String releaseVersion, final String launchType, final boolean isDomain) {
final String releaseVersion, final ModelVersion modelVersion, final String launchType, final boolean isDomain) {
this.productName = productName;
this.productVersion = productVersion;
this.releaseVersion = releaseVersion;
this.launchType = launchType;
this.isDomain = isDomain;
this.modelVersion = modelVersion;
}

@Override
Expand All @@ -49,6 +52,11 @@ public String getReleaseVersion() {
return releaseVersion;
}

@Override
public ModelVersion getModelVersion() {
return modelVersion;
}

@Override
public String getLaunchType() {
return launchType;
Expand Down Expand Up @@ -100,8 +108,12 @@ static DefaultContainerDescription lookup(final ModelControllerClient client)
final String productVersion = getValue(model, "product-version");
final String releaseVersion = getValue(model, "release-version");
final String launchType = getValue(model, "launch-type");
return new DefaultContainerDescription(productName, productVersion, releaseVersion, launchType,
"DOMAIN".equalsIgnoreCase(launchType));
final ModelVersion modelVersion = new ModelVersion(
model.get("management-major-version").asInt(0),
model.get("management-minor-version").asInt(0),
model.get("management-micro-version").asInt(0));
return new DefaultContainerDescription(productName, productVersion, releaseVersion, modelVersion,
launchType, "DOMAIN".equalsIgnoreCase(launchType));
}
throw new OperationExecutionException(op, result);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/wildfly/plugin/tools/ServerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static boolean isValidHomeDirectory(final String path) {
*/
public static ContainerDescription getContainerDescription(final ModelControllerClient client)
throws IOException, OperationExecutionException {
return DefaultContainerDescription.lookup(Assert.checkNotNullParam("client", client));
return ContainerDescription.lookup(Assert.checkNotNullParam("client", client));
}

/**
Expand Down

0 comments on commit 5756a44

Please sign in to comment.