Search in sources :

Example 1 with DataLoggerNotAvailableException

use of org.openmuc.framework.dataaccess.DataLoggerNotAvailableException in project OpenMUC by isc-konstanz.

the class ChannelResourceServlet method doGetHistory.

private void doGetHistory(ToJson json, String channelId, String fromParameter, String untilParameter, HttpServletResponse response) {
    long fromTimeStamp = 0;
    long untilTimeStamp = 0;
    List<String> channelIds = dataAccess.getAllIds();
    List<Record> records = null;
    if (channelIds.contains(channelId)) {
        Channel channel = dataAccess.getChannel(channelId);
        try {
            fromTimeStamp = Long.parseLong(fromParameter);
            untilTimeStamp = Long.parseLong(untilParameter);
        } catch (NumberFormatException ex) {
            ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_BAD_REQUEST, logger, "From/To value is not a long number.");
        }
        try {
            records = channel.getLoggedRecords(fromTimeStamp, untilTimeStamp);
        } catch (DataLoggerNotAvailableException e) {
            ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, logger, e.getMessage());
        } catch (IOException e) {
            ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_NOT_FOUND, logger, e.getMessage());
        }
        json.addRecordList(records, channel.getValueType());
    }
}
Also used : Channel(org.openmuc.framework.dataaccess.Channel) DataLoggerNotAvailableException(org.openmuc.framework.dataaccess.DataLoggerNotAvailableException) Record(org.openmuc.framework.data.Record) IOException(java.io.IOException)

Example 2 with DataLoggerNotAvailableException

use of org.openmuc.framework.dataaccess.DataLoggerNotAvailableException in project OpenMUC by isc-konstanz.

the class DataManager method getDataLogger.

DataLoggerService getDataLogger(String loggerId) throws DataLoggerNotAvailableException {
    DataLoggerService dataLogger;
    if (loggerId == null || loggerId.isEmpty()) {
        dataLogger = activeDataLoggers.peekFirst();
    } else {
        dataLogger = activeDataLoggers.stream().filter(activeLogger -> activeLogger.getId().equals(loggerId)).findFirst().orElseThrow(() -> {
            logger.warn("DataLogger with id " + loggerId + " not found for reading logs!");
            return new DataLoggerNotAvailableException();
        });
    }
    logger.debug("Accessing logged values using {}", dataLogger.getId());
    return dataLogger;
}
Also used : Arrays(java.util.Arrays) ListIterator(java.util.ListIterator) DeviceScanInfo(org.openmuc.framework.config.DeviceScanInfo) LoggerFactory(org.slf4j.LoggerFactory) DriverInfo(org.openmuc.framework.config.DriverInfo) Connection(org.openmuc.framework.driver.spi.Connection) Channel(org.openmuc.framework.dataaccess.Channel) DriverConfig(org.openmuc.framework.config.DriverConfig) DeviceScanListener(org.openmuc.framework.config.DeviceScanListener) Map(java.util.Map) ParseException(org.openmuc.framework.config.ParseException) ServerMapping(org.openmuc.framework.config.ServerMapping) ServerService(org.openmuc.framework.server.spi.ServerService) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException) ScanException(org.openmuc.framework.config.ScanException) Deactivate(org.osgi.service.component.annotations.Deactivate) DriverDeviceScanListener(org.openmuc.framework.driver.spi.DriverDeviceScanListener) ReferencePolicy(org.osgi.service.component.annotations.ReferencePolicy) ConfigWriteException(org.openmuc.framework.config.ConfigWriteException) Collectors(java.util.stream.Collectors) Flag(org.openmuc.framework.data.Flag) FileNotFoundException(java.io.FileNotFoundException) Executors(java.util.concurrent.Executors) ChannelState(org.openmuc.framework.dataaccess.ChannelState) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) ChannelConfig(org.openmuc.framework.config.ChannelConfig) ChannelChangeListener(org.openmuc.framework.dataaccess.ChannelChangeListener) Entry(java.util.Map.Entry) Optional(java.util.Optional) Queue(java.util.Queue) ReadRecordContainer(org.openmuc.framework.dataaccess.ReadRecordContainer) DataLoggerNotAvailableException(org.openmuc.framework.dataaccess.DataLoggerNotAvailableException) TransformerException(javax.xml.transform.TransformerException) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) DriverOptionsFactory(org.openmuc.framework.config.option.DriverOptionsFactory) HashMap(java.util.HashMap) Deque(java.util.Deque) RootConfig(org.openmuc.framework.config.RootConfig) ConfigService(org.openmuc.framework.config.ConfigService) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) LogicalDeviceChangeListener(org.openmuc.framework.dataaccess.LogicalDeviceChangeListener) ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) Component(org.osgi.service.component.annotations.Component) WriteValueContainer(org.openmuc.framework.dataaccess.WriteValueContainer) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) DataLoggerService(org.openmuc.framework.datalogger.spi.DataLoggerService) Activate(org.osgi.service.component.annotations.Activate) DriverNotAvailableException(org.openmuc.framework.config.DriverNotAvailableException) LinkedList(java.util.LinkedList) ArgumentSyntaxException(org.openmuc.framework.config.ArgumentSyntaxException) ServerMappingContainer(org.openmuc.framework.server.spi.ServerMappingContainer) CommandProcessor(org.apache.felix.service.command.CommandProcessor) ConfigChangeListener(org.openmuc.framework.config.ConfigChangeListener) Logger(org.slf4j.Logger) ReentrantLock(java.util.concurrent.locks.ReentrantLock) IOException(java.io.IOException) File(java.io.File) LogicalDevice(org.openmuc.framework.dataaccess.LogicalDevice) ScanInterruptedException(org.openmuc.framework.config.ScanInterruptedException) DeviceConfig(org.openmuc.framework.config.DeviceConfig) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DriverService(org.openmuc.framework.driver.spi.DriverService) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) DataAccessService(org.openmuc.framework.dataaccess.DataAccessService) DeviceState(org.openmuc.framework.dataaccess.DeviceState) Reference(org.osgi.service.component.annotations.Reference) LogChannel(org.openmuc.framework.datalogger.spi.LogChannel) RecordsReceivedListener(org.openmuc.framework.driver.spi.RecordsReceivedListener) DataLoggerService(org.openmuc.framework.datalogger.spi.DataLoggerService) DataLoggerNotAvailableException(org.openmuc.framework.dataaccess.DataLoggerNotAvailableException)

Aggregations

IOException (java.io.IOException)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Deque (java.util.Deque)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 Queue (java.util.Queue)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Executors (java.util.concurrent.Executors)1 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1