This plugin creates a dsl for Tigergraph. The dsl allows you to describe connections to a Tigergraph server.
The Giraffle plugin has been published to the Gradle plugins repository. You
may use it by referencing it within your plugins
block.
plugins {
id("com.optum.giraffle") version "1.0.2"
}
Fork and clone this repository. After this you should be able to make changes,
compile, test and publish. The publishToMavenLocal
will make the plugin
available to your Gradle projects.
In order to use this plugin you’ll need to install this plugin and Tigergraph’s gsql client.
To install the gradle plugin, follow the instructions outlined in Development Assistance.
The Tigergraph plugin in published to bintray, and is available via a
jcenter()
repository. To use the gsql_client
you’ll need to add the
jcenter()
to you repositories block.
repositories {
jcenter()
mavenLocal() // (1)
}
-
Not required unless you’re doing local plugin development.
build.gradle.kts
plugins {
id("com.optum.giraffle) version "1.0.2" // (1)
}
dependencies {
gsqlRuntime("com.tigergraph.client:gsql_client:2.3.2.1") // (2)
}
tigergraph {
scriptDir.set(file("scripts"))
tokens.set(emptyMap())
serverName.set("")
userName.set("")
password.set("")
adminUserName.set("")
adminPassword.set("")
}
-
Watch this version. You’ll need to update it as development proceeds.
-
This configuration isn’t required. The defaults within the plugin provide this dependency already. However, if you need to override the defaults, this is how you do that. You might want to override this value if you need a different version of the gsql_client.
This should put everything in order. The plugin defines a couple of tasks, and a dsl to handle connection parameters to your Tigergraph server(s).
The plugin creates a dsl, custom task types, and custom tasks.
The dsl provided by this plugin allow configuration that applies to all the tasks and types created by the plugin.
All the components belong within a tigergraph
closure. All of these are
properties, and need to be set
accordingly.
The scriptDir
configuration is a file
path location for where the gsql
scripts for your project live.
The default value for scriptDir
is db_scripts
. It is not necessary to set
this value if you’ve placed you scripts in this directory already.
Example: Kotlin
build.gradle.kts
tigergraph {
scriptDir.set(file("scripts"))
}
Example: Groovy
build.gradle
tigergraph {
scriptDir = file("scripts")
}
This plugin supports token replacement within your source scripts. Internally it uses an Ant filter. Simply provide a map as the parameter to this property, and your sources will have the tokens replaced before execution.
Example: Kotlin
build.gradl.kts
val tokenMap: LinkedHashMap<String, String> = linkedMapOf("graphname" to "hc")
tigergraph {
tokens.set(tokenMap)
}
This configuration will take each occurrence of @graphname@
and replace it
with the value of hc
within the source scripts.
The serverName
property configures which server to execute your scripts
against.
Example: Kotlin
build.gradle.kts
tigergraph {
serverName.set("dbsw00001")
}
The userName
property configures the username to use for connecting to
tigergraph. This is the default username to use. When a script requires
elevated privileges, see adminUserName and superUser.
The password
property configures the password to use for connecting to
tigergraph. This is property is used in conjunction with userName.
The adminUserName
property configures the username to use for connecting to
tigergraph. This is used when the superUser
property is set on a gsql script.
See superUser.
The adminPassword
property configures the password to use for connecting to
tigergraph. This is property is used in conjunction with adminUserName.
The plugin defines this task, and adds it to the project. This task copies
files from the scriptDir directory and copies the files to
the project’s buildDir
.
This is the step where token replacement occurs, as defined by the tokens property.
This defines a task type that allows you to execute your scripts against the tigergraph server with the properties set by the Tigergraph DSL
To use this task type you simply need to define the name of the script to execute, and optionally the superUser directive.
The path, relative to scriptDir to execute.
I like using this with plugin in conjunction with the Properties plugin. This allows you to use and configure different environments.
gradle.properties
username=joe
password=joehasabadpassword
host=dbsrv001
graphname=hc
build.gradle.kts
import com.optum.giraffle.tasks.GsqlCopySources
import com.optum.giraffle.tasks.GsqlTask
plugins {
id("com.optum.giraffle") version "0.1.0"
}
repositories {
mavenLocal()
jcenter()
}
val graphname: String by project // (1)
val host: String by project
val username: String by project
val password: String by project
val tokenMap: LinkedHashMap<String, String> = linkedMapOf("graphname" to graphname) // (2)
tigergraph { // (3)
scriptDir.set(file("db_scripts"))
tokens.set(tokenMap)
serverName.set(host)
userName.set(username)
password.set(password)
}
val createSchema by tasks.creating(GsqlTask::class) {
group = "Tigergraph Schema"
description = "Create the schema on the database"
scriptPath = "schema.gsql" // (4)
superUser = true // (5)
}
-
by project
is how you references project properties using the Kotlin DSL for Gradle. -
This is how you create a Kotlin map to pass to a property.
-
Our Tigergraph DSL. These settings apply for all interactions with Tigergraph.
-
The path to the source script relative to
scriptDir
. -
Informs the plugin which credentials to use.