@Test public void testKeepFilesNotChangedInThinClient() throws IOException { ThinNameClusterModel model = new ThinNameClusterModel(); model.setKerberosSubType( "" ); model.setName( ncTestName ); model.setOldName( ncTestName ); List<SimpleImmutableEntry<String, String>> siteFiles = new ArrayList<>(); SimpleImmutableEntry<String, String> thinSiteFile1 = new SimpleImmutableEntry<>( "name", CORE_SITE ); siteFiles.add( thinSiteFile1 ); SimpleImmutableEntry<String, String> thinSiteFile2 = new SimpleImmutableEntry<>( "name", HIVE_SITE ); siteFiles.add( thinSiteFile2 ); SimpleImmutableEntry<String, String> thinSiteFile3 = new SimpleImmutableEntry<>( "name", OOZIE_SITE ); siteFiles.add( thinSiteFile3 ); SimpleImmutableEntry<String, String> thinSiteFile4 = new SimpleImmutableEntry<>( "name", YARN_SITE ); siteFiles.add( thinSiteFile4 ); model.setSiteFiles( siteFiles ); List<NamedClusterSiteFile> namedClusterSiteFiles = new ArrayList<>(); NamedClusterSiteFileImpl sf1 = new NamedClusterSiteFileImpl(); sf1.setSiteFileName( CORE_SITE ); String originalContent = "originalContent"; sf1.setSiteFileContents( originalContent ); namedClusterSiteFiles.add( sf1 ); NamedClusterSiteFileImpl sf2 = new NamedClusterSiteFileImpl(); sf2.setSiteFileName( HIVE_SITE ); sf2.setSiteFileContents( originalContent ); namedClusterSiteFiles.add( sf2 ); NamedClusterSiteFileImpl sf3 = new NamedClusterSiteFileImpl(); sf3.setSiteFileName( OOZIE_SITE ); String originalOozieFileContent = "orig ofc"; sf3.setSiteFileContents( originalOozieFileContent ); namedClusterSiteFiles.add( sf3 ); NamedClusterSiteFileImpl sf4 = new NamedClusterSiteFileImpl(); sf4.setSiteFileName( YARN_SITE ); String originalYarnFileContent = "orig yfc"; sf4.setSiteFileContents( originalYarnFileContent ); namedClusterSiteFiles.add( sf4 ); when( namedCluster.getSiteFiles() ).thenReturn( namedClusterSiteFiles ); final Map<String, CachedFileItemStream> filesFromThinClient = new HashMap<>(); String modifiedCoreFileContent = "new cfc"; CachedFileItemStream modifiedCoreSiteFile = new CachedFileItemStream( new ByteArrayInputStream( modifiedCoreFileContent.getBytes() ), CORE_SITE, CORE_SITE ); filesFromThinClient.put( CORE_SITE, modifiedCoreSiteFile ); String modifiedHiveFileContent = "new hfc"; CachedFileItemStream modifiedHiveSiteFile = new CachedFileItemStream( new ByteArrayInputStream( modifiedHiveFileContent.getBytes() ), HIVE_SITE, HIVE_SITE ); filesFromThinClient.put( HIVE_SITE, modifiedHiveSiteFile ); CachedFileItemStream unmodifiedOozieSiteFile = new CachedFileItemStream( new ByteArrayInputStream( PLACEHOLDER_VALUE.getBytes() ), OOZIE_SITE, OOZIE_SITE ); filesFromThinClient.put( OOZIE_SITE, unmodifiedOozieSiteFile ); CachedFileItemStream unmodifiedYarnSiteFile = new CachedFileItemStream( new ByteArrayInputStream( PLACEHOLDER_VALUE.getBytes() ), YARN_SITE, YARN_SITE ); filesFromThinClient.put( YARN_SITE, unmodifiedYarnSiteFile ); JSONObject result = hadoopClusterManager.editNamedCluster( model, true, filesFromThinClient ); assertEquals( ncTestName, result.get( "namedCluster" ) ); for ( NamedClusterSiteFile ncsf : namedClusterSiteFiles ) { if ( ncsf.getSiteFileName().equals( CORE_SITE ) ) { assertEquals( modifiedCoreFileContent, ncsf.getSiteFileContents() ); } else if ( ncsf.getSiteFileName().equals( HIVE_SITE ) ) { assertEquals( modifiedHiveFileContent, ncsf.getSiteFileContents() ); } else if ( ncsf.getSiteFileName().equals( OOZIE_SITE ) ) { assertEquals( originalOozieFileContent, ncsf.getSiteFileContents() ); } else if ( ncsf.getSiteFileName().equals( YARN_SITE ) ) { assertEquals( originalYarnFileContent, ncsf.getSiteFileContents() ); } else { fail(); } } }
public JSONObject editNamedCluster( ThinNameClusterModel model, boolean isEditMode, Map<String, CachedFileItemStream> siteFilesSource ) { JSONObject response = new JSONObject(); response.put( NAMED_CLUSTER, "" ); try { final NamedCluster newNc = namedClusterService.getNamedClusterByName( model.getName(), metaStore ); final NamedCluster oldNc = namedClusterService.getNamedClusterByName( model.getOldName(), metaStore ); String shimId = oldNc.getShimIdentifier(); final List<NamedClusterSiteFile> existingSiteFiles = oldNc.getSiteFiles(); NamedCluster nc = convertToNamedCluster( model ); nc.setSiteFiles( getIntersectionSiteFiles( model, existingSiteFiles ) ); installSiteFiles( siteFilesSource, nc ); if ( newNc != null ) { namedClusterService.update( nc, metaStore ); } else { namedClusterService.create( nc, metaStore ); } File oldConfigFolder = new File( getNamedClusterConfigsRootDir() + fileSeparator + model.getOldName() ); File newConfigFolder = new File( getNamedClusterConfigsRootDir() + fileSeparator + nc.getName() ); if ( !oldConfigFolder.getName().equalsIgnoreCase( newConfigFolder.getName() ) ) { deleteConfigFolder( nc.getName() ); FileUtils.copyDirectory( oldConfigFolder, newConfigFolder ); } else { boolean success = oldConfigFolder.renameTo( newConfigFolder ); if ( !success ) { log.logError( "Renaming Named Cluster configuration folder failed." ); } } String keytabAuthenticationLocation = ""; String keytabImpersonationLocation = ""; String kerberosSubType = model.getKerberosSubType(); if ( !kerberosSubType.equals( KERBEROS_SUBTYPE.PASSWORD.getValue() ) ) { String configFile = getNamedClusterConfigsRootDir() + fileSeparator + nc.getName() + fileSeparator + CONFIG_PROPERTIES; PropertiesConfiguration config = new PropertiesConfiguration( new File( configFile ) ); keytabAuthenticationLocation = (String) config.getProperty( KEYTAB_AUTHENTICATION_LOCATION ); keytabImpersonationLocation = (String) config.getProperty( KEYTAB_IMPERSONATION_LOCATION ); } if ( nc.getShimIdentifier() != null && !nc.getShimIdentifier().equals( shimId ) ) { createConfigProperties( nc ); } setupKerberosSecurity( model, siteFilesSource, keytabAuthenticationLocation, keytabImpersonationLocation ); if ( isEditMode && !oldConfigFolder.getName().equalsIgnoreCase( newConfigFolder.getName() ) ) { deleteNamedCluster( metaStore, model.getOldName(), false ); } response.put( NAMED_CLUSTER, nc.getName() ); } catch ( Exception e ) { log.logError( e.getMessage() ); } return response; }
HadoopClusterManager implements RuntimeTestProgressCallback { public JSONObject editNamedCluster( ThinNameClusterModel model, boolean isEditMode, Map<String, CachedFileItemStream> siteFilesSource ) { JSONObject response = new JSONObject(); response.put( NAMED_CLUSTER, "" ); try { final NamedCluster newNc = namedClusterService.getNamedClusterByName( model.getName(), metaStore ); final NamedCluster oldNc = namedClusterService.getNamedClusterByName( model.getOldName(), metaStore ); String shimId = oldNc.getShimIdentifier(); final List<NamedClusterSiteFile> existingSiteFiles = oldNc.getSiteFiles(); NamedCluster nc = convertToNamedCluster( model ); nc.setSiteFiles( getIntersectionSiteFiles( model, existingSiteFiles ) ); installSiteFiles( siteFilesSource, nc ); if ( newNc != null ) { namedClusterService.update( nc, metaStore ); } else { namedClusterService.create( nc, metaStore ); } File oldConfigFolder = new File( getNamedClusterConfigsRootDir() + fileSeparator + model.getOldName() ); File newConfigFolder = new File( getNamedClusterConfigsRootDir() + fileSeparator + nc.getName() ); if ( !oldConfigFolder.getName().equalsIgnoreCase( newConfigFolder.getName() ) ) { deleteConfigFolder( nc.getName() ); FileUtils.copyDirectory( oldConfigFolder, newConfigFolder ); } else { boolean success = oldConfigFolder.renameTo( newConfigFolder ); if ( !success ) { log.logError( "Renaming Named Cluster configuration folder failed." ); } } String keytabAuthenticationLocation = ""; String keytabImpersonationLocation = ""; String kerberosSubType = model.getKerberosSubType(); if ( !kerberosSubType.equals( KERBEROS_SUBTYPE.PASSWORD.getValue() ) ) { String configFile = getNamedClusterConfigsRootDir() + fileSeparator + nc.getName() + fileSeparator + CONFIG_PROPERTIES; PropertiesConfiguration config = new PropertiesConfiguration( new File( configFile ) ); keytabAuthenticationLocation = (String) config.getProperty( KEYTAB_AUTHENTICATION_LOCATION ); keytabImpersonationLocation = (String) config.getProperty( KEYTAB_IMPERSONATION_LOCATION ); } if ( nc.getShimIdentifier() != null && !nc.getShimIdentifier().equals( shimId ) ) { createConfigProperties( nc ); } setupKerberosSecurity( model, siteFilesSource, keytabAuthenticationLocation, keytabImpersonationLocation ); if ( isEditMode && !oldConfigFolder.getName().equalsIgnoreCase( newConfigFolder.getName() ) ) { deleteNamedCluster( metaStore, model.getOldName(), false ); } response.put( NAMED_CLUSTER, nc.getName() ); } catch ( Exception e ) { log.logError( e.getMessage() ); } return response; } }
HadoopClusterManager implements RuntimeTestProgressCallback { public JSONObject editNamedCluster( ThinNameClusterModel model, boolean isEditMode, Map<String, CachedFileItemStream> siteFilesSource ) { JSONObject response = new JSONObject(); response.put( NAMED_CLUSTER, "" ); try { final NamedCluster newNc = namedClusterService.getNamedClusterByName( model.getName(), metaStore ); final NamedCluster oldNc = namedClusterService.getNamedClusterByName( model.getOldName(), metaStore ); String shimId = oldNc.getShimIdentifier(); final List<NamedClusterSiteFile> existingSiteFiles = oldNc.getSiteFiles(); NamedCluster nc = convertToNamedCluster( model ); nc.setSiteFiles( getIntersectionSiteFiles( model, existingSiteFiles ) ); installSiteFiles( siteFilesSource, nc ); if ( newNc != null ) { namedClusterService.update( nc, metaStore ); } else { namedClusterService.create( nc, metaStore ); } File oldConfigFolder = new File( getNamedClusterConfigsRootDir() + fileSeparator + model.getOldName() ); File newConfigFolder = new File( getNamedClusterConfigsRootDir() + fileSeparator + nc.getName() ); if ( !oldConfigFolder.getName().equalsIgnoreCase( newConfigFolder.getName() ) ) { deleteConfigFolder( nc.getName() ); FileUtils.copyDirectory( oldConfigFolder, newConfigFolder ); } else { boolean success = oldConfigFolder.renameTo( newConfigFolder ); if ( !success ) { log.logError( "Renaming Named Cluster configuration folder failed." ); } } String keytabAuthenticationLocation = ""; String keytabImpersonationLocation = ""; String kerberosSubType = model.getKerberosSubType(); if ( !kerberosSubType.equals( KERBEROS_SUBTYPE.PASSWORD.getValue() ) ) { String configFile = getNamedClusterConfigsRootDir() + fileSeparator + nc.getName() + fileSeparator + CONFIG_PROPERTIES; PropertiesConfiguration config = new PropertiesConfiguration( new File( configFile ) ); keytabAuthenticationLocation = (String) config.getProperty( KEYTAB_AUTHENTICATION_LOCATION ); keytabImpersonationLocation = (String) config.getProperty( KEYTAB_IMPERSONATION_LOCATION ); } if ( nc.getShimIdentifier() != null && !nc.getShimIdentifier().equals( shimId ) ) { createConfigProperties( nc ); } setupKerberosSecurity( model, siteFilesSource, keytabAuthenticationLocation, keytabImpersonationLocation ); if ( isEditMode && !oldConfigFolder.getName().equalsIgnoreCase( newConfigFolder.getName() ) ) { deleteNamedCluster( metaStore, model.getOldName(), false ); } response.put( NAMED_CLUSTER, nc.getName() ); } catch ( Exception e ) { log.logError( e.getMessage() ); } return response; } HadoopClusterManager( Spoon spoon, NamedClusterService namedClusterService, IMetaStore metaStore,
                               String internalShim ); }
