You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ad...@apache.org on 2017/11/24 12:40:10 UTC
[28/39] ambari git commit: AMBARI-22297. Fix configurations
import/export issues (adoroszlai)
AMBARI-22297. Fix configurations import/export issues (adoroszlai)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/5f89b952
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/5f89b952
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/5f89b952
Branch: refs/heads/branch-feature-AMBARI-14714-blueprintv2
Commit: 5f89b952c46407bdc0b4403002801d54fd0c38cb
Parents: 5c51dc1
Author: Attila Doroszlai <ad...@hortonworks.com>
Authored: Mon Nov 20 08:43:46 2017 +0100
Committer: Doroszlai, Attila <ad...@hortonworks.com>
Committed: Fri Nov 24 13:30:46 2017 +0100
----------------------------------------------------------------------
.../ambari/server/topology/Configurable.java | 24 +++++++-----
.../ambari/server/topology/Configuration.java | 4 ++
.../server/topology/BlueprintV2FactoryTest.java | 40 ++++++++++++--------
.../test/resources/blueprintv2/blueprintv2.json | 24 ++++++++----
4 files changed, 58 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/5f89b952/ambari-server/src/main/java/org/apache/ambari/server/topology/Configurable.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/Configurable.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/Configurable.java
index bab7da6..af91e40 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/Configurable.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/Configurable.java
@@ -18,13 +18,16 @@
package org.apache.ambari.server.topology;
+import static java.util.Collections.singletonMap;
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
+
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import java.util.stream.Collectors;
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.collect.Lists;
public interface Configurable {
void setConfiguration(Configuration configuration);
@@ -34,10 +37,10 @@ public interface Configurable {
default void setConfigs(Collection<Map<String, Map<String, Map<String, String>>>> configs) {
if (null != configs) {
Map<String, Map<String, String>> allProps = configs.stream().
- filter( map -> map != null && !map.isEmpty() && map.values().iterator().next().get("properties ") != null).
- collect(Collectors.toMap(
+ filter(map -> map != null && !map.isEmpty() && map.values().iterator().next().get(Configuration.PROPERTIES_KEY) != null).
+ collect(toMap(
config -> config.keySet().iterator().next(),
- config -> config.values().iterator().next().get("properties")
+ config -> config.values().iterator().next().get(Configuration.PROPERTIES_KEY)
));
setConfiguration(new Configuration(allProps, new HashMap<>()));
}
@@ -45,11 +48,12 @@ public interface Configurable {
@JsonProperty("configurations")
default Collection<Map<String, Map<String, Map<String, String>>>> getConfigs() {
- Map<String, Map<String, Map<String, String>>> configAsMap = new HashMap<>();
- if (null != getConfiguration()) {
- configAsMap.put("properties", getConfiguration().getProperties());
- }
- return Lists.newArrayList(configAsMap); // TODO replace with Collections.singletonList?
+ Configuration config = getConfiguration();
+ return config != null
+ ? config.getProperties().entrySet().stream()
+ .map(e -> singletonMap(e.getKey(), singletonMap(Configuration.PROPERTIES_KEY, e.getValue())))
+ .collect(toList())
+ : Collections.emptyList();
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/5f89b952/ambari-server/src/main/java/org/apache/ambari/server/topology/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/Configuration.java
index 6adcf18..123237f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/Configuration.java
@@ -30,6 +30,10 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
* Configuration for a topology entity such as a blueprint, hostgroup or cluster.
*/
public class Configuration {
+
+ public static final String PROPERTIES_KEY = "properties";
+ public static final String ATTRIBUTES_KEY = "properties_attributes";
+
/**
* properties for this configuration instance
*/
http://git-wip-us.apache.org/repos/asf/ambari/blob/5f89b952/ambari-server/src/test/java/org/apache/ambari/server/topology/BlueprintV2FactoryTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/topology/BlueprintV2FactoryTest.java b/ambari-server/src/test/java/org/apache/ambari/server/topology/BlueprintV2FactoryTest.java
index 6ae8039..78aa98c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/topology/BlueprintV2FactoryTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/topology/BlueprintV2FactoryTest.java
@@ -17,7 +17,6 @@
*/
package org.apache.ambari.server.topology;
-import static org.easymock.EasyMock.anyString;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
@@ -56,7 +55,7 @@ public class BlueprintV2FactoryTest {
@Before
public void setUp() throws Exception {
StackV2Factory stackFactory = mock(StackV2Factory.class);
- when(stackFactory.create(any(StackId.class), anyString())).thenAnswer(invocation -> {
+ when(stackFactory.create(any(StackId.class), any(String.class))).thenAnswer(invocation -> {
StackId stackId = invocation.getArgumentAt(0, StackId.class);
return new StackV2(stackId.getStackName(), stackId.getStackVersion(), invocation.getArgumentAt(1, String.class),
new HashMap<>(), new HashMap<>(), new HashMap<>(),
@@ -69,12 +68,26 @@ public class BlueprintV2FactoryTest {
@Test
public void testSerialization_parseJsonAsBlueprint() throws Exception {
- BlueprintV2 bp = blueprintFactory.convertFromJson(BLUEPRINTV2_JSON);
+ verifyBlueprintStructure1(blueprintFactory.convertFromJson(BLUEPRINTV2_JSON));
+ }
+
+ private void verifyBlueprintStructure1(BlueprintV2 bp) { // for "blueprintv2.json"
assertEquals(new StackId("HDPCORE", "3.0.0"),
bp.getServiceGroups().iterator().next().getServices().iterator().next().getStack().getStackId());
assertEquals(2, bp.getStackIds().size());
assertEquals(7, bp.getAllServiceIds().size());
assertEquals(2, bp.getServiceGroups().size());
+
+ Service zk1 = bp.getServiceGroup("CoreSG").getServiceByName("ZK1");
+ Map<String, Map<String, String>> expectedProperties = new HashMap<>();
+ Map<String, String> zooCfg = new HashMap<>();
+ zooCfg.put("dataDir", "/zookeeper1");
+ expectedProperties.put("zoo.cfg", zooCfg);
+ Map<String, String> zookeeperEnv = new HashMap<>();
+ zookeeperEnv.put("zk_user", "zkuser1");
+ zookeeperEnv.put("zk_server_heapsize", "256MB");
+ expectedProperties.put("zookeeper-env", zookeeperEnv);
+ assertEquals(expectedProperties, zk1.getConfiguration().getProperties());
}
@Test
@@ -92,23 +105,22 @@ public class BlueprintV2FactoryTest {
assertEquals(1, getAsList(blueprintAsMap, "host_groups").size());
assertEquals("host_group_1", getByPath(blueprintAsMap,
ImmutableList.of("host_groups", 0, "name")));
- System.out.println(blueprintAsMap);
}
@Test
public void testSerialization_serializeBlueprint() throws Exception {
- BlueprintV2 bp = blueprintFactory.convertFromJson(BLUEPRINTV2_JSON);
- String serialized = blueprintFactory.convertToJson(bp);
+ BlueprintV2 bp1 = blueprintFactory.convertFromJson(BLUEPRINTV2_JSON);
+ String serialized = blueprintFactory.convertToJson(bp1);
// Test that serialized blueprint can be read again
- bp = blueprintFactory.convertFromJson(serialized);
- assertEquals(2, bp.getStackIds().size());
- assertEquals(7, bp.getAllServiceIds().size());
- assertEquals(2, bp.getServiceGroups().size());
+ verifyBlueprintStructure1(blueprintFactory.convertFromJson(serialized));
}
@Test
public void testSerialization2_parseJsonAsBlueprint() throws Exception {
- BlueprintV2 bp = blueprintFactory.convertFromJson(BLUEPRINTV2_2_JSON);
+ verifyBlueprintStructure2(blueprintFactory.convertFromJson(BLUEPRINTV2_2_JSON));
+ }
+
+ private void verifyBlueprintStructure2(BlueprintV2 bp) {
assertEquals(new StackId("HDP", "3.0.0"),
bp.getServiceGroups().iterator().next().getServices().iterator().next().getStack().getStackId());
assertEquals(1, bp.getStackIds().size());
@@ -131,7 +143,6 @@ public class BlueprintV2FactoryTest {
assertEquals(1, getAsList(blueprintAsMap, "host_groups").size());
assertEquals("host_group_1", getByPath(blueprintAsMap,
ImmutableList.of("host_groups", 0, "name")));
- System.out.println(blueprintAsMap);
}
@Test
@@ -139,10 +150,7 @@ public class BlueprintV2FactoryTest {
BlueprintV2 bp = blueprintFactory.convertFromJson(BLUEPRINTV2_2_JSON);
String serialized = blueprintFactory.convertToJson(bp);
// Test that serialized blueprint can be read again
- bp = blueprintFactory.convertFromJson(serialized);
- assertEquals(1, bp.getStackIds().size());
- assertEquals(4, bp.getAllServiceIds().size());
- assertEquals(1, bp.getServiceGroups().size());
+ verifyBlueprintStructure2(blueprintFactory.convertFromJson(serialized));
}
private static Map<String, Object> getAsMap(Map<String, Object> parentMap, String key) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/5f89b952/ambari-server/src/test/resources/blueprintv2/blueprintv2.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/resources/blueprintv2/blueprintv2.json b/ambari-server/src/test/resources/blueprintv2/blueprintv2.json
index c5e2541..013b8d7 100644
--- a/ambari-server/src/test/resources/blueprintv2/blueprintv2.json
+++ b/ambari-server/src/test/resources/blueprintv2/blueprintv2.json
@@ -34,9 +34,17 @@
"stack_id": "HDPCORE-3.0.0",
"configurations": [
{
- "zoo.cfg" : {
- "properties" : {
- "dataDir" : "/zookeeper1"
+ "zoo.cfg": {
+ "properties": {
+ "dataDir": "/zookeeper1"
+ }
+ }
+ },
+ {
+ "zookeeper-env": {
+ "properties": {
+ "zk_user": "zkuser1",
+ "zk_server_heapsize": "256MB"
}
}
}
@@ -48,9 +56,9 @@
"stack_id": "HDPCORE-3.0.0",
"configurations": [
{
- "zoo.cfg" : {
- "properties" : {
- "dataDir" : "/zookeeper2"
+ "zoo.cfg": {
+ "properties": {
+ "dataDir": "/zookeeper2"
}
}
}
@@ -78,8 +86,8 @@
"stack_id": "HDPCORE-3.0.0",
"dependencies": [
{
- "service_group" : "CoreSG",
- "service_name" : "ZK2"
+ "service_group": "CoreSG",
+ "service_name": "ZK2"
}
]
},