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

mysql version not found. Update Version #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.java text

# Declare files that will always have LF line endings on checkout
*.sh text eol=lf
136 changes: 92 additions & 44 deletions common/src/main/java/es/inteco/plugin/dao/DataBaseManager.java
Original file line number Diff line number Diff line change
@@ -1,52 +1,100 @@
/*******************************************************************************
* Copyright (C) 2012 INTECO, Instituto Nacional de Tecnologías de la Comunicación,
* Copyright (C) 2012 INTECO, Instituto Nacional de Tecnologías de la Comunicación,
* This program is licensed and may be used, modified and redistributed under the terms
* of the European Public License (EUPL), either version 1.2 or (at your option) any later
* of the European Public License (EUPL), either version 1.2 or (at your option) any later
* version as soon as they are approved by the European Commission.
* 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. See the License for the specific language governing
* 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. See the License for the specific language governing
* permissions and more details.
* You should have received a copy of the EUPL1.2 license along with this program; if not,
* You should have received a copy of the EUPL1.2 license along with this program; if not,
* you may find it at http://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32017D0863
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Modificaciones: MINHAFP (Ministerio de Hacienda y Función Pública)
* Modificaciones: MINHAFP (Ministerio de Hacienda y Función Pública)
* Email: [email protected]
******************************************************************************/
package es.inteco.plugin.dao;

import es.inteco.common.logging.Logger;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.sql.Connection;

public final class DataBaseManager {

private DataBaseManager() {
}

public static Connection getConnection() throws Exception {
Logger.putLog("Conectando a la base de datos OAW", DataBaseManager.class, Logger.LOG_LEVEL_DEBUG);
try {
final Context initContext = new InitialContext();
final Context envContext = (Context) initContext.lookup("java:/comp/env");
final DataSource ds = (DataSource) envContext.lookup("jdbc/oaw");
return ds.getConnection();
} catch (Exception e) {
Logger.putLog("Error al conectar a la base de datos OAW", DataBaseManager.class, Logger.LOG_LEVEL_ERROR, e);
throw e;
}
}

public static void closeConnection(final Connection conn) {
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
Logger.putLog("Error al cerrar la conexión a base de datos OAW", DataBaseManager.class, Logger.LOG_LEVEL_ERROR, e);
}
}
}
}
package es.inteco.plugin.dao;

import es.inteco.common.logging.Logger;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.sql.Connection;

public final class DataBaseManager {

private DataBaseManager() {
}

private static int getNumberOfConnectionRetries() {
String retryString = System.getenv("DBCONN_RETRY_COUNT");
int retries = 0;
try {
retries = (retryString != null) ? Integer.parseInt(retryString) : 0;
} catch(NumberFormatException nfe) {
Logger.putLog("Failed to parse database connection retry count", DataBaseManager.class, Logger.LOG_LEVEL_ERROR, nfe);
}
return retries;
}

private static int getConnectionRetryDelay() {
String delayString = System.getenv("DBCONN_RETRY_DELAY");
int delay = 10;
try {
delay = (delayString != null) ? Integer.parseInt(delayString) : 0;
} catch(NumberFormatException nfe) {
Logger.putLog("Failed to parse database connection retry delay",DataBaseManager.class, Logger.LOG_LEVEL_ERROR, nfe);
}
return delay;
}

public static Connection getConnection() throws Exception {
Logger.putLog("Conectando a la base de datos OAW", DataBaseManager.class, Logger.LOG_LEVEL_DEBUG);

final int numberOfRetries = getNumberOfConnectionRetries();
final int retryDelay = getConnectionRetryDelay();

for (int numberOfRetriesLeft = numberOfRetries; numberOfRetriesLeft >= 0; numberOfRetriesLeft--) {
try {
final Context initContext = new InitialContext();
final Context envContext = (Context) initContext.lookup("java:/comp/env");

final DataSource ds = (DataSource) envContext.lookup("jdbc/oaw");
return ds.getConnection();
} catch (Exception e) {

if (numberOfRetriesLeft == 0) {
Logger.putLog("Error al conectar a la base de datos OAW", DataBaseManager.class, Logger.LOG_LEVEL_ERROR, e);

throw e;
} else {
Logger.putLog("Error al conectar a la base de datos OAW", DataBaseManager.class, Logger.LOG_LEVEL_ERROR);

try {
// Please verify/correct this Google Translate output ...
Logger.putLog(
"Durmiendo " + retryDelay + " segundos antes de volver a intentarlo ...",
DataBaseManager.class, Logger.LOG_LEVEL_ERROR
);
Thread.sleep(retryDelay * 1000L);
} catch (InterruptedException ie) {
Logger.putLog("Thread was interrupted during retry delay", DataBaseManager.class, Logger.LOG_LEVEL_WARNING);
}
}
}
}

return null;
}

public static void closeConnection(final Connection conn) {
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
Logger.putLog("Error al cerrar la conexión a base de datos OAW", DataBaseManager.class, Logger.LOG_LEVEL_ERROR, e);
}
}
}
}
18 changes: 18 additions & 0 deletions deployment/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM maven:3.6.3-jdk-8 AS MAVEN_TOOL_CHAIN

COPY common /tmp/common
COPY crawler /tmp/crawler
COPY intavcore /tmp/intavcore
COPY motor-js /tmp/motor-js
COPY oaw /tmp/oaw
COPY portal /tmp/portal

WORKDIR /tmp/oaw

RUN mvn clean install -P docker -DskipTests


FROM tomcat:7.0-jdk8-openjdk-slim

COPY --from=MAVEN_TOOL_CHAIN /tmp/portal/target/oaw.war $CATALINA_HOME/webapps/oaw.war
COPY deployment/docker/conf-context-oaw.xml $CATALINA_BASE/conf/Catalina/localhost/oaw.xml
7 changes: 7 additions & 0 deletions deployment/docker/conf-context-oaw.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Context path="/oaw" reloadable="true">
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" type="javax.sql.DataSource" name="jdbc/oaw" url="jdbc:mysql://mysql:3306/oaw"
maxActive="100" maxIdle="10" maxWait="-1" validationQuery="SELECT 1 as dbcp_connection_test"
removeAbandoned="true" testOnBorrow="true"
timeBetweenEvictionRunsMillis="60000" testWhileIdle="true"
defaultTransactionIsolation="READ_UNCOMMITTED" username="user" password="pass"/>
</Context>
Loading