Skip to content

Commit

Permalink
Merge pull request #3748 from LBNL-UCB-STI/inm/gcp-running-jupyter-bu…
Browse files Browse the repository at this point in the history
…gfix

GCP: running jupyter bugfixes
  • Loading branch information
nikolayilyin authored May 10, 2023
2 parents 9dcf153 + d650b3c commit 910538e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
6 changes: 3 additions & 3 deletions gcp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ tasks.register('deployToGCE') {
}

tasks.register("jupyterGCE") {
doLast {
doFirst {
project.ext."runJupyter" = "true"
project.ext."runBeam" = "false"
project.ext."beamConfigs" = ""
Expand All @@ -88,11 +88,11 @@ tasks.register("jupyterGCE") {
if (!project.hasProperty("shutdownBehaviour")) {
project.ext."shutdownBehaviour" = "stop"
}

dependsOn ':gcp:deployToGCE'
}
}

jupyterGCE.finalizedBy(deployToGCE)

static HttpResponse makeJsonPostRequest(String functionUrl, String requestBody) {
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault();
IdTokenCredentials tokenCredential =
Expand Down
29 changes: 19 additions & 10 deletions gcp/src/main/bash/cloud-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,36 +123,39 @@ EOF
echo "$start_json"
curl -X POST "https://ca4ircx74d.execute-api.us-east-2.amazonaws.com/production/spreadsheet" -H "Content-Type:application/json" --data "$start_json"

set -x

./gradlew assemble

if [ "${RUN_JUPYTER,,}" = "true" ]; then

echo "Running Jupyter"
export GOOGLE_API_KEY="$GOOGLE_API_KEY"

set -x
if [ -n "$JUPYTER_TOKEN" ] && [ -n "$JUPYTER_IMAGE" ]
then sudo ./gradlew jupyterStart -Puser=root -PjupyterToken="$JUPYTER_TOKEN" -PjupyterImage="$JUPYTER_IMAGE"
then ./gradlew jupyterStart -Puser=root -PjupyterToken="$JUPYTER_TOKEN" -PjupyterImage="$JUPYTER_IMAGE"
elif [ -n "$JUPYTER_TOKEN" ]
then sudo ./gradlew jupyterStart -Puser=root -PjupyterToken="$JUPYTER_TOKEN"
then ./gradlew jupyterStart -Puser=root -PjupyterToken="$JUPYTER_TOKEN"
elif [ -n "$JUPYTER_IMAGE" ]
then sudo ./gradlew jupyterStart -Puser=root -PjupyterImage="$JUPYTER_IMAGE"
else sudo ./gradlew jupyterStart -Puser=root
then ./gradlew jupyterStart -Puser=root -PjupyterImage="$JUPYTER_IMAGE"
else ./gradlew jupyterStart -Puser=root
fi
set +x

# somehow there are not enough permissions for gradle lock file if jupyter was run before
sudo chmod -R 777 .
else
echo "NOT going to start jupyter. [RUN_JUPYTER ('${RUN_JUPYTER,,}') not equal to 'true']"
fi


if [ "${RUN_BEAM,,}" = "true" ]; then
echo "Running BEAM"
export GOOGLE_API_KEY="$GOOGLE_API_KEY"

./gradlew --stacktrace :run -PappArgs="['--config', '$BEAM_CONFIG']" -PmaxRAM="$MAX_RAM"g
else
echo "NOT going to start BEAM. [RUN_BEAM ('${RUN_BEAM,,}') not equal to 'true']"
fi

set +x

# copy to bucket
storage_url=""
Expand Down Expand Up @@ -194,16 +197,22 @@ if [ -d "$finalPath" ]; then
health_metrics="$health_metrics, $metric:$count"
done < $simulation_health_analysis_output_file
health_metrics="{$(echo "$health_metrics" | cut -c3-)}"
echo "$health_metrics"
echo "Health Metrics: $health_metrics"
if [ "${STORAGE_PUBLISH,,}" != "false" ]; then
gsutil cp "$simulation_health_analysis_output_file" "gs://beam-core-outputs/$finalPath/$simulation_health_analysis_output_file"
fi
curl -H "Authorization:Bearer $SLACK_TOKEN" -F file=@$simulation_health_analysis_output_file -F initial_comment="Beam Health Analysis" -F channels="$SLACK_CHANNEL" "https://slack.com/api/files.upload"
fi


if [ "${RUN_BEAM,,}" != "true" ] && [ "${RUN_JUPYTER,,}" = "true" ]; then
final_status="Jupyter Instance"
else
final_status=$(check_simulation_result)
fi


#Slack message
final_status=$(check_simulation_result)
bye_msg=$(cat <<EOF
Run Completed
Run Name **$RUN_NAME**
Expand Down
1 change: 1 addition & 0 deletions gcp/src/main/python/deploy_beam/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def create_beam_instance(request):
startup_script = """
#!/bin/sh
CLOUD_INIT_SCRIPT_URL=$(curl http://metadata/computeMetadata/v1/instance/attributes/cloud_init_script_url -H "Metadata-Flavor: Google")
sudo chown -R clu:clu /home/clu
sudo -u clu bash -c "cd; wget $CLOUD_INIT_SCRIPT_URL"
sudo -u clu bash -c "cd; chmod 755 cloud-init.sh"
sudo -u clu bash -c "cd; ./cloud-init.sh &> cloud-init-output.log"
Expand Down

0 comments on commit 910538e

Please sign in to comment.