├── .gitignore
├── duke_logo.png
├── .github
├── dependabot.yml
├── workflows
│ ├── semantic.yml
│ ├── codeql-analysis.yml
│ └── linter.yml
├── PULL_REQUEST_TEMPLATE.md
└── ISSUE_TEMPLATE
│ ├── SUPPORT.yml
│ ├── FEATURE_REQUEST.yml
│ └── BUG_REPORT.yml
├── .markdownlint.yml
├── examples
├── .gitignore
├── docker-compose.yml
├── README.md
├── src
│ └── main
│ │ └── java
│ │ └── com
│ │ └── influxdb
│ │ └── v3
│ │ ├── ProxyExample.java
│ │ ├── TimeoutsExample.java
│ │ ├── DownsamplingExample.java
│ │ ├── IOxExample.java
│ │ ├── durable
│ │ ├── InfluxClientPool.java
│ │ └── Sensor.java
│ │ └── RetryExample.java
├── envoy.yaml
└── pom.xml
├── license_header.txt
├── LICENSE
├── src
├── main
│ └── java
│ │ └── com
│ │ └── influxdb
│ │ └── v3
│ │ └── client
│ │ ├── query
│ │ ├── QueryType.java
│ │ └── QueryOptions.java
│ │ ├── write
│ │ ├── WritePrecision.java
│ │ └── WritePrecisionConverter.java
│ │ ├── InfluxDBApiException.java
│ │ ├── internal
│ │ ├── Identity.java
│ │ ├── TypeCasting.java
│ │ ├── Arguments.java
│ │ ├── NanosecondConverter.java
│ │ └── VectorSchemaRootConverter.java
│ │ └── InfluxDBApiHttpException.java
├── test
│ └── java
│ │ └── com
│ │ └── influxdb
│ │ └── v3
│ │ └── client
│ │ ├── testdata
│ │ ├── influxdb-certificate.pem
│ │ └── docker.com.pem
│ │ ├── internal
│ │ ├── TypeCastingTest.java
│ │ ├── ArgumentsDurationTest.java
│ │ ├── NanosecondConverterTest.java
│ │ └── ArgumentsTest.java
│ │ ├── write
│ │ └── WritePrecisionConverterTest.java
│ │ ├── AbstractMockServerTest.java
│ │ ├── TestUtils.java
│ │ ├── InfluxDBClientTest.java
│ │ ├── issues
│ │ └── MemoryLeakIssueTest.java
│ │ ├── PointValuesTest.java
│ │ └── PointTest.java
└── site
│ └── site.xml
├── deploy-settings.xml
├── maven-version-rules.xml
├── scripts
└── influxdb-setup.sh
├── checkstyle.xml
├── README.md
├── .circleci
└── config.yml
└── CHANGELOG.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | target/
3 | .java-version
4 |
--------------------------------------------------------------------------------
/duke_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfluxCommunity/influxdb3-java/HEAD/duke_logo.png
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: "maven"
4 | directory: "/"
5 | schedule:
6 | interval: "weekly"
7 |
--------------------------------------------------------------------------------
/.markdownlint.yml:
--------------------------------------------------------------------------------
1 | {
2 | "MD013": false,
3 | "MD024": {
4 | "siblings_only": true
5 | },
6 | "MD033": {
7 | "allowed_elements": [ "a", "img", "p" ]
8 | },
9 | "MD041": false,
10 | }
--------------------------------------------------------------------------------
/.github/workflows/semantic.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: "Semantic PR and Commit Messages"
3 |
4 | on:
5 | pull_request:
6 | types: [opened, reopened, synchronize, edited]
7 | branches:
8 | - main
9 |
10 | jobs:
11 | semantic:
12 | uses: influxdata/validate-semantic-github-messages/.github/workflows/semantic.yml@main
13 | with:
14 | CHECK_PR_TITLE_OR_ONE_COMMIT: true
15 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | Closes #
2 |
3 | ## Proposed Changes
4 |
5 | _Briefly describe your proposed changes:_
6 |
7 | ## Checklist
8 |
9 |
10 |
11 | - [ ] CHANGELOG.md updated
12 | - [ ] Rebased/mergeable
13 | - [ ] A test has been added if appropriate
14 | - [ ] Tests pass
15 | - [ ] Commit messages are [conventional](https://www.conventionalcommits.org/en/v1.0.0/)
16 | - [ ] Sign [CLA](https://www.influxdata.com/legal/cla/) (if not already signed)
17 |
--------------------------------------------------------------------------------
/examples/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 | !**/src/main/**/target/
4 | !**/src/test/**/target/
5 |
6 | ### IntelliJ IDEA ###
7 | .idea/modules.xml
8 | .idea/jarRepositories.xml
9 | .idea/compiler.xml
10 | .idea/libraries/
11 | *.iws
12 | *.iml
13 | *.ipr
14 |
15 | ### Eclipse ###
16 | .apt_generated
17 | .classpath
18 | .factorypath
19 | .project
20 | .settings
21 | .springBeans
22 | .sts4-cache
23 |
24 | ### NetBeans ###
25 | /nbproject/private/
26 | /nbbuild/
27 | /dist/
28 | /nbdist/
29 | /.nb-gradle/
30 | build/
31 | !**/src/main/**/build/
32 | !**/src/test/**/build/
33 |
34 | ### VS Code ###
35 | .vscode/
36 |
37 | ### Mac OS ###
38 | .DS_Store
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/SUPPORT.yml:
--------------------------------------------------------------------------------
1 | name: Support request
2 | description: Open a support request
3 | labels: ["support"]
4 | body:
5 | - type: markdown
6 | attributes:
7 | value: |
8 | WOAHH, hold up. This isn't the best place for support questions.
9 | You can get a faster response on slack or forums:
10 |
11 | Please redirect any QUESTIONS about Telegraf usage to
12 | - InfluxData Slack Channel: https://app.slack.com/huddle/TH8RGQX5Z/C02UDUPLQKA
13 | - InfluxData Community Site: https://community.influxdata.com
14 |
15 | - type: textarea
16 | attributes:
17 | label: "Please direct all support questions to slack or the forums. Thank you."
18 |
--------------------------------------------------------------------------------
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | name: "CodeQL"
2 |
3 | on:
4 | push:
5 | branches: [ main ]
6 | pull_request:
7 | branches: [ main ]
8 |
9 | jobs:
10 | CodeQL-Build:
11 | runs-on: ubuntu-latest
12 |
13 | permissions:
14 | security-events: write
15 | actions: read
16 | contents: read
17 |
18 | steps:
19 | - name: Checkout repository
20 | uses: actions/checkout@v3
21 |
22 | - name: Initialize CodeQL
23 | uses: github/codeql-action/init@v2
24 | with:
25 | languages: java
26 |
27 | - name: Autobuild
28 | uses: github/codeql-action/autobuild@v2
29 |
30 | - name: Perform CodeQL Analysis
31 | uses: github/codeql-action/analyze@v2
32 |
--------------------------------------------------------------------------------
/.github/workflows/linter.yml:
--------------------------------------------------------------------------------
1 | name: "Lint Code Base"
2 |
3 | on:
4 | push:
5 | branches: [main]
6 | pull_request:
7 | branches: [main]
8 |
9 | jobs:
10 | build:
11 | permissions:
12 | contents: read
13 | packages: read
14 | statuses: write
15 |
16 | name: Lint Code Base
17 | runs-on: ubuntu-latest
18 |
19 | steps:
20 | - name: Checkout Code
21 | uses: actions/checkout@v3
22 | with:
23 | fetch-depth: 0
24 |
25 | - name: Lint Code Base
26 | uses: github/super-linter@v4.9.2
27 | env:
28 | VALIDATE_ALL_CODEBASE: false
29 | DEFAULT_BRANCH: main
30 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31 | LINTER_RULES_PATH: '.'
32 | MARKDOWN_CONFIG_FILE: .markdownlint.yml
33 | VALIDATE_MARKDOWN: true
34 | VALIDATE_BASH: true
35 | VALIDATE_JAVA: true
36 | JAVA_FILE_NAME: 'checkstyle.xml'
37 | VALIDATE_GITHUB_ACTIONS: true
38 |
--------------------------------------------------------------------------------
/license_header.txt:
--------------------------------------------------------------------------------
1 | The MIT License
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 InfluxData Inc.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml:
--------------------------------------------------------------------------------
1 | name: Feature request
2 | description: Create a feature request to make client more awesome
3 | labels: ["feature request"]
4 | body:
5 | - type: markdown
6 | attributes:
7 | value: |
8 | Thanks for taking time to share with us this feature request! Please describe why you would like this feature to be added to the client, how you plan to use it to make your life better.
9 | - type: textarea
10 | id: use-case
11 | attributes:
12 | label: Use Case
13 | description: Describe how you plan to use this feature.
14 | validations:
15 | required: true
16 | - type: textarea
17 | id: expected-behavior
18 | attributes:
19 | label: Expected behavior
20 | description: Describe what you expected to happen when you performed the above steps.
21 | validations:
22 | required: true
23 | - type: textarea
24 | id: actual-behavior
25 | attributes:
26 | label: Actual behavior
27 | description: Describe what actually happened when you performed the above steps.
28 | validations:
29 | required: true
30 | - type: textarea
31 | id: additional-info
32 | attributes:
33 | label: Additional info
34 | description: Include gist of relevant config, logs, etc.
35 | validations:
36 | required: false
37 |
38 |
--------------------------------------------------------------------------------
/examples/docker-compose.yml:
--------------------------------------------------------------------------------
1 | #
2 | # The MIT License
3 | #
4 | # Permission is hereby granted, free of charge, to any person obtaining a copy
5 | # of this software and associated documentation files (the "Software"), to deal
6 | # in the Software without restriction, including without limitation the rights
7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | # copies of the Software, and to permit persons to whom the Software is
9 | # furnished to do so, subject to the following conditions:
10 | #
11 | # The above copyright notice and this permission notice shall be included in
12 | # all copies or substantial portions of the Software.
13 | #
14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | # THE SOFTWARE.
21 | #
22 |
23 | version: "3"
24 |
25 | services:
26 | envoy:
27 | image: envoyproxy/envoy:v1.26-latest
28 | volumes:
29 | - ./envoy.yaml:/etc/envoy/envoy.yaml
30 | ports:
31 | - "10000:10000"
32 | environment:
33 | - ENVOY_UID=0
34 |
35 |
--------------------------------------------------------------------------------
/src/main/java/com/influxdb/v3/client/query/QueryType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package com.influxdb.v3.client.query;
23 |
24 | /**
25 | * Defines type of query sent to InfluxDB.
26 | */
27 | public enum QueryType {
28 |
29 | /**
30 | * Query by SQL.
31 | */
32 | SQL,
33 |
34 | /**
35 | * Query by InfluxQL.
36 | */
37 | InfluxQL
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/influxdb/v3/client/write/WritePrecision.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package com.influxdb.v3.client.write;
23 |
24 | /**
25 | * Defines WritePrecision.
26 | */
27 | public enum WritePrecision {
28 |
29 | /**
30 | * Time precision in milliseconds.
31 | */
32 | MS,
33 | /**
34 | * Time precision in seconds.
35 | */
36 | S,
37 | /**
38 | * Time precision in microseconds.
39 | */
40 | US,
41 | /**
42 | * Time precision in nanoseconds.
43 | */
44 | NS
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/src/main/java/com/influxdb/v3/client/InfluxDBApiException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package com.influxdb.v3.client;
23 |
24 | import javax.annotation.Nullable;
25 |
26 | /**
27 | * The InfluxDBApiException is thrown when an error occurs while interacting with InfluxDB.
28 | */
29 | public class InfluxDBApiException extends RuntimeException {
30 | /**
31 | * Construct a new InfluxDBApiException with the specified detail message.
32 | *
33 | * @param message the detail message.
34 | */
35 | public InfluxDBApiException(@Nullable final String message) {
36 | super(message);
37 | }
38 |
39 | /**
40 | * Construct a new InfluxDBApiException with the specified cause.
41 | *
42 | * @param cause the cause.
43 | */
44 | public InfluxDBApiException(@Nullable final Throwable cause) {
45 | super(cause);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/influxdb/v3/client/internal/Identity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package com.influxdb.v3.client.internal;
23 |
24 | /**
25 | * Functions for establishing caller identity.
26 | */
27 | final class Identity {
28 | private Identity() { }
29 |
30 | /**
31 | * Attempt to get the package version.
32 | * @return - package version or unknown.
33 | */
34 | static String getVersion() {
35 | Package mainPackage = Identity.class.getPackage();
36 | String version = mainPackage != null ? mainPackage.getImplementationVersion() : "unknown";
37 | return version == null ? "unknown" : version;
38 | }
39 |
40 | /**
41 | * Get a standard user-agent identity to be used in all HTTP based calls.
42 | * @return - the standard user-agent string.
43 | */
44 | static String getUserAgent() {
45 | return String.format("influxdb3-java/%s", getVersion());
46 | }
47 | }
--------------------------------------------------------------------------------
/src/test/java/com/influxdb/v3/client/testdata/influxdb-certificate.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
3 | TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
4 | cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
5 | WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
6 | ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
7 | MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
8 | h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
9 | 0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
10 | A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
11 | T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH
12 | B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC
13 | B5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUv
14 | KBds0pjBqAlkd25HN7rOrFleaJ1/ctaJxQZBKT5ZPt0m9STJEadao0xAH0ahmbWn
15 | OlFuhjuefXKnEgV4We0+UXgVCwOPjdAvBbI+e0ocS3MFEvzG6uBQE3xDk3SzynTn
16 | jh8BCNAw1FtxNrQHusEwMFxIt4I7mKZ9YIqioymCzLq9gwQbooMDQaHWBfEbwrbw
17 | qHyGO0aoSCqI3Haadr8faqU9GY/rOPNk3sgrDQoo//fb4hVC1CLQJ13hef4Y53CI
18 | rU7m2Ys6xt0nUW7/vGT1M0NPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNV
19 | HRMBAf8EBTADAQH/MB0GA1UdDgQWBBR5tFnme7bl5AFzgAiIyBpY9umbbjANBgkq
20 | hkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS/V9lZL
21 | ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ
22 | 3BebYhtF8GaV0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK
23 | NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5
24 | ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur
25 | TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
26 | jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
27 | oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
28 | 4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
29 | mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
30 | emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
31 | -----END CERTIFICATE-----
32 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/BUG_REPORT.yml:
--------------------------------------------------------------------------------
1 | name: Bug Report
2 | description: Create a bug report to help us improve
3 | labels: ["bug"]
4 | body:
5 | - type: markdown
6 | attributes:
7 | value: |
8 | Thanks for taking time to fill out this bug report! We reserve this repository issues for bugs with reproducible problems.
9 | Please redirect any questions about the client usage to our [Community Slack](https://app.slack.com/huddle/TH8RGQX5Z/C02UDUPLQKA) or [Community Page](https://community.influxdata.com/) we have a lot of talented community members there who could help answer your question more quickly.
10 |
11 | * Please add a :+1: or comment on a similar existing bug report instead of opening a new one.
12 | * Please check whether the bug can be reproduced with the latest release.
13 | - type: textarea
14 | id: specifications
15 | attributes:
16 | label: Specifications
17 | description: Describe the steps to reproduce the bug.
18 | value: |
19 | * Client Version:
20 | * InfluxDB Version:
21 | * Platform:
22 | validations:
23 | required: true
24 | - type: textarea
25 | id: reproduce
26 | attributes:
27 | label: Code sample to reproduce problem
28 | description: Provide a code sample that reproduces the problem
29 | value: |
30 | ```java
31 | ```
32 | validations:
33 | required: true
34 | - type: textarea
35 | id: expected-behavior
36 | attributes:
37 | label: Expected behavior
38 | description: Describe what you expected to happen when you performed the above steps.
39 | validations:
40 | required: true
41 | - type: textarea
42 | id: actual-behavior
43 | attributes:
44 | label: Actual behavior
45 | description: Describe what actually happened when you performed the above steps.
46 | validations:
47 | required: true
48 | - type: textarea
49 | id: additional-info
50 | attributes:
51 | label: Additional info
52 | description: Include gist of relevant config, logs, etc.
53 | validations:
54 | required: false
--------------------------------------------------------------------------------
/deploy-settings.xml:
--------------------------------------------------------------------------------
1 |
24 |
26 |
27 |
28 | ossrh
29 | ${env.SONATYPE_USERNAME}
30 | ${env.SONATYPE_PASSWORD}
31 |
32 |
33 |
34 |
35 |
36 | ossrh
37 |
38 | true
39 |
40 |
41 | ${env.GPG_EXECUTABLE}
42 | ${env.GPG_PASSPHRASE}
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/src/test/java/com/influxdb/v3/client/testdata/docker.com.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIFxDCCBKygAwIBAgIQDE0Qon/WHglZ2jXwZzD0xjANBgkqhkiG9w0BAQsFADA8
3 | MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRwwGgYDVQQDExNBbWF6b24g
4 | UlNBIDIwNDggTTAyMB4XDTI0MDgxODAwMDAwMFoXDTI1MDkxNjIzNTk1OVowFzEV
5 | MBMGA1UEAwwMKi5kb2NrZXIuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
6 | CgKCAQEAytONEwLLBXfyepD/iE7N76+xGDWE/7g21rpPRejCobpaKGVKSL4Y8Pf9
7 | whjh5pzBLxcpQMpYcg/oW+Cp4scjhXyi9yqrOC2Vf26DRA3ufjbescZUjPP28mPO
8 | N1gGQhnr0Sa7mbhNo5JVE7yxLrjhAZFCdEpl1LYdfosYxeBowVOaxBsGfUWCxYuI
9 | HbolTUUNWJKaAN7knKmrHF0a2a6BftaTyFK/6N1FV3rXs5oD+5DEYVFN8193fdz5
10 | DUcf5p7xzjx9yXmHfdomznUPL5Sja2FSigH+Gm6EG3cBKylVCpafwQhbYbpdkP12
11 | p7KtsPGUWIwBAyRr1AUqx0ceIafa9wIDAQABo4IC5TCCAuEwHwYDVR0jBBgwFoAU
12 | wDFSzVpQw4J8dHHOy+mc+XrrguIwHQYDVR0OBBYEFFgCnhEuuG5ptVcvPfBJZssU
13 | U6jFMBcGA1UdEQQQMA6CDCouZG9ja2VyLmNvbTATBgNVHSAEDDAKMAgGBmeBDAEC
14 | ATAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMC
15 | MDsGA1UdHwQ0MDIwMKAuoCyGKmh0dHA6Ly9jcmwucjJtMDIuYW1hem9udHJ1c3Qu
16 | Y29tL3IybTAyLmNybDB1BggrBgEFBQcBAQRpMGcwLQYIKwYBBQUHMAGGIWh0dHA6
17 | Ly9vY3NwLnIybTAyLmFtYXpvbnRydXN0LmNvbTA2BggrBgEFBQcwAoYqaHR0cDov
18 | L2NydC5yMm0wMi5hbWF6b250cnVzdC5jb20vcjJtMDIuY2VyMAwGA1UdEwEB/wQC
19 | MAAwggF+BgorBgEEAdZ5AgQCBIIBbgSCAWoBaAB3AN3cyjSV1+EWBeeVMvrHn/g9
20 | HFDf2wA6FBJ2Ciysu8gqAAABkWTCKI4AAAQDAEgwRgIhALzND2kn+PR4aObDiWGv
21 | 7QJZ/z4i/vhAGjd/vp2hjt4HAiEAytgsAcPUFd/Y98n5EQkMg6GBSUUygBMc7+Xk
22 | UVJXFgcAdQDm0jFjQHeMwRBBBtdxuc7B0kD2loSG+7qHMh39HjeOUAAAAZFkwiic
23 | AAAEAwBGMEQCIGXbP5ughe+EksczYEErOqY1LZHi9/SmXcp6/vAeuXBmAiB16Sw7
24 | 1sPB/CpKq75/pEwb5pamTdmeEIaHtGQTkTMZ5QB2AMz7D2qFcQll/pWbU87psnwi
25 | 6YVcDZeNtql+VMD+TA2wAAABkWTCKIoAAAQDAEcwRQIgX2WsD3ThDwalMCYqmf+X
26 | ICS9imyYmwKXJbfkSnMH/HkCIQCEkDrOAJZG1fGfyOzhSPHWPMxbuGwV18jBGe52
27 | D9PPQTANBgkqhkiG9w0BAQsFAAOCAQEAcW8Z3+JzqfGTYX+MBk2pQvo8msx+fINU
28 | ZzORUcFUNV0467G/Kc780S8GRxF8dr90WaFctMvw8yDOipfj0sacGJFVFFf5XoWu
29 | 1EqYyx3hgMLCQ5DzjAoY4X1KsfPRBe2DCsqf+Nt/TVzgVjOSglURBWKV2T+Av78H
30 | HiMjtEUZbatvuKvUg5S26dvUxXseN/8Jbbt9MCCGascPOf+zXGysoBSwglt0Nz7W
31 | hjXnY+BPeLD38ouUGx0R+sZbXICR6BIxtT4GgOcmJJ/KT3fcMObhsihiq6lO1aql
32 | Yo4AvWpg2tJtwFrG4ooDRyyARljHMUMIkuTz9Dypl/dnJJfzAQLjVA==
33 | -----END CERTIFICATE-----
34 |
--------------------------------------------------------------------------------
/maven-version-rules.xml:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
27 | (?i).*Alpha(?:-?\d+)?
28 | (?i).*a(?:-?\d+)?
29 | (?i).*Beta(?:-?\d+)?
30 | (?i).*-B(?:-?\d+)?
31 | (?i).*RC(?:-?\d+)?
32 | (?i).*CR(?:-?\d+)?
33 | (?i).*M(?:-?\d+)?
34 | (?i).*SNAP(?:-?\d+)?
35 | .*[-_\.](alpha|Alpha|ALPHA|beta|Beta|BETA|rc|RC)[-_\.]?.*
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/src/main/java/com/influxdb/v3/client/write/WritePrecisionConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package com.influxdb.v3.client.write;
23 |
24 | public final class WritePrecisionConverter {
25 |
26 | private WritePrecisionConverter() {
27 | }
28 |
29 | public static String toV2ApiString(final WritePrecision precision) {
30 | switch (precision) {
31 | case NS:
32 | return "ns";
33 | case US:
34 | return "us";
35 | case MS:
36 | return "ms";
37 | case S:
38 | return "s";
39 | default:
40 | throw new IllegalArgumentException("Unsupported precision '" + precision + "'");
41 | }
42 | }
43 |
44 | public static String toV3ApiString(final WritePrecision precision) {
45 | switch (precision) {
46 | case NS:
47 | return "nanosecond";
48 | case US:
49 | return "microsecond";
50 | case MS:
51 | return "millisecond";
52 | case S:
53 | return "second";
54 | default:
55 | throw new IllegalArgumentException("Unsupported precision '" + precision + "'");
56 | }
57 | }
58 | }
--------------------------------------------------------------------------------
/src/site/site.xml:
--------------------------------------------------------------------------------
1 |
24 |
26 |
27 | ${project.name}
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | org.apache.maven.skins
50 | maven-fluido-skin
51 | 1.7
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/src/test/java/com/influxdb/v3/client/internal/TypeCastingTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package com.influxdb.v3.client.internal;
23 |
24 | import org.apache.arrow.vector.util.Text;
25 | import org.junit.jupiter.api.Assertions;
26 | import org.junit.jupiter.api.Test;
27 |
28 | public class TypeCastingTest {
29 |
30 | @Test
31 | void testToLongValue() {
32 | Assertions.assertEquals(1, TypeCasting.toLongValue(1));
33 | Assertions.assertEquals(1.0, TypeCasting.toLongValue(1.23));
34 |
35 | Assertions.assertThrows(ClassCastException.class,
36 | () -> TypeCasting.toLongValue("1"));
37 | }
38 |
39 | @Test
40 | void testToDoubleValue() {
41 | Assertions.assertEquals(1.23, TypeCasting.toDoubleValue(1.23));
42 | Assertions.assertEquals(1.0, TypeCasting.toDoubleValue(1));
43 |
44 | Assertions.assertThrows(ClassCastException.class,
45 | () -> TypeCasting.toDoubleValue("1.2"));
46 | }
47 |
48 | @Test
49 | void testToStringValue() {
50 | Assertions.assertEquals("test", TypeCasting.toStringValue("test"));
51 | Assertions.assertEquals("test",
52 | TypeCasting.toStringValue(new Text("test")));
53 |
54 | Assertions.assertThrows(ClassCastException.class,
55 | () -> TypeCasting.toStringValue(1));
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/examples/README.md:
--------------------------------------------------------------------------------
1 | # Examples
2 |
3 | > :warning: The examples depends on the "influxdb3-java" module and this module should be built first by running "mvn install" in the root directory.
4 | > :warning: Some JDK internals must be exposed by adding `--add-opens=java.base/java.nio=ALL-UNNAMED` to your JVM arguments.
5 |
6 | ## Basic
7 |
8 | - [IOxExample](src/main/java/com/influxdb/v3/IOxExample.java) - How to use write and query data from InfluxDB IOx
9 |
10 | ## RetryExample
11 |
12 | - [RetryExample](src/main/java/com/influxdb/v3/RetryExample.java) - How to catch an `InfluxDBApiHttpException` to then retry making write requests.
13 |
14 | ### Command line run
15 |
16 | - Set environment variables.
17 |
18 | ```bash
19 |
20 | export INFLUX_HOST=
21 | export INFLUX_TOKEN=
22 | export INFLUX_DATABASE=
23 |
24 | ```
25 |
26 | - Run with maven
27 |
28 | ```bash
29 | mvn compile exec:java -Dexec.main="com.influxdb.v3.RetryExample"
30 | ```
31 |
32 | - Repeat previous step to force an HTTP 429 response and rewrite attempt.
33 |
34 | ## Durable example
35 |
36 | This example illustrates one approach to ensuring clients, once initialized, are long-lived and reused.
37 |
38 | The underlying write (HTTP/REST) and query (Apache arrow Flight/GRPC) transports are designed to be robust and to be able to recover from most errors. The InfluxDBClient query API is based on GRPC stubs and channels. [GRPC best practices](https://grpc.io/docs/guides/performance/) recommends reusing them and their resources for the life of an application if at all possible. Unnecessary frequent regeneration of InfluxDBClient instances is wasteful of system resources. Recreating the query transport means fully recreating a GRPC channel, its connection pool and its management API. Fully recreating a client only to use it for a single query also means recreating an unused write transport alongside the query transport. This example attempts to show a more resource friendly use of the API by leveraging already used client instances.
39 |
40 | - [DurableExample](src/main/java/com/influxdb/v3/durable/DurableExample.java)
41 | - [InfluxClientPool](src/main/java/com/influxdb/v3/durable/InfluxClientPool.java)
42 |
43 | ### Command line run
44 |
45 | - Set environment variables
46 |
47 | ```bash
48 |
49 | export INFLUX_HOST=
50 | export INFLUX_TOKEN=
51 | export INFLUX_DATABASE=
52 |
53 | ```
54 |
55 | - Run with maven
56 |
57 | ```bash
58 | MAVEN_OPTS="--add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED" mvn compile exec:java -Dexec.main="com.influxdb.v3.durable.DurableExample"
59 | ```
60 |
--------------------------------------------------------------------------------
/src/test/java/com/influxdb/v3/client/write/WritePrecisionConverterTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package com.influxdb.v3.client.write;
23 |
24 | import java.util.Map;
25 |
26 | import org.junit.jupiter.api.Test;
27 |
28 | import static org.junit.jupiter.api.Assertions.assertEquals;
29 |
30 | public class WritePrecisionConverterTest {
31 | @Test
32 | void toV2ApiString() {
33 | Map testCases = Map.of(
34 | WritePrecision.NS, "ns",
35 | WritePrecision.US, "us",
36 | WritePrecision.MS, "ms",
37 | WritePrecision.S, "s"
38 | );
39 |
40 | for (Map.Entry e : testCases.entrySet()) {
41 | WritePrecision precision = e.getKey();
42 | String expectedString = e.getValue();
43 | String result = WritePrecisionConverter.toV2ApiString(precision);
44 | assertEquals(expectedString, result, "Failed for precision: " + precision);
45 | }
46 | }
47 |
48 | @Test
49 | void toV3ApiString() {
50 | Map tc = Map.of(
51 | WritePrecision.NS, "nanosecond",
52 | WritePrecision.US, "microsecond",
53 | WritePrecision.MS, "millisecond",
54 | WritePrecision.S, "second"
55 | );
56 |
57 | for (Map.Entry e : tc.entrySet()) {
58 | WritePrecision precision = e.getKey();
59 | String expectedString = e.getValue();
60 | String result = WritePrecisionConverter.toV3ApiString(precision);
61 | assertEquals(expectedString, result, "Failed for precision: " + precision);
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/com/influxdb/v3/client/internal/TypeCasting.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package com.influxdb.v3.client.internal;
23 |
24 | import javax.annotation.Nonnull;
25 |
26 | import org.apache.arrow.vector.util.Text;
27 |
28 | /**
29 | * Functions for safe type casting.
30 | */
31 | public final class TypeCasting {
32 |
33 | private TypeCasting() { }
34 |
35 | /**
36 | * Safe casting to long value.
37 | *
38 | * @param value object to cast
39 | * @return long value
40 | */
41 | public static long toLongValue(@Nonnull final Object value) {
42 |
43 | if (long.class.isAssignableFrom(value.getClass())
44 | || Long.class.isAssignableFrom(value.getClass())) {
45 | return (long) value;
46 | }
47 |
48 | return ((Number) value).longValue();
49 | }
50 |
51 | /**
52 | * Safe casting to double value.
53 | *
54 | * @param value object to cast
55 | * @return double value
56 | */
57 | public static double toDoubleValue(@Nonnull final Object value) {
58 |
59 | if (double.class.isAssignableFrom(value.getClass())
60 | || Double.class.isAssignableFrom(value.getClass())) {
61 | return (double) value;
62 | }
63 |
64 | return ((Number) value).doubleValue();
65 | }
66 |
67 | /**
68 | * Safe casting to string value.
69 | *
70 | * @param value object to cast
71 | * @return string value
72 | */
73 | public static String toStringValue(@Nonnull final Object value) {
74 |
75 | if (Text.class.isAssignableFrom(value.getClass())) {
76 | return value.toString();
77 | }
78 |
79 | return (String) value;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/examples/src/main/java/com/influxdb/v3/ProxyExample.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package com.influxdb.v3;
23 |
24 | import java.util.UUID;
25 | import java.util.stream.Stream;
26 |
27 | import com.influxdb.v3.client.InfluxDBClient;
28 | import com.influxdb.v3.client.Point;
29 | import com.influxdb.v3.client.PointValues;
30 | import com.influxdb.v3.client.config.ClientConfig;
31 |
32 | public final class ProxyExample {
33 |
34 | private ProxyExample() {
35 | }
36 |
37 | public static void main(final String[] args) throws Exception {
38 | // Run docker-compose.yml file to start Envoy proxy
39 |
40 | String proxyUrl = "http://localhost:10000";
41 | String sslRootsFilePath = "src/test/java/com/influxdb/v3/client/testdata/influxdb-certificate.pem";
42 | ClientConfig clientConfig = new ClientConfig.Builder()
43 | .host(System.getenv("INFLUXDB_URL"))
44 | .token(System.getenv("INFLUXDB_TOKEN").toCharArray())
45 | .database(System.getenv("INFLUXDB_DATABASE"))
46 | .proxyUrl(proxyUrl)
47 | .sslRootsFilePath(sslRootsFilePath)
48 | .build();
49 |
50 | InfluxDBClient influxDBClient = InfluxDBClient.getInstance(clientConfig);
51 | String testId = UUID.randomUUID().toString();
52 | Point point = Point.measurement("My_Home")
53 | .setTag("room", "Kitchen")
54 | .setField("temp", 12.7)
55 | .setField("hum", 37)
56 | .setField("testId", testId);
57 | influxDBClient.writePoint(point);
58 |
59 | String query = String.format("SELECT * FROM \"My_Home\" WHERE \"testId\" = '%s'", testId);
60 | try (Stream stream = influxDBClient.queryPoints(query)) {
61 | stream.findFirst().ifPresent(values -> {
62 | assert values.getTimestamp() != null;
63 | System.out.printf("room[%s]: %s, temp: %3.2f, hum: %d",
64 | new java.util.Date(values.getTimestamp().longValue() / 1000000),
65 | values.getTag("room"),
66 | (Double) values.getField("temp"),
67 | (Long) values.getField("hum"));
68 | });
69 | }
70 | }
71 | }
72 |
73 |
--------------------------------------------------------------------------------
/src/test/java/com/influxdb/v3/client/internal/ArgumentsDurationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package com.influxdb.v3.client.internal;
23 |
24 | import org.assertj.core.api.Assertions;
25 | import org.junit.jupiter.api.Test;
26 |
27 | /**
28 | * @author Jakub Bednar (bednar@github) (20/08/2018 12:31)
29 | */
30 | @SuppressWarnings("ConstantConditions")
31 | class ArgumentsDurationTest {
32 |
33 | @Test
34 | void literals() {
35 |
36 | Arguments.checkDuration("1s", "duration");
37 | Arguments.checkDuration("10d", "duration");
38 | Arguments.checkDuration("1h15m", "duration");
39 | Arguments.checkDuration("5w", "duration");
40 | Arguments.checkDuration("1mo5d", "duration");
41 | Arguments.checkDuration("-1mo5d", "duration");
42 | Arguments.checkDuration("inf", "duration");
43 | Arguments.checkDuration("-inf", "duration");
44 | }
45 |
46 | @Test
47 | void literalNull() {
48 |
49 | Assertions.assertThatThrownBy(() -> Arguments.checkDuration(null, "duration"))
50 | .isInstanceOf(IllegalArgumentException.class)
51 | .hasMessage("Expecting a duration string for duration. But got: null");
52 | }
53 |
54 | @Test
55 | void literalEmpty() {
56 |
57 | Assertions.assertThatThrownBy(() -> Arguments.checkDuration("", "duration"))
58 | .isInstanceOf(IllegalArgumentException.class)
59 | .hasMessage("Expecting a duration string for duration. But got: ");
60 | }
61 |
62 | @Test
63 | void literalNotDuration() {
64 |
65 | Assertions.assertThatThrownBy(() -> Arguments.checkDuration("x", "duration"))
66 | .isInstanceOf(IllegalArgumentException.class)
67 | .hasMessage("Expecting a duration string for duration. But got: x");
68 | }
69 |
70 | @Test
71 | void notRequiredValid() {
72 |
73 | Arguments.checkDurationNotRequired(null, "duration");
74 | Arguments.checkDurationNotRequired("", "duration");
75 | Arguments.checkDurationNotRequired("1s", "duration");
76 | }
77 |
78 | @Test
79 | void notRequiredNotValid() {
80 |
81 | Assertions.assertThatThrownBy(() -> Arguments.checkDurationNotRequired("x", "duration"))
82 | .isInstanceOf(IllegalArgumentException.class)
83 | .hasMessage("Expecting a duration string for duration. But got: x");
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/test/java/com/influxdb/v3/client/AbstractMockServerTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package com.influxdb.v3.client;
23 |
24 | import java.io.IOException;
25 | import java.util.HashMap;
26 | import java.util.Map;
27 | import javax.annotation.Nonnull;
28 | import javax.annotation.Nullable;
29 |
30 | import mockwebserver3.MockResponse;
31 | import mockwebserver3.MockWebServer;
32 | import org.junit.jupiter.api.AfterEach;
33 | import org.junit.jupiter.api.BeforeEach;
34 |
35 | public abstract class AbstractMockServerTest {
36 |
37 | protected String baseURL;
38 | protected MockWebServer mockServer;
39 |
40 | @BeforeEach
41 | protected void startMockServer() {
42 |
43 | mockServer = new MockWebServer();
44 | try {
45 | mockServer.start();
46 | } catch (IOException e) {
47 | throw new RuntimeException(e);
48 | }
49 |
50 | baseURL = mockServer.url("/").url().toString();
51 | }
52 |
53 | @AfterEach
54 | protected void shutdownMockServer() throws IOException {
55 | mockServer.close();
56 | }
57 |
58 | @Nonnull
59 | protected MockResponse createEmptyResponse(final int responseCode) {
60 | return new MockResponse.Builder().code(responseCode).build();
61 | }
62 |
63 | @Nonnull
64 | protected MockResponse createResponse(final int responseCode,
65 | @Nullable final Map headers,
66 | @Nullable final String body) {
67 |
68 | MockResponse.Builder mrb = new MockResponse.Builder();
69 | mrb.code(responseCode);
70 | Map effectiveHeaders = new HashMap<>(Map.of("Content-Type", "text/csv; charset=utf-8",
71 | "Date", "Tue, 26 Jun 2018 13:15:01 GMT"));
72 | if (headers != null) {
73 | effectiveHeaders.putAll(headers);
74 | }
75 | for (Map.Entry entry : effectiveHeaders.entrySet()) {
76 | mrb.addHeader(entry.getKey(), entry.getValue());
77 | }
78 | if (body != null) {
79 | mrb.body(body);
80 | }
81 |
82 | return mrb.build();
83 | }
84 |
85 | @Nonnull
86 | protected MockResponse createResponse(final int responseCode) {
87 |
88 | return createResponse(responseCode, Map.of(
89 | "Content-Type", "text/csv; charset=utf-8",
90 | "Date", "Tue, 26 Jun 2018 13:15:01 GMT"
91 | ), null);
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/java/com/influxdb/v3/client/InfluxDBApiHttpException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package com.influxdb.v3.client;
23 |
24 | import java.net.http.HttpHeaders;
25 | import java.util.List;
26 | import javax.annotation.Nullable;
27 |
28 | /**
29 | * The InfluxDBApiHttpException gets thrown whenever an error status is returned
30 | * in the HTTP response. It facilitates recovering from such errors whenever possible.
31 | */
32 | public class InfluxDBApiHttpException extends InfluxDBApiException {
33 |
34 | /**
35 | * The HTTP headers associated with the error.
36 | */
37 | HttpHeaders headers;
38 | /**
39 | * The HTTP status code associated with the error.
40 | */
41 | int statusCode;
42 |
43 | /**
44 | * Construct a new InfluxDBApiHttpException with statusCode and headers.
45 | *
46 | * @param message the detail message.
47 | * @param headers headers returned in the response.
48 | * @param statusCode statusCode of the response.
49 | */
50 | public InfluxDBApiHttpException(
51 | @Nullable final String message,
52 | @Nullable final HttpHeaders headers,
53 | final int statusCode) {
54 | super(message);
55 | this.headers = headers;
56 | this.statusCode = statusCode;
57 | }
58 |
59 | /**
60 | * Construct a new InfluxDBApiHttpException with statusCode and headers.
61 | *
62 | * @param cause root cause of the exception.
63 | * @param headers headers returned in the response.
64 | * @param statusCode status code of the response.
65 | */
66 | public InfluxDBApiHttpException(
67 | @Nullable final Throwable cause,
68 | @Nullable final HttpHeaders headers,
69 | final int statusCode) {
70 | super(cause);
71 | this.headers = headers;
72 | this.statusCode = statusCode;
73 | }
74 |
75 | /**
76 | * Gets the HTTP headers property associated with the error.
77 | *
78 | * @return - the headers object.
79 | */
80 | public HttpHeaders headers() {
81 | return headers;
82 | }
83 |
84 | /**
85 | * Helper method to simplify retrieval of specific headers.
86 | *
87 | * @param name - name of the header.
88 | * @return - value matching the header key, or null if the key does not exist.
89 | */
90 | public List getHeader(final String name) {
91 | return headers.map().get(name);
92 | }
93 |
94 | /**
95 | * Gets the HTTP statusCode associated with the error.
96 | * @return - the HTTP statusCode.
97 | */
98 | public int statusCode() {
99 | return statusCode;
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/examples/envoy.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # The MIT License
3 | #
4 | # Permission is hereby granted, free of charge, to any person obtaining a copy
5 | # of this software and associated documentation files (the "Software"), to deal
6 | # in the Software without restriction, including without limitation the rights
7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | # copies of the Software, and to permit persons to whom the Software is
9 | # furnished to do so, subject to the following conditions:
10 | #
11 | # The above copyright notice and this permission notice shall be included in
12 | # all copies or substantial portions of the Software.
13 | #
14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | # THE SOFTWARE.
21 | #
22 |
23 | static_resources:
24 | listeners:
25 | - name: listener_0
26 | address:
27 | socket_address: { address: 0.0.0.0, port_value: 10000 }
28 | filter_chains:
29 | - filter_chain_match:
30 | filters:
31 | - name: envoy.filters.network.http_connection_manager
32 | typed_config:
33 | "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
34 | stat_prefix: ingress_http
35 | access_log:
36 | - name: envoy.access_loggers.stdout
37 | typed_config:
38 | "@type": type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog
39 | http2_protocol_options:
40 | allow_connect: true
41 | upgrade_configs:
42 | - upgrade_type: CONNECT
43 | http_filters:
44 | - name: envoy.filters.http.router
45 | typed_config:
46 | "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
47 |
48 | route_config:
49 | name: local_route
50 | virtual_hosts:
51 | - name: local_service
52 | domains: [ "*" ]
53 | routes:
54 | - match:
55 | connect_matcher: { }
56 | route:
57 | cluster: influxdb_cluster
58 | upgrade_configs:
59 | upgrade_type: CONNECT
60 | connect_config: { }
61 | - match:
62 | prefix: "/"
63 | route:
64 | cluster: influxdb_cluster
65 | prefix_rewrite: "/"
66 | auto_host_rewrite: true
67 | timeout: 10s
68 | cors:
69 | allow_origin_string_match:
70 | - prefix: "*"
71 | allow_methods: GET, PUT, DELETE, POST, OPTIONS
72 | clusters:
73 | - name: influxdb_cluster
74 | connect_timeout: 10s
75 | type: STRICT_DNS
76 | load_assignment:
77 | cluster_name: influxdb_cluster
78 | endpoints:
79 | - lb_endpoints:
80 | - endpoint:
81 | address:
82 | socket_address:
83 | address: "us-east-1-1.aws.cloud2.influxdata.com"
84 | port_value: 443
--------------------------------------------------------------------------------
/scripts/influxdb-setup.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | #
3 | # The MIT License
4 | #
5 | # Permission is hereby granted, free of charge, to any person obtaining a copy
6 | # of this software and associated documentation files (the "Software"), to deal
7 | # in the Software without restriction, including without limitation the rights
8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | # copies of the Software, and to permit persons to whom the Software is
10 | # furnished to do so, subject to the following conditions:
11 | #
12 | # The above copyright notice and this permission notice shall be included in
13 | # all copies or substantial portions of the Software.
14 | #
15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | # THE SOFTWARE.
22 | #
23 |
24 | set -e
25 |
26 | DEFAULT_INFLUXDB_DATABASE=my-db
27 | INFLUXDB_DATABASE="${INFLUXDB_DATABASE:-$DEFAULT_INFLUXDB_DATABASE}"
28 |
29 | #
30 | # Parse command line arguments
31 | #
32 | EXPORT_URL_ENV_VAR=""
33 | EXPORT_DB_ENV_VAR=""
34 | EXPORT_TOKEN_ENV_VAR=""
35 | while [[ $# -gt 0 ]]; do
36 | case $1 in
37 | --export-url-as)
38 | EXPORT_URL_ENV_VAR="$2"
39 | shift 2
40 | ;;
41 | --export-db-as)
42 | EXPORT_DB_ENV_VAR="$2"
43 | shift 2
44 | ;;
45 | --export-token-as)
46 | EXPORT_TOKEN_ENV_VAR="$2"
47 | shift 2
48 | ;;
49 | *)
50 | echo "Unknown option $1"
51 | exit 1
52 | ;;
53 | esac
54 | done
55 |
56 | #
57 | # Check prerequisites
58 | #
59 | for cmd in curl jq; do
60 | command -v ${cmd} &>/dev/null || { echo "'${cmd}' is not installed"; exit 1; }
61 | done
62 |
63 | echo
64 | echo "Wait to start InfluxDB 3.0"
65 | echo
66 | for i in {1..30}; do
67 | if curl -s -o /dev/null -w "%{http_code}" http://localhost:8181/ping | grep -q "401"; then
68 | break
69 | fi
70 | echo "Attempt $i/30: Waiting for InfluxDB to respond with 401..."
71 | sleep 1
72 | done
73 | echo "Done"
74 |
75 | echo
76 | echo "Create admin token"
77 | echo
78 | ADMIN_TOKEN=$(curl -s -X POST http://localhost:8181/api/v3/configure/token/admin | jq -r '.token')
79 | if [[ -z "$ADMIN_TOKEN" || "$ADMIN_TOKEN" == "null" ]]; then
80 | echo "Failed to create admin token"
81 | exit 1
82 | fi
83 | echo "ADMIN_TOKEN=$ADMIN_TOKEN"
84 |
85 | echo
86 | echo "Test the token"
87 | echo
88 | HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Bearer ${ADMIN_TOKEN}" http://localhost:8181/ping)
89 | if [[ "$HTTP_CODE" != "200" ]]; then
90 | echo "Token test failed with HTTP $HTTP_CODE"
91 | exit 1
92 | fi
93 | echo "Done"
94 |
95 | echo
96 | echo "Create database"
97 | echo
98 | HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST "http://localhost:8181/api/v3/configure/database" \
99 | -H "Authorization: Bearer ${ADMIN_TOKEN}" \
100 | -H "Content-Type: application/json" \
101 | -d "{\"db\":\"${INFLUXDB_DATABASE}\"}")
102 | if [[ "$HTTP_CODE" != "200" ]]; then
103 | echo "Database creation failed with HTTP $HTTP_CODE"
104 | exit 1
105 | fi
106 | echo "Done"
107 |
108 | #
109 | # Export results
110 | #
111 |
112 | export_var() {
113 | local var_name="$1" var_value="$2"
114 | [[ -n "$var_name" ]] || return
115 | [[ -n "$BASH_ENV" ]] || { echo "\$BASH_ENV not available (not in CircleCI), cannot export variables."; exit 1; }
116 | echo "Exporting $var_name=$var_value"
117 | echo "export $var_name=$var_value" >> "$BASH_ENV"
118 | }
119 |
120 | echo
121 | export_var "$EXPORT_URL_ENV_VAR" "http://localhost:8181"
122 | export_var "$EXPORT_DB_ENV_VAR" "$INFLUXDB_DATABASE"
123 | export_var "$EXPORT_TOKEN_ENV_VAR" "$ADMIN_TOKEN"
124 |
125 |
--------------------------------------------------------------------------------
/examples/src/main/java/com/influxdb/v3/TimeoutsExample.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package com.influxdb.v3;
23 |
24 | import java.time.Duration;
25 | import java.util.concurrent.TimeUnit;
26 | import java.util.stream.Stream;
27 |
28 | import com.influxdb.v3.client.InfluxDBClient;
29 | import com.influxdb.v3.client.PointValues;
30 | import com.influxdb.v3.client.config.ClientConfig;
31 |
32 | /**
33 | * This example shows how to set universal timeouts for writes and queries.
34 | *
35 | * The example depends on the "influxdb3-java" module and this module should be built first
36 | * by running "mvn install" in the root directory.
37 | */
38 | public final class TimeoutsExample {
39 |
40 | public static String resolveProperty(final String property, final String fallback) {
41 | return System.getProperty(property, System.getenv(property)) == null
42 | ? fallback : System.getProperty(property, System.getenv(property));
43 | }
44 |
45 | private TimeoutsExample() { }
46 |
47 | public static void main(final String[] args) {
48 | // timeout to use for writes. Experiment with lower values to see timeout exceptions.
49 | Duration writeTimeout = Duration.ofMillis(5000L);
50 | // timeout to use for queries. Experiment with lower values to see timeout exceptions.
51 | Duration queryTimeout = Duration.ofMillis(5000L);
52 |
53 | String host = resolveProperty("INFLUX_HOST", "http://localhost:8181");
54 | String token = resolveProperty("INFLUX_TOKEN", "my-token");
55 | String database = resolveProperty("INFLUX_DATABASE", "my-database");
56 |
57 | String measurement = "timeout_example";
58 |
59 | ClientConfig config = new ClientConfig.Builder()
60 | .host(host)
61 | .token(token.toCharArray())
62 | .database(database)
63 | .writeTimeout(writeTimeout) // set timeout to be used with the Write API
64 | .queryTimeout(queryTimeout) // set timeout to be used with the Query API
65 | .build();
66 |
67 | try (InfluxDBClient client = InfluxDBClient.getInstance(config)) {
68 | client.writeRecord(String.format("%s,id=0001 temp=30.14,ticks=42i", measurement));
69 |
70 | TimeUnit.SECONDS.sleep(1);
71 | String sql = String.format("SELECT * FROM %s ORDER BY time DESC", measurement);
72 | try (Stream values = client.queryPoints(sql)) {
73 | values.forEach(pv -> {
74 | String sv = measurement + ","
75 | + " id: " + pv.getTag("id") + ","
76 | + " fVal: " + pv.getFloatField("temp") + ","
77 | + " iVal: " + pv.getIntegerField("ticks") + ","
78 | + " " + pv.getTimestamp();
79 | System.out.println(sv);
80 | });
81 | }
82 | } catch (Exception e) {
83 | throw new RuntimeException(e);
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/examples/pom.xml:
--------------------------------------------------------------------------------
1 |
24 |
26 | 4.0.0
27 |
28 | com.influxdb.v3
29 | examples
30 | 1.0-SNAPSHOT
31 | jar
32 |
33 |
34 | UTF-8
35 | com.influxdb.v3.IOxExample
36 |
37 |
38 |
39 |
40 | com.influxdb
41 | influxdb3-java
42 | 1.8.0-SNAPSHOT
43 |
44 |
45 |
46 |
47 |
48 |
49 | org.codehaus.mojo
50 | exec-maven-plugin
51 | 1.2.1
52 |
53 |
54 |
55 | java
56 |
57 |
58 |
59 |
60 | ${exec.main}
61 |
62 |
63 |
64 | org.apache.maven.plugins
65 | maven-compiler-plugin
66 | 3.10.1
67 |
68 | 11
69 |
70 |
71 |
72 |
73 | org.apache.maven.plugins
74 | maven-checkstyle-plugin
75 | 3.2.1
76 |
77 | true
78 | ../checkstyle.xml
79 | true
80 | false
81 |
82 | src/main/java
83 |
84 |
85 |
86 |
87 | verify
88 |
89 | checkstyle
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/src/test/java/com/influxdb/v3/client/TestUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package com.influxdb.v3.client;
23 |
24 | import java.net.URI;
25 | import java.nio.charset.StandardCharsets;
26 | import java.util.ArrayList;
27 | import java.util.List;
28 | import javax.annotation.Nonnull;
29 |
30 | import org.apache.arrow.flight.FlightServer;
31 | import org.apache.arrow.flight.Location;
32 | import org.apache.arrow.flight.NoOpFlightProducer;
33 | import org.apache.arrow.flight.Ticket;
34 | import org.apache.arrow.memory.BufferAllocator;
35 | import org.apache.arrow.memory.RootAllocator;
36 | import org.apache.arrow.vector.VarCharVector;
37 | import org.apache.arrow.vector.VectorSchemaRoot;
38 | import org.apache.arrow.vector.types.pojo.ArrowType;
39 | import org.apache.arrow.vector.types.pojo.Field;
40 | import org.apache.arrow.vector.types.pojo.FieldType;
41 | import org.apache.arrow.vector.types.pojo.Schema;
42 |
43 | public final class TestUtils {
44 |
45 | private TestUtils() {
46 | throw new IllegalStateException("Utility class");
47 | }
48 |
49 | public static FlightServer simpleFlightServer(@Nonnull final URI uri,
50 | @Nonnull final BufferAllocator allocator,
51 | @Nonnull final NoOpFlightProducer producer) throws Exception {
52 | Location location = Location.forGrpcInsecure(uri.getHost(), uri.getPort());
53 | return FlightServer.builder(allocator, location, producer).build();
54 | }
55 |
56 | public static NoOpFlightProducer simpleProducer(@Nonnull final VectorSchemaRoot vectorSchemaRoot) {
57 | return new NoOpFlightProducer() {
58 | @Override
59 | public void getStream(final CallContext context,
60 | final Ticket ticket,
61 | final ServerStreamListener listener) {
62 | listener.start(vectorSchemaRoot);
63 | if (listener.isReady()) {
64 | listener.putNext();
65 | }
66 | listener.completed();
67 | }
68 | };
69 | }
70 |
71 | public static VectorSchemaRoot generateVectorSchemaRoot(final int fieldCount, final int rowCount) {
72 | List fields = new ArrayList<>();
73 | for (int i = 0; i < fieldCount; i++) {
74 | Field field = new Field("field" + i, FieldType.nullable(new ArrowType.Utf8()), null);
75 | fields.add(field);
76 | }
77 |
78 | Schema schema = new Schema(fields);
79 | VectorSchemaRoot vectorSchemaRoot = VectorSchemaRoot.create(schema, new RootAllocator(Long.MAX_VALUE));
80 | for (Field field : fields) {
81 | VarCharVector vector = (VarCharVector) vectorSchemaRoot.getVector(field);
82 | vector.allocateNew(rowCount);
83 | for (int i = 0; i < rowCount; i++) {
84 | vector.set(i, "Value".getBytes(StandardCharsets.UTF_8));
85 | }
86 | }
87 | vectorSchemaRoot.setRowCount(rowCount);
88 |
89 | return vectorSchemaRoot;
90 | }
91 | }
92 |
93 |
--------------------------------------------------------------------------------
/src/test/java/com/influxdb/v3/client/internal/NanosecondConverterTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package com.influxdb.v3.client.internal;
23 |
24 | import java.math.BigInteger;
25 |
26 | import org.apache.arrow.vector.types.TimeUnit;
27 | import org.apache.arrow.vector.types.pojo.ArrowType;
28 | import org.apache.arrow.vector.types.pojo.Field;
29 | import org.apache.arrow.vector.types.pojo.FieldType;
30 | import org.junit.jupiter.api.Assertions;
31 | import org.junit.jupiter.api.Test;
32 |
33 | public class NanosecondConverterTest {
34 |
35 | @Test
36 | void testGetTimestampNanosecond() {
37 | BigInteger timestampNanoSecond = null;
38 |
39 | // Second
40 | FieldType timeTypeSecond = new FieldType(true,
41 | new ArrowType.Timestamp(TimeUnit.SECOND, "UTC"),
42 | null);
43 | Field timeFieldSecond = new Field("time", timeTypeSecond, null);
44 | timestampNanoSecond = NanosecondConverter.getTimestampNano(123_456L, timeFieldSecond);
45 | Assertions.assertEquals(
46 | BigInteger.valueOf(123_456L)
47 | .multiply(BigInteger.valueOf(1_000_000_000)), timestampNanoSecond
48 | );
49 |
50 | // MilliSecond
51 | FieldType timeTypeMilliSecond = new FieldType(true,
52 | new ArrowType.Timestamp(TimeUnit.MILLISECOND, "UTC"),
53 | null);
54 | Field timeFieldMilliSecond = new Field("time", timeTypeMilliSecond, null);
55 | timestampNanoSecond = NanosecondConverter.getTimestampNano(123_456L, timeFieldMilliSecond);
56 | Assertions.assertEquals(
57 | BigInteger.valueOf(123_456L)
58 | .multiply(BigInteger.valueOf(1_000_000)), timestampNanoSecond
59 | );
60 |
61 | // MicroSecond
62 | FieldType timeTypeMicroSecond = new FieldType(true,
63 | new ArrowType.Timestamp(TimeUnit.MICROSECOND, "UTC"),
64 | null);
65 | Field timeFieldMicroSecond = new Field("time", timeTypeMicroSecond, null);
66 | timestampNanoSecond = NanosecondConverter.getTimestampNano(123_456L, timeFieldMicroSecond);
67 | Assertions.assertEquals(
68 | BigInteger.valueOf(123_456L)
69 | .multiply(BigInteger.valueOf(1_000)), timestampNanoSecond
70 | );
71 |
72 | // Nano Second
73 | FieldType timeTypeNanoSecond = new FieldType(true,
74 | new ArrowType.Timestamp(TimeUnit.NANOSECOND, "UTC"),
75 | null);
76 | Field timeFieldNanoSecond = new Field("time", timeTypeNanoSecond, null);
77 | timestampNanoSecond = NanosecondConverter.getTimestampNano(123_456L, timeFieldNanoSecond);
78 | Assertions.assertEquals(BigInteger.valueOf(123_456L), timestampNanoSecond);
79 |
80 | // For ArrowType.Time type
81 | FieldType timeMilliSecond = new FieldType(true,
82 | new ArrowType.Time(TimeUnit.MILLISECOND, 32),
83 | null);
84 | Field fieldMilliSecond = new Field("time", timeMilliSecond, null);
85 | timestampNanoSecond = NanosecondConverter.getTimestampNano(123_456L, fieldMilliSecond);
86 | Assertions.assertEquals(
87 | BigInteger.valueOf(123_456L)
88 | .multiply(BigInteger.valueOf(1_000_000)), timestampNanoSecond
89 | );
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/examples/src/main/java/com/influxdb/v3/DownsamplingExample.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package com.influxdb.v3;
23 |
24 | import java.time.Instant;
25 | import java.time.LocalDateTime;
26 | import java.time.ZoneOffset;
27 | import java.time.temporal.ChronoUnit;
28 | import java.util.stream.Stream;
29 |
30 | import com.influxdb.v3.client.InfluxDBClient;
31 | import com.influxdb.v3.client.Point;
32 | import com.influxdb.v3.client.PointValues;
33 |
34 | /**
35 | * The example depends on the "influxdb3-java" module and this module should be built first
36 | * by running "mvn install" in the root directory.
37 | */
38 | public final class DownsamplingExample {
39 | private DownsamplingExample() {
40 | }
41 |
42 | public static void main(final String[] args) throws Exception {
43 | String host = "https://us-east-1-1.aws.cloud2.influxdata.com";
44 | String token = "my-token";
45 | String database = "my-database";
46 |
47 | try (InfluxDBClient client = InfluxDBClient.getInstance(host, token.toCharArray(), database)) {
48 | //
49 | // Write data
50 | //
51 | Point point1 = Point.measurement("stat")
52 | .setTag("unit", "temperature")
53 | .setField("avg", 24.5)
54 | .setField("max", 45.0)
55 | .setTimestamp(Instant.now().minus(20, ChronoUnit.MINUTES));
56 | client.writePoint(point1);
57 |
58 | Point point2 = Point.measurement("stat")
59 | .setTag("unit", "temperature")
60 | .setField("avg", 28.0)
61 | .setField("max", 40.3)
62 | .setTimestamp(Instant.now().minus(10, ChronoUnit.MINUTES));
63 | client.writePoint(point2);
64 |
65 | Point point3 = Point.measurement("stat")
66 | .setTag("unit", "temperature")
67 | .setField("avg", 20.5)
68 | .setField("max", 49.0)
69 | .setTimestamp(Instant.now());
70 | client.writePoint(point3);
71 |
72 | //
73 | // Query downsampled data
74 | //
75 | String sql = "SELECT\n"
76 | + " date_bin('5 minutes', \"time\") as window_start,\n"
77 | + " AVG(\"avg\") as avg,\n"
78 | + " MAX(\"max\") as max\n"
79 | + " FROM \"stat\"\n"
80 | + " WHERE\n"
81 | + " \"time\" >= now() - interval '1 hour'\n"
82 | + " GROUP BY window_start\n"
83 | + " ORDER BY window_start ASC;\n";
84 |
85 |
86 | //
87 | // Execute downsampling query into pointValues
88 | //
89 | try (Stream stream = client.queryPoints(sql)) {
90 | stream.forEach(
91 | (PointValues row) -> {
92 | var timestamp = row.getField("window_start", LocalDateTime.class);
93 |
94 | if (timestamp == null) {
95 | return;
96 | }
97 |
98 | System.out.printf("%s: avg is %s, max is %s%n",
99 | timestamp, row.getFloatField("avg"), row.getFloatField("max"));
100 |
101 | //
102 | // write back downsampled date to 'stat_downsampled' measurement
103 | //
104 | var downsampledPoint = row
105 | .asPoint("stat_downsampled")
106 | .removeField("window_start")
107 | .setTimestamp(timestamp.toInstant(ZoneOffset.UTC));
108 |
109 | client.writePoint(downsampledPoint);
110 | });
111 | }
112 | }
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/src/test/java/com/influxdb/v3/client/InfluxDBClientTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package com.influxdb.v3.client;
23 |
24 | import java.util.Map;
25 | import java.util.Properties;
26 |
27 | import org.assertj.core.api.Assertions;
28 | import org.junit.jupiter.api.Test;
29 |
30 | import com.influxdb.v3.client.config.ClientConfig;
31 |
32 | public class InfluxDBClientTest {
33 |
34 | @Test
35 | void withProxyUrl() {
36 | String proxyUrl = "http://localhost:10000";
37 | ClientConfig.Builder builder = new ClientConfig.Builder();
38 | builder.proxyUrl(proxyUrl);
39 | ClientConfig clientConfig = builder.build();
40 | Assertions.assertThat(clientConfig.getProxyUrl()).isEqualTo(proxyUrl);
41 | }
42 |
43 | @Test
44 | void withSslRootsFilePath() {
45 | String path = "/path/to/cert";
46 | ClientConfig.Builder builder = new ClientConfig.Builder();
47 | builder.sslRootsFilePath(path);
48 | ClientConfig clientConfig = builder.build();
49 | Assertions.assertThat(clientConfig.sslRootsFilePath()).isEqualTo(path);
50 | }
51 |
52 | @Test
53 | void requiredHost() {
54 |
55 | Assertions.assertThatThrownBy(() -> InfluxDBClient.getInstance(null, "my-token".toCharArray(), "my-database"))
56 | .isInstanceOf(IllegalArgumentException.class)
57 | .hasMessage("The URL of the InfluxDB server has to be defined.");
58 | }
59 |
60 | @Test
61 | void requiredHostConnectionString() {
62 |
63 | Assertions.assertThatThrownBy(() -> InfluxDBClient.getInstance("?token=my-token&database=my-database"))
64 | .isInstanceOf(IllegalArgumentException.class)
65 | .hasMessageContaining("no protocol");
66 | }
67 |
68 | @Test
69 | void fromParameters() throws Exception {
70 |
71 | try (InfluxDBClient client = InfluxDBClient.getInstance("http://localhost:8086",
72 | "my-token".toCharArray(), "my-database")) {
73 | Assertions.assertThat(client).isNotNull();
74 | }
75 | }
76 |
77 | @Test
78 | void fromConnectionString() throws Exception {
79 |
80 | try (InfluxDBClient client = InfluxDBClient.getInstance("http://localhost:8086"
81 | + "?token=my-token&database=my-db")) {
82 | Assertions.assertThat(client).isNotNull();
83 | }
84 | }
85 |
86 | @Test
87 | void fromEnvOrProperties() throws Exception {
88 |
89 | final Properties old = System.getProperties();
90 | final Properties p = new Properties();
91 | p.put("influx.host", "http://localhost:8086");
92 | p.put("influx.token", "my-token");
93 | p.put("influx.database", "my-db");
94 | System.setProperties(p);
95 |
96 | try (InfluxDBClient client = InfluxDBClient.getInstance()) {
97 | Assertions.assertThat(client).isNotNull();
98 | } finally {
99 | System.setProperties(old);
100 | }
101 | }
102 |
103 | @Test
104 | void withDefaultTags() throws Exception {
105 |
106 | Map defaultTags = Map.of("unit", "U2", "model", "M1");
107 |
108 | try (InfluxDBClient client = InfluxDBClient.getInstance(
109 | "http://localhost:8086",
110 | "MY-TOKEN".toCharArray(),
111 | "MY-DATABASE",
112 | defaultTags)) {
113 | Assertions.assertThat(client).isNotNull();
114 | }
115 | }
116 |
117 | @Test
118 | public void unsupportedQueryParams() throws Exception {
119 | try (InfluxDBClient client = InfluxDBClient.getInstance("http://localhost:8086",
120 | "my-token".toCharArray(), "my-database")) {
121 |
122 | String query = "select * from cpu where client=$client";
123 | Map parameters = Map.of("client", client);
124 |
125 | Assertions.assertThatThrownBy(() -> client.queryPoints(query, parameters))
126 | .isInstanceOf(IllegalArgumentException.class)
127 | .hasMessage("The parameter client value has unsupported type: "
128 | + "class com.influxdb.v3.client.internal.InfluxDBClientImpl");
129 | }
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/examples/src/main/java/com/influxdb/v3/IOxExample.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package com.influxdb.v3;
23 |
24 | import java.time.Instant;
25 | import java.util.Map;
26 | import java.util.stream.Stream;
27 |
28 | import com.influxdb.v3.client.InfluxDBClient;
29 | import com.influxdb.v3.client.Point;
30 | import com.influxdb.v3.client.PointValues;
31 | import com.influxdb.v3.client.query.QueryOptions;
32 |
33 | /**
34 | * The example depends on the "influxdb3-java" module and this module should be built first
35 | * by running "mvn install" in the root directory.
36 | */
37 | public final class IOxExample {
38 | private IOxExample() {
39 | }
40 |
41 | public static void main(final String[] args) throws Exception {
42 | String host = "https://us-east-1-1.aws.cloud2.influxdata.com";
43 | String token = "my-token";
44 | String database = "my-database";
45 |
46 | try (InfluxDBClient client = InfluxDBClient.getInstance(host, token.toCharArray(), database)) {
47 |
48 | //
49 | // Write by Point
50 | //
51 | Point point = Point.measurement("temperature")
52 | .setTag("location", "west")
53 | .setField("value", 55.15)
54 | .setTimestamp(Instant.now().minusSeconds(-10));
55 | client.writePoint(point);
56 |
57 | //
58 | // Write by LineProtocol
59 | //
60 | String record = "temperature,location=north value=60.0";
61 | client.writeRecord(record);
62 |
63 | //
64 | // Query by SQL
65 | //
66 | System.out.printf("--------------------------------------------------------%n");
67 | System.out.printf("| %-8s | %-8s | %-30s |%n", "location", "value", "time");
68 | System.out.printf("--------------------------------------------------------%n");
69 |
70 | String sql = "select time,location,value from temperature order by time desc limit 10";
71 | try (Stream