ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [30/50] [abbrv] ambari git commit: AMBARI-14389. tez view disappeared after upgrading from ambari 2.1.2 to 2.2.0.0. (Dipayan Bhowmick via yusaku)
Date Fri, 08 Jan 2016 18:15:47 GMT
AMBARI-14389. tez view disappeared after upgrading from ambari 2.1.2 to 2.2.0.0. (Dipayan Bhowmick
via yusaku)


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

Branch: refs/heads/branch-dev-patch-upgrade
Commit: 09bfcff68ef741d09e7a1aab9fdba8d4ed165fd0
Parents: b73623f
Author: Yusaku Sako <yusaku@hortonworks.com>
Authored: Wed Jan 6 12:26:37 2016 -0800
Committer: Yusaku Sako <yusaku@hortonworks.com>
Committed: Wed Jan 6 12:27:19 2016 -0800

----------------------------------------------------------------------
 .../apache/ambari/server/view/ViewRegistry.java | 38 +++++++++++
 .../ambari/server/view/ViewRegistryTest.java    | 70 +++++++++++++++++---
 2 files changed, 100 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/09bfcff6/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 7e232f1..bb1dbbb 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
@@ -1540,6 +1540,9 @@ public class ViewRegistry {
         }
         persistView(viewDefinition, instanceDefinitions);
 
+        // add auto instance configurations if required
+        addAutoInstanceDefinition(viewDefinition);
+
         setViewStatus(viewDefinition, ViewEntity.ViewStatus.DEPLOYED, "Deployed " + extractedArchiveDirPath
+ ".");
 
         LOG.info("View deployed: " + viewDefinition.getName() + ".");
@@ -1552,6 +1555,41 @@ public class ViewRegistry {
     }
   }
 
