Skip to content

Commit

Permalink
fix pkg location init (apache#1927)
Browse files Browse the repository at this point in the history
* fix pkg location init

* test download-dir with permission
  • Loading branch information
rdhabalia authored Jun 7, 2018
1 parent 57f463d commit e5256f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ protected void startFunction(FunctionRuntimeInfo functionRuntimeInfo) throws Exc
if(isPkgUrlProvided && pkgLocation.startsWith(Utils.FILE)) {
pkgFile = new File(pkgLocation);
} else {
File pkgDir = new File(
workerConfig.getDownloadDirectory(),
getDownloadPackagePath(functionMetaData, instanceId));
pkgDir.mkdirs();

pkgFile = new File(
pkgDir,
new File(FunctionDetailsUtils.getDownloadFileName(functionMetaData.getFunctionDetails())).getName());
downloadFile(pkgFile, isPkgUrlProvided, functionMetaData, instanceId);
}

Expand All @@ -138,15 +146,8 @@ protected void startFunction(FunctionRuntimeInfo functionRuntimeInfo) throws Exc

private void downloadFile(File pkgFile, boolean isPkgUrlProvided, FunctionMetaData functionMetaData, int instanceId) throws FileNotFoundException, IOException {

File pkgDir = new File(
workerConfig.getDownloadDirectory(),
getDownloadPackagePath(functionMetaData, instanceId));
pkgDir.mkdirs();

pkgFile = new File(
pkgDir,
new File(FunctionDetailsUtils.getDownloadFileName(functionMetaData.getFunctionDetails())).getName());

File pkgDir = pkgFile.getParentFile();

if (pkgFile.exists()) {
log.warn("Function package exists already {} deleting it",
pkgFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public void testStartFunctionWithPkgUrl() throws Exception {
workerConfig.setPulsarServiceUrl("pulsar://localhost:6650");
workerConfig.setStateStorageServiceUrl("foo");
workerConfig.setFunctionAssignmentTopicName("assignments");
String downloadDir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
workerConfig.setDownloadDirectory(downloadDir);

RuntimeFactory factory = mock(RuntimeFactory.class);
Runtime runtime = mock(Runtime.class);
Expand Down

0 comments on commit e5256f1

Please sign in to comment.