Repository: ambari Updated Branches: refs/heads/branch-feature-AMBARI-14714 9cdbf08d9 -> 289c31f4c
AMBARI-21808 : Create registry failing with unique constraint violation after a failed registry request (mradhakrishnan) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/289c31f4 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/289c31f4 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/289c31f4 Branch: refs/heads/branch-feature-AMBARI-14714 Commit: 289c31f4cd31f621199388265bfcdf5fd15bb42e Parents: 9cdbf08 Author: Madhuvanthi Radhakrishnan <[email protected]> Authored: Thu Aug 24 14:06:00 2017 -0700 Committer: Madhuvanthi Radhakrishnan <[email protected]> Committed: Thu Aug 24 14:19:32 2017 -0700 ---------------------------------------------------------------------- .../controller/internal/RegistryResourceProvider.java | 12 +++++++++++- .../ambari/server/registry/RegistryManagerImpl.java | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/289c31f4/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryResourceProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryResourceProvider.java index 7722168..0ec6e66 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryResourceProvider.java @@ -17,6 +17,8 @@ */ package org.apache.ambari.server.controller.internal; +import java.net.URI; +import java.net.URL; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -40,6 +42,7 @@ import org.apache.ambari.server.controller.spi.SystemException; import org.apache.ambari.server.controller.spi.UnsupportedPropertyException; import org.apache.ambari.server.controller.utilities.PropertyHelper; import org.apache.ambari.server.registry.RegistryType; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang.Validate; /** @@ -220,12 +223,19 @@ public class RegistryResourceProvider extends AbstractControllerResourceProvider Validate.notEmpty(registryUri, "Registry uri should be provided when adding a new software registry"); Validate.isTrue(registryId == null, "Registry ID should not be set when adding a new software registry"); + try { + URI uri = new URI(registryUri); + URL url = uri.toURL(); + String jsonString = IOUtils.toString(url); + }catch(Exception e){ + Validate.isTrue(e == null, e.getMessage() + " Invalid registry uri. Please check."); + } + LOG.info("Received a createRegistry request" + ", registryName=" + registryName + ", registryType=" + registryType + ", registryUri=" + registryUri); - // TODO : Check if the software registry is already registered // TODO : Check for duplicates in the request. // TODO : Authorization?? } http://git-wip-us.apache.org/repos/asf/ambari/blob/289c31f4/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryManagerImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryManagerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryManagerImpl.java index 00e06b3..ef52fa4 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryManagerImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryManagerImpl.java @@ -99,6 +99,9 @@ public class RegistryManagerImpl implements RegistryManager { registryEntity.setRegistryName(registryName); registryEntity.setRegistryUri(registryUri); registryEntity.setRegistryType(registryType); + if(registryDAO.findByName(registryName) != null){ + throw new AmbariException("Registry "+registryName + " already exists"); + } Long registryId = registryDAO.create(registryEntity); registryEntity.setRegistryId(registryId); Registry registry = registryFactory.create(registryEntity);
