Class TagHistoryDatasourceSink
- java.lang.Object
-
- com.inductiveautomation.ignition.gateway.history.sf.sinks.AbstractSink
-
- com.inductiveautomation.ignition.gateway.history.sf.sinks.AbstractDatasourceSink
-
- com.inductiveautomation.gateway.tags.history.storage.TagHistoryDatasourceSink
-
- All Implemented Interfaces:
DataSink
,HistoryStorer
,IRecordListener<DatasourceRecord>
,AnnotationStorageProvider
public class TagHistoryDatasourceSink extends AbstractDatasourceSink implements AnnotationStorageProvider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
TagHistoryDatasourceSink.ProviderId
-
Field Summary
Fields Modifier and Type Field Description protected boolean
checkEnabled
-
Fields inherited from class com.inductiveautomation.ignition.gateway.history.sf.sinks.AbstractSink
faulted, faultError, faultTime
-
Fields inherited from interface com.inductiveautomation.ignition.gateway.history.DataSink
LOG_NAME_TEMPLATE
-
-
Constructor Summary
Constructors Constructor Description TagHistoryDatasourceSink(GatewayContext context, TagHistoryProviderRecord profile, TagHistorianSettingsRecord settings)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
acceptsData(HistoryFlavor dataType)
Returns whether or not the storer can accept the specified type of data.protected com.google.common.collect.Multimap<java.lang.String,HistoricalTagValue>
breakupByPartition(PartitionManager pm, ScanclassHistorySet theData)
Results
browse(QualifiedPath root, BrowseFilter filter)
protected void
checkTables()
protected PartitionManager
createPartitionManager(java.lang.Integer systemId, int time, TimeUnits units)
protected java.util.List<QualifiedValue>
executeAnnotationQuery(SRConnection conn, java.lang.String query, java.util.List<Annotation> annotations, java.util.function.Function<Annotation,java.lang.String> idRetriever, com.inductiveautomation.gateway.tags.history.storage.TagHistoryDatasourceSink.QueryType qt)
java.util.Map<java.lang.String,java.lang.Long>
getCurrentTagIds(TagHistoryDatasourceSink.ProviderId provId, java.util.Collection<java.lang.String> tagPathKeys)
This is a simplified version of getTagIds for retrieving the latest ids of existing tags.protected java.lang.String
getDescriptionKey()
protected int
getIdOfScanclassName(TagHistoryDatasourceSink.ProviderId pid, java.lang.String scName)
Gets the id of the given SC name, inserting if necessary.protected java.lang.String
getKeyForTagIdCache(int providerId, java.lang.String path)
protected java.lang.String
getLocalGatewayName()
protected PartitionManager
getOrCreatePartitionManager(java.lang.Integer systemId)
TagHistoryDatasourceSink.ProviderId
getProviderId(java.lang.String gatewayName, java.lang.String providerName)
protected TagHistoryDatasourceSink.ProviderId
getProviderIdForPath(QualifiedPath p)
protected SystemProviderDetails
getSystemDetails(int systemId)
Looks up the system details for the given id.protected SystemProviderDetails
getSystemDetails(java.lang.String gatewayName, boolean create)
Get the provider details of the gateway.protected java.util.Map<java.lang.String,HistoricalTagInfo>
getTagIds(ScanclassHistorySet data, TagHistoryDatasourceSink.ProviderId provId)
protected java.util.Map<QualifiedPath,java.lang.Long>
getTagPathIds(TagHistoryDatasourceSink.ProviderId pid, java.util.Collection<QualifiedPath> qualifiedPaths)
protected void
initialize()
protected java.util.List<QualifiedValue>
insertAnnotations(SRConnection conn, java.util.List<Annotation> annotations)
protected void
insertProvider(java.lang.String systemName, java.lang.String providerName)
protected void
insertTagValues(SRConnection conn, ScanclassHistorySet theData, TagHistoryDatasourceSink.ProviderId ids)
Actually inserts the tag values in to the Tag Value table.boolean
isAccepting()
Returns whether the data store is accepting data.boolean
isLicensedFor(HistoryFlavor dataType)
Assuming the storer accepts the flavor, is it currently licensed for it? If not, the data will not be stored.protected java.util.List<TagPath>
loadAllTags()
protected SystemProviderDetails
loadOrCreateSystemDetails(java.lang.String systemName)
protected void
loadTagIdCache(java.lang.Integer systemId)
protected void
retireTags(SRConnection conn, TagHistoryDatasourceSink.ProviderId pid, java.util.List<TagPath> paths)
protected void
retireTags(SRConnection conn, TagRetirementList paths)
Marks the given paths as retired, and removes them from the cache.protected void
retireTagsInternal(SRConnection conn, TagHistoryDatasourceSink.ProviderId pid, java.util.List<HistoricalTagInfo> toRetire)
void
setDatasourceName(java.lang.String dataSource)
void
shutdown()
protected void
startMaintenanceTasks()
If a maintenance task is defined, and we've been initialized (determined by the presence of Partition Manager), will register the tag with the execution engine.protected void
startOptimizedEngine(java.lang.Integer systemId, PartitionManager pm)
void
startup()
protected void
stopMaintenanceTasks()
protected java.util.List<QualifiedValue>
storeAnnotations(SRConnection conn, java.util.List<Annotation> annotations)
java.util.List<QualifiedValue>
storeAnnotations(java.util.List<Annotation> annotations)
protected void
storeDataToDatasource(SRConnection conn, HistoricalData data)
Stores the given data against the connection which has been pre-setup to execute in a transaction.protected void
storeScanClassSet(SRConnection conn, ScanclassHistorySet data)
protected void
storeValueToOptimized(OptimizedTableEngine engine, HistoricalTagValue v, int tagid, long ts)
protected boolean
tryToInit()
Initialization is really complex in this class because we don't really want to initialize until data comes in.protected void
uninitialize()
protected void
updateSCExecRecord(SRConnection conn, TagHistoryDatasourceSink.ProviderId provId, java.lang.String scName, int rate, java.util.Date execTime)
This class updates the scan class execution table.void
updateSettings(TagHistoryProviderRecord profile, TagHistorianSettingsRecord settings)
void
updateStatMetrics(java.util.Map<java.lang.String,NamedValue<StatMetric>> statMetrics)
void
updateStatusProperties(java.util.List<NamedValue> properties)
protected void
updateSystemName(java.lang.String newName)
protected boolean
useSce(ScanclassHistorySet data)
-
Methods inherited from class com.inductiveautomation.ignition.gateway.history.sf.sinks.AbstractDatasourceSink
getContext, getDatasource, getDatasourceName, getInfo, getQueryCache, recordAdded, recordDeleted, recordUpdated, runFirstTimeChecks, storeData, storeToDatasource, useBatching, useGeneratedKeys
-
Methods inherited from class com.inductiveautomation.ignition.gateway.history.sf.sinks.AbstractSink
createLogger, getFaultReason, getLogger, getPipelineName, getQuarantineManager, isFaulted, isInitialized, isStarted, setFaulted, setInitialized
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.inductiveautomation.ignition.gateway.history.DataSink
getLogName
-
-
-
-
Constructor Detail
-
TagHistoryDatasourceSink
public TagHistoryDatasourceSink(GatewayContext context, TagHistoryProviderRecord profile, TagHistorianSettingsRecord settings)
-
-
Method Detail
-
getLocalGatewayName
protected java.lang.String getLocalGatewayName()
-
updateSettings
public void updateSettings(TagHistoryProviderRecord profile, TagHistorianSettingsRecord settings)
-
setDatasourceName
public void setDatasourceName(java.lang.String dataSource)
- Overrides:
setDatasourceName
in classAbstractDatasourceSink
-
updateStatusProperties
public void updateStatusProperties(java.util.List<NamedValue> properties)
-
updateStatMetrics
public void updateStatMetrics(java.util.Map<java.lang.String,NamedValue<StatMetric>> statMetrics)
-
getDescriptionKey
protected java.lang.String getDescriptionKey()
- Specified by:
getDescriptionKey
in classAbstractDatasourceSink
-
acceptsData
public boolean acceptsData(HistoryFlavor dataType)
Description copied from interface:HistoryStorer
Returns whether or not the storer can accept the specified type of data.- Specified by:
acceptsData
in interfaceHistoryStorer
-
isLicensedFor
public boolean isLicensedFor(HistoryFlavor dataType)
Description copied from interface:HistoryStorer
Assuming the storer accepts the flavor, is it currently licensed for it? If not, the data will not be stored.- Specified by:
isLicensedFor
in interfaceHistoryStorer
-
tryToInit
protected boolean tryToInit()
Initialization is really complex in this class because we don't really want to initialize until data comes in. So, we have to prevent init, but also claim to accept, until we get the first data.- Overrides:
tryToInit
in classAbstractSink
-
startup
public void startup()
- Specified by:
startup
in interfaceDataSink
- Overrides:
startup
in classAbstractDatasourceSink
-
shutdown
public void shutdown()
- Specified by:
shutdown
in interfaceDataSink
- Overrides:
shutdown
in classAbstractDatasourceSink
-
initialize
protected void initialize()
- Overrides:
initialize
in classAbstractSink
-
uninitialize
protected void uninitialize()
- Overrides:
uninitialize
in classAbstractDatasourceSink
-
getOrCreatePartitionManager
protected PartitionManager getOrCreatePartitionManager(java.lang.Integer systemId) throws java.lang.Exception
- Throws:
java.lang.Exception
-
startOptimizedEngine
protected void startOptimizedEngine(java.lang.Integer systemId, PartitionManager pm)
-
createPartitionManager
protected PartitionManager createPartitionManager(java.lang.Integer systemId, int time, TimeUnits units) throws java.lang.Exception
- Throws:
java.lang.Exception
-
isAccepting
public boolean isAccepting()
Description copied from interface:DataSink
Returns whether the data store is accepting data.- Specified by:
isAccepting
in interfaceDataSink
- Overrides:
isAccepting
in classAbstractDatasourceSink
-
useSce
protected boolean useSce(ScanclassHistorySet data)
-
getProviderId
public TagHistoryDatasourceSink.ProviderId getProviderId(java.lang.String gatewayName, java.lang.String providerName) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getSystemDetails
protected SystemProviderDetails getSystemDetails(java.lang.String gatewayName, boolean create) throws java.lang.Exception
Get the provider details of the gateway. Will look it up/insert the gateway if allowed and necessary.- Throws:
java.lang.Exception
-
getSystemDetails
protected SystemProviderDetails getSystemDetails(int systemId)
Looks up the system details for the given id.
-
loadOrCreateSystemDetails
protected SystemProviderDetails loadOrCreateSystemDetails(java.lang.String systemName) throws java.lang.Exception
- Throws:
java.lang.Exception
-
insertProvider
protected void insertProvider(java.lang.String systemName, java.lang.String providerName) throws java.lang.Exception
- Throws:
java.lang.Exception
-
storeDataToDatasource
protected void storeDataToDatasource(SRConnection conn, HistoricalData data) throws java.lang.Exception
Stores the given data against the connection which has been pre-setup to execute in a transaction. Any error that occurs will cause the transaction to roll back.- Specified by:
storeDataToDatasource
in classAbstractDatasourceSink
- Throws:
java.lang.Exception
-
storeScanClassSet
protected void storeScanClassSet(SRConnection conn, ScanclassHistorySet data) throws java.lang.Exception
- Throws:
java.lang.Exception
-
updateSystemName
protected void updateSystemName(java.lang.String newName)
-
startMaintenanceTasks
protected void startMaintenanceTasks()
If a maintenance task is defined, and we've been initialized (determined by the presence of Partition Manager), will register the tag with the execution engine.
-
stopMaintenanceTasks
protected void stopMaintenanceTasks()
-
updateSCExecRecord
protected void updateSCExecRecord(SRConnection conn, TagHistoryDatasourceSink.ProviderId provId, java.lang.String scName, int rate, java.util.Date execTime) throws java.lang.Exception
This class updates the scan class execution table. This function updates an existing row with: matching name, matching rate, and end_time>(exec-2*rate). If nothing matches, a new row is inserted. A special case, however, occurs when rate==0. This indicates that the scan class does not run regularly. In this case, nothing will happen.- Throws:
java.lang.Exception
-
getIdOfScanclassName
protected int getIdOfScanclassName(TagHistoryDatasourceSink.ProviderId pid, java.lang.String scName) throws java.lang.Exception
Gets the id of the given SC name, inserting if necessary.- Throws:
java.lang.Exception
-
getKeyForTagIdCache
protected java.lang.String getKeyForTagIdCache(int providerId, java.lang.String path)
-
loadTagIdCache
protected void loadTagIdCache(java.lang.Integer systemId) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getCurrentTagIds
public java.util.Map<java.lang.String,java.lang.Long> getCurrentTagIds(TagHistoryDatasourceSink.ProviderId provId, java.util.Collection<java.lang.String> tagPathKeys) throws java.lang.Exception
This is a simplified version of getTagIds for retrieving the latest ids of existing tags. It will not add or retire tags. Anything that isn't present and valid is returned as -1.- Throws:
java.lang.Exception
-
getTagIds
protected java.util.Map<java.lang.String,HistoricalTagInfo> getTagIds(ScanclassHistorySet data, TagHistoryDatasourceSink.ProviderId provId) throws java.lang.Exception
- Throws:
java.lang.Exception
-
retireTags
protected void retireTags(SRConnection conn, TagRetirementList paths) throws java.lang.Exception
Marks the given paths as retired, and removes them from the cache. This is used when tags are deleted from the system. The getTagIds() function also retires tags when necessary.- Throws:
java.lang.Exception
-
retireTags
protected void retireTags(SRConnection conn, TagHistoryDatasourceSink.ProviderId pid, java.util.List<TagPath> paths) throws java.lang.Exception
- Throws:
java.lang.Exception
-
retireTagsInternal
protected void retireTagsInternal(SRConnection conn, TagHistoryDatasourceSink.ProviderId pid, java.util.List<HistoricalTagInfo> toRetire) throws java.lang.Exception
- Throws:
java.lang.Exception
-
insertTagValues
protected void insertTagValues(SRConnection conn, ScanclassHistorySet theData, TagHistoryDatasourceSink.ProviderId ids) throws java.lang.Exception
Actually inserts the tag values in to the Tag Value table.- Throws:
java.lang.Exception
-
loadAllTags
protected java.util.List<TagPath> loadAllTags()
-
browse
public Results browse(QualifiedPath root, BrowseFilter filter)
-
breakupByPartition
protected com.google.common.collect.Multimap<java.lang.String,HistoricalTagValue> breakupByPartition(PartitionManager pm, ScanclassHistorySet theData) throws java.lang.Exception
- Throws:
java.lang.Exception
-
storeValueToOptimized
protected void storeValueToOptimized(OptimizedTableEngine engine, HistoricalTagValue v, int tagid, long ts)
-
getProviderIdForPath
protected TagHistoryDatasourceSink.ProviderId getProviderIdForPath(QualifiedPath p)
-
getTagPathIds
protected java.util.Map<QualifiedPath,java.lang.Long> getTagPathIds(TagHistoryDatasourceSink.ProviderId pid, java.util.Collection<QualifiedPath> qualifiedPaths) throws java.lang.Exception
- Throws:
java.lang.Exception
-
storeAnnotations
public java.util.List<QualifiedValue> storeAnnotations(java.util.List<Annotation> annotations)
- Specified by:
storeAnnotations
in interfaceAnnotationStorageProvider
-
storeAnnotations
protected java.util.List<QualifiedValue> storeAnnotations(SRConnection conn, java.util.List<Annotation> annotations) throws java.lang.Exception
- Throws:
java.lang.Exception
-
insertAnnotations
protected java.util.List<QualifiedValue> insertAnnotations(SRConnection conn, java.util.List<Annotation> annotations) throws java.lang.Exception
- Throws:
java.lang.Exception
-
executeAnnotationQuery
protected java.util.List<QualifiedValue> executeAnnotationQuery(SRConnection conn, java.lang.String query, java.util.List<Annotation> annotations, java.util.function.Function<Annotation,java.lang.String> idRetriever, com.inductiveautomation.gateway.tags.history.storage.TagHistoryDatasourceSink.QueryType qt) throws java.lang.Exception
- Throws:
java.lang.Exception
-
checkTables
protected void checkTables() throws java.lang.Exception
- Throws:
java.lang.Exception
-
-