Skip to content

Commit 385dd82

Browse files
committed
Merge pull request #18 from gluster/reformat
Run the Java code through a standard formatter. Format settings in resource/
2 parents f7162f1 + b6fcad8 commit 385dd82

12 files changed

+1860
-1656
lines changed

resources/eclipse-formatting-settings.xml

Lines changed: 291 additions & 0 deletions
Large diffs are not rendered by default.

src/main/java/org/apache/hadoop/fs/glusterfs/FileInfoUtil.java

Lines changed: 57 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -11,68 +11,63 @@
1111
*
1212
* This class will be extended in the future to also return permissions.
1313
*/
14-
public class FileInfoUtil {
15-
16-
/**
17-
* Returns the array of values from ls -aFl :
18-
*
19-
* Currently only handles "owner" , since that is what is most needed by
20-
* the GFAPI that is meant to use this class.
21-
*
22-
* m = getLSinfo("myfile.txt").get("owner")
23-
* System.out.println(m) ; <-- jayunit100
24-
*/
25-
public static Map<String, String> getLSinfo(String filename) throws IOException {
26-
String ret="";
27-
try {
28-
String ls_str;
29-
Process ls_proc = Runtime.getRuntime().exec("/bin/ls -aFl " + filename);
30-
DataInputStream ls_in = new DataInputStream(
31-
ls_proc.getInputStream());
32-
try {
33-
//should only be one line if input is a file
34-
while ((ls_str = ls_in.readLine()) != null) {
35-
if(ls_str.length()<10)
36-
;
37-
else{
38-
ret+=(ls_str);
39-
}
40-
}
41-
}
42-
catch (IOException e) {
43-
throw new RuntimeException(e);
44-
}
45-
}
46-
catch (IOException e1) {
47-
throw new RuntimeException(e1);
48-
}
49-
//initialization to "" was only to make for clean appending.
50-
if(ret.equals(""))
51-
ret=null;
14+
public class FileInfoUtil{
5215

53-
//Convenience: transform to map
54-
Map<String, String> mm = lsToMap(ret);
55-
return mm;
56-
}
16+
/**
17+
* Returns the array of values from ls -aFl :
18+
*
19+
* Currently only handles "owner" , since that is what is most needed by the
20+
* GFAPI that is meant to use this class.
21+
*
22+
* m = getLSinfo("myfile.txt").get("owner") System.out.println(m) ; <--
23+
* jayunit100
24+
*/
25+
public static Map<String, String> getLSinfo(String filename) throws IOException{
26+
String ret="";
27+
try{
28+
String ls_str;
29+
Process ls_proc=Runtime.getRuntime().exec("/bin/ls -aFl "+filename);
30+
DataInputStream ls_in=new DataInputStream(ls_proc.getInputStream());
31+
try{
32+
// should only be one line if input is a file
33+
while ((ls_str=ls_in.readLine())!=null){
34+
if(ls_str.length()<10)
35+
;
36+
else{
37+
ret+=(ls_str);
38+
}
39+
}
40+
}catch (IOException e){
41+
throw new RuntimeException(e);
42+
}
43+
}catch (IOException e1){
44+
throw new RuntimeException(e1);
45+
}
46+
// initialization to "" was only to make for clean appending.
47+
if(ret.equals(""))
48+
ret=null;
49+
50+
// Convenience: transform to map
51+
Map<String, String> mm=lsToMap(ret);
52+
return mm;
53+
}
54+
55+
/**
56+
* Converts the output of ls -aFl to a map :
57+
*
58+
* EXPECTED INPUT STRING: -rwxr-xr-x. 1 root root 786 Mar 7 11:42
59+
* buildbranch_and_copyjartovms.sh*
60+
*
61+
* EXPECTED OUTPUT: key="owner" -> the owner of the file (root)
62+
* key="permissions" -> the hadoop permissions on the file.
63+
*/
64+
private static Map<String, String> lsToMap(String ret){
65+
String[] values=ret.split("\\s+");
66+
67+
Map<String, String> mm=new TreeMap();
68+
mm.put("owner", values[2]);
69+
70+
return mm;
71+
}
5772

58-
/**
59-
* Converts the output of ls -aFl to a map :
60-
*
61-
* EXPECTED INPUT STRING:
62-
* -rwxr-xr-x. 1 root root 786 Mar 7 11:42 buildbranch_and_copyjartovms.sh*
63-
*
64-
* EXPECTED OUTPUT:
65-
* key="owner" -> the owner of the file (root)
66-
* key="permissions" -> the hadoop permissions on the file.
67-
*/
68-
private static Map<String, String> lsToMap(String ret) {
69-
String[] values = ret.split("\\s+");
70-
71-
Map<String,String> mm = new TreeMap();
72-
mm.put("owner", values[2]);
73-
74-
return mm;
75-
}
76-
77-
7873
}

src/main/java/org/apache/hadoop/fs/glusterfs/GlusterFSBrickClass.java

Lines changed: 68 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -21,89 +21,85 @@
2121

2222
import java.io.*;
2323

24-
public class GlusterFSBrickClass {
25-
String host;
26-
String exportedFile;
27-
long start;
28-
long end;
29-
boolean isChunked;
30-
int stripeSize; // Stripe size in bytes
31-
int nrStripes; // number of stripes
32-
int switchCount; // for SR, DSR - number of replicas of each stripe
33-
// -1 for others
34-
35-
public GlusterFSBrickClass (String brick, long start, long len, boolean flag,
36-
int stripeSize, int nrStripes, int switchCount)
37-
throws IOException {
38-
this.host = brick2host(brick);
39-
this.exportedFile = brick2file(brick);
40-
this.start = start;
41-
this.end = start + len;
42-
this.isChunked = flag;
43-
this.stripeSize = stripeSize;
44-
this.nrStripes = nrStripes;
45-
this.switchCount = switchCount;
24+
public class GlusterFSBrickClass{
25+
String host;
26+
String exportedFile;
27+
long start;
28+
long end;
29+
boolean isChunked;
30+
int stripeSize; // Stripe size in bytes
31+
int nrStripes; // number of stripes
32+
int switchCount; // for SR, DSR - number of replicas of each stripe
33+
// -1 for others
34+
35+
public GlusterFSBrickClass(String brick, long start, long len, boolean flag, int stripeSize, int nrStripes, int switchCount) throws IOException{
36+
this.host=brick2host(brick);
37+
this.exportedFile=brick2file(brick);
38+
this.start=start;
39+
this.end=start+len;
40+
this.isChunked=flag;
41+
this.stripeSize=stripeSize;
42+
this.nrStripes=nrStripes;
43+
this.switchCount=switchCount;
44+
}
45+
46+
public boolean isChunked(){
47+
return isChunked;
48+
}
49+
50+
public String brickIsLocal(String hostname){
51+
String path=null;
52+
File f=null;
53+
if(host.equals(hostname))
54+
path=exportedFile;
55+
56+
return path;
57+
}
58+
59+
public int[] getBrickNumberInTree(long start,int len){
60+
long end=len;
61+
int startNodeInTree=((int) (start/stripeSize))%nrStripes;
62+
int endNodeInTree=((int) ((start+len)/stripeSize))%nrStripes;
63+
64+
if(startNodeInTree!=endNodeInTree){
65+
end=(start-(start%stripeSize))+stripeSize;
66+
end-=start;
4667
}
4768

48-
public boolean isChunked () {
49-
return isChunked;
50-
}
51-
52-
public String brickIsLocal(String hostname) {
53-
String path = null;
54-
File f = null;
55-
if (host.equals(hostname))
56-
path = exportedFile;
57-
58-
return path;
59-
}
60-
61-
public int[] getBrickNumberInTree(long start, int len) {
62-
long end = len;
63-
int startNodeInTree = ((int) (start / stripeSize)) % nrStripes;
64-
int endNodeInTree = ((int) ((start + len) / stripeSize)) % nrStripes;
69+
return new int[]{startNodeInTree,endNodeInTree,(int) end};
70+
}
6571

66-
if (startNodeInTree != endNodeInTree) {
67-
end = (start - (start % stripeSize)) + stripeSize;
68-
end -= start;
69-
}
72+
public boolean brickHasFilePart(int nodeInTree,int nodeLoc){
73+
if(switchCount==-1)
74+
return (nodeInTree==nodeLoc);
7075

71-
return new int[] {startNodeInTree, endNodeInTree, (int) end};
76+
nodeInTree*=switchCount;
77+
for(int i=nodeInTree;i<(nodeInTree+switchCount);i++){
78+
if(i==nodeLoc)
79+
return true;
7280
}
7381

74-
public boolean brickHasFilePart(int nodeInTree, int nodeLoc) {
75-
if (switchCount == -1)
76-
return (nodeInTree == nodeLoc);
82+
return false;
83+
}
7784

78-
nodeInTree *= switchCount;
79-
for (int i = nodeInTree; i < (nodeInTree + switchCount); i++) {
80-
if (i == nodeLoc)
81-
return true;
82-
}
85+
public String brick2host(String brick) throws IOException{
86+
String[] hf=null;
8387

84-
return false;
85-
}
86-
87-
public String brick2host (String brick)
88-
throws IOException {
89-
String[] hf = null;
88+
hf=brick.split(":");
89+
if(hf.length!=2)
90+
throw new IOException("Error getting hostname from brick");
9091

91-
hf = brick.split(":");
92-
if (hf.length != 2)
93-
throw new IOException("Error getting hostname from brick");
92+
return hf[0];
93+
}
9494

95-
return hf[0];
96-
}
95+
public String brick2file(String brick) throws IOException{
96+
String[] hf=null;
9797

98-
public String brick2file (String brick)
99-
throws IOException {
100-
String[] hf = null;
98+
hf=brick.split(":");
99+
if(hf.length!=2)
100+
throw new IOException("Error getting hostname from brick");
101101

102-
hf = brick.split(":");
103-
if (hf.length != 2)
104-
throw new IOException("Error getting hostname from brick");
105-
106-
return hf[1];
107-
}
102+
return hf[1];
103+
}
108104

109105
}

src/main/java/org/apache/hadoop/fs/glusterfs/GlusterFSBrickRepl.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,32 @@
2121

2222
import java.io.*;
2323

24-
public class GlusterFSBrickRepl {
25-
private String[] replHost;
26-
private long start;
27-
private long len;
28-
private int cnt;
29-
30-
GlusterFSBrickRepl(int replCount, long start, long len) {
31-
this.replHost = new String[replCount];
32-
this.start = start;
33-
this.len = len;
34-
this.cnt = 0;
35-
}
36-
37-
public void addHost (String host) {
38-
this.replHost[cnt++] = host;
39-
}
40-
41-
public String[] getReplHosts () {
42-
return this.replHost;
43-
}
44-
45-
public long getStartLen () {
46-
return this.start;
47-
}
48-
49-
public long getOffLen () {
50-
return this.len;
51-
}
24+
public class GlusterFSBrickRepl{
25+
private String[] replHost;
26+
private long start;
27+
private long len;
28+
private int cnt;
29+
30+
GlusterFSBrickRepl(int replCount, long start, long len){
31+
this.replHost=new String[replCount];
32+
this.start=start;
33+
this.len=len;
34+
this.cnt=0;
35+
}
36+
37+
public void addHost(String host){
38+
this.replHost[cnt++]=host;
39+
}
40+
41+
public String[] getReplHosts(){
42+
return this.replHost;
43+
}
44+
45+
public long getStartLen(){
46+
return this.start;
47+
}
48+
49+
public long getOffLen(){
50+
return this.len;
51+
}
5252
}

0 commit comments

Comments
 (0)