From c6c42da5c743e9d82d617ab22299be668c2d12e6 Mon Sep 17 00:00:00 2001 From: Jordon Saardchit Date: Mon, 2 Dec 2024 16:03:27 -0800 Subject: [PATCH] Fixing issue where edit cloud was breaking view when OLVM environment is completely down --- gradle.properties | 2 +- .../morpheus/olvm/OlvmOptionSourceProvider.groovy | 12 +++++++----- .../com/morpheus/olvm/util/OlvmComputeUtility.groovy | 8 ++++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/gradle.properties b/gradle.properties index e5cc1e9..28f07a9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=1.0.1 +version=1.0.2 karmanVersion=2.3.0 morpheusApiVersion=1.1.6 morpheusPluginGradleVersion=1.0.6 diff --git a/src/main/groovy/com/morpheus/olvm/OlvmOptionSourceProvider.groovy b/src/main/groovy/com/morpheus/olvm/OlvmOptionSourceProvider.groovy index c72c531..869fc55 100644 --- a/src/main/groovy/com/morpheus/olvm/OlvmOptionSourceProvider.groovy +++ b/src/main/groovy/com/morpheus/olvm/OlvmOptionSourceProvider.groovy @@ -112,11 +112,13 @@ class OlvmOptionSourceProvider extends AbstractOptionSourceProvider { def rtn if(cloud?.accountCredentialData?.username && cloud?.accountCredentialData?.password) { def connection = OlvmComputeUtility.getToken(cloud) - def dcResult = OlvmComputeUtility.listDatacenters([connection:connection]) - if (dcResult.success && dcResult.data.datacenters) { - rtn = [[name: morpheusContext.services.localization.get('gomorpheus.label.all'), value: 'all']] - for (dc in dcResult.data.datacenters) { - rtn << [name:dc.name, value:dc.id] + if (!connection.error) { + def dcResult = OlvmComputeUtility.listDatacenters([connection: connection]) + if (dcResult.success && dcResult.data.datacenters) { + rtn = [[name: morpheusContext.services.localization.get('gomorpheus.label.all'), value: 'all']] + for (dc in dcResult.data.datacenters) { + rtn << [name: dc.name, value: dc.id] + } } } } diff --git a/src/main/groovy/com/morpheus/olvm/util/OlvmComputeUtility.groovy b/src/main/groovy/com/morpheus/olvm/util/OlvmComputeUtility.groovy index 88bbb84..846f45d 100644 --- a/src/main/groovy/com/morpheus/olvm/util/OlvmComputeUtility.groovy +++ b/src/main/groovy/com/morpheus/olvm/util/OlvmComputeUtility.groovy @@ -1909,11 +1909,15 @@ class OlvmComputeUtility { ) if (resp.success) { - return [apiUrl: extractRootURL(config.endpointUrl), token: resp.data['access_token']] + return [success:true, apiUrl: extractRootURL(config.endpointUrl), token: resp.data['access_token']] } else { - throw new RuntimeException("Failed to authenticate to OLVM environment: ${extractErrorMessage(resp.data)}") + log.error("Failed to authenticate to OLVM environment: ${extractErrorMessage(resp.data)}") + return [success:false, apiUrl: extractRootURL(config.endpointUrl), error:extractErrorMessage(resp.data)] } } + catch (Throwable t) { + return [success:false, apiUrl: extractRootURL(config.endpointUrl), error:t.message] + } finally { client?.shutdownClient() }