UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void updatePhoenixConfigs() 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() && isAtLeastHdp25(stackId)) { Config hbaseSite = cluster.getDesiredConfigByType(HBASE_SITE_CONFIG); if (null != hbaseSite) { Map<String, String> hbaseSiteProperties = hbaseSite.getProperties(); String pqsKrbPrincipal = hbaseSiteProperties.get(PHOENIX_QUERY_SERVER_PRINCIPAL_KEY); String pqsKrbKeytab = hbaseSiteProperties.get(PHOENIX_QUERY_SERVER_KEYTAB_KEY); if (null != pqsKrbPrincipal && null != pqsKrbKeytab) { final Map<String, String> updatedKerberosProperties = new HashMap<>(); final KerberosDescriptor defaultDescriptor = getKerberosDescriptor(cluster); KerberosIdentityDescriptor spnegoDescriptor = defaultDescriptor.getIdentity("spnego"); if (null != spnegoDescriptor) { KerberosPrincipalDescriptor principalDescriptor = spnegoDescriptor.getPrincipalDescriptor(); if (null != principalDescriptor) { updatedKerberosProperties.put(PHOENIX_QUERY_SERVER_PRINCIPAL_KEY, principalDescriptor.getValue()); } KerberosKeytabDescriptor keytabDescriptor = spnegoDescriptor.getKeytabDescriptor(); if (null != keytabDescriptor) { updatedKerberosProperties.put(PHOENIX_QUERY_SERVER_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 testPhoenixQueryServerKerberosUpdateConfigs() throws Exception{ final String spnegoPrincipal = "HTTP/_HOST@EXAMPLE.COM"; final String spnegoKeytab = "/etc/security/keytabs/spnego.service.keytab"; final Map<String, String> oldPqsProperties = new HashMap<>(); oldPqsProperties.put("phoenix.queryserver.kerberos.principal", "hbase/_HOST@EXAMPLE.COM"); oldPqsProperties.put("phoenix.queryserver.keytab.file", "/etc/security/keytabs/hbase.service.keytab"); final Map<String, String> newPqsProperties = new HashMap<String, String>(); newPqsProperties.put("phoenix.queryserver.kerberos.principal", spnegoPrincipal); newPqsProperties.put("phoenix.queryserver.keytab.file", spnegoKeytab); final EasyMockSupport easyMockSupport = new EasyMockSupport(); AmbariManagementController controller = easyMockSupport.createNiceMock(AmbariManagementController.class); KerberosDescriptor kerberosDescriptor = easyMockSupport.createNiceMock(KerberosDescriptor.class); KerberosIdentityDescriptor kerberosIdentityDescriptor = easyMockSupport.createNiceMock(KerberosIdentityDescriptor.class); KerberosPrincipalDescriptor principalDescriptor = easyMockSupport.createNiceMock(KerberosPrincipalDescriptor.class); KerberosKeytabDescriptor keytabDescriptor = easyMockSupport.createNiceMock(KerberosKeytabDescriptor.class); Clusters clusters = easyMockSupport.createNiceMock(Clusters.class); final Cluster cluster = easyMockSupport.createNiceMock(Cluster.class); Config mockHbaseSite = easyMockSupport.createNiceMock(Config.class); final Map<String, Service> mockServices = new HashMap<>(); mockServices.put("HBASE", null); final StackId stackId = new StackId("HDP-2.5"); expect(controller.getClusters()).andReturn(clusters).once(); expect(clusters.getClusters()).andReturn(Collections.singletonMap("normal", cluster)).once(); expect(cluster.getCurrentStackVersion()).andReturn(stackId); expect(cluster.getServices()).andReturn(mockServices).once(); expect(cluster.getSecurityType()).andReturn(SecurityType.KERBEROS).anyTimes(); expect(cluster.getDesiredConfigByType(UpgradeCatalog240.HBASE_SITE_CONFIG)).andReturn(mockHbaseSite).atLeastOnce(); expect(mockHbaseSite.getProperties()).andReturn(oldPqsProperties).anyTimes(); expect(kerberosDescriptor.getIdentity("spnego")).andReturn(kerberosIdentityDescriptor).once(); expect(kerberosIdentityDescriptor.getPrincipalDescriptor()).andReturn(principalDescriptor).anyTimes(); expect(kerberosIdentityDescriptor.getKeytabDescriptor()).andReturn(keytabDescriptor).anyTimes(); expect(principalDescriptor.getValue()).andReturn(spnegoPrincipal).anyTimes(); expect(keytabDescriptor.getFile()).andReturn(spnegoKeytab).anyTimes(); Injector injector = easyMockSupport.createNiceMock(Injector.class); expect(injector.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes(); easyMockSupport.replayAll(); UpgradeCatalog240 upgradeCatalog240 = createMockBuilder(UpgradeCatalog240.class) .withConstructor(Injector.class) .withArgs(injector) .addMockedMethod("updateConfigurationProperties", String.class, Map.class, boolean.class, boolean.class) .addMockedMethod("getKerberosDescriptor", Cluster.class) .createMock(); expect(upgradeCatalog240.getKerberosDescriptor(cluster)).andReturn(kerberosDescriptor).once(); upgradeCatalog240.updateConfigurationProperties(UpgradeCatalog240.HBASE_SITE_CONFIG, newPqsProperties, true, false); expectLastCall().once(); replay(upgradeCatalog240); upgradeCatalog240.updatePhoenixConfigs(); easyMockSupport.verifyAll(); }
@Test public void testHBaseSpnegoPropertiesAreAdded() throws Exception{ final String spnegoPrincipal = "HTTP/_HOST@EXAMPLE.COM"; final String spnegoKeytab = "/etc/security/keytabs/spnego.service.keytab"; final Map<String, String> oldProperties = new HashMap<>(); final Map<String, String> newProperties = new HashMap<String, String>(); newProperties.put(UpgradeCatalog240.HBASE_SPNEGO_PRINCIPAL_KEY, spnegoPrincipal); newProperties.put(UpgradeCatalog240.HBASE_SPNEGO_KEYTAB_KEY, spnegoKeytab); final EasyMockSupport easyMockSupport = new EasyMockSupport(); AmbariManagementController controller = easyMockSupport.createNiceMock(AmbariManagementController.class); KerberosDescriptor kerberosDescriptor = easyMockSupport.createNiceMock(KerberosDescriptor.class); KerberosIdentityDescriptor kerberosIdentityDescriptor = easyMockSupport.createNiceMock(KerberosIdentityDescriptor.class); KerberosPrincipalDescriptor principalDescriptor = easyMockSupport.createNiceMock(KerberosPrincipalDescriptor.class); KerberosKeytabDescriptor keytabDescriptor = easyMockSupport.createNiceMock(KerberosKeytabDescriptor.class); Clusters clusters = easyMockSupport.createNiceMock(Clusters.class); final Cluster cluster = easyMockSupport.createNiceMock(Cluster.class); Config mockHbaseSite = easyMockSupport.createNiceMock(Config.class); final Map<String, Service> mockServices = new HashMap<>(); mockServices.put("HBASE", null); final StackId stackId = new StackId("HDP-2.5"); expect(controller.getClusters()).andReturn(clusters).once(); expect(clusters.getClusters()).andReturn(Collections.singletonMap("normal", cluster)).once(); expect(cluster.getCurrentStackVersion()).andReturn(stackId); expect(cluster.getServices()).andReturn(mockServices).once(); expect(cluster.getSecurityType()).andReturn(SecurityType.KERBEROS).anyTimes(); expect(cluster.getDesiredConfigByType(UpgradeCatalog240.HBASE_SITE_CONFIG)).andReturn(mockHbaseSite).atLeastOnce(); expect(mockHbaseSite.getProperties()).andReturn(oldProperties).anyTimes(); expect(kerberosDescriptor.getIdentity("spnego")).andReturn(kerberosIdentityDescriptor).anyTimes(); expect(kerberosIdentityDescriptor.getPrincipalDescriptor()).andReturn(principalDescriptor).anyTimes(); expect(kerberosIdentityDescriptor.getKeytabDescriptor()).andReturn(keytabDescriptor).anyTimes(); expect(principalDescriptor.getValue()).andReturn(spnegoPrincipal).anyTimes(); expect(keytabDescriptor.getFile()).andReturn(spnegoKeytab).anyTimes(); Injector injector = easyMockSupport.createNiceMock(Injector.class); expect(injector.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes(); easyMockSupport.replayAll(); UpgradeCatalog240 upgradeCatalog240 = createMockBuilder(UpgradeCatalog240.class) .withConstructor(Injector.class) .withArgs(injector) .addMockedMethod("updateConfigurationProperties", String.class, Map.class, boolean.class, boolean.class) .addMockedMethod("getKerberosDescriptor", Cluster.class) .createMock(); expect(upgradeCatalog240.getKerberosDescriptor(cluster)).andReturn(kerberosDescriptor).once(); upgradeCatalog240.updateConfigurationProperties(UpgradeCatalog240.HBASE_SITE_CONFIG, newProperties, true, false); expectLastCall().once(); replay(upgradeCatalog240); upgradeCatalog240.updatePhoenixConfigs(); easyMockSupport.verifyAll(); }