Commit 77bb9823 authored by Nico Mack's avatar Nico Mack

Added first implementation of InfluxDB Connector and Executor

parent 42daee41
......@@ -2,6 +2,7 @@ CONNECTOR_BUILDER_NAMESPACE=lu.list.itis.dkd.tui.cps.system.connector.builder
CONNECTOR_BUILDER_POSTFIX=Connector
URL_ELEMENT=url
DATABASE_ELEMENT=database
DRIVER_CLASS_ELEMENT=driverClass
USER_NAME_ELEMENT=username
PASSWORD_ELEMENT=password
......
......@@ -189,6 +189,11 @@
<artifactId>jersey-media-sse</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
<version>2.17</version>
</dependency>
</dependencies>
<repositories>
......
/**
* Copyright Luxembourg Institute of Science and Technology, 2019. All rights reserved. If you wish
* to use this code for any purpose, please contact the author(s).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package lu.list.itis.dkd.tui.cps.system.connector;
import lu.list.itis.dkd.tui.cps.system.connector.builder.BaseInfluxConnectorBuilder;
import com.google.common.base.Strings;
import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory;
import org.influxdb.dto.Pong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 1.8.0
* @version 1.0.0
*/
// ***************************************************************************
// * Class Definition *
// ***************************************************************************
public class InfluxConnector extends Connector<InfluxDB> {
private String url;
private String database;
private String username;
private String password;
private InfluxDB connection;
// ***************************************************************************
// * Constants
// ***************************************************************************
private static final Logger LOGGER = LoggerFactory.getLogger(InfluxConnector.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
public InfluxConnector(BaseInfluxConnectorBuilder<?> builder) {
super(builder);
this.url = builder.url;
this.database = builder.database;
this.username = builder.username;
this.password = builder.password;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// *Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public void connect() {
connection = (Strings.isNullOrEmpty(this.username)) ? InfluxDBFactory.connect(url) : InfluxDBFactory.connect(url, username, password);
Pong response = this.connection.ping();
if (response.isGood()) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Response from server (Pong) => {}!", response); //$NON-NLS-1$
}
super.connect();
} else {
LOGGER.error("Failed to connect to InfluxDB server via {}!", this.url); //$NON-NLS-1$
}
}
// ---------------------------------------------------------------------------
@Override
public InfluxDB getConnection() {
return this.connection;
}
// ---------------------------------------------------------------------------
@Override
public void disconnect() {
super.disconnect();
this.connection.close();
}
// ---------------------------------------------------------------------------
public String getDatabase() {
return this.database;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
/**
* Copyright Luxembourg Institute of Science and Technology, 2019. All rights reserved. If you wish
* to use this code for any purpose, please contact the author(s).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package lu.list.itis.dkd.tui.cps.system.connector.builder;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.bootstrapping.BootstrappingUtils;
import lu.list.itis.dkd.tui.cps.system.connector.InfluxConnector;
import lu.list.itis.dkd.tui.cps.system.connector.utility.ConnectorBundle;
import lu.list.itis.dkd.tui.exception.BuildException;
import org.jdom2.Element;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 1.8.0
* @version 1.0.0
*/
// ***************************************************************************
// * Class Definition *
// ***************************************************************************
public abstract class BaseInfluxConnectorBuilder<B extends BaseInfluxConnectorBuilder<B>> extends BaseConnectorBuilder<B> {
public String url;
public String database;
public String username;
public String password;
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public BaseInfluxConnectorBuilder(Element rootElement) throws BuildException {
super(rootElement);
this.buildFromBootstrap(rootElement, null, null);
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public BaseInfluxConnectorBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
this.buildFromBootstrap(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
this.url = BootstrappingUtils.getContentAsString(rootElement, ConnectorBundle.URL_ELEMENT, BootstrappingUtils.MANDATORY, null, context);
this.database = BootstrappingUtils.getContentAsString(rootElement, ConnectorBundle.DATABASE_ELEMENT, BootstrappingUtils.MANDATORY, null, context);
this.username = BootstrappingUtils.getContentAsString(rootElement, ConnectorBundle.USER_NAME_ELEMENT, BootstrappingUtils.OPTIONAL, null, context);
this.password = BootstrappingUtils.getContentAsString(rootElement, ConnectorBundle.PASSWORD_ELEMENT, BootstrappingUtils.OPTIONAL, null, context);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public abstract InfluxConnector build();
}
/**
* Copyright Luxembourg Institute of Science and Technology, 2019. All rights reserved. If you wish
* to use this code for any purpose, please contact the author(s).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package lu.list.itis.dkd.tui.cps.system.connector.builder;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.cps.system.connector.InfluxConnector;
import lu.list.itis.dkd.tui.exception.BuildException;
import org.jdom2.Element;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 1.8.0
* @version 1.0.0
*/
// ***************************************************************************
// * Class Definition *
// ***************************************************************************
public class InfluxConnectorBuilder extends BaseInfluxConnectorBuilder<InfluxConnectorBuilder> {
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public InfluxConnectorBuilder(Element rootElement) throws BuildException {
super(rootElement);
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public InfluxConnectorBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// *Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
@Override
public InfluxConnector build() {
return new InfluxConnector(this);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
......@@ -28,6 +28,7 @@ public class ConnectorBundle extends NLS {
public static String CONNECTOR_BUILDER_POSTFIX;
public static String URL_ELEMENT;
public static String DATABASE_ELEMENT;
public static String DRIVER_CLASS_ELEMENT;
public static String USER_NAME_ELEMENT;
public static String PASSWORD_ELEMENT;
......
......@@ -29,6 +29,10 @@ public abstract class Executor {
private static Logger LOGGER = LoggerFactory.getLogger(Executor.class.getSimpleName());
protected static final String SCALAR = "$"; //$NON-NLS-1$
protected static final String VECTOR = "@"; //$NON-NLS-1$
protected static final String MAP = "%"; //$NON-NLS-1$
protected static final String PARAMETER_TEMPLATE = "Parameter -> {} = {}"; //$NON-NLS-1$
protected static final String RESULT_TEMPLATE_PLAIN = "Result <- {} = {}"; //$NON-NLS-1$
protected static final String RESULT_TEMPLATE_EQUATE = "Result <- {}'{'{}'}' = {}"; //$NON-NLS-1$
......
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