Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.classpath
.git
.gitignore
.project
.settings
.travis.yml
LICENSE
README.md
pom.xml
src
target/classes
target/etcd-viewer-*-SNAPSHOT
target/generated-sources
target/generated-test-sources
target/maven-archiver
target/surefire-reports
target/test-classes
target/test-resources
target/work
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM jetty:9.2.12-jre7
FROM jetty:9.2-jre8

MAINTAINER Nikos Fountas "nikfoundas@gmail.com"

Expand All @@ -11,6 +11,3 @@ RUN curl --silent -L `cat /tmp/etcd-viewer-release-archive` > /var/lib/jetty/web

# To build your own local custom etcd viewer docker image comment the above RUN commands and uncomment the following
# ADD ./target/*.war /var/lib/jetty/webapps/ROOT.war

RUN chmod 644 /var/lib/jetty/webapps/ROOT.war
RUN chown jetty:jetty /var/lib/jetty/webapps/ROOT.war
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<slf4j.version>1.6.4</slf4j.version>
<log4j.version>1.2.16</log4j.version>
<junit.version>4.11</junit.version>
<mockito.version>2.15.0</mockito.version>

<bootstrap.version>3.3.4</bootstrap.version>
<fontawesome.version>4.3.0</fontawesome.version>
Expand Down Expand Up @@ -189,6 +190,13 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>

<!-- JETTY DEPENDENCIES FOR TESTING -->
<dependency>
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/github/etcd/service/EtcdCluster.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
*
*/
package org.github.etcd.service;

import java.util.Date;
Expand Down
25 changes: 11 additions & 14 deletions src/main/java/org/github/etcd/service/RestModule.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
/**
*
*/
package org.github.etcd.service;

import javax.inject.Inject;
import javax.inject.Singleton;

import org.github.etcd.service.api.v3.EtcdV3ProxyImpl;
import org.github.etcd.service.impl.ClusterManagerImpl;
import org.github.etcd.service.api.EtcdProxy;
import org.github.etcd.service.api.v2.EtcdV2ProxyImpl;
import org.github.etcd.service.api.v3.EtcdV3ProxyImpl;
import org.github.etcd.service.impl.ClusterManagerImpl;
import org.github.etcd.viewer.EtcdWebSession;

import com.google.inject.AbstractModule;
import com.google.inject.name.Names;

