diff --git a/java/timebase/commons/build.gradle b/java/timebase/commons/build.gradle index 2bc91266..c2ab2c91 100644 --- a/java/timebase/commons/build.gradle +++ b/java/timebase/commons/build.gradle @@ -5,7 +5,7 @@ description = "Timebase Commons Server API Library" dependencies { api project(':java:timebase:pub') - api project(':java:timebase:snmpagent') + //implementation project(':java:timebase:snmpagent') api ('com.epam.deltix:timebase-lang') api ('com.epam.deltix:timebase-util') @@ -37,6 +37,11 @@ dependencies { implementation 'com.github.sarxos:windows-registry-util:0.3' + implementation 'com.bettercloud:vault-java-driver' + + implementation 'com.azure:azure-identity' + implementation 'com.azure:azure-security-keyvault-secrets' + implementation 'com.epam.deltix:gflog-api', 'com.epam.deltix:gflog-core', 'com.epam.deltix:gflog-jul', diff --git a/java/timebase/commons/src/main/java/com/epam/deltix/qsrv/comm/cat/TomcatRunner.java b/java/timebase/commons/src/main/java/com/epam/deltix/qsrv/comm/cat/TomcatRunner.java index 1d903e50..8ad75dc3 100644 --- a/java/timebase/commons/src/main/java/com/epam/deltix/qsrv/comm/cat/TomcatRunner.java +++ b/java/timebase/commons/src/main/java/com/epam/deltix/qsrv/comm/cat/TomcatRunner.java @@ -21,13 +21,10 @@ import com.epam.deltix.qsrv.config.QuantServiceConfig.Type; import com.epam.deltix.qsrv.config.ServiceExecutor; import com.epam.deltix.qsrv.util.servlet.AccessFilter; -import com.epam.deltix.snmp.QuantServerSnmpObjectContainer; -import com.epam.deltix.snmp.SNMPTransportFactory; import com.epam.deltix.qsrv.util.tomcat.DXTomcat; import com.epam.deltix.util.collections.generated.ObjectArrayList; import com.epam.deltix.util.io.Home; import com.epam.deltix.util.lang.Util; -import com.epam.deltix.util.tomcat.ConnectionHandshakeHandler; import org.apache.catalina.Context; import org.apache.catalina.LifecycleException; diff --git a/java/timebase/commons/src/main/java/com/epam/deltix/qsrv/config/ServiceExecutor.java b/java/timebase/commons/src/main/java/com/epam/deltix/qsrv/config/ServiceExecutor.java index bb615514..31090caf 100644 --- a/java/timebase/commons/src/main/java/com/epam/deltix/qsrv/config/ServiceExecutor.java +++ b/java/timebase/commons/src/main/java/com/epam/deltix/qsrv/config/ServiceExecutor.java @@ -16,7 +16,6 @@ */ package com.epam.deltix.qsrv.config; -import com.epam.deltix.snmp.QuantServerSnmpObjectContainer; import org.apache.catalina.Context; import java.io.Closeable; @@ -35,10 +34,10 @@ public interface ServiceExecutor extends Closeable { */ void configure(Context context); - /** - * Implementors for this method may put own SNMP data objects into provided {@code snmpContextHolder}. - * @param snmpContextHolder container for SNMP data objects - */ - default void registerSnmpObjects(QuantServerSnmpObjectContainer snmpContextHolder) { - } +// /** +// * Implementors for this method may put own SNMP data objects into provided {@code snmpContextHolder}. +// * @param snmpContextHolder container for SNMP data objects +// */ +// default void registerSnmpObjects(QuantServerSnmpObjectContainer snmpContextHolder) { +// } } \ No newline at end of file diff --git a/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/AzureVaultConfig.java b/java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/AzureVaultConfig.java similarity index 100% rename from java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/AzureVaultConfig.java rename to java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/AzureVaultConfig.java diff --git a/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/AzureVaultStorage.java b/java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/AzureVaultStorage.java similarity index 100% rename from java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/AzureVaultStorage.java rename to java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/AzureVaultStorage.java diff --git a/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/HashicorpVaultConfig.java b/java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/HashicorpVaultConfig.java similarity index 100% rename from java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/HashicorpVaultConfig.java rename to java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/HashicorpVaultConfig.java diff --git a/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/HashicorpVaultStorage.java b/java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/HashicorpVaultStorage.java similarity index 100% rename from java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/HashicorpVaultStorage.java rename to java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/HashicorpVaultStorage.java diff --git a/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/SecretsStorage.java b/java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/SecretsStorage.java similarity index 100% rename from java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/SecretsStorage.java rename to java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/SecretsStorage.java diff --git a/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/SecretsStorageConfig.java b/java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/SecretsStorageConfig.java similarity index 100% rename from java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/SecretsStorageConfig.java rename to java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/SecretsStorageConfig.java diff --git a/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/VaultConfig.java b/java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/VaultConfig.java similarity index 100% rename from java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/VaultConfig.java rename to java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/VaultConfig.java diff --git a/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/VaultProviderType.java b/java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/VaultProviderType.java similarity index 100% rename from java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/VaultProviderType.java rename to java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/VaultProviderType.java diff --git a/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/VaultStorage.java b/java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/VaultStorage.java similarity index 100% rename from java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/VaultStorage.java rename to java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/VaultStorage.java diff --git a/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/VaultStorageFactory.java b/java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/VaultStorageFactory.java similarity index 100% rename from java/timebase/pub/src/main/java/com/epam/deltix/qsrv/util/secrets/VaultStorageFactory.java rename to java/timebase/commons/src/main/java/com/epam/deltix/qsrv/util/secrets/VaultStorageFactory.java diff --git a/java/timebase/commons/src/main/java/com/epam/deltix/snmp/QuantServerSnmpObjectContainer.java b/java/timebase/commons/src/main/java/com/epam/deltix/snmp/QuantServerSnmpObjectContainer.java deleted file mode 100644 index 9a9b5624..00000000 --- a/java/timebase/commons/src/main/java/com/epam/deltix/snmp/QuantServerSnmpObjectContainer.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2023 EPAM Systems, Inc - * - * See the NOTICE file distributed with this work for additional information - * regarding copyright ownership. 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 limitations under - * the License. - */ -package com.epam.deltix.snmp; - -/** - * Container object. - * Different services may store SNMP-data objects into to make them available for SNMP agent. - * - * @author Alexei Osipov - */ -public class QuantServerSnmpObjectContainer { - // TODO: Consider using Map instead - private Object timeBaseSnmpInfo; - private Object aggregatorSnmpInfo; - - public Object getTimeBaseSnmpInfo() { - return timeBaseSnmpInfo; - } - - public void setTimeBaseSnmpInfo(Object timeBaseSnmpInfo) { - this.timeBaseSnmpInfo = timeBaseSnmpInfo; - } - - public Object getAggregatorSnmpInfo() { - return aggregatorSnmpInfo; - } - - public void setAggregatorSnmpInfo(Object aggregatorSnmpInfo) { - this.aggregatorSnmpInfo = aggregatorSnmpInfo; - } - -} \ No newline at end of file diff --git a/java/timebase/commons/src/main/java/com/epam/deltix/snmp/SNMPTransportFactory.java b/java/timebase/commons/src/main/java/com/epam/deltix/snmp/SNMPTransportFactory.java deleted file mode 100644 index 4a3b23f6..00000000 --- a/java/timebase/commons/src/main/java/com/epam/deltix/snmp/SNMPTransportFactory.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2023 EPAM Systems, Inc - * - * See the NOTICE file distributed with this work for additional information - * regarding copyright ownership. 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 limitations under - * the License. - */ -package com.epam.deltix.snmp; - -import com.epam.deltix.qsrv.QSHome; -import com.epam.deltix.snmp.agent.EmbeddedAgent; -import com.epam.deltix.snmp.pub.SNMP; -import com.epam.deltix.snmp.s4jrt.ExternalSocketTransportMapping; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * @author Alexei Osipov - */ -public class SNMPTransportFactory { - protected static final Logger LOGGER = Logger.getLogger ("deltix.util.tomcat"); - - private static final Level LEVEL_STARTUP = new Level ("STARTUP", Level.SEVERE.intValue() - 10) { }; - public static final String TOP_SNMP_DATA_OBJECT_CLASS_NAME = "com.epam.deltix.qsrv.snmp.modimpl.QuantServerImpl"; - - public static ExternalSocketTransportMapping initializeSNMP(int port, QuantServerSnmpObjectContainer objectContainer) { - try { - long enterTime = System.currentTimeMillis(); - Object QSMIB = createTopLevelSnmpInfoObject(objectContainer, port); - - //QSMIB.setPort (port); - - EmbeddedAgent SNMPAgent = - new EmbeddedAgent( - QSHome.getFile("logs"), - SNMP.getMIB(QSMIB) - ); - - SNMPAgent.addUdpPort (null, port); - - ExternalSocketTransportMapping SNMP_TM = new ExternalSocketTransportMapping(null, port); - - SNMPAgent.addTransportMapping (SNMP_TM); - - SNMPAgent.loadDefaultProperties (); - - SNMPAgent.run (); - long exitTime = System.currentTimeMillis(); - LOGGER.info("Initialized SNMP (" + (exitTime - enterTime)/1000 + " seconds)"); - - return SNMP_TM; - } catch (Exception x) { - LOGGER.log ( - LEVEL_STARTUP, - "SNMP initialization failed. Continuing without SNMP support.", - x - ); - } - return null; - } - - - private static Class loadTopLevelSnmpInfoClass() throws RuntimeException { - String cname = TOP_SNMP_DATA_OBJECT_CLASS_NAME; - try { - return SNMPTransportFactory.class.getClassLoader().loadClass(cname); - } catch (ClassNotFoundException x) { - throw new RuntimeException("Unable to load top level SNMP object class '" + cname + "'", x); - } - } - - - private static Object createTopLevelSnmpInfoObject(QuantServerSnmpObjectContainer objectContainer, int port) { - Class clazz = loadTopLevelSnmpInfoClass(); - try { - Constructor constructor = clazz.getConstructor(QuantServerSnmpObjectContainer.class, Integer.TYPE); - return constructor.newInstance(objectContainer, port); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) { - throw new RuntimeException("Failed to create instance of " + clazz.getName(), e); - } - } -} \ No newline at end of file diff --git a/java/timebase/commons/src/main/java/com/epam/deltix/snmp/s4jrt/ExternalSocketTransportMapping.java b/java/timebase/commons/src/main/java/com/epam/deltix/snmp/s4jrt/ExternalSocketTransportMapping.java deleted file mode 100644 index bf76d427..00000000 --- a/java/timebase/commons/src/main/java/com/epam/deltix/snmp/s4jrt/ExternalSocketTransportMapping.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright 2023 EPAM Systems, Inc - * - * See the NOTICE file distributed with this work for additional information - * regarding copyright ownership. 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 limitations under - * the License. - */ -package com.epam.deltix.snmp.s4jrt; - -import com.epam.deltix.util.lang.Util; -import java.util.*; -import java.io.*; -import java.io.BufferedInputStream; -import java.net.*; - -import java.nio.ByteBuffer; - -import com.epam.deltix.util.tomcat.ConnectionHandshakeHandler; -import org.snmp4j.*; -import org.snmp4j.security.SecurityLevel; -import org.snmp4j.smi.*; -import org.snmp4j.transport.*; - -/** - * - */ -public class ExternalSocketTransportMapping - extends TcpTransportMapping implements ConnectionHandshakeHandler -{ - class SocketData { - final TcpAddress address; - final Socket socket; - final InputStream is; - final OutputStream os; - - public SocketData (TcpAddress peer, Socket socket, InputStream is, OutputStream os) { - this.socket = socket; - this.is = is; - this.os = os; - this.address = peer; - } - } - - private final Map sockets = - new HashMap <> (); - - private MessageLengthDecoder messageLengthDecoder = - new DefaultTcpTransportMapping.SnmpMesssageLengthDecoder(); - - public ExternalSocketTransportMapping (InetAddress ip, int port) { - super ( - new TcpAddress (ip == null ? IpAddress.ANY_IPADDRESS : ip, port) - ); - } - - @Override - public boolean handleHandshake ( - Socket socket, - BufferedInputStream bis, - OutputStream os - ) - throws IOException - { - final TcpAddress address = - new TcpAddress (socket.getInetAddress (), socket.getPort ()); - - try { - final SocketData data = new SocketData (address, socket, bis, os); - - synchronized (sockets) { - sockets.put (address, data); - } - - byte [] buffer = new byte [20000]; - - for (;;) { - int n = bis.read (buffer); - - if (n < 0) - break; - - ByteBuffer bb = ByteBuffer.wrap (buffer, 0, n); - - TransportStateReference tsr = - new TransportStateReference ( - this, - address, - null, - SecurityLevel.undefined, - SecurityLevel.undefined, - false, - data - ); - - fireProcessMessage (address, bb, tsr); - } - } catch (Throwable x) { - Util.logException("Error during handshake: %s", x); - } finally { - synchronized (sockets) { - sockets.remove (address); - } - } - return (true); - } - - @Override - public void close () throws IOException { - // close all sockets - synchronized (sockets) { - for (SocketData data : sockets.values()) { - - try { - data.socket.close(); - } catch (IOException e) { - S4JUtils.LOGGER.info("Closing error: %s").with(e); - } - } - - sockets.clear(); - } - } - - @Override - public int getMaxInboundMessageSize () { - return (Integer.MAX_VALUE); - } - - @Override - public boolean isListening () { - return (true); - } - - @Override - public void listen () throws IOException { - } - - @Override - public void sendMessage ( - TcpAddress address, - byte [] bytes, - TransportStateReference tsr // unused - ) - throws IOException - { - SocketData data; - - synchronized (sockets) { - data = sockets.get (address); - } - - if (data == null) // should open a socket in this case - throw new UnsupportedOperationException ( - "(Notification?) Sending to non-currently-open address " + address - ); - - data.os.write (bytes); - data.os.flush (); - } - - @Override - public MessageLengthDecoder getMessageLengthDecoder () { - return (messageLengthDecoder); - } - - @Override - public void setMessageLengthDecoder (MessageLengthDecoder mld) { - messageLengthDecoder = mld; - } - - @Override - public void setConnectionTimeout (long l) { - System.out.println ("setConnectionTimeout (" + l + ")"); - } - - @Override - public boolean close (TcpAddress address) throws IOException { - synchronized (sockets) { - SocketData data = sockets.remove (address); - - if (data == null) - return (false); - - data.socket.close (); - } - - return (true); - } -} \ No newline at end of file diff --git a/java/timebase/pub/build.gradle b/java/timebase/pub/build.gradle index 29b1bdf1..a3934cbe 100644 --- a/java/timebase/pub/build.gradle +++ b/java/timebase/pub/build.gradle @@ -25,9 +25,4 @@ dependencies { implementation 'com.sun.xml.bind:jaxb-core' compileOnly 'com.google.code.findbugs:jsr305' - - implementation 'com.bettercloud:vault-java-driver' - - implementation 'com.azure:azure-identity' - implementation 'com.azure:azure-security-keyvault-secrets' }