-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generation X and printing Y sorted integers into HDFS via YARN applic…
…ation to make it work pay attention to sequenceiq/hadoop-docker#56 issue description also minor pom-files fixes
- Loading branch information
1 parent
59b176c
commit a2c9430
Showing
11 changed files
with
135 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
Homework5/gs-yarn-basic-container/src/main/java/hello/container/DigitsGeneratorSorter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package hello.container; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FileSystem; | ||
import org.apache.hadoop.fs.Path; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.yarn.annotation.OnContainerStart; | ||
import org.springframework.yarn.annotation.YarnComponent; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.io.OutputStreamWriter; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.*; | ||
|
||
@YarnComponent | ||
public class DigitsGeneratorSorter { | ||
|
||
private static final int NUMBER_OF_GENERATED_RANDOM_DIGITS = 100000; | ||
private static final int NUMBER_OF_DIGITS_WRITE_TO_HDFS = 100; | ||
private static final Log LOGGER = LogFactory.getLog(DigitsGeneratorSorter.class); | ||
private static final String OUTPUT_FILE_NAME = "result"; | ||
|
||
@Autowired | ||
private Configuration configuration; | ||
|
||
@OnContainerStart | ||
public void onContainerStart() throws Exception { | ||
List<Integer> integerList = createAndSortDigits(NUMBER_OF_GENERATED_RANDOM_DIGITS); | ||
writeRecordsToHDFS(integerList, NUMBER_OF_DIGITS_WRITE_TO_HDFS); | ||
} | ||
|
||
private List<Integer> createAndSortDigits(int numberOfDigits) { | ||
LOGGER.info("Creating list of " + NUMBER_OF_GENERATED_RANDOM_DIGITS + " sorted digits ..."); | ||
Random random = new Random(); | ||
List<Integer> list = new ArrayList<Integer>(); | ||
for (int i = 0; i < numberOfDigits; i++) { | ||
list.add(Math.abs(random.nextInt())); | ||
} | ||
|
||
LOGGER.info("Sorting created list of " + NUMBER_OF_GENERATED_RANDOM_DIGITS + " ..."); | ||
Collections.sort(list); | ||
LOGGER.info("Sorting created list of " + NUMBER_OF_GENERATED_RANDOM_DIGITS + " complete"); | ||
|
||
LOGGER.info("Creation list of " + NUMBER_OF_GENERATED_RANDOM_DIGITS + " sorted digits complete"); | ||
return list; | ||
} | ||
|
||
private void writeRecordsToHDFS(List<Integer> integerList, int numberOfIntegerToWrite) throws URISyntaxException, IOException { | ||
LOGGER.info("Writing " + numberOfIntegerToWrite + " in sorted list to HDFS in /" + OUTPUT_FILE_NAME + " ..."); | ||
// TODO can be enhanced via | ||
// String hostname = System.getenv("HOSTNAME"); | ||
|
||
String hostname = "172.17.0.2"; | ||
Configuration configuration = new Configuration(); | ||
FileSystem fileSystem = FileSystem.get(new URI("hdfs://" + hostname + ":9000"), configuration); | ||
Path file = new Path("hdfs://" + hostname + ":9000/" + OUTPUT_FILE_NAME); | ||
if (fileSystem.exists(file)) { | ||
fileSystem.delete(file, true); | ||
} | ||
|
||
OutputStream outputStream = fileSystem.create(file); | ||
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8")); | ||
// TODO can be rewritten via streams | ||
for (int i = 0; i < numberOfIntegerToWrite; i++) { | ||
bufferedWriter.write(String.valueOf(integerList.get(i))); | ||
bufferedWriter.write("\n"); | ||
} | ||
|
||
bufferedWriter.close(); | ||
fileSystem.close(); | ||
|
||
LOGGER.info("Writing " + numberOfIntegerToWrite + " in sorted list to HDFS in /" + OUTPUT_FILE_NAME + " complete"); | ||
} | ||
|
||
} |
50 changes: 0 additions & 50 deletions
50
Homework5/gs-yarn-basic-container/src/main/java/hello/container/HelloPojo.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<!--Patched yarn settings for YARN managers to have limitless virtual memory--> | ||
<!--see https://github.com/sequenceiq/hadoop-docker/issues/56 for more info--> | ||
|
||
<configuration> | ||
<property> | ||
<name>yarn.nodemanager.aux-services</name> | ||
<value>mapreduce_shuffle</value> | ||
</property> | ||
|
||
<property> | ||
<name>yarn.application.classpath</name> | ||
<value>/usr/local/hadoop/etc/hadoop, /usr/local/hadoop/share/hadoop/common/*, /usr/local/hadoop/share/hadoop/common/lib/*, /usr/local/hadoop/share/hadoop/hdfs/*, /usr/local/hadoop/share/hadoop/hdfs/lib/*, /usr/local/hadoop/share/hadoop/mapreduce/*, /usr/local/hadoop/share/hadoop/mapreduce/lib/*, /usr/local/hadoop/share/hadoop/yarn/*, /usr/local/hadoop/share/hadoop/yarn/lib/*</value> | ||
</property> | ||
|
||
<property> | ||
<description> | ||
Number of seconds after an application finishes before the nodemanager's | ||
DeletionService will delete the application's localized file directory | ||
and log directory. | ||
|
||
To diagnose Yarn application problems, set this property's value large | ||
enough (for example, to 600 = 10 minutes) to permit examination of these | ||
directories. After changing the property's value, you must restart the | ||
nodemanager in order for it to have an effect. | ||
|
||
The roots of Yarn applications' work directories is configurable with | ||
the yarn.nodemanager.local-dirs property (see below), and the roots | ||
of the Yarn applications' log directories is configurable with the | ||
yarn.nodemanager.log-dirs property (see also below). | ||
</description> | ||
<name>yarn.nodemanager.delete.debug-delay-sec</name> | ||
<value>600</value> | ||
</property> | ||
<property> | ||
<name>yarn.nodemanager.vmem-check-enabled</name> | ||
<value>false</value> | ||
<description>Whether virtual memory limits will be enforced for containers</description> | ||
</property> | ||
<property> | ||
<name>yarn.nodemanager.vmem-pmem-ratio</name> | ||
<value>4</value> | ||
<description>Ratio between virtual memory to physical memory when setting memory limits for containers</description> | ||
</property> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters