From 35f0dba893f556f56dc282311fc115424c2e11cb Mon Sep 17 00:00:00 2001 From: Matteo Saloni Date: Thu, 11 Jul 2024 14:19:34 +0200 Subject: [PATCH] refactor: align k8s loggins --- .../infrastructure/k8s/K8sBaseFramework.java | 12 ++++----- .../k8s/K8sCronJobFramework.java | 12 ++++----- .../k8s/K8sDeploymentFramework.java | 23 ++++++++++------- .../infrastructure/k8s/K8sJobFramework.java | 23 ++++++++++------- .../infrastructure/k8s/K8sServeFramework.java | 25 +++++++++++-------- 5 files changed, 55 insertions(+), 40 deletions(-) diff --git a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sBaseFramework.java b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sBaseFramework.java index c4f5cbcf2..6b0e55ee9 100644 --- a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sBaseFramework.java +++ b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sBaseFramework.java @@ -200,8 +200,8 @@ public List pods(K object) throws K8sFrameworkException { return pods.getItems(); } catch (ApiException e) { log.error("Error with k8s: {}", e.getMessage()); - if (log.isDebugEnabled()) { - log.debug("k8s api response: {}", e.getResponseBody()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); } throw new K8sFrameworkException(e.getMessage()); @@ -288,8 +288,8 @@ public List logs(K object) throws K8sFrameworkException { return logs; } catch (ApiException e) { log.error("Error with k8s: {}", e.getMessage()); - if (log.isDebugEnabled()) { - log.debug("k8s api response: {}", e.getResponseBody()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); } throw new K8sFrameworkException(e.getMessage()); @@ -338,8 +338,8 @@ public List metrics(K object) throws K8sFrameworkException { return metrics; } catch (ApiException e) { log.error("Error with k8s: {}", e.getMessage()); - if (log.isDebugEnabled()) { - log.debug("k8s api response: {}", e.getResponseBody()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); } throw new K8sFrameworkException(e.getMessage()); diff --git a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sCronJobFramework.java b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sCronJobFramework.java index d259edbf0..c86e70344 100644 --- a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sCronJobFramework.java +++ b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sCronJobFramework.java @@ -214,8 +214,8 @@ public V1CronJob get(@NotNull V1CronJob job) throws K8sFrameworkException { return batchV1Api.readNamespacedCronJob(jobName, namespace, null); } catch (ApiException e) { log.info("Error with k8s: {}", e.getMessage()); - if (log.isDebugEnabled()) { - log.debug("k8s api response: {}", e.getResponseBody()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); } throw new K8sFrameworkException(e.getMessage()); @@ -234,8 +234,8 @@ public V1CronJob create(V1CronJob job) throws K8sFrameworkException { return batchV1Api.createNamespacedCronJob(namespace, job, null, null, null, null); } catch (ApiException e) { log.error("Error with k8s: {}", e.getResponseBody()); - if (log.isDebugEnabled()) { - log.debug("k8s api response: {}", e.getResponseBody()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); } throw new K8sFrameworkException(e.getResponseBody()); @@ -253,8 +253,8 @@ public void delete(V1CronJob job) throws K8sFrameworkException { batchV1Api.deleteNamespacedCronJob(jobName, namespace, null, null, null, null, null, null); } catch (ApiException e) { log.error("Error with k8s: {}", e.getResponseBody()); - if (log.isDebugEnabled()) { - log.debug("k8s api response: {}", e.getResponseBody()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); } throw new K8sFrameworkException(e.getResponseBody()); diff --git a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sDeploymentFramework.java b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sDeploymentFramework.java index 2008428a8..6353fb25b 100644 --- a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sDeploymentFramework.java +++ b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sDeploymentFramework.java @@ -76,7 +76,12 @@ public K8sDeploymentRunnable run(K8sDeploymentRunnable runnable) throws K8sFrame log.info("create initConfigMap for {}", String.valueOf(initConfigMap.getMetadata().getName())); coreV1Api.createNamespacedConfigMap(namespace, initConfigMap, null, null, null, null); } - } catch (ApiException | NullPointerException e) { + } catch (ApiException e) { + log.error("Error with k8s: {}", e.getMessage()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); + } + throw new K8sFrameworkException(e.getMessage()); } @@ -328,8 +333,8 @@ public V1Deployment apply(@NotNull V1Deployment deployment) throws K8sFrameworkE return appsV1Api.replaceNamespacedDeployment(deploymentName, namespace, deployment, null, null, null, null); } catch (ApiException e) { log.error("Error with k8s: {}", e.getMessage()); - if (log.isDebugEnabled()) { - log.debug("k8s api response: {}", e.getResponseBody()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); } throw new K8sFrameworkException(e.getMessage()); @@ -347,8 +352,8 @@ public V1Deployment get(@NotNull V1Deployment deployment) throws K8sFrameworkExc return appsV1Api.readNamespacedDeployment(deploymentName, namespace, null); } catch (ApiException e) { log.info("Error with k8s: {}", e.getResponseBody()); - if (log.isDebugEnabled()) { - log.debug("k8s api response: {}", e.getResponseBody()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); } throw new K8sFrameworkException(e.getResponseBody()); @@ -365,8 +370,8 @@ public V1Deployment create(V1Deployment deployment) throws K8sFrameworkException return appsV1Api.createNamespacedDeployment(namespace, deployment, null, null, null, null); } catch (ApiException e) { log.error("Error with k8s: {}", e.getResponseBody()); - if (log.isDebugEnabled()) { - log.debug("k8s api response: {}", e.getResponseBody()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); } throw new K8sFrameworkException(e.getResponseBody()); @@ -383,8 +388,8 @@ public void delete(@NotNull V1Deployment deployment) throws K8sFrameworkExceptio appsV1Api.deleteNamespacedDeployment(deploymentName, namespace, null, null, null, null, null, null); } catch (ApiException e) { log.error("Error with k8s: {}", e.getResponseBody()); - if (log.isDebugEnabled()) { - log.debug("k8s api response: {}", e.getResponseBody()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); } throw new K8sFrameworkException(e.getResponseBody()); diff --git a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sJobFramework.java b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sJobFramework.java index ad5aa7f52..160b79031 100644 --- a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sJobFramework.java +++ b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sJobFramework.java @@ -89,7 +89,12 @@ public K8sJobRunnable run(K8sJobRunnable runnable) throws K8sFrameworkException log.info("create initConfigMap for {}", String.valueOf(initConfigMap.getMetadata().getName())); coreV1Api.createNamespacedConfigMap(namespace, initConfigMap, null, null, null, null); } - } catch (ApiException | NullPointerException e) { + } catch (ApiException e) { + log.error("Error with k8s: {}", e.getMessage()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); + } + throw new K8sFrameworkException(e.getMessage()); } @@ -342,8 +347,8 @@ public V1Job get(@NotNull V1Job job) throws K8sFrameworkException { return batchV1Api.readNamespacedJob(jobName, namespace, null); } catch (ApiException e) { log.info("Error with k8s: {}", e.getMessage()); - if (log.isDebugEnabled()) { - log.debug("k8s api response: {}", e.getResponseBody()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); } throw new K8sFrameworkException(e.getMessage()); @@ -363,9 +368,9 @@ public V1Job create(V1Job job) throws K8sFrameworkException { log.info("Job created: {}", Objects.requireNonNull(createdJob.getMetadata()).getName()); return createdJob; } catch (ApiException e) { - log.error("Error with k8s: {}", e.getResponseBody()); - if (log.isDebugEnabled()) { - log.debug("k8s api response: {}", e.getResponseBody()); + log.error("Error with k8s: {}", e.getMessage()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); } throw new K8sFrameworkException(e.getResponseBody()); @@ -382,9 +387,9 @@ public void delete(V1Job job) throws K8sFrameworkException { batchV1Api.deleteNamespacedJob(jobName, namespace, null, null, null, null, null, null); } catch (ApiException e) { - log.error("Error with k8s: {}", e.getResponseBody()); - if (log.isDebugEnabled()) { - log.debug("k8s api response: {}", e.getResponseBody()); + log.error("Error with k8s: {}", e.getMessage()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); } throw new K8sFrameworkException(e.getResponseBody()); diff --git a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sServeFramework.java b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sServeFramework.java index ef8fae41f..79a4d32d9 100644 --- a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sServeFramework.java +++ b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/k8s/K8sServeFramework.java @@ -62,7 +62,12 @@ public K8sServeRunnable run(K8sServeRunnable runnable) throws K8sFrameworkExcept log.info("create initConfigMap for {}", String.valueOf(initConfigMap.getMetadata().getName())); coreV1Api.createNamespacedConfigMap(namespace, initConfigMap, null, null, null, null); } - } catch (ApiException | NullPointerException e) { + } catch (ApiException e) { + log.error("Error with k8s: {}", e.getMessage()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); + } + throw new K8sFrameworkException(e.getMessage()); } @@ -278,8 +283,8 @@ public V1Service apply(@NotNull V1Service service) throws K8sFrameworkException return coreV1Api.replaceNamespacedService(serviceName, namespace, service, null, null, null, null); } catch (ApiException e) { log.error("Error with k8s: {}", e.getMessage()); - if (log.isDebugEnabled()) { - log.debug("k8s api response: {}", e.getResponseBody()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); } throw new K8sFrameworkException(e.getMessage()); @@ -296,9 +301,9 @@ public V1Service get(@NotNull V1Service service) throws K8sFrameworkException { return coreV1Api.readNamespacedService(serviceName, namespace, null); } catch (ApiException e) { - log.info("Error with k8s: {}", e.getResponseBody()); - if (log.isDebugEnabled()) { - log.debug("k8s api response: {}", e.getResponseBody()); + log.info("Error with k8s: {}", e.getMessage()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); } throw new K8sFrameworkException(e.getResponseBody()); @@ -316,8 +321,8 @@ public V1Service create(V1Service service) throws K8sFrameworkException { return coreV1Api.createNamespacedService(namespace, service, null, null, null, null); } catch (ApiException e) { log.error("Error with k8s: {}", e.getMessage()); - if (log.isDebugEnabled()) { - log.debug("k8s api response: {}", e.getResponseBody()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); } throw new K8sFrameworkException(e.getMessage()); @@ -336,8 +341,8 @@ public void delete(V1Service service) throws K8sFrameworkException { coreV1Api.deleteNamespacedService(serviceName, namespace, null, null, null, null, null, null); } catch (ApiException e) { log.error("Error with k8s: {}", e.getMessage()); - if (log.isDebugEnabled()) { - log.debug("k8s api response: {}", e.getResponseBody()); + if (log.isTraceEnabled()) { + log.trace("k8s api response: {}", e.getResponseBody()); } throw new K8sFrameworkException(e.getMessage());