UpgradeCatalog222 extends AbstractUpgradeCatalog { protected void updateHDFSWidgetDefinition() throws AmbariException { LOG.info("Updating HDFS widget definition."); Map<String, List<String>> widgetMap = new HashMap<>(); Map<String, String> sectionLayoutMap = new HashMap<>(); List<String> hdfsSummaryWidgets = new ArrayList<>(Arrays.asList("NameNode RPC", "NN Connection Load", "NameNode GC count", "NameNode GC time", "NameNode Host Load")); widgetMap.put("HDFS_SUMMARY", hdfsSummaryWidgets); sectionLayoutMap.put("HDFS_SUMMARY", "default_hdfs_dashboard"); List<String> hdfsHeatmapWidgets = new ArrayList<>(Arrays.asList("HDFS Bytes Read", "HDFS Bytes Written", "DataNode Process Disk I/O Utilization", "DataNode Process Network I/O Utilization")); widgetMap.put("HDFS_HEATMAPS", hdfsHeatmapWidgets); sectionLayoutMap.put("HDFS_HEATMAPS", "default_hdfs_heatmap"); updateWidgetDefinitionsForService("HDFS", widgetMap, sectionLayoutMap); } @Inject  UpgradeCatalog222(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); static final String PRECISION_TABLE_TTL_PROPERTY; static final String CLUSTER_SECOND_TABLE_TTL_PROPERTY; static final String CLUSTER_MINUTE_TABLE_TTL_PROPERTY; static final String AMS_WEBAPP_ADDRESS_PROPERTY; static final String HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD_PROPERTY; static final String HBASE_RPC_TIMEOUT_PROPERTY; static final String PHOENIX_QUERY_TIMEOUT_PROPERTY; static final String PHOENIX_QUERY_KEEPALIVE_PROPERTY; static final String TIMELINE_METRICS_CLUSTER_AGGREGATOR_INTERPOLATION_ENABLED; static final String TIMELINE_METRICS_SINK_COLLECTION_PERIOD; static final String AMS_SERVICE_NAME; static final String AMS_COLLECTOR_COMPONENT_NAME; final static String HBASE_SITE_HBASE_COPROCESSOR_MASTER_CLASSES; final static String HBASE_SITE_HBASE_COPROCESSOR_REGION_CLASSES; final static String HBASE_SITE_HBASE_COPROCESSOR_REGIONSERVER_CLASSES; }
@Test public void testHDFSWidgetUpdateWithOnlyZkService() throws Exception { final Clusters clusters = createNiceMock(Clusters.class); final Cluster cluster = createNiceMock(Cluster.class); final AmbariManagementController controller = createNiceMock(AmbariManagementController.class); final Gson gson = new Gson(); final WidgetDAO widgetDAO = createNiceMock(WidgetDAO.class); final AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class); StackInfo stackInfo = createNiceMock(StackInfo.class); StackId stackId = new StackId("HDP", "2.0.0"); String widgetStr = "{\"layouts\":[{\"layout_name\":\"default_hdfs_dashboard\",\"display_name\":\"Standard HDFS Dashboard\",\"section_name\":\"HDFS_SUMMARY\",\"widgetLayoutInfo\":[{\"widget_name\":\"NameNode RPC\",\"metrics\":[],\"values\":[]}]}]}"; File dataDirectory = temporaryFolder.newFolder(); File file = new File(dataDirectory, "hdfs_widget.json"); FileUtils.writeStringToFile(file, widgetStr); final Injector mockInjector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(EntityManager.class).toInstance(createNiceMock(EntityManager.class)); bind(AmbariManagementController.class).toInstance(controller); bind(Clusters.class).toInstance(clusters); bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class)); bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class)); bind(Gson.class).toInstance(gson); bind(WidgetDAO.class).toInstance(widgetDAO); bind(StackManagerFactory.class).toInstance(createNiceMock(StackManagerFactory.class)); bind(AmbariMetaInfo.class).toInstance(metaInfo); } }); expect(controller.getClusters()).andReturn(clusters).anyTimes(); expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ put("normal", cluster); }}).anyTimes(); expect(cluster.getClusterId()).andReturn(1L).anyTimes(); expect(stackInfo.getService("HDFS")).andReturn(null); expect(cluster.getDesiredStackVersion()).andReturn(stackId); expect(metaInfo.getStack("HDP", "2.0.0")).andReturn(stackInfo); replay(clusters, cluster, controller, widgetDAO, metaInfo, stackInfo); UpgradeCatalog222 upgradeCatalog222 = createMockBuilder(UpgradeCatalog222.class) .withConstructor(Injector.class) .withArgs(mockInjector) .createMock(); upgradeCatalog222.updateHDFSWidgetDefinition(); }
@Test public void testHDFSWidgetUpdate() throws Exception { final Clusters clusters = createNiceMock(Clusters.class); final Cluster cluster = createNiceMock(Cluster.class); final AmbariManagementController controller = createNiceMock(AmbariManagementController.class); final Gson gson = new Gson(); final WidgetDAO widgetDAO = createNiceMock(WidgetDAO.class); final AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class); WidgetEntity widgetEntity = createNiceMock(WidgetEntity.class); WidgetEntity widgetEntity2 = createNiceMock(WidgetEntity.class); StackId stackId = new StackId("HDP", "2.0.0"); StackInfo stackInfo = createNiceMock(StackInfo.class); ServiceInfo serviceInfo = createNiceMock(ServiceInfo.class); String widgetStr = "{\n" + " \"layouts\": [\n" + " {\n" + " \"layout_name\": \"default_hdfs_dashboard\",\n" + " \"display_name\": \"Standard HDFS Dashboard\",\n" + " \"section_name\": \"HDFS_SUMMARY\",\n" + " \"widgetLayoutInfo\": [\n" + " {\n" + " \"widget_name\": \"NameNode RPC\",\n" + " \"metrics\": [],\n" + " \"values\": []\n" + " }\n" + " ]\n" + " },\n" + " {\n" + " \"layout_name\": \"default_hdfs_heatmap\",\n" + " \"display_name\": \"Standard HDFS HeatMaps\",\n" + " \"section_name\": \"HDFS_HEATMAPS\",\n" + " \"widgetLayoutInfo\": [\n" + " {\n" + " \"widget_name\": \"HDFS Bytes Read\",\n" + " \"metrics\": [],\n" + " \"values\": []\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + "}"; File dataDirectory = temporaryFolder.newFolder(); File file = new File(dataDirectory, "hdfs_widget.json"); FileUtils.writeStringToFile(file, widgetStr); final Injector mockInjector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(EntityManager.class).toInstance(createNiceMock(EntityManager.class)); bind(AmbariManagementController.class).toInstance(controller); bind(Clusters.class).toInstance(clusters); bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class)); bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class)); bind(Gson.class).toInstance(gson); bind(WidgetDAO.class).toInstance(widgetDAO); bind(StackManagerFactory.class).toInstance(createNiceMock(StackManagerFactory.class)); bind(AmbariMetaInfo.class).toInstance(metaInfo); } }); expect(controller.getClusters()).andReturn(clusters).anyTimes(); expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ put("normal", cluster); }}).anyTimes(); expect(cluster.getClusterId()).andReturn(1L).anyTimes(); expect(stackInfo.getService("HDFS")).andReturn(serviceInfo); expect(cluster.getDesiredStackVersion()).andReturn(stackId).anyTimes(); expect(metaInfo.getStack("HDP", "2.0.0")).andReturn(stackInfo).anyTimes(); expect(serviceInfo.getWidgetsDescriptorFile()).andReturn(file).anyTimes(); expect(widgetDAO.findByName(1L, "NameNode RPC", "ambari", "HDFS_SUMMARY")) .andReturn(Collections.singletonList(widgetEntity)); expect(widgetDAO.merge(widgetEntity)).andReturn(null); expect(widgetEntity.getWidgetName()).andReturn("Namenode RPC").anyTimes(); expect(widgetDAO.findByName(1L, "HDFS Bytes Read", "ambari", "HDFS_HEATMAPS")) .andReturn(Collections.singletonList(widgetEntity2)); expect(widgetDAO.merge(widgetEntity2)).andReturn(null); expect(widgetEntity2.getWidgetName()).andReturn("HDFS Bytes Read").anyTimes(); replay(clusters, cluster, controller, widgetDAO, metaInfo, widgetEntity, widgetEntity2, stackInfo, serviceInfo); mockInjector.getInstance(UpgradeCatalog222.class).updateHDFSWidgetDefinition(); verify(clusters, cluster, controller, widgetDAO, widgetEntity, widgetEntity2, stackInfo, serviceInfo); }