use of org.openmuc.framework.lib.osgi.config.PropertyHandler in project OpenMUC by isc-konstanz.
the class DbConnector method setSqlProperties.
/**
* returns a properties object with the attributes the datasource needs
*
* @return a properties object with the attributes the datasource needs
*/
private Properties setSqlProperties() {
PropertyHandler propertyHandler = PropertyHandlerProvider.getInstance().getPropertyHandler();
Properties properties = new Properties();
properties.setProperty("url", url);
properties.setProperty("password", propertyHandler.getString(Settings.PASSWORD));
properties.setProperty("user", propertyHandler.getString(Settings.USER));
if (!url.contains("h2")) {
if (url.contains(POSTGRESQL)) {
properties.setProperty("ssl", propertyHandler.getString(Settings.SSL));
}
properties.setProperty("tcpKeepAlive", propertyHandler.getString(Settings.TCP_KEEP_ALIVE));
properties.setProperty("socketTimeout", propertyHandler.getString(Settings.SOCKET_TIMEOUT));
}
return properties;
}
use of org.openmuc.framework.lib.osgi.config.PropertyHandler in project OpenMUC by isc-konstanz.
the class DbConnector method updateTimescale.
/**
* Updates the PostgreSQL timescale extension by executing a SQL query as a console command
*/
private void updateTimescale() {
try {
String line;
String[] cmd = new String[3];
int startPoint = url.lastIndexOf('/');
String dbName = url.substring(startPoint + 1);
if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
cmd[0] = "cmd.exe";
} else {
cmd[0] = "sh";
}
PropertyHandler propertyHandler = PropertyHandlerProvider.getInstance().getPropertyHandler();
cmd[1] = "-c";
cmd[2] = "PGPASSWORD=" + propertyHandler.getString(Settings.PSQL_PASS) + " psql -c 'ALTER EXTENSION timescaledb UPDATE;' -U postgres -h localhost -d " + dbName;
Process process = Runtime.getRuntime().exec(cmd);
BufferedReader stdOutReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
while ((line = stdOutReader.readLine()) != null) {
logger.info(line);
}
BufferedReader stdErrReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
while ((line = stdErrReader.readLine()) != null) {
logger.info(line);
}
} catch (Exception e) {
logger.error(MessageFormat.format("Unable to execute shell command: {0}", e.getMessage()));
}
}
use of org.openmuc.framework.lib.osgi.config.PropertyHandler in project OpenMUC by isc-konstanz.
the class TableSetupTest method setupInitializer.
@BeforeEach
void setupInitializer() throws SQLException {
accessMock = mock(DbAccess.class);
channelList = new ArrayList<>();
channelList.add(getMockedChannel("gridPower"));
channelList.add(getMockedChannel("pvPower"));
ResultSet resultMocked = mock(ResultSet.class);
ResultSetMetaData resultMetaMock = mock(ResultSetMetaData.class);
when(resultMetaMock.getColumnCount()).thenReturn(0);
when(resultMocked.getMetaData()).thenReturn(resultMetaMock);
when(accessMock.executeQuery(any())).thenReturn(resultMocked);
when(accessMock.getColumnLength(anyList(), anyString())).thenReturn(Collections.nCopies(20, 20));
PropertyHandler propHandlerMock = mock(PropertyHandler.class);
when(propHandlerMock.getString(Settings.URL)).thenReturn("jdbc:h2");
PropertyHandlerProvider.getInstance().setPropertyHandler(propHandlerMock);
tableSetup = new TableSetup(channelList, accessMock);
metaBuilder = new MetaBuilder(channelList, accessMock);
}
use of org.openmuc.framework.lib.osgi.config.PropertyHandler in project OpenMUC by isc-konstanz.
the class MqttLoggerTest method connect.
// @BeforeAll
static void connect() {
String packageName = MqttLogger.class.getPackage().getName().toLowerCase();
System.setProperty(packageName + ".host", "localhost");
System.setProperty(packageName + ".port", "1883");
System.setProperty(packageName + ".username", "guest");
System.setProperty(packageName + ".password", "guest");
System.setProperty(packageName + ".topic", "device/data");
System.setProperty(packageName + ".maxFileCount", "2");
System.setProperty(packageName + ".maxFileSize", "1");
System.setProperty(packageName + ".maxBufferSize", "1");
String pid = MqttLogger.class.getName();
MqttLoggerSettings settings = new MqttLoggerSettings();
PropertyHandler propertyHandler = new PropertyHandler(settings, pid);
MqttSettings Mqttsettings = new MqttSettings(propertyHandler.getString(MqttLoggerSettings.HOST), propertyHandler.getInt(MqttLoggerSettings.PORT), propertyHandler.getString(MqttLoggerSettings.USERNAME), propertyHandler.getString(MqttLoggerSettings.PASSWORD), propertyHandler.getBoolean(MqttLoggerSettings.SSL), propertyHandler.getInt(MqttLoggerSettings.MAX_BUFFER_SIZE), propertyHandler.getInt(MqttLoggerSettings.MAX_FILE_SIZE), propertyHandler.getInt(MqttLoggerSettings.MAX_FILE_COUNT), propertyHandler.getInt(MqttLoggerSettings.CONNECTION_RETRY_INTERVAL), propertyHandler.getInt(MqttLoggerSettings.CONNECTION_ALIVE_INTERVAL), propertyHandler.getString(MqttLoggerSettings.PERSISTENCE_DIRECTORY));
MqttConnection connection = new MqttConnection(Mqttsettings);
MqttWriter mqttWriter = new MqttWriter(connection, "mqttlogger");
mqttWriter.getConnection().connect();
}
Aggregations