You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by tb...@apache.org on 2014/11/04 17:54:08 UTC
git commit: AMBARI-8136 - Views: creating instance of same name
overwrites existing (tbeerbower)
Repository: ambari
Updated Branches:
refs/heads/trunk 5f05539b1 -> dac8a9d75
AMBARI-8136 - Views: creating instance of same name overwrites existing (tbeerbower)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/dac8a9d7
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/dac8a9d7
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/dac8a9d7
Branch: refs/heads/trunk
Commit: dac8a9d7533f6d433935268594765b67b216adde
Parents: 5f05539
Author: tbeerbower <tb...@hortonworks.com>
Authored: Tue Nov 4 11:53:43 2014 -0500
Committer: tbeerbower <tb...@hortonworks.com>
Committed: Tue Nov 4 11:53:58 2014 -0500
----------------------------------------------------------------------
.../internal/ViewInstanceResourceProvider.java | 12 ++++++++----
.../internal/ViewInstanceResourceProviderTest.java | 4 ----
2 files changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/dac8a9d7/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
index 3d7f6db..3f62cc3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
@@ -259,7 +259,7 @@ public class ViewInstanceResourceProvider extends AbstractResourceProvider {
}
// Convert a map of properties to a view instance entity.
- private ViewInstanceEntity toEntity(Map<String, Object> properties) throws AmbariException {
+ private ViewInstanceEntity toEntity(Map<String, Object> properties, boolean update) throws AmbariException {
String name = (String) properties.get(INSTANCE_NAME_PROPERTY_ID);
if (name == null || name.isEmpty()) {
throw new IllegalArgumentException("View instance name must be provided");
@@ -283,7 +283,11 @@ public class ViewInstanceResourceProvider extends AbstractResourceProvider {
throw new IllegalArgumentException("View name " + viewName + " does not exist.");
}
- ViewInstanceEntity viewInstanceEntity = viewRegistry.getInstanceDefinition(commonViewName, version, name);
+ ViewInstanceEntity viewInstanceEntity = null;
+
+ if (update) {
+ viewInstanceEntity = viewRegistry.getInstanceDefinition(commonViewName, version, name);
+ }
if (viewInstanceEntity == null) {
viewInstanceEntity = new ViewInstanceEntity();
@@ -346,7 +350,7 @@ public class ViewInstanceResourceProvider extends AbstractResourceProvider {
public Void invoke() throws AmbariException {
try {
ViewRegistry viewRegistry = ViewRegistry.getInstance();
- ViewInstanceEntity instanceEntity = toEntity(properties);
+ ViewInstanceEntity instanceEntity = toEntity(properties, false);
ViewEntity viewEntity = instanceEntity.getViewEntity();
String viewName = viewEntity.getCommonName();
@@ -380,7 +384,7 @@ public class ViewInstanceResourceProvider extends AbstractResourceProvider {
@Override
public Void invoke() throws AmbariException {
- ViewInstanceEntity instance = toEntity(properties);
+ ViewInstanceEntity instance = toEntity(properties, true);
ViewEntity view = instance.getViewEntity();
if (includeInstance(view.getCommonName(), view.getVersion(), instance.getInstanceName(), false)) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/dac8a9d7/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProviderTest.java
index a8b4c8d..023cba5 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProviderTest.java
@@ -143,8 +143,6 @@ public class ViewInstanceResourceProviderTest {
expect(singleton.instanceExists(viewInstanceEntity)).andReturn(false);
expect(singleton.instanceExists(viewInstanceEntity2)).andReturn(false);
expect(singleton.getDefinition("V1", "1.0.0")).andReturn(viewEntity).anyTimes();
- expect(singleton.getInstanceDefinition("V1", "1.0.0", "I1")).andReturn(viewInstanceEntity);
- expect(singleton.getInstanceDefinition("V1", "1.0.0", "I1")).andReturn(viewInstanceEntity2);
expect(singleton.getDefinition("V1", null)).andReturn(viewEntity).anyTimes();
Capture<Map<String, String>> captureProperties = new Capture<Map<String, String>>();
@@ -203,7 +201,6 @@ public class ViewInstanceResourceProviderTest {
expect(singleton.instanceExists(viewInstanceEntity)).andReturn(true);
expect(singleton.getDefinition("V1", "1.0.0")).andReturn(viewEntity).anyTimes();
- expect(singleton.getInstanceDefinition("V1", "1.0.0", "I1")).andReturn(viewInstanceEntity);
expect(singleton.getDefinition("V1", null)).andReturn(viewEntity);
expect(singleton.checkAdmin()).andReturn(true);
@@ -242,7 +239,6 @@ public class ViewInstanceResourceProviderTest {
viewInstanceEntity.setName("I1");
viewInstanceEntity.setViewEntity(viewEntity);
- expect(singleton.getInstanceDefinition("V1", "1.0.0", "I1")).andReturn(viewInstanceEntity);
expect(singleton.getDefinition("V1", "1.0.0")).andReturn(viewEntity).anyTimes();
expect(singleton.getDefinition("V1", null)).andReturn(viewEntity);