You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by al...@apache.org on 2015/11/20 02:31:50 UTC
ambari git commit: AMBARI-13951. Service install will fail if the
property-type attribute of any service config property has a value in a stack
not known to ambari-server (Sebastian Toader via alejandro)
Repository: ambari
Updated Branches:
refs/heads/trunk 15b12bc71 -> 3d3af0bce
AMBARI-13951. Service install will fail if the property-type attribute of any service config property has a value in a stack not known to ambari-server (Sebastian Toader via alejandro)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/3d3af0bc
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/3d3af0bc
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/3d3af0bc
Branch: refs/heads/trunk
Commit: 3d3af0bce733a13b81c6c3752648e110f976c441
Parents: 15b12bc
Author: Alejandro Fernandez <af...@hortonworks.com>
Authored: Thu Nov 19 17:29:24 2015 -0800
Committer: Alejandro Fernandez <af...@hortonworks.com>
Committed: Thu Nov 19 17:29:28 2015 -0800
----------------------------------------------------------------------
.../ambari/server/state/PropertyInfo.java | 11 +++++
.../ambari/server/state/PropertyInfoTest.java | 42 +++++++++++++++++++-
2 files changed, 51 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/3d3af0bc/ambari-server/src/main/java/org/apache/ambari/server/state/PropertyInfo.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/PropertyInfo.java b/ambari-server/src/main/java/org/apache/ambari/server/state/PropertyInfo.java
index bc90a8c..53837db 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/PropertyInfo.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/PropertyInfo.java
@@ -19,9 +19,12 @@
package org.apache.ambari.server.state;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
import org.apache.ambari.server.controller.StackConfigurationResponse;
import org.w3c.dom.Element;
+import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyElement;
@@ -72,6 +75,14 @@ public class PropertyInfo {
private Set<PropertyDependencyInfo> dependedByProperties =
new HashSet<PropertyDependencyInfo>();
+ //This method is called after all the properties (except IDREF) are unmarshalled for this object,
+ //but before this object is set to the parent object.
+ void afterUnmarshal(Unmarshaller unmarshaller, Object parent) {
+ // Iterate through propertyTypes and remove any unrecognized property types
+ // that may be introduced with custom service definitions
+ propertyTypes.remove(null);
+ }
+
public PropertyInfo() {
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/3d3af0bc/ambari-server/src/test/java/org/apache/ambari/server/state/PropertyInfoTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/PropertyInfoTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/PropertyInfoTest.java
index 31cf80b..b11c5d8 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/PropertyInfoTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/PropertyInfoTest.java
@@ -17,22 +17,27 @@
*/
package org.apache.ambari.server.state;
-import org.apache.ambari.server.state.stack.StackMetainfoXml;
+import com.google.common.collect.Sets;
import org.junit.Test;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
+import javax.xml.transform.stream.StreamSource;
+import java.io.ByteArrayInputStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
public class PropertyInfoTest {
@@ -89,4 +94,37 @@ public class PropertyInfoTest {
assertEquals("value1", attributes.get("foo"));
assertEquals("value2", attributes.get("bar"));
}
+
+ @Test
+ public void testUnknownPropertyType() throws Exception {
+ // Given
+ String xml =
+ "<property>\n"+
+ " <name>prop_name</name>\n" +
+ " <value>prop_val</value>\n" +
+ " <property-type>PASSWORD USER UNRECOGNIZED_TYPE</property-type>\n" +
+ " <description>test description</description>\n" +
+ "</property>";
+
+
+ // When
+ PropertyInfo propertyInfo = propertyInfoFrom(xml);
+
+ // Then
+ Set<PropertyInfo.PropertyType> expectedPropertyTypes = Sets.newHashSet(PropertyInfo.PropertyType.PASSWORD, PropertyInfo.PropertyType.USER);
+
+ assertEquals(expectedPropertyTypes, propertyInfo.getPropertyTypes());
+ }
+
+ public static PropertyInfo propertyInfoFrom(String xml) throws JAXBException {
+ JAXBContext jaxbCtx = JAXBContext.newInstance(PropertyInfo.class);
+ Unmarshaller unmarshaller = jaxbCtx.createUnmarshaller();
+
+ return unmarshaller.unmarshal(
+ new StreamSource(
+ new ByteArrayInputStream(xml.getBytes())
+ )
+ , PropertyInfo.class
+ ).getValue();
+ }
}
\ No newline at end of file