@@ -1214,23 +1214,31 @@ setup_zen_core_service_connection(){
12141214 WATSON_GATEWAY_ENDPOINT=" https://${WATSON_GATEWAY_SERVICE} :${WATSON_GATEWAY_PORT} "
12151215}
12161216
1217+ get_zen_access_pod () {
1218+ echo " $( oc get pods ${OC_ARGS} -o jsonpath=" {.items[0].metadata.name}" -l app.kubernetes.io/component=wd-backup-restore) "
1219+ }
1220+
12171221create_backup_instance_mappings (){
12181222 brlog " INFO" " Creating instance mapping file"
1223+ launch_utils_job " wd-backup-restore-util-job"
1224+ get_job_pod " app.kubernetes.io/component=wd-backup-restore"
1225+ wait_job_running ${POD}
12191226 local mapping_file=" ${MAPPING_FILE:- ${BACKUP_DIR} / instance_mapping.json} "
12201227 local wd_version=" ${WD_VERSION:- $(get_version)} "
12211228 setup_zen_core_service_connection
1222- ELASTIC_POD =$( get_elastic_pod )
1223- token=$( fetch_cmd_result ${ELASTIC_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /internal/v1/service_token?expiration_time=1000' -H 'secret: ${ZEN_CORE_TOKEN} ' -H 'cache-control: no-cache' | jq -r .token" -c elasticsearch )
1229+ ZEN_ACCESS_POD =$( get_zen_access_pod )
1230+ token=$( fetch_cmd_result ${ZEN_ACCESS_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /internal/v1/service_token?expiration_time=1000' -H 'secret: ${ZEN_CORE_TOKEN} ' -H 'cache-control: no-cache' | jq -r .token" )
12241231 if [ $( compare_version ${wd_version} " 4.0.9" ) -le 0 ] ; then
1225- mappings=$( fetch_cmd_result ${ELASTIC_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /v2/serviceInstance' -H 'Authorization: Bearer ${token} ' | jq -r '.requestObj[] | select(.ServiceInstanceType == \" discovery\" and .ProvisionStatus == \" PROVISIONED\" ) | { \" display_name\" : .ServiceInstanceDisplayName, \" source_instance_id\" : .CreateArguments.metadata.instanceId, \" dest_instance_id\" : \" <new_instance_id>\" }' | jq -s '{\" instance_mappings\" : .}'" -c elasticsearch )
1232+ mappings=$( fetch_cmd_result ${ZEN_ACCESS_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /v2/serviceInstance' -H 'Authorization: Bearer ${token} ' | jq -r '.requestObj[] | select(.ServiceInstanceType == \" discovery\" and .ProvisionStatus == \" PROVISIONED\" ) | { \" display_name\" : .ServiceInstanceDisplayName, \" source_instance_id\" : .CreateArguments.metadata.instanceId, \" dest_instance_id\" : \" <new_instance_id>\" }' | jq -s '{\" instance_mappings\" : .}'" )
12261233 else
1227- mappings=$( fetch_cmd_result ${ELASTIC_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /v3/service_instances?fetch_all_instances=true' -H 'Authorization: Bearer ${token} ' | jq -r '.service_instances | if (. | length != 0) and (map(.addon_type == \" discovery\" and .provision_status == \" PROVISIONED\" ) | any) then .[] | select(.addon_type == \" discovery\" and .provision_status == \" PROVISIONED\" ) | { \" display_name\" : .display_name, \" source_instance_id\" : .id, \" dest_instance_id\" : \" <new_instance_id>\" } else \" null\" end' | jq -s '{\" instance_mappings\" : .}'" -c elasticsearch )
1234+ mappings=$( fetch_cmd_result ${ZEN_ACCESS_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /v3/service_instances?fetch_all_instances=true&addon_type=discovery ' -H 'Authorization: Bearer ${token} ' | jq -r '.service_instances | if (. | length != 0) and (map(.addon_type == \" discovery\" and .provision_status == \" PROVISIONED\" ) | any) then .[] | select(.addon_type == \" discovery\" and .provision_status == \" PROVISIONED\" ) | { \" display_name\" : .display_name, \" source_instance_id\" : .id, \" dest_instance_id\" : \" <new_instance_id>\" } else \" null\" end' | jq -s '{\" instance_mappings\" : .}'" )
12281235 fi
12291236 if [ -z " ${mappings} " ] || echo " ${mappings} " | grep " null" > /dev/null || echo " ${mappings} " | grep " \[\]" > /dev/null ; then
12301237 brlog " ERROR" " Failed to get instances with CP4D API"
12311238 exit 1
12321239 fi
12331240 echo " ${mappings} " > ${mapping_file}
1241+ oc ${OC_ARGS} delete job wd-backup-restore-util-job
12341242 brlog " INFO" " Instance mapping file: ${mapping_file} "
12351243}
12361244
@@ -1240,13 +1248,13 @@ create_restore_instance_mappings(){
12401248 local rc=0
12411249 local mapping=' { "instance_mappings" : []}'
12421250 setup_zen_core_service_connection
1243- ELASTIC_POD =$( get_elastic_pod )
1244- _oc_cp " ${MAPPING_FILE} " " ${ELASTIC_POD } :/tmp/mapping.json" -c elasticsearch
1245- local token=$( fetch_cmd_result ${ELASTIC_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /internal/v1/service_token?expiration_time=1000' -H 'secret: ${ZEN_CORE_TOKEN} ' -H 'cache-control: no-cache' | jq -r .token" -c elasticsearch )
1246- local service_instances=$( fetch_cmd_result ${ELASTIC_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /v3/service_instances?fetch_all_instances=true' -H 'Authorization: Bearer ${token} ' | jq -r '${service_instance_query} '" -c elasticsearch )
1251+ ZEN_ACCESS_POD =$( get_zen_access_pod )
1252+ _oc_cp " ${MAPPING_FILE} " " ${ZEN_ACCESS_POD } :/tmp/mapping.json"
1253+ local token=$( fetch_cmd_result ${ZEN_ACCESS_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /internal/v1/service_token?expiration_time=1000' -H 'secret: ${ZEN_CORE_TOKEN} ' -H 'cache-control: no-cache' | jq -r .token" )
1254+ local service_instances=$( fetch_cmd_result ${ZEN_ACCESS_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /v3/service_instances?fetch_all_instances=true&addon_type=discovery ' -H 'Authorization: Bearer ${token} ' | jq -r '${service_instance_query} '" )
12471255 if [ -n " ${service_instances} " ] && [ " ${service_instances} " != " null" ] ; then
12481256 brlog " INFO" " Discovery instances exist. Check if they are same instance."
1249- local src_instances=$( fetch_cmd_result ${ELASTIC_POD } " jq -r '.instance_mappings[].source_instance_id' /tmp/mapping.json" -c elasticsearch )
1257+ local src_instances=$( fetch_cmd_result ${ZEN_ACCESS_POD } " jq -r '.instance_mappings[].source_instance_id' /tmp/mapping.json" )
12501258 len1=( ${service_instances} )
12511259 len2=( ${src_instances} )
12521260 if [ ${# len1[@]} -ne ${# len2[@]} ] ; then
@@ -1256,16 +1264,16 @@ create_restore_instance_mappings(){
12561264 for instance in ${src_instances}
12571265 do
12581266 if echo " ${service_instances} " | grep " ${instance} " > /dev/null ; then
1259- mapping=$( fetch_cmd_result ${ELASTIC_POD } " echo '${mapping} ' | jq -r '.instance_mappings |= . + [{\" source_instance_id\" : \" ${instance} \" , \" dest_instance_id\" : \" ${instance} \" }]'" )
1267+ mapping=$( fetch_cmd_result ${ZEN_ACCESS_POD } " echo '${mapping} ' | jq -r '.instance_mappings |= . + [{\" source_instance_id\" : \" ${instance} \" , \" dest_instance_id\" : \" ${instance} \" }]'" )
12601268 else
12611269 brlog " ERROR" " Instance ${instance} does not exist. Please create instance mapping, and specify it with '--mapping' option."
12621270 return 1
12631271 fi
12641272 done
12651273 else
12661274 brlog " INFO" " No Discovery instance exist. Create new one."
1267- local src_instances=( $( fetch_cmd_result ${ELASTIC_POD } " jq -r '.instance_mappings[].source_instance_id' /tmp/mapping.json" -c elasticsearch ) )
1268- local display_names=( $( fetch_cmd_result ${ELASTIC_POD } " jq -r '.instance_mappings[].display_name' /tmp/mapping.json" -c elasticsearch ) )
1275+ local src_instances=( $( fetch_cmd_result ${ZEN_ACCESS_POD } " jq -r '.instance_mappings[].source_instance_id' /tmp/mapping.json" ) )
1276+ local display_names=( $( fetch_cmd_result ${ZEN_ACCESS_POD } " jq -r '.instance_mappings[].display_name' /tmp/mapping.json" ) )
12691277 for i in " ${! src_instances[@]} "
12701278 do
12711279 instance_id=$( create_service_instance " ${display_names[$i]} " )
@@ -1274,7 +1282,7 @@ create_restore_instance_mappings(){
12741282 return 1
12751283 else
12761284 brlog " INFO" " Created Discovery service instance: ${instance_id} "
1277- mapping=$( fetch_cmd_result ${ELASTIC_POD } " echo '${mapping} ' | jq -r '.instance_mappings |= . + [{\" source_instance_id\" : \" ${src_instances[$i]} \" , \" dest_instance_id\" : \" ${instance_id} \" }]'" -c elasticsearch )
1285+ mapping=$( fetch_cmd_result ${ZEN_ACCESS_POD } " echo '${mapping} ' | jq -r '.instance_mappings |= . + [{\" source_instance_id\" : \" ${src_instances[$i]} \" , \" dest_instance_id\" : \" ${instance_id} \" }]'" )
12781286 fi
12791287 done
12801288 fi
@@ -1298,12 +1306,12 @@ check_instance_mappings(){
12981306 return 1
12991307 fi
13001308 setup_zen_core_service_connection
1301- ELASTIC_POD =$( get_elastic_pod )
1309+ ZEN_ACCESS_POD =$( get_zen_access_pod )
13021310 local file_name=" $( basename " ${MAPPING_FILE} " ) "
1303- _oc_cp " ${MAPPING_FILE} " " ${ELASTIC_POD } :/tmp/mapping.json" -c elasticsearch
1304- local token=$( fetch_cmd_result ${ELASTIC_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /internal/v1/service_token?expiration_time=1000' -H 'secret: ${ZEN_CORE_TOKEN} ' -H 'cache-control: no-cache' | jq -r .token" -c elasticsearch )
1305- local service_instances=$( fetch_cmd_result ${ELASTIC_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /v3/service_instances?fetch_all_instances=true' -H 'Authorization: Bearer ${token} ' | jq -r '${service_instance_query} '" -c elasticsearch )
1306- local dest_instances=$( fetch_cmd_result ${ELASTIC_POD } " jq -r '.instance_mappings[].dest_instance_id' /tmp/mapping.json" -c elasticsearch )
1311+ _oc_cp " ${MAPPING_FILE} " " ${ZEN_ACCESS_POD } :/tmp/mapping.json"
1312+ local token=$( fetch_cmd_result ${ZEN_ACCESS_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /internal/v1/service_token?expiration_time=1000' -H 'secret: ${ZEN_CORE_TOKEN} ' -H 'cache-control: no-cache' | jq -r .token" )
1313+ local service_instances=$( fetch_cmd_result ${ZEN_ACCESS_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /v3/service_instances?fetch_all_instances=true&addon_type=discovery ' -H 'Authorization: Bearer ${token} ' | jq -r '${service_instance_query} '" )
1314+ local dest_instances=$( fetch_cmd_result ${ZEN_ACCESS_POD } " jq -r '.instance_mappings[].dest_instance_id' /tmp/mapping.json" )
13071315 for instance in ${dest_instances}
13081316 do
13091317 if ! echo " ${service_instances} " | grep " ${instance} " > /dev/null ; then
@@ -1343,9 +1351,9 @@ require_tenant_backup(){
13431351
13441352check_instance_exists (){
13451353 setup_zen_core_service_connection
1346- ELASTIC_POD= ${ELASTIC_POD :- $(get_elastic_pod)}
1347- local token=" $( fetch_cmd_result ${ELASTIC_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /internal/v1/service_token?expiration_time=1000' -H 'secret: ${ZEN_CORE_TOKEN} ' -H 'cache-control: no-cache' | jq -r .token" -c elasticsearch ) "
1348- local service_instances=$( fetch_cmd_result ${ELASTIC_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /v3/service_instances?fetch_all_instances=true' -H 'Authorization: Bearer ${token} ' | jq -r '${service_instance_query} '" -c elasticsearch )
1354+ ZEN_ACCESS_POD= $( get_zen_access_pod )
1355+ local token=" $( fetch_cmd_result ${ZEN_ACCESS_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /internal/v1/service_token?expiration_time=1000' -H 'secret: ${ZEN_CORE_TOKEN} ' -H 'cache-control: no-cache' | jq -r .token" ) "
1356+ local service_instances=$( fetch_cmd_result ${ZEN_ACCESS_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /v3/service_instances?fetch_all_instances=true&addon_type=discovery ' -H 'Authorization: Bearer ${token} ' | jq -r '${service_instance_query} '" )
13491357 if [ -n " ${service_instances} " ] && [ " ${service_instances} " != " null" ] ; then
13501358 return 0
13511359 else
@@ -1355,7 +1363,7 @@ check_instance_exists(){
13551363
13561364create_service_instance (){
13571365 setup_zen_core_service_connection
1358- ELASTIC_POD= ${ELASTIC_POD :- $(get_elastic_pod)}
1366+ ZEN_ACCESS_POD= $( get_zen_access_pod )
13591367 local display_name=$1
13601368 local namespace=${NAMESPACE:- $(oc config view --minify --output ' jsonpath={..namespace}' )}
13611369 local request_file=" ${SCRIPT_DIR} /src/create_service_instance.json"
@@ -1366,7 +1374,7 @@ create_service_instance(){
13661374 -e " s/#instance#/${TENANT_NAME} /g" \
13671375 -e " s/#display_name#/${display_name} /g" \
13681376 " ${template} " > " ${request_file} "
1369- _oc_cp " ${request_file} " " ${ELASTIC_POD } :/tmp/request.json" -c elasticsearch
1377+ _oc_cp " ${request_file} " " ${ZEN_ACCESS_POD } :/tmp/request.json"
13701378 if [ -z " ${ZEN_USER_NAME+UNDEF} " ] ; then
13711379 brlog " WARN" " '--cp4d-user-name' option is not provided. Use default admin user to create Discovery instance" >&2
13721380 iam_secret=" $( oc get ${OC_ARGS} secret/ibm-iam-bindinfo-platform-auth-idp-credentials --ignore-not-found -o jsonpath=' {.metadata.name}' ) "
@@ -1379,12 +1387,12 @@ create_service_instance(){
13791387 fi
13801388 if [ -z " ${ZEN_UID+UNDEF} " ] ; then
13811389 brlog " INFO" " Get CP4D user ID for ${ZEN_USER_NAME} " >&2
1382- token=" $( fetch_cmd_result ${ELASTIC_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /internal/v1/service_token?expiration_time=1000' -H 'secret: ${ZEN_CORE_TOKEN} ' -H 'cache-control: no-cache' | jq -r .token" -c elasticsearch ) "
1383- ZEN_UID=" $( fetch_cmd_result ${ELASTIC_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /openapi/v1/users/${ZEN_USER_NAME} ' -H 'Authorization: Bearer ${token} ' | jq -r '.UserInfo.uid'" -c elasticsearch ) "
1390+ token=" $( fetch_cmd_result ${ZEN_ACCESS_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /internal/v1/service_token?expiration_time=1000' -H 'secret: ${ZEN_CORE_TOKEN} ' -H 'cache-control: no-cache' | jq -r .token" ) "
1391+ ZEN_UID=" $( fetch_cmd_result ${ZEN_ACCESS_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /openapi/v1/users/${ZEN_USER_NAME} ' -H 'Authorization: Bearer ${token} ' | jq -r '.UserInfo.uid'" ) "
13841392 fi
13851393 brlog " INFO" " Create Discovery instance as ${ZEN_USER_NAME} :${ZEN_UID} " >&2
1386- local token=$( fetch_cmd_result ${ELASTIC_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /internal/v1/service_token?uid=${ZEN_UID} &username=${ZEN_USER_NAME} &display_name=${ZEN_USER_NAME} ' -H 'secret: ${ZEN_CORE_TOKEN} ' -H 'cache-control: no-cache' | jq -r .token" -c elasticsearch )
1387- local instance_id=$( fetch_cmd_result ${ELASTIC_POD } " curl -ks -X POST '${WATSON_GATEWAY_ENDPOINT} /api/ibmcloud/resource-controller/resource_instances' -H 'Authorization: Bearer ${token} ' -H 'Content-Type: application/json' -d@/tmp/request.json | jq -r 'if .zen_id == null or .zen_id == \"\" then \" null\" else .zen_id end'" -c elasticsearch )
1394+ local token=$( fetch_cmd_result ${ZEN_ACCESS_POD } " curl -ks '${ZEN_CORE_API_ENDPOINT} /internal/v1/service_token?uid=${ZEN_UID} &username=${ZEN_USER_NAME} &display_name=${ZEN_USER_NAME} ' -H 'secret: ${ZEN_CORE_TOKEN} ' -H 'cache-control: no-cache' | jq -r .token" )
1395+ local instance_id=$( fetch_cmd_result ${ZEN_ACCESS_POD } " curl -ks -X POST '${WATSON_GATEWAY_ENDPOINT} /api/ibmcloud/resource-controller/resource_instances' -H 'Authorization: Bearer ${token} ' -H 'Content-Type: application/json' -d@/tmp/request.json | jq -r 'if .zen_id == null or .zen_id == \"\" then \" null\" else .zen_id end'" )
13881396 if [ " ${instance_id} " != " null" ] ; then
13891397 echo " ${instance_id} "
13901398 fi
0 commit comments