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
201f5ade
Commit
201f5ade
authored
Apr 25, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement caller for new provisioner
parent
1035ba0c
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
363 additions
and
57 deletions
+363
-57
pom.xml
drip-provisioner/pom.xml
+7
-0
.DS_Store
.../src/main/java/nl/uva/sne/drip/drip/provisioner/.DS_Store
+0
-0
RPCServer.java
...main/java/nl/uva/sne/drip/drip/provisioner/RPCServer.java
+11
-3
MessageParsing.java
...l/uva/sne/drip/drip/provisioner/utils/MessageParsing.java
+74
-0
Consumer.java
...in/java/nl/uva/sne/drip/drip/provisioner/v0/Consumer.java
+8
-54
Consumer.java
...in/java/nl/uva/sne/drip/drip/provisioner/v1/Consumer.java
+262
-0
provisioner.properies
drip-provisioner/src/main/resources/provisioner.properies
+1
-0
No files found.
drip-provisioner/pom.xml
View file @
201f5ade
...
@@ -21,6 +21,13 @@
...
@@ -21,6 +21,13 @@
<version>
1.0-SNAPSHOT
</version>
<version>
1.0-SNAPSHOT
</version>
</dependency>
</dependency>
<dependency>
<groupId>
nl.uva.sne.drip
</groupId>
<artifactId>
drip-provisioning-agent
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<dependency>
<dependency>
<groupId>
com.rabbitmq
</groupId>
<groupId>
com.rabbitmq
</groupId>
...
...
drip-provisioner/src/main/java/nl/uva/sne/drip/drip/provisioner/.DS_Store
deleted
100644 → 0
View file @
1035ba0c
File deleted
drip-provisioner/src/main/java/nl/uva/sne/drip/drip/provisioner/RPCServer.java
View file @
201f5ade
...
@@ -19,6 +19,7 @@ import com.rabbitmq.client.AMQP;
...
@@ -19,6 +19,7 @@ import com.rabbitmq.client.AMQP;
import
com.rabbitmq.client.Channel
;
import
com.rabbitmq.client.Channel
;
import
com.rabbitmq.client.Connection
;
import
com.rabbitmq.client.Connection
;
import
com.rabbitmq.client.ConnectionFactory
;
import
com.rabbitmq.client.ConnectionFactory
;
import
com.rabbitmq.client.DefaultConsumer
;
import
java.io.FileInputStream
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
...
@@ -34,7 +35,7 @@ import java.util.logging.Logger;
...
@@ -34,7 +35,7 @@ import java.util.logging.Logger;
*/
*/
public
class
RPCServer
{
public
class
RPCServer
{
private
static
final
String
RPC_QUEUE_NAME
=
"provisioner_queue
"
;
private
static
String
RPC_QUEUE_NAME
=
"provisioner_queue_v1
"
;
private
static
String
HOST
=
"127.0.0.1"
;
private
static
String
HOST
=
"127.0.0.1"
;
public
static
void
main
(
String
[]
argv
)
{
public
static
void
main
(
String
[]
argv
)
{
...
@@ -55,7 +56,9 @@ public class RPCServer {
...
@@ -55,7 +56,9 @@ public class RPCServer {
}
}
}
}
HOST
=
prop
.
getProperty
(
"rabbitmq.host"
,
"127.0.0.1"
);
HOST
=
prop
.
getProperty
(
"rabbitmq.host"
,
"127.0.0.1"
);
RPC_QUEUE_NAME
=
prop
.
getProperty
(
"rpc.queue.name"
,
"provisioner_queue_v1"
);
Logger
.
getLogger
(
RPCServer
.
class
.
getName
()).
log
(
Level
.
INFO
,
MessageFormat
.
format
(
"rabbitmq.host: {0}"
,
HOST
));
Logger
.
getLogger
(
RPCServer
.
class
.
getName
()).
log
(
Level
.
INFO
,
MessageFormat
.
format
(
"rabbitmq.host: {0}"
,
HOST
));
Logger
.
getLogger
(
RPCServer
.
class
.
getName
()).
log
(
Level
.
INFO
,
MessageFormat
.
format
(
"rpc.queue.name: {0}"
,
RPC_QUEUE_NAME
));
start
();
start
();
}
}
...
@@ -70,8 +73,13 @@ public class RPCServer {
...
@@ -70,8 +73,13 @@ public class RPCServer {
Channel
channel
=
connection
.
createChannel
();
Channel
channel
=
connection
.
createChannel
();
//We define the queue name
//We define the queue name
channel
.
queueDeclare
(
RPC_QUEUE_NAME
,
false
,
false
,
false
,
null
);
channel
.
queueDeclare
(
RPC_QUEUE_NAME
,
false
,
false
,
false
,
null
);
//Set our own customized consummer
DefaultConsumer
c
;
Consumer
c
=
new
Consumer
(
channel
);
if
(
RPC_QUEUE_NAME
.
endsWith
(
"v0"
))
{
c
=
new
nl
.
uva
.
sne
.
drip
.
drip
.
provisioner
.
v0
.
Consumer
(
channel
);
}
else
{
c
=
new
nl
.
uva
.
sne
.
drip
.
drip
.
provisioner
.
v1
.
Consumer
(
channel
);
}
//Start listening for messages
//Start listening for messages
channel
.
basicConsume
(
RPC_QUEUE_NAME
,
false
,
c
);
channel
.
basicConsume
(
RPC_QUEUE_NAME
,
false
,
c
);
...
...
drip-provisioner/src/main/java/nl/uva/sne/drip/drip/provisioner/utils/MessageParsing.java
0 → 100644
View file @
201f5ade
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
nl
.
uva
.
sne
.
drip
.
drip
.
provisioner
.
utils
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
/**
*
* @author S. Koulouzis
*/
public
class
MessageParsing
{
public
static
File
getTopology
(
JSONArray
parameters
,
String
tempInputDirPath
,
int
level
)
throws
JSONException
,
IOException
{
for
(
int
i
=
0
;
i
<
parameters
.
length
();
i
++)
{
JSONObject
param
=
(
JSONObject
)
parameters
.
get
(
i
);
String
name
=
(
String
)
param
.
get
(
"name"
);
if
(
name
.
equals
(
"topology"
))
{
JSONObject
attributes
=
param
.
getJSONObject
(
"attributes"
);
int
fileLevel
=
Integer
.
valueOf
((
String
)
attributes
.
get
(
"level"
));
if
(
fileLevel
==
level
)
{
String
originalFilename
=
(
String
)
attributes
.
get
(
"filename"
);
String
fileName
=
""
;
// String[] parts = originalFilename.split("_");
// String prefix = "";
// //Clear date part form file name
// if (isNumeric(parts[0])) {
// for (int j = 1; j < parts.length; j++) {
// fileName += prefix + parts[j];
// prefix = "_";
// }
// } else {
fileName
=
originalFilename
;
// }
File
topologyFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
fileName
);
topologyFile
.
createNewFile
();
String
val
=
(
String
)
param
.
get
(
"value"
);
writeValueToFile
(
val
,
topologyFile
);
return
topologyFile
;
}
}
}
return
null
;
}
public
static
void
writeValueToFile
(
String
value
,
File
file
)
throws
FileNotFoundException
{
try
(
PrintWriter
out
=
new
PrintWriter
(
file
))
{
out
.
print
(
value
);
}
if
(!
file
.
exists
()
||
file
.
length
()
<
value
.
getBytes
().
length
)
{
throw
new
FileNotFoundException
(
"File "
+
file
.
getAbsolutePath
()
+
" doesn't exist or contents are missing "
);
}
}
}
drip-provisioner/src/main/java/nl/uva/sne/drip/drip/provisioner/Consumer.java
→
drip-provisioner/src/main/java/nl/uva/sne/drip/drip/provisioner/
v0/
Consumer.java
View file @
201f5ade
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
*/
*/
package
nl
.
uva
.
sne
.
drip
.
drip
.
provisioner
;
package
nl
.
uva
.
sne
.
drip
.
drip
.
provisioner
.
v0
;
import
com.rabbitmq.client.AMQP
;
import
com.rabbitmq.client.AMQP
;
import
com.rabbitmq.client.Channel
;
import
com.rabbitmq.client.Channel
;
...
@@ -27,7 +27,6 @@ import java.io.FileOutputStream;
...
@@ -27,7 +27,6 @@ import java.io.FileOutputStream;
import
java.io.FileReader
;
import
java.io.FileReader
;
import
java.io.FileWriter
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.nio.file.Files
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.nio.file.Paths
;
import
java.nio.file.attribute.PosixFilePermission
;
import
java.nio.file.attribute.PosixFilePermission
;
...
@@ -40,6 +39,7 @@ import java.util.Properties;
...
@@ -40,6 +39,7 @@ import java.util.Properties;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.logging.Level
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
java.util.logging.Logger
;
import
nl.uva.sne.drip.drip.provisioner.utils.MessageParsing
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.io.FilenameUtils
;
import
org.apache.commons.io.FilenameUtils
;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
...
@@ -161,12 +161,12 @@ public class Consumer extends DefaultConsumer {
...
@@ -161,12 +161,12 @@ public class Consumer extends DefaultConsumer {
geniConfFile
=
cloudConfFile
;
geniConfFile
=
cloudConfFile
;
}
}
File
topologyFile
=
getTopology
(
parameters
,
tempInputDirPath
,
0
);
File
topologyFile
=
MessageParsing
.
getTopology
(
parameters
,
tempInputDirPath
,
0
);
File
mainTopologyFile
=
new
File
(
tempInputDirPath
+
"topology_main"
);
File
mainTopologyFile
=
new
File
(
tempInputDirPath
+
"topology_main"
);
FileUtils
.
moveFile
(
topologyFile
,
mainTopologyFile
);
FileUtils
.
moveFile
(
topologyFile
,
mainTopologyFile
);
mainTopologyPath
=
mainTopologyFile
.
getAbsolutePath
();
mainTopologyPath
=
mainTopologyFile
.
getAbsolutePath
();
topologyFile
=
getTopology
(
parameters
,
tempInputDirPath
,
1
);
topologyFile
=
MessageParsing
.
getTopology
(
parameters
,
tempInputDirPath
,
1
);
File
secondaryTopologyFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
topologyFile
.
getName
()
+
".yml"
);
File
secondaryTopologyFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
topologyFile
.
getName
()
+
".yml"
);
String
outputFilePath
=
tempInputDirPath
+
File
.
separator
+
topologyFile
.
getName
()
+
"_provisioned.yml"
;
String
outputFilePath
=
tempInputDirPath
+
File
.
separator
+
topologyFile
.
getName
()
+
"_provisioned.yml"
;
TopologyElement
x
=
new
TopologyElement
();
TopologyElement
x
=
new
TopologyElement
();
...
@@ -365,15 +365,6 @@ public class Consumer extends DefaultConsumer {
...
@@ -365,15 +365,6 @@ public class Consumer extends DefaultConsumer {
return
jo
.
toString
();
return
jo
.
toString
();
}
}
private
void
writeValueToFile
(
String
value
,
File
file
)
throws
FileNotFoundException
{
try
(
PrintWriter
out
=
new
PrintWriter
(
file
))
{
out
.
print
(
value
);
}
if
(!
file
.
exists
()
||
file
.
length
()
<
value
.
getBytes
().
length
)
{
throw
new
FileNotFoundException
(
"File "
+
file
.
getAbsolutePath
()
+
" doesn't exist or contents are missing "
);
}
}
private
File
getCloudConfigurationFile
(
JSONArray
parameters
,
String
tempInputDirPath
)
throws
JSONException
{
private
File
getCloudConfigurationFile
(
JSONArray
parameters
,
String
tempInputDirPath
)
throws
JSONException
{
for
(
int
i
=
0
;
i
<
parameters
.
length
();
i
++)
{
for
(
int
i
=
0
;
i
<
parameters
.
length
();
i
++)
{
JSONObject
param
=
(
JSONObject
)
parameters
.
get
(
i
);
JSONObject
param
=
(
JSONObject
)
parameters
.
get
(
i
);
...
@@ -382,7 +373,7 @@ public class Consumer extends DefaultConsumer {
...
@@ -382,7 +373,7 @@ public class Consumer extends DefaultConsumer {
try
{
try
{
File
confFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
name
);
File
confFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
name
);
if
(
confFile
.
createNewFile
())
{
if
(
confFile
.
createNewFile
())
{
writeValueToFile
((
String
)
param
.
get
(
"value"
),
confFile
);
MessageParsing
.
writeValueToFile
((
String
)
param
.
get
(
"value"
),
confFile
);
return
confFile
;
return
confFile
;
}
else
{
}
else
{
return
null
;
return
null
;
...
@@ -396,39 +387,6 @@ public class Consumer extends DefaultConsumer {
...
@@ -396,39 +387,6 @@ public class Consumer extends DefaultConsumer {
return
null
;
return
null
;
}
}
private
File
getTopology
(
JSONArray
parameters
,
String
tempInputDirPath
,
int
level
)
throws
JSONException
,
IOException
{
for
(
int
i
=
0
;
i
<
parameters
.
length
();
i
++)
{
JSONObject
param
=
(
JSONObject
)
parameters
.
get
(
i
);
String
name
=
(
String
)
param
.
get
(
"name"
);
if
(
name
.
equals
(
"topology"
))
{
JSONObject
attributes
=
param
.
getJSONObject
(
"attributes"
);
int
fileLevel
=
Integer
.
valueOf
((
String
)
attributes
.
get
(
"level"
));
if
(
fileLevel
==
level
)
{
String
originalFilename
=
(
String
)
attributes
.
get
(
"filename"
);
String
fileName
=
""
;
// String[] parts = originalFilename.split("_");
// String prefix = "";
// //Clear date part form file name
// if (isNumeric(parts[0])) {
// for (int j = 1; j < parts.length; j++) {
// fileName += prefix + parts[j];
// prefix = "_";
// }
// } else {
fileName
=
originalFilename
;
// }
File
topologyFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
fileName
);
topologyFile
.
createNewFile
();
String
val
=
(
String
)
param
.
get
(
"value"
);
writeValueToFile
(
val
,
topologyFile
);
return
topologyFile
;
}
}
}
return
null
;
}
private
Map
<
String
,
File
>
getCertificates
(
JSONArray
parameters
,
String
tempInputDirPath
)
throws
JSONException
,
IOException
{
private
Map
<
String
,
File
>
getCertificates
(
JSONArray
parameters
,
String
tempInputDirPath
)
throws
JSONException
,
IOException
{
Map
<
String
,
File
>
files
=
new
HashMap
<>();
Map
<
String
,
File
>
files
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
parameters
.
length
();
i
++)
{
for
(
int
i
=
0
;
i
<
parameters
.
length
();
i
++)
{
...
@@ -439,7 +397,7 @@ public class Consumer extends DefaultConsumer {
...
@@ -439,7 +397,7 @@ public class Consumer extends DefaultConsumer {
String
fileName
=
(
String
)
attribute
.
get
(
"filename"
);
String
fileName
=
(
String
)
attribute
.
get
(
"filename"
);
File
certificate
=
new
File
(
tempInputDirPath
+
File
.
separator
+
fileName
+
".pem"
);
File
certificate
=
new
File
(
tempInputDirPath
+
File
.
separator
+
fileName
+
".pem"
);
if
(
certificate
.
createNewFile
())
{
if
(
certificate
.
createNewFile
())
{
writeValueToFile
((
String
)
param
.
get
(
"value"
),
certificate
);
MessageParsing
.
writeValueToFile
((
String
)
param
.
get
(
"value"
),
certificate
);
Set
<
PosixFilePermission
>
perms
=
new
HashSet
<>();
Set
<
PosixFilePermission
>
perms
=
new
HashSet
<>();
perms
.
add
(
PosixFilePermission
.
OWNER_READ
);
perms
.
add
(
PosixFilePermission
.
OWNER_READ
);
Files
.
setPosixFilePermissions
(
Paths
.
get
(
certificate
.
getAbsolutePath
()),
perms
);
Files
.
setPosixFilePermissions
(
Paths
.
get
(
certificate
.
getAbsolutePath
()),
perms
);
...
@@ -469,7 +427,7 @@ public class Consumer extends DefaultConsumer {
...
@@ -469,7 +427,7 @@ public class Consumer extends DefaultConsumer {
String
sshKeyContent
=
(
String
)
param
.
get
(
"value"
);
String
sshKeyContent
=
(
String
)
param
.
get
(
"value"
);
File
sshKeyFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
"user.pem"
);
File
sshKeyFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
"user.pem"
);
if
(
sshKeyFile
.
createNewFile
())
{
if
(
sshKeyFile
.
createNewFile
())
{
writeValueToFile
(
sshKeyContent
,
sshKeyFile
);
MessageParsing
.
writeValueToFile
(
sshKeyContent
,
sshKeyFile
);
return
sshKeyFile
;
return
sshKeyFile
;
}
}
}
}
...
@@ -485,7 +443,7 @@ public class Consumer extends DefaultConsumer {
...
@@ -485,7 +443,7 @@ public class Consumer extends DefaultConsumer {
String
scriptContent
=
(
String
)
param
.
get
(
"value"
);
String
scriptContent
=
(
String
)
param
.
get
(
"value"
);
File
scriptFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
"guiscipt.sh"
);
File
scriptFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
"guiscipt.sh"
);
if
(
scriptFile
.
createNewFile
())
{
if
(
scriptFile
.
createNewFile
())
{
writeValueToFile
(
scriptContent
,
scriptFile
);
MessageParsing
.
writeValueToFile
(
scriptContent
,
scriptFile
);
return
scriptFile
;
return
scriptFile
;
}
}
}
}
...
@@ -493,8 +451,4 @@ public class Consumer extends DefaultConsumer {
...
@@ -493,8 +451,4 @@ public class Consumer extends DefaultConsumer {
return
null
;
return
null
;
}
}
private
static
boolean
isNumeric
(
String
str
)
{
return
str
.
matches
(
"-?\\d+(\\.\\d+)?"
);
}
}
}
drip-provisioner/src/main/java/nl/uva/sne/drip/drip/provisioner/v1/Consumer.java
0 → 100644
View file @
201f5ade
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
nl
.
uva
.
sne
.
drip
.
drip
.
provisioner
.
v1
;
import
com.rabbitmq.client.AMQP
;
import
com.rabbitmq.client.Channel
;
import
com.rabbitmq.client.DefaultConsumer
;
import
com.rabbitmq.client.Envelope
;
import
commonTool.CommonTool
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
nl.uva.sne.drip.drip.provisioner.utils.MessageParsing
;
import
org.apache.commons.io.FileUtils
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
provisioning.credential.EC2Credential
;
import
provisioning.credential.EGICredential
;
import
provisioning.credential.SSHKeyPair
;
import
provisioning.credential.UserCredential
;
import
provisioning.database.EGI.EGIDatabase
;
import
provisioning.database.UserDatabase
;
import
provisioning.engine.TEngine.TEngine
;
import
topologyAnalysis.TopologyAnalysisMain
;
/**
*
* This is an example of a Message consumer
*
*
* @author H. Zhou, S. Koulouzis
*/
public
class
Consumer
extends
DefaultConsumer
{
private
final
Channel
channel
;
Map
<
String
,
String
>
em
=
new
HashMap
<>();
public
Consumer
(
Channel
channel
)
throws
IOException
{
super
(
channel
);
this
.
channel
=
channel
;
em
.
put
(
"Virginia"
,
"ec2.us-east-1.amazonaws.com"
);
em
.
put
(
"California"
,
"ec2.us-west-1.amazonaws.com"
);
em
.
put
(
"Oregon"
,
"ec2.us-west-2.amazonaws.com"
);
em
.
put
(
"Mumbai"
,
"ec2.ap-south-1.amazonaws.com"
);
em
.
put
(
"Singapore"
,
"ec2.ap-southeast-1.amazonaws.com"
);
em
.
put
(
"Seoul"
,
"ec2.ap-northeast-2.amazonaws.com"
);
em
.
put
(
"Sydney"
,
"ec2.ap-southeast-2.amazonaws.com"
);
em
.
put
(
"Tokyo"
,
"ec2.ap-northeast-1.amazonaws.com"
);
em
.
put
(
"Frankfurt"
,
"ec2.eu-central-1.amazonaws.com"
);
em
.
put
(
"Ireland"
,
"ec2.eu-west-1.amazonaws.com"
);
em
.
put
(
"Paulo"
,
"ec2.sa-east-1.amazonaws.com"
);
}
@Override
public
void
handleDelivery
(
String
consumerTag
,
Envelope
envelope
,
AMQP
.
BasicProperties
properties
,
byte
[]
body
)
throws
IOException
{
//Create the reply properties which tells us where to reply, and which id to use.
//No need to change anything here
AMQP
.
BasicProperties
replyProps
=
new
AMQP
.
BasicProperties
.
Builder
()
.
correlationId
(
properties
.
getCorrelationId
())
.
build
();
String
response
=
""
;
try
{
//The queue only moves bytes so we need to convert them to stting
String
message
=
new
String
(
body
,
"UTF-8"
);
String
tempInputDirPath
=
System
.
getProperty
(
"java.io.tmpdir"
)
+
File
.
separator
+
"Input-"
+
Long
.
toString
(
System
.
nanoTime
())
+
File
.
separator
;
File
tempInputDir
=
new
File
(
tempInputDirPath
);
if
(!(
tempInputDir
.
mkdirs
()))
{
throw
new
FileNotFoundException
(
"Could not create input directory: "
+
tempInputDir
.
getAbsolutePath
());
}
invokeProvisioner
(
message
,
tempInputDirPath
);
TopologyAnalysisMain
topLevelTopology
=
null
;
response
=
generateResponse
(
topLevelTopology
);
}
catch
(
Throwable
ex
)
{
try
{
response
=
generateExeptionResponse
(
ex
);
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
JSONException
ex1
)
{
response
=
"{\"creationDate\": "
+
System
.
currentTimeMillis
()
+
",\"parameters\": [{\"url\": null,\"encoding\": UTF-8,"
+
"\"value\": \""
+
ex
.
getMessage
()
+
"\",\"name\": \""
+
ex
.
getClass
().
getName
()
+
"\",\"attributes\": null}]}"
;
}
}
finally
{
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
INFO
,
"Sending Response: {0}"
,
response
);
//We send the response back. No need to change anything here
channel
.
basicPublish
(
""
,
properties
.
getReplyTo
(),
replyProps
,
response
.
getBytes
(
"UTF-8"
));
channel
.
basicAck
(
envelope
.
getDeliveryTag
(),
false
);
}
}
private
void
invokeProvisioner
(
String
message
,
String
tempInputDirPath
)
throws
IOException
,
JSONException
,
Exception
{
//Use the Jackson API to convert json to Object
JSONObject
jo
=
new
JSONObject
(
message
);
JSONArray
parameters
=
jo
.
getJSONArray
(
"parameters"
);
startTopology
(
parameters
,
tempInputDirPath
);
}
private
void
startTopology
(
JSONArray
parameters
,
String
tempInputDirPath
)
throws
Exception
{
String
topTopologyLoadingPath
=
"ES/EGI/zh_all_test.yml"
;
File
topologyFile
=
MessageParsing
.
getTopology
(
parameters
,
tempInputDirPath
,
0
);
File
mainTopologyFile
=
new
File
(
tempInputDirPath
+
"topology_main"
);
FileUtils
.
moveFile
(
topologyFile
,
mainTopologyFile
);
topTopologyLoadingPath
=
mainTopologyFile
.
getAbsolutePath
();
//load 2nd level in same folder
topologyFile
=
MessageParsing
.
getTopology
(
parameters
,
tempInputDirPath
,
1
);
File
secondaryTopologyFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
topologyFile
.
getName
()
+
".yml"
);
String
outputFilePath
=
tempInputDirPath
+
File
.
separator
+
topologyFile
.
getName
()
+
"_provisioned.yml"
;
FileUtils
.
moveFile
(
topologyFile
,
secondaryTopologyFile
);
System
.
exit
(-
1
);
String
currentDir
=
CommonTool
.
getPathDir
(
topTopologyLoadingPath
);
TopologyAnalysisMain
tam
=
new
TopologyAnalysisMain
(
topTopologyLoadingPath
);
if
(!
tam
.
fullLoadWholeTopology
())
{
throw
new
Exception
(
"sth wrong!"
);
}
////Initial credentials and ssh key pairs
UserCredential
userCredential
=
new
UserCredential
();
EC2Credential
ec2Credential
=
new
EC2Credential
();
ec2Credential
.
accessKey
=
"23332323wer"
;
ec2Credential
.
secretKey
=
"fdfsdffdfsdf"
;
EGICredential
egiCredential
=
new
EGICredential
();
egiCredential
.
proxyFilePath
=
"/tmp/x509up_u0"
;
egiCredential
.
trustedCertPath
=
"/etc/grid-security/certificates"
;
if
(
userCredential
.
cloudAccess
==
null
)
{
userCredential
.
cloudAccess
=
new
HashMap
<>();
}
userCredential
.
cloudAccess
.
put
(
"ec2"
,
ec2Credential
);
userCredential
.
cloudAccess
.
put
(
"egi"
,
egiCredential
);
ArrayList
<
SSHKeyPair
>
sshKeyPairs
=
userCredential
.
loadSSHKeyPairFromFile
(
currentDir
);
if
(
sshKeyPairs
==
null
)
{
throw
new
NullPointerException
(
"ssh key pairs are null"
);
}
if
(
sshKeyPairs
.
isEmpty
())
{
throw
new
IOException
(
"No ssh key pair is loaded!"
);
}
else
if
(!
userCredential
.
initial
(
sshKeyPairs
,
tam
.
wholeTopology
))
{
throw
new
IOException
(
"ssh key pair initilaziation error"
);
}
///Initial Database
UserDatabase
userDatabase
=
new
UserDatabase
();
EGIDatabase
egiDatabase
=
new
EGIDatabase
();
egiDatabase
.
loadDomainInfoFromFile
(
currentDir
+
"EGI_Domain_Info"
);
/*EC2Database ec2Database = new EC2Database();
ec2Database.loadDomainFromFile(currentDir+"domains");
ec2Database.loadAmiFromFile(currentDir+"OS_Domain_AMI");*/
if
(
userDatabase
.
databases
==
null
)
{
userDatabase
.
databases
=
new
HashMap
<>();
}
//userDatabase.databases.put("ec2", ec2Database);
userDatabase
.
databases
.
put
(
"egi"
,
egiDatabase
);
/*ProvisionRequest pq = new ProvisionRequest();
pq.topologyName = "ec2_zh_b";
ArrayList<ProvisionRequest> provisionReqs = new ArrayList<ProvisionRequest>();
provisionReqs.add(pq);*/
TEngine
tEngine
=
new
TEngine
();
//tEngine.provision(tam.wholeTopology, userCredential, userDatabase, provisionReqs);
tEngine
.
provisionAll
(
tam
.
wholeTopology
,
userCredential
,
userDatabase
);
//For deployment parameters
String
userName
=
tam
.
wholeTopology
.
topologies
.
get
(
0
).
subTopology
.
getVMsinSubClass
().
get
(
0
).
defaultSSHAccount
;
String
ip
=
tam
.
wholeTopology
.
topologies
.
get
(
0
).
subTopology
.
getVMsinSubClass
().
get
(
0
).
publicAddress
;
String
vmRole
=
tam
.
wholeTopology
.
topologies
.
get
(
0
).
subTopology
.
getVMsinSubClass
().
get
(
0
).
role
;
String
curDir
=
CommonTool
.
getPathDir
(
tam
.
wholeTopology
.
loadingPath
);
String
accessKeyPath
=
curDir
+
File
.
separator
+
tam
.
wholeTopology
.
topologies
.
get
(
0
).
subTopology
.
accessKeyPair
.
SSHKeyPairId
+
File
.
separator
+
"id_rsa"
;
}
private
String
generateResponse
(
TopologyAnalysisMain
topMain
)
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
(
topMain
==
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
{
Map
<
String
,
String
>
fileArguments
=
new
HashMap
<>();
fileArguments
.
put
(
"encoding"
,
charset
);
Map
<
String
,
String
>
topMap
=
topMain
.
generateUserOutputs
();
fileArguments
.
put
(
"name"
,
"topLevel"
);
fileArguments
.
put
(
"value"
,
new
String
(
topMap
.
get
(
"topLevel"
).
getBytes
(),
charset
));
Set
<
String
>
set
=
topMap
.
keySet
();
for
(
String
totplogyName
:
set
)
{
if
(!
totplogyName
.
equals
(
"topLevel"
))
{
topMap
.
get
(
totplogyName
);
}
}
}
jo
.
put
(
"parameters"
,
parameters
);
return
jo
.
toString
();
}
private
String
generateExeptionResponse
(
Throwable
ex
)
throws
JSONException
{
JSONObject
jo
=
new
JSONObject
();
jo
.
put
(
"creationDate"
,
(
System
.
currentTimeMillis
()));
List
parameters
=
new
ArrayList
();
String
charset
=
"UTF-8"
;
Map
<
String
,
String
>
errorArgument
=
new
HashMap
<>();
errorArgument
.
put
(
"encoding"
,
charset
);
errorArgument
.
put
(
"name"
,
ex
.
getClass
().
getName
());
errorArgument
.
put
(
"value"
,
ex
.
getMessage
());
parameters
.
add
(
errorArgument
);
jo
.
put
(
"parameters"
,
parameters
);
return
jo
.
toString
();
}
private
void
writeValueToFile
(
String
value
,
File
file
)
throws
FileNotFoundException
{
try
(
PrintWriter
out
=
new
PrintWriter
(
file
))
{
out
.
print
(
value
);
}
if
(!
file
.
exists
()
||
file
.
length
()
<
value
.
getBytes
().
length
)
{
throw
new
FileNotFoundException
(
"File "
+
file
.
getAbsolutePath
()
+
" doesn't exist or contents are missing "
);
}
}
}
drip-provisioner/src/main/resources/provisioner.properies
View file @
201f5ade
rabbitmq.host=127.0.0.1
rabbitmq.host=127.0.0.1
rpc.queue.name=provisioner_queue_v1
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