Skip to content

Commit

Permalink
Added HadoopSession Pooling Libs. Fixed lcd issue not making adjustme…
Browse files Browse the repository at this point in the history
…nt to local current dir.
  • Loading branch information
dstreev committed May 6, 2021
1 parent add0326 commit f418a41
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 22 deletions.
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.streever.hadoop</groupId>
<artifactId>hadoop-cli</artifactId>
<version>2.3.1.0-SNAPSHOT</version>
<version>2.3.1.2-SNAPSHOT</version>
<name>Hadoop CLI</name>
<description>Hadoop Command Line Interface</description>
<properties>
Expand All @@ -50,6 +50,7 @@
<junit.version>4.13.1</junit.version>
<jackson.parser>2.11.1</jackson.parser>
<commons-io.version>2.4</commons-io.version>
<commons-pool.version>2.9.0</commons-pool.version>
<jcabi.manifests.version>1.1</jcabi.manifests.version>
<commons-lang.version>3.11</commons-lang.version>

Expand Down Expand Up @@ -137,6 +138,12 @@
<artifactId>commons-lang3</artifactId>
<version>${commons-lang.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>${commons-pool.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/streever/hadoop/HadoopSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,6 @@ public static HadoopSession get(String name) {
return instance;
}


private Options getOptions() {
// create Options object
Options options = new Options();
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/streever/hadoop/HadoopSessionFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.streever.hadoop;

import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;

public class HadoopSessionFactory extends BasePooledObjectFactory<HadoopSession> {
@Override
public HadoopSession create() throws Exception {
String[] api = {"-api"};
HadoopSession rtn = new HadoopSession();
rtn.start(api);
return rtn;
}

@Override
public PooledObject<HadoopSession> wrap(HadoopSession hadoopSession) {
return new DefaultPooledObject<HadoopSession>(hadoopSession);
}
}
30 changes: 30 additions & 0 deletions src/main/java/com/streever/hadoop/HadoopSessionPool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.streever.hadoop;

import org.apache.commons.pool2.ObjectPool;

public class HadoopSessionPool {

private ObjectPool<HadoopSession> pool;

public HadoopSessionPool(ObjectPool<HadoopSession> pool) {
this.pool = pool;
}

public HadoopSession borrow() {
HadoopSession rtn = null;
try {
rtn = pool.borrowObject();
} catch (Exception e) {
e.printStackTrace();
}
return rtn;
}

public void returnSession(HadoopSession session) {
try {
pool.returnObject(session);
} catch (Exception e) {
e.printStackTrace();
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/streever/hadoop/HadoopShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class HadoopShell {

public static void main(String[] args) throws Exception {
HadoopSession shell = HadoopSession.get("CLI");
HadoopSession shell = new HadoopSession();
if (!shell.start(args)) {
System.err.println("Couldn't start HDFS Shell");
System.exit(-1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void setWorkingDirectory(Path workingDirectory) {
// Strip the URI from the incoming path, if exists
this.workingDirectory = new Path(workingDirectory.toString().replace(getURI(), ""));
// Keep the Filesystem in sync
// fileSystem.setWorkingDirectory(new Path(workingDirectory.toString().replace(getURI(), "")));
fileSystem.setWorkingDirectory(new Path(workingDirectory.toString().replace(getURI(), "")));
}

public Date getLastAccessed() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.streever.hadoop;

import static org.junit.Assert.*;

public class HadoopSessionFactoryTest {

}
2 changes: 1 addition & 1 deletion src/test/java/com/streever/hadoop/HadoopSessionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class HadoopSessionTest extends TestCase {

public void setUp() throws Exception {
super.setUp();
shell = HadoopSession.get("shell1");
shell = new HadoopSession();
try {
String[] api = {"-api"};
shell.start(api);
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/streever/hadoop/api/TestApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class TestApi {

@Before
public void before() {
shell = HadoopSession.get("shell1");
shell2 = HadoopSession.get( "shell2");
shell = new HadoopSession();
shell2 = new HadoopSession();
try {
String[] api = {"-api"};
// boolean result = Arrays.stream(alphabet).anyMatch("A"::equals);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@
*/
public class SerializationTest {

@Test
public void DefinitionFromResourceTest001 () {
Definition definition = ReplicationHelper.definitionFromResource("/default_def.json");

System.out.println(definition.toString());

}

@Test
public void StateFromStringTest001 () {
State state = ReplicationHelper.stateFromResource("/default_state.json");

System.out.println(state.toString());

}
// @Test
// public void DefinitionFromResourceTest001 () {
// Definition definition = ReplicationHelper.definitionFromResource("/default_def.json");
//
// System.out.println(definition.toString());
//
// }
//
// @Test
// public void StateFromStringTest001 () {
// State state = ReplicationHelper.stateFromResource("/default_state.json");
//
// System.out.println(state.toString());
//
// }

}

0 comments on commit f418a41

Please sign in to comment.