@Test public void testUpdateKerberosDescriptorArtifact() throws Exception { final KerberosDescriptorFactory kerberosDescriptorFactory = new KerberosDescriptorFactory(); KerberosServiceDescriptor serviceDescriptor; URL systemResourceURL = ClassLoader.getSystemResource("kerberos/test_kerberos_descriptor_2_1_3.json"); assertNotNull(systemResourceURL); final KerberosDescriptor kerberosDescriptorOrig = kerberosDescriptorFactory.createInstance(new File(systemResourceURL.getFile())); assertNotNull(kerberosDescriptorOrig); serviceDescriptor = kerberosDescriptorOrig.getService("HDFS"); assertNotNull(serviceDescriptor); assertNotNull(serviceDescriptor.getIdentity("hdfs")); serviceDescriptor = kerberosDescriptorOrig.getService("OOZIE"); assertNotNull(serviceDescriptor); assertNotNull(serviceDescriptor.getIdentity("/HDFS/hdfs")); UpgradeCatalog220 upgradeMock = createMockBuilder(UpgradeCatalog220.class).createMock(); Capture<Map<String, Object>> updatedData = EasyMock.newCapture(); ArtifactEntity artifactEntity = createNiceMock(ArtifactEntity.class); expect(artifactEntity.getArtifactData()) .andReturn(kerberosDescriptorOrig.toMap()) .once(); artifactEntity.setArtifactData(capture(updatedData)); expectLastCall().once(); replay(artifactEntity, upgradeMock); upgradeMock.updateKerberosDescriptorArtifact(createNiceMock(ArtifactDAO.class), artifactEntity); verify(artifactEntity, upgradeMock); KerberosDescriptor kerberosDescriptorUpdated = new KerberosDescriptorFactory().createInstance(updatedData.getValue()); assertNotNull(kerberosDescriptorUpdated); serviceDescriptor = kerberosDescriptorUpdated.getService("HDFS"); assertNotNull(serviceDescriptor); assertNull(serviceDescriptor.getIdentity("hdfs")); KerberosComponentDescriptor namenodeComponent = serviceDescriptor.getComponent("NAMENODE"); assertNotNull(namenodeComponent.getIdentity("hdfs")); serviceDescriptor = kerberosDescriptorUpdated.getService("OOZIE"); assertNotNull(serviceDescriptor); assertNull(serviceDescriptor.getIdentity("/HDFS/hdfs")); assertNotNull(serviceDescriptor.getIdentity("/HDFS/NAMENODE/hdfs")); KerberosDescriptor kerberosDescriptor= new KerberosDescriptorFactory().createInstance(kerberosDescriptorOrig.toMap()); ArtifactEntity artifactEntityOrig = createNiceMock(ArtifactEntity.class); kerberosDescriptor.getService("HDFS").removeIdentity("hdfs"); expect(artifactEntityOrig.getArtifactData()).andReturn(kerberosDescriptor.toMap()).once(); replay(artifactEntityOrig); upgradeMock.updateKerberosDescriptorArtifact(createNiceMock(ArtifactDAO.class), artifactEntityOrig); verify(artifactEntityOrig); }
@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 hdfsService = kerberosDescriptor.getService("HDFS"); if(hdfsService != null) { KerberosIdentityDescriptor hdfsIdentity = hdfsService.getIdentity("hdfs"); if (hdfsIdentity != null) { KerberosComponentDescriptor namenodeComponent = hdfsService.getComponent("NAMENODE"); hdfsIdentity.setName("hdfs"); hdfsService.removeIdentity("hdfs"); namenodeComponent.putIdentity(hdfsIdentity); } } updateKerberosDescriptorIdentityReferences(kerberosDescriptor, "/HDFS/hdfs", "/HDFS/NAMENODE/hdfs"); updateKerberosDescriptorIdentityReferences(kerberosDescriptor.getServices(), "/HDFS/hdfs", "/HDFS/NAMENODE/hdfs"); artifactEntity.setArtifactData(kerberosDescriptor.toMap()); artifactDAO.merge(artifactEntity); } } } }
UpgradeCatalog220 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 hdfsService = kerberosDescriptor.getService("HDFS"); if(hdfsService != null) { KerberosIdentityDescriptor hdfsIdentity = hdfsService.getIdentity("hdfs"); if (hdfsIdentity != null) { KerberosComponentDescriptor namenodeComponent = hdfsService.getComponent("NAMENODE"); hdfsIdentity.setName("hdfs"); hdfsService.removeIdentity("hdfs"); namenodeComponent.putIdentity(hdfsIdentity); } } updateKerberosDescriptorIdentityReferences(kerberosDescriptor, "/HDFS/hdfs", "/HDFS/NAMENODE/hdfs"); updateKerberosDescriptorIdentityReferences(kerberosDescriptor.getServices(), "/HDFS/hdfs", "/HDFS/NAMENODE/hdfs"); artifactEntity.setArtifactData(kerberosDescriptor.toMap()); artifactDAO.merge(artifactEntity); } } } } }
UpgradeCatalog220 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 hdfsService = kerberosDescriptor.getService("HDFS"); if(hdfsService != null) { KerberosIdentityDescriptor hdfsIdentity = hdfsService.getIdentity("hdfs"); if (hdfsIdentity != null) { KerberosComponentDescriptor namenodeComponent = hdfsService.getComponent("NAMENODE"); hdfsIdentity.setName("hdfs"); hdfsService.removeIdentity("hdfs"); namenodeComponent.putIdentity(hdfsIdentity); } } updateKerberosDescriptorIdentityReferences(kerberosDescriptor, "/HDFS/hdfs", "/HDFS/NAMENODE/hdfs"); updateKerberosDescriptorIdentityReferences(kerberosDescriptor.getServices(), "/HDFS/hdfs", "/HDFS/NAMENODE/hdfs"); artifactEntity.setArtifactData(kerberosDescriptor.toMap()); artifactDAO.merge(artifactEntity); } } } } @Inject  UpgradeCatalog220(Injector injector); }
UpgradeCatalog220 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 hdfsService = kerberosDescriptor.getService("HDFS"); if(hdfsService != null) { KerberosIdentityDescriptor hdfsIdentity = hdfsService.getIdentity("hdfs"); if (hdfsIdentity != null) { KerberosComponentDescriptor namenodeComponent = hdfsService.getComponent("NAMENODE"); hdfsIdentity.setName("hdfs"); hdfsService.removeIdentity("hdfs"); namenodeComponent.putIdentity(hdfsIdentity); } } updateKerberosDescriptorIdentityReferences(kerberosDescriptor, "/HDFS/hdfs", "/HDFS/NAMENODE/hdfs"); updateKerberosDescriptorIdentityReferences(kerberosDescriptor.getServices(), "/HDFS/hdfs", "/HDFS/NAMENODE/hdfs"); artifactEntity.setArtifactData(kerberosDescriptor.toMap()); artifactDAO.merge(artifactEntity); } } } } @Inject  UpgradeCatalog220(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); @Transactional void bootstrapRepoVersionForHDP21(); }
UpgradeCatalog220 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 hdfsService = kerberosDescriptor.getService("HDFS"); if(hdfsService != null) { KerberosIdentityDescriptor hdfsIdentity = hdfsService.getIdentity("hdfs"); if (hdfsIdentity != null) { KerberosComponentDescriptor namenodeComponent = hdfsService.getComponent("NAMENODE"); hdfsIdentity.setName("hdfs"); hdfsService.removeIdentity("hdfs"); namenodeComponent.putIdentity(hdfsIdentity); } } updateKerberosDescriptorIdentityReferences(kerberosDescriptor, "/HDFS/hdfs", "/HDFS/NAMENODE/hdfs"); updateKerberosDescriptorIdentityReferences(kerberosDescriptor.getServices(), "/HDFS/hdfs", "/HDFS/NAMENODE/hdfs"); artifactEntity.setArtifactData(kerberosDescriptor.toMap()); artifactDAO.merge(artifactEntity); } } } } @Inject  UpgradeCatalog220(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); @Transactional void bootstrapRepoVersionForHDP21(); static final String UPGRADE_PACKAGE_COL; static final String UPGRADE_TYPE_COL; static final String REPO_VERSION_TABLE; }