-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrated persistence services from openhab1-addons
Signed-off-by: Kai Kreuzer <[email protected]>
- Loading branch information
1 parent
6c43a91
commit d189c71
Showing
184 changed files
with
14,185 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="test" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>org.openhab.persistence.dynamodb</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
4 changes: 4 additions & 0 deletions
4
bundles/org.openhab.persistence.dynamodb/.settings/org.eclipse.core.resources.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
eclipse.preferences.version=1 | ||
encoding//src/main/java=UTF-8 | ||
encoding//src/test/java=UTF-8 | ||
encoding/<project>=UTF-8 |
6 changes: 6 additions & 0 deletions
6
bundles/org.openhab.persistence.dynamodb/.settings/org.eclipse.jdt.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
org.eclipse.jdt.core.compiler.release=disabled | ||
org.eclipse.jdt.core.compiler.source=1.8 |
2 changes: 2 additions & 0 deletions
2
bundles/org.openhab.persistence.dynamodb/.settings/org.eclipse.jdt.ui.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eclipse.preferences.version=1 | ||
formatter_settings_version=12 |
4 changes: 4 additions & 0 deletions
4
bundles/org.openhab.persistence.dynamodb/.settings/org.eclipse.m2e.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
3 changes: 3 additions & 0 deletions
3
bundles/org.openhab.persistence.dynamodb/.settings/org.eclipse.pde.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
eclipse.preferences.version=1 | ||
pluginProject.extensions=false | ||
resolve.requirebundle=false |
117 changes: 117 additions & 0 deletions
117
bundles/org.openhab.persistence.dynamodb/ESH-INF/config/config.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<config-description:config-descriptions | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:config-description="http://openhab.org/schemas/config-description/v1.0.0" | ||
xsi:schemaLocation="http://openhab.org/schemas/config-description/v1.0.0 | ||
http://openhab.org/schemas/config-description-1.0.0.xsd"> | ||
|
||
<config-description uri="persistence:dynamodb"> | ||
|
||
<!-- | ||
############################ Amazon DynamoDB Persistence Service ################################## | ||
# | ||
# The following parameters are used to configure Amazon DynamoDB Persistence. | ||
# | ||
# Further details at https://docs.openhab.org/addons/persistence/dynamodb/readme.html | ||
# | ||
# | ||
# CONNECTION SETTINGS (follow OPTION 1 or OPTION 2) | ||
# | ||
# OPTION 1 (using accessKey and secretKey) | ||
#accessKey=AKIAIOSFODNN7EXAMPLE | ||
#secretKey=3+AAAAABBBbbbCCCCCCdddddd+7mnbIOLH | ||
#region=eu-west-1 | ||
# OPTION 2 (using profilesConfigFile and profile) | ||
# where profilesConfigFile points to AWS credentials file | ||
#profilesConfigFile=/etc/openhab2/aws_creds | ||
#profile=fooprofile | ||
#region=eu-west-1 | ||
# Credentials file example: | ||
# | ||
# [fooprofile] | ||
# aws_access_key_id=AKIAIOSFODNN7EXAMPLE | ||
# aws_secret_access_key=3+AAAAABBBbbbCCCCCCdddddd+7mnbIOLH | ||
# | ||
# ADVANCED CONFIGURATION (OPTIONAL) | ||
# | ||
# read capacity for the created tables | ||
#readCapacityUnits=1 | ||
# write capacity for the created tables | ||
#writeCapacityUnits=1 | ||
# table prefix used in the name of created tables | ||
#tablePrefix=openhab- | ||
--> | ||
<parameter name="region" type="text" required="true"> | ||
<label>AWS region ID</label> | ||
<description><![CDATA[AWS region ID as described in Step 2 in Setting up Amazon account.<br /> | ||
The region needs to match the region of the AWS user that will access Amazon DynamoDB.<br /> | ||
For example, eu-west-1.]]></description> | ||
</parameter> | ||
|
||
<parameter name="accessKey" type="text" required="false"> | ||
<label>AWS access key</label> | ||
<description><![CDATA[AWS access key of the AWS user that will access Amazon DynamoDB. | ||
<br /> | ||
Give either 1) access key and secret key, or 2) credentials file and profile name. | ||
]]></description> | ||
</parameter> | ||
|
||
<parameter name="secretKey" type="text" required="false"> | ||
<label>AWS secret key</label> | ||
<description><![CDATA[AWS secret key of the AWS user that will access Amazon DynamoDB. | ||
<br /> | ||
Give either 1) access key and secret key, or 2) credentials file and profile name. | ||
]]></description> | ||
</parameter> | ||
|
||
|
||
<parameter name="profilesConfigFile" type="text" required="false"> | ||
<label>AWS credentials file</label> | ||
<description><![CDATA[Path to the AWS credentials file. <br /> | ||
For example, /etc/openhab2/aws_creds. | ||
Please note that the user that runs openHAB must have approriate read rights to the credential file. | ||
<br /> | ||
Give either 1) access key and secret key, or 2) credentials file and profile name. | ||
]]></description> | ||
</parameter> | ||
|
||
<parameter name="profile" type="text" required="false"> | ||
<label>Profile name</label> | ||
<description><![CDATA[Name of the profile to use in AWS credentials file | ||
<br /> | ||
Give either 1) access key and secret key, or 2) credentials file and profile name. | ||
]]></description> | ||
</parameter> | ||
|
||
|
||
|
||
<parameter name="readCapacityUnits" type="integer" required="false" min="1"> | ||
<description>Read capacity for the created tables. Default is 1.</description> | ||
<label>Read capacity</label> | ||
<advanced>true</advanced> | ||
</parameter> | ||
|
||
<parameter name="writeCapacityUnits" type="integer" required="false" min="1"> | ||
<label>Write capacity</label> | ||
<description>Write capacity for the created tables. Default is 1.</description> | ||
<advanced>true</advanced> | ||
</parameter> | ||
|
||
<parameter name="tablePrefix" type="text" required="false"> | ||
<label>Table prefix</label> | ||
<description>Table prefix used in the name of created tables. Default is openhab-</description> | ||
<advanced>true</advanced> | ||
</parameter> | ||
|
||
</config-description> | ||
|
||
</config-description:config-descriptions> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
This content is produced and maintained by the openHAB project. | ||
|
||
* Project home: https://www.openhab.org | ||
|
||
== Declared Project Licenses | ||
|
||
This program and the accompanying materials are made available under the terms | ||
of the Eclipse Public License 2.0 which is available at | ||
https://www.eclipse.org/legal/epl-2.0/. | ||
|
||
== Source Code | ||
|
||
https://github.com/openhab/openhab-core | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
# Amazon DynamoDB Persistence | ||
|
||
This service allows you to persist state updates using the [Amazon DynamoDB](https://aws.amazon.com/dynamodb/) database. Query functionality is also fully supported. | ||
|
||
Features: | ||
|
||
* Writing/reading information to relational database systems | ||
* Configurable database table names | ||
* Automatic table creation | ||
|
||
## Disclaimer | ||
|
||
This service is provided "AS IS", and the user takes full responsibility of any charges or damage to Amazon data. | ||
|
||
## Table of Contents | ||
|
||
<!-- Using MarkdownTOC plugin for Sublime Text to update the table of contents (TOC) --> | ||
<!-- MarkdownTOC depth=3 autolink=true bracket=round --> | ||
|
||
- [Prerequisites](#prerequisites) | ||
- [Setting Up an Amazon Account](#setting-up-an-amazon-account) | ||
- [Configuration](#configuration) | ||
- [Basic configuration](#basic-configuration) | ||
- [Configuration Using Credentials File](#configuration-using-credentials-file) | ||
- [Advanced Configuration](#advanced-configuration) | ||
- [Details](#details) | ||
- [Tables Creation](#tables-creation) | ||
- [Caveats](#caveats) | ||
- [Developer Notes](#developer-notes) | ||
- [Updating Amazon SDK](#updating-amazon-sdk) | ||
|
||
<!-- /MarkdownTOC --> | ||
|
||
## Prerequisites | ||
|
||
You must first set up an Amazon account as described below. | ||
|
||
Users are recommended to familiarize themselves with AWS pricing before using this service. Please note that there might be charges from Amazon when using this service to query/store data to DynamoDB. See [Amazon DynamoDB pricing pages](https://aws.amazon.com/dynamodb/pricing/) for more details. Please also note possible [Free Tier](https://aws.amazon.com/free/) benefits. | ||
|
||
### Setting Up an Amazon Account | ||
|
||
* [Sign up](https://aws.amazon.com/) for Amazon AWS. | ||
* Select the AWS region in the [AWS console](https://console.aws.amazon.com/) using [these instructions](https://docs.aws.amazon.com/awsconsolehelpdocs/latest/gsg/getting-started.html#select-region). Note the region identifier in the URL (e.g. `https://eu-west-1.console.aws.amazon.com/console/home?region=eu-west-1` means that region id is `eu-west-1`). | ||
* **Create user for openHAB with IAM** | ||
* Open Services -> IAM -> Users -> Create new Users. Enter `openhab` to _User names_, keep _Generate an access key for each user_ checked, and finally click _Create_. | ||
* _Show User Security Credentials_ and record the keys displayed | ||
* **Configure user policy to have access for dynamodb** | ||
* Open Services -> IAM -> Policies | ||
* Check _AmazonDynamoDBFullAccess_ and click _Policy actions_ -> _Attach_ | ||
* Check the user created in step 2 and click _Attach policy_ | ||
|
||
## Configuration | ||
|
||
This service can be configured in the file `services/dynamodb.cfg`. | ||
|
||
### Basic configuration | ||
|
||
| Property | Default | Required | Description | | ||
| --------- | ------- | :------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| accessKey | | Yes | access key as shown in [Setting up Amazon account](#setting-up-amazon-account). | | ||
| secretKey | | Yes | secret key as shown in [Setting up Amazon account](#setting-up-amazon-account). | | ||
| region | | Yes | AWS region ID as described in [Setting up Amazon account](#setting-up-amazon-account). The region needs to match the region that was used to create the user. | | ||
|
||
### Configuration Using Credentials File | ||
|
||
Alternatively, instead of specifying `accessKey` and `secretKey`, one can configure a configuration profile file. | ||
|
||
| Property | Default | Required | Description | | ||
| ------------------ | ------- | :------: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| profilesConfigFile | | Yes | path to the credentials file. For example, `/etc/openhab2/aws_creds`. Please note that the user that runs openHAB must have approriate read rights to the credential file. For more details on the Amazon credential file format, see [Amazon documentation](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html). | | ||
| profile | | Yes | name of the profile to use | | ||
| region | | Yes | AWS region ID as described in Step 2 in [Setting up Amazon account](#setting-up-amazon-account). The region needs to match the region that was used to create the user. | | ||
|
||
Example of service configuration file (`services/dynamodb.cfg`): | ||
|
||
```ini | ||
profilesConfigFile=/etc/openhab2/aws_creds | ||
profile=fooprofile | ||
region=eu-west-1 | ||
``` | ||
|
||
Example of credentials file (`/etc/openhab2/aws_creds`): | ||
|
||
````ini | ||
[fooprofile] | ||
aws_access_key_id=testAccessKey | ||
aws_secret_access_key=testSecretKey | ||
```` | ||
|
||
### Advanced Configuration | ||
|
||
In addition to the configuration properties above, the following are also available: | ||
|
||
| Property | Default | Required | Description | | ||
| -------------------------- | ---------- | :------: | -------------------------------------------------------------------------------------------------- | | ||
| readCapacityUnits | 1 | No | read capacity for the created tables | | ||
| writeCapacityUnits | 1 | No | write capacity for the created tables | | ||
| tablePrefix | `openhab-` | No | table prefix used in the name of created tables | | ||
| bufferCommitIntervalMillis | 1000 | No | Interval to commit (write) buffered data. In milliseconds. | | ||
| bufferSize | 1000 | No | Internal buffer size which is used to batch writes to DynamoDB every `bufferCommitIntervalMillis`. | | ||
|
||
Typically you should not need to modify parameters related to buffering. | ||
|
||
Refer to Amazon documentation on [provisioned throughput](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ProvisionedThroughput.html) for details on read/write capacity. | ||
|
||
All item- and event-related configuration is done in the file `persistence/dynamodb.persist`. | ||
|
||
## Details | ||
|
||
### Tables Creation | ||
|
||
When an item is persisted via this service, a table is created (if necessary). Currently, the service will create at most two tables for different item types. The tables will be named `<tablePrefix><item-type>`, where the `<item-type>` is either `bigdecimal` (numeric items) or `string` (string and complex items). | ||
|
||
Each table will have three columns: `itemname` (item name), `timeutc` (in ISO 8601 format with millisecond accuracy), and `itemstate` (either a number or string representing item state). | ||
|
||
## Buffering | ||
|
||
By default, the service is asynchronous which means that data is not written immediately to DynamoDB but instead buffered in-memory. | ||
The size of the buffer, in terms of datapoints, can be configured with `bufferSize`. | ||
Every `bufferCommitIntervalMillis` the whole buffer of data is flushed to DynamoDB. | ||
|
||
It is recommended to have the buffering enabled since the synchronous behaviour (writing data immediately) might have adverse impact to the whole system when there is many items persisted at the same time. The buffering can be disabled by setting `bufferSize` to zero. | ||
|
||
The defaults should be suitable in many use cases. | ||
|
||
### Caveats | ||
|
||
When the tables are created, the read/write capacity is configured according to configuration. However, the service does not modify the capacity of existing tables. As a workaround, you can modify the read/write capacity of existing tables using the [Amazon console](https://aws.amazon.com/console/). | ||
|
||
## Developer Notes | ||
|
||
### Updating Amazon SDK | ||
|
||
1. Clean `lib/*` | ||
2. Update SDK version in `scripts/fetch_sdk_pom.xml`. You can use the [maven online repository browser](https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-dynamodb) to find the latest version available online. | ||
3. `scripts/fetch_sdk.sh` | ||
4. Copy `scripts/target/site/dependencies.html` and `scripts/target/dependency/*.jar` to `lib/` | ||
5. Generate `build.properties` entries | ||
`ls lib/*.jar | python -c "import sys; print(' ' + ',\\\\\\n '.join(map(str.strip, sys.stdin.readlines())))"` | ||
6. Generate `META-INF/MANIFEST.MF` `Bundle-ClassPath` entries | ||
`ls lib/*.jar | python -c "import sys; print(' ' + ',\\n '.join(map(str.strip, sys.stdin.readlines())))"` | ||
7. Generate `.classpath` entries | ||
`ls lib/*.jar | python -c "import sys;pre='<classpathentry exported=\"true\" kind=\"lib\" path=\"';post='\"/>'; print('\\t' + pre + (post + '\\n\\t' + pre).join(map(str.strip, sys.stdin.readlines())) + post)"` | ||
|
||
After these changes, it's good practice to run integration tests (against live AWS DynamoDB) in `org.openhab.persistence.dynamodb.test` bundle. See README.md in the test bundle for more information how to execute the tests. | ||
|
||
### Running integration tests | ||
|
||
To run integration tests, one needs to provide AWS credentials. | ||
|
||
Eclipse instructions | ||
1. Run all tests (in package org.openhab.persistence.dynamodb.internal) as JUnit Tests | ||
2. Configure the run configuration, and open Arguments sheet | ||
3. In VM arguments, provide the credentials for AWS | ||
```` | ||
-DDYNAMODBTEST_REGION=REGION-ID | ||
-DDYNAMODBTEST_ACCESS=ACCESS-KEY | ||
-DDYNAMODBTEST_SECRET=SECRET | ||
```` | ||
|
||
The tests will create tables with prefix `dynamodb-integration-tests-`. Note that when tests are begun, all data is removed from that table! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.openhab.addons.bundles</groupId> | ||
<artifactId>org.openhab.addons.reactor.bundles</artifactId> | ||
<version>3.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>org.openhab.persistence.dynamodb</artifactId> | ||
|
||
<name>openHAB Add-ons :: Bundles :: DynamoDB Persistence</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.amazonaws</groupId> | ||
<artifactId>aws-java-sdk-dynamodb</artifactId> | ||
<version>1.11.213</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Oops, something went wrong.