فهرست منبع

AMBARI-7705 - Views: create dtd to help validate view.xml files

tbeerbower 10 سال پیش
والد
کامیت
908307f804

+ 1 - 1
ambari-admin/src/main/resources/view.xml

@@ -21,7 +21,7 @@ limitations under the License. Kerberos, LDAP, Custom. Binary/Htt
   <system>true</system>
   <instance>
     <name>INSTANCE</name>
-    <visible>false</visible>
     <description>This view provides administration capabilities for Ambari</description>
+    <visible>false</visible>
   </instance>
 </view>

+ 286 - 0
ambari-views/src/main/resources/view.xsd

@@ -0,0 +1,286 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+  <xs:complexType name="ParameterType">
+    <xs:annotation>
+      <xs:documentation>Defines a configuration parameter that is used to when creating a view instance.
+      </xs:documentation>
+    </xs:annotation>
+    <xs:sequence>
+      <xs:element type="xs:string" name="name" minOccurs="1" maxOccurs="1">
+        <xs:annotation>
+          <xs:documentation>The name of the configuration parameter.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+      <xs:element type="xs:string" name="description" minOccurs="0" maxOccurs="1">
+        <xs:annotation>
+          <xs:documentation>The description of the configuration parameter.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+      <xs:element type="xs:boolean" name="required" minOccurs="0" maxOccurs="1" default="false">
+        <xs:annotation>
+          <xs:documentation>If true, the configuration parameter is required in order to create a view instance.  The default is false (not required).</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+      <xs:element type="xs:boolean" name="masked" minOccurs="0" maxOccurs="1" default="false">
+        <xs:annotation>
+          <xs:documentation>Indicated this parameter value is to be "masked" in the Ambari Web UI (i.e. not shown in the clear). Omitting this element default to not-masked. Otherwise, if true, the parameter value will be "masked" in the Web UI.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+    </xs:sequence>
+  </xs:complexType>
+
+  <xs:complexType name="ResourceType">
+    <xs:annotation>
+      <xs:documentation>Defines a resource that is exposed by the view.</xs:documentation>
+    </xs:annotation>
+    <xs:sequence>
+      <xs:element type="xs:string" name="name" minOccurs="1" maxOccurs="1">
+        <xs:annotation>
+          <xs:documentation>The name of the resource. This will be the resource endpoint name of the view instance.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+      <xs:element type="xs:string" name="plural-name" minOccurs="0" maxOccurs="1">
+        <xs:annotation>
+          <xs:documentation>The plural name of the resource.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+      <xs:element type="xs:string" name="id-property" minOccurs="0" maxOccurs="1">
+        <xs:annotation>
+          <xs:documentation>The name of the resource-class attribute which uniquely identifies this resource.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+      <xs:element type="xs:string" name="resource-class" minOccurs="0" maxOccurs="1">
+        <xs:annotation>
+          <xs:documentation>The JavaBean resource class.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+      <xs:element type="xs:string" name="provider-class" minOccurs="0" maxOccurs="1">
+        <xs:annotation>
+          <xs:documentation>The Ambari ResourceProvider implementation class.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+      <xs:element type="xs:string" name="service-class" minOccurs="1" maxOccurs="1">
+        <xs:annotation>
+          <xs:documentation>The JAX-RS annotated resource service class.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+      <xs:element type="xs:string" name="sub-resource-name" minOccurs="0" maxOccurs="unbounded">
+        <xs:annotation>
+          <xs:documentation>The sub-resource name.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+    </xs:sequence>
+  </xs:complexType>
+
+  <xs:complexType name="PermissionType">
+    <xs:annotation>
+      <xs:documentation>Defines a custom permission for the view.</xs:documentation>
+    </xs:annotation>
+    <xs:sequence>
+      <xs:element type="xs:string" name="name" minOccurs="1" maxOccurs="1">
+        <xs:annotation>
+          <xs:documentation>The unique custom permission name.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+      <xs:element type="xs:string" name="description" minOccurs="1" maxOccurs="1">
+        <xs:annotation>
+          <xs:documentation>The description of the custom view permission.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+    </xs:sequence>
+  </xs:complexType>
+
+  <xs:complexType name="PersistenceEntityType">
+    <xs:annotation>
+      <xs:documentation>Defines a persistence entity used by the view.</xs:documentation>
+    </xs:annotation>
+    <xs:sequence>
+      <xs:element type="xs:string" name="class" minOccurs="1" maxOccurs="1">
+        <xs:annotation>
+          <xs:documentation>The class name of the persistence entity JavaBean.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+      <xs:element type="xs:string" name="id-property" minOccurs="1" maxOccurs="1">
+        <xs:annotation>
+          <xs:documentation>The name of the entity class attribute which uniquely identifies this entity.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+    </xs:sequence>
+  </xs:complexType>
+
+  <xs:complexType name="PersistenceType">
+    <xs:annotation>
+      <xs:documentation>Defines the persistence entities used by the view.</xs:documentation>
+    </xs:annotation>
+    <xs:sequence>
+      <xs:element type="PersistenceEntityType" name="entity" minOccurs="0" maxOccurs="unbounded">
+        <xs:annotation>
+          <xs:documentation>Defines a persistence entity used by the view.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+    </xs:sequence>
+  </xs:complexType>
+
+  <xs:complexType name="InstancePropertyType">
+    <xs:annotation>
+      <xs:documentation>Defines a property value for a static instance of the view.</xs:documentation>
+    </xs:annotation>
+    <xs:sequence>
+      <xs:element type="xs:string" name="key" minOccurs="1" maxOccurs="1">
+        <xs:annotation>
+          <xs:documentation>The configuration parameter name.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+      <xs:element type="xs:string" name="value" minOccurs="1" maxOccurs="1">
+        <xs:annotation>
+          <xs:documentation>The configuration parameter value.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+    </xs:sequence>
+  </xs:complexType>
+
+  <xs:complexType name="InstanceType">
+    <xs:annotation>
+      <xs:documentation>Defines a static instance of the view.</xs:documentation>
+    </xs:annotation>
+    <xs:sequence>
+      <xs:element type="xs:string" name="name" minOccurs="1" maxOccurs="1">
+        <xs:annotation>
+          <xs:documentation>The unique name of the view instance.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+      <xs:element type="xs:string" name="label" minOccurs="0" maxOccurs="1">
+        <xs:annotation>
+          <xs:documentation>The display label of the view instance. If not set, the view definition label is used.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+      <xs:element type="xs:string" name="description" minOccurs="0" maxOccurs="1">
+        <xs:annotation>
+          <xs:documentation>The description of the view instance. If not set, the view definition description is used.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+      <xs:element type="xs:string" name="icon64" minOccurs="0" maxOccurs="1">
+        <xs:annotation>
+          <xs:documentation>Overrides the view icon64 for this specific view instance.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+      <xs:element type="xs:string" name="icon" minOccurs="0" maxOccurs="1">
+        <xs:annotation>
+          <xs:documentation>Overrides the view icon for this specific view instance.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+      <xs:element type="xs:boolean" name="visible" minOccurs="0" maxOccurs="1" default="true">
+        <xs:annotation>
+          <xs:documentation>If true, for the view instance to show up in the users view instance list.  The default value is true.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+      <xs:element type="InstancePropertyType" name="property" minOccurs="0" maxOccurs="unbounded">
+        <xs:annotation>
+          <xs:documentation>Specifies configuration parameters values for the view instance.</xs:documentation>
+        </xs:annotation>
+      </xs:element>
+    </xs:sequence>
+  </xs:complexType>
+
+  <xs:element name="view">
+    <xs:annotation>
+      <xs:documentation>Defines a view.</xs:documentation>
+    </xs:annotation>
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element type="xs:string" name="name" minOccurs="1" maxOccurs="1">
+          <xs:annotation>
+            <xs:documentation>The unique name of the view.</xs:documentation>
+          </xs:annotation>
+        </xs:element>
+        <xs:element type="xs:string" name="label" minOccurs="0" maxOccurs="1">
+          <xs:annotation>
+            <xs:documentation>The display label of the view.</xs:documentation>
+          </xs:annotation>
+        </xs:element>
+        <xs:element type="xs:string" name="version" minOccurs="1" maxOccurs="1">
+          <xs:annotation>
+            <xs:documentation>The version of the view.</xs:documentation>
+          </xs:annotation>
+        </xs:element>
+        <xs:element type="xs:string" name="description" minOccurs="0" maxOccurs="1">
+          <xs:annotation>
+            <xs:documentation>The description of the view.</xs:documentation>
+          </xs:annotation>
+        </xs:element>
+        <xs:element type="xs:string" name="icon64" minOccurs="0" maxOccurs="1">
+          <xs:annotation>
+            <xs:documentation>The 64x64 icon to display for this view. If this property is not set, the 32x32 sized icon
+              will be used.
+            </xs:documentation>
+          </xs:annotation>
+        </xs:element>
+        <xs:element type="xs:string" name="icon" minOccurs="0" maxOccurs="1">
+          <xs:annotation>
+            <xs:documentation>The 32x32 icon to display for this view. Suggested size is 32x32 and will be displayed as
+              8x8 and 16x16 as necessary. If this property is not set, a default view framework icon is used.
+            </xs:documentation>
+          </xs:annotation>
+        </xs:element>
+        <xs:element type="xs:boolean" name="system" minOccurs="0" maxOccurs="1" default="false">
+          <xs:annotation>
+            <xs:documentation>Indicates whether or not this is a system view.</xs:documentation>
+          </xs:annotation>
+        </xs:element>
+        <xs:element type="xs:string" name="view-class" minOccurs="0" maxOccurs="1">
+          <xs:annotation>
+            <xs:documentation>The View class to receive framework events.</xs:documentation>
+          </xs:annotation>
+        </xs:element>
+        <xs:element type="xs:string" name="masker-class" minOccurs="0" maxOccurs="1">
+          <xs:annotation>
+            <xs:documentation>The Masker class for masking view parameters.</xs:documentation>
+          </xs:annotation>
+        </xs:element>
+        <xs:element type="ParameterType" name="parameter" minOccurs="0" maxOccurs="unbounded">
+          <xs:annotation>
+            <xs:documentation>Defines a configuration parameter that is used to when creating a view instance.
+            </xs:documentation>
+          </xs:annotation>
+        </xs:element>
+        <xs:element type="ResourceType" name="resource" minOccurs="0" maxOccurs="unbounded">
+          <xs:annotation>
+            <xs:documentation>Defines a resource that is exposed by the view.</xs:documentation>
+          </xs:annotation>
+        </xs:element>
+        <xs:element type="PermissionType" name="permission" minOccurs="0" maxOccurs="unbounded">
+          <xs:annotation>
+            <xs:documentation>Defines a custom permission for the view.</xs:documentation>
+          </xs:annotation>
+        </xs:element>
+        <xs:element type="PersistenceType" name="persistence" minOccurs="0" maxOccurs="unbounded">
+          <xs:annotation>
+            <xs:documentation>Defines the persistence entities used by the view.</xs:documentation>
+          </xs:annotation>
+        </xs:element>
+        <xs:element type="InstanceType" name="instance" minOccurs="0" maxOccurs="unbounded">
+          <xs:annotation>
+            <xs:documentation>Defines a static instance of the view.</xs:documentation>
+          </xs:annotation>
+        </xs:element>
+      </xs:sequence>
+    </xs:complexType>
+  </xs:element>
+</xs:schema>

