@Test public void testFindScriptForDm() throws Exception { TestApplication app = new TestApplication(); String targetId1 = this.mngr.createTarget( "id: tid1\nhandler: h" ); File dir1 = new File( this.configurationMngr.getWorkingDirectory(), ConfigurationUtils.TARGETS + "/" + targetId1 + "/" + Constants.PROJECT_SUB_DIR_SCRIPTS ); Assert.assertTrue( new File( dir1, "sub" ).mkdirs()); Utils.writeStringInto( "#!/bin/bash\necho Bonjour le monde cruel > toto.txt", new File( dir1, "sub/whatever.sh" )); Utils.writeStringInto( "#!/bin/bash\necho Bonjour le monde cruel > toto.txt", new File( dir1, "sub/" + Constants.LOCAL_RESOURCE_PREFIX + "whatever.sh" )); Utils.writeStringInto( "#!/bin/bash\necho Bonjour le monde cruel > toto.txt", new File( dir1, "sub/properties-for-whatever.properties" )); this.mngr.associateTargetWith( targetId1, app, null ); File dmScript = this.mngr.findScriptForDm( app, app.getMySqlVm()); Assert.assertNull( dmScript ); Utils.writeStringInto( "#!/bin/bash\necho Bonjour le monde cruel > toto.txt", new File( dir1, "target." + Constants.SCOPED_SCRIPT_AT_DM_CONFIGURE_SUFFIX + ".sh" )); dmScript = this.mngr.findScriptForDm( app, app.getMySqlVm()); Assert.assertNotNull( dmScript ); Assert.assertEquals( "target." + Constants.SCOPED_SCRIPT_AT_DM_CONFIGURE_SUFFIX + ".sh", dmScript.getName()); }
@Override public File findScriptForDm( AbstractApplication app, Instance scopedInstance ) { File result = null; String targetId = findTargetId( app, InstanceHelpers.computeInstancePath( scopedInstance )); if( targetId != null ) { File targetDir = new File( findTargetDirectory( targetId ), Constants.PROJECT_SUB_DIR_SCRIPTS ); if( targetDir.isDirectory()){ for( File f : Utils.listAllFiles( targetDir )) { if( f.getName().toLowerCase().contains( Constants.SCOPED_SCRIPT_AT_DM_CONFIGURE_SUFFIX )) { result = f; break; } } } } return result; }
TargetsMngrImpl implements ITargetsMngr { @Override public File findScriptForDm( AbstractApplication app, Instance scopedInstance ) { File result = null; String targetId = findTargetId( app, InstanceHelpers.computeInstancePath( scopedInstance )); if( targetId != null ) { File targetDir = new File( findTargetDirectory( targetId ), Constants.PROJECT_SUB_DIR_SCRIPTS ); if( targetDir.isDirectory()){ for( File f : Utils.listAllFiles( targetDir )) { if( f.getName().toLowerCase().contains( Constants.SCOPED_SCRIPT_AT_DM_CONFIGURE_SUFFIX )) { result = f; break; } } } } return result; } }
TargetsMngrImpl implements ITargetsMngr { @Override public File findScriptForDm( AbstractApplication app, Instance scopedInstance ) { File result = null; String targetId = findTargetId( app, InstanceHelpers.computeInstancePath( scopedInstance )); if( targetId != null ) { File targetDir = new File( findTargetDirectory( targetId ), Constants.PROJECT_SUB_DIR_SCRIPTS ); if( targetDir.isDirectory()){ for( File f : Utils.listAllFiles( targetDir )) { if( f.getName().toLowerCase().contains( Constants.SCOPED_SCRIPT_AT_DM_CONFIGURE_SUFFIX )) { result = f; break; } } } } return result; } TargetsMngrImpl( IConfigurationMngr configurationMngr ); }
TargetsMngrImpl implements ITargetsMngr { @Override public File findScriptForDm( AbstractApplication app, Instance scopedInstance ) { File result = null; String targetId = findTargetId( app, InstanceHelpers.computeInstancePath( scopedInstance )); if( targetId != null ) { File targetDir = new File( findTargetDirectory( targetId ), Constants.PROJECT_SUB_DIR_SCRIPTS ); if( targetDir.isDirectory()){ for( File f : Utils.listAllFiles( targetDir )) { if( f.getName().toLowerCase().contains( Constants.SCOPED_SCRIPT_AT_DM_CONFIGURE_SUFFIX )) { result = f; break; } } } } return result; } TargetsMngrImpl( IConfigurationMngr configurationMngr ); @Override String createTarget( String targetContent ); @Override String createTarget( File targetPropertiesFile, ApplicationTemplate creator ); @Override void updateTarget( String targetId, String newTargetContent ); @Override void deleteTarget( String targetId ); @Override void associateTargetWith( String targetId, AbstractApplication app, String instancePathOrComponentName ); @Override void dissociateTargetFrom( AbstractApplication app, String instancePathOrComponentName ); @Override void copyOriginalMapping( Application app ); @Override void applicationWasDeleted( AbstractApplication app ); @Override TargetProperties findTargetProperties( AbstractApplication app, String instancePath ); @Override TargetProperties findTargetProperties( String targetId ); @Override String findTargetId( AbstractApplication app, String instancePath, boolean strict ); @Override String findTargetId( AbstractApplication app, String instancePath ); @Override Map<String,byte[]> findScriptResourcesForAgent( String targetId ); @Override Map<String,byte[]> findScriptResourcesForAgent( AbstractApplication app, Instance scopedInstance ); @Override File findScriptForDm( AbstractApplication app, Instance scopedInstance ); @Override List<TargetWrapperDescriptor> listAllTargets(); @Override TargetWrapperDescriptor findTargetById( String targetId ); @Override List<TargetWrapperDescriptor> listPossibleTargets( AbstractApplication app ); @Override void addHint( String targetId, AbstractApplication app ); @Override void removeHint( String targetId, AbstractApplication app ); @Override TargetProperties lockAndGetTarget( Application app, Instance scopedInstance ); @Override void unlockTarget( Application app, Instance scopedInstance ); @Override List<TargetUsageItem> findUsageStatistics( String targetId ); }
TargetsMngrImpl implements ITargetsMngr { @Override public File findScriptForDm( AbstractApplication app, Instance scopedInstance ) { File result = null; String targetId = findTargetId( app, InstanceHelpers.computeInstancePath( scopedInstance )); if( targetId != null ) { File targetDir = new File( findTargetDirectory( targetId ), Constants.PROJECT_SUB_DIR_SCRIPTS ); if( targetDir.isDirectory()){ for( File f : Utils.listAllFiles( targetDir )) { if( f.getName().toLowerCase().contains( Constants.SCOPED_SCRIPT_AT_DM_CONFIGURE_SUFFIX )) { result = f; break; } } } } return result; } TargetsMngrImpl( IConfigurationMngr configurationMngr ); @Override String createTarget( String targetContent ); @Override String createTarget( File targetPropertiesFile, ApplicationTemplate creator ); @Override void updateTarget( String targetId, String newTargetContent ); @Override void deleteTarget( String targetId ); @Override void associateTargetWith( String targetId, AbstractApplication app, String instancePathOrComponentName ); @Override void dissociateTargetFrom( AbstractApplication app, String instancePathOrComponentName ); @Override void copyOriginalMapping( Application app ); @Override void applicationWasDeleted( AbstractApplication app ); @Override TargetProperties findTargetProperties( AbstractApplication app, String instancePath ); @Override TargetProperties findTargetProperties( String targetId ); @Override String findTargetId( AbstractApplication app, String instancePath, boolean strict ); @Override String findTargetId( AbstractApplication app, String instancePath ); @Override Map<String,byte[]> findScriptResourcesForAgent( String targetId ); @Override Map<String,byte[]> findScriptResourcesForAgent( AbstractApplication app, Instance scopedInstance ); @Override File findScriptForDm( AbstractApplication app, Instance scopedInstance ); @Override List<TargetWrapperDescriptor> listAllTargets(); @Override TargetWrapperDescriptor findTargetById( String targetId ); @Override List<TargetWrapperDescriptor> listPossibleTargets( AbstractApplication app ); @Override void addHint( String targetId, AbstractApplication app ); @Override void removeHint( String targetId, AbstractApplication app ); @Override TargetProperties lockAndGetTarget( Application app, Instance scopedInstance ); @Override void unlockTarget( Application app, Instance scopedInstance ); @Override List<TargetUsageItem> findUsageStatistics( String targetId );  }