Repository: ambari Updated Branches: refs/heads/trunk edbd1f7d4 -> 908307f80
AMBARI-7705 - Views: create dtd to help validate view.xml files Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/908307f8 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/908307f8 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/908307f8 Branch: refs/heads/trunk Commit: 908307f804b5de250b7eb74d07b4ff4371f1a4e1 Parents: edbd1f7 Author: tbeerbower <[email protected]> Authored: Wed Oct 8 21:36:59 2014 -0400 Committer: tbeerbower <[email protected]> Committed: Thu Oct 9 17:00:07 2014 -0400 ---------------------------------------------------------------------- ambari-admin/src/main/resources/view.xml | 2 +- ambari-views/src/main/resources/view.xsd | 286 +++++++++++++++++++ .../org/apache/ambari/view/ViewXmlTest.java | 75 +++++ .../src/main/resources/view.xml | 9 +- .../views/slider/src/main/resources/view.xml | 6 +- 5 files changed, 370 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/908307f8/ambari-admin/src/main/resources/view.xml ---------------------------------------------------------------------- diff --git a/ambari-admin/src/main/resources/view.xml b/ambari-admin/src/main/resources/view.xml index 9bb4d8e..6adcf2e 100644 --- a/ambari-admin/src/main/resources/view.xml +++ b/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> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/908307f8/ambari-views/src/main/resources/view.xsd ---------------------------------------------------------------------- diff --git a/ambari-views/src/main/resources/view.xsd b/ambari-views/src/main/resources/view.xsd new file mode 100644 index 0000000..b95e4ec --- /dev/null +++ b/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> http://git-wip-us.apache.org/repos/asf/ambari/blob/908307f8/ambari-views/src/test/java/org/apache/ambari/view/ViewXmlTest.java ---------------------------------------------------------------------- diff --git a/ambari-views/src/test/java/org/apache/ambari/view/ViewXmlTest.java b/ambari-views/src/test/java/org/apache/ambari/view/ViewXmlTest.java new file mode 100644 index 0000000..68200ee --- /dev/null +++ b/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)); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/908307f8/contrib/views/capacity-scheduler/src/main/resources/view.xml ---------------------------------------------------------------------- diff --git a/contrib/views/capacity-scheduler/src/main/resources/view.xml b/contrib/views/capacity-scheduler/src/main/resources/view.xml index f23dae5..4bd33d5 100644 --- a/contrib/views/capacity-scheduler/src/main/resources/view.xml +++ b/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> http://git-wip-us.apache.org/repos/asf/ambari/blob/908307f8/contrib/views/slider/src/main/resources/view.xml ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/resources/view.xml b/contrib/views/slider/src/main/resources/view.xml index 8f8b78b..cf86d6a 100644 --- a/contrib/views/slider/src/main/resources/view.xml +++ b/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/[email protected] </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> \ No newline at end of file +</view>
