Repository: ambari Updated Branches: refs/heads/trunk dddbaaabf -> 9355f8f7c
Revert "AMBARI-6777. Views: view.xml instance changes are not picked up on redeploy. Unit test failure." This reverts commit 2585179a80c3cdefa7fa69be09689308150ffddb. Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9355f8f7 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9355f8f7 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9355f8f7 Branch: refs/heads/trunk Commit: 9355f8f7c3d3d186bb344605f6a909e0dd78f881 Parents: dddbaaa Author: Siddharth Wagle <[email protected]> Authored: Thu Aug 7 11:08:52 2014 -0700 Committer: Siddharth Wagle <[email protected]> Committed: Thu Aug 7 11:08:52 2014 -0700 ---------------------------------------------------------------------- .../server/orm/entities/ViewInstanceEntity.java | 25 ---- .../server/upgrade/UpgradeCatalog170.java | 2 - .../apache/ambari/server/view/ViewRegistry.java | 126 +++---------------- .../main/resources/Ambari-DDL-MySQL-CREATE.sql | 2 +- .../main/resources/Ambari-DDL-Oracle-CREATE.sql | 2 +- .../resources/Ambari-DDL-Postgres-CREATE.sql | 2 +- .../Ambari-DDL-Postgres-EMBEDDED-CREATE.sql | 2 +- .../ambari/server/view/ViewRegistryTest.java | 84 +++++-------- 8 files changed, 54 insertions(+), 191 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/9355f8f7/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java index 78afdff..fa303c7 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java @@ -125,13 +125,6 @@ public class ViewInstanceEntity implements ViewInstanceDefinition { private String icon64; /** - * The XML driven instance flag. - */ - @Column(name="xml_driven") - @Basic - private char xmlDriven = 'N'; - - /** * The instance properties. */ @OneToMany(cascade = CascadeType.ALL, mappedBy = "viewInstance") @@ -405,24 +398,6 @@ public class ViewInstanceEntity implements ViewInstanceDefinition { } /** - * Get the xml driven flag. - * - * @return the xml driven flag - */ - public boolean isXmlDriven() { - return xmlDriven == 'y' || xmlDriven == 'Y'; - } - - /** - * Set the xml driven flag. - * - * @param xmlDriven the xml driven flag - */ - public void setXmlDriven(boolean xmlDriven) { - this.xmlDriven = (xmlDriven) ? 'Y' : 'N'; - } - - /** * Get the instance properties. * * @return the instance properties http://git-wip-us.apache.org/repos/asf/ambari/blob/9355f8f7/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java index dba6ef7..9fbed00 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java @@ -186,8 +186,6 @@ public class UpgradeCatalog170 extends AbstractUpgradeCatalog { Integer.class, 1, 1, false)); dbAccessor.addColumn("viewinstance", new DBColumnInfo("resource_id", Long.class, 1, 1, false)); - dbAccessor.addColumn("viewinstance", new DBColumnInfo("xml_driven", - Character.class, 1, null, true)); dbAccessor.addColumn("clusters", new DBColumnInfo("resource_id", Long.class, 1, 1, false)); http://git-wip-us.apache.org/repos/asf/ambari/blob/9355f8f7/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java index b3eece2..58e68c2 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java @@ -76,7 +76,6 @@ import javax.xml.bind.Unmarshaller; import java.beans.IntrospectionException; import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -411,17 +410,13 @@ public class ViewRegistry { // extract the archive and get the class loader ClassLoader cl = extractViewArchive(archiveFile, helper.getFile(archivePath)); - viewConfig = helper.getViewConfigFromExtractedArchive(archivePath); - ViewEntity viewDefinition = createViewDefinition(viewConfig, configuration, cl, archivePath); Set<ViewInstanceEntity> instanceDefinitions = new HashSet<ViewInstanceEntity>(); for (InstanceConfig instanceConfig : viewConfig.getInstances()) { try { - ViewInstanceEntity instanceEntity = createViewInstanceDefinition(viewConfig, viewDefinition, instanceConfig); - instanceEntity.setXmlDriven(true); - instanceDefinitions.add(instanceEntity); + instanceDefinitions.add(createViewInstanceDefinition(viewConfig, viewDefinition, instanceConfig)); } catch (Exception e) { LOG.error("Caught exception adding view instance for view " + viewDefinition.getViewName(), e); @@ -534,9 +529,6 @@ public class ViewRegistry { ViewInstanceEntity entity = getInstanceDefinition(viewName, version, instanceName); if (entity != null) { - if (entity.isXmlDriven()) { - throw new IllegalStateException("View instances defined via xml can't be updated through api requests"); - } if (LOG.isDebugEnabled()) { LOG.debug("Updating view instance " + viewName + "/" + version + "/" + instanceName); @@ -572,9 +564,8 @@ public class ViewRegistry { * Uninstall a view instance for the view with the given view name. * * @param instanceEntity the view instance entity - * @throws IllegalStateException if the given instance is not in a valid state */ - public void uninstallViewInstance(ViewInstanceEntity instanceEntity) throws IllegalStateException { + public void uninstallViewInstance(ViewInstanceEntity instanceEntity) { ViewEntity viewEntity = getDefinition(instanceEntity.getViewName()); if (viewEntity != null) { @@ -583,9 +574,7 @@ public class ViewRegistry { String version = viewEntity.getVersion(); if (getInstanceDefinition(viewName, version, instanceName) != null) { - if (instanceEntity.isXmlDriven()) { - throw new IllegalStateException("View instances defined via xml can't be deleted through api requests"); - } + if (LOG.isDebugEnabled()) { LOG.debug("Deleting view instance " + viewName + "/" + version + "/" +instanceName); @@ -980,29 +969,13 @@ public class ViewRegistry { } } - /** - * Sync given view with data in DB. Ensures that view data in DB is updated, - * all instances changes from xml config are reflected to DB - * - * @param view view config from xml - * @param instanceDefinitions view instances from xml - * @throws Exception - */ + // sync the given view with the db private void syncView(ViewEntity view, Set<ViewInstanceEntity> instanceDefinitions) throws Exception { String viewName = view.getName(); - // get or create an admin resource type to represent this view - ResourceTypeEntity resourceTypeEntity = resourceTypeDAO.findByName(viewName); - if (resourceTypeEntity == null) { - resourceTypeEntity = new ResourceTypeEntity(); - resourceTypeEntity.setName(view.getName()); - resourceTypeDAO.create(resourceTypeEntity); - } - view.setResourceType(resourceTypeEntity); - ViewEntity persistedView = viewDAO.findByName(viewName); // if the view is not yet persisted ... @@ -1010,31 +983,13 @@ public class ViewRegistry { if (LOG.isDebugEnabled()) { LOG.debug("Creating View " + viewName + "."); } - - for( ViewInstanceEntity instance : view.getInstances()) { - - // create an admin resource to represent this view instance - ResourceEntity resourceEntity = new ResourceEntity(); - resourceEntity.setResourceType(resourceTypeEntity); - resourceDAO.create(resourceEntity); - - instance.setResource(resourceEntity); - } // ... merge it - viewDAO.merge(view); - - persistedView = viewDAO.findByName(viewName); - if (persistedView == null) { - String message = "View " + viewName + " can not be found."; - - LOG.error(message); - throw new IllegalStateException(message); - } + persistedView = viewDAO.merge(view); } - Map<String, ViewInstanceEntity> xmlInstanceEntityMap = new HashMap<String, ViewInstanceEntity>(); + Map<String, ViewInstanceEntity> instanceEntityMap = new HashMap<String, ViewInstanceEntity>(); for( ViewInstanceEntity instance : view.getInstances()) { - xmlInstanceEntityMap.put(instance.getName(), instance); + instanceEntityMap.put(instance.getName(), instance); } view.setResourceType(persistedView.getResourceType()); @@ -1047,12 +1002,7 @@ public class ViewRegistry { ViewInstanceEntity instance = view.getInstanceDefinition(instanceName); - if (persistedInstance.isXmlDriven() && !xmlInstanceEntityMap.containsKey(instanceName)) { - instanceDAO.remove(persistedInstance); - xmlInstanceEntityMap.remove(instanceName); - continue; - } - xmlInstanceEntityMap.remove(instanceName); + instanceEntityMap.remove(instanceName); // if the persisted instance is not in the registry ... if (instance == null) { @@ -1063,39 +1013,23 @@ public class ViewRegistry { } instance.setViewInstanceId(persistedInstance.getViewInstanceId()); - if (instance.isXmlDriven()) { - // override db data with data from {@InstanceConfig} - persistedInstance.setLabel(instance.getLabel()); - persistedInstance.setDescription(instance.getDescription()); - persistedInstance.setVisible(instance.isVisible()); - persistedInstance.setIcon(instance.getIcon()); - persistedInstance.setIcon64(instance.getIcon64()); - persistedInstance.setProperties(instance.getProperties()); - - instanceDAO.merge(persistedInstance); - } else { - // apply the persisted overrides to the in-memory instance - view.removeInstanceDefinition(instanceName); - view.addInstanceDefinition(persistedInstance); - } + // apply the persisted overrides to the in-memory instance + instance.setLabel(persistedInstance.getLabel()); + instance.setDescription(persistedInstance.getDescription()); + instance.setVisible(persistedInstance.isVisible()); + instance.setData(persistedInstance.getData()); + instance.setProperties(persistedInstance.getProperties()); + instance.setEntities(persistedInstance.getEntities()); instance.setResource(persistedInstance.getResource()); } - // these instances appear in the archive but not present in the db... add - // them to db and registry - for (ViewInstanceEntity instance : xmlInstanceEntityMap.values()) { - // create an admin resource to represent this view instance - ResourceEntity resourceEntity = new ResourceEntity(); - resourceEntity.setResourceType(resourceTypeEntity); - resourceDAO.create(resourceEntity); - instance.setResource(resourceEntity); - - instanceDAO.merge(instance); - bindViewInstance(view, instance); - instanceDefinitions.add(instance); + // these instances appear in the archive but have been deleted + // from the db... remove them from the registry + for (ViewInstanceEntity instance : instanceEntityMap.values()) { + view.removeInstanceDefinition(instance.getName()); + instanceDefinitions.remove(instance); } - } // ensure that the extracted view archive directory exists @@ -1322,26 +1256,6 @@ public class ViewRegistry { } /** - * Get the view configuration from the extracted archive file. - * - * @param archivePath path to extracted archive - * - * @return the associated view configuration - * - * @throws JAXBException if xml is malformed - * @throws FileNotFoundException if xml was not found - */ - public ViewConfig getViewConfigFromExtractedArchive(String archivePath) - throws JAXBException, FileNotFoundException { - - InputStream configStream = new FileInputStream(new File(archivePath + File.separator + VIEW_XML)); - JAXBContext jaxbContext = JAXBContext.newInstance(ViewConfig.class); - Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); - - return (ViewConfig) jaxbUnmarshaller.unmarshal(configStream); - } - - /** * Get a new file instance for the given path. * * @param path the path http://git-wip-us.apache.org/repos/asf/ambari/blob/9355f8f7/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql index 6e582e2..b1d2eba 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql @@ -69,7 +69,7 @@ CREATE TABLE blueprint_configuration (blueprint_name VARCHAR(255) NOT NULL, type CREATE TABLE hostgroup_configuration (blueprint_name VARCHAR(255) NOT NULL, hostgroup_name VARCHAR(255) NOT NULL, type_name VARCHAR(255) NOT NULL, config_data TEXT NOT NULL, config_attributes TEXT, PRIMARY KEY(blueprint_name, hostgroup_name, type_name)); CREATE TABLE viewmain (view_name VARCHAR(255) NOT NULL, label VARCHAR(255), version VARCHAR(255), resource_type_id INTEGER NOT NULL, icon VARCHAR(255), icon64 VARCHAR(255), archive VARCHAR(255), mask VARCHAR(255), PRIMARY KEY(view_name)); CREATE TABLE viewinstancedata (view_instance_id BIGINT, view_name VARCHAR(255) NOT NULL, view_instance_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, user_name VARCHAR(255) NOT NULL, value VARCHAR(2000) NOT NULL, PRIMARY KEY(VIEW_INSTANCE_ID, NAME, USER_NAME)); -CREATE TABLE viewinstance (view_instance_id BIGINT, resource_id BIGINT NOT NULL, view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, label VARCHAR(255), description VARCHAR(255), visible CHAR(1), icon VARCHAR(255), icon64 VARCHAR(255), xml_driven CHAR(1), PRIMARY KEY(view_instance_id)); +CREATE TABLE viewinstance (view_instance_id BIGINT, resource_id BIGINT NOT NULL, view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, label VARCHAR(255), description VARCHAR(255), visible CHAR(1), icon VARCHAR(255), icon64 VARCHAR(255), PRIMARY KEY(view_instance_id)); CREATE TABLE viewinstanceproperty (view_name VARCHAR(255) NOT NULL, view_instance_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, value VARCHAR(2000) NOT NULL, PRIMARY KEY(view_name, view_instance_name, name)); CREATE TABLE viewparameter (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255), required CHAR(1), masked CHAR(1), PRIMARY KEY(view_name, name)); CREATE TABLE viewresource (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, plural_name VARCHAR(255), id_property VARCHAR(255), subResource_names VARCHAR(255), provider VARCHAR(255), service VARCHAR(255), resource VARCHAR(255), PRIMARY KEY(view_name, name)); http://git-wip-us.apache.org/repos/asf/ambari/blob/9355f8f7/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql index b037e82..6ca8fdb 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql @@ -59,7 +59,7 @@ CREATE TABLE blueprint_configuration (blueprint_name VARCHAR2(255) NOT NULL, typ CREATE TABLE hostgroup_configuration (blueprint_name VARCHAR2(255) NOT NULL, hostgroup_name VARCHAR2(255) NOT NULL, type_name VARCHAR2(255) NOT NULL, config_data CLOB NOT NULL, config_attributes CLOB, PRIMARY KEY(blueprint_name, hostgroup_name, type_name)); CREATE TABLE viewmain (view_name VARCHAR(255) NOT NULL, label VARCHAR(255), version VARCHAR(255), resource_type_id NUMBER(10) NOT NULL, icon VARCHAR(255), icon64 VARCHAR(255), archive VARCHAR(255), mask VARCHAR(255), PRIMARY KEY(view_name)); CREATE TABLE viewinstancedata (view_instance_id NUMBER(19), view_name VARCHAR(255) NOT NULL, view_instance_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, user_name VARCHAR(255) NOT NULL, value VARCHAR(2000) NOT NULL, PRIMARY KEY(view_instance_id, name, user_name)); -CREATE TABLE viewinstance (view_instance_id NUMBER(19), resource_id NUMBER(19) NOT NULL, view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, label VARCHAR(255), description VARCHAR(255), visible CHAR(1), icon VARCHAR(255), icon64 VARCHAR(255), xml_driven CHAR(1), PRIMARY KEY(view_instance_id)); +CREATE TABLE viewinstance (view_instance_id NUMBER(19), resource_id NUMBER(19) NOT NULL, view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, label VARCHAR(255), description VARCHAR(255), visible CHAR(1), icon VARCHAR(255), icon64 VARCHAR(255), PRIMARY KEY(view_instance_id)); CREATE TABLE viewinstanceproperty (view_name VARCHAR(255) NOT NULL, view_instance_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, value VARCHAR(2000) NOT NULL, PRIMARY KEY(view_name, view_instance_name, name)); CREATE TABLE viewparameter (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255), required CHAR(1), masked CHAR(1), PRIMARY KEY(view_name, name)); CREATE TABLE viewresource (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, plural_name VARCHAR(255), id_property VARCHAR(255), subResource_names VARCHAR(255), provider VARCHAR(255), service VARCHAR(255), "resource" VARCHAR(255), PRIMARY KEY(view_name, name)); http://git-wip-us.apache.org/repos/asf/ambari/blob/9355f8f7/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql index 4ee213d..6ab57ac 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql @@ -97,7 +97,7 @@ CREATE TABLE hostgroup_configuration (blueprint_name VARCHAR(255) NOT NULL, host CREATE TABLE viewmain (view_name VARCHAR(255) NOT NULL, label VARCHAR(255), version VARCHAR(255), resource_type_id INTEGER NOT NULL, icon VARCHAR(255), icon64 VARCHAR(255), archive VARCHAR(255), mask VARCHAR(255), PRIMARY KEY(view_name)); CREATE TABLE viewinstancedata (view_instance_id BIGINT, view_name VARCHAR(255) NOT NULL, view_instance_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, user_name VARCHAR(255) NOT NULL, value VARCHAR(2000) NOT NULL, PRIMARY KEY(view_instance_id, name, user_name)); -CREATE TABLE viewinstance (view_instance_id BIGINT, resource_id BIGINT NOT NULL, view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, label VARCHAR(255), description VARCHAR(255), visible CHAR(1), icon VARCHAR(255), icon64 VARCHAR(255), xml_driven CHAR(1), PRIMARY KEY(view_instance_id)); +CREATE TABLE viewinstance (view_instance_id BIGINT, resource_id BIGINT NOT NULL, view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, label VARCHAR(255), description VARCHAR(255), visible CHAR(1), icon VARCHAR(255), icon64 VARCHAR(255), PRIMARY KEY(view_instance_id)); CREATE TABLE viewinstanceproperty (view_name VARCHAR(255) NOT NULL, view_instance_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, value VARCHAR(2000) NOT NULL, PRIMARY KEY(view_name, view_instance_name, name)); CREATE TABLE viewparameter (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255), required CHAR(1), masked CHAR(1), PRIMARY KEY(view_name, name)); CREATE TABLE viewresource (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, plural_name VARCHAR(255), id_property VARCHAR(255), subResource_names VARCHAR(255), provider VARCHAR(255), service VARCHAR(255), resource VARCHAR(255), PRIMARY KEY(view_name, name)); http://git-wip-us.apache.org/repos/asf/ambari/blob/9355f8f7/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql index f4ac3f3..ef70439 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql @@ -149,7 +149,7 @@ GRANT ALL PRIVILEGES ON TABLE ambari.hostgroup_configuration TO :username; CREATE TABLE ambari.viewmain (view_name VARCHAR(255) NOT NULL, label VARCHAR(255), version VARCHAR(255), resource_type_id INTEGER NOT NULL, icon VARCHAR(255), icon64 VARCHAR(255), archive VARCHAR(255), mask VARCHAR(255), PRIMARY KEY(view_name)); CREATE TABLE ambari.viewinstancedata (view_instance_id BIGINT, view_name VARCHAR(255) NOT NULL, view_instance_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, user_name VARCHAR(255) NOT NULL, value VARCHAR(2000) NOT NULL, PRIMARY KEY(view_instance_id, name, user_name)); -CREATE TABLE ambari.viewinstance (view_instance_id BIGINT, resource_id BIGINT NOT NULL, view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, label VARCHAR(255), description VARCHAR(255), visible CHAR(1), icon VARCHAR(255), icon64 VARCHAR(255), xml_driven CHAR(1), PRIMARY KEY(view_instance_id)); +CREATE TABLE ambari.viewinstance (view_instance_id BIGINT, resource_id BIGINT NOT NULL, view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, label VARCHAR(255), description VARCHAR(255), visible CHAR(1), icon VARCHAR(255), icon64 VARCHAR(255), PRIMARY KEY(view_instance_id)); CREATE TABLE ambari.viewinstanceproperty (view_name VARCHAR(255) NOT NULL, view_instance_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, value VARCHAR(2000) NOT NULL, PRIMARY KEY(view_name, view_instance_name, name)); CREATE TABLE ambari.viewparameter (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255), required CHAR(1), masked CHAR(1), PRIMARY KEY(view_name, name)); CREATE TABLE ambari.viewresource (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, plural_name VARCHAR(255), id_property VARCHAR(255), subResource_names VARCHAR(255), provider VARCHAR(255), service VARCHAR(255), resource VARCHAR(255), PRIMARY KEY(view_name, name)); http://git-wip-us.apache.org/repos/asf/ambari/blob/9355f8f7/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java index f383799..fbe1c90 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java @@ -18,32 +18,6 @@ package org.apache.ambari.server.view; -import static org.easymock.EasyMock.capture; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.createNiceMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URI; -import java.util.Collection; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; - -import javax.xml.bind.JAXBException; - import org.apache.ambari.server.api.resources.SubResourceDefinition; import org.apache.ambari.server.configuration.Configuration; import org.apache.ambari.server.controller.spi.Resource; @@ -74,12 +48,36 @@ import org.apache.ambari.server.view.events.EventImplTest; import org.apache.ambari.view.events.Event; import org.apache.ambari.view.events.Listener; import org.easymock.Capture; -import org.easymock.EasyMock; import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import javax.xml.bind.JAXBException; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +import static org.easymock.EasyMock.capture; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.createNiceMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; + /** * ViewRegistry tests. */ @@ -216,7 +214,6 @@ public class ViewRegistryTest { expect(viewDir.listFiles()).andReturn(new File[]{viewArchive}); - expect(viewArchive.getAbsolutePath()).andReturn("/var/lib/ambari-server/resources/views/work/MY_VIEW{1.0.0}"); expect(viewArchive.isDirectory()).andReturn(false); expect(archiveDir.exists()).andReturn(false); @@ -255,15 +252,12 @@ public class ViewRegistryTest { expect(libDir.listFiles()).andReturn(new File[]{fileEntry}); expect(fileEntry.toURI()).andReturn(new URI("file:./")); - expect(vDAO.findByName("MY_VIEW{1.0.0}")).andReturn(viewDefinition); - expect(vDAO.findAll()).andReturn(Collections.<ViewEntity>emptyList()); + Capture<ViewEntity> captureViewEntity = new Capture<ViewEntity>(); - expect(rtDAO.findByName("MY_VIEW{1.0.0}")).andReturn(null); - rtDAO.create(EasyMock.anyObject(ResourceTypeEntity.class)); - EasyMock.expectLastCall().anyTimes(); + expect(vDAO.findByName("MY_VIEW{1.0.0}")).andReturn(null); + expect(vDAO.merge(capture(captureViewEntity))).andReturn(viewDefinition); - rDAO.create(EasyMock.anyObject(ResourceEntity.class)); - EasyMock.expectLastCall().anyTimes(); + expect(vDAO.findAll()).andReturn(Collections.<ViewEntity>emptyList()); // replay mocks replay(configuration, viewDir, extractedArchiveDir, viewArchive, archiveDir, entryFile, classesDir, @@ -275,6 +269,7 @@ public class ViewRegistryTest { Set<ViewInstanceEntity> instanceEntities = registry.readViewArchives(configuration); Assert.assertEquals(2, instanceEntities.size()); + Assert.assertEquals("MY_VIEW", captureViewEntity.getValue().getCommonName()); // verify mocks verify(configuration, viewDir, extractedArchiveDir, viewArchive, archiveDir, entryFile, classesDir, @@ -353,7 +348,6 @@ public class ViewRegistryTest { expect(viewDir.listFiles()).andReturn(new File[]{viewArchive}); expect(viewArchive.isDirectory()).andReturn(false); - expect(viewArchive.getAbsolutePath()).andReturn("/var/lib/ambari-server/resources/views/work/MY_VIEW{1.0.0}").anyTimes(); expect(archiveDir.exists()).andReturn(false); expect(archiveDir.getAbsolutePath()).andReturn( @@ -398,13 +392,6 @@ public class ViewRegistryTest { expect(vDAO.findAll()).andReturn(Collections.<ViewEntity>emptyList()); - expect(rtDAO.findByName("MY_VIEW{1.0.0}")).andReturn(null); - rtDAO.create(EasyMock.anyObject(ResourceTypeEntity.class)); - EasyMock.expectLastCall().anyTimes(); - - rDAO.create(EasyMock.anyObject(ResourceEntity.class)); - EasyMock.expectLastCall().anyTimes(); - Capture<ResourceEntity> resourceEntityCapture = new Capture<ResourceEntity>(); // replay mocks @@ -799,17 +786,6 @@ public class ViewRegistryTest { } @Override - public ViewConfig getViewConfigFromExtractedArchive(String archivePath) - throws JAXBException, FileNotFoundException { - for (File viewConfigKey: viewConfigs.keySet()) { - if (viewConfigKey.getAbsolutePath().equals(archivePath)) { - return viewConfigs.get(viewConfigKey); - } - } - return null; - } - - @Override public File getFile(String path) { return files.get(path); }
