2015-11-19 14:39:21 -08:00
|
|
|
/**
|
|
|
|
* Copyright 2015 LinkedIn Corp. All rights reserved.
|
2017-08-22 21:32:53 -07:00
|
|
|
*
|
2015-11-19 14:39:21 -08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2017-08-22 21:32:53 -07:00
|
|
|
*
|
2015-11-19 14:39:21 -08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-08-22 21:32:53 -07:00
|
|
|
*
|
2015-11-19 14:39:21 -08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
*/
|
|
|
|
package controllers;
|
|
|
|
|
2017-08-07 13:55:05 -07:00
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileReader;
|
|
|
|
import java.io.IOException;
|
2017-08-03 15:04:56 -07:00
|
|
|
import java.lang.reflect.Constructor;
|
|
|
|
import javax.persistence.EntityManagerFactory;
|
2017-08-07 13:55:05 -07:00
|
|
|
|
2017-08-03 15:04:56 -07:00
|
|
|
import org.hibernate.hikaricp.internal.HikariCPConnectionProvider;
|
2017-08-07 13:55:05 -07:00
|
|
|
import play.Logger;
|
2017-08-03 15:04:56 -07:00
|
|
|
import play.Play;
|
2015-11-19 14:39:21 -08:00
|
|
|
import play.mvc.Controller;
|
|
|
|
import play.mvc.Result;
|
2017-09-14 15:41:44 -07:00
|
|
|
import wherehows.dao.ConnectionPoolProperties;
|
2017-08-03 15:04:56 -07:00
|
|
|
import wherehows.dao.DaoFactory;
|
2015-11-19 14:39:21 -08:00
|
|
|
|
|
|
|
|
|
|
|
public class Application extends Controller {
|
|
|
|
|
2017-08-07 17:26:37 -07:00
|
|
|
private static final String WHZ_APP_ENV = System.getenv("WHZ_APP_HOME");
|
|
|
|
private static final String DB_WHEREHOWS_URL = Play.application().configuration().getString("db.wherehows.url");
|
|
|
|
private static final String WHZ_DB_DSCLASSNAME =
|
|
|
|
Play.application().configuration().getString("hikaricp.dataSourceClassName");
|
|
|
|
private static final String DB_WHEREHOWS_USERNAME =
|
|
|
|
Play.application().configuration().getString("db.wherehows.username");
|
|
|
|
private static final String DB_WHEREHOWS_PASSWORD =
|
|
|
|
Play.application().configuration().getString("db.wherehows.password");
|
|
|
|
private static final String DB_WHEREHOWS_DIALECT = Play.application().configuration().getString("hikaricp.dialect");
|
2017-08-10 18:13:59 -07:00
|
|
|
private static final String DAO_FACTORY_CLASS =
|
|
|
|
Play.application().configuration().getString("dao.factory.class", DaoFactory.class.getCanonicalName());
|
2017-08-07 17:26:37 -07:00
|
|
|
|
2017-08-10 18:13:59 -07:00
|
|
|
private static final EntityManagerFactory ENTITY_MANAGER_FACTORY = ConnectionPoolProperties.builder()
|
|
|
|
.providerClass(HikariCPConnectionProvider.class.getName())
|
|
|
|
.dataSourceClassName(WHZ_DB_DSCLASSNAME)
|
|
|
|
.dataSourceURL(DB_WHEREHOWS_URL)
|
|
|
|
.dataSourceUser(DB_WHEREHOWS_USERNAME)
|
|
|
|
.dataSourcePassword(DB_WHEREHOWS_PASSWORD)
|
|
|
|
.dialect(DB_WHEREHOWS_DIALECT)
|
|
|
|
.build()
|
|
|
|
.buildEntityManagerFactory();
|
2017-08-07 17:26:37 -07:00
|
|
|
|
2017-08-10 18:13:59 -07:00
|
|
|
public static final DaoFactory DAO_FACTORY = createDaoFactory();
|
2017-08-07 17:26:37 -07:00
|
|
|
|
|
|
|
private static DaoFactory createDaoFactory() {
|
|
|
|
try {
|
2017-08-10 18:13:59 -07:00
|
|
|
Logger.info("Creating DAO factory: " + DAO_FACTORY_CLASS);
|
|
|
|
Class factoryClass = Class.forName(DAO_FACTORY_CLASS);
|
2017-08-07 17:26:37 -07:00
|
|
|
Constructor<? extends DaoFactory> ctor = factoryClass.getConstructor(EntityManagerFactory.class);
|
2017-08-10 18:13:59 -07:00
|
|
|
return ctor.newInstance(ENTITY_MANAGER_FACTORY);
|
2017-08-07 17:26:37 -07:00
|
|
|
} catch (Exception e) {
|
|
|
|
throw new RuntimeException(e);
|
2017-08-07 13:55:05 -07:00
|
|
|
}
|
2017-08-07 17:26:37 -07:00
|
|
|
}
|
2017-08-07 13:55:05 -07:00
|
|
|
|
2017-08-07 17:26:37 -07:00
|
|
|
public static Result index() {
|
|
|
|
return ok("TEST");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Result healthcheck() {
|
|
|
|
return ok("GOOD");
|
|
|
|
}
|
2017-08-07 13:55:05 -07:00
|
|
|
|
2017-08-07 17:26:37 -07:00
|
|
|
public static Result printDeps() {
|
|
|
|
String libPath = WHZ_APP_ENV + "/lib";
|
|
|
|
String commitFile = WHZ_APP_ENV + "/commit";
|
|
|
|
String commit = "";
|
|
|
|
|
|
|
|
if (WHZ_APP_ENV == null) {
|
|
|
|
return ok("WHZ_APP_HOME environmental variable not defined");
|
2017-08-07 13:55:05 -07:00
|
|
|
}
|
|
|
|
|
2017-08-07 17:26:37 -07:00
|
|
|
try {
|
2017-08-10 18:13:59 -07:00
|
|
|
commit = new BufferedReader(new FileReader(commitFile)).readLine();
|
2017-08-07 17:26:37 -07:00
|
|
|
} catch (IOException ioe) {
|
|
|
|
Logger.error("Error while reading commit file. Error message: " + ioe.getMessage());
|
2017-08-03 15:04:56 -07:00
|
|
|
}
|
2015-11-19 14:39:21 -08:00
|
|
|
|
2017-08-10 18:13:59 -07:00
|
|
|
//get all the files from /libs directory
|
2017-08-07 17:26:37 -07:00
|
|
|
File directory = new File(libPath);
|
2017-08-10 18:13:59 -07:00
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
if (directory.listFiles() != null) {
|
|
|
|
for (File file : directory.listFiles()) {
|
|
|
|
if (file.isFile()) {
|
|
|
|
sb.append(file.getName()).append("\n");
|
|
|
|
}
|
2017-08-07 17:26:37 -07:00
|
|
|
}
|
2017-08-07 13:55:05 -07:00
|
|
|
}
|
2017-08-07 17:26:37 -07:00
|
|
|
|
2017-08-10 18:13:59 -07:00
|
|
|
return ok("commit: " + commit + "\n" + "libraries: " + sb.toString());
|
2017-08-07 17:26:37 -07:00
|
|
|
}
|
2015-11-19 14:39:21 -08:00
|
|
|
}
|