Search in sources :

Example 1 with InfluxDbPacketSaver

use of me.retrodaredevil.solarthing.influxdb.influxdb1.InfluxDbPacketSaver in project solarthing by wildmountainfarms.

the class PacketHandlerInit method getPacketHandlerBundle.

public static PacketHandlerBundle getPacketHandlerBundle(List<DatabaseConfig> configs, String uniqueStatusName, String uniqueEventName, String sourceId, int fragmentId) {
    List<PacketHandler> statusPacketHandlers = new ArrayList<>();
    List<PacketHandler> eventPacketHandlers = new ArrayList<>();
    for (DatabaseConfig config : configs) {
        IndividualSettings statusIndividualSettings = config.getIndividualSettingsOrDefault(Constants.DATABASE_UPLOAD_ID, null);
        FrequencySettings statusFrequencySettings = statusIndividualSettings != null ? statusIndividualSettings.getFrequencySettings() : FrequencySettings.NORMAL_SETTINGS;
        if (CouchDbDatabaseSettings.TYPE.equals(config.getType())) {
            CouchDbDatabaseSettings settings = (CouchDbDatabaseSettings) config.getSettings();
            CouchDbInstance instance = CouchDbUtil.createInstance(settings.getCouchProperties(), settings.getOkHttpProperties());
            statusPacketHandlers.add(new ThrottleFactorPacketHandler(new AsyncPacketHandlerWrapper(new PrintPacketHandleExceptionWrapper(new CouchDbPacketSaver(instance.getDatabase(uniqueStatusName), false))), statusFrequencySettings));
            eventPacketHandlers.add(new AsyncRetryingPacketHandler(new CouchDbPacketSaver(instance.getDatabase(uniqueEventName), true)));
        } else if (InfluxDbDatabaseSettings.TYPE.equals(config.getType())) {
            LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "You are using InfluxDB 1.X! It is recommended that you switch to 2.0, but is not required.");
            InfluxDbDatabaseSettings settings = (InfluxDbDatabaseSettings) config.getSettings();
            String databaseName = settings.getDatabaseName();
            String measurementName = settings.getMeasurementName();
            statusPacketHandlers.add(new ThrottleFactorPacketHandler(new AsyncPacketHandlerWrapper(new PrintPacketHandleExceptionWrapper(new InfluxDbPacketSaver(settings.getInfluxProperties(), settings.getOkHttpProperties(), new ConstantNameGetter(databaseName != null ? databaseName : uniqueStatusName), measurementName != null ? new ConstantMeasurementPacketPointCreator(measurementName) : (databaseName != null ? new ConstantMeasurementPacketPointCreator(uniqueStatusName) : DocumentedMeasurementPacketPointCreator.INSTANCE), new FrequentRetentionPolicyGetter(new FrequentHandler<>(settings.getFrequentStatusRetentionPolicyList()))))), statusFrequencySettings));
            eventPacketHandlers.add(new AsyncRetryingPacketHandler(new InfluxDbPacketSaver(settings.getInfluxProperties(), settings.getOkHttpProperties(), new ConstantNameGetter(databaseName != null ? databaseName : uniqueEventName), measurementName != null ? new ConstantMeasurementPacketPointCreator(measurementName) : (databaseName != null ? new ConstantMeasurementPacketPointCreator(uniqueEventName) : DocumentedMeasurementPacketPointCreator.INSTANCE), new ConstantRetentionPolicyGetter(settings.getEventRetentionPolicy()))));
        } else if (InfluxDb2DatabaseSettings.TYPE.equals(config.getType())) {
            InfluxDb2DatabaseSettings settings = (InfluxDb2DatabaseSettings) config.getSettings();
            statusPacketHandlers.add(new ThrottleFactorPacketHandler(new AsyncPacketHandlerWrapper(new PrintPacketHandleExceptionWrapper(new InfluxDb2PacketSaver(settings.getInfluxDbProperties(), settings.getOkHttpProperties(), new ConstantNameGetter(uniqueStatusName), DocumentedMeasurementPacketPoint2Creator.INSTANCE))), statusFrequencySettings));
            eventPacketHandlers.add(new AsyncRetryingPacketHandler(new InfluxDb2PacketSaver(settings.getInfluxDbProperties(), settings.getOkHttpProperties(), new ConstantNameGetter(uniqueEventName), DocumentedMeasurementPacketPoint2Creator.INSTANCE)));
        } else if (LatestFileDatabaseSettings.TYPE.equals(config.getType())) {
            LatestFileDatabaseSettings settings = (LatestFileDatabaseSettings) config.getSettings();
            LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "Adding latest file 'database'. This currently only saves 'status' packets");
            statusPacketHandlers.add(new ThrottleFactorPacketHandler(new FileWritePacketHandler(settings.getFile(), new JacksonStringPacketHandler(MAPPER), false), statusFrequencySettings));
        } else if (PostDatabaseSettings.TYPE.equals(config.getType())) {
            PostDatabaseSettings settings = (PostDatabaseSettings) config.getSettings();
            statusPacketHandlers.add(new ThrottleFactorPacketHandler(new AsyncPacketHandlerWrapper(new PostPacketHandler(settings.getUrl(), new JacksonStringPacketHandler(MAPPER), MediaType.get("application/json"))), statusFrequencySettings));
        } else if (MqttDatabaseSettings.TYPE.equals(config.getType())) {
            MqttDatabaseSettings settings = (MqttDatabaseSettings) config.getSettings();
            String client = settings.getClientId();
            if (client == null) {
                client = "solarthing-" + sourceId + "-" + fragmentId;
            }
            statusPacketHandlers.add(new ThrottleFactorPacketHandler(new AsyncPacketHandlerWrapper(new MqttPacketSaver(settings.getBroker(), client, settings.getUsername(), settings.getPassword(), settings.getTopicFormat(), settings.isRetain(), sourceId, fragmentId)), statusFrequencySettings));
        }
    }
    return new PacketHandlerBundle(statusPacketHandlers, eventPacketHandlers);
}
Also used : ArrayList(java.util.ArrayList) FileWritePacketHandler(me.retrodaredevil.solarthing.packets.handling.implementations.FileWritePacketHandler) CouchDbPacketSaver(me.retrodaredevil.solarthing.couchdb.CouchDbPacketSaver) PostPacketHandler(me.retrodaredevil.solarthing.packets.handling.implementations.PostPacketHandler) CouchDbInstance(me.retrodaredevil.couchdbjava.CouchDbInstance) MqttPacketSaver(me.retrodaredevil.solarthing.mqtt.MqttPacketSaver) FrequentRetentionPolicyGetter(me.retrodaredevil.solarthing.influxdb.retention.FrequentRetentionPolicyGetter) ConstantMeasurementPacketPointCreator(me.retrodaredevil.solarthing.influxdb.influxdb1.ConstantMeasurementPacketPointCreator) ConstantRetentionPolicyGetter(me.retrodaredevil.solarthing.influxdb.retention.ConstantRetentionPolicyGetter) InfluxDbPacketSaver(me.retrodaredevil.solarthing.influxdb.influxdb1.InfluxDbPacketSaver) InfluxDb2PacketSaver(me.retrodaredevil.solarthing.influxdb.infuxdb2.InfluxDb2PacketSaver) FileWritePacketHandler(me.retrodaredevil.solarthing.packets.handling.implementations.FileWritePacketHandler) PostPacketHandler(me.retrodaredevil.solarthing.packets.handling.implementations.PostPacketHandler) JacksonStringPacketHandler(me.retrodaredevil.solarthing.packets.handling.implementations.JacksonStringPacketHandler) JacksonStringPacketHandler(me.retrodaredevil.solarthing.packets.handling.implementations.JacksonStringPacketHandler) ConstantNameGetter(me.retrodaredevil.solarthing.influxdb.ConstantNameGetter) IndividualSettings(me.retrodaredevil.solarthing.config.databases.IndividualSettings)

