From f4bbb267ab082b7e31c4cb185d5c8430c000e646 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Thu, 11 May 2017 17:45:23 +0200 Subject: [PATCH] library/roles/smartgears/smartgears/templates/get-scopes.j2: Fix the case when we are upgrading but we cannot get the state from the IS. In that case, we request new tokens to the IS. --- smartgears/smartgears/templates/get-scopes.j2 | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/smartgears/smartgears/templates/get-scopes.j2 b/smartgears/smartgears/templates/get-scopes.j2 index c8d4271d..3976db97 100644 --- a/smartgears/smartgears/templates/get-scopes.j2 +++ b/smartgears/smartgears/templates/get-scopes.j2 @@ -65,14 +65,11 @@ HTTP_PORT={{ item.http_port }} {% endif %} {% endif %} -if [ $USE_SAVED_STATE -ne 0 ] ; then - logger "$LOG_PREFIX First installation or moving avay to a configuration that needs to be present on all the VREs. Using our scopes list and not the state memorized one" +function get_scopes_from_auth() { for jar in $( ls -1 /home/gcube/tomcat/lib/ ) ; do export CLASSPATH="/home/gcube/SmartGears/lib/${jar}:$CLASSPATH" done - cd $LOCAL_LIB - java TokenGenerator {{ smartgears_hostname }} $TOKEN $HTTP_PORT $SCOPES_FILE $SCOPES_LIST >/dev/null 2>&1 RETVAL=$? if [ $RETVAL -eq 0 ] ; then @@ -81,6 +78,11 @@ if [ $USE_SAVED_STATE -ne 0 ] ; then logger "$LOG_PREFIX Unable to obtain the scope tokens, aborting" exit 1 fi +} + +if [ $USE_SAVED_STATE -ne 0 ] ; then + logger "$LOG_PREFIX First installation or moving avay to a configuration that needs to be present on all the VREs. Using our scopes list and not the state memorized one" + get_scopes_from_auth else logger "$LOG_PREFIX We are going to use the scopes memorized into the state" SCOPES_FILE=$SMARTGEARS_SAVED_STATE_PATH @@ -90,6 +92,13 @@ fi cd $SMARTGEARS_SCRIPTS_DIR . $GHN_ENV_FILE ./clean-container-state -s $SMARTGEARS_SAVED_STATE_F +RETVAL=$? +if [ $RETVAL -ne 0 ] ; then + # We were not able to get the running state from the IS. We get new ones + logger "$LOG_PREFIX We were not able to get the running state from the IS. We get new ones from the authorization service" + SCOPES_FILE={{ smartgears_user_home }}/.containerxml/2-container.xml + get_scopes_from_auth +fi # Now that we have the tokens, we can assemble the container.xml file