diff options
Diffstat (limited to 'participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/HelmClient.java')
-rw-r--r-- | participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/HelmClient.java | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/HelmClient.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/HelmClient.java index 87199688e..6a7c62b2e 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/HelmClient.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/HelmClient.java @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.onap.policy.clamp.acm.participant.kubernetes.exception.ServiceException; import org.onap.policy.clamp.acm.participant.kubernetes.models.ChartInfo; import org.onap.policy.clamp.acm.participant.kubernetes.models.HelmRepository; @@ -70,17 +71,18 @@ public class HelmClient { /** * Add repository if doesn't exist. * @param repo HelmRepository + * @return boolean true of false based on add repo success or failed * @throws ServiceException incase of error */ - public void addRepository(HelmRepository repo) throws ServiceException { - String output = executeCommand(prepareVerifyRepoCommand(repo)); - if (output.isEmpty()) { + public boolean addRepository(HelmRepository repo) throws ServiceException { + if (!verifyHelmRepoAlreadyExist(repo)) { logger.info("Adding repository to helm client"); executeCommand(prepareRepoAddCommand(repo)); logger.debug("Added repository {} to the helm client", repo.getRepoName()); - } else { - logger.info("Repository already exists"); + return true; } + logger.info("Repository already exists"); + return false; } @@ -184,7 +186,10 @@ public class HelmClient { return null; } - private ProcessBuilder prepareRepoAddCommand(HelmRepository repo) { + private ProcessBuilder prepareRepoAddCommand(HelmRepository repo) throws ServiceException { + if (StringUtils.isEmpty(repo.getAddress())) { + throw new ServiceException("Repository Should have valid address"); + } var url = repo.getProtocol() + "://" + repo.getAddress(); if (repo.getPort() != null) { url = url + ":" + repo.getPort(); @@ -202,9 +207,19 @@ public class HelmClient { return new ProcessBuilder().command(helmArguments); } - private ProcessBuilder prepareVerifyRepoCommand(HelmRepository repo) { - List<String> helmArguments = List.of("sh", "-c", "helm repo ls | grep " + repo.getRepoName()); - return new ProcessBuilder().command(helmArguments); + private boolean verifyHelmRepoAlreadyExist(HelmRepository repo) { + try { + logger.debug("Verify the repo already exist in helm repositories"); + List<String> helmArguments = List.of("sh", "-c", "helm repo list | grep " + repo.getRepoName()); + String response = executeCommand(new ProcessBuilder().command(helmArguments)); + if (StringUtils.isEmpty(response)) { + return false; + } + } catch (ServiceException e) { + logger.debug("Repository {} not found:", repo.getRepoName(), e); + return false; + } + return true; } private ProcessBuilder prepareVerifyNamespaceCommand(String namespace) { @@ -265,8 +280,6 @@ public class HelmClient { return false; } return true; - - } private boolean verifyLocalHelmRepo(File localFile) { |