HadoopClusterManager implements RuntimeTestProgressCallback { public JSONObject editNamedCluster( ThinNameClusterModel model, boolean isEditMode, Map<String, CachedFileItemStream> siteFilesSource ) { JSONObject response = new JSONObject(); response.put( NAMED_CLUSTER, "" ); try { final NamedCluster newNc = namedClusterService.getNamedClusterByName( model.getName(), metaStore ); final NamedCluster oldNc = namedClusterService.getNamedClusterByName( model.getOldName(), metaStore ); String shimId = oldNc.getShimIdentifier(); final List<NamedClusterSiteFile> existingSiteFiles = oldNc.getSiteFiles(); NamedCluster nc = convertToNamedCluster( model ); nc.setSiteFiles( getIntersectionSiteFiles( model, existingSiteFiles ) ); installSiteFiles( siteFilesSource, nc ); if ( newNc != null ) { namedClusterService.update( nc, metaStore ); } else { namedClusterService.create( nc, metaStore ); } File oldConfigFolder = new File( getNamedClusterConfigsRootDir() + fileSeparator + model.getOldName() ); File newConfigFolder = new File( getNamedClusterConfigsRootDir() + fileSeparator + nc.getName() ); if ( !oldConfigFolder.getName().equalsIgnoreCase( newConfigFolder.getName() ) ) { deleteConfigFolder( nc.getName() ); FileUtils.copyDirectory( oldConfigFolder, newConfigFolder ); } else { boolean success = oldConfigFolder.renameTo( newConfigFolder ); if ( !success ) { log.logError( "Renaming Named Cluster configuration folder failed." ); } } String keytabAuthenticationLocation = ""; String keytabImpersonationLocation = ""; String kerberosSubType = model.getKerberosSubType(); if ( !kerberosSubType.equals( KERBEROS_SUBTYPE.PASSWORD.getValue() ) ) { String configFile = getNamedClusterConfigsRootDir() + fileSeparator + nc.getName() + fileSeparator + CONFIG_PROPERTIES; PropertiesConfiguration config = new PropertiesConfiguration( new File( configFile ) ); keytabAuthenticationLocation = (String) config.getProperty( KEYTAB_AUTHENTICATION_LOCATION ); keytabImpersonationLocation = (String) config.getProperty( KEYTAB_IMPERSONATION_LOCATION ); } if ( nc.getShimIdentifier() != null && !nc.getShimIdentifier().equals( shimId ) ) { createConfigProperties( nc ); } setupKerberosSecurity( model, siteFilesSource, keytabAuthenticationLocation, keytabImpersonationLocation ); if ( isEditMode && !oldConfigFolder.getName().equalsIgnoreCase( newConfigFolder.getName() ) ) { deleteNamedCluster( metaStore, model.getOldName(), false ); } response.put( NAMED_CLUSTER, nc.getName() ); } catch ( Exception e ) { log.logError( e.getMessage() ); } return response; } HadoopClusterManager( Spoon spoon, NamedClusterService namedClusterService, IMetaStore metaStore,
                               String internalShim ); JSONObject importNamedCluster( ThinNameClusterModel model,
                                        Map<String, CachedFileItemStream> siteFilesSource ); JSONObject createNamedCluster( ThinNameClusterModel model,
                                        Map<String, CachedFileItemStream> siteFilesSource ); JSONObject editNamedCluster( ThinNameClusterModel model, boolean isEditMode,
                                      Map<String, CachedFileItemStream> siteFilesSource ); ThinNameClusterModel getNamedCluster( String namedCluster ); JSONObject installDriver( FileItemStream driver ); boolean isValidConfigurationFile( String fileName ); void deleteNamedCluster( IMetaStore metaStore, String namedCluster, boolean refreshTree ); Object runTests( RuntimeTester runtimeTester, String namedCluster ); void onProgress( final RuntimeTestStatus clusterTestStatus ); }
