Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 98C58200D0F for ; Thu, 24 Aug 2017 23:20:55 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 92E2116BA51; Thu, 24 Aug 2017 21:20:55 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D9BEC16BA4F for ; Thu, 24 Aug 2017 23:20:54 +0200 (CEST) Received: (qmail 45355 invoked by uid 500); 24 Aug 2017 21:20:53 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 45343 invoked by uid 99); 24 Aug 2017 21:20:53 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Aug 2017 21:20:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C7F3BE0667; Thu, 24 Aug 2017 21:20:52 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mradhakrishnan@apache.org To: commits@ambari.apache.org Message-Id: <0166798f8ade42a092d430c1948855d0@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: ambari git commit: AMBARI-21808 : Create registry failing with unique constraint violation after a failed registry request (mradhakrishnan) Date: Thu, 24 Aug 2017 21:20:52 +0000 (UTC) archived-at: Thu, 24 Aug 2017 21:20:55 -0000 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 Authored: Thu Aug 24 14:06:00 2017 -0700 Committer: Madhuvanthi Radhakrishnan 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);