Skip to content

Commit

Permalink
Merge pull request #42 from anthonydahanne/consistency
Browse files Browse the repository at this point in the history
Consistency support
  • Loading branch information
mathieucarbou authored Jun 15, 2018
2 parents ee595e4 + 21424be commit f6de9ef
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 11 deletions.
6 changes: 6 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ and then start it with :
java -jar target/tinypounderXXX.jar
----

or, in a single step :

---
./mvnw clean spring-boot:run
---

4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<version>1.5.14.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<vaadin.version>8.0.6</vaadin.version>
<vaadin.version>8.4.3</vaadin.version>
</properties>

<dependencies>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/terracotta/tinypounder/ProcUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void write(int b) throws IOException {
.workingDir(workDir)
.redirectStderr()
.pipeStdout(out)
.env("JAVA_OPTS", "-Dcom.terracottatech.tools.clustertool.timeout=10000")
.build();

Thread waiter = new Thread(() -> {
Expand Down
123 changes: 114 additions & 9 deletions src/main/java/org/terracotta/tinypounder/TinyPounderMainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.PopupView;
import com.vaadin.ui.RadioButtonGroup;
import com.vaadin.ui.Slider;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.ValoTheme;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -82,6 +84,8 @@ public class TinyPounderMainUI extends UI {
private static final int DATAROOT_PATH_COLUMN = 2;
private static final File HOME = new File(System.getProperty("user.home"));
private static final String VERSION = getVersion();
private static final String AVAILABILITY = "Availability";
private static final String CONSISTENCY = "Consistency";

@Autowired
private CacheManagerBusiness cacheManagerBusiness;
Expand Down Expand Up @@ -120,6 +124,7 @@ public class TinyPounderMainUI extends UI {
private GridLayout serverGrid;
private Slider reconnectWindow;
private GridLayout dataRootGrid;
private GridLayout consistencyGrid;
private Slider dataRoots;
private CheckBox platformPersistence;
private CheckBox platformBackup;
Expand All @@ -136,6 +141,8 @@ public class TinyPounderMainUI extends UI {
private Button generateTcConfig;
private TextField baseLocation;
private Button trashDataButton;
private RadioButtonGroup<String> consistencyGroup;
private TextField votersCountTextField;

@Override
protected void init(VaadinRequest vaadinRequest) {
Expand Down Expand Up @@ -317,13 +324,19 @@ private void addVoltronCommandsControls() {
clusterDumpBtn.setData("dump");
clusterDumpBtn.addClickListener((Button.ClickListener) this::executeClusterToolCommand);

Button clusterStatusBtn = new Button();
clusterStatusBtn.addStyleName("align-bottom");
clusterStatusBtn.setCaption("Status");
clusterStatusBtn.setData("status");
clusterStatusBtn.addClickListener((Button.ClickListener) this::executeClusterToolCommand);

Button clusterStopBtn = new Button();
clusterStopBtn.addStyleName("align-bottom");
clusterStopBtn.setCaption("Stop cluster");
clusterStopBtn.setData("stop");
clusterStopBtn.addClickListener((Button.ClickListener) this::executeClusterToolCommand);

row1.addComponents(clusterNameTF, clusterConfigBtn, clusterReConfigBtn, clusterBackupBtn, clusterDumpBtn, clusterStopBtn);
row1.addComponents(clusterNameTF, clusterConfigBtn, clusterReConfigBtn, clusterBackupBtn, clusterDumpBtn, clusterStopBtn, clusterStatusBtn);
}

voltronControlLayout.addComponentsAndExpand(row1);
Expand Down Expand Up @@ -366,23 +379,41 @@ private void executeClusterToolCommand(Button.ClickEvent event) {
}

case "dump":
case "status":
case "backup":
case "stop": {
ProcUtils.run(
workDir,
script + " " + command + " -n " + clusterNameTF.getValue() + " " + hostPortList.get(0),
script + " " + command + " -n " + clusterNameTF.getValue() + " " + hostPortList.stream().collect(Collectors.joining(" ")),
consoleLines,
newLine -> access(() -> updateMainConsole(consoleLines)),
() -> access(() -> consoles.setSelectedTab(mainConsole)));
break;
}
default:
// probably a serverName is coming in, so we want status for this server
String hostPort = getHostPortFromServerName(command);

ProcUtils.run(
workDir,
script + " status -s " + hostPort,
consoleLines,
newLine -> access(() -> updateMainConsole(consoleLines)),
() -> access(() -> consoles.setSelectedTab(mainConsole)));
break;

}

consoles.setSelectedTab(mainConsole);
updateMainConsole(consoleLines);
}

private String getHostPortFromServerName(String serverName) {
List<String> serverNameList = getServerNameList();
List<String> hostPortList = getHostPortList();
return hostPortList.get(serverNameList.indexOf(serverName));
}

private void updateMainConsole(Queue<String> consoleLines) {
String text = String.join("", consoleLines);
mainConsole.setValue(text);
Expand All @@ -407,7 +438,7 @@ private void updateServerControls() {

serverControls.removeAllComponents();
serverControls.setRows(nStripes * nServersPerStripe);
serverControls.setColumns(5);
serverControls.setColumns(6);

for (int i = consoles.getComponentCount() - 1; i > 0; i--) {
consoles.removeTab(consoles.getTab(i));
Expand Down Expand Up @@ -436,6 +467,13 @@ private void updateServerControls() {
stopBT.setData(serverName);
serverControls.addComponent(stopBT);

Button statusBT = new Button();
statusBT.setEnabled(false);
statusBT.setCaption("STATUS");
statusBT.setStyleName("align-top");
statusBT.setData(serverName);
serverControls.addComponent(statusBT);

Label pid = new Label();
serverControls.addComponent(pid);

Expand All @@ -445,11 +483,12 @@ private void updateServerControls() {
addConsole(serverName, stripeName + "-" + serverName);

startBT.addClickListener((Button.ClickListener) event -> {
startServer(stripeName, (String) event.getButton().getData(), startBT, stopBT, state, pid);
startServer(stripeName, (String) event.getButton().getData(), startBT, stopBT, statusBT, state, pid);
});
stopBT.addClickListener((Button.ClickListener) event -> {
stopServer(stripeName, (String) event.getButton().getData(), stopBT);
stopServer(stripeName, (String) event.getButton().getData(), stopBT, statusBT);
});
statusBT.addClickListener((Button.ClickListener) this::executeClusterToolCommand);
}
}
}
Expand All @@ -471,16 +510,33 @@ private List<String> getHostPortList() {
return servers;
}

private void stopServer(String stripeName, String serverName, Button stopBT) {
private List<String> getServerNameList() {
int nStripes = serverGrid.getRows() - 1;
int nServersPerStripe = serverGrid.getColumns() - 1;
List<String> servers = new ArrayList<>(nStripes * nServersPerStripe);
for (int stripeId = 1; stripeId < serverGrid.getRows(); stripeId++) {
for (int serverId = 1; serverId < serverGrid.getColumns(); serverId++) {
FormLayout form = (FormLayout) serverGrid.getComponent(serverId, stripeId);
if (form != null) {
TextField serverName = (TextField) form.getComponent(0);
servers.add(serverName.getValue());
}
}
}
return servers;
}

private void stopServer(String stripeName, String serverName, Button stopBT, Button statusBT) {
RunningServer runningServer = runningServers.get(stripeName + "-" + serverName);
if (runningServer != null) {
runningServer.stop();
stopBT.setEnabled(false);
statusBT.setEnabled(false);
runningServer.refreshConsole();
}
}

private void startServer(String stripeName, String serverName, Button startBT, Button stopBT, Label stateLBL, Label pidLBL) {
private void startServer(String stripeName, String serverName, Button startBT, Button stopBT, Button statusBT, Label stateLBL, Label pidLBL) {
File stripeconfig = tcConfigLocationPerStripe.get(stripeName);
if (stripeconfig == null) {
generateXML(false);
Expand All @@ -497,6 +553,7 @@ private void startServer(String stripeName, String serverName, Button startBT, B
runningServers.remove(key);
access(() -> {
stopBT.setEnabled(false);
statusBT.setEnabled(false);
startBT.setEnabled(true);
pidLBL.setValue("");
stateLBL.setValue("STOPPED");
Expand All @@ -516,6 +573,7 @@ private void startServer(String stripeName, String serverName, Button startBT, B
runningServer.start();
startBT.setEnabled(false);
stopBT.setEnabled(true);
statusBT.setEnabled(true);
runningServer.refreshConsole();
}

Expand Down Expand Up @@ -640,6 +698,44 @@ private void addVoltronConfigControls() {
platformPersistenceWanted(true);

layout.addComponentsAndExpand(dataRootGrid);

//consistency and voters
consistencyGrid = new GridLayout(2, 1);
consistencyGroup = new RadioButtonGroup<>();
consistencyGroup.setItems(AVAILABILITY, CONSISTENCY);
consistencyGroup.setSelectedItem(AVAILABILITY);
consistencyGroup.addStyleName(ValoTheme.OPTIONGROUP_HORIZONTAL);


consistencyGrid.addComponent(consistencyGroup);
consistencyGroup.addStyleName("align-bottom");

FormLayout votersGroup = new FormLayout();
votersGroup.addStyleName("align-bottom3");
votersCountTextField = new TextField("Voters count");
votersCountTextField.setMaxLength(2);
votersCountTextField.setValue("2");

votersCountTextField.addValueChangeListener(event -> {
try {
Integer.parseInt(event.getValue());
votersCountTextField.setCaption("Voters count");
} catch (NumberFormatException e) {
votersCountTextField.setCaption("Voters count - MUST BE INTEGER");
}
});

votersGroup.addComponent(votersCountTextField);

consistencyGroup.addValueChangeListener(event -> {
if (event.getValue().equals(AVAILABILITY)) {
consistencyGrid.removeComponent(votersGroup);
} else {
consistencyGrid.addComponent(votersGroup, 1, 0);
}
});

layout.addComponentsAndExpand(consistencyGrid);
}

// stripe / server form
Expand Down Expand Up @@ -843,10 +939,19 @@ private void generateXML(boolean skipConfirmOverwrite) {

// reconnect window
sb.append(" <client-reconnect-window>" + reconnectWindow.getValue().intValue() + "</client-reconnect-window>\n\n");
sb.append(" </servers>\n\n");

if (consistencyGroup.isSelected(CONSISTENCY)) {
int votersCount = Integer.parseInt(votersCountTextField.getValue());
sb.append(" <failover-priority>\n" +
" <consistency>\n" +
" <voter count=\"" + votersCount + "\"/>\n" +
" </consistency>\n" +
" </failover-priority>\n\n");
}

// ends XML
sb.append(" </servers>\n\n" +
"</tc-config>");
sb.append("</tc-config>");

String filename = "tc-config-stripe-" + stripeRow + ".xml";
File location = new File(settings.getKitPath(), filename);
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/VAADIN/themes/tinypounder/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ $v-layout-margin-bottom: 16px;
margin-top: 18px !important;
}

.align-bottom3, v-textfield-align-bottom3 {
margin-top: 3px !important;
}

.align-top {
top: -5px !important;
}
Expand Down

0 comments on commit f6de9ef

Please sign in to comment.