diff options
author | James Moger <james.moger@gitblit.com> | 2011-10-25 17:23:47 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2011-10-25 17:23:47 -0400 |
commit | 486ee115abb831b2ec78be6777fb1bca9e931df0 (patch) | |
tree | fc25ea7282eb5068a8620f81e8cb9ee9233d2ca2 /src | |
parent | 4c837a1de9f7706c7bfb0cbb14a7082f916826ae (diff) | |
download | gitblit-486ee115abb831b2ec78be6777fb1bca9e931df0.tar.gz gitblit-486ee115abb831b2ec78be6777fb1bca9e931df0.zip |
Documentation. Changed status RPC protection. Status tab for Manager.
Diffstat (limited to 'src')
-rw-r--r-- | src/com/gitblit/GitBlit.java | 8 | ||||
-rw-r--r-- | src/com/gitblit/RpcServlet.java | 6 | ||||
-rw-r--r-- | src/com/gitblit/client/GitblitClient.java | 7 | ||||
-rw-r--r-- | src/com/gitblit/client/GitblitPanel.java | 46 | ||||
-rw-r--r-- | src/com/gitblit/client/PropertiesTableModel.java | 106 | ||||
-rw-r--r-- | src/com/gitblit/client/StatusPanel.java | 119 | ||||
-rw-r--r-- | src/com/gitblit/models/ServerStatus.java | 11 | ||||
-rw-r--r-- | src/com/gitblit/wicket/GitBlitWebApp.properties | 9 |
8 files changed, 301 insertions, 11 deletions
diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index 8386d2d4..19edf204 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -253,7 +253,7 @@ public class GitBlit implements ServletContextListener { * @return true if the update succeeded
*/
public boolean updateSettings(Map<String, String> updatedSettings) {
- return settings.saveSettings(updatedSettings);
+ return settings.saveSettings(updatedSettings);
}
public ServerStatus getStatus() {
@@ -1389,7 +1389,7 @@ public class GitBlit implements ServletContextListener { repositoriesFolder = new File(settings.getString(Keys.git.repositoriesFolder, "git"));
logger.info("Git repositories folder " + repositoriesFolder.getAbsolutePath());
repositoryResolver = new FileResolver<Void>(repositoriesFolder, exportAll);
- serverStatus = new ServerStatus();
+ serverStatus = new ServerStatus(isGO());
String realm = settings.getString(Keys.realm.userService, "users.properties");
IUserService loginService = null;
try {
@@ -1433,12 +1433,14 @@ public class GitBlit implements ServletContextListener { @Override
public void contextInitialized(ServletContextEvent contextEvent) {
servletContext = contextEvent.getServletContext();
- settingsModel = loadSettingModels();
+ settingsModel = loadSettingModels();
if (settings == null) {
// Gitblit WAR is running in a servlet container
WebXmlSettings webxmlSettings = new WebXmlSettings(contextEvent.getServletContext());
configureContext(webxmlSettings, true);
}
+
+ serverStatus.servletContainer = servletContext.getServerInfo();
}
/**
diff --git a/src/com/gitblit/RpcServlet.java b/src/com/gitblit/RpcServlet.java index 1136692a..dd99e3f4 100644 --- a/src/com/gitblit/RpcServlet.java +++ b/src/com/gitblit/RpcServlet.java @@ -199,7 +199,11 @@ public class RpcServlet extends JsonServlet { }
} else if (RpcRequest.LIST_STATUS.equals(reqType)) {
// return the server's status information
- result = GitBlit.self().getStatus();
+ if (GitBlit.getBoolean(Keys.web.enableRpcAdministration, false)) {
+ result = GitBlit.self().getStatus();
+ } else {
+ response.sendError(notAllowedCode);
+ }
}
// send the result of the request
diff --git a/src/com/gitblit/client/GitblitClient.java b/src/com/gitblit/client/GitblitClient.java index d3a92b0d..761283eb 100644 --- a/src/com/gitblit/client/GitblitClient.java +++ b/src/com/gitblit/client/GitblitClient.java @@ -87,7 +87,7 @@ public class GitblitClient implements Serializable { try {
refreshSettings();
- status = RpcUtils.getStatus(url, account, password);
+ refreshStatus();
allowAdministration = true;
} catch (UnauthorizedException e) {
} catch (ForbiddenException e) {
@@ -141,6 +141,11 @@ public class GitblitClient implements Serializable { settings = RpcUtils.getSettings(url, account, password);
return settings;
}
+
+ public ServerStatus refreshStatus() throws IOException {
+ status = RpcUtils.getStatus(url, account, password);
+ return status;
+ }
public List<FederationModel> refreshFederationRegistrations() throws IOException {
List<FederationModel> list = RpcUtils.getFederationRegistrations(url, account, password);
diff --git a/src/com/gitblit/client/GitblitPanel.java b/src/com/gitblit/client/GitblitPanel.java index d67921ba..1a24f71b 100644 --- a/src/com/gitblit/client/GitblitPanel.java +++ b/src/com/gitblit/client/GitblitPanel.java @@ -118,6 +118,8 @@ public class GitblitPanel extends JPanel implements CloseTabListener { private HeaderPanel settingsHeader;
+ private StatusPanel statusPanel;
+
public GitblitPanel(GitblitRegistration reg) {
this(reg.url, reg.account, reg.password);
}
@@ -129,6 +131,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener { tabs.addTab(Translation.get("gb.repositories"), createRepositoriesPanel());
tabs.addTab(Translation.get("gb.users"), createUsersPanel());
tabs.addTab(Translation.get("gb.settings"), createSettingsPanel());
+ tabs.addTab(Translation.get("gb.status"), createStatusPanel());
setLayout(new BorderLayout());
add(tabs, BorderLayout.CENTER);
@@ -482,6 +485,24 @@ public class GitblitPanel extends JPanel implements CloseTabListener { return settingsPanel;
}
+ private JPanel createStatusPanel() {
+ JButton refreshStatus = new JButton(Translation.get("gb.refresh"));
+ refreshStatus.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ refreshStatus();
+ }
+ });
+
+ JPanel controls = new JPanel();
+ controls.add(refreshStatus);
+
+ JPanel panel = new JPanel(new BorderLayout());
+ statusPanel = new StatusPanel();
+ panel.add(statusPanel, BorderLayout.CENTER);
+ panel.add(controls, BorderLayout.SOUTH);
+ return panel;
+ }
+
public void login() throws IOException {
gitblit.login();
@@ -505,6 +526,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener { if (gitblit.allowAdministration()) {
updateSettingsTable();
+ updateStatusPanel();
Utils.packColumns(settingsTable, 5);
} else {
// remove the settings tab
@@ -539,6 +561,10 @@ public class GitblitPanel extends JPanel implements CloseTabListener { settingsHeader.setText(Translation.get("gb.settings"));
}
+ private void updateStatusPanel() {
+ statusPanel.setStatus(gitblit.getStatus());
+ }
+
private void filterRepositories(final String fragment) {
if (StringUtils.isEmpty(fragment)) {
repositoriesTable.setRowSorter(defaultRepositoriesSorter);
@@ -934,6 +960,22 @@ public class GitblitPanel extends JPanel implements CloseTabListener { worker.execute();
}
+ protected void refreshStatus() {
+ GitblitWorker worker = new GitblitWorker(GitblitPanel.this, RpcRequest.LIST_STATUS) {
+ @Override
+ protected Boolean doRequest() throws IOException {
+ gitblit.refreshStatus();
+ return true;
+ }
+
+ @Override
+ protected void onSuccess() {
+ updateStatusPanel();
+ }
+ };
+ worker.execute();
+ }
+
protected void editSetting(final SettingModel settingModel) {
final JTextField textField = new JTextField(settingModel.currentValue);
JPanel editPanel = new JPanel(new GridLayout(0, 1));
@@ -949,8 +991,8 @@ public class GitblitPanel extends JPanel implements CloseTabListener { if (settingModel.currentValue.equals(settingModel.defaultValue)) {
options = new String[] { Translation.get("gb.cancel"), Translation.get("gb.save") };
} else {
- options = new String[] { Translation.get("gb.cancel"), Translation.get("gb.setDefault"),
- Translation.get("gb.save") };
+ options = new String[] { Translation.get("gb.cancel"),
+ Translation.get("gb.setDefault"), Translation.get("gb.save") };
}
String defaultOption = options[0];
int selection = JOptionPane.showOptionDialog(GitblitPanel.this, settingPanel,
diff --git a/src/com/gitblit/client/PropertiesTableModel.java b/src/com/gitblit/client/PropertiesTableModel.java new file mode 100644 index 00000000..0c803f47 --- /dev/null +++ b/src/com/gitblit/client/PropertiesTableModel.java @@ -0,0 +1,106 @@ +/*
+ * Copyright 2011 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.client;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.swing.table.AbstractTableModel;
+
+/**
+ * Table model of a map of properties.
+ *
+ * @author James Moger
+ *
+ */
+public class PropertiesTableModel extends AbstractTableModel {
+
+ private static final long serialVersionUID = 1L;
+
+ List<String> keys;
+
+ Map<String, String> map;
+
+ enum Columns {
+ Name, Value;
+
+ @Override
+ public String toString() {
+ return name().replace('_', ' ');
+ }
+ }
+
+ public PropertiesTableModel() {
+ this(new HashMap<String, String>());
+ }
+
+ public PropertiesTableModel(Map<String, String> map) {
+ setProperties(map);
+ }
+
+ public void setProperties(Map<String, String> map) {
+ this.map = map;
+ keys = new ArrayList<String>(map.keySet());
+ Collections.sort(this.keys);
+ }
+
+ @Override
+ public int getRowCount() {
+ return keys.size();
+ }
+
+ @Override
+ public int getColumnCount() {
+ return Columns.values().length;
+ }
+
+ @Override
+ public String getColumnName(int column) {
+ Columns col = Columns.values()[column];
+ switch (col) {
+ case Name:
+ return Translation.get("gb.name");
+ }
+ return "";
+ }
+
+ /**
+ * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.
+ *
+ * @param columnIndex
+ * the column being queried
+ * @return the Object.class
+ */
+ public Class<?> getColumnClass(int columnIndex) {
+ return String.class;
+ }
+
+ @Override
+ public Object getValueAt(int rowIndex, int columnIndex) {
+ String key = keys.get(rowIndex);
+ Columns col = Columns.values()[columnIndex];
+ switch (col) {
+ case Name:
+ return key;
+ case Value:
+ return map.get(key);
+ }
+ return null;
+ }
+}
diff --git a/src/com/gitblit/client/StatusPanel.java b/src/com/gitblit/client/StatusPanel.java new file mode 100644 index 00000000..9015c80f --- /dev/null +++ b/src/com/gitblit/client/StatusPanel.java @@ -0,0 +1,119 @@ +/*
+ * Copyright 2011 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.client;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.Font;
+import java.awt.GridLayout;
+import java.awt.Insets;
+
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+
+import com.gitblit.models.ServerStatus;
+import com.gitblit.utils.ByteFormat;
+
+/**
+ * This panel displays the server status.
+ *
+ * @author James Moger
+ */
+public class StatusPanel extends JPanel {
+
+ private static final long serialVersionUID = 1L;
+ private final Insets insets = new Insets(5, 5, 5, 5);
+ private JLabel bootDate;
+ private JLabel servletContainer;
+ private JLabel heapMaximum;
+ private JLabel heapAllocated;
+ private JLabel heapUsed;
+ private PropertiesTableModel model;
+ private HeaderPanel headerPanel;
+
+ public StatusPanel() {
+ super();
+ initialize();
+ }
+
+ public StatusPanel(ServerStatus status) {
+ this();
+ setStatus(status);
+ }
+
+ private void initialize() {
+ bootDate = new JLabel();
+ servletContainer = new JLabel();
+
+ heapMaximum = new JLabel();
+ heapAllocated = new JLabel();
+ heapUsed = new JLabel();
+
+ JPanel fieldsPanel = new JPanel(new GridLayout(0, 1));
+ fieldsPanel.add(createFieldPanel("gb.bootDate", bootDate));
+ fieldsPanel.add(createFieldPanel("gb.servletContainer", servletContainer));
+ fieldsPanel.add(createFieldPanel("gb.heapUsed", heapUsed));
+ fieldsPanel.add(createFieldPanel("gb.heapAllocated", heapAllocated));
+ fieldsPanel.add(createFieldPanel("gb.heapMaximum", heapMaximum));
+
+ model = new PropertiesTableModel();
+ JTable propertiesTable = Utils.newTable(model);
+ String name = propertiesTable.getColumnName(PropertiesTableModel.Columns.Name.ordinal());
+ NameRenderer nameRenderer = new NameRenderer();
+ propertiesTable.setRowHeight(nameRenderer.getFont().getSize() + 8);
+ propertiesTable.getColumn(name).setCellRenderer(nameRenderer);
+
+ JPanel centerPanel = new JPanel(new BorderLayout());
+ centerPanel.add(fieldsPanel, BorderLayout.NORTH);
+ centerPanel.add(new JScrollPane(propertiesTable), BorderLayout.CENTER);
+
+ headerPanel = new HeaderPanel(Translation.get("gb.status"), null);
+ setLayout(new BorderLayout());
+ add(headerPanel, BorderLayout.NORTH);
+ add(centerPanel, BorderLayout.CENTER);
+ }
+
+ private JPanel createFieldPanel(String key, JLabel valueLabel) {
+ JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 5));
+ JLabel textLabel = new JLabel(Translation.get(key));
+ textLabel.setFont(textLabel.getFont().deriveFont(Font.BOLD));
+ textLabel.setPreferredSize(new Dimension(120, valueLabel.getFont().getSize() + 4));
+ panel.add(textLabel);
+ panel.add(valueLabel);
+ return panel;
+ }
+
+ @Override
+ public Insets getInsets() {
+ return insets;
+ }
+
+ public void setStatus(ServerStatus status) {
+ headerPanel.setText(Translation.get("gb.status"));
+ bootDate.setText(status.bootDate.toString());
+ servletContainer.setText(status.servletContainer);
+ ByteFormat byteFormat = new ByteFormat();
+ heapMaximum.setText(byteFormat.format(status.heapMaximum));
+ heapAllocated.setText(byteFormat.format(status.heapAllocated));
+ heapUsed.setText(byteFormat.format(status.heapAllocated - status.heapFree) + " ("
+ + byteFormat.format(status.heapFree) + " " + Translation.get("gb.free") + ")");
+ model.setProperties(status.systemProperties);
+ model.fireTableDataChanged();
+ }
+}
diff --git a/src/com/gitblit/models/ServerStatus.java b/src/com/gitblit/models/ServerStatus.java index 8dfc0fbc..1c40b5f4 100644 --- a/src/com/gitblit/models/ServerStatus.java +++ b/src/com/gitblit/models/ServerStatus.java @@ -33,18 +33,23 @@ public class ServerStatus implements Serializable { public final Date bootDate;
+ public final boolean isGO;
+
public final Map<String, String> systemProperties;
- public final long heapSize;
+ public final long heapMaximum;
public volatile long heapAllocated;
public volatile long heapFree;
+
+ public String servletContainer;
- public ServerStatus() {
+ public ServerStatus(boolean isGO) {
bootDate = new Date();
+ this.isGO = isGO;
- heapSize = Runtime.getRuntime().maxMemory();
+ heapMaximum = Runtime.getRuntime().maxMemory();
systemProperties = new TreeMap<String, String>();
put("file.encoding");
diff --git a/src/com/gitblit/wicket/GitBlitWebApp.properties b/src/com/gitblit/wicket/GitBlitWebApp.properties index 2052fb12..715cb156 100644 --- a/src/com/gitblit/wicket/GitBlitWebApp.properties +++ b/src/com/gitblit/wicket/GitBlitWebApp.properties @@ -166,4 +166,11 @@ gb.skipSummaryMetricsDescription = do not calculate metrics on the summary page gb.accessLevel = access level
gb.default = default
gb.setDefault = set default
-gb.since = since
\ No newline at end of file +gb.since = since
+gb.status = status
+gb.bootDate = boot date
+gb.servletContainer = servlet container
+gb.heapMaximum = maximum heap
+gb.heapAllocated = allocated heap
+gb.heapUsed = used heap
+gb.free = free
\ No newline at end of file |