UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void updateHBaseConfigs() throws AmbariException { final AmbariManagementController controller = injector.getInstance(AmbariManagementController.class); final Clusters clusters = controller.getClusters(); if (null != clusters) { Map<String, Cluster> clusterMap = clusters.getClusters(); if (null != clusterMap && !clusterMap.isEmpty()) { for (final Cluster cluster : clusterMap.values()) { Set<String> installedServices = cluster.getServices().keySet(); StackId stackId = cluster.getCurrentStackVersion(); if (installedServices.contains("HBASE") && SecurityType.KERBEROS == cluster.getSecurityType()) { Config hbaseSite = cluster.getDesiredConfigByType(HBASE_SITE_CONFIG); if (null != hbaseSite) { Map<String, String> hbaseSiteProperties = hbaseSite.getProperties(); boolean enableRangerHbase = false; boolean xmlConfigurationsSupported = false; Config rangerHbasePluginProperties = cluster.getDesiredConfigByType("ranger-hbase-plugin-properties"); if (rangerHbasePluginProperties != null && rangerHbasePluginProperties.getProperties().containsKey("ranger-hbase-plugin-enabled")) { enableRangerHbase = rangerHbasePluginProperties.getProperties().get("ranger-hbase-plugin-enabled").toLowerCase() == "yes"; } Config rangerEnv = cluster.getDesiredConfigByType("ranger-env"); if (rangerEnv != null && rangerEnv.getProperties().containsKey("xml_configurations_supported")) { xmlConfigurationsSupported = Boolean.parseBoolean(rangerEnv.getProperties().get("xml_configurations_supported")); } final Map<String, String> updatedHbaseProperties = new HashMap<>(); if (hbaseSiteProperties.containsKey("hbase.coprocessor.master.classes") && hbaseSiteProperties.get("hbase.coprocessor.master.classes").equals("{{hbase_coprocessor_master_classes}}")) { if (!enableRangerHbase) { updatedHbaseProperties.put("hbase.coprocessor.master.classes", "org.apache.hadoop.hbase.security.access.AccessController"); } else if (xmlConfigurationsSupported) { updatedHbaseProperties.put("hbase.coprocessor.master.classes", "org.apache.ranger.authorization.hbase.RangerAuthorizationCoprocessor"); } else { updatedHbaseProperties.put("hbase.coprocessor.master.classes", "com.xasecure.authorization.hbase.XaSecureAuthorizationCoprocessor"); } } if (hbaseSiteProperties.containsKey("hbase.coprocessor.regionserver.classes") && hbaseSiteProperties.get("hbase.coprocessor.regionserver.classes").equals("{{hbase_coprocessor_regionserver_classes}}")) { if (!enableRangerHbase) { updatedHbaseProperties.put("hbase.coprocessor.regionserver.classes", "org.apache.hadoop.hbase.security.access.AccessController"); } else if (xmlConfigurationsSupported) { updatedHbaseProperties.put("hbase.coprocessor.regionserver.classes", "org.apache.ranger.authorization.hbase.RangerAuthorizationCoprocessor"); } else { updatedHbaseProperties.put("hbase.coprocessor.regionserver.classes", "com.xasecure.authorization.hbase.XaSecureAuthorizationCoprocessor"); } } if (hbaseSiteProperties.containsKey("hbase.coprocessor.region.classes") && hbaseSiteProperties.get("hbase.coprocessor.region.classes").equals("{{hbase_coprocessor_region_classes}}")) { if (!enableRangerHbase) { updatedHbaseProperties.put("hbase.coprocessor.region.classes", "org.apache.hadoop.hbase.security.token.TokenProvider,org.apache.hadoop.hbase.security.access.SecureBulkLoadEndpoint,org.apache.hadoop.hbase.security.access.AccessController"); } else if (xmlConfigurationsSupported) { updatedHbaseProperties.put("hbase.coprocessor.region.classes", "org.apache.hadoop.hbase.security.token.TokenProvider,org.apache.hadoop.hbase.security.access.SecureBulkLoadEndpoint,org.apache.ranger.authorization.hbase.RangerAuthorizationCoprocessor"); } else { updatedHbaseProperties.put("hbase.coprocessor.region.classes", "org.apache.hadoop.hbase.security.token.TokenProvider,org.apache.hadoop.hbase.security.access.SecureBulkLoadEndpoint,com.xasecure.authorization.hbase.XaSecureAuthorizationCoprocessor"); } } updateConfigurationProperties(HBASE_SITE_CONFIG, updatedHbaseProperties, true, false); if (isAtLeastHdp25(stackId)) { String principal = hbaseSiteProperties.get(HBASE_SPNEGO_PRINCIPAL_KEY); String keytab = hbaseSiteProperties.get(HBASE_SPNEGO_KEYTAB_KEY); final Map<String, String> updatedKerberosProperties = new HashMap<>(); if (null == principal) { final KerberosDescriptor defaultDescriptor = getKerberosDescriptor(cluster); final KerberosIdentityDescriptor spnegoDescriptor = defaultDescriptor.getIdentity("spnego"); if (null != spnegoDescriptor) { KerberosPrincipalDescriptor principalDescriptor = spnegoDescriptor.getPrincipalDescriptor(); if (null != principalDescriptor) { updatedKerberosProperties.put(HBASE_SPNEGO_PRINCIPAL_KEY, principalDescriptor.getValue()); } } } if (null == keytab) { final KerberosDescriptor defaultDescriptor = getKerberosDescriptor(cluster); final KerberosIdentityDescriptor spnegoDescriptor = defaultDescriptor.getIdentity("spnego"); if (null != spnegoDescriptor) { KerberosKeytabDescriptor keytabDescriptor = spnegoDescriptor.getKeytabDescriptor(); if (null != keytabDescriptor) { updatedKerberosProperties.put(HBASE_SPNEGO_KEYTAB_KEY, keytabDescriptor.getFile()); } } } if (!updatedKerberosProperties.isEmpty()) { updateConfigurationProperties(HBASE_SITE_CONFIG, updatedKerberosProperties, true, false); } } } } } } } } @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 testUpdateHbaseConfigs() throws Exception{ EasyMockSupport easyMockSupport = new EasyMockSupport(); final AmbariManagementController mockAmbariManagementController = easyMockSupport.createNiceMock( AmbariManagementController.class); final ConfigHelper mockConfigHelper = easyMockSupport.createMock(ConfigHelper.class); final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class); final Cluster mockCluster = easyMockSupport.createNiceMock(Cluster.class); final Injector mockInjector = Guice.createInjector(new Module() { @Override public void configure(Binder binder) { binder.bind(AmbariManagementController.class).toInstance(mockAmbariManagementController); binder.bind(ConfigHelper.class).toInstance(mockConfigHelper); binder.bind(Clusters.class).toInstance(mockClusters); binder.bind(EntityManager.class).toInstance(entityManager); binder.bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class)); binder.bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class)); binder.bind(PasswordEncoder.class).toInstance(createNiceMock(PasswordEncoder.class)); binder.bind(HookContextFactory.class).toInstance(createMock(HookContextFactory.class)); binder.bind(HookService.class).toInstance(createMock(HookService.class)); } }); expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).anyTimes(); expect(mockClusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ put("normal", mockCluster); }}).anyTimes(); expect(mockCluster.getServices()).andReturn(new HashMap<String, Service>(){{put("HBASE",null);}}).anyTimes(); expect(mockCluster.getSecurityType()).andReturn(SecurityType.KERBEROS).anyTimes(); final Config mockHbaseSiteConfigs = easyMockSupport.createNiceMock(Config.class); expect(mockCluster.getDesiredConfigByType("hbase-site")).andReturn(mockHbaseSiteConfigs).atLeastOnce(); expect(mockHbaseSiteConfigs.getProperties()).andReturn(new HashMap<String, String>(){{ put("hbase.coprocessor.regionserver.classes","{{hbase_coprocessor_regionserver_classes}}"); put("hbase.coprocessor.region.classes","{{hbase_coprocessor_region_classes}}"); }}).anyTimes(); final Config mockRangerHbaseConfigs = easyMockSupport.createNiceMock(Config.class); expect(mockCluster.getDesiredConfigByType("ranger-hbase-plugin-properties")).andReturn(mockRangerHbaseConfigs).atLeastOnce(); expect(mockRangerHbaseConfigs.getProperties()).andReturn(new HashMap<String, String>(){{ put("ranger-hbase-plugin-enabled", "yes"); }}).anyTimes(); final Config mockRangerEnvConfigs = easyMockSupport.createNiceMock(Config.class); expect(mockCluster.getDesiredConfigByType("ranger-env")).andReturn(mockRangerEnvConfigs).atLeastOnce(); expect(mockRangerEnvConfigs.getProperties()).andReturn(new HashMap<String, String>(){{ put("xml_configurations_supported", "true"); }}).anyTimes(); Capture<Map<String, String>> hbaseCapture = newCapture(); expect(mockAmbariManagementController.createConfig(eq(mockCluster), eq("hbase-site"), capture(hbaseCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(null).once(); easyMockSupport.replayAll(); mockInjector.getInstance(UpgradeCatalog240.class).updateHBaseConfigs(); easyMockSupport.verifyAll(); assertEquals("org.apache.ranger.authorization.hbase.RangerAuthorizationCoprocessor", hbaseCapture.getValue().get("hbase.coprocessor.regionserver.classes")); assertEquals("org.apache.hadoop.hbase.security.token.TokenProvider,org.apache.hadoop.hbase.security.access.SecureBulkLoadEndpoint,org.apache.ranger.authorization.hbase.RangerAuthorizationCoprocessor", hbaseCapture.getValue().get("hbase.coprocessor.region.classes")); }