NamedClusterLoadSaveUtil { public void getXmlNamedCluster( NamedCluster namedCluster, NamedClusterService namedClusterService, IMetaStore metaStore, LogChannelInterface logChannelInterface, StringBuilder retval ) { if ( namedCluster != null ) { String namedClusterName = namedCluster.getName(); if ( !Const.isEmpty( namedClusterName ) ) { retval.append( " " ).append( XMLHandler.addTagValue( CLUSTER_NAME, namedClusterName ) ); } try { if ( metaStore != null && !StringUtils.isEmpty( namedClusterName ) && namedClusterService .contains( namedClusterName, metaStore ) ) { namedCluster = namedClusterService.read( namedClusterName, metaStore ); } } catch ( MetaStoreException e ) { logChannelInterface.logDebug( e.getMessage(), e ); } retval.append( " " ).append( XMLHandler.addTagValue( HDFS_HOSTNAME, namedCluster.getHdfsHost() ) ); retval.append( " " ).append( XMLHandler.addTagValue( HDFS_PORT, namedCluster.getHdfsPort() ) ); retval.append( " " ).append( XMLHandler.addTagValue( JOB_TRACKER_HOSTNAME, namedCluster .getJobTrackerHost() ) ); retval.append( " " ).append( XMLHandler.addTagValue( JOB_TRACKER_PORT, namedCluster.getJobTrackerPort() ) ); } }  void saveNamedClusterRep( NamedCluster namedCluster, NamedClusterService namedClusterService, Repository rep,
      IMetaStore metaStore, ObjectId id_job, ObjectId objectId, LogChannelInterface logChannelInterface ); void getXmlNamedCluster( NamedCluster namedCluster, NamedClusterService namedClusterService, IMetaStore metaStore,
      LogChannelInterface logChannelInterface, StringBuilder retval ); NamedCluster loadClusterConfig( NamedClusterService namedClusterService, ObjectId id_jobentry, Repository rep,
                                         IMetaStore metaStore, Node entrynode,
                                         LogChannelInterface logChannelInterface ); static final String CLUSTER_NAME; static final String HDFS_HOSTNAME; static final String HDFS_PORT; static final String JOB_TRACKER_HOSTNAME; static final String JOB_TRACKER_PORT; }
