If you’re unfamiliar with TigerGraph Cloud, you should check out Getting Started with TigerGraph Cloud. If you run into any barriers while working tutorial there are links on the bottom to reach out to the community for Q&A.
Pre-Requirements
Introduction to Giraffle
Giraffle can be used to help you automate the deployment of schema, loading jobs, and queries to TigerGraph
Giraffle helps you keep your code local while executing your gsql scripts on a remote server. Giraffle also helps you keep environment specific configuration out of your code. Most importantly it helps you keep your credentials out of your code.
To learn more about Giraffle, it’s suggested to check out the following, Deep Dive into Giraffle a GSQL Build Tool or Getting Started with Giraffle to learn how to use all of the Giraffle functionalities.
Setting up Giraffle on a New Project
For this tutorial, we will walk you through “how-to” to set up your project from the ground up.
Step 1) Create a Project Directory: Navigate to your project directory. If a project directory doesn’t exist create one and enter your project directory. A simple command to do this in a terminal:
mkdir yourprojectname
cd youprojectname
Step 2) Initialize Gradle: You can select “basic” and “Kotlin” as a default.
gradle init/* It will prompt you with */
It will prompt you with:Select type of project to generate:
1: basic
2: application
3: library
4: Gradle plugin
Enter selection (default: basic) [1..4] 1Select build script DSL:
1: Groovy
2: Kotlin
Enter selection (default: Groovy) [1..2] 2Project name (default: yourprojectname):
Initializing will give you the default gradle directories and files needed for giraffle and or gradle build projects.
Step 3) Add Giraffle Plugin: Add the following into your “build.gradle.kts”
import com.optum.giraffle.tasks.GsqlTaskplugins {
id("com.optum.giraffle") version "1.3.2.1"
id("net.saliman.properties") version "1.5.1"
}repositories{
jcenter()
}
To test if Giraffle is working running try “gradle tasks” you should new GSQL tasks appear
Step 4) Initialize GSQL project: There is a built-in task called “gsqlNewProject” that will set up your project directory with all the appropriate directories and files.
gradle gsqlNewProject --console=plain
You will need to have the following TigerGraph :
- Project name == Graph name
- Tigergraph Host == TigerGraph cloud hostname
- Admin Username
- Admin Password
- Username
- Password
If you’re reading this and don’t have those. Don’t worry. Check this blog out on Getting Started with TigerGraph Cloud and simply come back.
Step 6) Create a cert.txt file: This step is to prevent man-in-the-middle attacks. In your main project folder run the following but, replace hostname.
openssl s_client -connect hostname.i.tgcloud.io:14240 < /dev/null 2> /dev/null | \
openssl x509 -text > cert.txt
Step 7) Add caCert
In the file “build.gradle.kts” make sure your caCert is added:
import com.optum.giraffle.tasks.GsqlTask plugins {
id("com.optum.giraffle") version "1.3.3"
id("net.saliman.properties") version "1.5.1"
} repositories {
jcenter()
} val gsqlGraphname: String by project // <1>
val gsqlHost: String by project
val gsqlUserName: String by project
val gsqlPassword: String by project
val gsqlAdminUserName: String by project
val gsqlAdminPassword: String by project
caCert.set("./cert.txt") // ADD CERT HERE
val tokenMap: LinkedHashMap<String, String> = linkedMapOf("graphname" to gsqlGraphname) // <2>val grpSchema: String = "Tigergraph Schema" tigergraph { // <3>
scriptDir.set(file("db_scripts"))
tokens.set(tokenMap)
serverName.set(gsqlHost)
userName.set(gsqlUserName)
password.set(gsqlPassword)
adminUserName.set(gsqlAdminUserName) adminPassword.set(gsqlAdminPassword)
caCert.set("./cert.txt")
}
In the same file “build.gradle.kts” add the following caCert.set(“./cert.txt”)
tigergraph {
scriptDir.set(file("db_scripts"))
tokens.set(tokenMap)
serverName.set(gHost)
userName.set(gUserName)
password.set(gPassword)
adminUserName.set(gAdminUserName)
adminPassword.set(gAdminPassword)
caCert.set("./cert.txt") // ADD CERT HERE
gClientVersion?.let {
gsqlClientVersion.set(it)
}
}
Time to test
Run the following task to get a GSQL prompt to appear:
gradle gS --console=plain
If everything was configured correctly you should be able to see “Welcome to TigerGraph”
Conclusion
At this point you have a fully functional TigerGraph project build that allows you to:
- Abstract your important credentials and properties
- Co-develop by pushing your code to a git-repository
- Execute GSQL commands on the server