use of com.netflix.exhibitor.core.state.ServerSpec 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);
}
}
use of com.netflix.exhibitor.core.state.ServerSpec in project exhibitor by soabase.
the class ClusterResource method getClusterAsJson.
@Path("list")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getClusterAsJson() throws Exception {
InstanceConfig config = context.getExhibitor().getConfigManager().getConfig();
ObjectNode node = JsonNodeFactory.instance.objectNode();
ArrayNode serversNode = JsonNodeFactory.instance.arrayNode();
ServerList serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC));
for (ServerSpec spec : serverList.getSpecs()) {
serversNode.add(spec.getHostname());
}
node.put("servers", serversNode);
node.put("port", config.getInt(IntConfigs.CLIENT_PORT));
return JsonUtil.writeValueAsString(node);
}
use of com.netflix.exhibitor.core.state.ServerSpec in project exhibitor by soabase.
the class TestServerSpec method testSpecString.
@Test
public void testSpecString() {
ServerSpec s1 = new ServerSpec("host", 1, ServerType.STANDARD);
ServerSpec s2 = new ServerSpec("host", 2, ServerType.OBSERVER);
Assert.assertEquals(s1.toSpecString(), "1:host");
Assert.assertEquals(s2.toSpecString(), "O:2:host");
}
use of com.netflix.exhibitor.core.state.ServerSpec in project exhibitor by soabase.
the class FlexibleEnsembleBuilder method createPotentialServerList.
public ServerList createPotentialServerList() {
ServerList configuredServerList = clusterState.getConfiguredServerList();
int existingMaxId = getExistingMaxId(configuredServerList);
List<ServerSpec> newList = Lists.newArrayList();
Set<String> addedHostnames = Sets.newHashSet();
for (ServerStatus status : clusterState.getLiveInstances()) {
ServerSpec spec = configuredServerList.getSpec(status.getHostname());
if (spec == null) {
spec = new ServerSpec(status.getHostname(), ++existingMaxId, ServerType.STANDARD);
addedHostnames.add(spec.getHostname());
}
newList.add(spec);
}
if (usState.getUs() == null) {
ServerSpec spec = new ServerSpec(exhibitor.getThisJVMHostname(), ++existingMaxId, ServerType.STANDARD);
addedHostnames.add(spec.getHostname());
newList.add(spec);
}
int standardTypeCount = 0;
for (ServerSpec spec : newList) {
if (spec.getServerType() == ServerType.STANDARD) {
++standardTypeCount;
}
}
int observerThreshold = exhibitor.getConfigManager().getConfig().getInt(IntConfigs.OBSERVER_THRESHOLD);
if (observerThreshold > 0) {
for (int i = 0; (standardTypeCount >= observerThreshold) && (i < newList.size()); ++i) {
ServerSpec spec = newList.get(i);
if (// i.e. don't change existing instances to observer
addedHostnames.contains(spec.getHostname())) {
newList.set(i, new ServerSpec(spec.getHostname(), spec.getServerId(), ServerType.OBSERVER));
--standardTypeCount;
}
}
}
return new ServerList(newList);
}
use of com.netflix.exhibitor.core.state.ServerSpec in project exhibitor by soabase.
the class ClusterState method clear.
void clear() {
statuses.set(Lists.<ServerStatus>newArrayList());
updateTimeMs.set(System.currentTimeMillis());
configuredServerList.set(new ServerList(Lists.<ServerSpec>newArrayList()));
}
Aggregations