@Test public void testGetXmlNamedCluster_NoNPEWhenNCIsNull() { StringBuilder ncString = new StringBuilder(); try { namedClusterLoadSaveUtil.getXmlNamedCluster( null, namedClusterService, null, logChannelInterface, ncString ); assertEquals( "It should not be added any NamedCluster info but it was:" + ncString.toString(), 0, ncString .length() ); } catch ( NullPointerException ex ) { fail( "NPE occured but should not: " + ex ); } }
@Test public void testGetXmlNamedCluster() throws KettleException, MetaStoreException, IOException, SAXException, ParserConfigurationException { String testNcName = "testNcName"; String hdfsHost = "hdfsHost"; String hdfsPort = "hdfsPort"; String jobTrackerHost = "jobTrackerHost"; String jobTrackerPort = "jobTrackerPort"; when( namedCluster.getName() ).thenReturn( testNcName ); NamedCluster readNamedCluster = mock( NamedCluster.class ); when( readNamedCluster.getHdfsHost() ).thenReturn( hdfsHost ); when( readNamedCluster.getHdfsPort() ).thenReturn( hdfsPort ); when( readNamedCluster.getJobTrackerHost() ).thenReturn( jobTrackerHost ); when( readNamedCluster.getJobTrackerPort() ).thenReturn( jobTrackerPort ); when( namedClusterService.contains( testNcName, metaStore ) ).thenReturn( true ); when( namedClusterService.read( testNcName, metaStore ) ).thenReturn( readNamedCluster ); StringBuilder stringBuilder = new StringBuilder(); namedClusterLoadSaveUtil .getXmlNamedCluster( namedCluster, namedClusterService, metaStore, logChannelInterface, stringBuilder ); Node node = parseNamedClusterXml( stringBuilder.toString() ); assertEquals( testNcName, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.CLUSTER_NAME ) ); assertEquals( hdfsHost, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.HDFS_HOSTNAME ) ); assertEquals( hdfsPort, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.HDFS_PORT ) ); assertEquals( jobTrackerHost, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.JOB_TRACKER_HOSTNAME ) ); assertEquals( jobTrackerPort, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.JOB_TRACKER_PORT ) ); }
@Test public void testGetXmlNamedClusterEmptyName() throws KettleException, MetaStoreException, IOException, SAXException, ParserConfigurationException { String hdfsHost = "hdfsHost"; String hdfsPort = "hdfsPort"; String jobTrackerHost = "jobTrackerHost"; String jobTrackerPort = "jobTrackerPort"; when( namedCluster.getHdfsHost() ).thenReturn( hdfsHost ); when( namedCluster.getHdfsPort() ).thenReturn( hdfsPort ); when( namedCluster.getJobTrackerHost() ).thenReturn( jobTrackerHost ); when( namedCluster.getJobTrackerPort() ).thenReturn( jobTrackerPort ); StringBuilder stringBuilder = new StringBuilder(); namedClusterLoadSaveUtil .getXmlNamedCluster( namedCluster, namedClusterService, metaStore, logChannelInterface, stringBuilder ); Node node = parseNamedClusterXml( stringBuilder.toString() ); assertEquals( null, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.CLUSTER_NAME ) ); assertEquals( hdfsHost, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.HDFS_HOSTNAME ) ); assertEquals( hdfsPort, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.HDFS_PORT ) ); assertEquals( jobTrackerHost, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.JOB_TRACKER_HOSTNAME ) ); assertEquals( jobTrackerPort, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.JOB_TRACKER_PORT ) ); }
@Test public void testGetXmlNamedClusterNullMetastore() throws KettleException, MetaStoreException, IOException, SAXException, ParserConfigurationException { String testNcName = "testNcName"; String hdfsHost = "hdfsHost"; String hdfsPort = "hdfsPort"; String jobTrackerHost = "jobTrackerHost"; String jobTrackerPort = "jobTrackerPort"; when( namedCluster.getName() ).thenReturn( testNcName ); when( namedCluster.getHdfsHost() ).thenReturn( hdfsHost ); when( namedCluster.getHdfsPort() ).thenReturn( hdfsPort ); when( namedCluster.getJobTrackerHost() ).thenReturn( jobTrackerHost ); when( namedCluster.getJobTrackerPort() ).thenReturn( jobTrackerPort ); StringBuilder stringBuilder = new StringBuilder(); namedClusterLoadSaveUtil .getXmlNamedCluster( namedCluster, namedClusterService, null, logChannelInterface, stringBuilder ); Node node = parseNamedClusterXml( stringBuilder.toString() ); assertEquals( testNcName, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.CLUSTER_NAME ) ); assertEquals( hdfsHost, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.HDFS_HOSTNAME ) ); assertEquals( hdfsPort, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.HDFS_PORT ) ); assertEquals( jobTrackerHost, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.JOB_TRACKER_HOSTNAME ) ); assertEquals( jobTrackerPort, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.JOB_TRACKER_PORT ) ); }
@Test public void testGetXmlNamedClusterNotContains() throws KettleException, MetaStoreException, IOException, SAXException, ParserConfigurationException { String testNcName = "testNcName"; String hdfsHost = "hdfsHost"; String hdfsPort = "hdfsPort"; String jobTrackerHost = "jobTrackerHost"; String jobTrackerPort = "jobTrackerPort"; when( namedCluster.getName() ).thenReturn( testNcName ); when( namedCluster.getHdfsHost() ).thenReturn( hdfsHost ); when( namedCluster.getHdfsPort() ).thenReturn( hdfsPort ); when( namedCluster.getJobTrackerHost() ).thenReturn( jobTrackerHost ); when( namedCluster.getJobTrackerPort() ).thenReturn( jobTrackerPort ); when( namedClusterService.contains( testNcName, metaStore ) ).thenReturn( false ); StringBuilder stringBuilder = new StringBuilder(); namedClusterLoadSaveUtil .getXmlNamedCluster( namedCluster, namedClusterService, metaStore, logChannelInterface, stringBuilder ); Node node = parseNamedClusterXml( stringBuilder.toString() ); verify( namedClusterService, never() ).read( anyString(), eq( metaStore ) ); assertEquals( testNcName, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.CLUSTER_NAME ) ); assertEquals( hdfsHost, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.HDFS_HOSTNAME ) ); assertEquals( hdfsPort, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.HDFS_PORT ) ); assertEquals( jobTrackerHost, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.JOB_TRACKER_HOSTNAME ) ); assertEquals( jobTrackerPort, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.JOB_TRACKER_PORT ) ); }
@Test public void testGetXmlNamedClusterMetastoreException() throws KettleException, MetaStoreException, IOException, SAXException, ParserConfigurationException { String testNcName = "testNcName"; String hdfsHost = "hdfsHost"; String hdfsPort = "hdfsPort"; String jobTrackerHost = "jobTrackerHost"; String jobTrackerPort = "jobTrackerPort"; when( namedCluster.getName() ).thenReturn( testNcName ); when( namedCluster.getHdfsHost() ).thenReturn( hdfsHost ); when( namedCluster.getHdfsPort() ).thenReturn( hdfsPort ); when( namedCluster.getJobTrackerHost() ).thenReturn( jobTrackerHost ); when( namedCluster.getJobTrackerPort() ).thenReturn( jobTrackerPort ); when( namedClusterService.contains( testNcName, metaStore ) ).thenReturn( true ); MetaStoreException metaStoreException = new MetaStoreException( "msg" ); when( namedClusterService.read( testNcName, metaStore ) ).thenThrow( metaStoreException ); StringBuilder stringBuilder = new StringBuilder(); namedClusterLoadSaveUtil .getXmlNamedCluster( namedCluster, namedClusterService, metaStore, logChannelInterface, stringBuilder ); Node node = parseNamedClusterXml( stringBuilder.toString() ); verify( logChannelInterface ).logDebug( metaStoreException.getMessage(), metaStoreException ); assertEquals( testNcName, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.CLUSTER_NAME ) ); assertEquals( hdfsHost, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.HDFS_HOSTNAME ) ); assertEquals( hdfsPort, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.HDFS_PORT ) ); assertEquals( jobTrackerHost, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.JOB_TRACKER_HOSTNAME ) ); assertEquals( jobTrackerPort, XMLHandler.getTagValue( node, NamedClusterLoadSaveUtil.JOB_TRACKER_PORT ) ); }