Commit 8f0cfc5f authored by Spiros Koulouzis's avatar Spiros Koulouzis

Python smaple code

parent bfd668b4
......@@ -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) {
......
#!/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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment