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
67a1a59c
Commit
67a1a59c
authored
Feb 15, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added to parent project
Casted objects to strings
parent
cdf3304f
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
123 additions
and
120 deletions
+123
-120
.gitignore
.gitignore
+2
-1
pom.xml
drip-provisioner/pom.xml
+1
-1
Consumer.java
.../main/java/nl/uva/sne/drip/drip/provisioner/Consumer.java
+114
-113
pom.xml
pom.xml
+6
-5
No files found.
.gitignore
View file @
67a1a59c
...
...
@@ -3,3 +3,4 @@
/drip-planner/target/
/drip-commons/nbproject/
/drip-simple_planner/target/
/drip-provisioner/target/
\ No newline at end of file
drip-provisioner/pom.xml
View file @
67a1a59c
...
...
@@ -6,7 +6,7 @@
<artifactId>
drip
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<artifactId>
drip-
simple_
provisioner
</artifactId>
<artifactId>
drip-provisioner
</artifactId>
<packaging>
jar
</packaging>
<properties>
<maven.compiler.source>
1.8
</maven.compiler.source>
...
...
drip-provisioner/src/main/java/nl/uva/sne/drip/drip/provisioner/Consumer.java
View file @
67a1a59c
...
...
@@ -13,19 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
nl
.
uva
.
sne
.
drip
.
drip
.
p
lan
ner
;
package
nl
.
uva
.
sne
.
drip
.
drip
.
p
rovisio
ner
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.rabbitmq.client.AMQP
;
import
com.rabbitmq.client.Channel
;
import
com.rabbitmq.client.DefaultConsumer
;
import
com.rabbitmq.client.Envelope
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileReader
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.io.UnsupportedEncodingException
;
import
java.io.InputStreamReader
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
...
...
@@ -35,7 +35,6 @@ import java.util.Map;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
nl.uva.sne.drip.commons.types.Parameter
;
import
nl.uva.sne.drip.commons.types.Message
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
...
...
@@ -50,10 +49,10 @@ import org.json.JSONObject;
public
class
Consumer
extends
DefaultConsumer
{
private
final
Channel
channel
;
private
final
Planner
panner
;
private
final
String
jarFilePath
=
"/root/SWITCH/bin/ProvisioningCore.jar"
;
public
class
topologyElement
{
public
class
topologyElement
{
String
topologyName
=
""
;
String
outputFilePath
=
""
;
}
...
...
@@ -61,7 +60,6 @@ public class Consumer extends DefaultConsumer {
public
Consumer
(
Channel
channel
)
{
super
(
channel
);
this
.
channel
=
channel
;
this
.
panner
=
new
Planner
();
}
@Override
...
...
@@ -84,7 +82,7 @@ public class Consumer extends DefaultConsumer {
throw
new
FileNotFoundException
(
"Could not create input directory: "
+
tempInputDir
.
getAbsolutePath
());
}
ArrayList
topologyInfoArray
=
null
;
ArrayList
topologyInfoArray
;
topologyInfoArray
=
invokeProvisioner
(
message
,
tempInputDirPath
);
response
=
generateResponse
(
topologyInfoArray
);
...
...
@@ -102,7 +100,7 @@ public class Consumer extends DefaultConsumer {
////If the provisioner jar file is successfully invoked, the returned value should be a set of output file paths which are expected.
////If there are some errors or some information missing with this message, the returned value will be null.
////The input dir path contains '/'
private
ArrayList
<
topologyElement
>
invokeProvisioner
(
String
message
,
String
tempInputDirPath
)
throws
IOException
{
private
ArrayList
<
topologyElement
>
invokeProvisioner
(
String
message
,
String
tempInputDirPath
)
throws
IOException
,
JSONException
{
//Use the Jackson API to convert json to Object
JSONObject
jo
=
new
JSONObject
(
message
);
JSONArray
parameters
=
jo
.
getJSONArray
(
"parameters"
);
...
...
@@ -112,58 +110,61 @@ public class Consumer extends DefaultConsumer {
File
geniConfFile
=
null
;
//loop through the parameters in a message to find the input files
String
logDir
=
"null"
,
mainTopologyPath
=
"null"
,
sshKeyFilePath
=
"null"
,
scriptPath
=
"null"
;
ArrayList
<
topologyElement
>
topologyInfoArray
=
new
ArrayList
<
topologyElement
>
();
ArrayList
<
topologyElement
>
topologyInfoArray
=
new
ArrayList
();
for
(
int
i
=
0
;
i
<
parameters
.
length
();
i
++)
{
JSONObject
param
=
(
JSONObject
)
parameters
.
get
(
i
);
String
name
=
(
String
)
param
.
get
(
Parameter
.
NAME
);
if
(
name
.
equals
(
"ec2.conf"
))
{
try
{
ec2ConfFile
=
new
File
(
tempInputDirPath
+
"ec2.Conf"
);
if
(
ec2ConfFile
.
createNewFile
()){
ec2ConfFile
=
new
File
(
tempInputDirPath
+
"ec2.Conf"
);
if
(
ec2ConfFile
.
createNewFile
())
{
PrintWriter
out
=
new
PrintWriter
(
ec2ConfFile
);
out
.
print
(
param
.
get
(
Parameter
.
VALUE
));
}
else
}
else
{
return
null
;
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
(
);
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
e
);
return
null
;
}
}
else
if
(
name
.
equals
(
"geni.conf"
))
{
}
else
if
(
name
.
equals
(
"geni.conf"
))
{
try
{
geniConfFile
=
new
File
(
tempInputDirPath
+
"geni.Conf"
);
if
(
geniConfFile
.
createNewFile
()){
geniConfFile
=
new
File
(
tempInputDirPath
+
"geni.Conf"
);
if
(
geniConfFile
.
createNewFile
())
{
PrintWriter
out
=
new
PrintWriter
(
geniConfFile
);
out
.
print
(
param
.
get
(
Parameter
.
VALUE
));
}
else
}
else
{
return
null
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
return
null
;
}
}
else
if
(
name
.
equals
(
"topology"
))
{
}
else
if
(
name
.
equals
(
"topology"
))
{
JSONObject
attribute_level
=
param
.
getJSONObject
(
"attributes"
);
int
fileLevel
=
Integer
.
valueOf
(
attribute_level
.
get
(
"level"
));
if
(
fileLevel
==
0
)
/////if the file level is 0, it means that this is the top level description
int
fileLevel
=
Integer
.
valueOf
(
(
String
)
attribute_level
.
get
(
"level"
));
if
(
fileLevel
==
0
)
/////if the file level is 0, it means that this is the top level description
{
try
{
File
topologyFile
=
new
File
(
tempInputDirPath
+
"topology_main"
);
if
(
topologyFile
.
createNewFile
()){
File
topologyFile
=
new
File
(
tempInputDirPath
+
"topology_main"
);
if
(
topologyFile
.
createNewFile
())
{
PrintWriter
out
=
new
PrintWriter
(
geniConfFile
);
out
.
print
(
param
.
get
(
Parameter
.
VALUE
));
mainTopologyPath
=
topologyFile
.
getAbsolutePath
();
}
else
}
else
{
return
null
;
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
(
);
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
e
);
return
null
;
}
}
else
if
(
fileLevel
==
1
)
{
////this means that this file is the low level detailed description
String
fileName
=
attribute_level
.
get
(
"filename"
);
////This file name does not contain suffix of '.yml' for example
}
else
if
(
fileLevel
==
1
)
{
////this means that this file is the low level detailed description
String
fileName
=
(
String
)
attribute_level
.
get
(
"filename"
);
////This file name does not contain suffix of '.yml' for example
try
{
File
topologyFile
=
new
File
(
tempInputDirPath
+
fileName
+
".yml"
);
String
outputFilePath
=
tempInputDirPath
+
fileName
+
"_provisioned.yml"
;
if
(
topologyFile
.
createNewFile
()){
File
topologyFile
=
new
File
(
tempInputDirPath
+
fileName
+
".yml"
);
String
outputFilePath
=
tempInputDirPath
+
fileName
+
"_provisioned.yml"
;
if
(
topologyFile
.
createNewFile
())
{
PrintWriter
out
=
new
PrintWriter
(
geniConfFile
);
out
.
print
(
param
.
get
(
Parameter
.
VALUE
));
topologyElement
x
=
new
topologyElement
();
...
...
@@ -171,92 +172,97 @@ public class Consumer extends DefaultConsumer {
x
.
outputFilePath
=
outputFilePath
;
topologyInfoArray
.
add
(
x
);
}
else
}
else
{
return
null
;
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
(
);
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
e
);
return
null
;
}
}
}
else
if
(
name
.
equals
(
"logdir"
)){
logDir
=
param
.
get
(
Parameter
.
VALUE
);
}
else
if
(
name
.
equals
(
"sshkey"
)){
sshKeyFilePath
=
param
.
get
(
Parameter
.
VALUE
);
}
else
if
(
name
.
equals
(
"guiscript"
)){
scriptPath
=
param
.
get
(
Parameter
.
VALUE
);
}
else
{
}
else
if
(
name
.
equals
(
"logdir"
))
{
logDir
=
(
String
)
param
.
get
(
Parameter
.
VALUE
);
}
else
if
(
name
.
equals
(
"sshkey"
))
{
sshKeyFilePath
=
(
String
)
param
.
get
(
Parameter
.
VALUE
);
}
else
if
(
name
.
equals
(
"guiscript"
))
{
scriptPath
=
(
String
)
param
.
get
(
Parameter
.
VALUE
);
}
else
{
return
null
;
}
}
File
curDir
=
new
File
(
tempInputDirPath
);
String
[]
ls
=
curDir
.
list
();
for
(
int
i
=
0
;
i
<
ls
.
length
;
i
++)
{
if
(
ls
[
i
].
contains
(
"."
))
{
String
[]
fileTypes
=
ls
[
i
].
split
(
"\\."
);
if
(
fileTypes
.
length
>
0
)
{
int
lastIndex
=
fileTypes
.
length
-
1
;
for
(
int
i
=
0
;
i
<
ls
.
length
;
i
++)
{
if
(
ls
[
i
].
contains
(
"."
))
{
String
[]
fileTypes
=
ls
[
i
].
split
(
"\\."
);
if
(
fileTypes
.
length
>
0
)
{
int
lastIndex
=
fileTypes
.
length
-
1
;
String
fileType
=
fileTypes
[
lastIndex
];
if
(
fileType
.
equals
(
"yml"
))
{
String
toscaFile
=
curDir
+
ls
[
i
];
if
(!
sshKeyFilePath
.
equals
(
"null"
))
if
(
fileType
.
equals
(
"yml"
))
{
String
toscaFile
=
curDir
+
ls
[
i
];
if
(!
sshKeyFilePath
.
equals
(
"null"
))
{
changeKeyFilePath
(
toscaFile
,
sshKeyFilePath
);
}
if
(!
scriptPath
.
equals
(
"null"
))
if
(!
scriptPath
.
equals
(
"null"
))
{
changeGUIScriptFilePath
(
toscaFile
,
scriptPath
);
}
}
}
}
}
if
(
ec2ConfFile
==
null
&&
geniConfFile
==
null
)
if
(
ec2ConfFile
==
null
&&
geniConfFile
==
null
)
{
return
null
;
if
(
mainTopologyPath
.
equals
(
"null"
))
}
if
(
mainTopologyPath
.
equals
(
"null"
))
{
return
null
;
}
String
ec2ConfFilePath
=
"null"
;
String
geniConfFilePath
=
"null"
;
if
(
ec2ConfFile
!=
null
)
if
(
ec2ConfFile
!=
null
)
{
ec2ConfFilePath
=
ec2ConfFile
.
getAbsolutePath
();
if
(
geniConfFile
!=
null
)
}
if
(
geniConfFile
!=
null
)
{
geniConfFilePath
=
geniConfFile
.
getAbsolutePath
();
if
(
logDir
.
equals
(
"null"
))
}
if
(
logDir
.
equals
(
"null"
))
{
logDir
=
"/tmp/"
;
}
String
cmd
=
"java -jar "
+
jarFilePath
+
" ec2="
+
ec2ConfFilePath
+
" exogeni="
+
geniConfFilePath
+
" logDir="
+
logDir
+
" topology="
+
mainTopologyPath
;
String
cmd
=
"java -jar "
+
jarFilePath
+
" ec2="
+
ec2ConfFilePath
+
" exogeni="
+
geniConfFilePath
+
" logDir="
+
logDir
+
" topology="
+
mainTopologyPath
;
try
{
Process
p
=
Runtime
.
getRuntime
().
exec
(
cmd
);
p
.
waitFor
();
}
catch
(
IOException
|
InterruptedException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
(
);
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
e
);
}
topologyElement
x
=
new
topologyElement
();
x
.
topologyName
=
"kubernetes"
;
x
.
outputFilePath
=
tempInputDirPath
+
"file_kubernetes"
;
topologyInfoArray
.
add
();
x
.
outputFilePath
=
tempInputDirPath
+
"file_kubernetes"
;
topologyInfoArray
.
add
(
x
);
return
topologyInfoArray
;
}
////Change the key file path in the tosca file.
////Because the user needs to upload their public key file into the server file system.
private
void
changeKeyFilePath
(
String
toscaFilePath
,
String
newKeyFilePath
){
private
void
changeKeyFilePath
(
String
toscaFilePath
,
String
newKeyFilePath
)
{
File
toscaFile
=
new
File
(
toscaFilePath
);
String
fileContent
=
""
;
try
{
BufferedReader
in
=
new
BufferedReader
(
new
FileReader
(
toscaFile
));
String
line
=
""
;
while
((
line
=
in
.
readLine
())
!=
null
){
if
(
line
.
contains
(
"publicKeyPath"
))
fileContent
+=
(
"publicKeyPath: "
+
newKeyFilePath
+
"\n"
);
else
fileContent
+=
(
line
+
"\n"
);
while
((
line
=
in
.
readLine
())
!=
null
)
{
if
(
line
.
contains
(
"publicKeyPath"
))
{
fileContent
+=
(
"publicKeyPath: "
+
newKeyFilePath
+
"\n"
);
}
else
{
fileContent
+=
(
line
+
"\n"
);
}
}
in
.
close
();
...
...
@@ -265,29 +271,27 @@ public class Consumer extends DefaultConsumer {
fw
.
close
();
}
catch
(
FileNotFoundException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
(
);
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
e
);
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
(
);
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
e
);
}
}
private
void
changeGUIScriptFilePath
(
String
toscaFilePath
,
String
newScriptPath
){
private
void
changeGUIScriptFilePath
(
String
toscaFilePath
,
String
newScriptPath
)
{
File
toscaFile
=
new
File
(
toscaFilePath
);
String
fileContent
=
""
;
try
{
BufferedReader
in
=
new
BufferedReader
(
new
FileReader
(
toscaFile
));
String
line
=
""
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
if
(
line
.
contains
(
"script"
))
{
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
if
(
line
.
contains
(
"script"
))
{
int
index
=
line
.
indexOf
(
"script:"
);
String
prefix
=
line
.
substring
(
0
,
index
+
7
);
fileContent
+=
(
prefix
+
" "
+
newScriptPath
+
"\n"
);
String
prefix
=
line
.
substring
(
0
,
index
+
7
);
fileContent
+=
(
prefix
+
" "
+
newScriptPath
+
"\n"
);
}
else
{
fileContent
+=
(
line
+
"\n"
);
}
else
fileContent
+=
(
line
+
"\n"
);
}
in
.
close
();
...
...
@@ -296,40 +300,39 @@ public class Consumer extends DefaultConsumer {
fw
.
close
();
}
catch
(
FileNotFoundException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
(
);
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
e
);
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
(
);
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
e
);
}
}
private
String
generateResponse
(
ArrayList
<
topologyElement
>
outputs
)
throws
JSONException
,
IOException
{
//Use the JSONObject API to convert Object (Message) to json
JSONObject
jo
=
new
JSONObject
();
jo
.
put
(
"creationDate"
,
(
System
.
currentTimeMillis
()));
List
parameters
=
new
ArrayList
();
String
charset
=
"UTF-8"
;
if
(
outputs
==
null
)
{
if
(
outputs
==
null
)
{
Map
<
String
,
String
>
fileArguments
=
new
HashMap
<>();
fileArguments
.
put
(
"encoding"
,
charset
);
fileArguments
.
put
(
"name"
,
"ERROR"
);
fileArguments
.
put
(
"value"
,
"Some error with input messages!"
);
parameters
.
add
(
fileArguments
);
}
else
{
for
(
int
i
=
0
;
i
<
outputs
.
size
()
;
i
++)
{
}
else
{
for
(
int
i
=
0
;
i
<
outputs
.
size
();
i
++)
{
Map
<
String
,
String
>
fileArguments
=
new
HashMap
<>();
fileArguments
.
put
(
"encoding"
,
charset
);
File
f
=
new
File
(
outputs
.
get
(
i
).
outputFilePath
);
if
(
f
.
exists
())
{
if
(
f
.
exists
())
{
fileArguments
.
put
(
"name"
,
outputs
.
get
(
i
).
topologyName
);
byte
[]
bytes
=
Files
.
readAllBytes
(
Paths
.
get
(
f
.
getAbsolutePath
()));
fileArguments
.
put
(
"value"
,
new
String
(
bytes
,
charset
));
parameters
.
add
(
fileArguments
);
}
else
{
}
else
{
fileArguments
.
put
(
"name"
,
outputs
.
get
(
i
).
topologyName
);
fileArguments
.
put
(
"value"
,
"ERROR::There is no output for topology "
+
outputs
.
get
(
i
).
topologyName
);
fileArguments
.
put
(
"value"
,
"ERROR::There is no output for topology "
+
outputs
.
get
(
i
).
topologyName
);
parameters
.
add
(
fileArguments
);
}
...
...
@@ -339,6 +342,4 @@ public class Consumer extends DefaultConsumer {
return
jo
.
toString
();
}
}
pom.xml
View file @
67a1a59c
...
...
@@ -12,5 +12,6 @@
<module>
drip-api
</module>
<module>
drip-commons
</module>
<module>
drip-simple_planner
</module>
<module>
drip-provisioner
</module>
</modules>
</project>
\ No newline at end of file
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