Repository: ambari
Updated Branches:
  refs/heads/trunk dcedac206 -> be13513cf


AMBARI-7529. On upgrade to 1.7.0, automatically create Jobs view instance.


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1ea0f474
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1ea0f474
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1ea0f474

Branch: refs/heads/trunk
Commit: 1ea0f474ee9316dbb18beda3cec6935d3ffc14f3
Parents: dcedac2
Author: Siddharth Wagle <swa...@hortonworks.com>
Authored: Fri Sep 26 16:57:41 2014 -0700
Committer: Siddharth Wagle <swa...@hortonworks.com>
Committed: Fri Sep 26 16:57:41 2014 -0700

----------------------------------------------------------------------
 .../server/upgrade/UpgradeCatalog170.java       | 139 +++++++++++++------
 .../apache/ambari/server/view/ViewRegistry.java |  26 +++-
 .../server/upgrade/UpgradeCatalog170Test.java   |  63 +++++++--
 .../ambari/server/upgrade/UpgradeTest.java      |  11 +-
 contrib/views/jobs/src/main/resources/view.xml  |   4 +-
 5 files changed, 181 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1ea0f474/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 6693e20..d86bf35 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
@@ -46,6 +46,7 @@ import 
org.apache.ambari.server.orm.entities.ClusterConfigEntity;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
 import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
 import org.apache.ambari.server.orm.entities.ClusterServiceEntityPK;
+import org.apache.ambari.server.orm.entities.ClusterConfigMappingEntity;
 import org.apache.ambari.server.orm.entities.ConfigGroupConfigMappingEntity;
 import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
 import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
@@ -70,6 +71,7 @@ import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.ConfigHelper;
 import org.apache.ambari.server.utils.StageUtils;
