Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Update versions; fix reporting of WildFly version 9
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed May 11, 2015
1 parent 25b59ac commit 1f501be
Showing 1 changed file with 58 additions and 68 deletions.
126 changes: 58 additions & 68 deletions zanata-war/src/main/java/org/zanata/ZanataInit.java
Expand Up @@ -51,8 +51,6 @@
import javax.naming.NamingException;
import javax.servlet.ServletContext;

import com.google.common.base.Optional;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -82,9 +80,9 @@
@Slf4j
public class ZanataInit {
private static final DefaultArtifactVersion MIN_EAP_VERSION =
new DefaultArtifactVersion("6.3.3");
new DefaultArtifactVersion("6.4.0.GA");
private static final DefaultArtifactVersion MIN_WILDFLY_VERSION =
new DefaultArtifactVersion("8.1.0");
new DefaultArtifactVersion("9.0.0.CR1");


static {
Expand All @@ -106,7 +104,7 @@ public class ZanataInit {

@Observer("org.jboss.seam.postInitialization")
public void initZanata() throws Exception {
AppServerVersion appServerVersion = checkJBossVersion();
checkAppServerVersion();
ServletContext servletContext =
ServletLifecycle.getCurrentServletContext();
String appServerHome = servletContext.getRealPath("/");
Expand All @@ -131,7 +129,7 @@ public void initZanata() throws Exception {
this.applicationConfiguration.setBuildTimestamp(zanataVersion.getBuildTimeStamp());
this.applicationConfiguration.setScmDescribe(zanataVersion.getScmDescribe());

logBanner(zanataVersion, appServerVersion);
logBanner(zanataVersion);

if (this.applicationConfiguration.isDebug()) {
log.info("debug: enabled");
Expand Down Expand Up @@ -175,68 +173,69 @@ public void initZanata() throws Exception {
log.info("Started Zanata...");
}

private Optional<DefaultArtifactVersion> getEAPVersion()
throws AttributeNotFoundException, MBeanException,
ReflectionException, InstanceNotFoundException,
MalformedObjectNameException {
try {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName("jboss.as:management-root=server");
String productName = (String) (server.getAttribute(name, "productName"));
if (productName == null || !productName.equals("EAP")) {
return Optional.absent();
}
String version = (String) (server.getAttribute(name, "productVersion"));
log.info("EAP productVersion: {}", version);
return Optional.of(new DefaultArtifactVersion(version));
} catch (Exception e) {
log.debug(e.toString(), e);
return Optional.absent();
private void checkAppServerVersion()
throws MalformedObjectNameException, AttributeNotFoundException,
MBeanException, ReflectionException, InstanceNotFoundException {
MBeanServer jmx = ManagementFactory.getPlatformMBeanServer();
ObjectName server = new ObjectName("jboss.as:management-root=server");
String releaseCodename =
(String) jmx.getAttribute(server, "releaseCodename");
String releaseVersion =
(String) jmx.getAttribute(server, "releaseVersion");
String productName =
(String) jmx.getAttribute(server, "productName");
String productVersion =
(String) jmx.getAttribute(server, "productVersion");

log.info("App server release codename: {}", releaseCodename);
log.info("App server release version: {}", releaseVersion);

switch ((productName == null) ? "" : productName) {
case "EAP":
checkEAPVersion(productVersion);
break;
case "WildFly Full":
checkWildFlyVersion(productVersion);
break;
default:
log.warn(
"Unknown app server. This application requires EAP >= {} or WildFly Full >= {}",
MIN_EAP_VERSION, MIN_WILDFLY_VERSION);
break;
}
}

private Optional<DefaultArtifactVersion> getASReleaseVersion()
throws AttributeNotFoundException, MBeanException,
ReflectionException, InstanceNotFoundException,
MalformedObjectNameException {
try {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName("jboss.as:management-root=server");
String version = (String) (server.getAttribute(name, "releaseVersion"));
if (version == null) {
return Optional.absent();
private void checkEAPVersion(String productVersion) {
if (productVersion != null) {
DefaultArtifactVersion pv =
new DefaultArtifactVersion(productVersion);
if (pv.compareTo(MIN_EAP_VERSION) < 0) {
log.warn(
"EAP version is {}. Please upgrade to {} or later.",
productVersion, MIN_EAP_VERSION);
} else {
log.info("EAP version: {}", productVersion);
}
log.info("JBoss AS releaseVersion: {}", version);
return Optional.of(new DefaultArtifactVersion(version));
} catch (Exception e) {
log.debug(e.toString(), e);
return Optional.absent();
} else {
log.warn("EAP version is unknown");
}
}

private AppServerVersion checkJBossVersion()
throws MalformedObjectNameException, AttributeNotFoundException,
MBeanException, ReflectionException, InstanceNotFoundException {
Optional<DefaultArtifactVersion> eapVersion = getEAPVersion();
Optional<DefaultArtifactVersion> asReleaseVersion =
getASReleaseVersion();
if (eapVersion.isPresent()) {
if (eapVersion.get().compareTo(MIN_EAP_VERSION) < 0) {
log.warn("EAP version is {}. Please upgrade to {} or later.",
eapVersion.get(), MIN_EAP_VERSION);
}
} else {
if (asReleaseVersion.isPresent()) {
if (asReleaseVersion.get().compareTo(MIN_WILDFLY_VERSION) < 0) {
log.warn("WildFly version is {}. Please upgrade to {} or later.",
asReleaseVersion.get(), MIN_WILDFLY_VERSION);
}
private void checkWildFlyVersion(String productVersion) {
if (productVersion != null) {
DefaultArtifactVersion pv =
new DefaultArtifactVersion(productVersion);
if (pv.compareTo(MIN_WILDFLY_VERSION) < 0) {
log.warn(
"WildFly Full version is {}. Please upgrade to {} or later.",
productVersion, MIN_WILDFLY_VERSION);
} else {
log.warn("Unknown app server. This application requires EAP >= {} or WildFly >= {}",
MIN_EAP_VERSION, MIN_WILDFLY_VERSION);
log.info("WildFly Full version: {}",
productVersion);
}
} else {
log.warn("WildFly Full version is unknown");
}
return new AppServerVersion(eapVersion, asReleaseVersion);
}

private void checkLuceneLocks(File indexDir)
Expand Down Expand Up @@ -415,26 +414,17 @@ private static void list(Context ctx, String indent, StringBuffer buffer,
}
}

private void logBanner(VersionInfo ver, AppServerVersion appServerVersion) {
private void logBanner(VersionInfo ver) {
log.info("============================================");
log.info(" _____ _ ");
log.info(" /__ / ____ _____ ____ _/ /_____ _ ");
log.info(" / / / __ `/ __ \\/ __ `/ __/ __ `/ ");
log.info(" / /__/ /_/ / / / / /_/ / /_/ /_/ / ");
log.info(" /____/\\__,_/_/ /_/\\__,_/\\__/\\__,_/ ");
log.info(" Application version: " + ver.getVersionNo());
if (appServerVersion.eapVersion.isPresent()) {
log.info(" EAP version: " + appServerVersion.eapVersion.get());
}
log.info(" AS version: " + appServerVersion.asVersion.orNull());
log.info(" SCM: " + ver.getScmDescribe());
log.info(" Red Hat Inc 2008-2014");
log.info("============================================");
}

@Value private static class AppServerVersion {
Optional<DefaultArtifactVersion> eapVersion;
Optional<DefaultArtifactVersion> asVersion;
}

}

0 comments on commit 1f501be

Please sign in to comment.