public Cluster(ClusterInfo clusterInfo) { this.eucalyptusConfigurationFileParser = new EucalyptusConfigurationFileParser();
String minVlanId = eucalyptusConfigurationFileParser.getValue("MIN_VLAN_ID", "10");
String maxVlanId = eucalyptusConfigurationFileParser.getValue("MAX_VLAN_ID", "4096");
this.clusterInfo = clusterInfo;
this.state = new ClusterState(this, Integer.parseInt(minVlanId), Integer.parseInt(maxVlanId)); this.nodeState = new ClusterNodeState(this); this.messageQueue = new ClusterMessageQueue(this); this.rscUpdater = new ResourceUpdateCallback(this); this.addrUpdater = new AddressUpdateCallback(this); this.vmUpdater = new VmUpdateCallback(this); this.nodeLogUpdater = new NodeLogCallback(this); this.nodeCertUpdater = new NodeCertCallback(this); this.nodeMap = new ConcurrentSkipListMap<String, NodeInfo>();
}
Then in ClusterState constructor:
public ClusterState(Cluster parent, int minVlanId, int maxVlanId) {
this.parent = parent;
LOG.info(String.format("Using min vlan id of %d, and max vlan id of %d", minVlanId, maxVlanId)); this.availableVlans = new ConcurrentSkipListSet<Integer>();
for (int i = minVlanId; i < maxVlanId; i++) this.availableVlans.add(i);
}
public class EucalyptusConfigurationFileParserTest {
private EucalyptusConfigurationFileParser eucalyptusConfigurationFileParser;
@Before
public void before() {
URL url = this.getClass().getClassLoader().getResource("com/bt/koala/eucalyptus/conf/test.euca.conf");
eucalyptusConfigurationFileParser = new EucalyptusConfigurationFileParser(url.getPath());
}
/**
* Should read quoted value from config file
*/
@Test
public void shouldRealQuotedValueFromConfigFile() {
// act
String res = eucalyptusConfigurationFileParser.getValue("START_CLOUD");
// assert assertEquals("N", res);
}
/**
* Should read non-quoted value from config file
*/
@Test
public void shouldRealNonQuotedValueFromConfigFile() {
// act
String res = eucalyptusConfigurationFileParser.getValue("NC_PORT");
// assert assertEquals("8775", res);
}
/**
* Should read key with blank value
*/
@Test
public void shouldRealKeyWithBlankValue() {
// act
String res = eucalyptusConfigurationFileParser.getValue("NODES");
// assert assertEquals("", res);
}
/**
* Should return null for unknonwn key
*/
@Test
public void shouldReturnNullForUnknownKey() {
// act
String res = eucalyptusConfigurationFileParser.getValue("UNKNOWN");
// assert assertNull(res);
}
/**
* Should return default value for unknonwn key with default value
*/
@Test
public void shouldReturnDefaultValueForUnknownKeyWithDefaultValue() {
// act
String res = eucalyptusConfigurationFileParser.getValue("UNKNOWN", "dflt");
// assert assertEquals("dflt", res);
}
/**
* Should fail for bad path
*/
@Test(expected = RuntimeException.class)
public void shouldFailForBadPath() {
// setup eucalyptusConfigurationFileParser = new EucalyptusConfigurationFileParser("moo");
@Chris,
In the Cluster.java constructor:
public Cluster(ClusterInfo clusterInfo) {
this.eucalyptu sConfigurationF ileParser = new EucalyptusConfi gurationFilePar ser(); gurationFilePar ser.getValue( "MIN_VLAN_ ID", "10"); gurationFilePar ser.getValue( "MAX_VLAN_ ID", "4096");
String minVlanId = eucalyptusConfi
String maxVlanId = eucalyptusConfi
this.state = new ClusterState(this, Integer.
}
Then in ClusterState constructor:
public ClusterState( Cluster parent, int minVlanId, int maxVlanId) {
this.parent = parent;
for (int i = minVlanId; i < maxVlanId; i++)
}
Then a new configuration file reader:
import java.io. BufferedReader; FileInputStream ; IOException; InputStreamRead er;
import java.io.File;
import java.io.
import java.io.
import java.io.
import java.util.HashMap;
import java.util.Map;
import org.apache. commons. logging. Log; commons. logging. LogFactory;
import org.apache.
public class EucalyptusConfi gurationFilePar ser { getLog( EucalyptusConfi gurationFilePar ser.class) ; RELATIVE_ CONFIG_ FILE_PATH = "/etc/eucalyptu s/eucalyptus. conf"; getProperty( "euca.home" ); rationFilePath;
private static Log LOG = LogFactory.
private static final String DEFAULT_
private static final String eucaHome = System.
private String absoluteConfigu
private Map<String, String> configMap = new HashMap<String, String>();
public EucalyptusConfi gurationFilePar ser() {
this(eucaHome + DEFAULT_ RELATIVE_ CONFIG_ FILE_PATH) ;
}
public EucalyptusConfi gurationFilePar ser(String absoluteConfigu rationFilePath) {
this.absoluteC onfigurationFil ePath = absoluteConfigu rationFilePath;
LOG.info( String. format( "Set euca config file absolute path to %s", this.absoluteCo nfigurationFile Path));
}
public String getValue(String key) {
return getValue(key, null);
}
public String getValue(String key, String defaultValue) {
String value = configMap.get(key);
if (value == null)
return defaultValue;
return value;
}
protected void loadConfig() {
LOG.info( String. format( "Loading euca config from %s", absoluteConfigu rationFilePath) );
FileInputS tream fileInputStream = new FileInputStream(new File(absoluteCo nfigurationFile Path));
BufferedRe ader reader = new BufferedReader(new InputStreamRead er(fileInputStr eam));
String trimmedLine = line.trim(); startsWith( "#") || trimmedLine. length( ) < 1)
continue;
try {
String line;
while ((line = reader.readLine()) != null) {
if (trimmedLine.
if (parts.length > 1) {
}
}
} catch (IOException e) {
throw new RuntimeExceptio
}
}
}
With tests:
import static org.junit. Assert. assertEquals; Assert. assertNull;
import static org.junit.
import java.net.URL;
import org.junit.Before;
import org.junit.Test;
public class EucalyptusConfi gurationFilePar serTest { gurationFilePar ser eucalyptusConfi gurationFilePar ser;
private EucalyptusConfi
@Before ).getClassLoade r().getResource ("com/bt/ koala/eucalyptu s/conf/ test.euca. conf");
public void before() {
URL url = this.getClass(
}
/** dValueFromConfi gFile() { gurationFilePar ser.getValue( "START_ CLOUD") ;
* Should read quoted value from config file
*/
@Test
public void shouldRealQuote
// act
String res = eucalyptusConfi
// assert
assertEquals( "N", res);
}
/** otedValueFromCo nfigFile( ) { gurationFilePar ser.getValue( "NC_PORT" );
* Should read non-quoted value from config file
*/
@Test
public void shouldRealNonQu
// act
String res = eucalyptusConfi
// assert
assertEquals( "8775", res);
}
/** thBlankValue( ) { gurationFilePar ser.getValue( "NODES" );
* Should read key with blank value
*/
@Test
public void shouldRealKeyWi
// act
String res = eucalyptusConfi
// assert
assertEquals( "", res);
}
/** lForUnknownKey( ) { gurationFilePar ser.getValue( "UNKNOWN" );
* Should return null for unknonwn key
*/
@Test
public void shouldReturnNul
// act
String res = eucalyptusConfi
// assert
assertNull( res);
}
/** aultValueForUnk nownKeyWithDefa ultValue( ) { gurationFilePar ser.getValue( "UNKNOWN" , "dflt");
* Should return default value for unknonwn key with default value
*/
@Test
public void shouldReturnDef
// act
String res = eucalyptusConfi
// assert
assertEquals( "dflt", res);
}
/** n.class) dPath() {
eucalyptusConf igurationFilePa rser = new EucalyptusConfi gurationFilePar ser("moo" );
* Should fail for bad path
*/
@Test(expected = RuntimeExceptio
public void shouldFailForBa
// setup
// act
eucalyptusConf igurationFilePa rser.getValue( "NC_PORT" );
}
}