diff options
Diffstat (limited to 'so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java')
15 files changed, 342 insertions, 244 deletions
diff --git a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/CamundaVariableNameConstants.java b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/CamundaVariableNameConstants.java index 47c5795..1a90fb5 100644 --- a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/CamundaVariableNameConstants.java +++ b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/CamundaVariableNameConstants.java @@ -31,6 +31,7 @@ public class CamundaVariableNameConstants { public static final String KUBE_KINDS_PARAM_NAME = "kubeKinds"; public static final String KIND_PARAM_NAME = "kind"; public static final String RELEASE_NAME_PARAM_NAME = "releaseName"; + public static final String NAMESPACE_PARAM_NAME = "namespace"; public static final String JOB_ID_PARAM_NAME = "jobId"; public static final String JOB_BUSINESS_KEY_PARAM_NAME = "jobBusinessKey"; public static final String CREATE_AS_REQUEST_PARAM_NAME = "createAsRequest"; diff --git a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/helm/HelmClient.java b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/helm/HelmClient.java index db5d092..67ce91b 100644 --- a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/helm/HelmClient.java +++ b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/helm/HelmClient.java @@ -32,17 +32,64 @@ import org.onap.so.cnfm.lcm.bpmn.flows.exceptions.HelmClientExecuteException; */ public interface HelmClient { - void runHelmChartInstallWithDryRunFlag(final String releaseName, final Path kubeconfig, final Path helmChart) - throws HelmClientExecuteException; + /** + * Execute <a href="https://helm.sh/docs/helm/helm_install/">helm install</a> with dry run flag + * + * @param namespace Namespace scope for this request + * @param releaseName Name of the release given to helm install + * @param kubeconfig kubernetes configuration file path + * @param helmChart path of the helm chart to install + * + * @throws HelmClientExecuteException when exception occurs while executing command + */ + void runHelmChartInstallWithDryRunFlag(final String namespace, final String releaseName, final Path kubeconfig, + final Path helmChart) throws HelmClientExecuteException; - List<String> getKubeKinds(final String releaseName, final Path kubeconfig, final Path helmChart) - throws HelmClientExecuteException; + /** + * Retrieve kube kinds using <a href="https://helm.sh/docs/helm/helm_template/">helm template</a> with dry run and + * skip-tests flag + * + * + * @param namespace Namespace scope for this request + * @param releaseName Name of the release given to helm install + * @param kubeconfig kubernetes configuration file path + * @param helmChart path of the helm chart to install + * + * @return Resources for helmChart as a List of strings + */ + List<String> getKubeKinds(final String namespace, final String releaseName, final Path kubeconfig, + final Path helmChart) throws HelmClientExecuteException; - List<String> getKubeKindsUsingManifestCommand(final String releaseName, final Path kubeconfig) - throws HelmClientExecuteException; + /** + * Retrieve kube kinds using <a href="https://helm.sh/docs/helm/helm_get_manifest/">helm get manifest</a> + * + * @param namespace Namespace scope for this request + * @param releaseName Name of the release given to helm install + * @param kubeconfig kubernetes configuration file path + * @return + * @throws HelmClientExecuteException + */ + List<String> getKubeKindsUsingManifestCommand(final String namespace, final String releaseName, + final Path kubeconfig) throws HelmClientExecuteException; - void installHelmChart(final String releaseName, final Path kubeconfig, final Path helmChart, + /** + * @param namespace Namespace scope for this request + * @param releaseName Name of the release given to helm install + * @param kubeconfig kubernetes configuration file path + * @param helmChart path of the helm chart to install + * @param lifeCycleParams override values in a chart + * @throws HelmClientExecuteException + */ + void installHelmChart(final String namespace, final String releaseName, final Path kubeconfig, final Path helmChart, final Map<String, String> lifeCycleParams) throws HelmClientExecuteException; - void unInstallHelmChart(final String releaseName, final Path kubeConfigFilePath) throws HelmClientExecuteException; + /** + * + * @param namespace Namespace scope for this request + * @param releaseName Name of the release given to helm install + * @param kubeConfigFilePath kubernetes configuration file path + * @throws HelmClientExecuteException + */ + void unInstallHelmChart(final String namespace, final String releaseName, final Path kubeConfigFilePath) + throws HelmClientExecuteException; } diff --git a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/helm/HelmClientImpl.java b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/helm/HelmClientImpl.java index b43bda6..e53a7c6 100644 --- a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/helm/HelmClientImpl.java +++ b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/helm/HelmClientImpl.java @@ -46,7 +46,6 @@ import org.springframework.stereotype.Service; @Service public class HelmClientImpl implements HelmClient { - private static final String DEFAULT_NAMESPACE = "default"; private static final String KIND_KEY = "kind: "; private static final String ANY_UNICODE_NEWLINE = "\\R"; private static final Logger logger = LoggerFactory.getLogger(HelmClientImpl.class); @@ -60,37 +59,23 @@ public class HelmClientImpl implements HelmClient { private static final Set<String> SUPPORTED_KINDS = Set.of(KIND_JOB, KIND_POD, KIND_SERVICE, KIND_DEPLOYMENT, KIND_REPLICA_SET, KIND_DAEMON_SET, KIND_STATEFUL_SET); - /** - * Execute a helm install dry run - * - * @param releaseName Name of the release given to helm install - * @param kubeconfig kubernetes configuration file path - * @param helmChart path of the helm chart to install - * - * @throws HelmClientExecuteException when exception occurs on executing command - */ @Override - public void runHelmChartInstallWithDryRunFlag(final String releaseName, final Path kubeconfig, final Path helmChart) - throws HelmClientExecuteException { - logger.info("Running dry-run on {} to cluster {} using releaseName: {}", helmChart, kubeconfig, releaseName); - final ProcessBuilder processBuilder = prepareDryRunCommand(releaseName, kubeconfig, helmChart); + public void runHelmChartInstallWithDryRunFlag(final String namespace, final String releaseName, + final Path kubeconfig, final Path helmChart) throws HelmClientExecuteException { + logger.info("Running dry-run on {} to cluster {} using namespace: {}, releaseName: {}", helmChart, kubeconfig, + namespace, releaseName); + final ProcessBuilder processBuilder = prepareDryRunCommand(namespace, releaseName, kubeconfig, helmChart); executeCommand(processBuilder); logger.info("Successfully ran dry for Chart {}", helmChart); } - /** - * - * @param releaseName Name of the release given to helm install - * @param kubeconfig kubernetes configuration file path - * @param helmChart path of the helm chart to install - * - * @return Resources for helmChart as a List of strings - */ @Override - public List<String> getKubeKinds(final String releaseName, final Path kubeconfig, final Path helmChart) { - logger.info("Retrieving kinds from chart {} using releaseName {}", helmChart, releaseName); - final ProcessBuilder processBuilder = prepareKubeKindCommand(releaseName, kubeconfig, helmChart); + public List<String> getKubeKinds(final String namespace, final String releaseName, final Path kubeconfig, + final Path helmChart) { + logger.info("Retrieving kinds from chart {} using namespace: {}, releaseName {}", helmChart, namespace, + releaseName); + final ProcessBuilder processBuilder = prepareKubeKindCommand(namespace, releaseName, kubeconfig, helmChart); final String response = executeCommand(processBuilder); if (StringUtils.isEmpty(response)) { logger.warn("Response is empty: {}", response); @@ -104,11 +89,12 @@ public class HelmClientImpl implements HelmClient { @Override - public List<String> getKubeKindsUsingManifestCommand(final String releaseName, final Path kubeConfig) - throws HelmClientExecuteException { - logger.info("Retrieving kinds from helm release history using releaseName {}", releaseName); + public List<String> getKubeKindsUsingManifestCommand(final String namespace, final String releaseName, + final Path kubeConfig) throws HelmClientExecuteException { + logger.info("Retrieving kinds from helm release history using namespace: {}, releaseName {}", namespace, + releaseName); - final ProcessBuilder processBuilder = prepareGetKubeKindCommand(releaseName, kubeConfig); + final ProcessBuilder processBuilder = prepareGetKubeKindCommand(namespace, releaseName, kubeConfig); final String response = executeCommand(processBuilder); if (StringUtils.isEmpty(response)) { logger.warn("Response is empty: {}", response); @@ -120,35 +106,22 @@ public class HelmClientImpl implements HelmClient { return kinds; } - - /** - * - * @param releaseName Name of the release given to helm install - * @param kubeconfig kubernetes configuration file path - * @param helmChart path of the helm chart to install - * @throws HelmClientExecuteException when exception occurs on executing command - */ @Override - public void installHelmChart(final String releaseName, final Path kubeconfig, final Path helmChart, - final Map<String, String> lifeCycleParams) throws HelmClientExecuteException { + public void installHelmChart(final String namespace, final String releaseName, final Path kubeconfig, + final Path helmChart, final Map<String, String> lifeCycleParams) throws HelmClientExecuteException { logger.info("Installing {} to cluster {} using releaseName: {}", helmChart, kubeconfig, releaseName); final ProcessBuilder processBuilder = - prepareInstallCommand(releaseName, kubeconfig, helmChart, lifeCycleParams); + prepareInstallCommand(namespace, releaseName, kubeconfig, helmChart, lifeCycleParams); executeCommand(processBuilder); logger.info("Chart {} installed successfully", helmChart); } - /** - * @param releaseName Name of the release given to helm install - * @param kubeConfigFilePath kubernetes configuration file path - * @throws HelmClientExecuteException when exception occurs on executing command - */ @Override - public void unInstallHelmChart(final String releaseName, final Path kubeConfigFilePath) + public void unInstallHelmChart(final String namespace, final String releaseName, final Path kubeConfigFilePath) throws HelmClientExecuteException { logger.info("uninstalling the release {} from cluster {}", releaseName, kubeConfigFilePath); - final ProcessBuilder processBuilder = prepareUnInstallCommand(releaseName, kubeConfigFilePath); + final ProcessBuilder processBuilder = prepareUnInstallCommand(namespace, releaseName, kubeConfigFilePath); final String commandResponse = executeCommand(processBuilder); if (!StringUtils.isEmpty(commandResponse) && commandResponse.contains("Release not loaded")) { throw new HelmClientExecuteException( @@ -158,15 +131,16 @@ public class HelmClientImpl implements HelmClient { logger.info("Release {} uninstalled successfully", releaseName); } - private ProcessBuilder prepareDryRunCommand(final String releaseName, final Path kubeconfig, final Path helmChart) { - final List<String> helmArguments = List.of("helm", "install", releaseName, "-n", DEFAULT_NAMESPACE, + private ProcessBuilder prepareDryRunCommand(final String namespace, final String releaseName, final Path kubeconfig, + final Path helmChart) { + final List<String> helmArguments = List.of("helm", "install", releaseName, "-n", namespace, helmChart.toString(), "--dry-run", "--kubeconfig", kubeconfig.toString()); return getProcessBuilder().command(helmArguments); } - private ProcessBuilder prepareInstallCommand(final String releaseName, final Path kubeconfig, final Path helmChart, - final Map<String, String> lifeCycleParams) { - final List<String> commands = new ArrayList<>(List.of("helm", "install", releaseName, "-n", DEFAULT_NAMESPACE, + private ProcessBuilder prepareInstallCommand(final String namespace, final String releaseName, + final Path kubeconfig, final Path helmChart, final Map<String, String> lifeCycleParams) { + final List<String> commands = new ArrayList<>(List.of("helm", "install", releaseName, "-n", namespace, helmChart.toString(), "--kubeconfig", kubeconfig.toString())); if (lifeCycleParams != null && !lifeCycleParams.isEmpty()) { @@ -190,25 +164,26 @@ public class HelmClientImpl implements HelmClient { } } - private ProcessBuilder prepareUnInstallCommand(final String releaseName, final Path kubeConfig) { + private ProcessBuilder prepareUnInstallCommand(final String namespace, final String releaseName, + final Path kubeConfig) { logger.debug("Will remove tis log after checking ubeconfig path: {}", kubeConfig.toFile().getName()); - final List<String> helmArguments = new ArrayList<>(List.of("helm", "uninstall", releaseName, "-n", - DEFAULT_NAMESPACE, "--kubeconfig", kubeConfig.toString())); + final List<String> helmArguments = new ArrayList<>( + List.of("helm", "uninstall", releaseName, "-n", namespace, "--kubeconfig", kubeConfig.toString())); return getProcessBuilder().command(helmArguments); } - private ProcessBuilder prepareKubeKindCommand(final String releaseName, final Path kubeconfig, - final Path helmChart) { - final List<String> commands = - List.of("helm", "template", releaseName, "-n", DEFAULT_NAMESPACE, helmChart.toString(), "--dry-run", - "--kubeconfig", kubeconfig.toString(), "--skip-tests", "| grep kind | uniq"); + private ProcessBuilder prepareKubeKindCommand(final String namespace, final String releaseName, + final Path kubeconfig, final Path helmChart) { + final List<String> commands = List.of("helm", "template", releaseName, "-n", namespace, helmChart.toString(), + "--dry-run", "--kubeconfig", kubeconfig.toString(), "--skip-tests", "| grep kind | uniq"); final List<String> helmArguments = List.of("sh", "-c", toString(commands)); return getProcessBuilder().command(helmArguments); } - private ProcessBuilder prepareGetKubeKindCommand(final String releaseName, final Path kubeconfig) { - final List<String> commands = List.of("helm", "get", "manifest", releaseName, "-n", DEFAULT_NAMESPACE, - "--kubeconfig", kubeconfig.toString(), "| grep kind | uniq"); + private ProcessBuilder prepareGetKubeKindCommand(final String namespace, final String releaseName, + final Path kubeconfig) { + final List<String> commands = List.of("helm", "get", "manifest", releaseName, "-n", namespace, "--kubeconfig", + kubeconfig.toString(), "| grep kind | uniq"); final List<String> helmArguments = List.of("sh", "-c", toString(commands)); return getProcessBuilder().command(helmArguments); } diff --git a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/kubernetes/KubernetesClient.java b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/kubernetes/KubernetesClient.java index d4a3425..5efeaef 100644 --- a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/kubernetes/KubernetesClient.java +++ b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/kubernetes/KubernetesClient.java @@ -30,26 +30,25 @@ import io.kubernetes.client.openapi.ApiClient; */ public interface KubernetesClient extends KubernetesResourceStatusCheck { - List<KubernetesResource> getJobResources(final ApiClient apiClient, final String labelSelector) - throws KubernetesRequestProcessingException; + List<KubernetesResource> getJobResources(final ApiClient apiClient, final String namespace, + final String labelSelector) throws KubernetesRequestProcessingException; - List<KubernetesResource> getDeploymentResources(final ApiClient apiClient, final String labelSelector) - throws KubernetesRequestProcessingException; + List<KubernetesResource> getDeploymentResources(final ApiClient apiClient, final String namespace, + final String labelSelector) throws KubernetesRequestProcessingException; - List<KubernetesResource> getPodResources(final ApiClient apiClient, final String labelSelector) - throws KubernetesRequestProcessingException; + List<KubernetesResource> getPodResources(final ApiClient apiClient, final String namespace, + final String labelSelector) throws KubernetesRequestProcessingException; - List<KubernetesResource> getServiceResources(final ApiClient apiClient, final String labelSelector) - throws KubernetesRequestProcessingException; + List<KubernetesResource> getServiceResources(final ApiClient apiClient, final String namespace, + final String labelSelector) throws KubernetesRequestProcessingException; - List<KubernetesResource> getReplicaSetResources(final ApiClient apiClient, final String labelSelector) - throws KubernetesRequestProcessingException; + List<KubernetesResource> getReplicaSetResources(final ApiClient apiClient, final String namespace, + final String labelSelector) throws KubernetesRequestProcessingException; - List<KubernetesResource> getDaemonSetResources(final ApiClient apiClient, final String labelSelector) - throws KubernetesRequestProcessingException; - - List<KubernetesResource> getStatefulSetResources(final ApiClient apiClient, final String labelSelector) - throws KubernetesRequestProcessingException; + List<KubernetesResource> getDaemonSetResources(final ApiClient apiClient, final String namespace, + final String labelSelector) throws KubernetesRequestProcessingException; + List<KubernetesResource> getStatefulSetResources(final ApiClient apiClient, final String namespace, + final String labelSelector) throws KubernetesRequestProcessingException; } diff --git a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/kubernetes/KubernetesClientImpl.java b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/kubernetes/KubernetesClientImpl.java index 5018091..2f4e1b9 100644 --- a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/kubernetes/KubernetesClientImpl.java +++ b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/kubernetes/KubernetesClientImpl.java @@ -114,13 +114,14 @@ public class KubernetesClientImpl implements KubernetesClient { private Integer timeoutSeconds; @Override - public boolean isJobReady(final ApiClient apiClient, final String labelSelector) + public boolean isJobReady(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException { - logger.debug("Will check if Job is ready using labelSelector: {}", labelSelector); + + logger.debug("Will check if Job is ready using namespace: {}, labelSelector: {}", namespace, labelSelector); try { final BatchV1Api batchV1Api = new BatchV1Api(apiClient); - final Call call = batchV1Api.listJobForAllNamespacesCall(null, null, null, labelSelector, null, null, null, - null, timeoutSeconds, ENABLE_WATCH, null); + final Call call = batchV1Api.listNamespacedJobCall(namespace, null, null, null, null, labelSelector, null, + null, null, timeoutSeconds, ENABLE_WATCH, null); final Map<V1Job, String> readyResources = getReadyResources(apiClient, call, new TypeToken<Response<V1Job>>() {}.getType()); @@ -134,9 +135,9 @@ public class KubernetesClientImpl implements KubernetesClient { logger.debug("JobList is ready ..."); return true; } + logger.debug("JobList is not yet Ready: {}", jobNotReadyList); return false; - } logger.warn("No items found in jobList : {}", readyResources); @@ -147,18 +148,20 @@ public class KubernetesClientImpl implements KubernetesClient { } catch (final RuntimeException runtimeException) { handleRuntimeException(KIND_JOB, labelSelector, runtimeException); } + logger.debug("Returning false as Job is not ready ..."); return false; } @Override - public boolean isPodReady(final ApiClient apiClient, final String labelSelector) + public boolean isPodReady(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException { - logger.debug("Will check if Pod is ready using labelSelector: {}", labelSelector); + + logger.debug("Will check if Pod is ready using namespace: {}, labelSelector: {}", namespace, labelSelector); try { final CoreV1Api coreV1Api = new CoreV1Api(apiClient); - final Call call = coreV1Api.listPodForAllNamespacesCall(null, null, null, labelSelector, null, null, null, - null, timeoutSeconds, ENABLE_WATCH, null); + final Call call = coreV1Api.listNamespacedPodCall(namespace, null, null, null, null, labelSelector, null, + null, null, timeoutSeconds, ENABLE_WATCH, null); final Map<V1Pod, String> readyResources = getReadyResources(apiClient, call, new TypeToken<Response<V1Pod>>() {}.getType()); @@ -172,9 +175,9 @@ public class KubernetesClientImpl implements KubernetesClient { logger.debug("PodList is ready ..."); return true; } + logger.debug("PodList is not yet Ready: {}", podNotReadyList); return false; - } logger.warn("No items found in podList : {}", readyResources); @@ -187,18 +190,18 @@ public class KubernetesClientImpl implements KubernetesClient { } logger.debug("Returning false as Pod is not ready ..."); - return false; } @Override - public boolean isServiceReady(final ApiClient apiClient, final String labelSelector) + public boolean isServiceReady(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException { - logger.debug("Will check if Service is ready using labelSelector: {}", labelSelector); + + logger.debug("Will check if Service is ready using namespace: {}, labelSelector: {}", namespace, labelSelector); try { final CoreV1Api api = new CoreV1Api(apiClient); - final Call call = api.listServiceForAllNamespacesCall(null, null, null, labelSelector, null, null, null, - null, timeoutSeconds, ENABLE_WATCH, null); + final Call call = api.listNamespacedServiceCall(namespace, null, null, null, null, labelSelector, null, + null, null, timeoutSeconds, ENABLE_WATCH, null); final Map<V1Service, String> readyResources = getReadyResources(apiClient, call, new TypeToken<Response<V1Service>>() {}.getType()); @@ -212,9 +215,9 @@ public class KubernetesClientImpl implements KubernetesClient { logger.debug("ServiceList is ready ..."); return true; } + logger.debug("ServiceList is not yet Ready: {}", serviceNotReadyList); return false; - } logger.warn("No items found in serviceList : {}", readyResources); @@ -231,14 +234,15 @@ public class KubernetesClientImpl implements KubernetesClient { } @Override - public boolean isDeploymentReady(final ApiClient apiClient, final String labelSelector) + public boolean isDeploymentReady(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException { - logger.debug("Will check if Deployment is ready using labelSelector: {}", labelSelector); + logger.debug("Will check if Deployment is ready using namespace: {}, labelSelector: {}", namespace, + labelSelector); try { final AppsV1Api appsV1Api = new AppsV1Api(apiClient); - final Call call = appsV1Api.listDeploymentForAllNamespacesCall(null, null, null, labelSelector, null, null, - null, null, timeoutSeconds, ENABLE_WATCH, null); + final Call call = appsV1Api.listNamespacedDeploymentCall(namespace, null, null, null, null, labelSelector, + null, null, null, timeoutSeconds, ENABLE_WATCH, null); final Map<V1Deployment, String> readyResources = getReadyResources(apiClient, call, new TypeToken<Response<V1Deployment>>() {}.getType()); @@ -252,9 +256,9 @@ public class KubernetesClientImpl implements KubernetesClient { logger.debug("DeploymentList is ready ..."); return true; } + logger.debug("DeploymentList is not yet Ready: {}", deploymentNotReadyList); return false; - } logger.warn("No items found in deploymentList : {}", readyResources); @@ -271,13 +275,15 @@ public class KubernetesClientImpl implements KubernetesClient { } @Override - public boolean isReplicaSetReady(final ApiClient apiClient, final String labelSelector) + public boolean isReplicaSetReady(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException { - logger.debug("Will check if ReplicaSet is ready using labelSelector: {}", labelSelector); + + logger.debug("Will check if ReplicaSet is ready using namespace: {}, labelSelector: {}", namespace, + labelSelector); try { final AppsV1Api appsV1Api = new AppsV1Api(apiClient); - final Call call = appsV1Api.listReplicaSetForAllNamespacesCall(null, null, null, labelSelector, null, null, - null, null, timeoutSeconds, ENABLE_WATCH, null); + final Call call = appsV1Api.listNamespacedReplicaSetCall(namespace, null, null, null, null, labelSelector, + null, null, null, timeoutSeconds, ENABLE_WATCH, null); final Map<V1ReplicaSet, String> readyResources = getReadyResources(apiClient, call, new TypeToken<Response<V1ReplicaSet>>() {}.getType()); @@ -291,9 +297,9 @@ public class KubernetesClientImpl implements KubernetesClient { logger.debug("ReplicaSetList is ready ..."); return true; } + logger.debug("ReplicaSetList is not yet Ready: {}", replicaSet); return false; - } logger.warn("No items found in replicaSetList : {}", readyResources); @@ -304,18 +310,21 @@ public class KubernetesClientImpl implements KubernetesClient { } catch (final RuntimeException runtimeException) { handleRuntimeException(KIND_REPLICA_SET, labelSelector, runtimeException); } + logger.debug("Returning false as ReplicaSet is not ready ..."); return false; } @Override - public boolean isDaemonSetReady(final ApiClient apiClient, final String labelSelector) + public boolean isDaemonSetReady(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException { - logger.debug("Will check if DaemonSet is ready using labelSelector: {}", labelSelector); + + logger.debug("Will check if DaemonSet is ready using namespace: {}, labelSelector: {}", namespace, + labelSelector); try { final AppsV1Api appsV1Api = new AppsV1Api(apiClient); - final Call call = appsV1Api.listDaemonSetForAllNamespacesCall(null, null, null, labelSelector, null, null, - null, null, timeoutSeconds, ENABLE_WATCH, null); + final Call call = appsV1Api.listNamespacedDaemonSetCall(namespace, null, null, null, null, labelSelector, + null, null, null, timeoutSeconds, ENABLE_WATCH, null); final Map<V1DaemonSet, String> readyResources = getReadyResources(apiClient, call, new TypeToken<Response<V1DaemonSet>>() {}.getType()); @@ -329,9 +338,9 @@ public class KubernetesClientImpl implements KubernetesClient { logger.debug("DaemonSetList is ready ..."); return true; } + logger.debug("DaemonSetList is not yet Ready: {}", daemonSetNotReadyList); return false; - } logger.warn("No items found in daemonSetList : {}", readyResources); @@ -342,18 +351,21 @@ public class KubernetesClientImpl implements KubernetesClient { } catch (final RuntimeException runtimeException) { handleRuntimeException(KIND_DAEMON_SET, labelSelector, runtimeException); } + logger.debug("Returning false as DaemonSet is not ready ..."); return false; } @Override - public boolean isStatefulSetReady(final ApiClient apiClient, final String labelSelector) + public boolean isStatefulSetReady(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException { - logger.debug("Will check if StatefulSet is ready using labelSelector: {}", labelSelector); + + logger.debug("Will check if StatefulSet is ready using namespace: {}, labelSelector: {}", namespace, + labelSelector); try { final AppsV1Api appsV1Api = new AppsV1Api(apiClient); - final Call call = appsV1Api.listStatefulSetForAllNamespacesCall(null, null, null, labelSelector, null, null, - null, null, timeoutSeconds, ENABLE_WATCH, null); + final Call call = appsV1Api.listNamespacedStatefulSetCall(namespace, null, null, null, null, labelSelector, + null, null, null, timeoutSeconds, ENABLE_WATCH, null); final Map<V1StatefulSet, String> readyResources = getReadyResources(apiClient, call, new TypeToken<Response<V1StatefulSet>>() {}.getType()); @@ -385,13 +397,14 @@ public class KubernetesClientImpl implements KubernetesClient { } @Override - public boolean isServiceDeleted(final ApiClient apiClient, final String labelSelector) + public boolean isServiceDeleted(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException { - logger.debug("Check is Service deleted by using labelSelector: {}", labelSelector); + + logger.debug("Check is Service deleted by using namespace: {}, labelSelector: {}", namespace, labelSelector); try { final CoreV1Api coreV1Api = new CoreV1Api(apiClient); - final V1ServiceList v1ServiceList = coreV1Api.listServiceForAllNamespaces(null, null, null, labelSelector, - null, null, null, null, timeoutSeconds, DISABLE_WATCH); + final V1ServiceList v1ServiceList = coreV1Api.listNamespacedService(namespace, null, null, null, null, + labelSelector, null, null, null, timeoutSeconds, DISABLE_WATCH); logger.debug("Response from list service for all Namespaces: {}", v1ServiceList); return v1ServiceList.getItems().isEmpty(); } catch (final ApiException exception) { @@ -404,13 +417,14 @@ public class KubernetesClientImpl implements KubernetesClient { } @Override - public boolean isPodDeleted(final ApiClient apiClient, final String labelSelector) + public boolean isPodDeleted(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException { - logger.debug("Check is Pod deleted by using labelSelector: {}", labelSelector); + + logger.debug("Check is Pod deleted by using namespace: {}, labelSelector: {}", namespace, labelSelector); try { final CoreV1Api coreV1Api = new CoreV1Api(apiClient); - final V1PodList v1PodList = coreV1Api.listPodForAllNamespaces(null, null, null, labelSelector, null, null, - null, null, timeoutSeconds, DISABLE_WATCH); + final V1PodList v1PodList = coreV1Api.listNamespacedPod(namespace, null, null, null, null, labelSelector, + null, null, null, timeoutSeconds, DISABLE_WATCH); logger.debug("Response from list Pod for all Namespaces: {}", v1PodList); return v1PodList.getItems().isEmpty(); } catch (final ApiException exception) { @@ -423,13 +437,13 @@ public class KubernetesClientImpl implements KubernetesClient { } @Override - public boolean isJobDeleted(final ApiClient apiClient, final String labelSelector) + public boolean isJobDeleted(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException { - logger.debug("Check is Job deleted by using labelSelector: {}", labelSelector); + logger.debug("Check is Job deleted by using namespace: {}, labelSelector: {}", namespace, labelSelector); try { final BatchV1Api batchV1Api = new BatchV1Api(apiClient); - final V1JobList v1JobList = batchV1Api.listJobForAllNamespaces(null, null, null, labelSelector, null, null, - null, null, timeoutSeconds, DISABLE_WATCH); + final V1JobList v1JobList = batchV1Api.listNamespacedJob(namespace, null, null, null, null, labelSelector, + null, null, null, timeoutSeconds, DISABLE_WATCH); logger.debug("Response from list Job for all Namespaces: {}", v1JobList); return v1JobList.getItems().isEmpty(); } catch (final ApiException exception) { @@ -442,13 +456,13 @@ public class KubernetesClientImpl implements KubernetesClient { } @Override - public boolean isDeploymentDeleted(final ApiClient apiClient, final String labelSelector) + public boolean isDeploymentDeleted(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException { - logger.debug("Check is Deployment deleted by using labelSelector: {}", labelSelector); + logger.debug("Check is Deployment deleted by using namespace: {}, labelSelector: {}", namespace, labelSelector); try { final AppsV1Api batchV1Api = new AppsV1Api(apiClient); - final V1DeploymentList v1DeploymentList = batchV1Api.listDeploymentForAllNamespaces(null, null, null, - labelSelector, null, null, null, null, timeoutSeconds, DISABLE_WATCH); + final V1DeploymentList v1DeploymentList = batchV1Api.listNamespacedDeployment(namespace, null, null, null, + null, labelSelector, null, null, null, timeoutSeconds, DISABLE_WATCH); logger.debug("Response from list Deployment for all Namespaces: {}", v1DeploymentList); return v1DeploymentList.getItems().isEmpty(); } catch (final ApiException exception) { @@ -461,13 +475,13 @@ public class KubernetesClientImpl implements KubernetesClient { } @Override - public boolean isReplicaSetDeleted(final ApiClient apiClient, final String labelSelector) + public boolean isReplicaSetDeleted(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException { - logger.debug("Check is ReplicaSet deleted by using labelSelector: {}", labelSelector); + logger.debug("Check is ReplicaSet deleted by using namespace: {}, labelSelector: {}", namespace, labelSelector); try { final AppsV1Api batchV1Api = new AppsV1Api(apiClient); - final V1ReplicaSetList v1ReplicaSetList = batchV1Api.listReplicaSetForAllNamespaces(null, null, null, - labelSelector, null, null, null, null, timeoutSeconds, DISABLE_WATCH); + final V1ReplicaSetList v1ReplicaSetList = batchV1Api.listNamespacedReplicaSet(namespace, null, null, null, + null, labelSelector, null, null, null, timeoutSeconds, DISABLE_WATCH); logger.debug("Response from list ReplicaSet for all Namespaces: {}", v1ReplicaSetList); return v1ReplicaSetList.getItems().isEmpty(); } catch (final ApiException exception) { @@ -480,13 +494,13 @@ public class KubernetesClientImpl implements KubernetesClient { } @Override - public boolean isDaemonSetDeleted(final ApiClient apiClient, final String labelSelector) + public boolean isDaemonSetDeleted(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException { - logger.debug("Check is DaemonSet deleted by using labelSelector: {}", labelSelector); + logger.debug("Check is DaemonSet deleted by using namespace: {}, labelSelector: {}", namespace, labelSelector); try { final AppsV1Api batchV1Api = new AppsV1Api(apiClient); - final V1DaemonSetList v1DaemonSetList = batchV1Api.listDaemonSetForAllNamespaces(null, null, null, - labelSelector, null, null, null, null, timeoutSeconds, DISABLE_WATCH); + final V1DaemonSetList v1DaemonSetList = batchV1Api.listNamespacedDaemonSet(namespace, null, null, null, + null, labelSelector, null, null, null, timeoutSeconds, DISABLE_WATCH); logger.debug("Response from list DaemonSet for all Namespaces: {}", v1DaemonSetList); return v1DaemonSetList.getItems().isEmpty(); } catch (final ApiException exception) { @@ -499,13 +513,14 @@ public class KubernetesClientImpl implements KubernetesClient { } @Override - public boolean isStatefulSetDeleted(final ApiClient apiClient, final String labelSelector) + public boolean isStatefulSetDeleted(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException { - logger.debug("Check is StatefulSet deleted by using labelSelector: {}", labelSelector); + logger.debug("Check is StatefulSet deleted by using namespace: {}, labelSelector: {}", namespace, + labelSelector); try { final AppsV1Api batchV1Api = new AppsV1Api(apiClient); - final V1StatefulSetList v1StatefulSetList = batchV1Api.listStatefulSetForAllNamespaces(null, null, null, - labelSelector, null, null, null, null, timeoutSeconds, DISABLE_WATCH); + final V1StatefulSetList v1StatefulSetList = batchV1Api.listNamespacedStatefulSet(namespace, null, null, + null, null, labelSelector, null, null, null, timeoutSeconds, DISABLE_WATCH); logger.debug("Response from list StatefulSet for all Namespaces: {}", v1StatefulSetList); return v1StatefulSetList.getItems().isEmpty(); } catch (final ApiException exception) { @@ -519,13 +534,13 @@ public class KubernetesClientImpl implements KubernetesClient { @Override - public List<KubernetesResource> getJobResources(final ApiClient apiClient, final String labelSelector) - throws KubernetesRequestProcessingException { - logger.debug("Retrieving Jobs using labelSelector: {}", labelSelector); + public List<KubernetesResource> getJobResources(final ApiClient apiClient, final String namespace, + final String labelSelector) throws KubernetesRequestProcessingException { + logger.debug("Retrieving Jobs using namespace: {}, labelSelector: {}", namespace, labelSelector); try { final BatchV1Api batchV1Api = new BatchV1Api(apiClient); - final V1JobList jobList = batchV1Api.listJobForAllNamespaces(null, null, null, labelSelector, null, null, - null, null, timeoutSeconds, DISABLE_WATCH); + final V1JobList jobList = batchV1Api.listNamespacedJob(namespace, null, null, null, null, labelSelector, + null, null, null, timeoutSeconds, DISABLE_WATCH); logger.debug("Received Jobs: {}", jobList); return getKubernetesResource(jobList); @@ -543,13 +558,13 @@ public class KubernetesClientImpl implements KubernetesClient { } @Override - public List<KubernetesResource> getDeploymentResources(final ApiClient apiClient, final String labelSelector) - throws KubernetesRequestProcessingException { - logger.debug("Retrieving Deployment using labelSelector: {}", labelSelector); + public List<KubernetesResource> getDeploymentResources(final ApiClient apiClient, final String namespace, + final String labelSelector) throws KubernetesRequestProcessingException { + logger.debug("Retrieving Deployment using namespace: {}, labelSelector: {}", namespace, labelSelector); try { final AppsV1Api appsV1Api = new AppsV1Api(apiClient); - final V1DeploymentList deploymentList = appsV1Api.listDeploymentForAllNamespaces(null, null, null, - labelSelector, null, null, null, null, timeoutSeconds, DISABLE_WATCH); + final V1DeploymentList deploymentList = appsV1Api.listNamespacedDeployment(namespace, null, null, null, + null, labelSelector, null, null, null, timeoutSeconds, DISABLE_WATCH); logger.debug("Received Deployments: {}", deploymentList); return getKubernetesResource(deploymentList); @@ -567,13 +582,13 @@ public class KubernetesClientImpl implements KubernetesClient { } @Override - public List<KubernetesResource> getPodResources(final ApiClient apiClient, final String labelSelector) - throws KubernetesRequestProcessingException { - logger.debug("Retrieving Pod using labelSelector: {}", labelSelector); + public List<KubernetesResource> getPodResources(final ApiClient apiClient, final String namespace, + final String labelSelector) throws KubernetesRequestProcessingException { + logger.debug("Retrieving Pod using namespace: {}, labelSelector: {}", namespace, labelSelector); try { final CoreV1Api coreV1Api = new CoreV1Api(apiClient); - final V1PodList podList = coreV1Api.listPodForAllNamespaces(null, null, null, labelSelector, null, null, - null, null, timeoutSeconds, DISABLE_WATCH); + final V1PodList podList = coreV1Api.listNamespacedPod(namespace, null, null, null, null, labelSelector, + null, null, null, timeoutSeconds, DISABLE_WATCH); logger.debug("Received Pods: {}", podList); return getKubernetesResource(podList); @@ -591,13 +606,13 @@ public class KubernetesClientImpl implements KubernetesClient { } @Override - public List<KubernetesResource> getServiceResources(final ApiClient apiClient, final String labelSelector) - throws KubernetesRequestProcessingException { - logger.debug("Retrieving Service using labelSelector: {}", labelSelector); + public List<KubernetesResource> getServiceResources(final ApiClient apiClient, final String namespace, + final String labelSelector) throws KubernetesRequestProcessingException { + logger.debug("Retrieving Service using namespace: {}, labelSelector: {}", namespace, labelSelector); try { final CoreV1Api coreV1Api = new CoreV1Api(apiClient); - final V1ServiceList serviceList = coreV1Api.listServiceForAllNamespaces(null, null, null, labelSelector, - null, null, null, null, timeoutSeconds, DISABLE_WATCH); + final V1ServiceList serviceList = coreV1Api.listNamespacedService(namespace, null, null, null, null, + labelSelector, null, null, null, timeoutSeconds, DISABLE_WATCH); logger.debug("Received Services: {}", serviceList); return getKubernetesResource(serviceList); @@ -615,13 +630,13 @@ public class KubernetesClientImpl implements KubernetesClient { } @Override - public List<KubernetesResource> getReplicaSetResources(final ApiClient apiClient, final String labelSelector) - throws KubernetesRequestProcessingException { - logger.debug("Retrieving ReplicaSet using labelSelector: {}", labelSelector); + public List<KubernetesResource> getReplicaSetResources(final ApiClient apiClient, final String namespace, + final String labelSelector) throws KubernetesRequestProcessingException { + logger.debug("Retrieving ReplicaSet using namespace: {}, labelSelector: {}", namespace, labelSelector); try { final AppsV1Api appsV1Api = new AppsV1Api(apiClient); - final V1ReplicaSetList replicaSetList = appsV1Api.listReplicaSetForAllNamespaces(null, null, null, - labelSelector, null, null, null, null, timeoutSeconds, DISABLE_WATCH); + final V1ReplicaSetList replicaSetList = appsV1Api.listNamespacedReplicaSet(namespace, null, null, null, + null, labelSelector, null, null, null, timeoutSeconds, DISABLE_WATCH); logger.debug("Received ReplicaSets: {}", replicaSetList); return getKubernetesResource(replicaSetList); @@ -639,14 +654,14 @@ public class KubernetesClientImpl implements KubernetesClient { } @Override - public List<KubernetesResource> getDaemonSetResources(final ApiClient apiClient, final String labelSelector) - throws KubernetesRequestProcessingException { - logger.debug("Retrieving DaemonSet using labelSelector: {}", labelSelector); + public List<KubernetesResource> getDaemonSetResources(final ApiClient apiClient, final String namespace, + final String labelSelector) throws KubernetesRequestProcessingException { + logger.debug("Retrieving DaemonSet using namespace: {}, labelSelector: {}", namespace, labelSelector); try { final AppsV1Api appsV1Api = new AppsV1Api(apiClient); - final V1DaemonSetList daemonSetList = appsV1Api.listDaemonSetForAllNamespaces(null, null, null, - labelSelector, null, null, null, null, timeoutSeconds, DISABLE_WATCH); + final V1DaemonSetList daemonSetList = appsV1Api.listNamespacedDaemonSet(namespace, null, null, null, null, + labelSelector, null, null, null, timeoutSeconds, DISABLE_WATCH); logger.debug("Received DaemonSets: {}", daemonSetList); return getKubernetesResource(daemonSetList); @@ -664,14 +679,14 @@ public class KubernetesClientImpl implements KubernetesClient { } @Override - public List<KubernetesResource> getStatefulSetResources(final ApiClient apiClient, final String labelSelector) - throws KubernetesRequestProcessingException { - logger.debug("Retrieving StatefulSet using labelSelector: {}", labelSelector); + public List<KubernetesResource> getStatefulSetResources(final ApiClient apiClient, final String namespace, + final String labelSelector) throws KubernetesRequestProcessingException { + logger.debug("Retrieving StatefulSet using namespace: {}, labelSelector: {}", namespace, labelSelector); try { final AppsV1Api appsV1Api = new AppsV1Api(apiClient); - final V1StatefulSetList statefulSetList = appsV1Api.listStatefulSetForAllNamespaces(null, null, null, - labelSelector, null, null, null, null, timeoutSeconds, DISABLE_WATCH); + final V1StatefulSetList statefulSetList = appsV1Api.listNamespacedStatefulSet(namespace, null, null, null, + null, labelSelector, null, null, null, timeoutSeconds, DISABLE_WATCH); logger.debug("Received StatefulSets: {}", statefulSetList); return getKubernetesResource(statefulSetList); diff --git a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/kubernetes/KubernetesResourceStatusCheck.java b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/kubernetes/KubernetesResourceStatusCheck.java index b32fd65..a75957a 100644 --- a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/kubernetes/KubernetesResourceStatusCheck.java +++ b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/kubernetes/KubernetesResourceStatusCheck.java @@ -29,45 +29,45 @@ import org.onap.so.cnfm.lcm.bpmn.flows.exceptions.KubernetesRequestProcessingExc * */ public interface KubernetesResourceStatusCheck { - boolean isJobReady(final ApiClient apiClient, final String labelSelector) + boolean isJobReady(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException; - boolean isPodReady(final ApiClient apiClient, final String labelSelector) + boolean isPodReady(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException; - boolean isServiceReady(final ApiClient apiClient, final String labelSelector) + boolean isServiceReady(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException; - boolean isDeploymentReady(final ApiClient apiClient, final String labelSelector) + boolean isDeploymentReady(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException; - boolean isReplicaSetReady(final ApiClient apiClient, final String labelSelector) + boolean isReplicaSetReady(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException; - boolean isDaemonSetReady(final ApiClient apiClient, final String labelSelector) + boolean isDaemonSetReady(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException; - boolean isStatefulSetReady(final ApiClient apiClient, final String labelSelector) + boolean isStatefulSetReady(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException; - boolean isServiceDeleted(final ApiClient apiClient, final String labelSelector) + boolean isServiceDeleted(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException; - boolean isPodDeleted(final ApiClient apiClient, final String labelSelector) + boolean isPodDeleted(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException; - boolean isJobDeleted(final ApiClient apiClient, final String labelSelector) + boolean isJobDeleted(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException; - boolean isDeploymentDeleted(final ApiClient apiClient, final String labelSelector) + boolean isDeploymentDeleted(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException; - boolean isReplicaSetDeleted(final ApiClient apiClient, final String labelSelector) + boolean isReplicaSetDeleted(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException; - boolean isDaemonSetDeleted(final ApiClient apiClient, final String labelSelector) + boolean isDaemonSetDeleted(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException; - boolean isStatefulSetDeleted(final ApiClient apiClient, final String labelSelector) + boolean isStatefulSetDeleted(final ApiClient apiClient, final String namespace, final String labelSelector) throws KubernetesRequestProcessingException; } diff --git a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/CreateAsTask.java b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/CreateAsTask.java index 6e2b489..f63ffb4 100644 --- a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/CreateAsTask.java +++ b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/CreateAsTask.java @@ -31,18 +31,18 @@ import static org.onap.so.cnfm.lcm.bpmn.flows.extclients.sdc.SdcCsarPropertiesCo import static org.onap.so.cnfm.lcm.bpmn.flows.extclients.sdc.SdcCsarPropertiesConstants.PROVIDER_PARAM_NAME; import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.CLOUD_OWNER_PARAM_KEY; import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.CLOUD_REGION_PARAM_KEY; +import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.NAMESPACE_KEY; import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.RESOURCE_ID_KEY; import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.SERVICE_INSTANCE_ID_PARAM_KEY; import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.SERVICE_INSTANCE_NAME_PARAM_KEY; import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.TENANT_ID_PARAM_KEY; -import java.util.Arrays; +import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.UUID; -import java.time.LocalDateTime; - import org.camunda.bpm.engine.delegate.DelegateExecution; import org.onap.aai.domain.yang.GenericVnf; import org.onap.so.cnfm.lcm.bpmn.flows.extclients.aai.AaiServiceProvider; @@ -51,9 +51,9 @@ import org.onap.so.cnfm.lcm.bpmn.flows.extclients.sdc.SdcCsarPackageParser; import org.onap.so.cnfm.lcm.bpmn.flows.extclients.sdc.SdcPackageProvider; import org.onap.so.cnfm.lcm.database.beans.AsDeploymentItem; import org.onap.so.cnfm.lcm.database.beans.AsInst; +import org.onap.so.cnfm.lcm.database.beans.AsLifecycleParam; import org.onap.so.cnfm.lcm.database.beans.JobStatusEnum; import org.onap.so.cnfm.lcm.database.beans.State; -import org.onap.so.cnfm.lcm.database.beans.AsLifecycleParam; import org.onap.so.cnfm.lcm.database.service.DatabaseServiceProvider; import org.onap.so.cnfm.lcm.model.AsInstance; import org.onap.so.cnfm.lcm.model.AsInstance.InstantiationStateEnum; @@ -73,6 +73,7 @@ public class CreateAsTask extends AbstractServiceTask { private static final String ASD_PROPERTIES_PARAM_NAME = "asdProperties"; private static final String DOES_AS_PACKAGE_EXISTS_PARAM_NAME = "doesAsPackageExists"; private static final String DOES_AS_INSTANCE_EXISTS_PARAM_NAME = "doesAsInstanceExists"; + private static final String DEFAULT_NAMESPACE = "default"; private static final Logger logger = LoggerFactory.getLogger(CreateAsTask.class); private final AaiServiceProvider aaiServiceProvider; @@ -180,6 +181,7 @@ public class CreateAsTask extends AbstractServiceTask { final String cloudRegion = getMandatoryValue(additionalParams, CLOUD_REGION_PARAM_KEY, execution); final String tenantId = getMandatoryValue(additionalParams, TENANT_ID_PARAM_KEY, execution); final String resourceId = (String) additionalParams.get(RESOURCE_ID_KEY); + final String namespace = getNamespace((String) additionalParams.get(NAMESPACE_KEY)); final String serviceInstanceName = getMandatoryValue(additionalParams, SERVICE_INSTANCE_NAME_PARAM_KEY, execution); @@ -202,7 +204,8 @@ public class CreateAsTask extends AbstractServiceTask { .asApplicationVersion(getParamValue(asdProperties, APPLICATION_VERSION_PARAM_NAME)) .description(createAsRequest.getAsInstanceDescription()).serviceInstanceId(serviceInstanceId) .serviceInstanceName(serviceInstanceName).cloudOwner(cloudOwner).cloudRegion(cloudRegion) - .tenantId(tenantId).status(State.NOT_INSTANTIATED).statusUpdatedTime(LocalDateTime.now()); + .tenantId(tenantId).namespace(namespace).status(State.NOT_INSTANTIATED) + .statusUpdatedTime(LocalDateTime.now()); @SuppressWarnings("unchecked") final List<DeploymentItem> deploymentItems = @@ -327,6 +330,15 @@ public class CreateAsTask extends AbstractServiceTask { return asInstId; } + private String getNamespace(final String namespace) { + if (namespace != null && !namespace.isBlank()) { + logger.debug("Namespace found in additionalParams namespace: {}", namespace); + return namespace; + } + logger.debug("No namespace found in additionalParams, will use namespace: {}", DEFAULT_NAMESPACE); + return DEFAULT_NAMESPACE; + } + private String getParamValue(final Map<String, Object> properties, final String key) { final Object object = properties.get(key); if (object != null) { diff --git a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/InstantiateAsTask.java b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/InstantiateAsTask.java index 9fa3100..e378d57 100644 --- a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/InstantiateAsTask.java +++ b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/InstantiateAsTask.java @@ -215,6 +215,8 @@ public class InstantiateAsTask extends AbstractServiceTask { setJobStatus(execution, IN_PROGRESS, "Preparing InstantiateDeploymentItemRequest requests"); final String asInstId = (String) execution.getVariable(AS_INSTANCE_ID_PARAM_NAME); + final AsInst asInst = getAsInst(execution, asInstId); + final InstantiateAsRequest instantiateAsRequest = (InstantiateAsRequest) execution.getVariable(INSTANTIATE_AS_REQUEST_PARAM_NAME); @@ -254,7 +256,8 @@ public class InstantiateAsTask extends AbstractServiceTask { requests.add(new InstantiateDeploymentItemRequest().asInstId(asInstId) .asDeploymentItemInstId(asDeploymentItemInstId).asDeploymentItemName(asDeploymentItem.getName()) .helmArtifactFilePath(artifactFilePath).deploymentOrder(asDeploymentItem.getDeploymentOrder()) - .kubeConfigFile(kubeConfigFile).lifeCycleParameters(lifeCycleParams).releaseName((releaseName))); + .kubeConfigFile(kubeConfigFile).lifeCycleParameters(lifeCycleParams).releaseName((releaseName)) + .namespace(asInst.getNamespace())); }); diff --git a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/InstantiateDeploymentItemRequest.java b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/InstantiateDeploymentItemRequest.java index b7b8598..5eeef53 100644 --- a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/InstantiateDeploymentItemRequest.java +++ b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/InstantiateDeploymentItemRequest.java @@ -41,6 +41,7 @@ public class InstantiateDeploymentItemRequest implements Serializable, Comparabl private Integer deploymentOrder; private Map<String, String> lifeCycleParameters; private String releaseName; + private String namespace; private static final Comparator<Integer> COMPARATOR = Comparator.nullsFirst(Integer::compare); @@ -148,10 +149,23 @@ public class InstantiateDeploymentItemRequest implements Serializable, Comparabl return this; } + public String getNamespace() { + return namespace; + } + + public void setNamespace(final String namespace) { + this.namespace = namespace; + } + + public InstantiateDeploymentItemRequest namespace(final String namespace) { + this.namespace = namespace; + return this; + } + @Override public int hashCode() { return Objects.hash(asInstId, asDeploymentItemInstId, asDeploymentItemName, helmArtifactFilePath, - deploymentOrder, kubeConfigFile, lifeCycleParameters, releaseName); + deploymentOrder, kubeConfigFile, lifeCycleParameters, releaseName, namespace); } @Override @@ -170,7 +184,7 @@ public class InstantiateDeploymentItemRequest implements Serializable, Comparabl && Objects.equals(deploymentOrder, other.deploymentOrder) && Objects.equals(kubeConfigFile, other.kubeConfigFile) && Objects.equals(lifeCycleParameters, other.lifeCycleParameters) - && Objects.equals(releaseName, other.releaseName); + && Objects.equals(releaseName, other.releaseName) && Objects.equals(namespace, other.namespace); } return false; } @@ -187,6 +201,7 @@ public class InstantiateDeploymentItemRequest implements Serializable, Comparabl sb.append(" kubeConfigFile: ").append(toIndentedString(kubeConfigFile)).append("\n"); sb.append(" LifeCycleParameters: ").append(toIndentedString(lifeCycleParameters)).append("\n"); sb.append(" releaseName: ").append(toIndentedString(releaseName)).append("\n"); + sb.append(" namespace: ").append(toIndentedString(namespace)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/InstantiateDeploymentItemTask.java b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/InstantiateDeploymentItemTask.java index 4017946..b8b4893 100644 --- a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/InstantiateDeploymentItemTask.java +++ b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/InstantiateDeploymentItemTask.java @@ -25,6 +25,7 @@ import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.AS_IN import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.KUBE_CONFIG_FILE_PATH_PARAM_NAME; import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.KUBE_KINDS_PARAM_NAME; import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.KUBE_KINDS_RESULT_PARAM_NAME; +import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.NAMESPACE_PARAM_NAME; import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.RELEASE_NAME_PARAM_NAME; import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_DAEMON_SET; import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_DEPLOYMENT; @@ -33,8 +34,6 @@ import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_POD; import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_REPLICA_SET; import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_SERVICE; import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_STATEFUL_SET; - -import io.kubernetes.client.openapi.ApiClient; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -59,6 +58,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import io.kubernetes.client.openapi.ApiClient; /** * @@ -161,13 +161,14 @@ public class InstantiateDeploymentItemTask extends AbstractServiceTask { (InstantiateDeploymentItemRequest) execution.getVariable(INSTANTIATE_REQUEST_PARAM_NAME); final String releaseName = request.getReleaseName(); + final String namespace = request.getNamespace(); try { final Path kubeConfigFilePath = Paths.get(request.getKubeConfigFile()); final Path helmChartPath = Paths.get(request.getHelmArtifactFilePath()); logger.debug("Running helm install with dry run flag"); - helmClient.runHelmChartInstallWithDryRunFlag(releaseName, kubeConfigFilePath, helmChartPath); + helmClient.runHelmChartInstallWithDryRunFlag(namespace, releaseName, kubeConfigFilePath, helmChartPath); } catch (final Exception exception) { final String message = "Unable to run helm install with dry run flag"; logger.error(message, exception); @@ -187,7 +188,10 @@ public class InstantiateDeploymentItemTask extends AbstractServiceTask { final Path kubeConfigFilePath = Paths.get(request.getKubeConfigFile()); final Path helmChartPath = Paths.get(request.getHelmArtifactFilePath()); final String releaseName = request.getReleaseName(); - final List<String> kubeKinds = helmClient.getKubeKinds(releaseName, kubeConfigFilePath, helmChartPath); + final String namespace = request.getNamespace(); + + final List<String> kubeKinds = + helmClient.getKubeKinds(namespace, releaseName, kubeConfigFilePath, helmChartPath); if (kubeKinds.isEmpty()) { abortOperation(execution, @@ -218,14 +222,18 @@ public class InstantiateDeploymentItemTask extends AbstractServiceTask { final InstantiateDeploymentItemRequest request = (InstantiateDeploymentItemRequest) execution.getVariable(INSTANTIATE_REQUEST_PARAM_NAME); + + final String namespace = request.getNamespace(); final String releaseName = request.getReleaseName(); + execution.setVariable(RELEASE_NAME_PARAM_NAME, releaseName); + execution.setVariable(NAMESPACE_PARAM_NAME, namespace); try { final Path kubeConfigFilePath = Paths.get(request.getKubeConfigFile()); final Path helmChartPath = Paths.get(request.getHelmArtifactFilePath()); final Map<String, String> lifeCycleParams = request.getLifeCycleParameters(); - helmClient.installHelmChart(releaseName, kubeConfigFilePath, helmChartPath, lifeCycleParams); + helmClient.installHelmChart(namespace, releaseName, kubeConfigFilePath, helmChartPath, lifeCycleParams); } catch (final Exception exception) { final String message = "Unable to install helm chart: " + request.getHelmArtifactFilePath() + " using kube-config file: " + request.getKubeConfigFile(); @@ -263,6 +271,7 @@ public class InstantiateDeploymentItemTask extends AbstractServiceTask { public void retrieveKubernetesResources(final DelegateExecution execution) { logger.info("Executing retrieveKubernetesResources"); + final String namespace = (String) execution.getVariable(NAMESPACE_PARAM_NAME); final String releaseName = (String) execution.getVariable(RELEASE_NAME_PARAM_NAME); final String kubeConfigFile = (String) execution.getVariable(KUBE_CONFIG_FILE_PATH_PARAM_NAME); @SuppressWarnings("unchecked") @@ -279,25 +288,29 @@ public class InstantiateDeploymentItemTask extends AbstractServiceTask { labelSelector); switch (kind) { case KIND_JOB: - resources.addAll(kubernetesClient.getJobResources(apiClient, labelSelector)); + resources.addAll(kubernetesClient.getJobResources(apiClient, namespace, labelSelector)); break; case KIND_POD: - resources.addAll(kubernetesClient.getPodResources(apiClient, labelSelector)); + resources.addAll(kubernetesClient.getPodResources(apiClient, namespace, labelSelector)); break; case KIND_SERVICE: - resources.addAll(kubernetesClient.getServiceResources(apiClient, labelSelector)); + resources.addAll(kubernetesClient.getServiceResources(apiClient, namespace, labelSelector)); break; case KIND_DEPLOYMENT: - resources.addAll(kubernetesClient.getDeploymentResources(apiClient, labelSelector)); + resources.addAll( + kubernetesClient.getDeploymentResources(apiClient, namespace, labelSelector)); break; case KIND_REPLICA_SET: - resources.addAll(kubernetesClient.getReplicaSetResources(apiClient, labelSelector)); + resources.addAll( + kubernetesClient.getReplicaSetResources(apiClient, namespace, labelSelector)); break; case KIND_DAEMON_SET: - resources.addAll(kubernetesClient.getDaemonSetResources(apiClient, labelSelector)); + resources.addAll( + kubernetesClient.getDaemonSetResources(apiClient, namespace, labelSelector)); break; case KIND_STATEFUL_SET: - resources.addAll(kubernetesClient.getStatefulSetResources(apiClient, labelSelector)); + resources.addAll( + kubernetesClient.getStatefulSetResources(apiClient, namespace, labelSelector)); break; default: logger.warn("Unknown resource type {} found skipping it ...", kind); diff --git a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/MonitorHelmInstallStatusTask.java b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/MonitorHelmInstallStatusTask.java index 4462829..7156d4d 100644 --- a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/MonitorHelmInstallStatusTask.java +++ b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/MonitorHelmInstallStatusTask.java @@ -24,8 +24,8 @@ import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.AS_DE import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.KIND_PARAM_NAME; import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.KUBE_CONFIG_FILE_PATH_PARAM_NAME; import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.KUBE_KINDS_RESULT_PARAM_NAME; +import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.NAMESPACE_PARAM_NAME; import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.RELEASE_NAME_PARAM_NAME; - import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_DAEMON_SET; import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_DEPLOYMENT; import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_JOB; @@ -33,8 +33,6 @@ import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_POD; import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_REPLICA_SET; import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_SERVICE; import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_STATEFUL_SET; - -import io.kubernetes.client.openapi.ApiClient; import java.util.Map; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.onap.so.cnfm.lcm.bpmn.flows.exceptions.KubernetesRequestTimeOut; @@ -46,6 +44,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import io.kubernetes.client.openapi.ApiClient; /** @@ -89,33 +88,35 @@ public class MonitorHelmInstallStatusTask extends AbstractServiceTask { logger.info("Executing isResourceReady "); final String kind = (String) execution.getVariable(KIND_PARAM_NAME); final String releaseName = (String) execution.getVariable(RELEASE_NAME_PARAM_NAME); + final String namespace = (String) execution.getVariable(NAMESPACE_PARAM_NAME); final String kubeConfigFile = (String) execution.getVariable(KUBE_CONFIG_FILE_PATH_PARAM_NAME); final String labelSelector = "app.kubernetes.io/instance=" + releaseName; try { final ApiClient apiClient = kubernetesClientProvider.getApiClient(kubeConfigFile); boolean isReady = false; - logger.debug("Will check if resource type: {} is ready using labelSelector: {}", kind, labelSelector); + logger.debug("Will check if resource type: {} is ready using namespace: {}, labelSelector: {}", kind, + namespace, labelSelector); switch (kind) { case KIND_JOB: - isReady = kubernetesClient.isJobReady(apiClient, labelSelector); + isReady = kubernetesClient.isJobReady(apiClient, namespace, labelSelector); break; case KIND_POD: - isReady = kubernetesClient.isPodReady(apiClient, labelSelector); + isReady = kubernetesClient.isPodReady(apiClient, namespace, labelSelector); break; case KIND_SERVICE: - isReady = kubernetesClient.isServiceReady(apiClient, labelSelector); + isReady = kubernetesClient.isServiceReady(apiClient, namespace, labelSelector); break; case KIND_DEPLOYMENT: - isReady = kubernetesClient.isDeploymentReady(apiClient, labelSelector); + isReady = kubernetesClient.isDeploymentReady(apiClient, namespace, labelSelector); break; case KIND_REPLICA_SET: - isReady = kubernetesClient.isReplicaSetReady(apiClient, labelSelector); + isReady = kubernetesClient.isReplicaSetReady(apiClient, namespace, labelSelector); break; case KIND_DAEMON_SET: - isReady = kubernetesClient.isDaemonSetReady(apiClient, labelSelector); + isReady = kubernetesClient.isDaemonSetReady(apiClient, namespace, labelSelector); break; case KIND_STATEFUL_SET: - isReady = kubernetesClient.isStatefulSetReady(apiClient, labelSelector); + isReady = kubernetesClient.isStatefulSetReady(apiClient, namespace, labelSelector); break; default: diff --git a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/MonitorHelmUnInstallStatusTask.java b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/MonitorHelmUnInstallStatusTask.java index 3f2a1bd..5d2f41c 100644 --- a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/MonitorHelmUnInstallStatusTask.java +++ b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/MonitorHelmUnInstallStatusTask.java @@ -24,8 +24,8 @@ import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.AS_DE import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.KIND_PARAM_NAME; import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.KUBE_CONFIG_FILE_PATH_PARAM_NAME; import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.KUBE_KINDS_RESULT_PARAM_NAME; +import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.NAMESPACE_PARAM_NAME; import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.RELEASE_NAME_PARAM_NAME; - import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_DAEMON_SET; import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_DEPLOYMENT; import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_JOB; @@ -33,8 +33,6 @@ import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_POD; import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_REPLICA_SET; import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_SERVICE; import static org.onap.so.cnfm.lcm.bpmn.flows.Constants.KIND_STATEFUL_SET; - -import io.kubernetes.client.openapi.ApiClient; import java.util.Map; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.onap.so.cnfm.lcm.bpmn.flows.exceptions.KubernetesRequestTimeOut; @@ -46,6 +44,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import io.kubernetes.client.openapi.ApiClient; /** * @author Raviteja Karumuri (raviteja.karumuri@est.tech) @@ -84,6 +83,7 @@ public class MonitorHelmUnInstallStatusTask extends AbstractServiceTask { public void isResourceDeleted(final DelegateExecution execution) { logger.info("Executing isResourceDeleted "); final String kind = (String) execution.getVariable(KIND_PARAM_NAME); + final String namespace = (String) execution.getVariable(NAMESPACE_PARAM_NAME); final String releaseName = (String) execution.getVariable(RELEASE_NAME_PARAM_NAME); final String kubeConfigFile = (String) execution.getVariable(KUBE_CONFIG_FILE_PATH_PARAM_NAME); final String labelSelector = "app.kubernetes.io/instance=" + releaseName; @@ -93,25 +93,25 @@ public class MonitorHelmUnInstallStatusTask extends AbstractServiceTask { logger.debug("Will check if resource type: {} is Deleted using labelSelector: {}", kind, labelSelector); switch (kind) { case KIND_JOB: - isDeleted = kubernetesClient.isJobDeleted(apiClient, labelSelector); + isDeleted = kubernetesClient.isJobDeleted(apiClient, namespace, labelSelector); break; case KIND_POD: - isDeleted = kubernetesClient.isPodDeleted(apiClient, labelSelector); + isDeleted = kubernetesClient.isPodDeleted(apiClient, namespace, labelSelector); break; case KIND_SERVICE: - isDeleted = kubernetesClient.isServiceDeleted(apiClient, labelSelector); + isDeleted = kubernetesClient.isServiceDeleted(apiClient, namespace, labelSelector); break; case KIND_DEPLOYMENT: - isDeleted = kubernetesClient.isDeploymentDeleted(apiClient, labelSelector); + isDeleted = kubernetesClient.isDeploymentDeleted(apiClient, namespace, labelSelector); break; case KIND_REPLICA_SET: - isDeleted = kubernetesClient.isReplicaSetDeleted(apiClient, labelSelector); + isDeleted = kubernetesClient.isReplicaSetDeleted(apiClient, namespace, labelSelector); break; case KIND_DAEMON_SET: - isDeleted = kubernetesClient.isDaemonSetDeleted(apiClient, labelSelector); + isDeleted = kubernetesClient.isDaemonSetDeleted(apiClient, namespace, labelSelector); break; case KIND_STATEFUL_SET: - isDeleted = kubernetesClient.isStatefulSetDeleted(apiClient, labelSelector); + isDeleted = kubernetesClient.isStatefulSetDeleted(apiClient, namespace, labelSelector); break; default: diff --git a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/TerminateAsTask.java b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/TerminateAsTask.java index 4ffcb2d..e863108 100644 --- a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/TerminateAsTask.java +++ b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/TerminateAsTask.java @@ -132,6 +132,8 @@ public class TerminateAsTask extends AbstractServiceTask { final String asInstId = (String) execution.getVariable(AS_INSTANCE_ID_PARAM_NAME); final String kubeConfigFile = (String) execution.getVariable(KUBE_CONFIG_FILE_PARAM_NAME); + final AsInst asInst = getAsInst(execution, asInstId); + final List<AsDeploymentItem> asDeploymentItems = databaseServiceProvider.getAsDeploymentItemByAsInstId(asInstId); @@ -147,6 +149,7 @@ public class TerminateAsTask extends AbstractServiceTask { terminatedeploymentitemrequest.setDeploymentOrder(asDeploymentItem.getDeploymentOrder()); terminatedeploymentitemrequest.setKubeConfigFile(kubeConfigFile); terminatedeploymentitemrequest.setReleaseName(asDeploymentItem.getReleaseName()); + terminatedeploymentitemrequest.setNamespace(asInst.getNamespace()); requests.add(terminatedeploymentitemrequest); diff --git a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/TerminateDeploymentItemRequest.java b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/TerminateDeploymentItemRequest.java index b4fb233..3ef3ebe 100644 --- a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/TerminateDeploymentItemRequest.java +++ b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/TerminateDeploymentItemRequest.java @@ -40,6 +40,7 @@ public class TerminateDeploymentItemRequest implements Serializable, Comparable< private String kubeConfigFile; private Integer deploymentOrder; private String releaseName; + private String namespace; private static final Comparator<Integer> COMPARATOR = Comparator.nullsFirst(Integer::compare).reversed(); @@ -83,6 +84,14 @@ public class TerminateDeploymentItemRequest implements Serializable, Comparable< this.releaseName = releaseName; } + public String getNamespace() { + return namespace; + } + + public void setNamespace(final String namespace) { + this.namespace = namespace; + } + @Override public boolean equals(final Object obj) { if (obj instanceof TerminateDeploymentItemRequest) { @@ -91,15 +100,14 @@ public class TerminateDeploymentItemRequest implements Serializable, Comparable< && Objects.equals(asDeploymentItemInstId, that.asDeploymentItemInstId) && Objects.equals(kubeConfigFile, that.kubeConfigFile) && Objects.equals(deploymentOrder, that.deploymentOrder) - && Objects.equals(releaseName, that.releaseName); + && Objects.equals(releaseName, that.releaseName) && Objects.equals(namespace, that.namespace); } return false; } @Override public int hashCode() { - return Objects.hash(asInstId, asDeploymentItemInstId, kubeConfigFile, deploymentOrder, - releaseName); + return Objects.hash(asInstId, asDeploymentItemInstId, kubeConfigFile, deploymentOrder, releaseName, namespace); } @Override @@ -116,6 +124,7 @@ public class TerminateDeploymentItemRequest implements Serializable, Comparable< sb.append(" deploymentOrder: ").append(toIndentedString(deploymentOrder)).append("\n"); sb.append(" kubeConfigFile: ").append(toIndentedString(kubeConfigFile)).append("\n"); sb.append(" releaseName: ").append(toIndentedString(releaseName)).append("\n"); + sb.append(" namespace: ").append(toIndentedString(namespace)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/TerminateDeploymentItemTask.java b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/TerminateDeploymentItemTask.java index e78f8f0..6c1e187 100644 --- a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/TerminateDeploymentItemTask.java +++ b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/tasks/TerminateDeploymentItemTask.java @@ -24,6 +24,7 @@ import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.AS_DE import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.KUBE_CONFIG_FILE_PATH_PARAM_NAME; import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.KUBE_KINDS_PARAM_NAME; import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.KUBE_KINDS_RESULT_PARAM_NAME; +import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.NAMESPACE_PARAM_NAME; import static org.onap.so.cnfm.lcm.bpmn.flows.CamundaVariableNameConstants.RELEASE_NAME_PARAM_NAME; import java.nio.file.Path; import java.nio.file.Paths; @@ -99,10 +100,11 @@ public class TerminateDeploymentItemTask extends AbstractServiceTask { final TerminateDeploymentItemRequest request = (TerminateDeploymentItemRequest) execution.getVariable(TERMINATE_REQUEST_PARAM_NAME); final String releaseName = request.getReleaseName(); + final String namespace = request.getNamespace(); try { final Path kubeConfigFilePath = Paths.get(request.getKubeConfigFile()); - helmClient.unInstallHelmChart(releaseName, kubeConfigFilePath); + helmClient.unInstallHelmChart(namespace, releaseName, kubeConfigFilePath); } catch (final Exception exception) { final String message = "Failed to uninstall helm chart: " + " using kube-config file: " + request.getKubeConfigFile() + "for reason: " + exception.getMessage(); @@ -135,9 +137,11 @@ public class TerminateDeploymentItemTask extends AbstractServiceTask { final TerminateDeploymentItemRequest request = (TerminateDeploymentItemRequest) execution.getVariable(TERMINATE_REQUEST_PARAM_NAME); final String releaseName = request.getReleaseName(); + final String namespace = request.getNamespace(); final Path kubeConfigFilePath = Paths.get(request.getKubeConfigFile()); final Map<String, Boolean> kubeKindsMap = new HashMap<>(); - final List<String> kinds = helmClient.getKubeKindsUsingManifestCommand(releaseName, kubeConfigFilePath); + final List<String> kinds = + helmClient.getKubeKindsUsingManifestCommand(namespace, releaseName, kubeConfigFilePath); if (kinds.isEmpty()) { abortOperation(execution, "Unable to retrieve kinds from helm release history for releaseName: " + releaseName); @@ -145,6 +149,7 @@ public class TerminateDeploymentItemTask extends AbstractServiceTask { kinds.forEach(kind -> kubeKindsMap.put(kind, false)); execution.setVariable(RELEASE_NAME_PARAM_NAME, releaseName); + execution.setVariable(NAMESPACE_PARAM_NAME, namespace); execution.setVariable(KUBE_KINDS_RESULT_PARAM_NAME, kubeKindsMap); execution.setVariable(KUBE_KINDS_PARAM_NAME, kinds); } |