UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void addSliderClientConfig() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); ConfigHelper configHelper = ambariManagementController.getConfigHelper(); Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters); for (final Cluster cluster : clusterMap.values()) { Set<String> installedServices = cluster.getServices().keySet(); if (installedServices.contains(SLIDER_SERVICE_NAME)) { Config sliderClientConfig = cluster.getDesiredConfigByType(SLIDER_CLIENT_CONFIG); if (sliderClientConfig == null) { configHelper.createConfigType(cluster, ambariManagementController, SLIDER_CLIENT_CONFIG, new HashMap<String, String>(), AUTHENTICATED_USER_NAME, ""); } } } } @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 testAddSliderClientConfig() throws Exception{ EasyMockSupport easyMockSupport = new EasyMockSupport(); final AmbariManagementController mockAmbariManagementController = easyMockSupport.createNiceMock(AmbariManagementController.class); final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class); final Cluster mockClusterExpected = easyMockSupport.createNiceMock(Cluster.class); final ConfigHelper configHelper = easyMockSupport.createNiceMock(ConfigHelper.class); final Service serviceSlider = easyMockSupport.createNiceMock(Service.class); Map<String, Service> servicesMap = new HashMap<>(); servicesMap.put("SLIDER", serviceSlider); final Injector mockInjector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(AmbariManagementController.class).toInstance(mockAmbariManagementController); bind(PasswordEncoder.class).toInstance(createMock(PasswordEncoder.class)); bind(Clusters.class).toInstance(mockClusters); bind(EntityManager.class).toInstance(entityManager); bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class)); bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class)); bind(HookContextFactory.class).toInstance(createMock(HookContextFactory.class)); bind(HookService.class).toInstance(createMock(HookService.class)); } }); expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once(); expect(mockClusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ put("normal", mockClusterExpected); }}).atLeastOnce(); expect(mockAmbariManagementController.getConfigHelper()).andReturn(configHelper).once(); expect(mockClusterExpected.getServices()).andReturn(servicesMap).once(); expect(mockClusterExpected.getDesiredConfigByType("slider-client")).andReturn(null).once(); configHelper.createConfigType(mockClusterExpected, mockAmbariManagementController, "slider-client", new HashMap<String, String>(), "ambari-upgrade", ""); expectLastCall().once(); easyMockSupport.replayAll(); mockInjector.getInstance(UpgradeCatalog240.class).addSliderClientConfig(); easyMockSupport.verifyAll(); }