UpgradeCatalog250 extends AbstractUpgradeCatalog { @Override protected void updateKerberosDescriptorArtifact(ArtifactDAO artifactDAO, ArtifactEntity artifactEntity) throws AmbariException { if (artifactEntity != null) { Map<String, Object> data = artifactEntity.getArtifactData(); if (data != null) { final KerberosDescriptor kerberosDescriptor = new KerberosDescriptorFactory().createInstance(data); if (kerberosDescriptor != null) { KerberosServiceDescriptor logSearchKerberosDescriptor = kerberosDescriptor.getService("LOGSEARCH"); KerberosServiceDescriptor atlasKerberosDescriptor = kerberosDescriptor.getService("ATLAS"); KerberosServiceDescriptor rangerKerberosDescriptor = kerberosDescriptor.getService("RANGER"); addInfrSolrDescriptor(artifactDAO, artifactEntity, kerberosDescriptor, atlasKerberosDescriptor, "ATLAS_SERVER"); addInfrSolrDescriptor(artifactDAO, artifactEntity, kerberosDescriptor, logSearchKerberosDescriptor, "LOGSEARCH_SERVER"); addInfrSolrDescriptor(artifactDAO, artifactEntity, kerberosDescriptor, rangerKerberosDescriptor, "RANGER_ADMIN"); KerberosServiceDescriptor stormKerberosDescriptor = kerberosDescriptor.getService("STORM"); if (stormKerberosDescriptor != null) { KerberosComponentDescriptor componentDescriptor = stormKerberosDescriptor.getComponent("NIMBUS"); if (componentDescriptor != null) { KerberosIdentityDescriptor origIdentityDescriptor = componentDescriptor.getIdentity("/STORM/NIMBUS/nimbus_server"); if (origIdentityDescriptor != null) { KerberosPrincipalDescriptor origPrincipalDescriptor = origIdentityDescriptor.getPrincipalDescriptor(); KerberosPrincipalDescriptor newPrincipalDescriptor = new KerberosPrincipalDescriptor( null, null, (origPrincipalDescriptor == null) ? "ranger-storm-audit/xasecure.audit.jaas.Client.option.principal" : origPrincipalDescriptor.getConfiguration(), null ); KerberosKeytabDescriptor origKeytabDescriptor = origIdentityDescriptor.getKeytabDescriptor(); KerberosKeytabDescriptor newKeytabDescriptor = new KerberosKeytabDescriptor( null, null, null, null, null, (origKeytabDescriptor == null) ? "ranger-storm-audit/xasecure.audit.jaas.Client.option.keyTab" : origKeytabDescriptor.getConfiguration(), false); componentDescriptor.removeIdentity("/STORM/NIMBUS/nimbus_server"); componentDescriptor.putIdentity(new KerberosIdentityDescriptor("/STORM/storm_components", null, newPrincipalDescriptor, newKeytabDescriptor, null)); } } } KerberosServiceDescriptor yarnKerberosDescriptor = kerberosDescriptor.getService("YARN"); if (yarnKerberosDescriptor != null) { Map<String, KerberosConfigurationDescriptor> configs = yarnKerberosDescriptor.getConfigurations(); KerberosConfigurationDescriptor yarnSiteConfigDescriptor = configs.get("yarn-site"); if (yarnSiteConfigDescriptor != null) { Map<String, String> properties = yarnSiteConfigDescriptor.getProperties(); if (properties != null && properties.containsKey(YARN_LCE_CGROUPS_MOUNT_PATH)) { properties.remove(YARN_LCE_CGROUPS_MOUNT_PATH); } } } KerberosServiceDescriptor hbaseKerberosDescriptor = kerberosDescriptor.getService("HBASE"); if (hbaseKerberosDescriptor != null) { KerberosComponentDescriptor hbaseMasterKerberosDescriptor = hbaseKerberosDescriptor.getComponent("HBASE_MASTER"); if (hbaseMasterKerberosDescriptor != null) { KerberosIdentityDescriptor identityDescriptor = hbaseMasterKerberosDescriptor.getIdentity("/HBASE/HBASE_MASTER/hbase_master_hbase"); if (identityDescriptor != null) { KerberosPrincipalDescriptor principalDescriptor = identityDescriptor.getPrincipalDescriptor(); KerberosKeytabDescriptor keytabDescriptor = identityDescriptor.getKeytabDescriptor(); identityDescriptor.setReference(identityDescriptor.getName()); identityDescriptor.setName("ranger_hbase_audit"); principalDescriptor.setValue(null); keytabDescriptor.setFile(null); } } } artifactEntity.setArtifactData(kerberosDescriptor.toMap()); artifactDAO.merge(artifactEntity); } } } } @Inject  UpgradeCatalog250(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); static final String COMPONENT_TABLE; static final String COMPONENT_VERSION_TABLE; static final String COMPONENT_VERSION_PK; static final String COMPONENT_VERSION_FK_COMPONENT; static final String COMPONENT_VERSION_FK_REPO_VERSION; }
@Test public void testUpdateKerberosDescriptorArtifact() throws Exception { final String propertyToRemove = "yarn.nodemanager.linux-container-executor.cgroups.mount-path"; final KerberosDescriptorFactory kerberosDescriptorFactory = new KerberosDescriptorFactory(); KerberosServiceDescriptor serviceDescriptor; URL systemResourceURL = ClassLoader.getSystemResource("kerberos/test_kerberos_descriptor_2_5_infra_solr.json"); Assert.assertNotNull(systemResourceURL); final KerberosDescriptor kerberosDescriptorOrig = kerberosDescriptorFactory.createInstance(new File(systemResourceURL.getFile())); serviceDescriptor = kerberosDescriptorOrig.getService("LOGSEARCH"); Assert.assertNotNull(serviceDescriptor); Assert.assertNotNull(serviceDescriptor.getComponent("LOGSEARCH_SERVER")); Assert.assertNotNull(serviceDescriptor.getComponent("LOGSEARCH_SERVER").getIdentity("logsearch")); Assert.assertNotNull(serviceDescriptor.getComponent("LOGSEARCH_SERVER").getIdentity("/AMBARI_INFRA/INFRA_SOLR/infra-solr")); serviceDescriptor = kerberosDescriptorOrig.getService("ATLAS"); Assert.assertNotNull(serviceDescriptor); Assert.assertNotNull(serviceDescriptor.getComponent("ATLAS_SERVER")); serviceDescriptor = kerberosDescriptorOrig.getService("RANGER"); Assert.assertNotNull(serviceDescriptor); Assert.assertNotNull(serviceDescriptor.getComponent("RANGER_ADMIN")); serviceDescriptor = kerberosDescriptorOrig.getService("STORM"); Assert.assertNotNull(serviceDescriptor); Assert.assertNotNull(serviceDescriptor.getComponent("NIMBUS")); UpgradeCatalog250 upgradeMock = createMockBuilder(UpgradeCatalog250.class).withConstructor(injector).createMock(); ArtifactEntity artifactEntity = createNiceMock(ArtifactEntity.class); expect(artifactEntity.getArtifactData()) .andReturn(kerberosDescriptorOrig.toMap()) .once(); Capture<Map<String, Object>> updateData = Capture.newInstance(CaptureType.ALL); artifactEntity.setArtifactData(capture(updateData)); expectLastCall().times(1); ArtifactDAO artifactDAO = createNiceMock(ArtifactDAO.class); expect(artifactDAO.merge(anyObject(ArtifactEntity.class))).andReturn(artifactEntity).times(1); replay(artifactEntity, artifactDAO, upgradeMock); upgradeMock.updateKerberosDescriptorArtifact(artifactDAO, artifactEntity); verify(artifactEntity, artifactDAO, upgradeMock); KerberosDescriptor kerberosDescriptorUpdated = new KerberosDescriptorFactory().createInstance(updateData.getValue()); getIdentity(kerberosDescriptorUpdated,null, null, "spnego"); getIdentity(kerberosDescriptorUpdated,"LOGSEARCH", "LOGSEARCH_SERVER", "/AMBARI_INFRA/INFRA_SOLR/infra-solr"); getIdentity(kerberosDescriptorUpdated,"ATLAS", "ATLAS_SERVER", "/AMBARI_INFRA/INFRA_SOLR/infra-solr"); getIdentity(kerberosDescriptorUpdated,"RANGER", "RANGER_ADMIN", "/AMBARI_INFRA/INFRA_SOLR/infra-solr"); getIdentity(kerberosDescriptorUpdated,"STORM", "NIMBUS", "/STORM/storm_components"); Assert.assertFalse(kerberosDescriptorUpdated.getService("YARN").getConfigurations().get("yarn-site").getProperties().containsKey(propertyToRemove)); KerberosIdentityDescriptor rangerHbaseAuditIdentityDescriptor = getIdentity(kerberosDescriptorUpdated,"HBASE", "HBASE_MASTER", "ranger_hbase_audit"); KerberosPrincipalDescriptor rangerHbaseAuditPrincipalDescriptor = rangerHbaseAuditIdentityDescriptor.getPrincipalDescriptor(); Assert.assertNotNull(rangerHbaseAuditPrincipalDescriptor); Assert.assertNull(rangerHbaseAuditPrincipalDescriptor.getValue()); KerberosKeytabDescriptor rangerHbaseAuditKeytabDescriptor = rangerHbaseAuditIdentityDescriptor.getKeytabDescriptor(); Assert.assertNotNull(rangerHbaseAuditKeytabDescriptor); Assert.assertNull(rangerHbaseAuditKeytabDescriptor.getFile()); }