Search in sources :

Example 1 with ServerSpec

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);
    }
}
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)

Example 2 with ServerSpec

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);
}
Also used : ServerSpec(com.netflix.exhibitor.core.state.ServerSpec) InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) ObjectNode(org.codehaus.jackson.node.ObjectNode) ServerList(com.netflix.exhibitor.core.state.ServerList) ArrayNode(org.codehaus.jackson.node.ArrayNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with ServerSpec

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");
}
Also used : ServerSpec(com.netflix.exhibitor.core.state.ServerSpec) Test(org.testng.annotations.Test)

Example 4 with ServerSpec

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);
}
Also used : ServerSpec(com.netflix.exhibitor.core.state.ServerSpec) ServerStatus(com.netflix.exhibitor.core.entities.ServerStatus) ServerList(com.netflix.exhibitor.core.state.ServerList)

Example 5 with ServerSpec

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()));
}
Also used : ServerSpec(com.netflix.exhibitor.core.state.ServerSpec) ServerList(com.netflix.exhibitor.core.state.ServerList)

Aggregations

ServerSpec (com.netflix.exhibitor.core.state.ServerSpec)9 ServerList (com.netflix.exhibitor.core.state.ServerList)7 InstanceConfig (com.netflix.exhibitor.core.config.InstanceConfig)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 ServerStatus (com.netflix.exhibitor.core.entities.ServerStatus)2 InstanceStateTypes (com.netflix.exhibitor.core.state.InstanceStateTypes)2 ObjectNode (org.codehaus.jackson.node.ObjectNode)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 BackupConfigSpec (com.netflix.exhibitor.core.backup.BackupConfigSpec)1 EncodedConfigParser (com.netflix.exhibitor.core.config.EncodedConfigParser)1 IntConfigs (com.netflix.exhibitor.core.config.IntConfigs)1 StringConfigs (com.netflix.exhibitor.core.config.StringConfigs)1 FourLetterWord (com.netflix.exhibitor.core.state.FourLetterWord)1 ServerType (com.netflix.exhibitor.core.state.ServerType)1 UsState (com.netflix.exhibitor.core.state.UsState)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1