Commit a428e436 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Parse to Message POJO

parent c3886b3f
/*
* 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.api.dao;
import nl.uva.sne.drip.commons.types.ClusterCredentials;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
*
* @author S. Koulouzis
*/
public interface ClusterCredentialsDao extends MongoRepository<ClusterCredentials, String> {
}
......@@ -15,6 +15,8 @@
*/
package nl.uva.sne.drip.api.rest;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -26,7 +28,7 @@ import java.util.logging.Logger;
import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.api.dao.CloudCredentialsDao;
import nl.uva.sne.drip.commons.types.Message;
import nl.uva.sne.drip.commons.types.Parameter;
import nl.uva.sne.drip.commons.types.MessageParameter;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -37,9 +39,11 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.rpc.DRIPCaller;
import nl.uva.sne.drip.api.rpc.DeployerCaller;
import nl.uva.sne.drip.api.service.ClusterCredentialService;
import nl.uva.sne.drip.api.service.ProvisionService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.commons.types.CloudCredentials;
import nl.uva.sne.drip.commons.types.ClusterCredentials;
import nl.uva.sne.drip.commons.types.DeployParameter;
import nl.uva.sne.drip.commons.types.LoginKey;
import nl.uva.sne.drip.commons.types.ProvisionInfo;
......@@ -63,6 +67,9 @@ public class DeployController {
@Autowired
private ProvisionService provisionService;
@Autowired
private ClusterCredentialService clusterCredentialService;
@RequestMapping(value = "/deploy/{id}", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
......@@ -70,14 +77,21 @@ public class DeployController {
try (DRIPCaller deployer = new DeployerCaller(messageBrokerHost);) {
Message deployerInvokationMessage = buildDeployerMessage(provisionID);
Message response = deployer.call(deployerInvokationMessage);
// Message response = generateFakeResponse();
List<Parameter> params = response.getParameters();
for (Parameter p : params) {
// Message response = deployer.call(deployerInvokationMessage);
Message response = generateFakeResponse();
List<MessageParameter> params = response.getParameters();
ClusterCredentials clusterCred = new ClusterCredentials();
for (MessageParameter p : params) {
String name = p.getName();
// System.err.println("Name: " + name);
String value = p.getValue();
// System.err.println("Value: " + value);
// Map<String, Object> map = Converter.ymlString2Map(value);
// clusterCred.setKvMap(map);
clusterCredentialService.getDao().save(clusterCred);
}
return null;
return clusterCred.getId();
} catch (IOException | TimeoutException | JSONException | InterruptedException ex) {
Logger.getLogger(DeployController.class.getName()).log(Level.SEVERE, null, ex);
}
......@@ -90,10 +104,10 @@ public class DeployController {
CloudCredentials cCred = cloudCredentialsDao.findOne(cloudConfID);
List<LoginKey> loginKeys = cCred.getLoginKeys();
List<DeployParameter> deployParams = pro.getDeployParameters();
List<Parameter> parameters = new ArrayList<>();
List<MessageParameter> parameters = new ArrayList<>();
for (DeployParameter dp : deployParams) {
String cName = dp.getCloudCertificateName();
Parameter messageParameter = new Parameter();
MessageParameter messageParameter = new MessageParameter();
messageParameter.setName("credential");
messageParameter.setEncoding("UTF-8");
String key = null;
......@@ -122,4 +136,35 @@ public class DeployController {
return deployInvokationMessage;
}
private Message generateFakeResponse() throws IOException, TimeoutException, InterruptedException, JSONException {
String strResponse = "{'creationDate': 1488453891505, 'parameters': "
+ "[{'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DaGdMOEcKN0JqZmwxSGtqRWFYZUtsS1BTZ3NYYlNLdXNiUjNHTjdM"
+ "SGtZd0NQa0FXT1hoSmV6andxUVFTdzVyMUdVbXAvRgpFaHBKOTByM2l3NUJ3MnJxOUdRNytOb1lQNENQdXYwd0N3V0wrWXd3ejhFSzhvVi9vdGNxdWxYVWUwUUZlL2txCkN3VGJvS2JBRElXd2xoSDdDd09ZOHo3SnRjREZ2WEtRYnRlTGNyUTY5MFYyTUQxeTZyeUdmUUhsaWtsRjA2Sk8KMElXSVhDam1NYXppaG1hNGVHQTRHOXZ6R2lMMVlyZGIxVDdYbFd3Zm5iOTg1QmVUWEZvV1JjMUo3RjFvQ3BaVwp2OTN3cko5L01uUzZxN3p2NkdNaUE0Rm5VanZiUDB4OHhWVXpsYjVvVG5HenFycSt2MXJLQklGSlFXdz0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=\\n server: https://52.201.84.116:6443\\n name: kubernetes\\ncontexts:\\n- context:\\n cluster: kubernetes\\n user: admin\\n name: admin@kubernetes\\n- context:\\n cluster: kubernetes\\n user: kubelet\\n name: kubelet@kubernetes\\ncurrent-context: admin@kubernetes\\nkind: Config\\npreferences: {}\\nusers:\\n- name: admin\\n user:\\n client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM0ekNDQWN1Z0F3SUJBZ0lJWlR0eVhaRWNRUTh3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB4TnpBek1ESXhNVEl6TXpoYUZ3MHhPREF6TURJeE1USXpOREJhTUJzeApHVEFYQmdOVkJBTVRFR3QxWW1WeWJtVjBaWE10WVdSdGFXNHdnZ0VpTUEwR0NTcUdTSWIzRFFFQkFRVUFBNElCCkR3QXdnZ0VLQW9JQkFRRFFkOWdJK0liTVhDWlB6d244cGZuK1Vxd0RldXRKZjY5YWFCNFI4ZjZsSHl0dVRyNTk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OUhOSmRkdjBSVWg2WW9ZMjJ5cnJnbWphMS9xcm92YmppOHZ5VFUxREt3CnZBODB4dnd0eUZGOHhlSStQdTk2bTc4Q2dZQnlteGpUZU9ENjkrSktaOUFmc3BnazU0aUFNL0JIWWcvNkMyc2YKUkZ2U0wvdUdEREp1WUtZTHZUUmtjZ0ptSlF5TjA5NFpyL015WlU1SHprVzRRQ1VvcXd3aUJqRHJwS0hPWG5RSApodzBzSXV6UVc0Tk1lUUNjS0luR2dEQ1F4bVZWL2Mvd1h0dXYySWVJeWlnUnRzZ1dtNmFScElFS1lXRXJlV2pkCmlPZ0JjUUtCZ0ZZeTJYMmRubHVnUUI5TDhDWVRYMDZ2Q3ZNM3BsOWIwZXN3MFcxTzljVGJEbmViYXRUdW1lUy8KMEtpUHh5b2tBS1pCM3NDTUl3ZC9ZbTdtbEdjRU9aNEhCLzJCWURHaTdUWFdyTjkwRmVGZFlPVVRXWEpQaHNwQwpQRXVET2hGSHBMZTN6Smxyck9ySG1Ebm5aOFdtWU4rdGZzNnVuVHVsSXZPQWFKd01xVlZ4Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==\\n', "
+ "'encoding': 'UTF-8'}]}";
strResponse = strResponse.replaceAll("'null'", "null").replaceAll("\'", "\"").replaceAll(" ", "");
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
return mapper.readValue(strResponse, Message.class);
}
}
......@@ -33,7 +33,7 @@ import java.util.logging.Logger;
import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.api.dao.CloudCredentialsDao;
import nl.uva.sne.drip.commons.types.Message;
import nl.uva.sne.drip.commons.types.Parameter;
import nl.uva.sne.drip.commons.types.MessageParameter;
import nl.uva.sne.drip.commons.utils.Converter;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -104,9 +104,9 @@ public class ProvisionController {
Message response = provisioner.call(provisionerInvokationMessage);
// Message response = generateFakeResponse();
List<Parameter> params = response.getParameters();
List<MessageParameter> params = response.getParameters();
for (Parameter p : params) {
for (MessageParameter p : params) {
String name = p.getName();
if (!name.equals("kubernetes")) {
String value = p.getValue();
......@@ -147,29 +147,29 @@ public class ProvisionController {
private Message buildProvisionerMessage(ProvisionInfo pReq) throws JSONException, IOException {
Message invokationMessage = new Message();
List<Parameter> parameters = new ArrayList();
List<MessageParameter> parameters = new ArrayList();
CloudCredentials cred = cloudCredentialsDao.findOne(pReq.getCloudConfID());
if (cred == null) {
throw new NotFoundException("Cloud credentials :" + pReq.getCloudConfID() + " not found");
}
Parameter conf = buildCloudConfParam(cred);
MessageParameter conf = buildCloudConfParam(cred);
parameters.add(conf);
List<Parameter> certs = buildCertificatesParam(cred);
List<MessageParameter> certs = buildCertificatesParam(cred);
parameters.addAll(certs);
List<Parameter> topologies = buildTopologyParams(pReq.getPlanID());
List<MessageParameter> topologies = buildTopologyParams(pReq.getPlanID());
parameters.addAll(topologies);
String scriptID = pReq.getUserScriptID();
if (scriptID != null) {
List<Parameter> userScripts = buildScriptParams(scriptID);
List<MessageParameter> userScripts = buildScriptParams(scriptID);
parameters.addAll(userScripts);
}
String userKeyID = pReq.getUserKeyID();
if (userKeyID != null) {
List<Parameter> userKeys = buildKeysParams(userKeyID);
List<MessageParameter> userKeys = buildKeysParams(userKeyID);
parameters.addAll(userKeys);
}
......@@ -178,8 +178,8 @@ public class ProvisionController {
return invokationMessage;
}
private Parameter buildCloudConfParam(CloudCredentials cred) throws JsonProcessingException, JSONException, IOException {
Parameter conf = null;
private MessageParameter buildCloudConfParam(CloudCredentials cred) throws JsonProcessingException, JSONException, IOException {
MessageParameter conf = null;
String provider = cred.getCloudProviderName();
if (provider == null) {
throw new BadRequestException("Provider name can't be null. Check the cloud credentials: " + cred.getId());
......@@ -192,18 +192,18 @@ public class ProvisionController {
return conf;
}
private List<Parameter> buildCertificatesParam(CloudCredentials cred) {
private List<MessageParameter> buildCertificatesParam(CloudCredentials cred) {
List<LoginKey> loginKeys = cred.getLoginKeys();
if (loginKeys == null || loginKeys.isEmpty()) {
throw new BadRequestException("Log in keys can't be empty");
}
List<Parameter> parameters = new ArrayList<>();
List<MessageParameter> parameters = new ArrayList<>();
for (LoginKey lk : loginKeys) {
String domainName = lk.getAttributes().get("domain_name");
if (domainName == null) {
domainName = lk.getAttributes().get("domain_name ");
}
Parameter cert = new Parameter();
MessageParameter cert = new MessageParameter();
cert.setName("certificate");
cert.setValue(lk.getKey());
Map<String, String> attributes = new HashMap<>();
......@@ -214,13 +214,13 @@ public class ProvisionController {
return parameters;
}
private List<Parameter> buildTopologyParams(String planID) throws JSONException {
private List<MessageParameter> buildTopologyParams(String planID) throws JSONException {
Plan plan = planService.getDao().findOne(planID);
if (plan == null) {
throw new NotFoundException();
}
List<Parameter> parameters = new ArrayList();
Parameter topology = new Parameter();
List<MessageParameter> parameters = new ArrayList();
MessageParameter topology = new MessageParameter();
topology.setName("topology");
topology.setValue(Converter.map2YmlString(plan.getKvMap()));
Map<String, String> attributes = new HashMap<>();
......@@ -232,7 +232,7 @@ public class ProvisionController {
Set<String> ids = plan.getLoweLevelPlanIDs();
for (String lowID : ids) {
Plan lowPlan = planService.getDao().findOne(lowID);
topology = new Parameter();
topology = new MessageParameter();
topology.setName("topology");
topology.setValue(Converter.map2YmlString(lowPlan.getKvMap()));
attributes = new HashMap<>();
......@@ -244,13 +244,13 @@ public class ProvisionController {
return parameters;
}
private Parameter buildEC2Conf(CloudCredentials cred) throws JsonProcessingException, JSONException, IOException {
private MessageParameter buildEC2Conf(CloudCredentials cred) throws JsonProcessingException, JSONException, IOException {
Properties prop = Converter.getEC2Properties(cred);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
prop.store(baos, null);
byte[] bytes = baos.toByteArray();
Parameter conf = new Parameter();
MessageParameter conf = new MessageParameter();
conf.setName("ec2.conf");
String charset = "UTF-8";
conf.setValue(new String(bytes, charset));
......@@ -258,13 +258,13 @@ public class ProvisionController {
}
private List<Parameter> buildScriptParams(String userScriptID) {
private List<MessageParameter> buildScriptParams(String userScriptID) {
UserScript script = userScriptService.getDao().findOne(userScriptID);
if (script == null) {
throw new BadRequestException("User script: " + userScriptID + " was not found");
}
List<Parameter> parameters = new ArrayList();
Parameter scriptParameter = new Parameter();
List<MessageParameter> parameters = new ArrayList();
MessageParameter scriptParameter = new MessageParameter();
scriptParameter.setName("guiscript");
scriptParameter.setValue(script.getContents());
scriptParameter.setEncoding("UTF-8");
......@@ -272,13 +272,13 @@ public class ProvisionController {
return parameters;
}
private List<Parameter> buildKeysParams(String userKeyID) {
private List<MessageParameter> buildKeysParams(String userKeyID) {
LoginKey key = userKeysService.get(userKeyID, LoginKey.Type.PUBLIC);
if (key == null) {
throw new BadRequestException("User key: " + userKeyID + " was not found");
}
List<Parameter> parameters = new ArrayList();
Parameter keyParameter = new Parameter();
List<MessageParameter> parameters = new ArrayList();
MessageParameter keyParameter = new MessageParameter();
keyParameter.setName("sshkey");
keyParameter.setValue(key.getKey());
keyParameter.setEncoding("UTF-8");
......
......@@ -16,7 +16,7 @@ import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeoutException;
import nl.uva.sne.drip.commons.types.Message;
import nl.uva.sne.drip.commons.types.Parameter;
import nl.uva.sne.drip.commons.types.MessageParameter;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
......@@ -118,7 +118,8 @@ public abstract class DRIPCaller implements AutoCloseable {
}
});
String strResponse = response.take();
strResponse = strResponse.replaceAll("'null'", "null").replaceAll("\'", "\"").replaceAll(" ", "");
System.err.println(strResponse);
// return unMarshallWithSimpleJson(strResponse);
return mapper.readValue(strResponse, Message.class);
}
......@@ -130,12 +131,12 @@ public abstract class DRIPCaller implements AutoCloseable {
Message responseMessage = new Message();
responseMessage.setCreationDate((Long) jsonObj.get("creationDate"));
JSONArray jsonParams = (JSONArray) jsonObj.get("parameters");
List<Parameter> parameters = new ArrayList<>();
List<MessageParameter> parameters = new ArrayList<>();
for (int i = 0; i < jsonParams.length(); i++) {
JSONObject jsonParam = (JSONObject) jsonParams.get(i);
Parameter parameter = new Parameter();
MessageParameter parameter = new MessageParameter();
parameter.setName(jsonParam.getString("name"));
parameter.setValue(jsonParam.getString("value"));
parameters.add(parameter);
......
/*
* 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.api.service;
import nl.uva.sne.drip.api.dao.ClusterCredentialsDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
*
* @author S. Koulouzis
*/
@Service
public class ClusterCredentialService {
@Autowired
private ClusterCredentialsDao dao;
/**
* @return the dao
*/
public ClusterCredentialsDao getDao() {
return dao;
}
}
......@@ -24,7 +24,7 @@ import java.util.concurrent.TimeoutException;
import nl.uva.sne.drip.api.exception.BadRequestException;
import nl.uva.sne.drip.api.rpc.PlannerCaller;
import nl.uva.sne.drip.commons.types.Message;
import nl.uva.sne.drip.commons.types.Parameter;
import nl.uva.sne.drip.commons.types.MessageParameter;
import nl.uva.sne.drip.commons.types.ToscaRepresentation;
import nl.uva.sne.drip.commons.utils.Converter;
import org.json.JSONException;
......@@ -51,8 +51,8 @@ public class PlannerService {
Message plannerInvokationMessage = buildPlannerMessage(toscaId);
Message plannerReturnedMessage = planner.call(plannerInvokationMessage);
List<Parameter> parameters = plannerReturnedMessage.getParameters();
for (Parameter param : parameters) {
List<MessageParameter> parameters = plannerReturnedMessage.getParameters();
for (MessageParameter param : parameters) {
}
ToscaRepresentation tr = new ToscaRepresentation();
......@@ -75,7 +75,7 @@ public class PlannerService {
Message invokationMessage = new Message();
List parameters = new ArrayList();
Parameter jsonArgument = new Parameter();
MessageParameter jsonArgument = new MessageParameter();
String charset = "UTF-8";
jsonArgument.setValue(new String(bytes, charset));
jsonArgument.setEncoding(charset);
......
......@@ -30,7 +30,7 @@ import nl.uva.sne.drip.api.dao.PlanDao;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.rpc.PlannerCaller;
import nl.uva.sne.drip.commons.types.Message;
import nl.uva.sne.drip.commons.types.Parameter;
import nl.uva.sne.drip.commons.types.MessageParameter;
import nl.uva.sne.drip.commons.types.Plan;
import nl.uva.sne.drip.commons.types.ToscaRepresentation;
import nl.uva.sne.drip.commons.utils.Converter;
......@@ -62,14 +62,14 @@ public class SimplePlannerService {
Plan topLevel;
try (PlannerCaller planner = new PlannerCaller(messageBrokerHost)) {
Message plannerReturnedMessage = planner.call(plannerInvokationMessage);
List<Parameter> planFiles = plannerReturnedMessage.getParameters();
List<MessageParameter> planFiles = plannerReturnedMessage.getParameters();
topLevel = new Plan();
Set<String> ids = topLevel.getLoweLevelPlanIDs();
if (ids == null) {
ids = new HashSet<>();
}
Plan lowerLevelPlan = null;
for (Parameter p : planFiles) {
for (MessageParameter p : planFiles) {
//Should have levels in attributes
Map<String, String> attributess = p.getAttributes();
if (attributess != null) {
......@@ -108,7 +108,7 @@ public class SimplePlannerService {
Message invokationMessage = new Message();
List parameters = new ArrayList();
Parameter fileArgument = new Parameter();
MessageParameter fileArgument = new MessageParameter();
String charset = "UTF-8";
fileArgument.setValue(new String(bytes, charset));
......@@ -116,7 +116,7 @@ public class SimplePlannerService {
fileArgument.setName("input");
parameters.add(fileArgument);
fileArgument = new Parameter();
fileArgument = new MessageParameter();
bytes = Files.readAllBytes(Paths.get(System.getProperty("user.home") + File.separator + "Downloads/DRIP/example_a.yml"));
fileArgument.setValue(new String(bytes, charset));
fileArgument.setEncoding(charset);
......
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