Search in sources :

Example 1 with UsState

use of com.netflix.exhibitor.core.state.UsState in project exhibitor by soabase.

the class StandardProcessOperations method prepConfigFile.

private void prepConfigFile(Details details) throws IOException {
    UsState usState = new UsState(exhibitor);
    File idFile = new File(details.dataDirectory, "myid");
    if (usState.getUs() != null) {
        Files.createParentDirs(idFile);
        String id = String.format("%d\n", usState.getUs().getServerId());
        Files.write(id.getBytes(), idFile);
    } else {
        exhibitor.getLog().add(ActivityLog.Type.INFO, "Starting in standalone mode");
        if (idFile.exists() && !idFile.delete()) {
            exhibitor.getLog().add(ActivityLog.Type.ERROR, "Could not delete ID file: " + idFile);
        }
    }
    Properties localProperties = new Properties();
    localProperties.putAll(details.properties);
    localProperties.setProperty("clientPort", Integer.toString(usState.getConfig().getInt(IntConfigs.CLIENT_PORT)));
    String portSpec = String.format(":%d:%d", usState.getConfig().getInt(IntConfigs.CONNECT_PORT), usState.getConfig().getInt(IntConfigs.ELECTION_PORT));
    for (ServerSpec spec : usState.getServerList().getSpecs()) {
        localProperties.setProperty("server." + spec.getServerId(), spec.getHostname() + portSpec + spec.getServerType().getZookeeperConfigValue());
    }
    if ((usState.getUs() != null) && (usState.getUs().getServerType() == ServerType.OBSERVER)) {
        localProperties.setProperty("peerType", "observer");
    }
    File configFile = new File(details.configDirectory, "zoo.cfg");
    OutputStream out = new BufferedOutputStream(new FileOutputStream(configFile));
    try {
        localProperties.store(out, "Auto-generated by Exhibitor - " + new Date());
    } finally {
        CloseableUtils.closeQuietly(out);
    }
}
Also used : ServerSpec(com.netflix.exhibitor.core.state.ServerSpec) UsState(com.netflix.exhibitor.core.state.UsState) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) Properties(java.util.Properties) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) Date(java.util.Date)

Aggregations

ServerSpec (com.netflix.exhibitor.core.state.ServerSpec)1 UsState (com.netflix.exhibitor.core.state.UsState)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 Date (java.util.Date)1 Properties (java.util.Properties)1