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
8f0cfc5f
Commit
8f0cfc5f
authored
Feb 16, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Python smaple code
parent
bfd668b4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
42 deletions
+49
-42
PlannerController.java
...main/java/nl/uva/sne/drip/api/rest/PlannerController.java
+10
-42
rpc_server.py
python/rpc_server.py
+39
-0
No files found.
drip-api/src/main/java/nl/uva/sne/drip/api/rest/PlannerController.java
View file @
8f0cfc5f
...
...
@@ -51,6 +51,7 @@ import nl.uva.sne.drip.api.rpc.DRIPCaller;
import
nl.uva.sne.drip.api.rpc.ProvisionerCaller
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.commons.types.CloudCredentials
;
import
nl.uva.sne.drip.commons.types.LoginKey
;
import
org.apache.commons.io.FilenameUtils
;
/**
...
...
@@ -107,48 +108,7 @@ public class PlannerController {
return
null
;
}
@RequestMapping
(
value
=
"/get"
,
method
=
RequestMethod
.
GET
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
Message
get
()
{
try
{
File
tempFile1
=
new
File
(
"/home/alogo/Downloads/DRIP/input.yaml"
);
Message
message1
=
new
Message
();
message1
.
setCreationDate
((
System
.
currentTimeMillis
()));
List
<
Parameter
>
parameters
=
new
ArrayList
();
Parameter
numParam
=
new
Parameter
();
String
numParamName
=
"input"
;
numParam
.
setName
(
numParamName
);
numParam
.
setValue
(
"33000"
);
parameters
.
add
(
numParam
);
Parameter
fileParamContents
=
new
Parameter
();
String
fileParamContentsName
=
"someInputFile"
;
fileParamContents
.
setName
(
fileParamContentsName
);
byte
[]
bytes
=
Files
.
readAllBytes
(
Paths
.
get
(
tempFile1
.
getAbsolutePath
()));
String
charset
=
"UTF-8"
;
fileParamContents
.
setValue
(
new
String
(
bytes
,
charset
));
fileParamContents
.
setEncoding
(
charset
);
parameters
.
add
(
fileParamContents
);
Parameter
fileParamRef
=
new
Parameter
();
fileParamRef
.
setName
(
"theNameOfTheParamater"
);
fileParamRef
.
setURL
(
"http://www.gutenberg.org/cache/epub/3160/pg3160.txt"
);
Map
<
String
,
String
>
attributes
=
new
HashMap
<>();
attributes
.
put
(
"level"
,
"0"
);
fileParamRef
.
setAttributes
(
attributes
);
parameters
.
add
(
fileParamRef
);
message1
.
setParameters
(
parameters
);
return
message1
;
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
PlannerController
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
return
null
;
}
private
Message
buildPlannerMessage
(
String
toscaId
)
throws
JSONException
,
UnsupportedEncodingException
,
IOException
{
ToscaRepresentation
t2
=
dao
.
findOne
(
toscaId
);
Map
<
String
,
Object
>
map
=
t2
.
getKvMap
();
...
...
@@ -191,6 +151,14 @@ public class PlannerController {
conf
.
setName
(
"ec2.conf"
);
conf
.
setValue
(
new
String
(
bytes
,
charset
));
parameters
.
add
(
conf
);
List
<
LoginKey
>
loginKeys
=
cred
.
getLogineKys
();
for
(
LoginKey
lk
:
loginKeys
){
String
domainName
=
lk
.
getAttributes
().
get
(
"domain_name"
);
Parameter
cert
=
new
Parameter
();
cert
.
setName
(
"certificate"
);
cert
.
setValue
(
charset
);
}
List
<
Parameter
>
returnedParams
=
plannerReturnedMessage
.
getParameters
();
for
(
Parameter
param
:
returnedParams
)
{
...
...
python/rpc_server.py
0 → 100755
View file @
8f0cfc5f
#!/usr/bin/env python
import
pika
import
json
connection
=
pika
.
BlockingConnection
(
pika
.
ConnectionParameters
(
host
=
'172.17.0.2'
))
channel
=
connection
.
channel
()
channel
.
queue_declare
(
queue
=
'planner_queue'
)
def
handleDelivery
(
message
):
parsed_json
=
json
.
loads
(
message
)
params
=
parsed_json
[
"parameters"
]
for
param
in
params
:
name
=
param
[
"name"
]
value
=
param
[
"value"
]
def
on_request
(
ch
,
method
,
props
,
body
):
handleDelivery
(
body
)
print
(
" Message
%
s"
%
body
)
response
=
"AAAAAAAAAAAAAAAAAAAAAA"
ch
.
basic_publish
(
exchange
=
''
,
routing_key
=
props
.
reply_to
,
properties
=
pika
.
BasicProperties
(
correlation_id
=
\
props
.
correlation_id
),
body
=
str
(
response
))
ch
.
basic_ack
(
delivery_tag
=
method
.
delivery_tag
)
channel
.
basic_qos
(
prefetch_count
=
1
)
channel
.
basic_consume
(
on_request
,
queue
=
'planner_queue'
)
print
(
" [x] Awaiting RPC requests"
)
channel
.
start_consuming
()
\ 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