Commit 1b461967 authored by Feng Xue's avatar Feng Xue

Fix the bug of millions of WARNING messages

Caused by quality improvement, reverting the Version.java to the previous
commit, solves the problem
Fixes #2096
parent 7ef876f3
package com.nesstar.rest;
import com.nesstar.rest.filters.*;
import com.nesstar.rest.filters.TabulationEntityTagFilter;
import com.nesstar.rest.filters.CorrelationEntityTagFilter;
import com.nesstar.rest.filters.EntityTagFilter;
import com.nesstar.rest.filters.CubeEntityTagFilter;
import com.nesstar.rest.filters.RegressionEntityTagFilter;
import com.nesstar.rest.filters.LanguageFilter;
import com.nesstar.rest.filters.CommonEntityTagFilter;
import com.nesstar.rest.resources.SearchResource;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.servlets.CrossOriginFilter;
......@@ -24,26 +30,26 @@ import com.yammer.dropwizard.config.Bootstrap;
import com.yammer.dropwizard.config.Environment;
import com.yammer.dropwizard.config.FilterBuilder;
public final class NesstarDropService extends Service<NesstarDropConfiguration> {
public class NesstarDropService extends Service<NesstarDropConfiguration> {
private static final int SECONDSINONEDAY = 60 * 60 * 24;
public static void main(String[] args) throws Exception {
new NesstarDropService().run(args);
}
@Override
public void initialize(final Bootstrap<NesstarDropConfiguration> bootstrap) {
public void initialize(Bootstrap<NesstarDropConfiguration> bootstrap) {
bootstrap.setName("Nesstar-REST_API");
bootstrap.addBundle(new AssetsBundle("/assets/", "/"));
}
@Override
public void run(final NesstarDropConfiguration configuration, final Environment environment) {
final String serverURI = configuration.getServerURI();
final String userId = configuration.getUserId();
final String password = configuration.getPassword();
public void run(NesstarDropConfiguration configuration, Environment environment) {
String serverURI = configuration.getServerURI();
String userId = configuration.getUserId();
String password = configuration.getPassword();
environment.setSessionHandler(new SessionHandler());
final ServerHandler serverHandler = new ServerHandler(serverURI, userId, password);
ServerHandler serverHandler = new ServerHandler(serverURI, userId, password);
environment.addResource(new CorrelationResource(serverHandler));
environment.addResource(new RegressionResource(serverHandler));
......@@ -60,23 +66,23 @@ public final class NesstarDropService extends Service<NesstarDropConfiguration>
environment.addHealthCheck(new NesstarHealthCheck(serverHandler));
final FilterBuilder filterConfig = environment.addFilter(CrossOriginFilter.class, "*");
FilterBuilder filterConfig = environment.addFilter(CrossOriginFilter.class, "*");
filterConfig.setInitParam(CrossOriginFilter.PREFLIGHT_MAX_AGE_PARAM, String.valueOf(SECONDSINONEDAY)); // 1 day
filterConfig.setInitParam(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
final TabulationEntityTagFilter tabulationETagFilter = new TabulationEntityTagFilter(serverHandler);
TabulationEntityTagFilter tabulationETagFilter = new TabulationEntityTagFilter(serverHandler);
environment.addFilter(tabulationETagFilter, "/study/*");
final CorrelationEntityTagFilter correlationEntityTagFilter = new CorrelationEntityTagFilter(serverHandler);
CorrelationEntityTagFilter correlationEntityTagFilter = new CorrelationEntityTagFilter(serverHandler);
environment.addFilter(correlationEntityTagFilter, "/study/*");
final RegressionEntityTagFilter regressionEntityTagFilter = new RegressionEntityTagFilter(serverHandler);
RegressionEntityTagFilter regressionEntityTagFilter = new RegressionEntityTagFilter(serverHandler);
environment.addFilter(regressionEntityTagFilter, "/study/*");
final CubeEntityTagFilter cubeETagFilter = new CubeEntityTagFilter(serverHandler);
CubeEntityTagFilter cubeETagFilter = new CubeEntityTagFilter(serverHandler);
environment.addFilter(cubeETagFilter, "/cube/*");
final EntityTagFilter eTagFilter = new CommonEntityTagFilter(serverHandler);
EntityTagFilter eTagFilter = new CommonEntityTagFilter(serverHandler);
environment.addFilter(eTagFilter, "/*");
environment.addFilter(LanguageFilter.class, "*");
......
......@@ -11,32 +11,32 @@ import java.util.jar.Manifest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class Version {
public class Version {
private static String versionNumber;
private static final Logger LOG = LoggerFactory.getLogger(Version.class);
private static Version instance = new Version();
private static String versionNumber = readVersionNumber();
private Version() {
LOG.debug("Initializing version");
versionNumber = readVersionNumber();
}
public static String version() {
return getInstance().getVersion();
}
private static Version getInstance() {
return instance;
return VersionHolder.INSTANCE;
}
private String getVersion() {
return versionNumber;
}
private static String readVersionNumber() {
private String readVersionNumber() {
LOG.debug("Reading version number");
String version;
try {
final Manifest manifest = getManifest();
Manifest manifest = getManifest();
version = getVersionFromManifest(manifest);
} catch (IOException e) {
LOG.warn("Exception occurred while reading manifest: {}, {}", e.getMessage(), e.getCause());
......@@ -44,33 +44,35 @@ public final class Version {
}
return version;
}
private static Manifest getManifest() throws IOException {
private Manifest getManifest() throws IOException {
LOG.debug("Getting manifest");
final Enumeration manifestSources = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME);
final Manifest manifest = new Manifest();
Enumeration manifestSources = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME);
while (manifestSources.hasMoreElements()) {
final URL url = (URL) manifestSources.nextElement();
final InputStream stream = url.openStream();
if (stream == null) {
continue;
}
manifest.read(stream);
final Attributes attributes = manifest.getMainAttributes();
final String mainClassName = attributes.getValue("Main-Class");
if ("com.nesstar.rest.NesstarDropService".equals(mainClassName)) {
return manifest;
URL url = (URL) manifestSources.nextElement();
InputStream stream = url.openStream();
if (stream != null) {
Manifest manifest = new Manifest(stream);
Attributes attributes = manifest.getMainAttributes();
String mainClassName = attributes.getValue("Main-Class");
if ("com.nesstar.rest.NesstarDropService".equals(mainClassName)) {
return manifest;
}
}
}
return null;
}
private static String getVersionFromManifest(final Manifest manifest) throws IOException {
private String getVersionFromManifest(Manifest mf) throws IOException {
String version = null;
if (manifest != null) {
final Attributes attributes = manifest.getMainAttributes();
if (mf != null) {
Attributes attributes = mf.getMainAttributes();
version = attributes.getValue("Implementation-Version");
}
return version;
}
private static class VersionHolder {
private static final Version INSTANCE = new Version();
}
}
......@@ -17,7 +17,7 @@ import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
public class RegressionEntityTagFilter extends OperationEntityTagFilter{
public class RegressionEntityTagFilter extends OperationEntityTagFilter {
private static final Logger LOG = LoggerFactory.getLogger(RegressionEntityTagFilter.class);
public RegressionEntityTagFilter(ServerHandler serverHandler) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment