Commit d3d3fa2d authored by Spiros Koulouzis's avatar Spiros Koulouzis

fixed json format bug

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