public class RestModule extends AbstractModule {

private static final String ETCD_NODE = "etcd.clientURL";

public static final String SELECTED_CLUSTER_NAME = "selectedCluster";

@Override
protected void configure() {

String etcdAddress = System.getenv(ETCD_NODE);
if (etcdAddress == null) {
etcdAddress = System.getProperty(ETCD_NODE, "http://localhost:2379/");
}

bindConstant().annotatedWith(Names.named(ETCD_NODE)).to(etcdAddress);
bindParameterValue(ClusterManagerImpl.DEFAULT_CLIENT_URL_KEY);
bindParameterValue(ClusterManagerImpl.CLUSTER_STORE_PATH_KEY);

bind(ClusterManager.class).to(ClusterManagerImpl.class).in(Singleton.class);

bind(EtcdProxyFactory.class).to(EtcdProxyFactoryImpl.class).in(Singleton.class);
}

private void bindParameterValue(String parameterName) {
String parameterValue = System.getenv(parameterName);
if (parameterValue == null) {
parameterValue = System.getProperty(parameterName, "");
}
bindConstant().annotatedWith(Names.named(parameterName)).to(parameterValue);
}

private static class EtcdProxyFactoryImpl implements EtcdProxyFactory {
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/github/etcd/service/api/EtcdNode.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
*
*/
package org.github.etcd.service.api;

import java.io.Serializable;
Expand Down
94 changes: 82 additions & 12 deletions src/main/java/org/github/etcd/service/impl/ClusterManagerImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.github.etcd.service.impl;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand All @@ -21,6 +24,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.inject.name.Named;

public class ClusterManagerImpl implements ClusterManager {

private static final Logger log = LoggerFactory.getLogger(ClusterManager.class);
Expand All @@ -41,24 +49,47 @@ public int compare(EtcdMember o1, EtcdMember o2) {
STATE_MAPPINGS.put("StateFollower", "follower");
}

@Inject
private EtcdProxyFactory proxyFactory;
private final EtcdProxyFactory proxyFactory;

private Map<String, EtcdCluster> clusters = Collections.synchronizedMap(new LinkedHashMap<String, EtcdCluster>());

private static final String DEFAULT_ETCD_CLIENT = "ETCD_CLIENT_URL";

public ClusterManagerImpl() {

String etcdAddress = System.getenv(DEFAULT_ETCD_CLIENT);
if (etcdAddress == null) {
etcdAddress = System.getProperty(DEFAULT_ETCD_CLIENT, "http://localhost:2379");
public static final String DEFAULT_CLIENT_URL_KEY = "ETCD_CLIENT_URL";
private static final String DEFAULT_CLIENT_URL = "http://localhost:2379/";
public static final String CLUSTER_STORE_PATH_KEY = "CLUSTER_STORE_PATH";
private static final String CLUSTER_STORE_FILENAME = "clusters.json";

private final File clusterStoreFile;
private final ObjectMapper mapper = new ObjectMapper();

@Inject
public ClusterManagerImpl(@Named(DEFAULT_CLIENT_URL_KEY) String defaultClientUrl,
@Named(CLUSTER_STORE_PATH_KEY) String clusterStorePath,
EtcdProxyFactory proxyFactory) {
log.debug("{}: {}", DEFAULT_CLIENT_URL_KEY, defaultClientUrl);
log.debug("{}: {}", CLUSTER_STORE_PATH_KEY, clusterStorePath);

if (Strings.isNullOrEmpty(defaultClientUrl)) {
defaultClientUrl = DEFAULT_CLIENT_URL;
log.debug("Using default {}: {}", DEFAULT_CLIENT_URL_KEY, defaultClientUrl);
}

this.proxyFactory = proxyFactory;

if (!Strings.isNullOrEmpty(clusterStorePath)) {
clusterStoreFile = new File(clusterStorePath, CLUSTER_STORE_FILENAME);
if (clusterStoreFile.exists()) {
loadClusters();
}
} else {
clusterStoreFile = null;
}

addCluster("default", etcdAddress, ApiVersion.V3);
// addCluster("kvm", "http://192.168.122.201:2379/");
if (clusters.isEmpty()) {
addCluster("Local V2", defaultClientUrl, ApiVersion.V2);
addCluster("Local V3", defaultClientUrl, ApiVersion.V3);
}
}

@Override
public boolean exists(String name) {
return clusters.containsKey(name);
Expand All @@ -73,12 +104,17 @@ public EtcdCluster getCluster(String name) {
public EtcdCluster addCluster(String name, String etcdPeerAddress, ApiVersion apiVersion) {
EtcdCluster cluster = new EtcdCluster(name, etcdPeerAddress, apiVersion);
clusters.put(name, cluster);

persistClusters();

return cluster;
}

@Override
public void removeCluster(String name) {
clusters.remove(name);

persistClusters();
}

@Override
Expand Down Expand Up @@ -157,6 +193,40 @@ public void refreshCluster(String name) {
cluster.setLastRefreshTime(new Date());
cluster.setRefreshed(true);

persistClusters();
}

private void loadClusters() {
log.info("Loading {}", clusterStoreFile.getAbsolutePath());
try {
Map<String, EtcdCluster> incoming = mapper.readValue(clusterStoreFile,
new TypeReference<Map<String, EtcdCluster>>() {});
clusters = Collections.synchronizedMap(incoming);

log.debug("Loaded {} clusters", clusters.size());
} catch (IOException e) {
log.error("Unable to read cluster config from {}", clusterStoreFile.getAbsolutePath());
}
}

private synchronized void persistClusters() {
if (clusterStoreFile != null) {
try {
Files.createDirectories(clusterStoreFile.getParentFile().toPath());
} catch (IOException e) {
log.error("Unable to create configured cluster storage directory {}",
clusterStoreFile.getParentFile().getAbsolutePath(), e);
return;
}

log.debug("Writing {} clusters", clusters.size());

try {
mapper.writeValue(clusterStoreFile, clusters);
} catch (IOException e) {
log.error("Unable to write cluster config to {}", clusterStoreFile.getAbsolutePath(), e);
}
}
}

}
3 changes: 0 additions & 3 deletions src/main/java/org/github/etcd/viewer/ConvertUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
*
*/
package org.github.etcd.viewer;

import org.apache.wicket.request.mapper.parameter.PageParameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.ResourceModel;
import org.apache.wicket.util.visit.IVisit;
import org.apache.wicket.util.visit.IVisitor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
*
*/
package org.github.etcd.viewer.html.node;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
*
*/
package org.github.etcd.viewer.html.pages;

import org.apache.wicket.AttributeModifier;
Expand Down
3 changes: 0 additions & 3 deletions src/test/java/org/github/etcd/rest/EtcdResource.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
*
*/
package org.github.etcd.rest;

import javax.ws.rs.DELETE;
Expand Down
Loading