Commit d3d3fa2d authored by Spiros Koulouzis's avatar Spiros Koulouzis

fixed json format bug

added simple playbook
parent eec95fe0
......@@ -72,7 +72,7 @@
<h1 class="page-header">Files and Libraries</h1>
<h3 id="artifact_gwt_json_overlay">GWT JSON Overlay</h3>
<p class="lead">Created April 20, 2017</p>
<p class="lead">Created April 21, 2017</p>
<p> <p>
The <a href="http://code.google.com/webtoolkit/">Google Web Toolkit</a> JSON Overlay library provides the JSON Overlays that
can be used to access the Web service API for this application.
......@@ -97,7 +97,7 @@
</tbody>
</table>
<h3 id="artifact_java_json_client_library">Java JSON Client Library</h3>
<p class="lead">Created April 20, 2017</p>
<p class="lead">Created April 21, 2017</p>
<p><p>
The Java client-side library is used to provide the set of Java objects that can be serialized
to/from JSON using <a href="http://jackson.codehaus.org/">Jackson</a>. This is useful for accessing the
......@@ -127,7 +127,7 @@
</tbody>
</table>
<h3 id="artifact_java_xml_client_library">Java XML Client Library</h3>
<p class="lead">Created April 20, 2017</p>
<p class="lead">Created April 21, 2017</p>
<p><p>
The Java client-side library is used to access the Web service API for this application using Java.
</p>
......@@ -155,7 +155,7 @@
</tbody>
</table>
<h3 id="artifact_js_client_library">JavaScript Client Library</h3>
<p class="lead">Created April 20, 2017</p>
<p class="lead">Created April 21, 2017</p>
<p><p>
The JavaScript client-side library defines classes that can be (de)serialized to/from JSON.
This is useful for accessing the resources that are published by this application, but only
......@@ -190,7 +190,7 @@
</tbody>
</table>
<h3 id="artifact_php_json_client_library">PHP JSON Client Library</h3>
<p class="lead">Created April 20, 2017</p>
<p class="lead">Created April 21, 2017</p>
<p><p>
The PHP JSON client-side library defines the PHP classes that can be (de)serialized to/from JSON.
This is useful for accessing the resources that are published by this application, but only
......@@ -219,7 +219,7 @@
</tbody>
</table>
<h3 id="artifact_php_xml_client_library">PHP XML Client Library</h3>
<p class="lead">Created April 20, 2017</p>
<p class="lead">Created April 21, 2017</p>
<p><p>
The PHP client-side library defines the PHP classes that can be (de)serialized to/from XML.
This is useful for accessing the resources that are published by this application, but only
......@@ -251,7 +251,7 @@
</tbody>
</table>
<h3 id="artifact_ruby_json_client_library">Ruby JSON Client Library</h3>
<p class="lead">Created April 20, 2017</p>
<p class="lead">Created April 21, 2017</p>
<p><p>
The Ruby JSON client-side library defines the Ruby classes that can be (de)serialized to/from JSON.
This is useful for accessing the REST endpoints that are published by this application, but only
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -129,40 +129,11 @@ public abstract class DRIPCaller implements AutoCloseable {
if (clean.contains("\"value\":{\"")) {
return Converter.string2Message(clean);
}
Logger.getLogger(DRIPCaller.class.getName()).log(Level.INFO, "Got: {0}", clean);
return mapper.readValue(clean, Message.class);
}
private Message unMarshallWithSimpleJson(String strResponse) throws JSONException {
strResponse = strResponse.replaceAll("'null'", "null").replaceAll("\'", "\"").replaceAll(" ", "");
JSONObject jsonObj = new JSONObject(strResponse);
Message responseMessage = new Message();
responseMessage.setCreationDate((Long) jsonObj.get("creationDate"));
JSONArray jsonParams = (JSONArray) jsonObj.get("parameters");
List<MessageParameter> parameters = new ArrayList<>();
for (int i = 0; i < jsonParams.length(); i++) {
JSONObject jsonParam = (JSONObject) jsonParams.get(i);
MessageParameter parameter = new MessageParameter();
parameter.setName(jsonParam.getString("name"));
parameter.setValue(jsonParam.getString("value"));
parameters.add(parameter);
if (clean.contains("\"null\"")) {
clean = clean.replaceAll("\"null\"", "null");
}
Logger.getLogger(DRIPCaller.class.getName()).log(Level.INFO, "Got: {0}", clean);
responseMessage.setParameters(parameters);
return responseMessage;//
return mapper.readValue(clean, Message.class);
}
// public Message unmarshall(String strResponse) throws IOException {
//
// mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
// strResponse = strResponse.replaceAll("'null'", "null").replaceAll("\'", "\"").replaceAll(" ", "");
//// return unMarshallWithSimpleJson(strResponse);
// return mapper.readValue(strResponse, Message.class);
// }
}
......@@ -15,7 +15,6 @@
*/
package nl.uva.sne.drip.api.service;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -48,7 +47,6 @@ import org.springframework.stereotype.Service;
import nl.uva.sne.drip.api.dao.DeployDao;
import nl.uva.sne.drip.api.dao.KeyPairDao;
import nl.uva.sne.drip.api.exception.KeyException;
import nl.uva.sne.drip.commons.utils.MessageGenerator;
import nl.uva.sne.drip.data.v1.external.KeyPair;
/**
......@@ -115,28 +113,14 @@ public class DeployService {
deployInfo.getManagerType().toLowerCase(),
deployInfo.getConfigurationID());
Message response = MessageGenerator.generateArtificialMessage(System.getProperty("user.home")
+ File.separator + "workspace" + File.separator + "DRIP"
+ File.separator + "docs" + File.separator + "json_samples"
+ File.separator + "deployer_ansible_response2.json");
// Message response = (deployer.call(deployerInvokationMessage));
// Message response = generateFakeResponse();
// Message response = MessageGenerator.generateArtificialMessage(System.getProperty("user.home")
// + File.separator + "workspace" + File.separator + "DRIP"
// + File.separator + "docs" + File.separator + "json_samples"
// + File.separator + "deployer_ansible_response2.json");
Message response = (deployer.call(deployerInvokationMessage));
List<MessageParameter> params = response.getParameters();
DeployResponse deployResponse = new DeployResponse();
for (MessageParameter p : params) {
String name = p.getName();
if (name.equals("credential")) {
String value = p.getValue();
Key k = new Key();
k.setKey(value);
KeyPair pair = new KeyPair();
pair.setPrivateKey(k);
deployResponse.setKey(pair);
save(deployResponse);
return deployResponse;
}
}
return handleResponse(params);
} catch (IOException | TimeoutException | JSONException | InterruptedException ex) {
Logger.getLogger(DeployController.class.getName()).log(Level.SEVERE, null, ex);
......@@ -225,4 +209,27 @@ public class DeployService {
ansibleParameter.setValue(playbook);
return ansibleParameter;
}
private DeployResponse handleResponse(List<MessageParameter> params) throws KeyException {
DeployResponse deployResponse = new DeployResponse();
for (MessageParameter p : params) {
String name = p.getName();
System.err.println(name + " : " + p.getValue());
if (name.equals("credential")) {
String value = p.getValue();
Key k = new Key();
k.setKey(value);
k.setType(Key.KeyType.PRIVATE);
KeyPair pair = new KeyPair();
pair.setPrivateKey(k);
deployResponse.setKey(pair);
}
if (name.equals("ansible_output")) {
String value = p.getValue();
}
}
save(deployResponse);
return deployResponse;
}
}
......@@ -59,10 +59,10 @@ public class ConfigurationController {
@RequestMapping(value = "/post", method = RequestMethod.POST)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String post(@RequestBody String toscaContents) {
String post(@RequestBody String yamlContents) {
try {
return playbookService.saveStringContents(toscaContents);
return playbookService.saveStringContents(yamlContents);
} catch (IOException ex) {
Logger.getLogger(ConfigurationController.class.getName()).log(Level.SEVERE, null, ex);
}
......
---
- hosts: all
tasks:
- name: ls
command: ls -lah /
register: streamoutput
become: true
- debug: msg="{{ streamoutput.stdout }}"
\ No newline at end of file
......@@ -3,7 +3,7 @@ import pika
import json
import os
import time
import json
from vm_info import VmInfo
import docker_kubernetes
import docker_engine
......@@ -32,9 +32,8 @@ done = False
def threaded_function(args):
while not done:
print "Done: %r" %(done)
connection.process_data_events()
sleep(30)
sleep(5)
def handleDelivery(message):
parsed_json = json.loads(message)
......@@ -57,7 +56,7 @@ def handleDelivery(message):
role = param["attributes"]["role"]
node_num += 1
key = path + "%d.txt" % (node_num)
print
fo = open(key, "w")
fo.write(value)
fo.close()
......@@ -107,12 +106,11 @@ def on_request(ch, method, props, body):
par["url"] = "null"
par["encoding"] = "UTF-8"
par["name"] = res_name
value = ret.replace("\"", "\\\"")
print value
par["value"] = "\""+ret+"\""
par["value"] = ret
par["attributes"] = "null"
response["parameters"].append(par)
response = json.dumps(response)
print "Response: %s " % response
ch.basic_publish(exchange='',
......@@ -132,6 +130,11 @@ thread.start()
print(" [x] Awaiting RPC requests")
channel.start_consuming()
done = True
thread.stop()
\ No newline at end of file
try:
channel.start_consuming()
except KeyboardInterrupt:
#thread.stop()
done = True
thread.join()
print "threads successfully closed"
......@@ -11,7 +11,7 @@
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!--<maven.test.skip>true</maven.test.skip>-->
<maven.test.skip>true</maven.test.skip>
</properties>
......
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