Skip to content
Snippets Groups Projects
Select Git revision
  • 3dabdabc844f70d5039727f78bfcbc145f5b63c3
  • main default protected
  • TANGOARCH-955
  • TANGOARCH-898
4 results

tango-controls-timeseries

  • Clone with SSH
  • Clone with HTTPS
  • Table of content

    Tango TimeSeries (TTS) API

    A Java API to managed insert/select of Tango timeseries data with Timescale.

    This project contains 2 modules:

    • tango-timeseries-persistence: contains all API to interact with the timeseries database
    • tango-archiver-pool config: manages the configuration of the archiving Tango devices.

    tango-timeseries-persistence

    Contains 3 services: Tango data insertion, Tango data fetching and configuration

    Tango data insertion

    The first one is to insert Tango attributes (class fr.soleil.tango.archiving.services.TangoArchivingInserterService). Sample code to register an attribute and insert a value:

      // build database connection
    DatabaseConnectionConfig config = new DatabaseConnectionConfig(); 
    config.setName("tts");
    config.setHost("test-postgres-01");
    config.setDbType(DatabaseConnectionConfig.DataBaseType.POSTGRESQL);
    config.setName("tts");
    config.setUser("tts");
    config.setPassword("tts");
    config.setPort("5432");
    config.setConnectionTimeout(10000);
    config.setIdleTimeout(10000);
    config.setMaxPoolSize(90);
    
    // start an new attribute in periodic mode
    final TangoArchivingInserterService insertService = new TangoArchivingServicesBuilder().buildInserter(config);
    InsertionModes insertionModes = new InsertionModes();
    insertionModes.setPeriodic(true);
    insertionModes.setPeriodPeriodic(124);
    insertService.registerAttribute("archiving/source/tangotest.1/double_scalar",insertionModes, "archiving/archiver/1",0);
    
    // insert a value
    AttributeEvent event = new AttributeEvent();
    event.setDataTime(Timestamp.from(Instant.now()));
    event.setQuality(1);
    event.setFullName("archiving/source/tangotest.1/double_scalar");
    event.setValueR(1);
    event.setValueR(2);
    insertService.insertAttribute(event, AttrDataFormat.SCALAR, false);

    Tango data Fetching

    The second service is to fetch data from the database (class fr.soleil.tango.archiving.services.TangoArchivingFetcherService). Here is a sample code:

      TangoArchivingFetcherService fetcherService = new TangoArchivingServicesBuilder().buildFetcher(config);
    // get last inserted value
    AttributeValue value = fetcherService.getLast("archiving/source/tangotest.1/double_scalar", false);
    // get all values since a timestamp
    AttributeValueSeries values = fetcherService.getSince("archiving/source/tangotest.1/double_scalar", Timestamp.valueOf(LocalDateTime.now().minusDays(30)), false);

    Archiving configuration

    The third service is for managing archiving configuration (class fr.soleil.tango.archiving.services.TangoArchivingConfigService). Here is a sample code:

      TangoArchivingConfigService configService = new TangoArchivingServicesBuilder().buildConfigFetcher(config);
    final Map<InsertionModes, InsertionStatus> started = configService.getStartedAttributes();
    final Optional<AttributeConfig> attributeConfig = configService.getAttributeConfig(123);

    tango-archiver-pool config

    This module is to manage the configuration of the archiving (start or stop attributes) through Tango devices (called archiver)

    DatabaseConnectionConfig config = new DatabaseConnectionConfig();
    config.setName("tts");
    config.setHost("postgres-01");
    config.setUser("tts");
    config.setPassword("tts");
    config.setDbType(DatabaseConnectionConfig.DataBaseType.POSTGRESQL);
    
    TangoArchiverProperties properties = new TangoArchiverProperties();
    properties.setArchiverClassName("TimeseriesArchiver");
    
    TangoArchivingSystemConfigurationService service = new TangoArchivingSystemConfigurationBuilder().build(config, properties);
    service.updateArchiversList();
    
    ArchivingConfigs archivingConfigs = new ArchivingConfigs();
    ArchivingConfig config = new ArchivingConfig();
    AttributeConfig attributeConfig = new AttributeConfig();
    InsertionModes modes = new InsertionModes();
    modes.setPeriodic(true);
    modes.setPeriodPeriodic(100);
    config.setModes(modes);
    config.setAttributeConfig(attributeConfig);
    archivingConfigs.addConfiguration(config);
    
    Map<String, ArchivingConfigs> result = service.startArchiving(archivingConfigs);

    Foreseen evolutions

    Backport existing Legacy MySQL API to this API