+ 75 - 0
ambari-views/src/test/java/org/apache/ambari/view/ViewXmlTest.java

@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.view;
+
+import org.junit.Test;
+
+import javax.xml.XMLConstants;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import java.io.File;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * view.xml related tests.
+ */
+public class ViewXmlTest {
+
+  @Test
+  public void testValidateViewXmls() throws Exception {
+
+    List<File> viewXmlFiles = new LinkedList<File>();
+
+    File ambariViewsDir = new File("."); //ambari-views
+    File xsdFile        = new File("./target/classes/view.xsd");
+
+    // validate each of the view.xml files under ambari-views
+    for (File file : getViewXmlFiles(viewXmlFiles, ambariViewsDir.listFiles())) {
+      validateViewXml(file, xsdFile);
+    }
+  }
+
+  private List<File> getViewXmlFiles(List<File> viewXmlFiles, File[] files) throws Exception{
+
+    if (files != null) {
+      for (File file : files) {
+        if (file.isDirectory()) {
+          getViewXmlFiles(viewXmlFiles, file.listFiles());
+        } else {
+          String absolutePath = file.getAbsolutePath();
+
+          if (absolutePath.endsWith("/src/main/resources/view.xml")) {
+            viewXmlFiles.add(file);
+          }
+        }
+      }
+    }
+    return viewXmlFiles;
+  }
+
+  private void validateViewXml(File xmlFile, File xsdFile) throws Exception {
+    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+
+    Schema schema = schemaFactory.newSchema(xsdFile);
+
+    schema.newValidator().validate(new StreamSource(xmlFile));
+  }
+}

