Skip to content
Snippets Groups Projects
Commit b1331653 authored by gwen-soleil's avatar gwen-soleil
Browse files

WIP: start implementing data fetching from multiple databases.

parent 3dabdabc
No related branches found
No related tags found
No related merge requests found
/*
* Copyright (c) 2025.
*
* Synchrotron Soleil
* L'Orme des merisiers
* Saint Aubin
* BP48
* 91192 GIF-SUR-YVETTE CEDEX
*
* gwenaelle.abeille@synchrotron-soleil.fr
*
* This software is a computer program whose purpose is to provide an Java API for managing insertion and fetching of Tango data into a database
*
* This software is governed by the CeCILL license under French law and abiding by the rules of distribution of free software.
* You can use, modify and/ or redistribute the software under the terms of the CeCILL license as circulated by CEA, CNRS and
* INRIA at the following URL "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users
* are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive
* licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or
* reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to
* manipulate, and that also therefore means that it is reserved for developers and experienced professionals having
* in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and
* operate it in the same conditions as regards security.
*
* The fact that you are presently reading this means that you have had knowledge of the CeCILL license and that you accept its
* terms.
*/
package fr.soleil.tango.archiving.build;
import java.sql.Timestamp;
import java.util.Set;
public class DatabaseSelector {
private final String id;
private final Set<String> attributeNamesRegexList;
private final Timestamp startTimestamp;
private final Timestamp endTimestamp;
private final DatabaseConnectionConfig config;
private final boolean isConfigurationMaster;
public DatabaseSelector(final String id, final Timestamp startTimestamp, final Timestamp endTimestamp,
Set<String> attributeNamesRegexList, DatabaseConnectionConfig config,
boolean isConfigurationMaster) {
this.id = id;
this.startTimestamp = startTimestamp;
this.endTimestamp = endTimestamp;
this.attributeNamesRegexList = attributeNamesRegexList;
this.isConfigurationMaster = isConfigurationMaster;
this.config = config;
}
public boolean isConfigurationMaster() {
return isConfigurationMaster;
}
public String getId() {
return id;
}
public DatabaseConnectionConfig getConfig() {
return config;
}
public Set<String> getAttributeNamesRegexList() {
return attributeNamesRegexList;
}
public Timestamp getStartTimestamp() {
return startTimestamp;
}
public Timestamp getEndTimestamp() {
return endTimestamp;
}
}
...@@ -32,14 +32,21 @@ ...@@ -32,14 +32,21 @@
package fr.soleil.tango.archiving.build; package fr.soleil.tango.archiving.build;
import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import fr.soleil.database.connection.DataBaseParameters; import fr.soleil.tango.archiving.exception.TangoTimeseriesException;
import fr.soleil.tango.archiving.infra.injection.LegacyModuleInjector; import fr.soleil.tango.archiving.infra.injection.MySqlDBModuleInjector;
import fr.soleil.tango.archiving.infra.injection.TimeScaleModuleInjector; import fr.soleil.tango.archiving.infra.injection.TimeScaleModuleInjector;
import fr.soleil.tango.archiving.services.MultiTangoArchivingFetcherService;
import fr.soleil.tango.archiving.services.TangoArchivingConfigService; import fr.soleil.tango.archiving.services.TangoArchivingConfigService;
import fr.soleil.tango.archiving.services.TangoArchivingFetcherService; import fr.soleil.tango.archiving.services.TangoArchivingFetcherService;
import fr.soleil.tango.archiving.services.TangoArchivingInserterService; import fr.soleil.tango.archiving.services.TangoArchivingInserterService;
import fr.soleil.tango.archiving.services.mulitdb.MultiArchivingFetcherDataSources;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static fr.soleil.tango.archiving.build.DataBasePoolsCache.getDataSource; import static fr.soleil.tango.archiving.build.DataBasePoolsCache.getDataSource;
...@@ -70,6 +77,35 @@ public class TangoArchivingServicesBuilder { ...@@ -70,6 +77,35 @@ public class TangoArchivingServicesBuilder {
return injector.getInstance(TangoArchivingConfigService.class); return injector.getInstance(TangoArchivingConfigService.class);
} }
public MultiTangoArchivingFetcherService buildMultiConfigFetcher(List<DatabaseSelector> databaseSelector) {
Map<String, DatabaseSelector> databaseSelectorMap = new HashMap<>();
Map<String, TangoArchivingFetcherService> attributeFetcherMap = new HashMap<>();
for (DatabaseSelector selector : databaseSelector) {
DatabaseConnectionConfig config = selector.getConfig();
Injector injector;
if (config.getDbType() == DatabaseConnectionConfig.DataBaseType.POSTGRESQL) {
injector = Guice.createInjector(new TimeScaleModuleInjector(getDataSource(config)));
} else if (config.getDbType() == DatabaseConnectionConfig.DataBaseType.MYSQL) {
injector = Guice.createInjector(new MySqlDBModuleInjector(getDataSource(config)));
} else {
throw new TangoTimeseriesException("DB type not supported");
}
TangoArchivingFetcherService service = injector.getInstance(TangoArchivingFetcherService.class);
databaseSelectorMap.put(selector.getId(), selector);
attributeFetcherMap.put(selector.getId(), service);
}
MultiArchivingFetcherDataSources dataSources = new MultiArchivingFetcherDataSources(databaseSelectorMap, attributeFetcherMap);
Injector multiInjector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
super.configure();
bind(MultiArchivingFetcherDataSources.class).toInstance(dataSources);
}
});
return multiInjector.getInstance(MultiTangoArchivingFetcherService.class);
}
/** /**
* Create a service to insert tango attributes into a PostGreSQL/Timescale database * Create a service to insert tango attributes into a PostGreSQL/Timescale database
* If several services are built, the datasource connection pools will be shared if database type/host/name/user are the same * If several services are built, the datasource connection pools will be shared if database type/host/name/user are the same
...@@ -82,16 +118,5 @@ public class TangoArchivingServicesBuilder { ...@@ -82,16 +118,5 @@ public class TangoArchivingServicesBuilder {
return injector.getInstance(TangoArchivingInserterService.class); return injector.getInstance(TangoArchivingInserterService.class);
} }
/**
* Create a service to insert tango attributes into legacy HDB/TDB database
*
* @param dataBaseParameters {@link DataBaseParameters}
* @return {@link TangoArchivingInserterService}
*/
public TangoArchivingInserterService buildLegacyInserter(DataBaseParameters dataBaseParameters) {
Injector injector = Guice.createInjector(new LegacyModuleInjector(dataBaseParameters));
return injector.getInstance(TangoArchivingInserterService.class);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment