Skip to content

Commit

Permalink
begin to add tez repack
Browse files Browse the repository at this point in the history
  • Loading branch information
kgyrtkirk committed Nov 4, 2019
1 parent a65dd3c commit 1407c7c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
58 changes: 58 additions & 0 deletions src/main/java/hu/rxd/toolbox/switcher/TarGzProducer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package hu.rxd.toolbox.switcher;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.RegexFileFilter;


public class TarGzProducer {

public URL createTarGzip(Path inputDirectoryPath) throws IOException {
File outputFile = new File("/path/to/filename.tar.gz");

try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
GzipCompressorOutputStream gzipOutputStream = new GzipCompressorOutputStream(bufferedOutputStream);
TarArchiveOutputStream tarArchiveOutputStream = new TarArchiveOutputStream(gzipOutputStream)) {

tarArchiveOutputStream.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
tarArchiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);

List<File> files = new ArrayList<>(FileUtils.listFiles(
inputDirectoryPath.toFile(),
new RegexFileFilter("^(.*?)"),
DirectoryFileFilter.DIRECTORY
));

for (int i = 0; i < files.size(); i++) {
File currentFile = files.get(i);

String relativeFilePath = new File(inputDirectoryPath.toUri()).toURI().relativize(
new File(currentFile.getAbsolutePath()).toURI()).getPath();

TarArchiveEntry tarEntry = new TarArchiveEntry(currentFile, relativeFilePath);
tarEntry.setSize(currentFile.length());

tarArchiveOutputStream.putArchiveEntry(tarEntry);
tarArchiveOutputStream.write(IOUtils.toByteArray(new FileInputStream(currentFile)));
tarArchiveOutputStream.closeArchiveEntry();
}
tarArchiveOutputStream.close();
return outputFile.toURI().toURL();
}
}
}
9 changes: 5 additions & 4 deletions src/main/java/hu/rxd/toolbox/switcher/TezComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@ public Component getComponentType() {

@Override
protected void provideComponent(File targetPath, Version ver) throws Exception {
File expandPath = new File(baseDir, targetPath.getName() + ".tmp");
FileUtils.deleteDirectory(expandPath);
switch (ver.type) {
case HDP:
case CDP:
LOG.info("downloading: {}", ver);
File f = downloadArtifact(getCandidateUrls(ver));
File expandPath = new File(baseDir, targetPath.getName() + ".tmp");
FileUtils.deleteDirectory(expandPath);
File targetTgz = new File(expandPath, "/share/tez.tar.gz");
FileUtils.forceMkdir(targetTgz.getParentFile());
FileUtils.copyFile(f, targetTgz);
expandPath.renameTo(targetPath);
return;
default:
expand1DirReleaseArtifact(targetPath, downloadArtifact(getCandidateUrls(ver)));
expand1DirReleaseArtifact(expandPath, downloadArtifact(getCandidateUrls(ver)));

}
expandPath.renameTo(targetPath);
}

@Override
Expand Down

0 comments on commit 1407c7c

Please sign in to comment.