@Test public void testInjectConfigurations_exceptionOnConflict() throws Exception { File karafEtc = this.folder.newFolder(); File injectionDir = new File( karafEtc, AgentUtils.INJECTED_CONFIGS_DIR ); Assert.assertTrue( injectionDir.mkdirs()); File conflict = new File( karafEtc, "valid1.cfg" ); Assert.assertTrue( conflict.mkdir()); Utils.writeStringInto( "ip = <ip-address>\napp = <application-name>\n", new File( injectionDir, "valid1.cfg.tpl" )); Assert.assertEquals( 2, karafEtc.listFiles().length ); AgentUtils.injectConfigurations( karafEtc.getAbsolutePath(), "app", "/vm", "default", "127.0.0.1" ); Assert.assertEquals( 2, karafEtc.listFiles().length ); File f = new File( karafEtc, "valid1.cfg" ); Assert.assertTrue( f.isDirectory()); }
public static void injectConfigurations( String karafEtc, String applicationName, String scopedInstancePath, String domain, String ipAddress ) { File injectionDir = new File( karafEtc, INJECTED_CONFIGS_DIR ); if( injectionDir.isDirectory()) { for( File source : Utils.listAllFiles( injectionDir, ".cfg.tpl" )) { try { File target = new File( karafEtc, source.getName().replaceFirst( "\\.tpl$", "" )); if( Constants.KARAF_CFG_FILE_AGENT.equalsIgnoreCase( target.getName())) continue; String content = Utils.readFileContent( source ); content = content.replace( "<domain>", domain ); content = content.replace( "<application-name>", applicationName ); content = content.replace( "<scoped-instance-path>", scopedInstancePath ); content = content.replace( "<ip-address>", ipAddress ); Utils.writeStringInto( content, target ); } catch( IOException e ) { Logger logger = Logger.getLogger( AgentUtils.class.getName()); logger.severe( "A configuration file could not be injected from " + source.getName()); Utils.logException( logger, e ); } } } }
AgentUtils { public static void injectConfigurations( String karafEtc, String applicationName, String scopedInstancePath, String domain, String ipAddress ) { File injectionDir = new File( karafEtc, INJECTED_CONFIGS_DIR ); if( injectionDir.isDirectory()) { for( File source : Utils.listAllFiles( injectionDir, ".cfg.tpl" )) { try { File target = new File( karafEtc, source.getName().replaceFirst( "\\.tpl$", "" )); if( Constants.KARAF_CFG_FILE_AGENT.equalsIgnoreCase( target.getName())) continue; String content = Utils.readFileContent( source ); content = content.replace( "<domain>", domain ); content = content.replace( "<application-name>", applicationName ); content = content.replace( "<scoped-instance-path>", scopedInstancePath ); content = content.replace( "<ip-address>", ipAddress ); Utils.writeStringInto( content, target ); } catch( IOException e ) { Logger logger = Logger.getLogger( AgentUtils.class.getName()); logger.severe( "A configuration file could not be injected from " + source.getName()); Utils.logException( logger, e ); } } } } }
AgentUtils { public static void injectConfigurations( String karafEtc, String applicationName, String scopedInstancePath, String domain, String ipAddress ) { File injectionDir = new File( karafEtc, INJECTED_CONFIGS_DIR ); if( injectionDir.isDirectory()) { for( File source : Utils.listAllFiles( injectionDir, ".cfg.tpl" )) { try { File target = new File( karafEtc, source.getName().replaceFirst( "\\.tpl$", "" )); if( Constants.KARAF_CFG_FILE_AGENT.equalsIgnoreCase( target.getName())) continue; String content = Utils.readFileContent( source ); content = content.replace( "<domain>", domain ); content = content.replace( "<application-name>", applicationName ); content = content.replace( "<scoped-instance-path>", scopedInstancePath ); content = content.replace( "<ip-address>", ipAddress ); Utils.writeStringInto( content, target ); } catch( IOException e ) { Logger logger = Logger.getLogger( AgentUtils.class.getName()); logger.severe( "A configuration file could not be injected from " + source.getName()); Utils.logException( logger, e ); } } } } private  AgentUtils(); }
AgentUtils { public static void injectConfigurations( String karafEtc, String applicationName, String scopedInstancePath, String domain, String ipAddress ) { File injectionDir = new File( karafEtc, INJECTED_CONFIGS_DIR ); if( injectionDir.isDirectory()) { for( File source : Utils.listAllFiles( injectionDir, ".cfg.tpl" )) { try { File target = new File( karafEtc, source.getName().replaceFirst( "\\.tpl$", "" )); if( Constants.KARAF_CFG_FILE_AGENT.equalsIgnoreCase( target.getName())) continue; String content = Utils.readFileContent( source ); content = content.replace( "<domain>", domain ); content = content.replace( "<application-name>", applicationName ); content = content.replace( "<scoped-instance-path>", scopedInstancePath ); content = content.replace( "<ip-address>", ipAddress ); Utils.writeStringInto( content, target ); } catch( IOException e ) { Logger logger = Logger.getLogger( AgentUtils.class.getName()); logger.severe( "A configuration file could not be injected from " + source.getName()); Utils.logException( logger, e ); } } } } private  AgentUtils(); static boolean isValidIP( String ip ); static void copyInstanceResources( Instance instance, Map<String,byte[]> fileNameToFileContent ); static void executeScriptResources( File scriptsDir ); static void deleteInstanceResources( Instance instance ); static void changeRoboconfLogLevel( String logLevel, String etcDir ); static Map<String,byte[]> collectLogs( String karafData ); static String findIpAddress( String networkInterface ); static void injectConfigurations(
			String karafEtc,
			String applicationName,
			String scopedInstancePath,
			String domain,
			String ipAddress ); }
AgentUtils { public static void injectConfigurations( String karafEtc, String applicationName, String scopedInstancePath, String domain, String ipAddress ) { File injectionDir = new File( karafEtc, INJECTED_CONFIGS_DIR ); if( injectionDir.isDirectory()) { for( File source : Utils.listAllFiles( injectionDir, ".cfg.tpl" )) { try { File target = new File( karafEtc, source.getName().replaceFirst( "\\.tpl$", "" )); if( Constants.KARAF_CFG_FILE_AGENT.equalsIgnoreCase( target.getName())) continue; String content = Utils.readFileContent( source ); content = content.replace( "<domain>", domain ); content = content.replace( "<application-name>", applicationName ); content = content.replace( "<scoped-instance-path>", scopedInstancePath ); content = content.replace( "<ip-address>", ipAddress ); Utils.writeStringInto( content, target ); } catch( IOException e ) { Logger logger = Logger.getLogger( AgentUtils.class.getName()); logger.severe( "A configuration file could not be injected from " + source.getName()); Utils.logException( logger, e ); } } } } private  AgentUtils(); static boolean isValidIP( String ip ); static void copyInstanceResources( Instance instance, Map<String,byte[]> fileNameToFileContent ); static void executeScriptResources( File scriptsDir ); static void deleteInstanceResources( Instance instance ); static void changeRoboconfLogLevel( String logLevel, String etcDir ); static Map<String,byte[]> collectLogs( String karafData ); static String findIpAddress( String networkInterface ); static void injectConfigurations(
			String karafEtc,
			String applicationName,
			String scopedInstancePath,
			String domain,
			String ipAddress ); static final String INJECTED_CONFIGS_DIR; }