Aggregations

ArrayList (java.util.ArrayList)1 CouchDbInstance (me.retrodaredevil.couchdbjava.CouchDbInstance)1 IndividualSettings (me.retrodaredevil.solarthing.config.databases.IndividualSettings)1 CouchDbPacketSaver (me.retrodaredevil.solarthing.couchdb.CouchDbPacketSaver)1 ConstantNameGetter (me.retrodaredevil.solarthing.influxdb.ConstantNameGetter)1 ConstantMeasurementPacketPointCreator (me.retrodaredevil.solarthing.influxdb.influxdb1.ConstantMeasurementPacketPointCreator)1 InfluxDbPacketSaver (me.retrodaredevil.solarthing.influxdb.influxdb1.InfluxDbPacketSaver)1 InfluxDb2PacketSaver (me.retrodaredevil.solarthing.influxdb.infuxdb2.InfluxDb2PacketSaver)1 ConstantRetentionPolicyGetter (me.retrodaredevil.solarthing.influxdb.retention.ConstantRetentionPolicyGetter)1 FrequentRetentionPolicyGetter (me.retrodaredevil.solarthing.influxdb.retention.FrequentRetentionPolicyGetter)1 MqttPacketSaver (me.retrodaredevil.solarthing.mqtt.MqttPacketSaver)1 FileWritePacketHandler (me.retrodaredevil.solarthing.packets.handling.implementations.FileWritePacketHandler)1 JacksonStringPacketHandler (me.retrodaredevil.solarthing.packets.handling.implementations.JacksonStringPacketHandler)1 PostPacketHandler (me.retrodaredevil.solarthing.packets.handling.implementations.PostPacketHandler)1