+  private void addAutoInstanceDefinition(ViewEntity viewEntity) {
+    ViewConfig viewConfig = viewEntity.getConfiguration();
+    String viewName = viewEntity.getViewName();
+
+    AutoInstanceConfig autoInstanceConfig = viewConfig.getAutoInstance();
+    if (autoInstanceConfig == null) {
+      return;
+    }
+
+    List<String> services = autoInstanceConfig.getServices();
+
+    Map<String, org.apache.ambari.server.state.Cluster> allClusters = clustersProvider.get().getClusters();
+    for (org.apache.ambari.server.state.Cluster cluster : allClusters.values()) {
+
+      String clusterName = cluster.getClusterName();
+      StackId stackId = cluster.getCurrentStackVersion();
+      Set<String> serviceNames = cluster.getServices().keySet();
+
+      for (String service : services) {
+        try {
+
+          if (checkAutoInstanceConfig(autoInstanceConfig, stackId, service, serviceNames))
{
+            LOG.info("Auto creating instance of view " + viewName + " for cluster " + clusterName
+ ".");
+            ViewInstanceEntity viewInstanceEntity = createViewInstanceEntity(viewEntity,
viewConfig, autoInstanceConfig);
+            viewInstanceEntity.setClusterHandle(clusterName);
+            installViewInstance(viewInstanceEntity);
+          }
+        } catch (Exception e) {
+          LOG.error("Can't auto create instance of view " + viewName + " for cluster " +
clusterName +
+            ".  Caught exception :" + e.getMessage(), e);
+        }
+      }
+    }
+  }
+
   /**
    * Check the configured view max and min Ambari versions for the given view entity
    * against the given Ambari server version.

http://git-wip-us.apache.org/repos/asf/ambari/blob/09bfcff6/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 f40360e..5b24b19 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
@@ -238,20 +238,25 @@ public class ViewRegistryTest {
 
   @Test
   public void testReadViewArchives() throws Exception {
-    testReadViewArchives(false, false);
+    testReadViewArchives(false, false, false);
   }
 
   @Test
   public void testReadViewArchives_removeUndeployed() throws Exception {
-    testReadViewArchives(false, true);
+    testReadViewArchives(false, true, false);
   }
 
   @Test
   public void testReadViewArchives_badArchive() throws Exception {
-    testReadViewArchives(true, false);
+    testReadViewArchives(true, false, false);
   }
 
-  private void testReadViewArchives(boolean badArchive, boolean removeUndeployed) throws
Exception {
+  @Test
+  public void testReadViewArchives_viewAutoInstanceCreation() throws Exception {
+    testReadViewArchives(false, false, true);
+  }
+
+  private void testReadViewArchives(boolean badArchive, boolean removeUndeployed, boolean
checkAutoInstanceCreation) throws Exception {
 
     File viewDir = createNiceMock(File.class);
     File extractedArchiveDir = createNiceMock(File.class);
@@ -394,19 +399,52 @@ public class ViewRegistryTest {
     expect(fileEntry.toURI()).andReturn(new URI("file:./")).anyTimes();
 
     expect(configuration.isViewRemoveUndeployedEnabled()).andReturn(removeUndeployed).anyTimes();
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Service service = createNiceMock(Service.class);
+    ViewInstanceEntity viewAutoInstanceEntity = createNiceMock(ViewInstanceEntity.class);
+    Capture<ViewInstanceEntity> viewAutoInstanceCapture = new Capture<ViewInstanceEntity>();
+
+    ViewInstanceDataEntity autoInstanceDataEntity = createNiceMock(ViewInstanceDataEntity.class);
+    expect(autoInstanceDataEntity.getName()).andReturn("p1").anyTimes();
+    expect(autoInstanceDataEntity.getUser()).andReturn(" ").anyTimes();
+
+    Map<String, Service> serviceMap = new HashMap<String, Service>();
+    serviceMap.put("HDFS", service);
+    serviceMap.put("HIVE", service);
+
+
+    StackId stackId = new StackId("HDP-2.0");
+
+    if(checkAutoInstanceCreation) {
+      Map<String, Cluster> allClusters = new HashMap<String, Cluster>();
+      expect(cluster.getClusterName()).andReturn("c1").anyTimes();
+      expect(cluster.getCurrentStackVersion()).andReturn(stackId).anyTimes();
+      expect(cluster.getServices()).andReturn(serviceMap).anyTimes();
+      allClusters.put("c1", cluster);
+      expect(clusters.getClusters()).andReturn(allClusters);
+
+      expect(viewInstanceDAO.merge(capture(viewAutoInstanceCapture))).andReturn(viewAutoInstanceEntity).anyTimes();
+      expect(viewInstanceDAO.findByName("MY_VIEW{1.0.0}", "AUTO-INSTANCE")).andReturn(viewAutoInstanceEntity).anyTimes();
+      expect(viewAutoInstanceEntity.getInstanceData("p1")).andReturn(autoInstanceDataEntity).anyTimes();
+    } else {
+      expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>());
+    }
+
     if (removeUndeployed) {
       expect(viewDAO.findAll()).andReturn(Collections.<ViewEntity>emptyList());
     }
 
     // replay mocks
     replay(configuration, viewDir, extractedArchiveDir, viewArchive, archiveDir, entryFile,
classesDir,
-        libDir, metaInfDir, fileEntry, viewJarFile, jarEntry, fos, resourceDAO, viewDAO,
viewInstanceDAO);
+        libDir, metaInfDir, fileEntry, viewJarFile, jarEntry, fos, resourceDAO, viewDAO,
viewInstanceDAO, clusters,
+      cluster, viewAutoInstanceEntity);
 
     TestViewArchiveUtility archiveUtility =
         new TestViewArchiveUtility(viewConfigs, files, outputStreams, jarFiles, badArchive);
 
     ViewRegistry registry = getRegistry(viewDAO, viewInstanceDAO, userDAO, memberDAO, privilegeDAO,
-        resourceDAO, resourceTypeDAO, securityHelper, handlerList, null, archiveUtility,
ambariMetaInfo);
+        resourceDAO, resourceTypeDAO, securityHelper, handlerList, null, archiveUtility,
ambariMetaInfo, clusters);
 
     registry.readViewArchives();
 
@@ -419,6 +457,8 @@ public class ViewRegistryTest {
       view = registry.getDefinition("MY_VIEW", "1.0.0");
     }
 
+    int instanceDefinitionSize = checkAutoInstanceCreation ? 3: 2;
+
     if (badArchive) {
       Assert.assertNull(view);
       Assert.assertTrue(archiveUtility.isDeploymentFailed());
@@ -427,9 +467,21 @@ public class ViewRegistryTest {
       Assert.assertEquals(ViewDefinition.ViewStatus.DEPLOYED, view.getStatus());
 
       Collection<ViewInstanceEntity> instanceDefinitions = registry.getInstanceDefinitions(view);
-      Assert.assertEquals(2, instanceDefinitions.size());
+      ArrayList<ViewInstanceEntity> filteredInstanceDefinition = new ArrayList<>();
+      Assert.assertEquals(instanceDefinitionSize, instanceDefinitions.size());
 
-      for (ViewInstanceEntity viewInstanceEntity : instanceDefinitions) {
+      if(checkAutoInstanceCreation) {
+        Assert.assertEquals(viewAutoInstanceCapture.getValue(), registry.getInstanceDefinition("MY_VIEW",
"1.0.0", "AUTO-INSTANCE"));
+      }
+
+      //Filter out AutoInstance view Entity
+      for(ViewInstanceEntity entity : instanceDefinitions) {
+        if(!entity.getName().equals("AUTO-INSTANCE")) {
+          filteredInstanceDefinition.add(entity);
+        }
+      }
+
+      for (ViewInstanceEntity viewInstanceEntity : filteredInstanceDefinition) {
         Assert.assertEquals("v1", viewInstanceEntity.getInstanceData("p1").getValue());
 
         Collection<ViewEntityEntity> entities = viewInstanceEntity.getEntities();
@@ -440,6 +492,8 @@ public class ViewRegistryTest {
       }
     }
 
+
+
     // verify mocks
     verify(configuration, viewDir, extractedArchiveDir, viewArchive, archiveDir, entryFile,
classesDir,
         libDir, metaInfDir, fileEntry, viewJarFile, jarEntry, fos, resourceDAO, viewDAO,
viewInstanceDAO);


Mime
View raw message