HadoopClusterManager implements RuntimeTestProgressCallback { public JSONObject editNamedCluster( ThinNameClusterModel model, boolean isEditMode, Map<String, CachedFileItemStream> siteFilesSource ) { JSONObject response = new JSONObject(); response.put( NAMED_CLUSTER, "" ); try { final NamedCluster newNc = namedClusterService.getNamedClusterByName( model.getName(), metaStore ); final NamedCluster oldNc = namedClusterService.getNamedClusterByName( model.getOldName(), metaStore ); String shimId = oldNc.getShimIdentifier(); final List<NamedClusterSiteFile> existingSiteFiles = oldNc.getSiteFiles(); NamedCluster nc = convertToNamedCluster( model ); nc.setSiteFiles( getIntersectionSiteFiles( model, existingSiteFiles ) ); installSiteFiles( siteFilesSource, nc ); if ( newNc != null ) { namedClusterService.update( nc, metaStore ); } else { namedClusterService.create( nc, metaStore ); } File oldConfigFolder = new File( getNamedClusterConfigsRootDir() + fileSeparator + model.getOldName() ); File newConfigFolder = new File( getNamedClusterConfigsRootDir() + fileSeparator + nc.getName() ); if ( !oldConfigFolder.getName().equalsIgnoreCase( newConfigFolder.getName() ) ) { deleteConfigFolder( nc.getName() ); FileUtils.copyDirectory( oldConfigFolder, newConfigFolder ); } else { boolean success = oldConfigFolder.renameTo( newConfigFolder ); if ( !success ) { log.logError( "Renaming Named Cluster configuration folder failed." ); } } String keytabAuthenticationLocation = ""; String keytabImpersonationLocation = ""; String kerberosSubType = model.getKerberosSubType(); if ( !kerberosSubType.equals( KERBEROS_SUBTYPE.PASSWORD.getValue() ) ) { String configFile = getNamedClusterConfigsRootDir() + fileSeparator + nc.getName() + fileSeparator + CONFIG_PROPERTIES; PropertiesConfiguration config = new PropertiesConfiguration( new File( configFile ) ); keytabAuthenticationLocation = (String) config.getProperty( KEYTAB_AUTHENTICATION_LOCATION ); keytabImpersonationLocation = (String) config.getProperty( KEYTAB_IMPERSONATION_LOCATION ); } if ( nc.getShimIdentifier() != null && !nc.getShimIdentifier().equals( shimId ) ) { createConfigProperties( nc ); } setupKerberosSecurity( model, siteFilesSource, keytabAuthenticationLocation, keytabImpersonationLocation ); if ( isEditMode && !oldConfigFolder.getName().equalsIgnoreCase( newConfigFolder.getName() ) ) { deleteNamedCluster( metaStore, model.getOldName(), false ); } response.put( NAMED_CLUSTER, nc.getName() ); } catch ( Exception e ) { log.logError( e.getMessage() ); } return response; } HadoopClusterManager( Spoon spoon, NamedClusterService namedClusterService, IMetaStore metaStore,
                               String internalShim ); JSONObject importNamedCluster( ThinNameClusterModel model,
                                        Map<String, CachedFileItemStream> siteFilesSource ); JSONObject createNamedCluster( ThinNameClusterModel model,
                                        Map<String, CachedFileItemStream> siteFilesSource ); JSONObject editNamedCluster( ThinNameClusterModel model, boolean isEditMode,
                                      Map<String, CachedFileItemStream> siteFilesSource ); ThinNameClusterModel getNamedCluster( String namedCluster ); JSONObject installDriver( FileItemStream driver ); boolean isValidConfigurationFile( String fileName ); void deleteNamedCluster( IMetaStore metaStore, String namedCluster, boolean refreshTree ); Object runTests( RuntimeTester runtimeTester, String namedCluster ); void onProgress( final RuntimeTestStatus clusterTestStatus ); static final String STRING_NAMED_CLUSTERS; static final String PLACEHOLDER_VALUE; }