Tutorial: Run a data pipeline using Jet
Learn how to run a data pipeline in Hazelcast using Jet.
Overview
In this tutorial, you'll:
- Build and deploy a custom Jet pipeline implementation to cloud storage.
- Deploy Hazelcast with the Jet engine configured.
- Start the Jet pipeline.
- Check the Jet pipeline.
- Cancel the Jet pipeline.
The tutorial should take approximately 20 minutes to complete.
Prerequisites
Before you begin, make sure that you have:
- A running Kubernetes cluster.
- The Kubernetes command line tool, kubectl.
- The Maven command line tool, mvn.
- Deployed Hazelcast Platform Operator.
- The Hazelcast Code Samples repository https://github.com/hazelcast/hazelcast-code-samples cloned to your local machine.
- Blob storage and access credentials on one of the following cloud providers: AWS, GCP, Azure.
Deploy the Jet pipeline JAR to cloud storage
In this step, you'll build the Jet pipeline JAR from the tutorial's GitHub repository, and upload it to your cloud provider.
-
Clone the sample project.
- HTTPS
- SSH
bashgit clone https://github.com/hazelcast-guides/hazelcast-platform-operator-jet.gitcd hazelcast-platform-operator-jetbashcd hazelcast-platform-operator-jetThe sample code for this tutorial is in the
jet-pipeline/src/main/java/org/example/run/directory. -
Build the Jet pipeline JAR.
shellmvn package -f ./jet-pipeline -
Upload the Jet pipeline JAR to the storage blob/bucket of your cloud provider, replacing the placeholder values.
- S3
- GCS
- ABS
bashaws s3 cp jet-pipeline/target/jet-pipeline-run-1.0.0.jar s3://<BUCKET_NAME>bashgsutil cp jet-pipeline/target/jet-pipeline-run-1.0.0.jar gs://<BUCKET_NAME>bashaz storage blob upload --account-name <ACCOUNT_NAME> --container-name <CONTAINER_NAME> --file jet-pipeline/target/jet-pipeline-run-1.0.0.jar -
Create a secret for your cloud storage.
- AWS
- GCP
- Azure
bashkubectl create secret generic <SECRET-NAME> --from-literal=region=<region> \--from-literal=access-key-id=<access-key-id> \--from-literal=secret-access-key=<secret-access-key>bashkubectl create secret generic <SECRET-NAME> --from-file=google-credentials-path=<service_account_json_file>bashkubectl create secret generic <SECRET-NAME> \--from-literal=storage-account=<storage-account> \--from-literal=storage-key=<storage-key>
If you want to learn more about other authentication methods, see Authorization Methods to Access Cloud Storage.
Start the Hazelcast cluster
-
Create a secret with your Hazelcast Enterprise License.
shellkubectl create secret generic hazelcast-license-key --from-literal=license-key=<hz-license-key> -
Create a Hazelcast cluster with the Jet engine configured.
shellkubectl apply -f - <<EOFapiVersion: hazelcast.com/v1alpha1kind: Hazelcastmetadata:name: my-hazelcastspec:licenseKeySecretName: hazelcast-license-keyclusterSize: 3jet:resourceUploadEnabled: trueEOFnoteYou need to use Hazelcast 5.3 or above to submit Jet jobs with Operator.
-
Check the cluster status to make sure that it's up and running.
shellkubectl get hazelcast my-hazelcastNAME STATUS MEMBERSmy-hazelcast Running 3/3
Run the data pipeline
In this step, you'll start, check and cancel the Jet job that runs the data pipeline.
-
Start the Jet job you have already deployed:
Replace the <BUCKET-URI> with the appropriate sample bucket URI for your cloud provider:
- s3://hazelcast-jet-pipeline
- gs://hazelcast-jet-pipeline
- azblob://hazelcast-jet-pipeline
shellkubectl apply -f - <<EOFapiVersion: hazelcast.com/v1alpha1kind: JetJobmetadata:name: my-jet-jobspec:hazelcastResourceName: my-hazelcaststate: RunningjarName: jet-pipeline-run-1.0.0.jarbucketConfig:bucketURI: "<BUCKET-URI>"secretName: <SECRET-NAME>EOF -
Check status of the Jet job.
bashkubectl get jetjob my-jet-job -wThe output will look something like this. Wait until the
Runningstatus appears.bashNAME STATUS ID SUBMISSIONTIME COMPLETIONTIMEmy-jet-job Starting 0my-jet-job Running 732187341048774657 2023-07-14T10:51:06Z -
Check the output of the Jet pipeline in the logs:
bashkubectl logs -l app.kubernetes.io/name=hazelcast -c hazelcast | grep sequenceThe logs of the Jet pipeline are displayed in the output.
bash{"time":"2023-07-14T10:51:06,679", "logger": "com.hazelcast.jet.impl.connector.WriteLoggerP", "level": "INFO", "msg": "[172.17.0.6]:5702 [dev] [5.3.1] [my-jet-job/loggerSink#0] SimpleEvent(timestamp=10:51:06.000, sequence=0) "}{"time":"2023-07-14T10:51:07,675", "logger": "com.hazelcast.jet.impl.connector.WriteLoggerP", "level": "INFO", "msg": "[172.17.0.6]:5702 [dev] [5.3.1] [my-jet-job/loggerSink#0] SimpleEvent(timestamp=10:51:07.000, sequence=1) "}{"time":"2023-07-14T10:51:08,681", "logger": "com.hazelcast.jet.impl.connector.WriteLoggerP", "level": "INFO", "msg": "[172.17.0.6]:5702 [dev] [5.3.1] [my-jet-job/loggerSink#0] SimpleEvent(timestamp=10:51:08.000, sequence=2) "}{"time":"2023-07-14T10:51:09,679", "logger": "com.hazelcast.jet.impl.connector.WriteLoggerP", "level": "INFO", "msg": "[172.17.0.6]:5702 [dev] [5.3.1] [my-jet-job/loggerSink#0] SimpleEvent(timestamp=10:51:09.000, sequence=3) "}{"time":"2023-07-14T10:51:10,682", "logger": "com.hazelcast.jet.impl.connector.WriteLoggerP", "level": "INFO", "msg": "[172.17.0.6]:5702 [dev] [5.3.1] [my-jet-job/loggerSink#0] SimpleEvent(timestamp=10:51:10.000, sequence=4) "}{"time":"2023-07-14T10:51:11,678", "logger": "com.hazelcast.jet.impl.connector.WriteLoggerP", "level": "INFO", "msg": "[172.17.0.6]:5702 [dev] [5.3.1] [my-jet-job/loggerSink#0] SimpleEvent(timestamp=10:51:11.000, sequence=5) "}{"time":"2023-07-14T10:51:12,677", "logger": "com.hazelcast.jet.impl.connector.WriteLoggerP", "level": "INFO", "msg": "[172.17.0.6]:5702 [dev] [5.3.1] [my-jet-job/loggerSink#0] SimpleEvent(timestamp=10:51:12.000, sequence=6) "}........ -
Cancel the Jet job by setting the
spec.statetoCanceled. Use one of the following options.-
Cancel the Jet job using
kubectl apply:shellkubectl apply -f - <<EOFapiVersion: hazelcast.com/v1alpha1kind: JetJobmetadata:name: my-jet-jobspec:hazelcastResourceName: my-hazelcaststate: CanceledjarName: jet-pipeline-run-1.0.0.jarbucketConfig:bucketURI: "<BUCKET-URI>"secretName: <SECRET-NAME>EOF -
Cancel the Jet job using
kubectl patch:bashkubectl patch jetjob my-jet-job -p '{"spec":{"state":"Canceled"}}' --type=merge
-
-
Check the Jet job status to make sure the job was cancelled.
bashkubectl get jetjob my-jet-jobThe output shows the Jet job status as
ExecutionFailed.bashNAME STATUS ID SUBMISSIONTIME COMPLETIONTIMEmy-jet-job ExecutionFailed 732229926463209474 2023-07-14T13:40:19Z 2023-07-14T14:07:51Z -
See a more detailed message for the status of the Jet job:
bashkubectl get jetjob my-jet-job -o custom-columns=:.status.failureTextThe failure text appears in the output.
bashcom.hazelcast.jet.impl.exception.CancellationByUserExceptionat com.hazelcast.jet.impl.MasterJobContext.createCancellationException(MasterJobContext.java:211)at com.hazelcast.jet.impl.MasterJobContext.getErrorFromResponses(MasterJobContext.java:653)at com.hazelcast.jet.impl.MasterJobContext.lambda$invokeStartExecution$12(MasterJobContext.java:576)at com.hazelcast.jet.impl.MasterContext.lambda$invokeOnParticipant$3(MasterContext.java:376)........
Clean up
To clean up all the resources you created during the tutorial, and to remove the custom resources and secrets, run the following command:
kubectl delete secret <SECRET-NAME>
kubectl delete $(kubectl get hazelcast -o name)
Deleting the Hazelcast CR also deletes the Jet jobs linked to it.
Summary
In this tutorial, you learned how to:
- Build and deploy a custom Jet pipeline implementation to cloud storage.
- Deploy Hazelcast with the Jet engine configured.
- Start a Jet pipeline.
- Check a Jet pipeline.
- Cancel a Jet pipeline.
Next steps
See also: