@Test public void testUpdateKerberosDescriptorArtifact_Simple() throws Exception { final KerberosDescriptorFactory kerberosDescriptorFactory = new KerberosDescriptorFactory(); KerberosServiceDescriptor serviceDescriptor; URL systemResourceURL = ClassLoader.getSystemResource("kerberos/test_kerberos_descriptor_simple.json"); assertNotNull(systemResourceURL); final KerberosDescriptor kerberosDescriptorOrig = kerberosDescriptorFactory.createInstance(new File(systemResourceURL.getFile())); assertNotNull(kerberosDescriptorOrig); assertNotNull(kerberosDescriptorOrig.getIdentity("hdfs")); serviceDescriptor = kerberosDescriptorOrig.getService("HDFS"); assertNotNull(serviceDescriptor); assertNotNull(serviceDescriptor.getIdentity("/hdfs")); assertNull(serviceDescriptor.getIdentity("hdfs")); serviceDescriptor = kerberosDescriptorOrig.getService("OOZIE"); assertNotNull(serviceDescriptor); assertNotNull(serviceDescriptor.getIdentity("/hdfs")); assertNull(serviceDescriptor.getIdentity("/HDFS/hdfs")); UpgradeCatalog210 upgradeMock = createMockBuilder(UpgradeCatalog210.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); assertNull(kerberosDescriptorUpdated.getIdentity("/hdfs")); serviceDescriptor = kerberosDescriptorUpdated.getService("HDFS"); assertNotNull(serviceDescriptor); assertNull(serviceDescriptor.getIdentity("/hdfs")); assertNotNull(serviceDescriptor.getIdentity("hdfs")); serviceDescriptor = kerberosDescriptorUpdated.getService("OOZIE"); assertNotNull(serviceDescriptor); assertNull(serviceDescriptor.getIdentity("/hdfs")); assertNotNull(serviceDescriptor.getIdentity("/HDFS/hdfs")); }
@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) { KerberosIdentityDescriptor hdfsIdentity = kerberosDescriptor.getIdentity("hdfs"); if (hdfsIdentity != null) { KerberosServiceDescriptor hdfsService = kerberosDescriptor.getService("HDFS"); if (hdfsService == null) { hdfsService = new KerberosServiceDescriptorFactory().createInstance("HDFS", (Map) null); hdfsService.putIdentity(hdfsIdentity); kerberosDescriptor.putService(hdfsService); } else { KerberosIdentityDescriptor hdfsReferenceIdentity = hdfsService.getIdentity("/hdfs"); if (hdfsReferenceIdentity != null) { hdfsIdentity.update(hdfsReferenceIdentity); hdfsIdentity.setName("hdfs"); hdfsService.removeIdentity("/hdfs"); } hdfsService.putIdentity(hdfsIdentity); } kerberosDescriptor.removeIdentity("hdfs"); } updateKerberosDescriptorIdentityReferences(kerberosDescriptor, "/hdfs", "/HDFS/hdfs"); updateKerberosDescriptorIdentityReferences(kerberosDescriptor.getServices(), "/hdfs", "/HDFS/hdfs"); artifactEntity.setArtifactData(kerberosDescriptor.toMap()); artifactDAO.merge(artifactEntity); } } } }
UpgradeCatalog210 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) { KerberosIdentityDescriptor hdfsIdentity = kerberosDescriptor.getIdentity("hdfs"); if (hdfsIdentity != null) { KerberosServiceDescriptor hdfsService = kerberosDescriptor.getService("HDFS"); if (hdfsService == null) { hdfsService = new KerberosServiceDescriptorFactory().createInstance("HDFS", (Map) null); hdfsService.putIdentity(hdfsIdentity); kerberosDescriptor.putService(hdfsService); } else { KerberosIdentityDescriptor hdfsReferenceIdentity = hdfsService.getIdentity("/hdfs"); if (hdfsReferenceIdentity != null) { hdfsIdentity.update(hdfsReferenceIdentity); hdfsIdentity.setName("hdfs"); hdfsService.removeIdentity("/hdfs"); } hdfsService.putIdentity(hdfsIdentity); } kerberosDescriptor.removeIdentity("hdfs"); } updateKerberosDescriptorIdentityReferences(kerberosDescriptor, "/hdfs", "/HDFS/hdfs"); updateKerberosDescriptorIdentityReferences(kerberosDescriptor.getServices(), "/hdfs", "/HDFS/hdfs"); artifactEntity.setArtifactData(kerberosDescriptor.toMap()); artifactDAO.merge(artifactEntity); } } } } }
UpgradeCatalog210 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) { KerberosIdentityDescriptor hdfsIdentity = kerberosDescriptor.getIdentity("hdfs"); if (hdfsIdentity != null) { KerberosServiceDescriptor hdfsService = kerberosDescriptor.getService("HDFS"); if (hdfsService == null) { hdfsService = new KerberosServiceDescriptorFactory().createInstance("HDFS", (Map) null); hdfsService.putIdentity(hdfsIdentity); kerberosDescriptor.putService(hdfsService); } else { KerberosIdentityDescriptor hdfsReferenceIdentity = hdfsService.getIdentity("/hdfs"); if (hdfsReferenceIdentity != null) { hdfsIdentity.update(hdfsReferenceIdentity); hdfsIdentity.setName("hdfs"); hdfsService.removeIdentity("/hdfs"); } hdfsService.putIdentity(hdfsIdentity); } kerberosDescriptor.removeIdentity("hdfs"); } updateKerberosDescriptorIdentityReferences(kerberosDescriptor, "/hdfs", "/HDFS/hdfs"); updateKerberosDescriptorIdentityReferences(kerberosDescriptor.getServices(), "/hdfs", "/HDFS/hdfs"); artifactEntity.setArtifactData(kerberosDescriptor.toMap()); artifactDAO.merge(artifactEntity); } } } } @Inject  UpgradeCatalog210(Injector injector); }
UpgradeCatalog210 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) { KerberosIdentityDescriptor hdfsIdentity = kerberosDescriptor.getIdentity("hdfs"); if (hdfsIdentity != null) { KerberosServiceDescriptor hdfsService = kerberosDescriptor.getService("HDFS"); if (hdfsService == null) { hdfsService = new KerberosServiceDescriptorFactory().createInstance("HDFS", (Map) null); hdfsService.putIdentity(hdfsIdentity); kerberosDescriptor.putService(hdfsService); } else { KerberosIdentityDescriptor hdfsReferenceIdentity = hdfsService.getIdentity("/hdfs"); if (hdfsReferenceIdentity != null) { hdfsIdentity.update(hdfsReferenceIdentity); hdfsIdentity.setName("hdfs"); hdfsService.removeIdentity("/hdfs"); } hdfsService.putIdentity(hdfsIdentity); } kerberosDescriptor.removeIdentity("hdfs"); } updateKerberosDescriptorIdentityReferences(kerberosDescriptor, "/hdfs", "/HDFS/hdfs"); updateKerberosDescriptorIdentityReferences(kerberosDescriptor.getServices(), "/hdfs", "/HDFS/hdfs"); artifactEntity.setArtifactData(kerberosDescriptor.toMap()); artifactDAO.merge(artifactEntity); } } } } @Inject  UpgradeCatalog210(Injector injector); @Override String getSourceVersion(); @Override String getTargetVersion(); }
UpgradeCatalog210 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) { KerberosIdentityDescriptor hdfsIdentity = kerberosDescriptor.getIdentity("hdfs"); if (hdfsIdentity != null) { KerberosServiceDescriptor hdfsService = kerberosDescriptor.getService("HDFS"); if (hdfsService == null) { hdfsService = new KerberosServiceDescriptorFactory().createInstance("HDFS", (Map) null); hdfsService.putIdentity(hdfsIdentity); kerberosDescriptor.putService(hdfsService); } else { KerberosIdentityDescriptor hdfsReferenceIdentity = hdfsService.getIdentity("/hdfs"); if (hdfsReferenceIdentity != null) { hdfsIdentity.update(hdfsReferenceIdentity); hdfsIdentity.setName("hdfs"); hdfsService.removeIdentity("/hdfs"); } hdfsService.putIdentity(hdfsIdentity); } kerberosDescriptor.removeIdentity("hdfs"); } updateKerberosDescriptorIdentityReferences(kerberosDescriptor, "/hdfs", "/HDFS/hdfs"); updateKerberosDescriptorIdentityReferences(kerberosDescriptor.getServices(), "/hdfs", "/HDFS/hdfs"); artifactEntity.setArtifactData(kerberosDescriptor.toMap()); artifactDAO.merge(artifactEntity); } } } } @Inject  UpgradeCatalog210(Injector injector); @Override String getSourceVersion(); @Override String getTargetVersion();  }