+ 5 - 4
contrib/views/capacity-scheduler/src/main/resources/view.xml

@@ -38,12 +38,13 @@
         <!-- <hidden>true</hidden> -->
     </parameter>
 
+    <resource>
+      <name>scheduler</name>
+      <service-class>org.apache.ambari.view.capacityscheduler.CapacitySchedulerService</service-class>
+    </resource>
+
     <instance>
         <name>Scheduler</name>
     </instance>
 
-    <resource>
-        <name>scheduler</name>
-        <service-class>org.apache.ambari.view.capacityscheduler.CapacitySchedulerService</service-class>
-    </resource>
 </view>

+ 3 - 3
contrib/views/slider/src/main/resources/view.xml

@@ -46,14 +46,14 @@ limitations under the License. Kerberos, LDAP, Custom. Binary/Htt
 		<description>Kerberos principal associated with this view. For
 			example: ambari/_HOST@EXAMPLE.COM
 		</description>
-		<required>optional</required>
+		<required>false</required>
 	</parameter>
 	<parameter>
 		<name>view.kerberos.principal.keytab</name>
 		<description>Path to the Kerberos principal keytab used for view's
 			user. For example: /etc/security/keytabs/ambari.headless.keytab
 		</description>
-		<required>optional</required>
+		<required>false</required>
 	</parameter>
   <resource>
     <name>status</name>
@@ -75,4 +75,4 @@ limitations under the License. Kerberos, LDAP, Custom. Binary/Htt
     <provider-class>org.apache.ambari.view.slider.SliderAppTypesResourceProvider</provider-class>
     <service-class>org.apache.ambari.view.slider.rest.SliderAppTypesResource</service-class>
   </resource>
-</view>
+</view>