UpgradeCatalog240 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 = Collections.singletonList("NameNode Operations"); widgetMap.put("HDFS_SUMMARY", hdfsSummaryWidgets); sectionLayoutMap.put("HDFS_SUMMARY", "default_hdfs_dashboard"); updateWidgetDefinitionsForService("HDFS", widgetMap, sectionLayoutMap); } @Inject  UpgradeCatalog240(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); static final String DESIRED_VERSION_COLUMN_NAME; static final String BLUEPRINT_SETTING_TABLE; static final String BLUEPRINT_NAME_COL; static final String SETTING_NAME_COL; static final String SETTING_DATA_COL; static final String ID; static final String BLUEPRINT_TABLE; static final String VIEWINSTANCE_TABLE; static final String SHORT_URL_COLUMN; static final String CLUSTER_HANDLE_COLUMN; static final String REQUESTSCHEDULE_TABLE; static final String AUTHENTICATED_USER_ID_COLUMN; static final String TIMELINE_METRICS_SINK_COLLECTION_PERIOD; static final String ONE_DIR_PER_PARITION_PROPERTY; static final String VIEWURL_TABLE; static final String URL_ID_COLUMN; static final String PRECISION_TABLE_TTL_PROPERTY; static final String CLUSTER_SECOND_TABLE_TTL_PROPERTY; static final String CLUSTER_TYPE_COLUMN; static final String REMOTE_AMBARI_CLUSTER_TABLE; static final String REMOTE_AMBARI_CLUSTER_SERVICE_TABLE; static final String CLUSTER_ID; static final String SERVICE_NAME; static final String CLUSTER_NAME; }
@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); 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 Operations\",\n" + " \"metrics\": [],\n" + " \"values\": []\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + "}"; TemporaryFolder temporaryFolder = new TemporaryFolder(); 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); bind(PasswordEncoder.class).toInstance(createNiceMock(PasswordEncoder.class)); bind(HookContextFactory.class).toInstance(createMock(HookContextFactory.class)); bind(HookService.class).toInstance(createMock(HookService.class)); } }); 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 Operations", "ambari", "HDFS_SUMMARY")) .andReturn(Collections.singletonList(widgetEntity)); expect(widgetDAO.merge(widgetEntity)).andReturn(null); expect(widgetEntity.getWidgetName()).andReturn("Namenode Operations").anyTimes(); replay(clusters, cluster, controller, widgetDAO, metaInfo, widgetEntity, stackInfo, serviceInfo); mockInjector.getInstance(UpgradeCatalog240.class).updateHDFSWidgetDefinition(); verify(clusters, cluster, controller, widgetDAO, widgetEntity, stackInfo, serviceInfo); }