Prerequisites:

  • Have JetStream user privileges.
  • Know the branch you would like to create the bookmark on.
  • Know the container or template that branch belongs to.
  • (Optional) Know when you would like the bookmark to expire.

Jet Stream administrators can use this CLI cookbook recipe to create a bookmark on Jet Stream using the Delphix Engine CLI.

 
The following script is for educational and demonstration purposes only and is not supported by Delphix.

This script can be downloaded by selecting createBookmark.sh.

Creating a bookmark in Jet Stream

#!/bin/bash

# A sample script for calls to the CLI. This one creates a Jet Stream bookmark.
#
# VERY IMPORTANT: In order for this to work, you need to go through the steps here:
# https://docs.delphix.com/display/DOCS43/CLI+Cookbook%3A+Configuring+Key-Based+SSH+Authentication+for+Automation
# After this you will not need to use a username and password to log into the delphix engine. If you do not
# setup the SSH authentication you will have to manually enter the password.
#

##example##
#./createBookmark.sh -p "bookmark test" -e "2016-07-27T23:38:56.453Z" -t "2016-07-27T01:45:56.453Z" -T [tag1,tag2,tag3,tag4,tag5] bkmrk3 JS_BRANCH-41

##### Constants

# Describes a Delphix software revision.
VERSION="1.6.2"

##### Default Values. These can be overwriten with optional arguments.
engine="10.0.1.10"
username="dev"

##### Functions

# Help Menu
function usage {
echo "Usage: createBookmark.sh [[-h] | options...] <bookmark name> <branch name format JS_BRANCH-n>"
echo "Create a Jet Stream Bookmark on the given branch."
echo ""
echo "Positional arguments"
echo " <bookmark name> "
echo " <branch name>"
echo ""
echo "Optional Arguments:"
echo " -h Show this message and exit"
echo " -d Delphix engine IP address or host name, otherwise revert to default"
echo " -u Server user. Password needs to manually provide at run time, otherwise revert to default"
echo " -D Description of this bookmark. Type: string"
echo " -s Pass [-s true] if need to make bookmark in shared mode"
echo " -t The time at which the bookmark should be created. If no time is included, the bookmark will be created at the latest point in time. Type: date, must be in ISO 8601 extended format [yyyy]-[MM]-[dd]T[HH]:[mm]:[ss].[SSS]Z"
echo " -T A set of user-defined labels for this bookmark. No spaces allowed. Array of Type: string. In format, [tag1,tag2,..] "
}

# Create Our Session, including establishing the API version.
function create_session
{
echo "creating session..."
SSH_CMD="ssh ${username}@${engine}"
${SSH_CMD} "version $VERSION"
check_result
}

# Check the result of the curl. If there are problems, inform the user then exit.
function check_result
{
exitStatus=$?
if [ $exitStatus -ne 0 ]
then
echo "command failed with exit status $exitStatus"
echo $result 
exit 1
fi
}

function get_branch
{
echo "retrieveing branch $branchRef to find Source Data Layout..."
result=$(${SSH_CMD} "jetstream branch; ls; select ${branchRef}; ls")

# Get everything in the result that comes after dataLayout.
temp=${result#*dataLayout: }

# Get rid of everything after
dataLayout=${temp%% *}

}

function create_bookmark
{ 
get_branch

echo "creating bookmark..."

# If there is not creation time, we need to use JSTimelinePointLatestTimeInput.
if [ -z $creationTime ]
then
pointParams="set timelinePointParameters.sourceDataLayout=$dataLayout;"
pointParams="$pointParams set timelinePointParameters.type=JSTimelinePointLatestTimeInput;"
else
pointParams="set timelinePointParameters.sourceDataLayout=$dataLayout;"
pointParams="$pointParams set timelinePointParameters.type=JSTimelinePointTimeInput;"
pointParams="$pointParams set timelinePointParameters.time=\"$creationTime\";"
fi

# These are the required parameters.
paramString="
\"bookmark\": {
\"branch\": \"${branchRef}\", 
\"name\": \"${bookmarkName}\","
paramString="jetstream bookmark; create; set bookmark.name=$bookmarkName; set bookmark.branch=$branchRef;"
paramString="$paramString $pointParams"

# Fill in optional parameters if there are any.
if [[ -n $description ]]
then
paramString="$paramString set bookmark.description=\"$description\";"
fi

if [[ -n $shared ]]
then
paramString="$paramString set bookmark.shared=$shared;"
fi

if [[ -n $tags ]]
then
# Add quotes back to the passed in tags so they are processed correctly.
tags=${tags//[/[\"}
tags=${tags//,/\",\"}
tags=${tags//]/\"]}

paramString="$paramString set bookmark.tags=$tags;"
fi
paramString="$paramString commit;"
result=$(${SSH_CMD} $paramString)
check_result
echo "Verifying job status..."
# Get everything in the result that comes after job.
temp=${result#*job}
# Get rid of everything after 
resultArray=($temp)
jobRef=($resultArray)
jobString="job;select $jobRef;ls"
result=$(${SSH_CMD} $jobString)
check_result
# Get everything in the result that comes after job.
temp=${result#*jobState:}
# Get rid of everything after
resultArray=($temp)
jobState=($resultArray)

if [ $jobState = "COMPLETED" ]
then
echo "successfully created bookmark $bookmarkName"
else
echo "unable to create bookmark"
echo result
fi

}

##### Main

while getopts "u:d:D:s:t:T:h" flag; do
case "$flag" in
u ) username=${OPTARG%:*}
;;
d ) engine=$OPTARG
;;
D ) description=$OPTARG
;;
s ) shared=true
;;
t ) creationTime=$OPTARG
;;
T ) tags=$OPTARG
;;
h ) usage
exit
;;
* ) usage
exit 1
esac
done

# Shift the parameters so we only have the positional arguments left
shift $((OPTIND-1))

# Check that there are 2 positional arguments
if [ $# != 2 ]
then
usage
exit 1
fi

# Get the two positional arguments
bookmarkName=$1
shift
branchRef=$1
create_session
create_bookmark