Coder Social home page Coder Social logo

parj / jdbc-inquirer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hsbc/jdbc-inquirer

0.0 1.0 0.0 56 KB

Tests jdbc connectivity to a source. Useful in an environment that has multiple firewalls/networks.

License: Apache License 2.0

Java 100.00%

jdbc-inquirer's Introduction

jdbc-inquirer

The jdbc-inquirer checks connectivity via JDBC. When setting up environments, one would like to know if the connectivity to a database works.

Especially in complex network environments a simple curl or wget or telnet does not cut it or if one is working with a distroless image.

The app got written overnight as the team we working were struggling to prove that an app from a Kubernetes cluster could do a database (which was sitting in a different network zone).

Furthermore, as we were testing, we found different jdbc providers behaved very slightly differently, which meant our code had to deal with idiosyncrasies.

The **jdbc-inquirer **could also be used to perform health checks.

TL;DR

#Grab jdbc-inquirer jar
curl -O --url 'https://repo1.maven.org/maven2/com/hsbc/engineering/jdbc-inquirer/1.0.1/jdbc-inquirer-1.0.1.jar'


#Grab a driver jar. An example - hive jdbc
curl -O --url 'https://repo1.maven.org/maven2/org/apache/hive/hive-jdbc/3.1.3/hive-jdbc-3.1.3-standalone.jar'

#Test connection
java -cp "./*" -DJDBC_CLASS_NAME="org.apache.hive.jdbc.HiveDriver" -DJDBC_USER="I_AM_A_USER" -DJDBC_PASSWORD="I_AM_A_TOKEN" -DJDBC_URL="jdbc:hive2://server:9999/schema" com.hsbc.engineering.JDBCInquirer

Obtaining the jar

OR

  • set the following in your pom.xml
...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.5.0</version>
        <executions>
          <execution>
            <id>copy</id>
            <phase>validate</phase>
            <goals>
              <goal>copy</goal>
            </goals>

            <configuration>
              <artifactItems>
                <!-- Obtain the jdbc inquirer-->
                <artifactItem>
                  <groupId>com.hsbc.engineering</groupId>
                  <artifactId>jdbc-inquirer</artifactId>
                  <version>1.0.1</version>
                  <classifier>standalone</classifier>
                  <type>jar</type>
                  <overWrite>true</overWrite>
                  <outputDirectory>${project.build.directory}/</outputDirectory>
                </artifactItem>
                <!-- Obtain a jdbc driver, an example below is hive -->
                <artifactItem>
                  <groupId>org.apache.hive</groupId>
                  <artifactId>hive-jdbc</artifactId>
                  <version>3.1.3</version>
                  <classifier>standalone</classifier>
                  <type>jar</type>
                  <overWrite>true</overWrite>
                  <outputDirectory>${project.build.directory}/</outputDirectory>
                </artifactItem>
              </artifactItems>
              <overWriteReleases>true</overWriteReleases>
              <overWriteSnapshots>true</overWriteSnapshots>
            </configuration>
          </execution>
        </executions>
      </plugin>

To use

#Using system properties
java -cp "target/*" -DJDBC_CLASS_NAME="org.apache.hive.jdbc.HiveDriver" -DJDBC_USER="I_AM_A_USER" -DJDBC_PASSWORD="I_AM_A_TOKEN" -DJDBC_URL="jdbc:hive2://server:9999/schema" com.hsbc.engineering.JDBCInquirer
java -cp "target/*" -DJDBC_CLASS_NAME="org.apache.hive.jdbc.HiveDriver" -DJDBC_USER="I_AM_A_USER" -DJDBC_PASSWORD="I_AM_A_TOKEN" -DJDBC_URL="jdbc:hive2://server:9999/schema" -DJDBC_SQL="show databases" -DRUN_PERFORMANCE_EXTRACTION_TEST='true' com.hsbc.engineering.JDBCInquirer

#Launch the program
java -cp [directory that contains this jar and the jdbc jars] com.hsbc.engineering.JDBCInquirer

#Using environment variables
export JDBC_CLASS_NAME='jdbc_class_name'
export JDBC_URL='jdbc_url'
export JDBC_USER='jdbc_user'                 #optional
export JDBC_PASSWORD='jdbc_password'         #optional
export JDBC_SQL='jdbc_sql'                   #optional
export RUN_PERFORMANCE_EXTRACTION_TEST=true  #optional

#Launch the program
java -cp [directory that contains this jar and the jdbc jars] com.hsbc.engineering.JDBCInquirer

Building the package

  • Clone the repo
  • Run ./mvnw package

TODO

  • Docker container for this
  • Add JDBC specs as test

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.