public void addClusterToMeta( String clusterName ) { NamedClusterServiceOsgi ncso = meta.getNamedClusterServiceOsgi(); if ( ncso != null ) { NamedClusterOsgi nc = ncso.getNamedClusterByName( clusterName, meta.getMetaStore() ); if ( nc == null ) { nc = namedClusterPool.get( clusterName ); // The local metastore doesn't have it. Recover from pool } if ( nc != null ) { addClusterToMeta( nc ); } } }
/** * Class creates an embedded metastores for NamedClusters * * @param meta The TransMeta or JobMeta */ public NamedClusterEmbedManager( AbstractMeta meta, LogChannelInterface log ) { this.meta = meta; this.log = log; NamedClusterServiceOsgi ncso = meta.getNamedClusterServiceOsgi(); if ( ncso == null ) { //throw new IllegalArgumentException( "Meta does not contain a NamedClusterService" ); embeddedMetaStoreFactory = null; // Should only happen from test classes return; } if ( testMetaStoreFactory == null ) { embeddedMetaStoreFactory = new MetaStoreFactory( ncso.getClusterTemplate().getClass(), meta.getEmbeddedMetaStore(), NAMESPACE ); } else { embeddedMetaStoreFactory = testMetaStoreFactory; } }
@Test public void testGetSetNamedClusterServiceOsgi() throws Exception { assertNull( meta.getNamedClusterServiceOsgi() ); NamedClusterServiceOsgi mockNamedClusterOsgi = mock( NamedClusterServiceOsgi.class ); meta.setNamedClusterServiceOsgi( mockNamedClusterOsgi ); assertEquals( mockNamedClusterOsgi, meta.getNamedClusterServiceOsgi() ); }
/** * Clear the embedded metastore of any named clusters */ public void clear() { NamedClusterServiceOsgi ncso = meta.getNamedClusterServiceOsgi(); if ( ncso != null ) { //Don't kill the embedded if we don't have the service to rebuild addedAllClusters = false; addedAnyClusters = false; // The embeddedMetaStoreFactory may be null if creating a brand new job and attempting to run before it ever // saved. if ( embeddedMetaStoreFactory != null ) { try { List<NamedClusterOsgi> list = embeddedMetaStoreFactory.getElements(); for ( NamedClusterOsgi nc : list ) { namedClusterPool.put( nc.getName(), nc ); embeddedMetaStoreFactory.deleteElement( nc.getName() ); } } catch ( MetaStoreException e ) { logMetaStoreException( e ); } } } }
@Before public void setUp() { mockLog = mock( LogChannelInterface.class ); mockMeta = mock( AbstractMeta.class ); mockMetaStoreFactory = mock( MetaStoreFactory.class ); NamedClusterEmbedManager.testMetaStoreFactory = mockMetaStoreFactory; IMetaStore mockMetaStore = mock( IMetaStore.class ); mockNamedCluster1 = mock( NamedClusterOsgi.class ); mockNamedCluster2 = mock( NamedClusterOsgi.class ); when( mockNamedCluster1.getName() ).thenReturn( CLUSTER1_NAME ); when( mockNamedCluster2.getName() ).thenReturn( CLUSTER2_NAME ); mockNamedClusterService = mock( NamedClusterServiceOsgi.class ); when( mockMeta.getNamedClusterServiceOsgi() ).thenReturn( mockNamedClusterService ); when( mockMeta.getMetaStore() ).thenReturn( mockMetaStore ); when( mockNamedClusterService.getClusterTemplate() ).thenReturn( mock( NamedClusterOsgi.class ) ); when( mockNamedClusterService.getNamedClusterByName( eq( CLUSTER1_NAME ), any() ) ).thenReturn( mockNamedCluster1 ); when( mockNamedClusterService.getNamedClusterByName( eq( CLUSTER2_NAME ), any() ) ).thenReturn( mockNamedCluster2 ); namedClusterEmbedManager = new NamedClusterEmbedManager( mockMeta, mockLog ); }
private void addAllClusters() { NamedClusterServiceOsgi ncso = meta.getNamedClusterServiceOsgi(); if ( ncso != null && meta.getMetaStore() != null ) { try { List<String> list = ncso.listNames( meta.getMetaStore() ); for ( String name : list ) { addClusterToMeta( name ); } for ( NamedClusterOsgi nc : namedClusterPool.values() ) { if ( !list.contains( nc.getName() ) ) { addClusterToMeta( nc ); } } addedAllClusters = true; } catch ( MetaStoreException e ) { logMetaStoreException( e ); } } }