Skip to content

Commit

Permalink
Merge pull request #124 from RoanKanninga/master
Browse files Browse the repository at this point in the history
last fixes (see comment)
  • Loading branch information
marieke-bijlsma authored Apr 17, 2019
2 parents 74be138 + 5999de0 commit 3b66673
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 34 deletions.
6 changes: 4 additions & 2 deletions bin/copyProjectDataToPrm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ function archiveSampleSheet() {
local _startedCount=$(ls -1 "${_controlFileDir}/"*".${SCRIPT_NAME}.started" 2>/dev/null | wc -l)
local _failedCount=$(ls -1 "${_controlFileDir}/"*".${SCRIPT_NAME}.failed" 2>/dev/null | wc -l)
local _finishedCount=$(ls -1 "${_controlFileDir}/"*".${SCRIPT_NAME}.finished" 2>/dev/null | wc -l)

if [[ ${_startedCount} -eq 0 && ${_failedCount} -eq 0 && ${_finishedCount} -gt 0 ]]
then
log4Bash 'DEBUG' "${LINENO}" "${FUNCNAME:-main}" '0' "Archiving sample sheet for ${_project}..."
Expand All @@ -370,14 +370,16 @@ function archiveSampleSheet() {
mv "${_archiveSampleSheetControlFileBase}."{started,failed}
echo "Ooops! $(date '+%Y-%m-%d-T%H%M'): Failed to move ${_project}.${SAMPLESHEET_EXT} to ${HOSTNAME_PRM}:${PRM_ROOT_DIR}/Samplesheets/archive folder: ${_status}" \
>> "${_archiveSampleSheetControlFileBase}.failed"

else
log4Bash 'DEBUG' ${LINENO} "${FUNCNAME:-main}" 0 "Moved ${_project}.${SAMPLESHEET_EXT} to ${HOSTNAME_PRM}:${PRM_ROOT_DIR}/Samplesheets/archive folder."
echo "OK! $(date '+%Y-%m-%d-T%H%M'): Moved ${_project}.${SAMPLESHEET_EXT} to ${HOSTNAME_PRM}:${PRM_ROOT_DIR}/Samplesheets/archive folder." \
>> "${_archiveSampleSheetControlFileBase}.started" \
&& rm -f "${_archiveSampleSheetControlFileBase}.failed" \
&& mv "${_archiveSampleSheetControlFileBase}."{started,finished}
fi
log4Bash 'DEBUG' ${LINENO} "${FUNCNAME:-main}" 0 "removing ${TMP_ROOT_DIR}/Samplesheets/${_project}.${SAMPLESHEET_EXT}"
rm -f "${TMP_ROOT_DIR}/Samplesheets/${_project}.${SAMPLESHEET_EXT}"

}

function getSampleType(){
Expand Down
75 changes: 43 additions & 32 deletions lib/sharedFunctions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -172,38 +172,44 @@ function trackAndTracePostFromFile() {
local _file="${3}"

log4Bash 'DEBUG' "${LINENO}" "${FUNCNAME:-main}" '0' "Trying to get a token for REST API @ https://${MOLGENISSERVER}/api/v1/login..."
if curl -f -s -H "Content-Type: application/json" -X POST -d "{"username"="${USERNAME}", "password"="${PASSWORD}"}" https://${MOLGENISSERVER}/api/v1/login
then
local _curlResponse=$(curl -H "Content-Type: application/json" -X POST -d "{"username"="${USERNAME}", "password"="${PASSWORD}"}" https://${MOLGENISSERVER}/api/v1/login)
local _token=${_curlResponse:10:32}

log4Bash 'DEBUG' "${LINENO}" "${FUNCNAME:-main}" '0' "Trying to POST track&trace info using action ${_action} for entityTypeId=${_entityTypeId} from file=${_file} to https://${MOLGENISSERVER}/plugin/importwizard/importFile..."

local _curlResponse=$(curl -H "Content-Type: application/json" -X POST -d "{"username"="${USERNAME}", "password"="${PASSWORD}"}" https://${MOLGENISSERVER}/api/v1/login)
local _token=${_curlResponse:10:32}

log4Bash 'DEBUG' "${LINENO}" "${FUNCNAME:-main}" '0' "Trying to POST track&trace info using action ${_action} for entityTypeId=${_entityTypeId} from file=${_file} to https://${MOLGENISSERVER}/plugin/importwizard/importFile..."

local _lastHttpResponseStatus=$(curl -i \
local _lastHttpResponseStatus=$(curl -i \
-H "x-molgenis-token:${_token}" \
-X POST \
-F "file=@${_file}" \
-F "entityTypeId=${_entityTypeId}" \
-F "action=${_action}" \
-F "-FmetadataAction=ignore" \
-F 'notify=false' \
https://${MOLGENISSERVER}/plugin/importwizard/importFile \
| grep -E '^HTTP/[0-9]+.[0-9]+ [0-9]{3}' \
| tail -n 1)

local _regex='^HTTP/[0-9]+.[0-9]+ ([0-9]{3})'
if [[ "${_lastHttpResponseStatus}" =~ ${_regex} ]]
then
local _statusCode="${BASH_REMATCH[1]}"
if [[ ${_statusCode} -ge 400 ]]

local _regex='^HTTP/[0-9]+.[0-9]+ ([0-9]{3})'
if [[ "${_lastHttpResponseStatus}" =~ ${_regex} ]]
then
log4Bash 'ERROR' "${LINENO}" "${FUNCNAME:-main}" '0' "HTTP response status was ${_lastHttpResponseStatus}."
log4Bash 'ERROR' "${LINENO}" "${FUNCNAME:-main}" '0' "Failed to POST track&trace info using action ${_action} for entityTypeId=${_entityTypeId} from file=${_file} to https://${MOLGENISSERVER}/plugin/importwizard/importFile"
local _statusCode="${BASH_REMATCH[1]}"
if [[ ${_statusCode} -ge 400 ]]
then
log4Bash 'ERROR' "${LINENO}" "${FUNCNAME:-main}" '0' "HTTP response status was ${_lastHttpResponseStatus}."
log4Bash 'ERROR' "${LINENO}" "${FUNCNAME:-main}" '0' "Failed to POST track&trace info using action ${_action} for entityTypeId=${_entityTypeId} from file=${_file} to https://${MOLGENISSERVER}/plugin/importwizard/importFile"
else
log4Bash 'DEBUG' "${LINENO}" "${FUNCNAME:-main}" '0' "Successfully POSTed track&trace info. HTTP response status was ${_lastHttpResponseStatus}."
fi
else
log4Bash 'DEBUG' "${LINENO}" "${FUNCNAME:-main}" '0' "Successfully POSTed track&trace info. HTTP response status was ${_lastHttpResponseStatus}."
log4Bash 'ERROR' "${LINENO}" "${FUNCNAME:-main}" '0' "Failed to parse status code number from HTTP response status ${_lastHttpResponseStatus}."
log4Bash 'ERROR' "${LINENO}" "${FUNCNAME:-main}" '0' "Failed to POST track&trace info using action ${_action} for entityTypeId=${_entityTypeId} from file=${_file} to https://${MOLGENISSERVER}/plugin/importwizard/importFile"
fi
else
log4Bash 'ERROR' "${LINENO}" "${FUNCNAME:-main}" '0' "Failed to parse status code number from HTTP response status ${_lastHttpResponseStatus}."
log4Bash 'ERROR' "${LINENO}" "${FUNCNAME:-main}" '0' "Failed to POST track&trace info using action ${_action} for entityTypeId=${_entityTypeId} from file=${_file} to https://${MOLGENISSERVER}/plugin/importwizard/importFile"
echo "could not connect to a molgenis server: ${MOLGENISSERVER}"
fi

}

function trackAndTracePut() {
Expand All @@ -212,12 +218,14 @@ function trackAndTracePut() {
local _field="${3}"
local _content="${4}"
log4Bash 'DEBUG' "${LINENO}" "${FUNCNAME:-main}" '0' "Trying to get a token for REST API @ https://${MOLGENISSERVER}/api/v1/login..."
local _curlResponse=$(curl -H "Content-Type: application/json" -X POST -d "{"username"="${USERNAME}", "password"="${PASSWORD}"}" https://${MOLGENISSERVER}/api/v1/login)
local _token=${_curlResponse:10:32}
if curl -H "Content-Type: application/json" -X POST -d "{"username"="${USERNAME}", "password"="${PASSWORD}"}" https://${MOLGENISSERVER}/api/v1/login
then
local _curlResponse=$(curl -H "Content-Type: application/json" -X POST -d "{"username"="${USERNAME}", "password"="${PASSWORD}"}" https://${MOLGENISSERVER}/api/v1/login)
local _token=${_curlResponse:10:32}

log4Bash 'DEBUG' "${LINENO}" "${FUNCNAME:-main}" '0' "Trying to set status ${_content} for field ${_field} in entityTypeId=${_entityTypeId} with jobID ${_jobID}"
echo "curl -i -H \"x-molgenis-token:${_token}\" -X PUT -d \"${_content}\" https://${MOLGENISSERVER}/api/v1/${_entityTypeId}/${_jobID}/${_field}"
local _lastHttpResponseStatus=$(curl -i \
log4Bash 'DEBUG' "${LINENO}" "${FUNCNAME:-main}" '0' "Trying to set status ${_content} for field ${_field} in entityTypeId=${_entityTypeId} with jobID ${_jobID}"
echo "curl -i -H \"x-molgenis-token:${_token}\" -X PUT -d \"${_content}\" https://${MOLGENISSERVER}/api/v1/${_entityTypeId}/${_jobID}/${_field}"
local _lastHttpResponseStatus=$(curl -i \
-H "Content-Type:application/json" \
-H "x-molgenis-token:${_token}" \
-X PUT \
Expand All @@ -226,19 +234,22 @@ function trackAndTracePut() {
| grep -E '^HTTP/[0-9]+.[0-9]+ [0-9]{3}' \
| tail -n 1)

local _regex='^HTTP/[0-9]+.[0-9]+ ([0-9]{3})'
if [[ "${_lastHttpResponseStatus}" =~ ${_regex} ]]
then
local _statusCode="${BASH_REMATCH[1]}"
if [[ ${_statusCode} -ge 400 ]]
local _regex='^HTTP/[0-9]+.[0-9]+ ([0-9]{3})'
if [[ "${_lastHttpResponseStatus}" =~ ${_regex} ]]
then
log4Bash 'ERROR' "${LINENO}" "${FUNCNAME:-main}" '0' "HTTP response status was ${_lastHttpResponseStatus}."
log4Bash 'ERROR' "${LINENO}" "${FUNCNAME:-main}" '0' "Failed to set status ${_content} for field ${_field} in entityTypeId=${_entityTypeId} with jobID ${_jobID}"
local _statusCode="${BASH_REMATCH[1]}"
if [[ ${_statusCode} -ge 400 ]]
then
log4Bash 'ERROR' "${LINENO}" "${FUNCNAME:-main}" '0' "HTTP response status was ${_lastHttpResponseStatus}."
log4Bash 'ERROR' "${LINENO}" "${FUNCNAME:-main}" '0' "Failed to set status ${_content} for field ${_field} in entityTypeId=${_entityTypeId} with jobID ${_jobID}"
else
log4Bash 'DEBUG' "${LINENO}" "${FUNCNAME:-main}" '0' "Successfully PUTted track&trace info. HTTP response status was ${_lastHttpResponseStatus}."
fi
else
log4Bash 'DEBUG' "${LINENO}" "${FUNCNAME:-main}" '0' "Successfully PUTted track&trace info. HTTP response status was ${_lastHttpResponseStatus}."
log4Bash 'ERROR' "${LINENO}" "${FUNCNAME:-main}" '0' "Failed to parse status code number from HTTP response status ${_lastHttpResponseStatus}."
log4Bash 'ERROR' "${LINENO}" "${FUNCNAME:-main}" '0' "Failed to set status ${_content} for field ${_field} in entityTypeId=${_entityTypeId} with jobID ${_jobID}"
fi
else
log4Bash 'ERROR' "${LINENO}" "${FUNCNAME:-main}" '0' "Failed to parse status code number from HTTP response status ${_lastHttpResponseStatus}."
log4Bash 'ERROR' "${LINENO}" "${FUNCNAME:-main}" '0' "Failed to set status ${_content} for field ${_field} in entityTypeId=${_entityTypeId} with jobID ${_jobID}"
echo "could not upload to a molgenis server: ${MOLGENISSERVER}"
fi
}

0 comments on commit 3b66673

Please sign in to comment.