Commit bcffffd4 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Implemented Planning API v0

parent 2f8b45bf
......@@ -75,6 +75,19 @@ public class ToscaService {
return t.getId();
}
public String save(String yamlString, String name) throws IOException {
if (name == null) {
name = System.currentTimeMillis() + "_" + "tosca.yaml";
}
yamlString = yamlString.replaceAll("\\.", "\uff0E");
Map<String, Object> map = Converter.ymlString2Map(yamlString);
ToscaRepresentation t = new ToscaRepresentation();
t.setName(name);
t.setKvMap(map);
dao.save(t);
return t.getId();
}
public void delete(String id) {
dao.delete(id);
}
......
......@@ -16,6 +16,8 @@
package nl.uva.sne.drip.api.v0.rest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -31,7 +33,9 @@ import nl.uva.sne.drip.api.service.PlannerService;
import nl.uva.sne.drip.api.service.ToscaService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.commons.v0.types.File;
import nl.uva.sne.drip.commons.v0.types.Plan;
import org.apache.commons.io.FilenameUtils;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -57,14 +61,50 @@ public class PlannerController0 {
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
Result plan(@RequestBody Plan plan0) {
try {
nl.uva.sne.drip.commons.v1.types.ToscaRepresentation toscaRep = new nl.uva.sne.drip.commons.v1.types.ToscaRepresentation();
toscaRep.setKvMap(Converter.ymlString2Map(plan0.getFile()));
toscaService.getDao().save(toscaRep);
nl.uva.sne.drip.commons.v1.types.Plan plan1 = plannerService.getPlan(toscaRep.getId());
String yaml = plan0.getFile();
yaml = yaml.replaceAll("\\\\n", "\n");
String id = toscaService.save(yaml, null);
nl.uva.sne.drip.commons.v1.types.Plan plan1 = plannerService.getPlan(id);
return null;
} catch (JSONException | IOException | TimeoutException | InterruptedException ex) {
Result r = new Result();
r.setInfo("INFO");
r.setStatus(Result.status.Success);
List<File> files = new ArrayList<>();
File e = new File();
e.level = String.valueOf(plan1.getLevel());
String p1Name = FilenameUtils.getBaseName(plan1.getName());
if (p1Name == null) {
p1Name = "Planned_tosca_file_" + plan1.getLevel();
plan1.setName(p1Name);
plannerService.getDao().save(plan1);
}
e.name = p1Name;
e.content = Converter.map2YmlString(plan1.getKvMap()).replaceAll("\n", "\\n");
files.add(e);
for (String lowiID : plan1.getLoweLevelPlanIDs()) {
nl.uva.sne.drip.commons.v1.types.Plan lowPlan1 = plannerService.getDao().findOne(lowiID);
e = new File();
e.level = String.valueOf(lowPlan1.getLevel());
p1Name = lowPlan1.getName();
if (p1Name == null) {
p1Name = "Planned_tosca_file_" + lowPlan1.getLevel();
plan1.setName(p1Name);
plannerService.getDao().save(lowPlan1);
}
e.name = p1Name;
e.content = Converter.map2YmlString(lowPlan1.getKvMap()).replaceAll("\n", "\\n");;
files.add(e);
}
r.file = files;
return r;
} catch (IOException | JSONException | TimeoutException | InterruptedException ex) {
Logger.getLogger(PlannerController0.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
......@@ -73,13 +113,19 @@ public class PlannerController0 {
@RequestMapping(value = "/get", method = RequestMethod.GET, produces = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
Plan plan() {
Plan p = new Plan();
p.setFile("tosca_definitions_version: tosca_simple_yaml_1_0\\n\\n\\ndescription: example file for infrastructure planner\\n\\n\\nrepositories:\\n MOG_docker_hub: \\n description: MOG project’s code repository in GitHub\\n url: https://github.com/switch-project/mog\\n credential:\\n protocol: xauth\\n token_type: X-Auth-Token\\n # token encoded in Base64\\n token: 604bbe45ac7143a79e14f3158df67091\\n\\n\\nartifact_types:\\n tosca.artifacts.Deployment.Image.Container.Docker:\\n derived_from: tosca.artifacts.Deployment.Image\\n\\n\\ndata_types:\\n Switch.datatypes.QoS.AppComponent:\\n derived_from: tosca.datatypes.Root\\n properties:\\n response_time:\\n type: string\\n\\n Switch.datatypes.Application.Connection.EndPoint:\\n derived_from: tosca.datatypes.Root\\n properties:\\n address:\\n type: string\\n component_name:\\n type: string\\n netmask:\\n type: string\\n port_name:\\n type: string\\n\\n Switch.datatypes.Application.Connection.Multicast:\\n derived_from: tosca.datatypes.Root\\n properties:\\n multicastAddrIP:\\n type: string\\n multicastAddrPort:\\n type: integer\\n\\n Switch.datatypes.Network.EndPoint:\\n derived_from: tosca.datatypes.Root\\n properties:\\n address:\\n type: string\\n host_name:\\n type: string\\n netmask:\\n type: string\\n port_name:\\n type: string\\n\\n Switch.datatypes.Network.Multicast:\\n derived_from: tosca.datatypes.Root\\n properties:\\n multicastAddrIP:\\n type: string\\n multicastAddrPort:\\n type: integer\\n\\n\\nnode_types:\\n\\n Switch.nodes.Application.Container.Docker:\\n derived_from: tosca.nodes.Container.Application\\n properties:\\n QoS:\\n type: Switch.datatypes.QoS.AppComponent\\n artifacts:\\n docker_image:\\n type: tosca.artifacts.Deployment.Image.Container.Docker\\n interfaces:\\n Standard:\\n create:\\n inputs:\\n command:\\n type: string\\n exported_ports:\\n type: list\\n entry_schema:\\n type: string\\n port_bindings:\\n type: list\\n entry_schema:\\n type: string\\n\\n Switch.nodes.Application.Container.Docker.MOG.InputDistributor:\\n derived_from: Switch.nodes.Application.Container.Docker\\n artifacts:\\n docker_image:\\n type: tosca.artifacts.Deployment.Image.Container.Docker\\n file: \"mogswitch/InputDistributor:1.0\"\\n repository: MOG_docker_hub\\n properties:\\n inPort: \\n type: integer\\n waitingTime:\\n type: integer\\n multicastAddrIP:\\n type: string\\n multicastAddrPort:\\n type: integer\\n videoWidth:\\n type: integer\\n videoHeight:\\n type: integer\\n\\n Switch.nodes.Application.Container.Docker.MOG.ProxyTranscoder:\\n derived_from: Switch.nodes.Application.Container.Docker \\n artifacts:\\n docker_image:\\n type: tosca.artifacts.Deployment.Image.Container.Docker\\n file: \"mogswitch/ProxyTranscoder:1.0\"\\n repository: MOG_docker_hub\\n properties:\\n multicastAddrIP: \\n type: string\\n multicastAddrPort:\\n type: integer\\n videoWidth:\\n type: integer\\n videoHeight:\\n type: integer\\n\\n Switch.nodes.Application.Connection:\\n derived_from: tosca.nodes.Root \\n properties:\\n source:\\n type: Switch.datatypes.Application.Connection.EndPoint\\n target:\\n type: Switch.datatypes.Application.Connection.EndPoint\\n bandwidth:\\n type: string\\n latency: \\n type: string\\n jitter: \\n type: string\\n multicast:\\n type: Switch.datatypes.Application.Connection.Multicast\\n\\n Switch.nodes.Compute:\\n derived_from: tosca.nodes.Compute\\n properties:\\n OStype:\\n type: string\\n nodetype:\\n type: string\\n domain:\\n type: string\\n public_address:\\n type: string\\n \n"
+ " ethernet_port:\\n type: list\\n entry_schema:\\n type: tosca.datatypes.network.NetworkInfo\\n script:\\n type: string\\n installation:\\n type: string\\n ssh_credential:\\n type: tosca.datatypes.Credential\\n\\n Switch.nodes.Network:\\n derived_from: tosca.nodes.network.Network\\n properties:\\n bandwidth:\\n type: string\\n latency:\\n type: string\\n jitter:\\n type: string\\n source:\\n type: Switch.datatypes.Network.EndPoint\\n target:\\n type: Switch.datatypes.Network.EndPoint\\n multicast:\\n type: Switch.datatypes.Network.Multicast\\n\\n\\ntopology_template:\\n \\n node_templates:\\n 2d13d708e3a9441ab8336ce874e08dd1:\\n type: Switch.nodes.Application.Container.Docker.MOG.InputDistributor\\n artifacts:\\n docker_image:\\n file: \"mogswitch/InputDistributor:1.0\"\\n type: tosca.artifacts.Deployment.Image.Container.Docker\\n repository: MOG_docker_hub\\n properties:\\n QoS:\\n response_time: 30ms\\n inPort: 2000\\n waitingTime: 5\\n multicastAddrIP: 255.2.2.0\\n multicastAddrPort: 3000\\n videoWidth: 176\\n videoHeight: 100\\n interfaces:\\n Standard:\\n create:\\n implementation: docker_image\\n inputs:\\n command: InputDistributor\\n exported_ports:\\n - 2000\\n port_bindings:\\n - \"2000:2000\"\\n - \"3000:3000\"\\n\\n 8fcc1788d9ee462c826572c79fdb2a6a:\\n type: Switch.nodes.Application.Container.Docker.MOG.ProxyTranscoder\\n artifacts:\\n docker_image:\\n file: \"mogswitch/ProxyTranscoder:1.0\"\\n type: tosca.artifacts.Deployment.Image.Container.Docker\\n repository: MOG_docker_hub\\n properties:\\n QoS:\\n response_time: 30ms\\n multicastAddrIP: 255.2.2.0\\n multicastAddrPort: 3000\\n videoWidth: 176\\n videoHeight: 100\\n interfaces:\\n Standard:\\n create:\\n implementation: docker_image\\n inputs:\\n command: ProxyTranscoder\\n exported_ports:\\n - 80\\n port_bindings:\\n - \"8080:80\"\\n\\n 5e0add703c8a43938a39301f572e46c0:\\n type: Switch.nodes.Application.Connection\\n properties:\\n source:\\n address: 192.168.21.11\\n component_name: 2d13d708e3a9441ab8336ce874e08dd1\\n netmask: 255.255.255.0\\n port_name: \"inputDistributor_out\"\\n target:\\n address: 192.168.21.12\\n component_name: 8fcc1788d9ee462c826572c79fdb2a6a\\n netmask: 255.255.255.0\\n port_name: \"proxyTranscoder_in\"\\n latency: 30ms\\n bandwidth: 130MB/s\\n jitter: 500ms\\n multicast:\\n multicastAddrIP: 255.2.2.0\\n multicastAddrPort: 3000\\n");
p.setPwd("123");
p.setUser("user");
return p;
Result plan() {
Result r = new Result();
r.setInfo("INFO");
r.setStatus(Result.status.Success);
List<File> files = new ArrayList<>();
File e = new File();
e.level = "0";
e.name = "Planned_tosca_file_a.yaml";
e.content = "$Planned_tosca_file_a";
files.add(e);
r.file = files;
return r;
}
}
......@@ -105,7 +105,7 @@ public class UserScriptController {
*
* @return a list of all the IDs
*/
@RequestMapping(value = "/ids")
@RequestMapping(value = "/ids", method = RequestMethod.GET)
public @ResponseBody
List<String> getIds() {
List<UserScript> all = dao.findAll();
......
/*
* 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.v0.types;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlValue;
/**
*
* @author S. Koulouzis
*/
public class File {
@XmlAttribute
public String name;
@XmlAttribute
public String level;
@XmlValue
public String content;
}
......@@ -17,7 +17,6 @@ package nl.uva.sne.drip.commons.v0.types;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
......
......@@ -15,6 +15,10 @@
*/
package nl.uva.sne.drip.commons.v0.types;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
/**
......@@ -24,4 +28,40 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Result {
private status status;
private String info;
public List<File> file;
/**
* @return the type
*/
public status getStatus() {
return status;
}
public void setStatus(status status) {
this.status = status;
}
public static enum status {
Success,
Fail
}
/**
* @return the info
*/
public String getInfo() {
return info;
}
/**
* @param info the info to set
*/
public void setInfo(String info) {
this.info = info;
}
}
......@@ -53,7 +53,7 @@ public class UserScript {
*
* @return the name
*/
@DocumentationExample("client.py")
@DocumentationExample("config.sh")
public String getName() {
return name;
}
......@@ -70,14 +70,6 @@ public class UserScript {
*
* @return the contents
*/
@DocumentationExample("config.sh")
public String getContents() {
return contents;
}
/**
* @param contents the contents to set
*/
@DocumentationExample(" #!/bin/bash\n"
+ "echo \"Reading system-wide config....\" >&2\\n"
+ ". /etc/cool.cfg\n"
......@@ -85,6 +77,13 @@ public class UserScript {
+ " echo \"Reading user config....\" >&2\\n"
+ " . ~/.coolrc\\n"
+ "fi")
public String getContents() {
return contents;
}
/**
* @param contents the contents to set
*/
public void setContents(String contents) {
this.contents = contents;
}
......
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