Commit 1b947c6c authored by Spiros Koulouzis's avatar Spiros Koulouzis

Added cloud credentials

Added json examples 
parent 3e7ef0cf
/drip-commons/target/
/drip-api/target/
/drip-planner/target/
/drip-commons/nbproject/
\ No newline at end of file
/drip-commons/nbproject/
/drip-simple_planner/target/
\ No newline at end of file
{
"key": "AKISAKISAKIS",
"keyIdAlias": "6J76J76J76J76J76J76J7",
"logineKys": [
{
"attributes": {
"domain_name ": "California"
},
"type": "PUBLIC",
"key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpQIBAAKCAQEA3Tz2mr7SZiAMfQyuvBjM9Oi..Z1BjP5CE/Wm/Rr500P\nRK+Lh9x5eJPo5CAZ3/ANBE0sTK0ZsDGMak2m1g7..3VHqIxFTz0Ta1d+NAj\nwnLe4nOb7/eEJbDPkk05ShhBrJGBKKxb8n104o/..PdzbFMIyNjJzBM2o5y\n5A13wiLitEO7nco2WfyYkQzaxCw0AwzlkVHiIyC..71pSzkv6sv+4IDMbT/\nXpCo8L6wTarzrywnQsh+etLD6FtTjYbbrvZ8RQM..Hg2qxraAV++HNBYmNW\ns0duEdjUbJK+ZarypXI9TtnS4o1Ckj7POfljiQI..IBAFyidxtqRQyv5KrD\nkbJ+q+rsJxQlaipn2M4lGuQJEfIxELFDyd3XpxP..Un/82NZNXlPmRIopXs\n2T91jiLZEUKQw+n73j26adTbteuEaPGSrTZxBLR..yssO0wWomUyILqVeti\n6AkL0NJAuKcucHGqWVgUIa4g1haE0ilcm6dWUDo..fd+PpzdCJf1s4NdUWK\nYV2GJcutGQb+jqT5DTUqAgST7N8M28rwjK6nVMI..BUpP0xpPnuYDyPOw6x\n4hBt8DZQYyduzIXBXRBKNiNdv8fum68/5klHxp6..4HRkMUL958UVeljUsT\nBFQlO9UCgYEA/VqzXVzlz8K36VSTMPEhB5zBATV..PRiXtYK1YpYV4/jSUj\nvvT4hP8uoYNC+BlEMi98LtnxZIh0V4rqHDsScAq..VyeSLH0loKMZgpwFEm\nbEIDnEOD0nKrfT/9K9sPYgvB43wsLEtUujaYw3W..Liy0WKmB8CgYEA34xn\n1QlOOhHBn9Z8qYjoDYhvcj+a89tD9eMPhesfQFw..rsfGcXIonFmWdVygbe\n6Doihc+GIYIq/QP4jgMksE1ADvczJSke92ZfE2i..fitBpQERNJO0BlabfP\nALs5NssKNmLkWS2U2BHCbv4DzDXwiQB37KPOL1c..kBHfF2/htIs20d1UVL\n+PK+aXKwguI6bxLGZ3of0UH+mGsSl0mkp7kYZCm..OTQtfeRqP8rDSC7DgA\nkHc5ajYqh04AzNFaxjRo+M3IGICUaOdKnXd0Fda..QwfoaX4QlRTgLqb7AN\nZTzM9WbmnYoXrx17kZlT3lsCgYEAm757XI3WJVj..WoLj1+v48WyoxZpcai\nuv9bT4Cj+lXRS+gdKHK+SH7J3x2CRHVS+WH/SVC..DxuybvebDoT0TkKiCj\nBWQaGzCaJqZa+POHK0klvS+9ln0/6k539p95tfX..X4TCzbVG6+gJiX0ysz\nYfehn5MCgYEAkMiKuWHCsVyCab3RUf6XA9gd3qY..fCTIGtS1tR5PgFIV+G\nengiVoWc/hkj8SBHZz1n1xLN7KDf8ySU06MDggB..hJ+gXJKy+gf3mF5Kmj\nDtkpjGHQzPF6vOe907y5NQLvVFGXUq/FIJZxB8k..fJdHEm2M4=\n-----END RSA PRIVATE KEY-----"
},
{
"attributes": {
"domain_name ": "Virginia"
},
"type": "PUBLIC",
"key": "-----BEGIN RSA PRIVATE KEY-----\nMIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp\nwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5\n1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh\n3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2\npIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX\nGukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il\nAkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF\nL0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k\nX6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl\nU9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ\n37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=\n-----END RSA PRIVATE KEY-----"
}
],
"cloudProviderName": "ec2"
}
{
"key": "my_secret_password",
"keyIdAlias": "geni",
"logineKys": [
{
"attributes": null,
"key": "-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEA+xGZ/wcz9ugFpP07Nspo6U17l0YhFiFpxxU4pTk3Lifz9R3zsIsu\nERwta7+fWIfxOo208ett/jhskiVodSEt3QBGh4XBipyWopKwZ93HHaDVZAALi/2A\n+xTBtWdEo7XGUujKDvC2/aZKukfjpOiUI8AhLAfjmlcD/UZ1QPh0mHsglRNCmpCw\nmwSXA9VNmhz+PiB+Dml4WWnKW/VHo2ujTXxq7+efMU4H2fny3Se3KYOsFPFGZ1TN\nQSYlFuShWrHPtiLmUdPoP6CV2mML1tk+l7DIIqXrQhLUKDACeM5roMx0kLhUWB8P\n+0uj1CNlNN4JRZlC7xFfqiMbFRU9Z4N6YwIDAQAB\n-----END RSA PUBLIC KEY-----",
"type": "PUBLIC"
},
{
"attributes": null,
"key": "-----BEGIN RSA PRIVATE KEY-----\nMIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp\nwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5\n1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh\n3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2\npIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX\nGukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il\nAkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF\nL0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k\nX6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl\nU9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ\n37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=\n-----END RSA PRIVATE KEY-----",
"type": "PRIVATE"
}
],
"cloudProviderName": "exogeni"
}
{
"creationDate": 1487002029722,
"parameters": [
{
"url": null,
"encoding": null,
"value": "33000",
"name": "input",
"attributes": null
},
{
"url": null,
"encoding": "UTF-8",
"value": "0.84\n 0.735\n 0.44\n 0.211\n 0.669\n 0.683\n 0.011\n 0.435\n 0.246\n 0.006\n 0.046\n 0.214\n 0.872\n 0.206\n 0.643\n 0.289\n 0.381\n 0.05\n 0.831\n 0.835\n 0.953\n 0.119\n 0.214\n 0.412\n 0.643\n 0.714\n 0.672\n 0.929\n 0.562\n 0.216\n 0.386\n 0.309\n 0.977\n 0.281\n 0.522\n 0.393\n 0.217\n 0.002\n 0.147\n 0.755\n 0.745\n 0.074\n 0.032\n 0.844\n 0.636\n 0.74\n 0.473\n 0.539\n 0.032\n 0.268\n 0.736\n 0.232\n 0.278\n 0.309\n 0.143\n 0.171\n 0.491\n 0.55\n 0.087\n 0.723\n 0.274\n 0.757\n 0.263\n 0.09\n 0.563\n 0.747\n 0.935\n 0.493\n 0.108\n 0.448\n 0.128\n 0.498\n 0.691\n 0.791\n 0.499\n 0.474\n 0.045\n 0.338\n 0.754\n 0.838\n 0.758\n 0.8\n 0.055\n 0.798\n 0.517\n 0.619\n 0.055\n 0.803\n 0.467\n 0.47\n 0.842\n 0.294\n 0.977\n 0.211\n 0.513\n 0.282\n 0.147\n 0.219\n 0.445\n 0.157\n\n",
"name": "someInputFile",
"attributes": null
},
{
"url": "http://www.gutenberg.org/cache/epub/3160/pg3160.txt",
"encoding": null,
"value": null,
"name": "theNameOfTheParamater",
"attributes": {
"level": "0"
}
}
]
}
......@@ -56,6 +56,17 @@
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
......
/*
* 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.conf;
public class MessageSecurityWebApplicationInitializer{
//extends AbstractSecurityWebApplicationInitializer {
}
/*
* 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.conf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import nl.uva.sne.drip.api.dao.UserDao;
/**
*
*/
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
auth.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
@Bean
public PasswordEncoder passwordEncoder() {
PasswordEncoder encoder = new BCryptPasswordEncoder();
return encoder;
}
}
......@@ -27,6 +27,7 @@ public class WebAppInitializer implements WebApplicationInitializer {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(Config.class);
ctx.register(MongoConfig.class);
// ctx.register(SecurityConfig.class);
ctx.setServletContext(servletContext);
......
/*
* 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.CloudCredentials;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
*
* @author S. Koulouzis
*/
public interface CloudCredentialsDao extends MongoRepository<CloudCredentials, String> {
}
/*
* 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.ToscaRepresentation;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
*
* @author S. Koulouzis
*/
public interface ToscaDao extends MongoRepository<ToscaRepresentation, String> {
}
......@@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.rest;
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.commons.types.User;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
*
* @author S. Koulouzis
*/
public interface ToscaRepository extends MongoRepository<ToscaRepresentation, String> {
public interface UserDao extends MongoRepository<User, String> {
}
/*
* Copyright 2017 S. Koulouzis.
*
* 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.rest;
import nl.uva.sne.drip.api.rpc.PlannerCaller;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.commons.types.CloudCredentials;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import nl.uva.sne.drip.commons.types.LoginKey;
import nl.uva.sne.drip.api.dao.CloudCredentialsDao;
import org.springframework.web.bind.annotation.PathVariable;
/**
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/rest/configuration")
@Component
public class CloudConfigurationController {
@Autowired
private CloudCredentialsDao dao;
//
// @RequestMapping(value = "/upload", method = RequestMethod.POST)
// public @ResponseBody
// String loginKeyUpload(@RequestParam("file") MultipartFile file) throws JSONException {
// if (!file.isEmpty()) {
// try {
//
// String originalFileName = file.getOriginalFilename();
// String name = System.currentTimeMillis() + "_" + originalFileName;
// byte[] bytes = file.getBytes();
// String key = new String(bytes, "UTF-8");
// CloudCredentials kr = new CloudCredentials();
//
// return null;
// } catch (IOException | IllegalStateException ex) {
// Logger.getLogger(CloudConfigurationController.class.getName()).log(Level.SEVERE, null, ex);
// } finally {
// if (planner != null) {
// try {
// planner.close();
// } catch (IOException | TimeoutException ex) {
// Logger.getLogger(CloudConfigurationController.class.getName()).log(Level.WARNING, null, ex);
// }
// }
// }
// }
// return null;
// }
@RequestMapping(method = RequestMethod.POST)
public @ResponseBody
String postConf(CloudCredentials cc) throws JSONException {
dao.save(cc);
return cc.getId();
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public CloudCredentials get(@PathVariable("id") String id) throws JSONException, IOException {
return dao.findOne(id);
}
@RequestMapping(value = "/ids")
public @ResponseBody
List<String> getIds() {
List<CloudCredentials> all = dao.findAll();
List<String> ids = new ArrayList<>();
for (CloudCredentials tr : all) {
ids.add(tr.getId());
}
return ids;
}
}
/*
* 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.rest;
import nl.uva.sne.drip.commons.types.ToscaRepresentation;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
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.utils.Converter;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import nl.uva.sne.drip.api.dao.ToscaDao;
/**
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/rest/planner")
@Component
public class PlannerController {
@Value("${message.broker.host}")
private String messageBrokerHost;
@Autowired
private ToscaDao dao;
@RequestMapping(value = "/plan/{tosca_id}", method = RequestMethod.POST)
public @ResponseBody
String plann(@PathVariable("tosca_id") String toscaId) throws JSONException, IOException, TimeoutException {
PlannerCaller planner = null;
try {
ToscaRepresentation t2 = dao.findOne(toscaId);
Map<String, Object> map = t2.getKvMap();
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
byte[] bytes = ymlStr.getBytes();
Message invokationMessage = new Message();
List parameters = new ArrayList();
Parameter fileArgument = new Parameter();
String charset = "UTF-8";
fileArgument.setValue(new String(bytes, charset));
fileArgument.setEncoding(charset);
fileArgument.setName("input");
parameters.add(fileArgument);
fileArgument = new Parameter();
bytes = Files.readAllBytes(Paths.get("/home/alogo/Downloads/DRIP/example_a.yml"));
fileArgument.setValue(new String(bytes, charset));
fileArgument.setEncoding(charset);
fileArgument.setName("example");
parameters.add(fileArgument);
invokationMessage.setParameters(parameters);
invokationMessage.setCreationDate((System.currentTimeMillis()));
planner = new PlannerCaller(messageBrokerHost);
String returned = planner.plan(invokationMessage);
System.err.println(returned);
ObjectMapper mapper = new ObjectMapper();
Message request = mapper.readValue(returned, Message.class);
return returned;
} catch (UnsupportedEncodingException | TimeoutException | InterruptedException ex) {
Logger.getLogger(PlannerController.class.getName()).log(Level.SEVERE, null, ex);
} finally {
if (planner != null) {
planner.close();
}
}
return null;
}
@RequestMapping(value = "/get", method = RequestMethod.GET)
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;
}
}
......@@ -15,24 +15,17 @@
*/
package nl.uva.sne.drip.api.rest;
import com.fasterxml.jackson.databind.ObjectMapper;
import nl.uva.sne.drip.commons.types.Parameter;
import nl.uva.sne.drip.commons.types.ToscaRepresentation;
import nl.uva.sne.drip.api.rpc.PlannerCaller;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.commons.types.Message;
import nl.uva.sne.drip.commons.utils.Converter;
import static nl.uva.sne.drip.commons.utils.Converter.ymlString2Map;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
......@@ -42,8 +35,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import static nl.uva.sne.drip.commons.utils.Converter.ymlString2Map;
import org.springframework.web.bind.annotation.PathVariable;
import nl.uva.sne.drip.api.dao.ToscaDao;
/**
*
......@@ -57,11 +50,8 @@ public class ToscaController {
@Value("${message.broker.host}")
private String messageBrokerHost;
// For some reson only Autowired decelred here work
// @Autowired
// private UploadService upload;
@Autowired
private ToscaRepository dao;
private ToscaDao dao;
// curl -X POST -F "file=@DRIP/input.yaml" localhost:8080/drip-api/rest/upload
@RequestMapping(value = "/upload", method = RequestMethod.POST)
......@@ -79,47 +69,11 @@ public class ToscaController {
Map<String, Object> map = Converter.ymlString2Map(str);
ToscaRepresentation t = new ToscaRepresentation();
t.setName(name);
t.setKvMap(map);
dao.save(t);
// String ymlStr = Converter.map2YmlString(map);
// ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
// map = Converter.ymlString2Map(ymlStr);
// t.setKvMap(map);
// ToscaRepresentation t2 = dao.findOne(id);
// map = t2.getKvMap();
// String ymlStr = Converter.map2YmlString(map);
// ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
// System.err.println(ymlStr);
// Message invokationMessage = new Message();
//
// List parameters = new ArrayList();
// Parameter fileArgument = new Parameter();
//
// String charset = "UTF-8";
// fileArgument.setValue(new String(bytes, charset));
// fileArgument.setEncoding(charset);
// fileArgument.setName("input");
// parameters.add(fileArgument);
//
// fileArgument = new Parameter();
// bytes = Files.readAllBytes(Paths.get("/home/alogo/Downloads/DRIP/example_a.yml"));
// fileArgument.setValue(new String(bytes, charset));
// fileArgument.setEncoding(charset);
// fileArgument.setName("example");
// parameters.add(fileArgument);
//
// invokationMessage.setParameters(parameters);
// invokationMessage.setCreationDate((System.currentTimeMillis()));
//
// planner = new PlannerCaller(messageBrokerHost);
// String returned = planner.plan(invokationMessage);
// ObjectMapper mapper = new ObjectMapper();
// Message request = mapper.readValue(returned, Message.class);
//
// System.err.println(returned);
// System.err.println(request.getCreationDate());
return t.getId();//"You successfully uploaded " + name + " into " + name + "-uploaded !";
return t.getId();
} catch (IOException | IllegalStateException ex) {
Logger.getLogger(ToscaController.class.getName()).log(Level.SEVERE, null, ex);
} finally {
......@@ -138,7 +92,7 @@ public class ToscaController {
// curl http://localhost:8080/drip-api/rest/tosca/589e1160d9925f9dc127e882/?fromat=yaml
@RequestMapping(value = "/{id}", method = RequestMethod.GET, params = {"fromat"})
public @ResponseBody
String getTosca(@PathVariable("id") String id, @RequestParam(value = "fromat") String fromat) throws JSONException {
String get(@PathVariable("id") String id, @RequestParam(value = "fromat") String fromat) throws JSONException {
Map<String, Object> map = dao.findOne(id).getKvMap();
if (fromat != null && fromat.equals("yml")) {
String ymlStr = Converter.map2YmlString(map);
......@@ -158,7 +112,7 @@ public class ToscaController {
// http://localhost:8080/drip-api/rest/tosca/ids
@RequestMapping(value = "/ids")
public @ResponseBody
List<String> getIds() throws JSONException {
List<String> getIds() {
List<ToscaRepresentation> all = dao.findAll();
List<String> ids = new ArrayList<>();
for (ToscaRepresentation tr : all) {
......
......@@ -15,34 +15,46 @@
*/
package nl.uva.sne.drip.api.rest;
import org.json.JSONException;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.commons.types.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import nl.uva.sne.drip.api.dao.UserDao;
/**
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/rest")
@RequestMapping("/user/")
@Component
public class ProvisionController {
public class UserController {
@Value("${message.broker.host}")
private String messageBrokerHost;
@Autowired
private ToscaRepository dao;
private UserDao userRepository;
@RequestMapping(value = "/t", method = RequestMethod.GET)
public ToscaRepresentation toscaUpload() throws JSONException {
return dao.findAll().get(0);
@RequestMapping(value = "/register", method = RequestMethod.POST)
public @ResponseBody
String register(User user) {
userRepository.save(user);
return "registration";
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public @ResponseBody
User get(@PathVariable("id") String id) {
try {
return userRepository.findOne(id);
} catch (Exception ex) {
Logger.getLogger(UserController.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
}
......@@ -15,39 +15,28 @@
*/
package nl.uva.sne.drip.api.rest;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import nl.uva.sne.drip.api.dao.UserDao;
/**
*
* @author S. Koulouzis
*/
@Service
public class UploadService {
public class UserService implements UserDetailsService {
@Autowired
private ToscaRepository dao;
public List<ToscaRepresentation> findAll() {
Iterable<ToscaRepresentation> all = dao.findAll();
List<ToscaRepresentation> list = new ArrayList();
Iterator<ToscaRepresentation> it = all.iterator();
while (it.hasNext()) {
list.add(it.next());
}
return list;
}
public ToscaRepresentation findOneById(String id) {
return dao.findOne(id);
}
private UserDao userRepository;
public ToscaRepository getDao() {
return dao;
@Override
public UserDetails loadUserByUsername(String string) throws UsernameNotFoundException {
return null;
}
}
input.tosca.folder.path=/tmp/
message.broker.host=172.17.0.2
message.broker.host=172.17.0.3
db.name=drip
db.username=drip-user
db.password=drip-pass
......@@ -45,6 +45,18 @@
<version>1.17</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.10.0.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>4.2.1.RELEASE</version>
<type>jar</type>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
......
/*
* 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.commons.types;
import java.util.List;
import java.util.Map;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
*
* @author S. Koulouzis
*/
@Document
public class CloudCredentials {
@Id
private String id;
private String key;
private String keyIdAlias;
private List<LoginKey> logineKys;
private String cloudProviderName;
public final String getId() {
return id;
}
public final void setId(final String id) {
this.id = id;
}
/**
* @return the key
*/
public String getKey() {
return key;
}
/**
* @param key the key to set
*/
public void setKey(String key) {
this.key = key;
}
/**
* @return the keyIdAlias
*/
public String getKeyIdAlias() {
return keyIdAlias;
}
/**
* @param keyIdAlias the keyIdAlias to set
*/
public void setKeyIdAlias(String keyIdAlias) {
this.keyIdAlias = keyIdAlias;
}
/**
* @return the logineKys
*/
public List<LoginKey> getLogineKys() {
return logineKys;
}
/**
* @param logineKys the logineKys to set
*/
public void setLogineKys(List<LoginKey> logineKys) {
this.logineKys = logineKys;
}
/**
* @return the cloudProviderName
*/
public String getCloudProviderName() {
return cloudProviderName;
}
/**
* @param cloudProviderName the cloudProviderName to set
*/
public void setCloudProviderName(String cloudProviderName) {
this.cloudProviderName = cloudProviderName;
}
}
/*
* 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.commons.types;
import java.util.Map;
import org.springframework.data.mongodb.core.mapping.Document;
/**
*
* @author S. Koulouzis
*/
@Document
public class LoginKey {
private Map<String, String> attributes;
private String key;
private Type type;
public static enum Type {
PRIVATE,
PUBLIC
}
/**
* @return the type
*/
public Type getType() {
return type;
}
/**
* @param type the type to set
*/
public void setType(Type type) {
this.type = type;
}
/**
* @return the attributes
*/
public Map<String, String> getAttributes() {
return attributes;
}
/**
* @param attributes the attributes to set
*/
public void setAttributes(Map<String, String> attributes) {
this.attributes = attributes;
}
/**
* @return the key
*/
public String getKey() {
return key;
}
/**
* @param key the key to set
*/
public void setKey(String key) {
this.key = key;
}
}
......@@ -16,6 +16,7 @@
package nl.uva.sne.drip.commons.types;
import java.io.Serializable;
import java.util.Map;
/**
*
......@@ -27,6 +28,7 @@ public class Parameter implements Serializable {
private String encoding;
private String value;
private String name;
private Map<String, String> attributes;
public static final String NAME = "name";
public static final String URL = "url";
......@@ -74,4 +76,18 @@ public class Parameter implements Serializable {
this.value = value;
}
/**
* @return the attributes
*/
public Map<String, String> getAttributes() {
return attributes;
}
/**
* @param attributes the attributes to set
*/
public void setAttributes(Map<String, String> attributes) {
this.attributes = attributes;
}
}
......@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.rest;
package nl.uva.sne.drip.commons.types;
import java.util.Map;
import javax.persistence.Id;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
......@@ -29,6 +29,8 @@ public class ToscaRepresentation {
@Id
private String id;
private String name;
private Map<String, Object> kvMap;
public final String getId() {
......@@ -53,4 +55,18 @@ public class ToscaRepresentation {
this.kvMap = kvMap;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
}
/*
* 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.commons.types;
import nl.uva.sne.drip.commons.utils.PasswordUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.Collection;
import java.util.List;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
/**
*
* @author S. Koulouzis
*/
@JsonIgnoreProperties({"password"})
@Document
public class User implements UserDetails {
@Id
private String id;
private String username;
@JsonIgnore
private String password;
private List<String> roles;
private boolean expired;
private boolean nonLocked;
private boolean credentialsNonExpired;
private boolean enabled;
private Collection<? extends GrantedAuthority> authorities;
public void setPassword(String password) throws Exception {
this.password = PasswordUtil.hash(password);
}
public boolean isValide(String password) throws Exception {
if (this.password != null && password != null) {
return PasswordUtil.validate(this.password, password);
}
return false;
}
public List<String> getRoles() {
return roles;
}
public void setRoles(List<String> roles) {
this.roles = roles;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return this.authorities;
}
@Override
public String getUsername() {
return this.username;
}
@Override
public boolean isAccountNonExpired() {
return this.expired;
}
@Override
public boolean isAccountNonLocked() {
return this.nonLocked;
}
@Override
public boolean isCredentialsNonExpired() {
return this.credentialsNonExpired;
}
@Override
public boolean isEnabled() {
return this.enabled;
}
@Override
public String getPassword() {
return this.password;
}
}
/*
* 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.commons.utils;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*
* @author S. Koulouzis
*/
public class PasswordUtil {
public static String hash(String password) throws NoSuchAlgorithmException {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
messageDigest.update(password.getBytes());
return new String(messageDigest.digest());
}
public static boolean validate(String password, String password0) throws NoSuchAlgorithmException {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
messageDigest.update(password.getBytes());
String h1 = new String(messageDigest.digest());
messageDigest.update(password0.getBytes());
String h2 = new String(messageDigest.digest());
return h1.equals(h2);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<netbeans.hint.licensePath>${project.basedir}/../licenseheader.txt</netbeans.hint.licensePath>
</properties>
</project-shared-configuration>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>drip-planner</artifactId>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip-commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
<type>jar</type>
</dependency>
</dependencies>
</project>
\ No newline at end of file
/*
* 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.drip.planner;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.commons.types.Parameter;
import nl.uva.sne.drip.commons.types.Message;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
*
* @author S. Koulouzis
*/
public class Consumer extends DefaultConsumer {
private final Channel channel;
private final Planner panner;
public Consumer(Channel channel) {
super(channel);
this.channel = channel;
this.panner = new Planner();
}
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
AMQP.BasicProperties replyProps = new AMQP.BasicProperties.Builder()
.correlationId(properties.getCorrelationId())
.build();
String response = "";
try {
String message = new String(body, "UTF-8");
File[] inputFiles;
File tempDir = new File(System.getProperty("java.io.tmpdir") + File.separator + this.getClass().getSimpleName() + "-" + Long.toString(System.nanoTime()));
if (!(tempDir.mkdirs())) {
throw new FileNotFoundException("Could not create output directory: " + tempDir.getAbsolutePath());
}
inputFiles = jacksonUnmarshalExample(message);
panner.plan(inputFiles[0].getAbsolutePath(), inputFiles[1].getAbsolutePath(), tempDir.getAbsolutePath());
inputFiles = simpleJsonUnmarshalExample(message);
List<File> files = panner.plan(inputFiles[0].getAbsolutePath(), inputFiles[1].getAbsolutePath(), tempDir.getAbsolutePath());
response = jacksonMarshalExample(files);
System.err.println(response);
response = simpleJsonMarshalExample(files);
System.err.println(response);
} catch (JSONException | FileNotFoundException ex) {
response = ex.getMessage();
Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex);
} finally {
channel.basicPublish("", properties.getReplyTo(), replyProps, response.getBytes("UTF-8"));
channel.basicAck(envelope.getDeliveryTag(), false);
}
}
private File[] jacksonUnmarshalExample(String message) throws IOException {
File[] files = new File[2];
ObjectMapper mapper = new ObjectMapper();
Message request = mapper.readValue(message, Message.class);
List<Parameter> params = request.getParameters();
File inputFile = File.createTempFile("input-", Long.toString(System.nanoTime()));
File exampleFile = File.createTempFile("example-", Long.toString(System.nanoTime()));
for (Parameter param : params) {
if (param.getName().equals("input")) {
try (PrintWriter out = new PrintWriter(inputFile)) {
out.print(param.getValue());
}
files[0] = inputFile;
}
if (param.getName().equals("example")) {
try (PrintWriter out = new PrintWriter(exampleFile)) {
out.print(param.getValue());
}
files[1] = exampleFile;
}
}
return files;
}
private File[] simpleJsonUnmarshalExample(String message) throws JSONException, FileNotFoundException, IOException {
File[] files = new File[2];
JSONObject jo = new JSONObject(message);
JSONArray parameters = jo.getJSONArray("parameters");
File inputFile = File.createTempFile("input-", Long.toString(System.nanoTime()));
File exampleFile = File.createTempFile("example-", Long.toString(System.nanoTime()));
for (int i = 0; i < parameters.length(); i++) {
JSONObject param = (JSONObject) parameters.get(i);
String name = (String) param.get(Parameter.NAME);
if (name.equals("input")) {
try (PrintWriter out = new PrintWriter(inputFile)) {
out.print(param.get(Parameter.VALUE));
}
files[0] = inputFile;
}
if (name.equals("example")) {
try (PrintWriter out = new PrintWriter(exampleFile)) {
out.print(param.get(Parameter.VALUE));
}
files[1] = exampleFile;
}
}
return files;
}
private String jacksonMarshalExample(List<File> files) throws UnsupportedEncodingException, IOException {
Message responseMessage = new Message();
List parameters = new ArrayList();
String charset = "UTF-8";
for (File f : files) {
Parameter fileParam = new Parameter();
byte[] bytes = Files.readAllBytes(Paths.get(f.getAbsolutePath()));
fileParam.setValue(new String(bytes, charset));
fileParam.setEncoding(charset);
fileParam.setName(f.getName());
parameters.add(fileParam);
}
responseMessage.setParameters(parameters);
responseMessage.setCreationDate((System.currentTimeMillis()));
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(responseMessage);
}
private String simpleJsonMarshalExample(List<File> files) throws JSONException, IOException {
JSONObject jo = new JSONObject();
jo.put("creationDate", (System.currentTimeMillis()));
List parameters = new ArrayList();
String charset = "UTF-8";
for (File f : files) {
Map<String, String> fileArguments = new HashMap<>();
fileArguments.put("encoding", charset);
fileArguments.put("name", f.getName());
byte[] bytes = Files.readAllBytes(Paths.get(f.getAbsolutePath()));
fileArguments.put("value", new String(bytes, charset));
parameters.add(fileArguments);
}
jo.put("parameters", parameters);
return jo.toString();
}
}
/*
* 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.drip.planner;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
*
* @author S. Koulouzis
*/
public class Planner {
public List<File> plan(String input, String example, String outputDirPath) throws FileNotFoundException, IOException {
// TODO Auto-generated method stub
BufferedReader in;
in = new BufferedReader(new FileReader(input));
String line;
boolean check = false;
ArrayList<String> dockerNames = new ArrayList<>();
while ((line = in.readLine()) != null) {
if (line.contains("topology_template")) {
check = true;
}
if (check) {
if (line.contains("file")) {
String content = line.trim().replace('\"', ' ');
String[] cs = content.split(":");
String docker_name = cs[1].trim();
dockerNames.add(docker_name);
}
}
if (line.contains("tosca_definitions_version")
|| line.contains("description")
|| line.contains("repositories")
|| line.contains("artifact_types") || line.contains("data_types")
|| line.contains("node_types")) {
check = false;
}
}
in.close();
in = new BufferedReader(new FileReader(example));
String block = "";
String head = "";
boolean block_b = false;
while ((line = in.readLine()) != null) {
if (line.contains("components")) {
block_b = true;
continue;
}
if (block_b) {
block += line + "\n";
}
if (!block_b) {
head += line + "\n";
}
}
in.close();
UUID fuuid = UUID.randomUUID();
String file_guid = fuuid.toString();
String outfPath = outputDirPath + "/" + file_guid + ".yml";
FileWriter outputf = new FileWriter(outfPath);
outputf.write(head);
outputf.write("components:\n");
for (int i = 0; i < dockerNames.size(); i++) {
UUID uuid = UUID.randomUUID();
String name_guid = uuid.toString();
String privateAddress = "192.168.10." + (i + 10);
if (i == 0) {
outputf.write(generateVM(block, name_guid, dockerNames.get(i), privateAddress, "master"));
} else {
outputf.write(generateVM(block, name_guid, dockerNames.get(i), privateAddress, "slave"));
}
}
outputf.close();
String allFilePath = outputDirPath + "/" + "planner_output_all.yml";
outputf = new FileWriter(allFilePath);
outputf.write("topologies:\n");
outputf.write(" - topology: " + file_guid + "\n");
outputf.write(" cloudProvider: EC2\n");
outputf.close();
List<File> outputFiles = new ArrayList<>();
outputFiles.add(new File(outfPath));
outputFiles.add(new File(allFilePath));
return outputFiles;
}
private String generateVM(String block, String nodeName, String dockerName, String privateAddress, String role) {
block = block.replaceAll("nodeA", nodeName);
block = block.replaceAll("DOCKER", "\"" + dockerName + "\"");
block = block.replaceAll("192.168.10.10", privateAddress);
block = block.replaceAll("ROLE", role);
return block;
}
}
/*
* 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.drip.planner;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author S. Koulouzis
*/
public class RPCServer {
private static final String RPC_QUEUE_NAME = "planner_queue";
private static final String HOST = "172.17.0.2";
public static void main(String[] argv) {
start();
}
private static void start() {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(HOST);
try (Connection connection = factory.newConnection()) {
Channel channel = connection.createChannel();
channel.queueDeclare(RPC_QUEUE_NAME, false, false, false, null);
Consumer c = new Consumer(channel);
channel.basicConsume(RPC_QUEUE_NAME, false, c);
//Block so we don't close the channel
while (true) {
try {
Thread.sleep(100);
} catch (InterruptedException _ignore) {
}
}
} catch (IOException | TimeoutException ex) {
Logger.getLogger(RPCServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
......@@ -11,6 +11,6 @@
<modules>
<module>drip-api</module>
<module>drip-commons</module>
<module>drip-planner</module>
<module>drip-simple_planner</module>
</modules>
</project>
\ 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