Skip to content

Commit

Permalink
Merge pull request #310 from GEOS-ESM/develop
Browse files Browse the repository at this point in the history
GitFlow: Merge develop into main
  • Loading branch information
tclune authored Mar 3, 2023
2 parents 9cce4f3 + 2d354be commit afec9c0
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 17 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

## [3.26.0] - 2023-03-03

### Changed

- Add detection of Azure
- Change site detection code to distinguish between Rome and non-Rome
nodes at NAS (since there is an OS difference between them that has
run-time effects)

## [3.25.0] - 2023-02-17

### Added
Expand Down
87 changes: 70 additions & 17 deletions external_libraries/DetermineSite.cmake
Original file line number Diff line number Diff line change
@@ -1,29 +1,82 @@
# Set the site variable

set(DETECTED_SITE "UNKNOWN")

# In ecbuild, ecbuild itself sets a site_name for us
# called BUILD_SITE. If it didn't, we could use
# site_name(BUILD_SITE) as they do

# Here we try to detect the site using the hostname essentially. This we can pretty easily do
# because we know the NASA systems.

if (${BUILD_SITE} MATCHES "discover*" OR ${BUILD_SITE} MATCHES "borg*" OR ${BUILD_SITE} MATCHES "warp*")
set (DETECTED_SITE "NCCS")
elseif (${BUILD_SITE} MATCHES "pfe" OR ${BUILD_SITE} MATCHES "r[0-9]*i[0-9]*n[0-9]*" OR ${BUILD_SITE} MATCHES "r[0-9]*c[0-9]*t[0-9]*n[0-9]*")
set (DETECTED_SITE "NAS")
set (DETECTED_SITE "NCCS")
# At NAS, if you want to run on Rome, you have to build on Rome due to
# OS differences. So we make a variable that can let us make the setup
# scripts aware of this.
elseif (${BUILD_SITE} MATCHES "pfe" OR ${BUILD_SITE} MATCHES "r[0-9]*i[0-9]*n[0-9]*")
set (DETECTED_SITE "NAS")
set (BUILT_ON_ROME FALSE)
elseif (${BUILD_SITE} MATCHES "r[0-9]*c[0-9]*t[0-9]*n[0-9]*")
set (DETECTED_SITE "NAS")
set (BUILT_ON_ROME TRUE)
elseif (EXISTS /ford1/share/gmao_SIteam AND EXISTS /ford1/local AND ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set (DETECTED_SITE "GMAO.desktop")
else ()
file(DOWNLOAD http://169.254.169.254/latest/meta-data/instance-id ${CMAKE_CURRENT_BINARY_DIR}/instance-id
INACTIVITY_TIMEOUT 1.0
TIMEOUT 1.0
STATUS DOWNLOAD_STATUS
)
list(GET DOWNLOAD_STATUS 0 RETURN_CODE)

if (RETURN_CODE EQUAL 0)
set (DETECTED_SITE "AWS")
else ()
set (DETECTED_SITE ${BUILD_SITE})
endif ()
set (DETECTED_SITE "GMAO.desktop")
endif ()

# If we didn't detect the site, try to detect AWS
if (NOT DEFINED DETECTED_SITE OR DETECTED_SITE STREQUAL "UNKNOWN")
# Try to detect AWS
file(DOWNLOAD http://169.254.169.254/latest/meta-data/instance-id ${CMAKE_CURRENT_BINARY_DIR}/instance-id
INACTIVITY_TIMEOUT 1.0
TIMEOUT 1.0
STATUS DOWNLOAD_STATUS
)
list(GET DOWNLOAD_STATUS 0 RETURN_CODE)

if (RETURN_CODE EQUAL 0)
set (DETECTED_SITE "AWS")
endif ()
endif ()

# If we didn't detect AWS, we look for Azure
if (NOT DEFINED DETECTED_SITE OR DETECTED_SITE STREQUAL "UNKNOWN")
# Per https://learn.microsoft.com/en-us/azure/virtual-machines/linux/instance-metadata-service?tabs=linux
# it says you can run:
# curl -s -H Metadata:true --noproxy "*" "http://169.254.169.254/metadata/instance?api-version=2021-02-01" | jq
# to know more about the instance. Well, we don't need jq, we just need to know if we can get to
# that page. So we'll just try to download it.
file(DOWNLOAD http://169.254.169.254/metadata/instance?api-version=2021-02-01 ${CMAKE_CURRENT_BINARY_DIR}/instance
HTTPHEADER "Metadata:true"
INACTIVITY_TIMEOUT 1.0
TIMEOUT 1.0
STATUS DOWNLOAD_STATUS
)

list(GET DOWNLOAD_STATUS 0 RETURN_CODE)

if (RETURN_CODE EQUAL 0)
set (DETECTED_SITE "Azure")
endif ()
endif ()

# Note: No access to Google Cloud yet but my guess is we do something similar following:
# https://cloud.google.com/compute/docs/instances/detect-compute-engine

# Finally, if we didn't detect anything, we'll just use the BUILD_SITE
if (NOT DEFINED DETECTED_SITE OR DETECTED_SITE STREQUAL "UNKNOWN")
set (DETECTED_SITE ${BUILD_SITE})
endif ()

set(GEOS_SITE ${DETECTED_SITE} CACHE STRING "Detected site for use with GEOS setup scripts")
message(STATUS "Setting GEOS_SITE to ${GEOS_SITE}")

# Add message to say where we built at NAS
if (DETECTED_SITE STREQUAL "NAS")
if (BUILT_ON_ROME)
message(STATUS "Building on AMD Rome nodes at NAS")
else()
message(STATUS "Building on Intel nodes at NAS")
endif()
endif()

0 comments on commit afec9c0

Please sign in to comment.