Skip to content

Commit

Permalink
Rename JSON property
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Scavo committed Jun 14, 2017
1 parent edd5b53 commit e71fdf4
Showing 1 changed file with 37 additions and 35 deletions.
72 changes: 37 additions & 35 deletions bin/compute_md_vital_stats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@ display_help () {
The JSON file contains a single array. Each array element is
a JavaScript object with the following fields:
successFlag boolean success or failure?
message string message string
metadataLocation string HTTP location
creationInstant string ISO 8601 dateTime
LastModified string ISO 8601 dateTime
currentTime string ISO 8601 dateTime
validUntil string ISO 8601 dateTime
validityInterval string ISO 8601 duration
sinceCreation string ISO 8601 duration
untilExpiration string ISO 8601 duration
deploymentLag string ISO 8601 duration
successFlag boolean success or failure?
message string message string
metadataLocation string HTTP location
creationInstant string ISO 8601 dateTime
LastModified string ISO 8601 dateTime
currentTime string ISO 8601 dateTime
validUntil string ISO 8601 dateTime
validityInterval string ISO 8601 duration
sinceCreation string ISO 8601 duration
untilExpiration string ISO 8601 duration
betweenCreationAndModified string ISO 8601 duration
For example:
Expand All @@ -121,7 +121,7 @@ display_help () {
"validityInterval": "P14DT0H0M0S",
"sinceCreation": "P0DT17H32M35S",
"untilExpiration": "P13DT6H27M25S",
"deploymentLag": "P0DT1H13M44S"
"betweenCreationAndModified": "P0DT1H13M44S"
}
EXAMPLES
Expand Down Expand Up @@ -307,7 +307,7 @@ append_json_object () {
local validityInterval=$( escape_special_json_chars "$validityInterval" )
local sinceCreation=$( escape_special_json_chars "$sinceCreation" )
local untilExpiration=$( escape_special_json_chars "$untilExpiration" )
local deploymentLag=$( escape_special_json_chars "$deploymentLag" )
local betweenCreationAndModified=$( escape_special_json_chars "$betweenCreationAndModified" )

local boolean_value="true"
! $success && boolean_value="false"
Expand All @@ -324,7 +324,7 @@ append_json_object () {
"validityInterval": "$validityInterval",
"sinceCreation": "$sinceCreation",
"untilExpiration": "$untilExpiration",
"deploymentLag": "$deploymentLag"
"betweenCreationAndModified": "$betweenCreationAndModified"
}
JSON_OBJECT
}
Expand All @@ -343,14 +343,16 @@ init_global_vars () {
validityInterval=
untilExpiration=
sinceCreation=
deploymentLag=
betweenCreationAndModified=
}

get_cached_resource () {

local status_code

md_location="$1"

# TODO: Check if cache up-to-date (conditional_get -I)

# get a cached content file
conditional_get $local_opts -C -d "$CACHE_DIR" -T "$tmp_dir" "$md_location" > "$xml_file"
Expand All @@ -359,7 +361,7 @@ get_cached_resource () {
# resource must be cached
success=false
message="Resource not found"
print_log_message -E "$script_name: metadata resource not cached: $md_location"
print_log_message -E "$script_name: resource not cached: $md_location"
return 1
fi
if [ $status_code -gt 1 ]; then
Expand All @@ -376,7 +378,7 @@ get_cached_resource () {
# resource must be cached
success=false
message="Resource not found"
print_log_message -E "$script_name: metadata resource not cached: $md_location"
print_log_message -E "$script_name: resource not cached: $md_location"
return 1
fi
if [ $status_code -gt 1 ]; then
Expand All @@ -397,7 +399,7 @@ parse_cached_content () {
local secsUntilExpiration
local secsSinceCreation

print_log_message -I "$script_name parsing cached metadata file for resource: $md_location"
print_log_message -I "$script_name parsing cached metadata for resource: $md_location"

# extract @ID, @creationInstant, @validUntil (in that order)
tstamps=$( /usr/bin/xsltproc $xsl_file $xml_file )
Expand All @@ -415,7 +417,7 @@ parse_cached_content () {
if [ $status_code -ne 0 ]; then
success=false
message="Unable to parse @validUntil"
print_log_message -E "$script_name: cut failed ($status_code)"
print_log_message -E "$script_name: cut failed ($status_code) on validUntil"
return 0
fi

Expand All @@ -434,7 +436,7 @@ parse_cached_content () {
if [ $status_code -ne 0 ]; then
success=false
message="Unable to parse @creationInstant"
print_log_message -E "$script_name: cut failed ($status_code)"
print_log_message -E "$script_name: cut failed ($status_code) on creationInstant"
return 0
fi

Expand All @@ -453,7 +455,7 @@ parse_cached_content () {
if [ $status_code -ne 0 ]; then
success=false
message="Unable to compute validity interval"
print_log_message -E "$script_name: secsUntil failed ($status_code)"
print_log_message -E "$script_name: secsUntil failed ($status_code) on validityInterval"
return 0
fi

Expand All @@ -463,7 +465,7 @@ parse_cached_content () {
if [ $status_code -ne 0 ]; then
success=false
message="Unable to convert validity interval"
print_log_message -E "$script_name: secs2duration failed ($status_code)"
print_log_message -E "$script_name: secs2duration failed ($status_code) on validityInterval"
return 0
fi
print_log_message -D "$script_name computed validity interval: $validityInterval"
Expand All @@ -474,7 +476,7 @@ parse_cached_content () {
if [ $status_code -ne 0 ]; then
success=false
message="Unable to compute current time"
print_log_message -E "$script_name: dateTime_now_canonical failed ($status_code)"
print_log_message -E "$script_name: dateTime_now_canonical failed ($status_code) on currentTime"
return 0
fi
print_log_message -D "$script_name computed current time: $currentTime"
Expand All @@ -485,7 +487,7 @@ parse_cached_content () {
if [ $status_code -ne 0 ]; then
success=false
message="Unable to compute time to expiration"
print_log_message -E "$script_name: secsUntil failed ($status_code)"
print_log_message -E "$script_name: secsUntil failed ($status_code) on untilExpiration"
return 0
fi

Expand All @@ -495,7 +497,7 @@ parse_cached_content () {
if [ $status_code -ne 0 ]; then
success=false
message="Unable to convert secs until expiration"
print_log_message -E "$script_name: secs2duration failed ($status_code)"
print_log_message -E "$script_name: secs2duration failed ($status_code) on untilExpiration"
return 0
fi
print_log_message -D "$script_name computed time until expiration: $untilExpiration"
Expand All @@ -506,7 +508,7 @@ parse_cached_content () {
if [ $status_code -ne 0 ]; then
success=false
message="Unable to compute time since creation"
print_log_message -E "$script_name: secsSince failed ($status_code)"
print_log_message -E "$script_name: secsSince failed ($status_code) on sinceCreation"
return 0
fi

Expand All @@ -516,7 +518,7 @@ parse_cached_content () {
if [ $status_code -ne 0 ]; then
success=false
message="Unable to convert secs since creation"
print_log_message -E "$script_name: secs2duration failed ($status_code)"
print_log_message -E "$script_name: secs2duration failed ($status_code) on sinceCreation"
return 0
fi
print_log_message -D "$script_name computed time since creation: $sinceCreation"
Expand All @@ -529,9 +531,9 @@ parse_cached_headers () {
local header_name
local status_code
local last_modified_apache
local deploymentLagSecs
local betweenCreationAndModifiedSecs

print_log_message -I "$script_name parsing cached header file for resource: $md_location"
print_log_message -I "$script_name parsing cached header for resource: $md_location"

# get the Last-Modified response header
header_name=Last-Modified
Expand All @@ -547,31 +549,31 @@ parse_cached_headers () {
if [ $status_code -ne 0 ]; then
success=false
message="Unable to convert LastModified date"
print_log_message -E "$script_name: dateTime_apache2canonical failed ($status_code)"
print_log_message -E "$script_name: dateTime_apache2canonical failed ($status_code) on last_modified"
return 0
fi
print_log_message -D "$script_name computed LastModified date: $last_modified"

# compute the length of time between @creationInstant and LastModified (in secs)
deploymentLagSecs=$( secsUntil -b $creationInstant $last_modified )
betweenCreationAndModifiedSecs=$( secsUntil -b $creationInstant $last_modified )
status_code=$?
if [ $status_code -ne 0 ]; then
success=false
message="Unable to compute deployment lag"
print_log_message -E "$script_name: secsUntil failed ($status_code)"
print_log_message -E "$script_name: secsUntil failed ($status_code) on betweenCreationAndModified"
return 0
fi

# convert secs to duration
deploymentLag=$( secs2duration "$deploymentLagSecs" )
betweenCreationAndModified=$( secs2duration "$betweenCreationAndModifiedSecs" )
status_code=$?
if [ $status_code -ne 0 ]; then
success=false
message="Unable to convert deployment lag tim"
print_log_message -E "$script_name: secs2duration failed ($status_code)"
print_log_message -E "$script_name: secs2duration failed ($status_code) on betweenCreationAndModified"
return 0
fi
print_log_message -D "$script_name computed deployment lag: $deploymentLag"
print_log_message -D "$script_name computed time between @creationInstant and LastModified: $betweenCreationAndModified"

return 0
}
Expand Down

0 comments on commit e71fdf4

Please sign in to comment.