Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UvA
CONF
Commits
98c7bd7a
Commit
98c7bd7a
authored
Mar 19, 2020
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added tests
parent
d790ac01
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
43 deletions
+89
-43
Converter.java
...rc/main/java/nl/uva/sne/drip/commons/utils/Converter.java
+28
-8
CloudStormService.java
...n/java/nl/uva/sne/drip/provisioner/CloudStormService.java
+3
-4
CloudStormServiceTest.java
...va/nl/uva/sne/drip/provisioner/CloudStormServiceTest.java
+58
-31
No files found.
commons/src/main/java/nl/uva/sne/drip/commons/utils/Converter.java
View file @
98c7bd7a
...
...
@@ -16,27 +16,20 @@
package
nl
.
uva
.
sne
.
drip
.
commons
.
utils
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.FileVisitResult
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.nio.file.SimpleFileVisitor
;
import
java.nio.file.attribute.BasicFileAttributes
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.ArrayList
;
import
java.util.Base64
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipFile
;
import
java.util.zip.ZipOutputStream
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
...
...
@@ -105,4 +98,31 @@ public class Converter {
return
new
String
(
encodedBytes
,
StandardCharsets
.
UTF_8
);
}
public
static
void
zipFolder
(
String
sourceDir
,
String
zipFile
)
throws
FileNotFoundException
,
IOException
{
FileOutputStream
fout
=
new
FileOutputStream
(
zipFile
);
try
(
ZipOutputStream
zout
=
new
ZipOutputStream
(
fout
))
{
File
fileSource
=
new
File
(
sourceDir
);
addDirectory
(
zout
,
fileSource
);
}
}
private
static
void
addDirectory
(
ZipOutputStream
zout
,
File
fileSource
)
throws
FileNotFoundException
,
IOException
{
File
[]
files
=
fileSource
.
listFiles
();
for
(
File
file
:
files
)
{
if
(
file
.
isDirectory
())
{
addDirectory
(
zout
,
file
);
continue
;
}
byte
[]
buffer
=
new
byte
[
1024
];
try
(
final
FileInputStream
fin
=
new
FileInputStream
(
file
))
{
zout
.
putNextEntry
(
new
ZipEntry
(
file
.
getName
()));
int
length
;
while
((
length
=
fin
.
read
(
buffer
))
>
0
)
{
zout
.
write
(
buffer
,
0
,
length
);
}
zout
.
closeEntry
();
}
}
}
}
provisioner/src/main/java/nl/uva/sne/drip/provisioner/CloudStormService.java
View file @
98c7bd7a
...
...
@@ -453,17 +453,16 @@ class CloudStormService {
}
Map
<
String
,
String
>
provisionedFiles
=
new
HashMap
<>();
provisionedFiles
.
put
(
"type"
,
ENCODED_FILE_DATATYPE
);
Path
zipPath
=
Paths
.
get
(
tempInputDirPath
+
TOPOLOGY_RELATIVE_PATH
+
File
.
separator
+
TOPOLOGY_FOLDER_NAME
+
".zip"
);
Path
sourceFolderPath
=
Paths
.
get
(
tempInputDirPath
+
TOPOLOGY_RELATIVE_PATH
)
;
String
zipPath
=
(
tempInputDirPath
+
File
.
separator
+
TOPOLOGY_FOLDER_NAME
+
".zip"
);
String
sourceFolderPath
=
tempInputDirPath
+
TOPOLOGY_RELATIVE_PATH
;
Converter
.
zipFolder
(
sourceFolderPath
,
zipPath
);
String
cloudStormZipFileContentsAsBase64
=
Converter
.
encodeFileToBase64Binary
(
zipPath
.
toFile
().
getAbsolutePath
()
);
String
cloudStormZipFileContentsAsBase64
=
Converter
.
encodeFileToBase64Binary
(
zipPath
);
provisionedFiles
.
put
(
"file_contents"
,
cloudStormZipFileContentsAsBase64
);
provisionedFiles
.
put
(
"encoding"
,
"base64"
);
provisionedFiles
.
put
(
"file_ext"
,
"zip"
);
artifacts
.
put
(
"provisioned_files"
,
provisionedFiles
);
vmTopologyMap
.
getNodeTemplate
().
setArtifacts
(
artifacts
);
return
vmTopologyMap
;
}
...
...
provisioner/src/test/java/nl/uva/sne/drip/provisioner/CloudStormServiceTest.java
View file @
98c7bd7a
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment