@Test public void testReconfigureMessaging_withAgentConfigurationFile() throws IOException { File karafEtc = this.folder.newFolder(); final File msgConf = new File( karafEtc, "net.roboconf.messaging.rabbitmq.cfg" ); final File agentConf = new File( karafEtc, Constants.KARAF_CFG_FILE_AGENT ); Properties props = new Properties(); props.setProperty( "key", "value" ); props.setProperty( "something", "else" ); props.setProperty( Constants.MESSAGING_TYPE, "http" ); Utils.writePropertiesFile( props, agentConf ); Map<String,String> msgData = new HashMap<> (); msgData.put( MessagingConstants.MESSAGING_TYPE_PROPERTY, "rabbitmq" ); msgData.put("net.roboconf.messaging.rabbitmq.server.ip", "rabbit-server"); msgData.put("net.roboconf.messaging.rabbitmq.server.username", "user1"); msgData.put("net.roboconf.messaging.rabbitmq.server.password", "password1"); msgData.put("test", "issue #779"); Assert.assertFalse( msgConf.exists()); Assert.assertTrue( agentConf.exists()); this.userDataHelper.reconfigureMessaging( karafEtc.getAbsolutePath(), msgData); Assert.assertTrue( msgConf.exists()); Assert.assertTrue( agentConf.exists()); Properties p = Utils.readPropertiesFile( msgConf ); Assert.assertEquals( 4, p.keySet().size()); String val = p.getProperty("net.roboconf.messaging.rabbitmq.server.ip"); Assert.assertEquals(val, "rabbit-server"); val = p.getProperty("net.roboconf.messaging.rabbitmq.server.username"); Assert.assertEquals(val, "user1"); val = p.getProperty("net.roboconf.messaging.rabbitmq.server.password"); Assert.assertEquals(val, "password1"); val = p.getProperty("test"); Assert.assertEquals(val, "issue #779"); p = Utils.readPropertiesFile( agentConf ); Assert.assertEquals( 3, p.size()); Assert.assertEquals( "rabbitmq", p.get( Constants.MESSAGING_TYPE )); Assert.assertEquals( "else", p.get( "something" )); Assert.assertEquals( "value", p.get( "key" )); msgData.remove( "test" ); msgData.put("net.roboconf.messaging.rabbitmq.server.username", "user2"); this.userDataHelper.reconfigureMessaging( karafEtc.getAbsolutePath(), msgData); p = Utils.readPropertiesFile( msgConf ); Assert.assertEquals( 4, p.keySet().size()); val = p.getProperty("net.roboconf.messaging.rabbitmq.server.ip"); Assert.assertEquals(val, "rabbit-server"); val = p.getProperty("net.roboconf.messaging.rabbitmq.server.username"); Assert.assertEquals(val, "user2"); val = p.getProperty("net.roboconf.messaging.rabbitmq.server.password"); Assert.assertEquals(val, "password1"); val = p.getProperty("test"); Assert.assertEquals(val, "issue #779"); }
public void reconfigureMessaging( String etcDir, Map<String,String> msgData ) throws IOException { String messagingType = msgData.get( MessagingConstants.MESSAGING_TYPE_PROPERTY ); Logger.getLogger( getClass().getName()).fine( "Messaging type for reconfiguration: " + messagingType ); if( ! Utils.isEmptyOrWhitespaces( etcDir ) && ! Utils.isEmptyOrWhitespaces( messagingType )) { File f = new File( etcDir, "net.roboconf.messaging." + messagingType + ".cfg" ); Logger logger = Logger.getLogger( getClass().getName()); Properties props = Utils.readPropertiesFileQuietly( f, logger ); props.putAll( msgData ); props.remove( MessagingConstants.MESSAGING_TYPE_PROPERTY ); Utils.writePropertiesFile( props, f ); f = new File( etcDir, Constants.KARAF_CFG_FILE_AGENT ); props = Utils.readPropertiesFileQuietly( f, Logger.getLogger( getClass().getName())); if( messagingType != null ) { props.put( Constants.MESSAGING_TYPE, messagingType ); Utils.writePropertiesFile( props, f ); } } }
UserDataHelper { public void reconfigureMessaging( String etcDir, Map<String,String> msgData ) throws IOException { String messagingType = msgData.get( MessagingConstants.MESSAGING_TYPE_PROPERTY ); Logger.getLogger( getClass().getName()).fine( "Messaging type for reconfiguration: " + messagingType ); if( ! Utils.isEmptyOrWhitespaces( etcDir ) && ! Utils.isEmptyOrWhitespaces( messagingType )) { File f = new File( etcDir, "net.roboconf.messaging." + messagingType + ".cfg" ); Logger logger = Logger.getLogger( getClass().getName()); Properties props = Utils.readPropertiesFileQuietly( f, logger ); props.putAll( msgData ); props.remove( MessagingConstants.MESSAGING_TYPE_PROPERTY ); Utils.writePropertiesFile( props, f ); f = new File( etcDir, Constants.KARAF_CFG_FILE_AGENT ); props = Utils.readPropertiesFileQuietly( f, Logger.getLogger( getClass().getName())); if( messagingType != null ) { props.put( Constants.MESSAGING_TYPE, messagingType ); Utils.writePropertiesFile( props, f ); } } } }
UserDataHelper { public void reconfigureMessaging( String etcDir, Map<String,String> msgData ) throws IOException { String messagingType = msgData.get( MessagingConstants.MESSAGING_TYPE_PROPERTY ); Logger.getLogger( getClass().getName()).fine( "Messaging type for reconfiguration: " + messagingType ); if( ! Utils.isEmptyOrWhitespaces( etcDir ) && ! Utils.isEmptyOrWhitespaces( messagingType )) { File f = new File( etcDir, "net.roboconf.messaging." + messagingType + ".cfg" ); Logger logger = Logger.getLogger( getClass().getName()); Properties props = Utils.readPropertiesFileQuietly( f, logger ); props.putAll( msgData ); props.remove( MessagingConstants.MESSAGING_TYPE_PROPERTY ); Utils.writePropertiesFile( props, f ); f = new File( etcDir, Constants.KARAF_CFG_FILE_AGENT ); props = Utils.readPropertiesFileQuietly( f, Logger.getLogger( getClass().getName())); if( messagingType != null ) { props.put( Constants.MESSAGING_TYPE, messagingType ); Utils.writePropertiesFile( props, f ); } } }  }
UserDataHelper { public void reconfigureMessaging( String etcDir, Map<String,String> msgData ) throws IOException { String messagingType = msgData.get( MessagingConstants.MESSAGING_TYPE_PROPERTY ); Logger.getLogger( getClass().getName()).fine( "Messaging type for reconfiguration: " + messagingType ); if( ! Utils.isEmptyOrWhitespaces( etcDir ) && ! Utils.isEmptyOrWhitespaces( messagingType )) { File f = new File( etcDir, "net.roboconf.messaging." + messagingType + ".cfg" ); Logger logger = Logger.getLogger( getClass().getName()); Properties props = Utils.readPropertiesFileQuietly( f, logger ); props.putAll( msgData ); props.remove( MessagingConstants.MESSAGING_TYPE_PROPERTY ); Utils.writePropertiesFile( props, f ); f = new File( etcDir, Constants.KARAF_CFG_FILE_AGENT ); props = Utils.readPropertiesFileQuietly( f, Logger.getLogger( getClass().getName())); if( messagingType != null ) { props.put( Constants.MESSAGING_TYPE, messagingType ); Utils.writePropertiesFile( props, f ); } } }  AgentProperties findParametersForAmazonOrOpenStack( Logger logger ); AgentProperties findParametersForAzure( Logger logger ); AgentProperties findParametersForVmware( Logger logger ); AgentProperties findParametersFromUrl( String url, Logger logger ); void reconfigureMessaging( String etcDir, Map<String,String> msgData ); }
UserDataHelper { public void reconfigureMessaging( String etcDir, Map<String,String> msgData ) throws IOException { String messagingType = msgData.get( MessagingConstants.MESSAGING_TYPE_PROPERTY ); Logger.getLogger( getClass().getName()).fine( "Messaging type for reconfiguration: " + messagingType ); if( ! Utils.isEmptyOrWhitespaces( etcDir ) && ! Utils.isEmptyOrWhitespaces( messagingType )) { File f = new File( etcDir, "net.roboconf.messaging." + messagingType + ".cfg" ); Logger logger = Logger.getLogger( getClass().getName()); Properties props = Utils.readPropertiesFileQuietly( f, logger ); props.putAll( msgData ); props.remove( MessagingConstants.MESSAGING_TYPE_PROPERTY ); Utils.writePropertiesFile( props, f ); f = new File( etcDir, Constants.KARAF_CFG_FILE_AGENT ); props = Utils.readPropertiesFileQuietly( f, Logger.getLogger( getClass().getName())); if( messagingType != null ) { props.put( Constants.MESSAGING_TYPE, messagingType ); Utils.writePropertiesFile( props, f ); } } }  AgentProperties findParametersForAmazonOrOpenStack( Logger logger ); AgentProperties findParametersForAzure( Logger logger ); AgentProperties findParametersForVmware( Logger logger ); AgentProperties findParametersFromUrl( String url, Logger logger ); void reconfigureMessaging( String etcDir, Map<String,String> msgData );  }