+import org.apache.ambari.server.view.ViewRegistry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -115,9 +117,16 @@ public class UpgradeCatalog170 extends 
AbstractUpgradeCatalog {
   private static final String ALERT_TABLE_GROUPING = "alert_grouping";
   private static final String ALERT_TABLE_NOTICE = "alert_notice";
   public static final String JOBS_VIEW_NAME = "JOBS";
+  public static final String VIEW_NAME_REG_EXP = JOBS_VIEW_NAME + "\\{.*\\}";
   public static final String JOBS_VIEW_INSTANCE_NAME = "JOBS_1";
   public static final String SHOW_JOBS_FOR_NON_ADMIN_KEY = 
"showJobsForNonAdmin";
   public static final String JOBS_VIEW_INSTANCE_LABEL = "Jobs";
+  public static final String CLUSTER_STATE_STACK_HDP_2_1 = 
"{\"stackName\":\"HDP\",\"stackVersion\":\"2.1\"}";
+  public static final String YARN_TIMELINE_SERVICE_WEBAPP_ADDRESS_PROPERTY = 
"yarn.timeline-service.webapp.address";
+  public static final String YARN_RESOURCEMANAGER_WEBAPP_ADDRESS_PROPERTY = 
"yarn.resourcemanager.webapp.address";
+  public static final String YARN_SITE = "yarn-site";
+  public static final String YARN_ATS_URL_PROPERTY = "yarn.ats.url";
+  public static final String YARN_RESOURCEMANAGER_URL_PROPERTY = 
"yarn.resourcemanager.url";
 
   //SourceVersion is only for book-keeping purpos
   @Override
@@ -1295,56 +1304,96 @@ public class UpgradeCatalog170 extends 
AbstractUpgradeCatalog {
     final KeyValueDAO keyValueDAO = injector.getInstance(KeyValueDAO.class);
     final PermissionDAO permissionDAO = 
injector.getInstance(PermissionDAO.class);
     final PrivilegeDAO privilegeDAO = injector.getInstance(PrivilegeDAO.class);
-
-    ViewEntity jobsView = viewDAO.findByCommonName(JOBS_VIEW_NAME);
-    if (jobsView != null) {
-      ViewInstanceEntity jobsInstance = 
jobsView.getInstanceDefinition(JOBS_VIEW_INSTANCE_NAME);
-      if (jobsInstance == null) {
-        jobsInstance = new ViewInstanceEntity(jobsView, 
JOBS_VIEW_INSTANCE_NAME, JOBS_VIEW_INSTANCE_LABEL);
-        ResourceEntity resourceEntity = new ResourceEntity();
-        resourceEntity.setResourceType(resourceTypeDAO.findByName(
-            ViewEntity.getViewName(
-                jobsView.getCommonName(),
-                jobsView.getVersion())));
-        jobsInstance.setResource(resourceEntity);
-        jobsView.addInstanceDefinition(jobsInstance);
-        resourceDAO.create(resourceEntity);
-        viewInstanceDAO.create(jobsInstance);
-        viewDAO.merge(jobsView);
-      }
-      // get showJobsForNonAdmin value and remove it
-      boolean showJobsForNonAdmin = false;
-      KeyValueEntity showJobsKeyValueEntity = 
keyValueDAO.findByKey(SHOW_JOBS_FOR_NON_ADMIN_KEY);
-      if (showJobsKeyValueEntity != null) {
-        String value = showJobsKeyValueEntity.getValue();
-        showJobsForNonAdmin = Boolean.parseBoolean(value);
-        keyValueDAO.remove(showJobsKeyValueEntity);
-      }
-      if (showJobsForNonAdmin) {
-        ResourceEntity jobsResource = jobsInstance.getResource();
-        PermissionEntity viewUsePermission = 
permissionDAO.findViewUsePermission();
-        for (UserEntity userEntity : userDAO.findAll()) {
-          // check if user has VIEW.USE privilege for JOBS view
-          List<PrivilegeEntity> privilegeEntities = 
privilegeDAO.findAllByPrincipal(
-              Collections.singletonList(userEntity.getPrincipal()));
-          boolean hasJobsUsePrivilege = false;
-          for (PrivilegeEntity privilegeEntity : privilegeEntities) {
-            if (privilegeEntity.getResource().getId() == 
jobsInstance.getResource().getId() &&
-                privilegeEntity.getPermission().getId() == 
viewUsePermission.getId()) {
-              hasJobsUsePrivilege = true;
-              break;
+    final ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
+    final ViewRegistry viewRegistry = injector.getInstance(ViewRegistry.class);
+
+    List<ClusterEntity> clusters = clusterDAO.findAll();
+    if (!clusters.isEmpty()) {
+      ClusterEntity currentCluster = clusters.get(0);
+      String currentStackVersion = 
currentCluster.getClusterStateEntity().getCurrentStackVersion();
+      if (CLUSTER_STATE_STACK_HDP_2_1.equals(currentStackVersion)) {
+        ViewRegistry.initInstance(viewRegistry);
+        viewRegistry.readViewArchives(VIEW_NAME_REG_EXP);
+        ViewEntity jobsView = viewDAO.findByCommonName(JOBS_VIEW_NAME);
+
+        if (jobsView != null) {
+          ViewInstanceEntity jobsInstance = 
jobsView.getInstanceDefinition(JOBS_VIEW_INSTANCE_NAME);
+          if (jobsInstance == null) {
+            jobsInstance = new ViewInstanceEntity(jobsView, 
JOBS_VIEW_INSTANCE_NAME, JOBS_VIEW_INSTANCE_LABEL);
+            ResourceEntity resourceEntity = new ResourceEntity();
+            resourceEntity.setResourceType(resourceTypeDAO.findByName(
+                ViewEntity.getViewName(
+                    jobsView.getCommonName(),
+                    jobsView.getVersion())));
+            String atsHost;
+            String rmHost;
+            try {
+              ClusterConfigEntity currentYarnConfig = null;
+              for (ClusterConfigMappingEntity configMappingEntity : 
currentCluster.getConfigMappingEntities()) {
+                if (YARN_SITE.equals(configMappingEntity.getType()) && 
configMappingEntity.isSelected() > 0) {
+                  currentYarnConfig = 
clusterDAO.findConfig(currentCluster.getClusterId(),
+                      configMappingEntity.getType(), 
configMappingEntity.getTag());
+                  break;
+                }
+              }
+              Type type = new TypeToken<Map<String, String>>() {}.getType();
+              Map<String, String> yarnSiteProps = 
StageUtils.getGson().fromJson(currentYarnConfig.getData(), type);
+              atsHost = 
yarnSiteProps.get(YARN_TIMELINE_SERVICE_WEBAPP_ADDRESS_PROPERTY);
+              rmHost = 
yarnSiteProps.get(YARN_RESOURCEMANAGER_WEBAPP_ADDRESS_PROPERTY);
+            } catch (Exception ex) {
+              // Required properties failed to be set, therefore jobs instance 
should not be created
+              return;
             }
+            jobsInstance.setResource(resourceEntity);
+            jobsInstance.putProperty(YARN_ATS_URL_PROPERTY, "http://"; + 
atsHost);
+            jobsInstance.putProperty(YARN_RESOURCEMANAGER_URL_PROPERTY, 
"http://"; + rmHost);
+            jobsView.addInstanceDefinition(jobsInstance);
+            resourceDAO.create(resourceEntity);
+            viewInstanceDAO.create(jobsInstance);
+            viewDAO.merge(jobsView);
           }
-          // if not - add VIEW.use privilege
-          if (!hasJobsUsePrivilege) {
-            PrivilegeEntity privilegeEntity = new PrivilegeEntity();
-            privilegeEntity.setResource(jobsResource);
-            privilegeEntity.setPermission(viewUsePermission);
-            privilegeEntity.setPrincipal(userEntity.getPrincipal());
-            privilegeDAO.create(privilegeEntity);
+          // get showJobsForNonAdmin value and remove it
+          boolean showJobsForNonAdmin = false;
+          KeyValueEntity showJobsKeyValueEntity = 
keyValueDAO.findByKey(SHOW_JOBS_FOR_NON_ADMIN_KEY);
+          if (showJobsKeyValueEntity != null) {
+            String value = showJobsKeyValueEntity.getValue();
+            showJobsForNonAdmin = Boolean.parseBoolean(value);
+            keyValueDAO.remove(showJobsKeyValueEntity);
+          }
+          if (showJobsForNonAdmin) {
+            ResourceEntity jobsResource = jobsInstance.getResource();
+            long jobsResourceId = jobsResource.getId();
+            PermissionEntity viewUsePermission = 
permissionDAO.findViewUsePermission();
+            PermissionEntity adminPermission = 
permissionDAO.findAmbariAdminPermission();
+            int viewUsePermissionId = viewUsePermission.getId();
+            int adminPermissionId = adminPermission.getId();
+            for (UserEntity userEntity : userDAO.findAll()) {
+              // check if user has VIEW.USE privilege for JOBS view
+              List<PrivilegeEntity> privilegeEntities = 
privilegeDAO.findAllByPrincipal(
+                  Collections.singletonList(userEntity.getPrincipal()));
+              boolean hasJobsUsePrivilege = false;
+              for (PrivilegeEntity privilegeEntity : privilegeEntities) {
+                int privilegePermissionId = 
privilegeEntity.getPermission().getId();
+                Long privilegeResourceId = 
privilegeEntity.getResource().getId();
+                if ((privilegePermissionId == viewUsePermissionId && 
privilegeResourceId == jobsResourceId)
+                    || privilegePermissionId == adminPermissionId) {
+                  hasJobsUsePrivilege = true;
+                  break;
+                }
+              }
+              // if not - add VIEW.use privilege
+              if (!hasJobsUsePrivilege) {
+                PrivilegeEntity privilegeEntity = new PrivilegeEntity();
+                privilegeEntity.setResource(jobsResource);
+                privilegeEntity.setPermission(viewUsePermission);
+                privilegeEntity.setPrincipal(userEntity.getPrincipal());
+                privilegeDAO.create(privilegeEntity);
+              }
+            }
           }
         }
       }
     }
+
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1ea0f474/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 58c4334..5f775a6 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
@@ -102,6 +102,7 @@ public class ViewRegistry {
    */
   private static final String EXTRACTED_ARCHIVES_DIR = "work";
   private static final String EXTRACT_COMMAND = "extract";
+  private static final String ALL_VIEWS_REG_EXP = ".*";
 
   /**
    * Thread pool
@@ -424,10 +425,19 @@ public class ViewRegistry {
   }
 
   /**
-   * Read the view archives.
+   * Read all view archives.
    */
   public void readViewArchives() {
-    readViewArchives(false, true);
+    readViewArchives(false, true, ALL_VIEWS_REG_EXP, true);
+  }
+
+  /**
+   * Read only view archives with names corresponding to given regular 
expression.
+   *
+   * @param viewNameRegExp view name regular expression
+   */
+  public void readViewArchives(String viewNameRegExp) {
+    readViewArchives(false, false, viewNameRegExp, false);
   }
 
   /**
@@ -1147,9 +1157,9 @@ public class ViewRegistry {
     }
   }
 
-
   // read the view archives.
-  private void readViewArchives(boolean systemOnly, boolean useExecutor) {
+  private void readViewArchives(boolean systemOnly, boolean useExecutor,
+                                String viewNameRegExp, boolean 
removeUndeployed) {
     try {
       File viewDir = configuration.getViewsDir();
 
@@ -1173,6 +1183,10 @@ public class ViewRegistry {
               String version    = viewConfig.getVersion();
               String viewName   = ViewEntity.getViewName(commonName, version);
 
+              if (!viewName.matches(viewNameRegExp)) {
+                continue;
+              }
+
               final String extractedArchiveDirPath = extractedArchivesPath + 
File.separator + viewName;
               final File extractedArchiveDirFile = 
archiveUtility.getFile(extractedArchiveDirPath);
 
@@ -1210,7 +1224,9 @@ public class ViewRegistry {
             }
           }
 
-          removeUndeployedViews();
+          if (removeUndeployed) {
+            removeUndeployedViews();
+          }
         }
       } else {
         LOG.error("Could not create extracted view archive directory " + 
extractedArchivesPath + ".");

http://git-wip-us.apache.org/repos/asf/ambari/blob/1ea0f474/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java
index 2edc5b5..0c92f44 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java
@@ -18,6 +18,13 @@
 
 package org.apache.ambari.server.upgrade;
 
+import static 
org.apache.ambari.server.upgrade.UpgradeCatalog170.CLUSTER_STATE_STACK_HDP_2_1;
+import static 
org.apache.ambari.server.upgrade.UpgradeCatalog170.JOBS_VIEW_NAME;
+import static 
org.apache.ambari.server.upgrade.UpgradeCatalog170.SHOW_JOBS_FOR_NON_ADMIN_KEY;
+import static 
org.apache.ambari.server.upgrade.UpgradeCatalog170.YARN_RESOURCEMANAGER_WEBAPP_ADDRESS_PROPERTY;
+import static org.apache.ambari.server.upgrade.UpgradeCatalog170.YARN_SITE;
+import static 
org.apache.ambari.server.upgrade.UpgradeCatalog170.YARN_TIMELINE_SERVICE_WEBAPP_ADDRESS_PROPERTY;
+
 import com.google.inject.Binder;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
@@ -49,8 +56,10 @@ import org.apache.ambari.server.orm.dao.UserDAO;
 import org.apache.ambari.server.orm.dao.ViewDAO;
 import org.apache.ambari.server.orm.dao.ViewInstanceDAO;
 import org.apache.ambari.server.orm.entities.ClusterConfigEntity;
+import org.apache.ambari.server.orm.entities.ClusterConfigMappingEntity;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
 import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
+import org.apache.ambari.server.orm.entities.ClusterStateEntity;
 import org.apache.ambari.server.orm.entities.ConfigGroupConfigMappingEntity;
 import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
 import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntityPK;
@@ -59,6 +68,7 @@ import 
org.apache.ambari.server.orm.entities.HostComponentStateEntityPK;
 import org.apache.ambari.server.orm.entities.HostEntity;
 import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
 import org.apache.ambari.server.orm.entities.KeyValueEntity;
+import org.apache.ambari.server.orm.entities.PermissionEntity;
 import org.apache.ambari.server.orm.entities.PrivilegeEntity;
 import org.apache.ambari.server.orm.entities.ResourceEntity;
 import org.apache.ambari.server.orm.entities.ResourceTypeEntity;
@@ -74,7 +84,9 @@ import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.ConfigHelper;
 import org.apache.ambari.server.state.HostComponentAdminState;
 import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.view.ViewRegistry;
 import org.easymock.Capture;
+import org.easymock.IAnswer;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -116,6 +128,7 @@ import static org.easymock.EasyMock.createStrictMock;
 import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.getCurrentArguments;
 import static org.easymock.EasyMock.isA;
 import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.reset;
@@ -422,6 +435,9 @@ public class UpgradeCatalog170Test {
     Clusters clusters = createStrictMock(Clusters.class);
     Config config = createStrictMock(Config.class);
     Config pigConfig = createStrictMock(Config.class);
+    ViewRegistry viewRegistry = createNiceMock(ViewRegistry.class);
+    PermissionEntity adminPermission = createNiceMock(PermissionEntity.class);
+    PermissionEntity viewUsePermission = 
createNiceMock(PermissionEntity.class);
 
     ClusterConfigEntity clusterConfigEntity = 
createNiceMock(ClusterConfigEntity.class);
     ConfigGroupConfigMappingDAO configGroupConfigMappingDAO = 
createNiceMock(ConfigGroupConfigMappingDAO.class);
@@ -448,6 +464,8 @@ public class UpgradeCatalog170Test {
     TypedQuery<HostRoleCommandEntity> q = createNiceMock(TypedQuery.class);
     List<HostRoleCommandEntity> r = new ArrayList<HostRoleCommandEntity>();
     ResultSet userRolesResultSet = createNiceMock(ResultSet.class);
+    ClusterEntity clusterEntity = createNiceMock(ClusterEntity.class);
+    ClusterConfigEntity configEntity = 
createNiceMock(ClusterConfigEntity.class);
 
     Method m = AbstractUpgradeCatalog.class.getDeclaredMethod
         ("updateConfigurationProperties", String.class, Map.class, 
boolean.class, boolean.class);
@@ -543,13 +561,20 @@ public class UpgradeCatalog170Test {
     
expect(injector.getInstance(PermissionDAO.class)).andReturn(permissionDAO).anyTimes();
     
expect(injector.getInstance(PrivilegeDAO.class)).andReturn(privilegeDAO).anyTimes();
     
expect(injector.getInstance(KeyValueDAO.class)).andReturn(keyValueDAO).anyTimes();
+    
expect(injector.getInstance(ViewRegistry.class)).andReturn(viewRegistry).anyTimes();
 
+    String yarnConfig = String.format("{'%s':'%s', '%s':'%s'}",
+        YARN_TIMELINE_SERVICE_WEBAPP_ADDRESS_PROPERTY, "timeline:8081",
+        YARN_RESOURCEMANAGER_WEBAPP_ADDRESS_PROPERTY, "resource_man:8081");
     
expect(configGroupConfigMappingDAO.findAll()).andReturn(configGroupConfigMappingEntities).once();
-    expect(userDAO.findAll()).andReturn(Collections.<UserEntity> 
emptyList()).times(2);
-    expect(clusterDAO.findAll()).andReturn(Collections.<ClusterEntity> 
emptyList()).anyTimes();
+    
expect(userDAO.findAll()).andReturn(Collections.<UserEntity>emptyList()).times(2);
+    
expect(clusterDAO.findAll()).andReturn(Collections.singletonList(clusterEntity)).anyTimes();
+    expect(configEntity.getData()).andReturn(yarnConfig);
+    expect(clusterDAO.findConfig(1L, YARN_SITE, 
"version1")).andReturn(configEntity).anyTimes();
     expect(viewDAO.findAll()).andReturn(Collections.<ViewEntity> 
emptyList()).anyTimes();
     
expect(viewInstanceDAO.findAll()).andReturn(Collections.<ViewInstanceEntity> 
emptyList()).anyTimes();
-    expect(permissionDAO.findAmbariAdminPermission()).andReturn(null);
+    
expect(permissionDAO.findAmbariAdminPermission()).andReturn(adminPermission).anyTimes();
+    
expect(permissionDAO.findViewUsePermission()).andReturn(viewUsePermission).anyTimes();
     expect(permissionDAO.findClusterOperatePermission()).andReturn(null);
     expect(permissionDAO.findClusterReadPermission()).andReturn(null);
 
@@ -559,18 +584,36 @@ public class UpgradeCatalog170Test {
     ViewEntity jobsView = createNiceMock(ViewEntity.class);
     KeyValueEntity showJobsKeyValue = createNiceMock(KeyValueEntity.class);
     UserEntity user = createNiceMock(UserEntity.class);
-
+    ClusterConfigMappingEntity configMappingEntity = 
createNiceMock(ClusterConfigMappingEntity.class);
+    ClusterStateEntity clusterStateEntity = 
createNiceMock(ClusterStateEntity.class);
+
+    expect(clusterEntity.getClusterId()).andReturn(1L).anyTimes();
+    
expect(clusterEntity.getConfigMappingEntities()).andReturn(Collections.singleton(configMappingEntity));
+    
expect(clusterEntity.getClusterStateEntity()).andReturn(clusterStateEntity).anyTimes();
+    
expect(clusterStateEntity.getCurrentStackVersion()).andReturn(CLUSTER_STATE_STACK_HDP_2_1);
+    expect(configMappingEntity.getType()).andReturn(YARN_SITE).anyTimes();
+    expect(configMappingEntity.isSelected()).andReturn(1).anyTimes();
+    expect(configMappingEntity.getTag()).andReturn("version1");
     expect(userDAO.findAll()).andReturn(Collections.singletonList(user));
-    
expect(jobsView.getCommonName()).andReturn(UpgradeCatalog170.JOBS_VIEW_NAME);
+    expect(jobsView.getCommonName()).andReturn(JOBS_VIEW_NAME);
     expect(jobsView.getVersion()).andReturn("1.0.0");
-    
expect(viewDAO.findByCommonName(UpgradeCatalog170.JOBS_VIEW_NAME)).andReturn(jobsView).once();
+    
expect(viewDAO.findByCommonName(JOBS_VIEW_NAME)).andReturn(jobsView).once();
     expect(showJobsKeyValue.getValue()).andReturn("true");
-    
expect(keyValueDAO.findByKey(UpgradeCatalog170.SHOW_JOBS_FOR_NON_ADMIN_KEY)).andReturn(showJobsKeyValue);
+    
expect(keyValueDAO.findByKey(SHOW_JOBS_FOR_NON_ADMIN_KEY)).andReturn(showJobsKeyValue);
     
expect(privilegeDAO.findAllByPrincipal(anyObject(List.class))).andReturn(Collections.<PrivilegeEntity>emptyList());
     expect(viewDAO.merge(jobsView)).andReturn(jobsView);
 
     resourceDAO.create(anyObject(ResourceEntity.class));
+    expect(adminPermission.getId()).andReturn(3);
+    expect(viewUsePermission.getId()).andReturn(4);
     viewInstanceDAO.create(anyObject(ViewInstanceEntity.class));
+    expectLastCall().andAnswer(new IAnswer<Object>() {
+      @Override
+      public Object answer() throws Throwable {
+        ((ViewInstanceEntity) 
getCurrentArguments()[0]).getResource().setId(1L);
+        return null;
+      }
+    });
     keyValueDAO.remove(showJobsKeyValue);
     privilegeDAO.create(anyObject(PrivilegeEntity.class));
 
@@ -579,7 +622,8 @@ public class UpgradeCatalog170Test {
     replay(dbAccessor, configuration, injector, cluster, clusters, amc, 
config, configHelper, pigConfig);
     replay(userDAO, clusterDAO, viewDAO, viewInstanceDAO, permissionDAO, 
configGroupConfigMappingDAO);
     replay(resourceTypeDAO, resourceDAO, keyValueDAO, privilegeDAO, 
clusterConfigEntity);
-    replay(jobsView, showJobsKeyValue, user);
+    replay(jobsView, showJobsKeyValue, user, viewRegistry, viewUsePermission, 
adminPermission);
+    replay(clusterEntity, configEntity, configMappingEntity, 
clusterStateEntity);
 
     Class<?> c = AbstractUpgradeCatalog.class;
     Field f = c.getDeclaredField("configuration");
@@ -595,7 +639,8 @@ public class UpgradeCatalog170Test {
     upgradeCatalog.executeDMLUpdates();
 
     verify(upgradeCatalog, dbAccessor, configuration, injector, cluster, 
clusters, amc, config, configHelper,
-        jobsView, showJobsKeyValue, privilegeDAO, viewDAO, viewInstanceDAO, 
resourceDAO, keyValueDAO, userRolesResultSet);
+        jobsView, showJobsKeyValue, privilegeDAO, viewDAO, viewInstanceDAO, 
resourceDAO, keyValueDAO,
+        viewRegistry, userRolesResultSet, clusterEntity, configEntity, 
configMappingEntity, clusterStateEntity);
   }
 
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/1ea0f474/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeTest.java 
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeTest.java
index c89a0b4..b70d252 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeTest.java
@@ -28,6 +28,8 @@ import org.apache.ambari.server.controller.ControllerModule;
 import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.orm.dao.*;
 import org.apache.ambari.server.utils.VersionUtils;
+import org.apache.ambari.server.view.ViewRegistry;
+import org.easymock.EasyMock;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
@@ -148,7 +150,14 @@ public class UpgradeTest {
   }
 
   private void performUpgrade(String targetVersion) throws Exception {
-    Injector injector = Guice.createInjector(new 
SchemaUpgradeHelper.UpgradeHelperModule(properties));
+    Injector injector = Guice.createInjector(new 
SchemaUpgradeHelper.UpgradeHelperModule(properties) {
+      @Override
+      protected void configure() {
+        super.configure();
+        ViewRegistry viewRegistryMock = 
EasyMock.createNiceMock(ViewRegistry.class);
+        bind(ViewRegistry.class).toInstance(viewRegistryMock);
+      }
+    });
     SchemaUpgradeHelper schemaUpgradeHelper = 
injector.getInstance(SchemaUpgradeHelper.class);
 
     LOG.info("Upgrading schema to target version = " + targetVersion);

http://git-wip-us.apache.org/repos/asf/ambari/blob/1ea0f474/contrib/views/jobs/src/main/resources/view.xml
----------------------------------------------------------------------
diff --git a/contrib/views/jobs/src/main/resources/view.xml 
b/contrib/views/jobs/src/main/resources/view.xml
index 30adca2..6dd5ee6 100644
--- a/contrib/views/jobs/src/main/resources/view.xml
+++ b/contrib/views/jobs/src/main/resources/view.xml
@@ -21,11 +21,11 @@ limitations under the License. Kerberos, LDAP, Custom. 
Binary/Htt
   <parameter>
       <name>yarn.ats.url</name>
       <description>The URL to the YARN Application Timeline Server, used to 
provide Jobs information, typically, this is the 
yarn.timeline-service.webapp.address property in the yarn-site.xml 
configuration. For example: http://yarn.ats.address:8188</description>
-      <required>false</required>
+      <required>true</required>
   </parameter>
   <parameter>
       <name>yarn.resourcemanager.url</name>
       <description>The URL to the YARN ResourceManager, used to provide YARN 
Application data. For example: 
http://yarn.resourcemanager.address:8088</description>
-      <required>false</required>
+      <required>true</required>
   </parameter>
 </view>

Reply via email to