Skip to content

Commit

Permalink
Merge pull request #39 from hashgraph/wait-for-postgres
Browse files Browse the repository at this point in the history
Move wait-for-postgres.sh to Java
  • Loading branch information
gregscullard authored Aug 19, 2019
2 parents c315402 + cc18dfb commit 60ee4ff
Show file tree
Hide file tree
Showing 22 changed files with 75 additions and 231 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# Log file
*.log

# OS specific
.DS_Store

# BlueJ files
*.ctxt

Expand Down
2 changes: 0 additions & 2 deletions DockerSourceCompile

This file was deleted.

26 changes: 3 additions & 23 deletions buildimages.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#!/bin/bash
set -e

mkdir docker/runtime
mkdir docker/runtime/config
mkdir docker/runtime/lib
rm -rf docker/runtime/sql
mkdir docker/runtime/sql
rm -rf docker/runtime/rest-api
mkdir docker/runtime/rest-api
rm -rf docker/runtime/{sql,rest-api}
mkdir -p docker/runtime/{config,lib,rest-api,sql}

DOCOMPILE=3
echo "Compile source via 1-docker-compose, 2-local maven, 3-skip?"
Expand Down Expand Up @@ -39,28 +35,12 @@ fi

cd docker

cp ../src/main/resources/postgres/postgresInit.sql .
cp ../src/main/resources/postgres/V*.sql runtime/sql
cp -r ../config/* runtime/config/
cp -r ../target/lib/* runtime/lib
cp ../target/mirrorNode.jar runtime/mirrorNode.jar
cp -r ../rest-api/* runtime/rest-api

cp ./wait-for-postgres.sh runtime/
chmod +x runtime/wait-for-postgres.sh

cp ./balanceParse.sh runtime/
chmod +x runtime/balanceParse.sh

cp ./recordDownloadParse.sh runtime/
chmod +x runtime/recordDownloadParse.sh

cp ./eventDownloadParse.sh runtime/
chmod +x runtime/eventDownloadParse.sh

cp ./update102.sh runtime/
chmod +x runtime/update102.sh

cp ./restapi.sh runtime/
chmod +x runtime/restapi.sh

Expand Down
5 changes: 5 additions & 0 deletions config/0.0.102-35.232.131.251-integration.net
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

�0.0.3"�308201a2300d06092a864886f70d01010105000382018f003082018a0282018100d43035acbca32e4c5b83a208ad43854584f21e97391e5c18f2507e5c1228ebd9c3b4c6d3fd47bf46df01e3d27a7cf3e04496cd6957edc7dc616f7e47407f12bfa6f0f7ed29160042a860f0987b2ac4856d911cba767a618cc259743ffba1a45624797acf69a45e36dcaf017d3cdbfb06ba87945439ac2f8043a8a807b6baff15899cc5a540eb67bf2192be155c1ab1020964e007492ecaf8098220cbcff1892852ee9764f3341c8afe7a3b94f49b7f2eb184fbbdde5d5f5724b0c708c241f6221d4e345c6c3dbe481b2eda144e35e30a241384153582ffce7f3680b27435b641c5a5a973893f36d7c68cc2183c6831c817840d92b5c9c3d4b47ee8a834ed6e9233183d0ea5846cc8ddda4acddab9e43a0f1741f47ae28ca7716960e5e99e76bb492a7bc50ab0813db89b19f0f992fa900b774a743f941ebb41ee6ddd5692ec909fcb7f8653a9eebf17edc96c01d448d13175fa9ada7ffbc7cf045a630eef9a12630e7944950a1efd471f6586d3a08fef80d6db780f276551ac3bf2f0d517c04f0203010001
�0.0.4"�308201a2300d06092a864886f70d01010105000382018f003082018a0282018100e40437b217f7a8e54c3ed3c9632eeb6881799237bef8f0195ef1e1f843fdc620ea20fa2530ed9fe557e5b47c0b3994eb25ca51a3e3418302966a9edc5fb3081435b44c8700a0f85113e7bf31d6fadb3a0cfca1ad8705502cee28c9a99581e8b487c37e35025fbcd17a3965f302cb24e95a77233968d3a6cd74be54d32f0e6731a620f441891f585b2cbc1feaa730779cac52f96a9485e8fe4c5e67111bc608737d165b71393d6a655e23fbc11e01863e80445aca0ce0373e679e59b57ed5b3af5ce8a7e42fc3f922734aa3369c38dde2acb56ac7a0ace42296ae7097dabc70dfdf732d351042fc00bfb2280af933c5ee38833e54bbd43bd511c197839860316e894cc9ed1ca4a68d5ca2a364f8f5723d81e1634e56df063a5cbab8ee96d10690b07b3a36c0c11e2cbabbfdf85b7d326157c6efc76f5dbb06730415549ec1f50651f7381b52013cbdd64612f3e2ab40ab60c1682c027c8e17c205e9efd9e67336f3cc88b59a9fb8339afbe1b4677e5fccc6a329d9fbc4eb382026a810b6d877c10203010001
�0.0.5"�308201a2300d06092a864886f70d01010105000382018f003082018a0282018100d08c46187146528d3ef15f691c0568797dbbb0f43eec2fcfb15d35a5b900d57177c5b670baec3f05ac506aba47b9b840aed18bc0c224505d0c03117a5a86b3113f978ae6b433cf5d9b88ca79faad0d82214230bc63bbfd7cc4db69b85a8c4336758223d4953ba06fccee06485eaff68e008e109d021505bd38af068de0820e250c654a877e94ffaa9a467a123bbccc7568c015aec6e7ffc4b3a0444994b67685c4dab91b0ad11b1b1e59557154c28118c2926bed049657a8b0f4180eee2dbc55f9abacae06a8358d9688de3ad47c9cbd8c932c04e26e2046bae9f903923843926db4a85cc5d82e2181018c1d1d1e1d97054937376511dce204b8f74ae5974f518c71e84087f31d2652d737b8186db6d6e1fbdcdde6f2144f6a75fc9df78c955105edf5f9e40eb850084db7bf9126613ba8164e507dc1157c7837563fb96b5f6d82e5163b95ab19ba1bbfa7777c37aef87caae8ebb569995b7adf3cc75dbd2586073b4f1688b4d5a3bc294b33b1e3c5d24d6ec5db2fa96fd654067c5a74ef2b470203010001
�0.0.6"�308201a2300d06092a864886f70d01010105000382018f003082018a028201810091d77fa70c3bcf9917972b09f0192cc2fc60802f0c1b0d58f1dbfc6c21c2fd26a708cefaed30858547058638f36eb9371194e7c01002665c47306e1db9cf0c547edaec6fd9345705e6dd33afe098ab1b66d62cf3240b853278395fc3507dd6c4d249bde8329cf9455a6850c2a4214870a04a5ca3bf009ba28277617cb4929fbf058ade3539c64660f5ade9c070993db21eac83ce028d8b6d7824454df7db3c14c4b15514b701be9cd37f7a1ebe6cd52939fd0956eda5a18d5a1dd670a3fd1f7dc4901ab89c8c5e8cfa75d7a4044275e2dc6dd4dde74258f1a0d88d61e8d55f2a4534225ea36a8a3f3dc9a720611e1894b3a02b9900952e2ad2cdc7bccf1f13bdf90c0981e242bc5c690017838ceeb41fe59933b240033545f3899d039189b82acf4a7e10b902a76d6d1341b04152d2df3dbd4d2bf3a85c3d668348033684865cbe3b715a4276557791e427f64aa18352450565f55e450d13385ea015c70ed0b2e7c1a34a1abc708574f48da9305fcce0793d47482c308b0283956a03f945ada10203010001
8 changes: 3 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
version: '3.3'
services:
compiler:
build:
context: ./
dockerfile: DockerSourceCompile
command: mvn install
image: maven:3.6.1-jdk-11-slim
tty: true
volumes:
- .:/mirrornode

command: /mirrornode/docker/build.sh
working_dir: /mirrornode
5 changes: 0 additions & 5 deletions docker/MirrorNodeClientImage

This file was deleted.

3 changes: 0 additions & 3 deletions docker/Postgres

This file was deleted.

24 changes: 0 additions & 24 deletions docker/RecordsDownloader

This file was deleted.

26 changes: 0 additions & 26 deletions docker/RecordsParser

This file was deleted.

4 changes: 0 additions & 4 deletions docker/RestClientImage

This file was deleted.

4 changes: 0 additions & 4 deletions docker/balanceParse.sh

This file was deleted.

3 changes: 0 additions & 3 deletions docker/build.sh

This file was deleted.

38 changes: 12 additions & 26 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ version: '3.3'
services:
# this is the database container
mirror-node-postgres:
build:
context: ./
dockerfile: Postgres
image: postgres:11.4-alpine
stop_signal: SIGTERM
tty: true
env_file:
Expand All @@ -31,22 +29,18 @@ services:

# this downloads balance files, its behaviour is controlled by ./config/config.json
mirror-node-balance-downloader:
build:
context: ./
dockerfile: MirrorNodeClientImage
image: adoptopenjdk:11-jre-hotspot
working_dir: /MirrorNodeCode
env_file:
- .env
volumes:
- ./MirrorNodeData:/MirrorNodeData
- ./runtime:/MirrorNodeCode
command: /usr/bin/java -Dlog4j.configurationFile=./config/log4j2.xml -cp mirrorNode.jar com.hedera.downloader.AccountBalancesDownloader
command: java -Dlog4j.configurationFile=./config/log4j2.xml -cp mirrorNode.jar com.hedera.downloader.AccountBalancesDownloader

# this processes balance files and puts the result in the database, its behaviour is controlled by ./config/config.json
mirror-node-balance-parser:
build:
context: ./
dockerfile: MirrorNodeClientImage
image: adoptopenjdk:11-jre-hotspot
depends_on:
- mirror-node-postgres
environment:
Expand All @@ -60,13 +54,11 @@ services:
volumes:
- ./MirrorNodeData:/MirrorNodeData
- ./runtime:/MirrorNodeCode
command: ./balanceParse.sh
command: java -Dlog4j.configurationFile=./config/log4j2.xml -cp mirrorNode.jar com.hedera.balanceFileLogger.BalanceFileLogger

# this downloads and processes record files and puts the result in the database, its behaviour is controlled by ./config/config.json
mirror-node-record-download-parse:
build:
context: ./
dockerfile: MirrorNodeClientImage
image: adoptopenjdk:11-jre-hotspot
depends_on:
- mirror-node-postgres
environment:
Expand All @@ -80,13 +72,11 @@ services:
volumes:
- ./MirrorNodeData:/MirrorNodeData
- ./runtime:/MirrorNodeCode
command: ./recordDownloadParse.sh
command: java -Dlog4j.configurationFile=./config/log4j2.xml -cp mirrorNode.jar com.hedera.downloader.DownloadAndParseRecordFiles

# this downloads and processes event files and puts the result in the database, its behaviour is controlled by ./config/config.json
mirror-node-event-download-parse:
build:
context: ./
dockerfile: MirrorNodeClientImage
image: adoptopenjdk:11-jre-hotspot
depends_on:
- mirror-node-postgres
environment:
Expand All @@ -100,26 +90,22 @@ services:
volumes:
- ./MirrorNodeData:/MirrorNodeData
- ./runtime:/MirrorNodeCode
command: ./eventDownloadParse.sh
command: java -Dlog4j.configurationFile=./config/log4j2.xml -cp mirrorNode.jar com.hedera.downloader.DownloadAndParseEventFiles

# this downloads the latest 0.0.102 file from the network if the .env file contains the necessary information
mirror-node-102-file-update:
build:
context: ./
dockerfile: MirrorNodeClientImage
image: adoptopenjdk:11-jre-hotspot
working_dir: /MirrorNodeCode
env_file:
- runtime/.102env
volumes:
- ./MirrorNodeData:/MirrorNodeData
- ./runtime:/MirrorNodeCode
command: ./update102.sh
command: java -Dlog4j.configurationFile=./config/log4j2.xml -cp mirrorNode.jar com.hedera.addressBook.NetworkAddressBook

# this runs the REST API for mirror node
mirror-node-rest-api:
build:
context: ./
dockerfile: RestClientImage
image: node:11
working_dir: /MirrorNodeCode
environment:
- DB_HOST=mirror-node-postgres
Expand Down
4 changes: 0 additions & 4 deletions docker/eventDownloadParse.sh

This file was deleted.

4 changes: 0 additions & 4 deletions docker/recordDownloadParse.sh

This file was deleted.

1 change: 0 additions & 1 deletion docker/restapi.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash
./wait-for-postgres.sh

cd rest-api
npm install
Expand Down
3 changes: 0 additions & 3 deletions docker/update102.sh

This file was deleted.

13 changes: 0 additions & 13 deletions docker/wait-for-postgres.sh

This file was deleted.

43 changes: 23 additions & 20 deletions src/main/java/com/hedera/databaseUtilities/DatabaseUtilities.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
package com.hedera.databaseUtilities;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.google.common.util.concurrent.Uninterruptibles;
import com.hedera.configLoader.ConfigLoader;
import com.hedera.utilities.Utility;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;

import com.hedera.configLoader.ConfigLoader;
import java.sql.*;
import java.util.concurrent.TimeUnit;

public class DatabaseUtilities {
private static final Logger log = LogManager.getLogger("databaseUtilities");
static final Marker LOGM_EXCEPTION = MarkerManager.getMarker("EXCEPTION");
private static final Logger log = LogManager.getLogger(DatabaseUtilities.class);

public static Connection openDatabase(Connection connect) {
if (connect == null) {
try {
// Setup the connection with the DB
String url = ConfigLoader.getDBUrl();
String userName = ConfigLoader.getDBUserName();
String password = ConfigLoader.getDBPassword();

connect = DriverManager.getConnection(url, userName, password);
} catch (SQLException e) {
e.printStackTrace();
log.error(LOGM_EXCEPTION, "Exception {}", e);
return null;
while (true) {
try {
if (Utility.checkStopFile()) {
log.info("Stop file found, stopping.");
break;
}

// Setup the connection with the DB
String url = ConfigLoader.getDBUrl();
String userName = ConfigLoader.getDBUserName();
String password = ConfigLoader.getDBPassword();

return DriverManager.getConnection(url, userName, password);
} catch (SQLException e) {
log.warn("Unable to connect to database. Will retry in 3s: {}", e.getMessage());
}
Uninterruptibles.sleepUninterruptibly(3, TimeUnit.SECONDS);
}
}
return connect;
Expand Down
Loading

0 comments on commit 60ee4ff

Please sign in to comment.