feat(clientLibs): add Kotlin and Scala client library (#18198)
* feat(clientLibs): add Kotlin and Scala client library Signed-off-by: Jakub Bednar <jakub.bednar@gmail.com> * feat(clientLibs): add Kotlin logo from - https://resources.jetbrains.com/storage/products/kotlin/docs/kotlin_logos.zip Signed-off-by: Jakub Bednar <jakub.bednar@gmail.com> * feat(clientLibs): add Scala logo from - https://github.com/kaeawc/scala-logo Signed-off-by: Jakub Bednar <jakub.bednar@gmail.com> * fix(clientLibs): fixing logos, small code cleanup * fix(clientLibs): run prettier Co-authored-by: Russ Savage <russ@influxdata.com>pull/18277/head
parent
d30540e0b2
commit
97200f1b92
|
|
@ -0,0 +1,86 @@
|
|||
// Libraries
|
||||
import React, {FunctionComponent} from 'react'
|
||||
import {connect} from 'react-redux'
|
||||
|
||||
// Components
|
||||
import ClientLibraryOverlay from 'src/clientLibraries/components/ClientLibraryOverlay'
|
||||
import TemplatedCodeSnippet from 'src/shared/components/TemplatedCodeSnippet'
|
||||
|
||||
// Constants
|
||||
import {clientKotlinLibrary} from 'src/clientLibraries/constants'
|
||||
|
||||
// Types
|
||||
import {AppState} from 'src/types'
|
||||
|
||||
// Selectors
|
||||
import {getOrg} from 'src/organizations/selectors'
|
||||
|
||||
interface StateProps {
|
||||
org: string
|
||||
}
|
||||
|
||||
type Props = StateProps
|
||||
|
||||
const ClientKotlinOverlay: FunctionComponent<Props> = props => {
|
||||
const {
|
||||
name,
|
||||
url,
|
||||
buildWithMavenCodeSnippet,
|
||||
buildWithGradleCodeSnippet,
|
||||
initializeClientCodeSnippet,
|
||||
executeQueryCodeSnippet,
|
||||
} = clientKotlinLibrary
|
||||
const {org} = props
|
||||
const server = window.location.origin
|
||||
|
||||
return (
|
||||
<ClientLibraryOverlay title={`${name} Client Library`}>
|
||||
<p>
|
||||
For more detailed and up to date information check out the{' '}
|
||||
<a href={url} target="_blank">
|
||||
GitHub Repository
|
||||
</a>
|
||||
</p>
|
||||
<h5>Add Dependency</h5>
|
||||
<p>Build with Maven</p>
|
||||
<TemplatedCodeSnippet template={buildWithMavenCodeSnippet} label="Code" />
|
||||
<p>Build with Gradle</p>
|
||||
<TemplatedCodeSnippet
|
||||
template={buildWithGradleCodeSnippet}
|
||||
label="Code"
|
||||
/>
|
||||
<h5>Initialize the Client</h5>
|
||||
<TemplatedCodeSnippet
|
||||
template={initializeClientCodeSnippet}
|
||||
label="Kotlin Code"
|
||||
defaults={{
|
||||
server: 'basepath',
|
||||
token: 'token',
|
||||
org: 'orgID',
|
||||
bucket: 'bucketID',
|
||||
}}
|
||||
values={{
|
||||
server,
|
||||
org,
|
||||
}}
|
||||
/>
|
||||
<h5>Execute a Flux query</h5>
|
||||
<TemplatedCodeSnippet
|
||||
template={executeQueryCodeSnippet}
|
||||
label="Kotlin Code"
|
||||
/>
|
||||
</ClientLibraryOverlay>
|
||||
)
|
||||
}
|
||||
|
||||
const mstp = (state: AppState): StateProps => {
|
||||
return {
|
||||
org: getOrg(state).id,
|
||||
}
|
||||
}
|
||||
|
||||
export {ClientKotlinOverlay}
|
||||
export default connect<StateProps, {}, Props>(
|
||||
mstp,
|
||||
null
|
||||
)(ClientKotlinOverlay)
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
// Libraries
|
||||
import React, {FunctionComponent} from 'react'
|
||||
import {connect} from 'react-redux'
|
||||
|
||||
// Components
|
||||
import ClientLibraryOverlay from 'src/clientLibraries/components/ClientLibraryOverlay'
|
||||
import TemplatedCodeSnippet from 'src/shared/components/TemplatedCodeSnippet'
|
||||
|
||||
// Constants
|
||||
import {clientScalaLibrary} from 'src/clientLibraries/constants'
|
||||
|
||||
// Types
|
||||
import {AppState} from 'src/types'
|
||||
|
||||
// Selectors
|
||||
import {getOrg} from 'src/organizations/selectors'
|
||||
|
||||
interface StateProps {
|
||||
org: string
|
||||
}
|
||||
|
||||
type Props = StateProps
|
||||
|
||||
const ClientScalaOverlay: FunctionComponent<Props> = props => {
|
||||
const {
|
||||
name,
|
||||
url,
|
||||
buildWithSBTCodeSnippet,
|
||||
buildWithMavenCodeSnippet,
|
||||
buildWithGradleCodeSnippet,
|
||||
initializeClientCodeSnippet,
|
||||
executeQueryCodeSnippet,
|
||||
} = clientScalaLibrary
|
||||
const {org} = props
|
||||
const server = window.location.origin
|
||||
|
||||
return (
|
||||
<ClientLibraryOverlay title={`${name} Client Library`}>
|
||||
<p>
|
||||
For more detailed and up to date information check out the{' '}
|
||||
<a href={url} target="_blank">
|
||||
GitHub Repository
|
||||
</a>
|
||||
</p>
|
||||
<h5>Add Dependency</h5>
|
||||
<p>Build with sbt</p>
|
||||
<TemplatedCodeSnippet template={buildWithSBTCodeSnippet} label="Code" />
|
||||
<p>Build with Maven</p>
|
||||
<TemplatedCodeSnippet template={buildWithMavenCodeSnippet} label="Code" />
|
||||
<p>Build with Gradle</p>
|
||||
<TemplatedCodeSnippet
|
||||
template={buildWithGradleCodeSnippet}
|
||||
label="Code"
|
||||
/>
|
||||
<h5>Initialize the Client</h5>
|
||||
<TemplatedCodeSnippet
|
||||
template={initializeClientCodeSnippet}
|
||||
label="Scala Code"
|
||||
defaults={{
|
||||
server: 'basepath',
|
||||
token: 'token',
|
||||
org: 'orgID',
|
||||
bucket: 'bucketID',
|
||||
}}
|
||||
values={{
|
||||
server,
|
||||
org,
|
||||
}}
|
||||
/>
|
||||
<h5>Execute a Flux query</h5>
|
||||
<TemplatedCodeSnippet
|
||||
template={executeQueryCodeSnippet}
|
||||
label="Scala Code"
|
||||
/>
|
||||
</ClientLibraryOverlay>
|
||||
)
|
||||
}
|
||||
|
||||
const mstp = (state: AppState): StateProps => {
|
||||
return {
|
||||
org: getOrg(state).id,
|
||||
}
|
||||
}
|
||||
|
||||
export {ClientScalaOverlay}
|
||||
export default connect<StateProps, {}, Props>(
|
||||
mstp,
|
||||
null
|
||||
)(ClientScalaOverlay)
|
||||
|
|
@ -1,11 +1,15 @@
|
|||
import {SFC} from 'react'
|
||||
import CSharpLogo from '../graphics/CSharpLogo'
|
||||
import GoLogo from '../graphics/GoLogo'
|
||||
import JavaLogo from '../graphics/JavaLogo'
|
||||
import JSLogo from '../graphics/JSLogo'
|
||||
import PHPLogo from '../graphics/PHPLogo'
|
||||
import PythonLogo from '../graphics/PythonLogo'
|
||||
import RubyLogo from '../graphics/RubyLogo'
|
||||
import {
|
||||
CSharpLogo,
|
||||
GoLogo,
|
||||
JavaLogo,
|
||||
JSLogo,
|
||||
KotlinLogo,
|
||||
PHPLogo,
|
||||
PythonLogo,
|
||||
RubyLogo,
|
||||
ScalaLogo,
|
||||
} from '../graphics'
|
||||
|
||||
export interface ClientLibrary {
|
||||
id: string
|
||||
|
|
@ -392,12 +396,127 @@ $writeApi->write($point, WritePrecision::S, $bucket, $org);`,
|
|||
$writeApi->write($dataArray, WritePrecision::S, $bucket, $org);`,
|
||||
}
|
||||
|
||||
export const clientKotlinLibrary = {
|
||||
id: 'kotlin',
|
||||
name: 'Kotlin',
|
||||
url:
|
||||
'https://github.com/influxdata/influxdb-client-java/tree/master/client-kotlin',
|
||||
image: KotlinLogo,
|
||||
buildWithMavenCodeSnippet: `<dependency>
|
||||
<groupId>com.influxdb</groupId>
|
||||
<artifactId>influxdb-client-kotlin</artifactId>
|
||||
<version>1.8.0</version>
|
||||
</dependency>`,
|
||||
buildWithGradleCodeSnippet: `dependencies {
|
||||
compile "com.influxdb:influxdb-client-kotlin:1.8.0"
|
||||
}`,
|
||||
initializeClientCodeSnippet: `package example
|
||||
|
||||
import com.influxdb.client.kotlin.InfluxDBClientKotlinFactory
|
||||
import kotlinx.coroutines.channels.consumeEach
|
||||
import kotlinx.coroutines.channels.filter
|
||||
import kotlinx.coroutines.channels.take
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
fun main() = runBlocking {
|
||||
|
||||
// You can generate a Token from the "Tokens Tab" in the UI
|
||||
val token = "<%= token %>"
|
||||
val org = "<%= org %>"
|
||||
val bucket = "<%= bucket %>"
|
||||
|
||||
val client = InfluxDBClientKotlinFactory.create("<%= server %>", token.toCharArray(), org)
|
||||
}`,
|
||||
executeQueryCodeSnippet: `val query = ("from(bucket: \\"$bucket\\")"
|
||||
+ " |> range(start: -1d)"
|
||||
+ " |> filter(fn: (r) => (r[\\"_measurement\\"] == \\"cpu\\" and r[\\"_field\\"] == \\"usage_system\\"))")
|
||||
|
||||
// Result is returned as a stream
|
||||
val results = client.getQueryKotlinApi().query(query)
|
||||
|
||||
// Example of additional result stream processing on client side
|
||||
results
|
||||
// filter on client side using \`filter\` built-in operator
|
||||
.filter { "cpu0" == it.getValueByKey("cpu") }
|
||||
// take first 20 records
|
||||
.take(20)
|
||||
// print results
|
||||
.consumeEach { println("Measurement: $\{it.measurement}, value: $\{it.value}") }
|
||||
|
||||
client.close()`,
|
||||
}
|
||||
|
||||
export const clientScalaLibrary = {
|
||||
id: 'scala',
|
||||
name: 'Scala',
|
||||
url:
|
||||
'https://github.com/influxdata/influxdb-client-java/tree/master/client-scala',
|
||||
image: ScalaLogo,
|
||||
buildWithSBTCodeSnippet: `libraryDependencies += "com.influxdb" % "influxdb-client-scala" % "1.8.0"`,
|
||||
buildWithMavenCodeSnippet: `<dependency>
|
||||
<groupId>com.influxdb</groupId>
|
||||
<artifactId>influxdb-client-scala</artifactId>
|
||||
<version>1.8.0</version>
|
||||
</dependency>`,
|
||||
buildWithGradleCodeSnippet: `dependencies {
|
||||
compile "com.influxdb:influxdb-client-scala:1.8.0"
|
||||
}`,
|
||||
initializeClientCodeSnippet: `package example
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import akka.stream.scaladsl.Sink
|
||||
import com.influxdb.client.scala.InfluxDBClientScalaFactory
|
||||
import com.influxdb.query.FluxRecord
|
||||
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration.Duration
|
||||
|
||||
object InfluxDB2ScalaExample {
|
||||
|
||||
implicit val system: ActorSystem = ActorSystem("it-tests")
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
|
||||
// You can generate a Token from the "Tokens Tab" in the UI
|
||||
val token = "<%= token %>"
|
||||
val org = "<%= org %>"
|
||||
val bucket = "<%= bucket %>"
|
||||
|
||||
val client = InfluxDBClientScalaFactory.create("<%= server %>", token.toCharArray, org)
|
||||
}
|
||||
}`,
|
||||
executeQueryCodeSnippet: `val query = (s"""from(bucket: "$bucket")"""
|
||||
+ " |> range(start: -1d)"
|
||||
+ " |> filter(fn: (r) => (r[\\"_measurement\\"] == \\"cpu\\" and r[\\"_field\\"] == \\"usage_system\\"))")
|
||||
|
||||
// Result is returned as a stream
|
||||
val results = client.getQueryScalaApi().query(query)
|
||||
|
||||
// Example of additional result stream processing on client side
|
||||
val sink = results
|
||||
// filter on client side using \`filter\` built-in operator
|
||||
.filter(it => "cpu0" == it.getValueByKey("cpu"))
|
||||
// take first 20 records
|
||||
.take(20)
|
||||
// print results
|
||||
.runWith(Sink.foreach[FluxRecord](it => println(s"Measurement: $\{it.getMeasurement}, value: $\{it.getValue}")
|
||||
))
|
||||
|
||||
// wait to finish
|
||||
Await.result(sink, Duration.Inf)
|
||||
|
||||
client.close()
|
||||
system.terminate()`,
|
||||
}
|
||||
|
||||
export const clientLibraries: ClientLibrary[] = [
|
||||
clientCSharpLibrary,
|
||||
clientGoLibrary,
|
||||
clientJavaLibrary,
|
||||
clientJSLibrary,
|
||||
clientKotlinLibrary,
|
||||
clientPHPLibrary,
|
||||
clientPythonLibrary,
|
||||
clientRubyLibrary,
|
||||
clientScalaLibrary,
|
||||
]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
// Libraries
|
||||
import React, {SFC} from 'react'
|
||||
|
||||
const KotlinLogo: SFC = () => {
|
||||
return (
|
||||
<svg
|
||||
x={0}
|
||||
y={0}
|
||||
viewBox="0 0 60 60"
|
||||
xmlSpace="preserve"
|
||||
width="80"
|
||||
height="100"
|
||||
>
|
||||
<linearGradient
|
||||
id="kotlin-a"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1={15.959}
|
||||
y1={-13.014}
|
||||
x2={44.307}
|
||||
y2={15.333}
|
||||
gradientTransform="matrix(1 0 0 -1 0 61)"
|
||||
>
|
||||
<stop offset={0.097} stopColor="#0095d5" />
|
||||
<stop offset={0.301} stopColor="#238ad9" />
|
||||
<stop offset={0.621} stopColor="#557bde" />
|
||||
<stop offset={0.864} stopColor="#7472e2" />
|
||||
<stop offset={1} stopColor="#806ee3" />
|
||||
</linearGradient>
|
||||
<path fill="url(#kotlin-a)" d="M0 60L30.1 29.9 60 60z" />
|
||||
<linearGradient
|
||||
id="kotlin-b"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1={4.209}
|
||||
y1={48.941}
|
||||
x2={20.673}
|
||||
y2={65.405}
|
||||
gradientTransform="matrix(1 0 0 -1 0 61)"
|
||||
>
|
||||
<stop offset={0.118} stopColor="#0095d5" />
|
||||
<stop offset={0.418} stopColor="#3c83dc" />
|
||||
<stop offset={0.696} stopColor="#6d74e1" />
|
||||
<stop offset={0.833} stopColor="#806ee3" />
|
||||
</linearGradient>
|
||||
<path fill="url(#kotlin-b)" d="M0 0L30.1 0 0 32.5z" />
|
||||
<linearGradient
|
||||
id="kotlin-c"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1={-10.102}
|
||||
y1={5.836}
|
||||
x2={45.731}
|
||||
y2={61.669}
|
||||
gradientTransform="matrix(1 0 0 -1 0 61)"
|
||||
>
|
||||
<stop offset={0.107} stopColor="#c757bc" />
|
||||
<stop offset={0.214} stopColor="#d0609a" />
|
||||
<stop offset={0.425} stopColor="#e1725c" />
|
||||
<stop offset={0.605} stopColor="#ee7e2f" />
|
||||
<stop offset={0.743} stopColor="#f58613" />
|
||||
<stop offset={0.823} stopColor="#f88909" />
|
||||
</linearGradient>
|
||||
<path fill="url(#kotlin-c)" d="M30.1 0L0 31.7 0 60 30.1 29.9 60 0z" />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
export default KotlinLogo
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
// Libraries
|
||||
import React, {SFC} from 'react'
|
||||
|
||||
const ScalaLogo: SFC = () => {
|
||||
return (
|
||||
<svg viewBox="0 0 64 64" height={100} width={100}>
|
||||
<linearGradient id="scala-a">
|
||||
<stop offset={0} stopColor="#656565" />
|
||||
<stop offset={1} stopColor="#010101" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="scala-c"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1={13.528}
|
||||
x2={88.264}
|
||||
xlinkHref="#scala-a"
|
||||
y1={-36.176}
|
||||
y2={-36.176}
|
||||
/>
|
||||
<linearGradient
|
||||
id="scala-d"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1={13.528}
|
||||
x2={88.264}
|
||||
xlinkHref="#scala-a"
|
||||
y1={3.91}
|
||||
y2={3.91}
|
||||
/>
|
||||
<linearGradient id="scala-b">
|
||||
<stop offset={0} stopColor="#9f1c20" />
|
||||
<stop offset={1} stopColor="#ed2224" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="scala-e"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1={13.528}
|
||||
x2={88.264}
|
||||
xlinkHref="#scala-b"
|
||||
y1={-55.974}
|
||||
y2={-55.974}
|
||||
/>
|
||||
<linearGradient
|
||||
id="scala-f"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1={13.528}
|
||||
x2={88.264}
|
||||
xlinkHref="#scala-b"
|
||||
y1={-15.87}
|
||||
y2={-15.87}
|
||||
/>
|
||||
<linearGradient
|
||||
id="scala-g"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1={13.528}
|
||||
x2={88.264}
|
||||
xlinkHref="#scala-b"
|
||||
y1={24.22}
|
||||
y2={24.22}
|
||||
/>
|
||||
<path
|
||||
d="M13.4-31s75 7.5 75 20v-30s0-12.5-75-20z"
|
||||
fill="url(#scala-d)"
|
||||
transform="matrix(.4923 0 0 .4923 6.942 39.877)"
|
||||
/>
|
||||
<path
|
||||
d="M13.4 9s75 7.5 75 20V-1s0-12.5-75-20z"
|
||||
fill="url(#scala-d)"
|
||||
transform="matrix(.4923 0 0 .4923 6.942 39.877)"
|
||||
/>
|
||||
<path
|
||||
d="M88.4-81v30s0 12.5-75 20v-30s75-7.5 75-20"
|
||||
fill="url(#scala-e)"
|
||||
transform="matrix(.4923 0 0 .4923 6.942 39.877)"
|
||||
/>
|
||||
<path
|
||||
d="M13.4-21s75-7.5 75-20v30s0 12.5-75 20z"
|
||||
fill="url(#scala-f)"
|
||||
transform="matrix(.4923 0 0 .4923 6.942 39.877)"
|
||||
/>
|
||||
<path
|
||||
d="M13.4 49V19s75-7.5 75-20v30s0 12.5-75 20"
|
||||
fill="url(#scala-g)"
|
||||
transform="matrix(.4923 0 0 .4923 6.942 39.877)"
|
||||
/>
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
export default ScalaLogo
|
||||
|
|
@ -4,9 +4,11 @@ import GoLogo from 'src/clientLibraries/graphics/GoLogo'
|
|||
import {GoogleLogo} from 'src/clientLibraries/graphics/GoogleLogo'
|
||||
import JavaLogo from 'src/clientLibraries/graphics/JavaLogo'
|
||||
import JSLogo from 'src/clientLibraries/graphics/JSLogo'
|
||||
import KotlinLogo from 'src/clientLibraries/graphics/KotlinLogo'
|
||||
import PHPLogo from 'src/clientLibraries/graphics/PHPLogo'
|
||||
import PythonLogo from 'src/clientLibraries/graphics/PythonLogo'
|
||||
import RubyLogo from 'src/clientLibraries/graphics/RubyLogo'
|
||||
import ScalaLogo from 'src/clientLibraries/graphics/ScalaLogo'
|
||||
|
||||
export {
|
||||
CSharpLogo,
|
||||
|
|
@ -15,7 +17,9 @@ export {
|
|||
GoogleLogo,
|
||||
JavaLogo,
|
||||
JSLogo,
|
||||
KotlinLogo,
|
||||
PHPLogo,
|
||||
PythonLogo,
|
||||
RubyLogo,
|
||||
ScalaLogo,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,9 +54,11 @@ import ClientCSharpOverlay from 'src/clientLibraries/components/ClientCSharpOver
|
|||
import ClientGoOverlay from 'src/clientLibraries/components/ClientGoOverlay'
|
||||
import ClientJavaOverlay from 'src/clientLibraries/components/ClientJavaOverlay'
|
||||
import ClientJSOverlay from 'src/clientLibraries/components/ClientJSOverlay'
|
||||
import ClientKotlinOverlay from 'src/clientLibraries/components/ClientKotlinOverlay'
|
||||
import ClientPHPOverlay from 'src/clientLibraries/components/ClientPHPOverlay'
|
||||
import ClientPythonOverlay from 'src/clientLibraries/components/ClientPythonOverlay'
|
||||
import ClientRubyOverlay from 'src/clientLibraries/components/ClientRubyOverlay'
|
||||
import ClientScalaOverlay from 'src/clientLibraries/components/ClientScalaOverlay'
|
||||
import TemplateImportOverlay from 'src/templates/components/TemplateImportOverlay'
|
||||
import TemplateExportOverlay from 'src/templates/components/TemplateExportOverlay'
|
||||
import VariablesIndex from 'src/variables/containers/VariablesIndex'
|
||||
|
|
@ -371,6 +373,10 @@ class Root extends PureComponent {
|
|||
path="javascript-node"
|
||||
component={ClientJSOverlay}
|
||||
/>
|
||||
<Route
|
||||
path="kotlin"
|
||||
component={ClientKotlinOverlay}
|
||||
/>
|
||||
<Route
|
||||
path="php"
|
||||
component={ClientPHPOverlay}
|
||||
|
|
@ -383,6 +389,10 @@ class Root extends PureComponent {
|
|||
path="ruby"
|
||||
component={ClientRubyOverlay}
|
||||
/>
|
||||
<Route
|
||||
path="scala"
|
||||
component={ClientScalaOverlay}
|
||||
/>
|
||||
</Route>
|
||||
</Route>
|
||||
<Route path="settings">
|
||||
|
|
|
|||
Loading…
Reference in New Issue