summaryrefslogtreecommitdiffstats
path: root/src/com.gluster.storage.management.server
diff options
context:
space:
mode:
authorShireesh Anjal <shireesh@gluster.com>2011-07-24 22:21:43 +0530
committerShireesh Anjal <shireesh@gluster.com>2011-07-24 22:21:43 +0530
commit1e8135f9e270e7c6557e66532160fbea40ea8bba (patch)
tree4beb7246ca0d64c8c676e119804f4c68bf2f18d5 /src/com.gluster.storage.management.server
parentc3f598a9a5dc66428c98e026f621caf647ae09fd (diff)
parent069be5f7df55052c6b1e00ea7580d94aa97e142b (diff)
Merge branch 'master' of github.com:gluster/console
Conflicts: src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/GlusterDataModelManager.java src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/ChartsPreferencePage.java src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/ClusterSummaryView.java src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/ServerUtil.java
Diffstat (limited to 'src/com.gluster.storage.management.server')
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/KeysResource.java29
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java9
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/ServerUtil.java42
3 files changed, 73 insertions, 7 deletions
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/KeysResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/KeysResource.java
index 5ac37bd1..af64af47 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/KeysResource.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/KeysResource.java
@@ -82,16 +82,33 @@ public class KeysResource extends AbstractResource {
String targetPemFile = targetDir + File.separator + SshUtil.PEM_FILE.getName();
String targetPubKeyFile = targetDir + File.separator + SshUtil.PUBLIC_KEY_FILE.getName();
+ if (!SshUtil.PEM_FILE.isFile()) {
+ throw new GlusterRuntimeException("No private key file [" + SshUtil.PEM_FILE.getName() + "] found!" );
+ }
+
+ if (!SshUtil.PUBLIC_KEY_FILE.isFile()) {
+ throw new GlusterRuntimeException("No public key file [" + SshUtil.PUBLIC_KEY_FILE.getName() + "] found!" );
+ }
+
// Copy keys to temp folder
- processUtil.executeCommand("cp", sourcePemFile, targetPemFile);
- processUtil.executeCommand("cp", sourcePubKeyFile, targetPubKeyFile);
-
- // To zip the key files
- processUtil.executeCommand("tar", "cvf", zipFile, "-C", "/tmp", SshUtil.PEM_FILE.getName(),
+ ProcessResult result = processUtil.executeCommand("cp", sourcePemFile, targetPemFile);
+ if (!result.isSuccess()) {
+ throw new GlusterRuntimeException("Failed to copy key files! [" + result.getOutput() + "]");
+ }
+ result = processUtil.executeCommand("cp", sourcePubKeyFile, targetPubKeyFile);
+ if (!result.isSuccess()) {
+ throw new GlusterRuntimeException("Failed to copy key files! [" + result.getOutput() + "]");
+ }
+
+ // To compress the key files
+ result = processUtil.executeCommand("tar", "cvf", zipFile, "-C", "/tmp", SshUtil.PEM_FILE.getName(),
SshUtil.PUBLIC_KEY_FILE.getName());
+ if (!result.isSuccess()) {
+ throw new GlusterRuntimeException("Failed to compress key files! [" + result.getOutput() + "]");
+ }
// To remove the copied key files
- processUtil.executeCommand("rm", "-f", targetPubKeyFile, targetPubKeyFile);
+ processUtil.executeCommand("rm", "-f", targetPubKeyFile, targetPubKeyFile); // Ignore the errors if any
return zipFile;
}
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java
index 304da012..22da9ca3 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java
@@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.regex.Pattern;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -410,7 +411,13 @@ public class GlusterUtil {
}
private void addBrickToVolume(Volume volume, String serverName, String brickDir, BRICK_STATUS status) {
- volume.addBrick(new Brick(serverName, status, brickDir.split("/")[2].trim(), brickDir));
+ //If brick directory has standard path, find and assign device name otherwise null
+ String stdBrickDirPattern = "^/export/.*/.*"; // e.g: /export/sdb/test
+ String deviceName = null;
+ if (Pattern.matches(stdBrickDirPattern, brickDir) ) {
+ deviceName = brickDir.split("/")[2].trim();
+ }
+ volume.addBrick(new Brick(serverName, status, deviceName, brickDir));
}
// Do not throw exception, Gracefully handle as Offline brick.
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/ServerUtil.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/ServerUtil.java
index 8048615e..609b4f65 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/ServerUtil.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/ServerUtil.java
@@ -224,6 +224,48 @@ public class ServerUtil {
return (Status) executeOnServer(true, serverName, REMOTE_SCRIPT_GET_DISK_FOR_DIR + " " + brickDir, Status.class);
}
+ public ServerStats fetchCPUUsageData(String serverName) {
+ Object output = executeOnServer(true, serverName, "get_rrd_cpu_details.py 1d", ServerStats.class);
+ //String cpuUsageData = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> <xport> <meta> <start>1310468100</start> <step>300</step> <end>1310471700</end> <rows>13</rows> <columns>3</columns> <legend> <entry>user</entry> <entry>system</entry> <entry>total</entry> </legend> </meta> <data> <row><t>1310468100</t><v>2.23802952e-1</v><v>4.3747778209e-01</v><v>6.6128073384e-01</v></row> <row><t>1310468400</t><v>2.3387347338e-01</v><v>4.4642717442e-01</v><v>6.8030064780e-01</v></row> <row><t>1310468700</t><v>5.5043873220e+00</v><v>6.2462376636e+00</v><v>1.1750624986e+01</v></row> <row><t>1310469000</t><v>2.4350593653e+01</v><v>2.6214585217e+01</v><v>5.0565178869e+01</v></row> <row><t>1310469300</t><v>4.0786489953e+01</v><v>4.6784713828e+01</v><v>8.7571203781e+01</v></row> <row><t>1310469600</t><v>4.1459955508e+01</v><v>5.2546309044e+01</v><v>9.4006264551e+01</v></row> <row><t>1310469900</t><v>4.2312286165e+01</v><v>5.2390588332e+01</v><v>9.4702874497e+01</v></row> <row><t>1310470200</t><v>4.2603794982e+01</v><v>5.1598861493e+01</v><v>9.4202656475e+01</v></row> <row><t>1310470500</t><v>3.8238751290e+01</v><v>4.5312089966e+01</v><v>8.3550841256e+01</v></row> <row><t>1310470800</t><v>1.7949961224e+01</v><v>2.1282058418e+01</v><v>3.9232019642e+01</v></row> <row><t>1310471100</t><v>1.2330371421e-01</v><v>4.6347832868e-01</v><v>5.8678204289e-01</v></row> <row><t>1310471400</t><v>1.6313260492e-01</v><v>5.4088119561e-01</v><v>7.0401380052e-01</v></row> <row><t>1310471700</t><v>NaN</v><v>NaN</v><v>NaN</v></row> </data> </xport>";
+ //Object output = unmarshal(ServerStats.class, cpuUsageData, false);
+ if(output instanceof Status) {
+ throw new GlusterRuntimeException(((Status)output).toString());
+ }
+ return (ServerStats) output;
+ }
+
+ private ServerStats getFirstOnlineServerCPUStats(List<String> serverNames, boolean removeServerOnError, boolean removeOnlineServer) {
+ for(int i = serverNames.size() - 1; i >= 0; i--) {
+ String serverName = serverNames.get(i);
+ try {
+ ServerStats stats = fetchCPUUsageData(serverName);
+ if(removeOnlineServer) {
+ serverNames.remove(serverName);
+ }
+ return stats;
+ } catch(Exception e) {
+ // server might be offline - continue with next one
+ logger.warn("Couldn't fetch CPU stats from server [" + serverName + "]!", e);
+ if(removeServerOnError) {
+ serverNames.remove(serverName);
+ }
+ continue;
+ }
+ }
+ throw new GlusterRuntimeException("All servers offline!");
+ }
+
+ public ServerStats fetchAggregatedCPUStats(List<String> serverNames) {
+ if(serverNames == null || serverNames.size() == 0) {
+ throw new GlusterRuntimeException("No server names passed to fetchAggregaredCPUUsageData!");
+ }
+
+ ServerStats firstServerStats = getFirstOnlineServerCPUStats(serverNames, true, true);
+
+ ServerStats aggregatedStats = new ServerStats(firstServerStats);
+ aggregateCPUStats(serverNames, aggregatedStats);
+ return aggregatedStats;
+ }
public static void main(String[] args) {
// ServerStats stats = new ServerUtil().fetchCPUUsageData("s1", "1d");