Commit c0b42137 authored by Spiros Koulouzis's avatar Spiros Koulouzis

added debug messages

parent 632cb1d3
...@@ -17,22 +17,22 @@ description: > ...@@ -17,22 +17,22 @@ description: >
topology_template: topology_template:
node_templates: node_templates:
mysql: mongo:
type: tosca.nodes.ARTICONF.Container.Application.Docker type: tosca.nodes.ARTICONF.Container.Application.Docker
properties: properties:
ports: ports:
- "3306:3306" - "27017:27017"
volumes: volumes:
- db_data:/var/lib/mysql - db-data:/data/db
environment: environment:
MYSQL_ROOT_PASSWORD: somewordpress ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress DATABASE: db
MYSQL_USER: wordpress USER: user
MYSQL_PASSWORD: wordpress PASSWORD: passwd
artifacts: artifacts:
image: image:
type: tosca.artifacts.Deployment.Image.Container.Docker type: tosca.artifacts.Deployment.Image.Container.Docker
file: mysql:5.7 file: mongo:3
repository: docker_hub repository: docker_hub
...@@ -40,12 +40,12 @@ topology_template: ...@@ -40,12 +40,12 @@ topology_template:
type: tosca.nodes.ARTICONF.Container.Application.Docker type: tosca.nodes.ARTICONF.Container.Application.Docker
properties: properties:
ports: ports:
- "8000:80" - "30000:80"
volumes: volumes:
- /etc/hostname:/etc/host_hostname:ro - /etc/hostname:/etc/host_hostname:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock
environment: environment:
publish: "127.0.0.1:8000:80" publish: "127.0.0.1:30000:80"
artifacts: artifacts:
image: image:
type: tosca.artifacts.Deployment.Image.Container.Docker type: tosca.artifacts.Deployment.Image.Container.Docker
...@@ -55,12 +55,12 @@ topology_template: ...@@ -55,12 +55,12 @@ topology_template:
policies: policies:
- scalability: - scalability:
type: tosca.policies.ARTICONF.Performance.CPU type: tosca.policies.ARTICONF.Performance.CPU
targets: [ mysql ] targets: [ mongo ]
properties: properties:
constraint_name: cpu_load constraint_name: cpu_load
max_value: 90 max_value: 90
- faultTolerance: - faultTolerance:
type: tosca.policies.ARTICONF.FaultTolerance type: tosca.policies.ARTICONF.FaultTolerance
targets: [ mysql ] targets: [ mongo ]
properties: properties:
level: 1 level: 1
This diff is collapsed.
...@@ -82,9 +82,11 @@ public class ToscaHelper { ...@@ -82,9 +82,11 @@ public class ToscaHelper {
String ymlStr = objectMapper.writeValueAsString(toscaTemplate); String ymlStr = objectMapper.writeValueAsString(toscaTemplate);
File toscaTemplateFile = File.createTempFile("temp-toscaTemplate", ".yml"); File toscaTemplateFile = File.createTempFile("temp-toscaTemplate", ".yml");
FileUtils.writeByteArrayToFile(toscaTemplateFile, ymlStr.getBytes()); FileUtils.writeByteArrayToFile(toscaTemplateFile, ymlStr.getBytes());
Logger.getLogger(ToscaHelper.class.getName()).log(Level.INFO, "Uploading ToscaTemplate to sure-tosca service....");
String resp = api.uploadToscaTemplate(toscaTemplateFile); String resp = api.uploadToscaTemplate(toscaTemplateFile);
id = Integer.valueOf(resp); id = Integer.valueOf(resp);
Logger.getLogger(ToscaHelper.class.getName()).log(Level.FINE, "Uploaded ToscaTemplate to sure-tosca service got back id: " + id); toscaTemplateFile.deleteOnExit();
Logger.getLogger(ToscaHelper.class.getName()).log(Level.INFO, "Uploaded ToscaTemplate to sure-tosca service got back id: {0}", id);
} }
public List<Map<String, Object>> getProvisionInterfaceDefinitions(List<String> toscaInterfaceTypes) throws ApiException { public List<Map<String, Object>> getProvisionInterfaceDefinitions(List<String> toscaInterfaceTypes) throws ApiException {
......
...@@ -83,4 +83,8 @@ public class Message implements Serializable { ...@@ -83,4 +83,8 @@ public class Message implements Serializable {
this.toscaTemplate = toscaTemplate; this.toscaTemplate = toscaTemplate;
} }
public void setExeption(Exception exception) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
} }
...@@ -74,9 +74,9 @@ def handle_delivery(message): ...@@ -74,9 +74,9 @@ def handle_delivery(message):
vms = tosca.get_vms(tosca_template_json) vms = tosca.get_vms(tosca_template_json)
inventory_path = ansible_service.write_inventory_file(tmp_path, vms) inventory_path = ansible_service.write_inventory_file(tmp_path, vms)
paths = ansible_service.write_playbooks_from_tosca_interface(interfaces, tmp_path) paths = ansible_service.write_playbooks_from_tosca_interface(interfaces, tmp_path)
for playbook_path in paths: # for playbook_path in paths:
out,err = ansible_service.run(inventory_path,playbook_path) # out,err = ansible_service.run(inventory_path,playbook_path)
api_key, join_token, discovery_token_ca_cert_hash = ansible_service.parse_tokens(out.decode("utf-8")) # api_key, join_token, discovery_token_ca_cert_hash = ansible_service.parse_tokens(out.decode("utf-8"))
ansible_playbook_path = k8s_service.write_ansible_k8s_files(tosca_template_json, tmp_path) ansible_playbook_path = k8s_service.write_ansible_k8s_files(tosca_template_json, tmp_path)
out, err = ansible_service.run(inventory_path, ansible_playbook_path) out, err = ansible_service.run(inventory_path, ansible_playbook_path)
......
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: NAME
name: NAME
namespace: application
spec:
selector:
matchLabels:
app: NAME
replicas: 1
template:
metadata:
labels:
app: NAME
spec:
containers:
- image: IMAGE_NAME
name: NAME
ports:
- containerPort: PORT
env:
- name: ENV_NAME
value: ENV_VAL
apiVersion: v1
kind: Service
metadata:
labels:
app: NAME
name: NAME
namespace: application
spec:
type: NodePort
ports:
- port: CONTAINER_PORT
nodePort: NODE_PORT
selector:
app: NAME
import os
from _ast import mod from _ast import mod
import yaml import yaml
...@@ -5,6 +6,18 @@ import yaml ...@@ -5,6 +6,18 @@ import yaml
yaml.Dumper.ignore_aliases = lambda *args: True yaml.Dumper.ignore_aliases = lambda *args: True
def get_template_dictionary(file_name):
template_path = "./k8s/"
template_file_path = template_path + file_name
if not os.path.exists(template_file_path):
template_path = "../k8s/"
template_file_path = template_path + file_name
with open(template_file_path, 'r') as stream:
data = yaml.safe_load(stream)
return data
def get_dockers(tosca_template_json): def get_dockers(tosca_template_json):
dockers = [] dockers = []
node_templates = tosca_template_json['topology_template']['node_templates'] node_templates = tosca_template_json['topology_template']['node_templates']
...@@ -15,47 +28,84 @@ def get_dockers(tosca_template_json): ...@@ -15,47 +28,84 @@ def get_dockers(tosca_template_json):
return dockers return dockers
def create_service_definition(docker_name, docker):
k8s_service = get_template_dictionary('template-service.yaml')
k8s_service['metadata']['labels']['app'] = docker_name
k8s_service['metadata']['name'] = docker_name
docker_ports = docker[docker_name]['properties']['ports'][0].split(':')
k8s_service['spec']['ports'][0]['port'] = docker_ports[1]
k8s_service['spec']['ports'][0]['nodePort'] = docker_ports[0]
k8s_service['spec']['selector']['app'] = docker_name
# k8s_service = {'apiVersion': 'v1', 'kind': 'Service'}
# labels = {'app': docker_name}
# metadata = {'labels': labels, 'name': docker_name, 'namespace': 'application'}
# k8s_service['metadata'] = metadata
# spec = {'type': 'NodePort'}
# port = {'port': docker_ports[1], 'nodePort': docker_ports[0]}
# ports = [port]
# spec['ports'] = ports
# app = {'app': docker_name}
# spec['selector'] = app
# k8s_service['spec'] = spec
# # print(yaml.safe_dump(k8s_service))
return k8s_service
def create_deployment_definition(docker_name, docker):
docker_ports = docker[docker_name]['properties']['ports'][0].split(':')
deployment = get_template_dictionary('template-deployment.yaml')
deployment['metadata']['labels']['app'] = docker_name
deployment['metadata']['name'] = docker_name
deployment['spec']['selector']['matchLabels']['app'] = docker_name
deployment['spec']['template']['metadata']['labels']['app'] = docker_name
deployment['spec']['template']['spec']['containers'][0]['image'] = docker[docker_name]['artifacts']['image']['file']
deployment['spec']['template']['spec']['containers'][0]['ports'][0]['containerPort'] = docker_ports[1]
deployment['spec']['template']['spec']['containers'][0]['name'] = docker_name
if docker[docker_name]['properties'] and 'environment' in docker[docker_name]['properties']:
env_list = []
for env in docker[docker_name]['properties']['environment']:
k8s_env = {'name': env, 'value': docker[docker_name]['properties']['environment'][env]}
env_list.append(k8s_env)
deployment['spec']['template']['spec']['containers'][0]['env'] = env_list
# labels = {'app': docker_name}
# metadata = {'labels': labels, 'name': docker_name, 'namespace': 'application'}
# deployment = {'apiVersion': 'apps/v1', 'kind': 'Deployment', 'metadata': metadata}
#
# match_labels = {'app': docker_name}
# selector = {'matchLabels': match_labels}
# spec = {'selector': selector, 'replicas': 1}
# labels = {'app': docker_name}
# metadata = {'labels': labels}
# template = {'metadata': metadata}
#
# containers = []
# container = {'image': docker[docker_name]['artifacts']['image']['file'], 'name': docker_name}
# docker_ports = docker[docker_name]['properties']['ports'][0].split(':')
# ports = {'containerPort': docker_ports[1]}
# container['ports'] = ports
# containers.append(container)
# template_spec = {'containers': containers}
# template['spec'] = template_spec
#
# spec['template'] = template
#
# deployment['spec'] = spec
return deployment
def get_k8s_definitions(dockers): def get_k8s_definitions(dockers):
k8s_services = [] k8s_services = []
k8s_deployments = [] k8s_deployments = []
definitions = {} definitions = {}
for docker in dockers: for docker in dockers:
docker_name = next(iter(docker)) docker_name = next(iter(docker))
k8s_service = {'apiVersion': 'v1', 'kind': 'Service'}
labels = {'app': docker_name} k8s_service = create_service_definition(docker_name, docker)
metadata = {'labels': labels, 'name': docker_name}
k8s_service['metadata'] = metadata
spec = {'type': 'NodePort'}
docker_ports = docker[docker_name]['properties']['ports'][0].split(':')
ports = {'port': docker_ports[1], 'nodePort': docker_ports[0]}
spec['ports'] = ports
app = {'app': docker_name}
spec['selector'] = app
k8s_service['spec'] = spec
# print(yaml.safe_dump(k8s_service))
k8s_services.append(k8s_service) k8s_services.append(k8s_service)
# ----------------------------------------------------------- # -----------------------------------------------------------
deployment = {'apiVersion': 'apps/v1', 'kind': 'Deployment', 'metadata': metadata} deployment = create_deployment_definition(docker_name, docker)
match_labels = {'app': docker_name}
selector = {'matchLabels': match_labels}
spec = {'selector': selector, 'replicas': 1}
labels['app'] = docker_name
metadata = {'labels': labels}
template = {'metadata': metadata}
containers = []
container = {'image': docker[docker_name]['artifacts']['image']['file'], 'name': docker_name}
ports = {'containerPort': docker_ports[1]}
container['ports'] = ports
containers.append(container)
template_spec = {'containers': containers}
template['spec'] = template_spec
spec['template'] = template
deployment['spec'] = spec
k8s_deployments.append(deployment) k8s_deployments.append(deployment)
# print(yaml.dump(deployment)) # print(yaml.dump(deployment))
definitions['services'] = k8s_services definitions['services'] = k8s_services
...@@ -63,6 +113,35 @@ def get_k8s_definitions(dockers): ...@@ -63,6 +113,35 @@ def get_k8s_definitions(dockers):
return definitions return definitions
def create_pip_task():
pip_task = {'name': 'install kubernetes'}
modules = ['setuptools', 'kubernetes', 'openshift']
pip = {'name': modules}
pip_task['pip'] = pip
return pip_task
def create_service_task(i, services_def):
task = {'name': 'Create a Service object' + str(i)}
k8s = {'state': 'present', 'definition': services_def}
task['k8s'] = k8s
return task
def create_deployment_task(i, deployments_def):
task = {'name': 'Create a deployment object' + str(i)}
k8s = {'state': 'present', 'definition': deployments_def}
task['k8s'] = k8s
return task
def create_namespace_task():
task = {'name': 'create namespace'}
k8s = {'name': 'application', 'api_version': 'v1', 'kind': 'Namespace', 'state': 'present'}
task['k8s'] = k8s
return task
def write_ansible_k8s_files(tosca_template_json, tmp_path): def write_ansible_k8s_files(tosca_template_json, tmp_path):
dockers = get_dockers(tosca_template_json) dockers = get_dockers(tosca_template_json)
k8s_definitions = get_k8s_definitions(dockers) k8s_definitions = get_k8s_definitions(dockers)
...@@ -70,23 +149,20 @@ def write_ansible_k8s_files(tosca_template_json, tmp_path): ...@@ -70,23 +149,20 @@ def write_ansible_k8s_files(tosca_template_json, tmp_path):
deployments = k8s_definitions['deployments'] deployments = k8s_definitions['deployments']
i = 0 i = 0
tasks = [] tasks = []
pip_task = {'name': 'install kubernetes'} pip_task = create_pip_task()
modules = ['setuptools', 'kubernetes', 'pkg_resources']
pip = {'name': modules}
pip_task['pip'] = pip
tasks.append(pip_task) tasks.append(pip_task)
namespace_task = create_namespace_task()
tasks.append(namespace_task)
for services_def in services: for services_def in services:
task = {'name': 'Create a Service object' + str(i)} task = create_service_task(i, services_def)
k8s = {'state': 'present', 'definition': services_def}
task['k8s'] = k8s
i += 1 i += 1
tasks.append(task) tasks.append(task)
i = 0 i = 0
for deployments_def in deployments: for deployments_def in deployments:
task = {'name': 'Create a deployment object' + str(i)} task = create_deployment_task(i, deployments_def)
k8s = {'state': 'present', 'definition': deployments_def}
task['k8s'] = k8s
i += 1 i += 1
tasks.append(task) tasks.append(task)
...@@ -98,4 +174,5 @@ def write_ansible_k8s_files(tosca_template_json, tmp_path): ...@@ -98,4 +174,5 @@ def write_ansible_k8s_files(tosca_template_json, tmp_path):
with open(ansible_playbook_path, 'w') as file: with open(ansible_playbook_path, 'w') as file:
documents = yaml.dump(ansible_playbook, file) documents = yaml.dump(ansible_playbook, file)
return ansible_playbook_path return ansible_playbook_path
import copy
import json
import logging
import os
import os.path
import tempfile
import time
import unittest
from service import k8s_service, tosca, ansible_service
class TestDeployer(unittest.TestCase):
def test(self):
logger = logging.getLogger(__name__)
tosca_path = "../../TOSCA/"
input_tosca_file_path = tosca_path + '/message_example_provisioned.json'
if not os.path.exists(input_tosca_file_path):
tosca_path = "../TOSCA/"
input_tosca_file_path = tosca_path + '/message_example_provisioned.json'
with open(input_tosca_file_path, 'r') as stream:
parsed_json_message = json.load(stream)
# parsed_json_message = json.loads(message)
owner = parsed_json_message['owner']
tosca_file_name = 'tosca_template'
tosca_template_json = parsed_json_message['toscaTemplate']
interfaces = tosca.get_interfaces(tosca_template_json)
tmp_path = tempfile.mkdtemp()
vms = tosca.get_vms(tosca_template_json)
inventory_path = ansible_service.write_inventory_file(tmp_path, vms)
paths = ansible_service.write_playbooks_from_tosca_interface(interfaces, tmp_path)
# for playbook_path in paths:
# out,err = ansible_service.run(inventory_path,playbook_path)
# api_key, join_token, discovery_token_ca_cert_hash = ansible_service.parse_tokens(out.decode("utf-8"))
ansible_playbook_path = k8s_service.write_ansible_k8s_files(tosca_template_json, tmp_path)
# out, err = ansible_service.run(inventory_path, ansible_playbook_path)
if __name__ == '__main__':
import unittest
unittest.main()
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/drip-deployer.iml" filepath="$PROJECT_DIR$/.idea/drip-deployer.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="350a2cb3-d21f-4a78-bd8c-7614f85494cc" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/../deployer/__main__.py" beforeDir="false" afterPath="$PROJECT_DIR$/../deployer/__main__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../deployer/service/ansible_service.py" beforeDir="false" afterPath="$PROJECT_DIR$/../deployer/service/ansible_service.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../deployer/service/k8s_service.py" beforeDir="false" afterPath="$PROJECT_DIR$/../deployer/service/k8s_service.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../provisioner/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../provisioner/pom.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component>
<component name="ProjectId" id="1XDOwMpLrjLoOX7wa6ziawR8wDT" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showExcludedFiles" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../deployer" />
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="350a2cb3-d21f-4a78-bd8c-7614f85494cc" name="Default Changelist" comment="" />
<created>1580577435383</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1580577435383</updated>
</task>
<servers />
</component>
<component name="WindowStateProjectService">
<state x="1043" y="437" width="530" height="598" key="FileChooserDialogImpl" timestamp="1580577475090">
<screen x="67" y="34" width="2493" height="1406" />
</state>
<state x="1043" y="437" width="530" height="598" key="FileChooserDialogImpl/67.34.2493.1406@67.34.2493.1406" timestamp="1580577475090" />
</component>
</project>
\ No newline at end of file
...@@ -2,6 +2,7 @@ package nl.uva.sne.drip.api; ...@@ -2,6 +2,7 @@ package nl.uva.sne.drip.api;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import java.util.logging.Level;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
...@@ -47,6 +48,7 @@ public class DeployerApiController implements DeployerApi { ...@@ -47,6 +48,7 @@ public class DeployerApiController implements DeployerApi {
return new ResponseEntity<>(planedYemplateId, HttpStatus.OK); return new ResponseEntity<>(planedYemplateId, HttpStatus.OK);
} catch (Exception ex) { } catch (Exception ex) {
java.util.logging.Logger.getLogger(DeployerApiController.class.getName()).log(Level.SEVERE, null, ex);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} }
......
...@@ -2,6 +2,7 @@ package nl.uva.sne.drip.api; ...@@ -2,6 +2,7 @@ package nl.uva.sne.drip.api;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import java.util.logging.Level;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
...@@ -45,8 +46,10 @@ public class PlannerApiController implements PlannerApi { ...@@ -45,8 +46,10 @@ public class PlannerApiController implements PlannerApi {
String planedYemplateId = dripService.plan(id); String planedYemplateId = dripService.plan(id);
return new ResponseEntity<>(planedYemplateId, HttpStatus.OK); return new ResponseEntity<>(planedYemplateId, HttpStatus.OK);
} catch (ApiException ex) { } catch (ApiException ex) {
java.util.logging.Logger.getLogger(PlannerApiController.class.getName()).log(Level.SEVERE, null, ex);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (Exception ex) { } catch (Exception ex) {
java.util.logging.Logger.getLogger(PlannerApiController.class.getName()).log(Level.SEVERE, null, ex);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} }
} }
......
...@@ -49,8 +49,10 @@ public class ProvisionerApiController implements ProvisionerApi { ...@@ -49,8 +49,10 @@ public class ProvisionerApiController implements ProvisionerApi {
String planedYemplateId = dripService.provision(id); String planedYemplateId = dripService.provision(id);
return new ResponseEntity<>(planedYemplateId, HttpStatus.OK); return new ResponseEntity<>(planedYemplateId, HttpStatus.OK);
} catch (ApiException ex) { } catch (ApiException ex) {
java.util.logging.Logger.getLogger(ProvisionerApiController.class.getName()).log(Level.SEVERE, null, ex);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (Exception ex) { } catch (Exception ex) {
java.util.logging.Logger.getLogger(ProvisionerApiController.class.getName()).log(Level.SEVERE, null, ex);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} }
} }
......
...@@ -57,6 +57,7 @@ public class ToscaTemplateApiController implements ToscaTemplateApi { ...@@ -57,6 +57,7 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
return new ResponseEntity<>(ymlStr, HttpStatus.OK); return new ResponseEntity<>(ymlStr, HttpStatus.OK);
} catch (IOException e) { } catch (IOException e) {
log.error("Couldn't serialize response for content type ", e); log.error("Couldn't serialize response for content type ", e);
java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.SEVERE, null, e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (NotFoundException ex) { } catch (NotFoundException ex) {
java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.SEVERE, null, ex);
...@@ -78,6 +79,7 @@ public class ToscaTemplateApiController implements ToscaTemplateApi { ...@@ -78,6 +79,7 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
return new ResponseEntity<>(id, HttpStatus.OK); return new ResponseEntity<>(id, HttpStatus.OK);
} catch (IOException e) { } catch (IOException e) {
log.error("Couldn't serialize response for content type ", e); log.error("Couldn't serialize response for content type ", e);
java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.SEVERE, null, e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} }
} }
...@@ -93,6 +95,7 @@ public class ToscaTemplateApiController implements ToscaTemplateApi { ...@@ -93,6 +95,7 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
String id = toscaTemplateService.saveFile(file); String id = toscaTemplateService.saveFile(file);
return new ResponseEntity<>(id, HttpStatus.OK); return new ResponseEntity<>(id, HttpStatus.OK);
} catch (IOException e) { } catch (IOException e) {
java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.SEVERE, null, e);
log.error("Couldn't serialize response for content type application/json", e); log.error("Couldn't serialize response for content type application/json", e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} }
......
...@@ -16,6 +16,7 @@ import javax.validation.constraints.*; ...@@ -16,6 +16,7 @@ import javax.validation.constraints.*;
import javax.validation.Valid; import javax.validation.Valid;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-10-10T17:15:46.465Z") @javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-10-10T17:15:46.465Z")
...@@ -44,6 +45,7 @@ public class UserApiController implements UserApi { ...@@ -44,6 +45,7 @@ public class UserApiController implements UserApi {
return new ResponseEntity<>(objectMapper.readValue("\"\"", String.class), HttpStatus.NOT_IMPLEMENTED); return new ResponseEntity<>(objectMapper.readValue("\"\"", String.class), HttpStatus.NOT_IMPLEMENTED);
} catch (IOException e) { } catch (IOException e) {
log.error("Couldn't serialize response for content type application/json", e); log.error("Couldn't serialize response for content type application/json", e);
java.util.logging.Logger.getLogger(UserApiController.class.getName()).log(Level.SEVERE, null, e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} }
} }
...@@ -59,6 +61,7 @@ public class UserApiController implements UserApi { ...@@ -59,6 +61,7 @@ public class UserApiController implements UserApi {
return new ResponseEntity<>(objectMapper.readValue("\"\"", String.class), HttpStatus.NOT_IMPLEMENTED); return new ResponseEntity<>(objectMapper.readValue("\"\"", String.class), HttpStatus.NOT_IMPLEMENTED);
} catch (IOException e) { } catch (IOException e) {
log.error("Couldn't serialize response for content type application/json", e); log.error("Couldn't serialize response for content type application/json", e);
java.util.logging.Logger.getLogger(ProvisionerApiController.class.getName()).log(Level.SEVERE, null, e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} }
} }
...@@ -86,6 +89,7 @@ public class UserApiController implements UserApi { ...@@ -86,6 +89,7 @@ public class UserApiController implements UserApi {
return new ResponseEntity<User>(objectMapper.readValue("{ \"firstName\" : \"firstName\", \"lastName\" : \"lastName\", \"password\" : \"password\", \"userStatus\" : 6, \"id\" : 0, \"email\" : \"email\", \"username\" : \"username\"}", User.class), HttpStatus.NOT_IMPLEMENTED); return new ResponseEntity<User>(objectMapper.readValue("{ \"firstName\" : \"firstName\", \"lastName\" : \"lastName\", \"password\" : \"password\", \"userStatus\" : 6, \"id\" : 0, \"email\" : \"email\", \"username\" : \"username\"}", User.class), HttpStatus.NOT_IMPLEMENTED);
} catch (IOException e) { } catch (IOException e) {
log.error("Couldn't serialize response for content type application/json", e); log.error("Couldn't serialize response for content type application/json", e);
java.util.logging.Logger.getLogger(ProvisionerApiController.class.getName()).log(Level.SEVERE, null, e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} }
} }
......
...@@ -128,7 +128,6 @@ public class DRIPService { ...@@ -128,7 +128,6 @@ public class DRIPService {
} }
private ToscaTemplate setProvisionOperation(ToscaTemplate toscaTemplate, String operation) throws IOException, JsonProcessingException, ApiException, Exception { private ToscaTemplate setProvisionOperation(ToscaTemplate toscaTemplate, String operation) throws IOException, JsonProcessingException, ApiException, Exception {
// helper.uploadToscaTemplate(toscaTemplate);
List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates(); List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates();
for (NodeTemplateMap vmTopologyMap : vmTopologies) { for (NodeTemplateMap vmTopologyMap : vmTopologies) {
Map<String, Object> provisionerInterface = helper.getProvisionerInterfaceFromVMTopology(vmTopologyMap); Map<String, Object> provisionerInterface = helper.getProvisionerInterfaceFromVMTopology(vmTopologyMap);
......
...@@ -27,6 +27,8 @@ import java.util.List; ...@@ -27,6 +27,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.commons.utils.Converter; import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.commons.utils.ToscaHelper; import nl.uva.sne.drip.commons.utils.ToscaHelper;
import nl.uva.sne.drip.model.cloud.storm.CloudsStormVM; import nl.uva.sne.drip.model.cloud.storm.CloudsStormVM;
...@@ -139,7 +141,7 @@ class CloudStormService { ...@@ -139,7 +141,7 @@ class CloudStormService {
topTopology.setTopologies(cloudsStormSubTopology); topTopology.setTopologies(cloudsStormSubTopology);
objectMapper.writeValue(new File(tempInputDirPath + File.separator + TOP_TOPOLOGY_FILE_NAME), topTopology); objectMapper.writeValue(new File(tempInputDirPath + File.separator + TOP_TOPOLOGY_FILE_NAME), topTopology);
Logger.getLogger(CloudStormService.class.getName()).log(Level.INFO, "Wrote CloudStorm topology files in: " + tempInputDirPath + File.separator + TOP_TOPOLOGY_FILE_NAME);
return subTopologiesAndVMs; return subTopologiesAndVMs;
} }
...@@ -156,7 +158,7 @@ class CloudStormService { ...@@ -156,7 +158,7 @@ class CloudStormService {
Set<PosixFilePermission> perms = new HashSet<>(); Set<PosixFilePermission> perms = new HashSet<>();
perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.OWNER_READ);
Files.setPosixFilePermissions(Paths.get(tempInputDirPath + File.separator + userPrivateName), perms); Files.setPosixFilePermissions(Paths.get(tempInputDirPath + File.separator + userPrivateName), perms);
Logger.getLogger(CloudStormService.class.getName()).log(Level.INFO, "Wrote ssh keys in: " + tempInputDirPath + File.separator + userPrivateName);
return publicKeyPath; return publicKeyPath;
} }
...@@ -216,6 +218,7 @@ class CloudStormService { ...@@ -216,6 +218,7 @@ class CloudStormService {
} }
} }
} }
Logger.getLogger(CloudStormService.class.getName()).log(Level.INFO, "Found best matching VM: " + bestMatchingVM);
return bestMatchingVM; return bestMatchingVM;
} }
...@@ -238,6 +241,7 @@ class CloudStormService { ...@@ -238,6 +241,7 @@ class CloudStormService {
CloudCredentialDB cloudStormCredentials = new CloudCredentialDB(); CloudCredentialDB cloudStormCredentials = new CloudCredentialDB();
cloudStormCredentials.setCloudCreds(cloudStormCredentialList); cloudStormCredentials.setCloudCreds(cloudStormCredentialList);
objectMapper.writeValue(new File(credentialsTempInputDirPath + File.separator + "cred.yml"), cloudStormCredentials); objectMapper.writeValue(new File(credentialsTempInputDirPath + File.separator + "cred.yml"), cloudStormCredentials);
Logger.getLogger(CloudStormService.class.getName()).log(Level.INFO, "Wrote cloudStorm credentials at : " + credentialsTempInputDirPath + File.separator + "cred.yml");
} }
private CredentialInfo getCloudStormCredentialInfo(Credential toscaCredentials, String tmpPath) throws FileNotFoundException, IOException { private CredentialInfo getCloudStormCredentialInfo(Credential toscaCredentials, String tmpPath) throws FileNotFoundException, IOException {
......
...@@ -61,15 +61,16 @@ public class Consumer extends DefaultConsumer { ...@@ -61,15 +61,16 @@ public class Consumer extends DefaultConsumer {
@Override @Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException, FileNotFoundException, JsonProcessingException { public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException, FileNotFoundException, JsonProcessingException {
try { Message responceMessage = null;
//Create the reply properties which tells us where to reply, and which id to use.
//No need to change anything here
AMQP.BasicProperties replyProps = new AMQP.BasicProperties.Builder() AMQP.BasicProperties replyProps = new AMQP.BasicProperties.Builder()
.correlationId(properties.getCorrelationId()) .correlationId(properties.getCorrelationId())
.build(); .build();
try {
//Create the reply properties which tells us where to reply, and which id to use.
//No need to change anything here
Message message = objectMapper.readValue(new String(body, "UTF-8"), Message.class); Message message = objectMapper.readValue(new String(body, "UTF-8"), Message.class);
logger.log(Level.INFO, "Got Request: '{'0'}'{0}", message.getToscaTemplate()); logger.log(Level.INFO, "Got Request: {0}", objectMapper.writeValueAsString(message));
String tempInputDirPath = System.getProperty("java.io.tmpdir") + File.separator + "Input-" + Long.toString(System.nanoTime()) + File.separator; String tempInputDirPath = System.getProperty("java.io.tmpdir") + File.separator + "Input-" + Long.toString(System.nanoTime()) + File.separator;
File tempInputDir = new File(tempInputDirPath); File tempInputDir = new File(tempInputDirPath);
...@@ -80,21 +81,27 @@ public class Consumer extends DefaultConsumer { ...@@ -80,21 +81,27 @@ public class Consumer extends DefaultConsumer {
CloudStormService service = new CloudStormService(this.properties, message.getToscaTemplate()); CloudStormService service = new CloudStormService(this.properties, message.getToscaTemplate());
ToscaTemplate toscaTemplate = service.execute(); ToscaTemplate toscaTemplate = service.execute();
Message responceMessage = new Message(); responceMessage = new Message();
responceMessage.setCreationDate(System.currentTimeMillis()); responceMessage.setCreationDate(System.currentTimeMillis());
responceMessage.setToscaTemplate(toscaTemplate); responceMessage.setToscaTemplate(toscaTemplate);
} catch (Exception ex) {
responceMessage = handleException(ex);
// Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex);
} finally {
String response = objectMapper.writeValueAsString(responceMessage); String response = objectMapper.writeValueAsString(responceMessage);
logger.log(Level.INFO, "Sending Response: '{'0'}'{0}", response); logger.log(Level.INFO, "Sending Response: '{'0'}'{0}", response);
channel.basicPublish("", properties.getReplyTo(), replyProps, response.getBytes("UTF-8")); channel.basicPublish("", properties.getReplyTo(), replyProps, response.getBytes("UTF-8"));
channel.basicAck(envelope.getDeliveryTag(), false); channel.basicAck(envelope.getDeliveryTag(), false);
} catch (JSchException | ApiException ex) {
Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex);
} }
} }
private Message handleException(Exception ex) {
Message errorMessage = new Message();
errorMessage.setCreationDate(System.currentTimeMillis());
errorMessage.setExeption(new ApiException(ex));
return errorMessage;
}
} }
...@@ -76,7 +76,13 @@ def get_tosca_template_model_by_id(id): ...@@ -76,7 +76,13 @@ def get_tosca_template_model_by_id(id):
def get_tosca_template(tosca_template_dict): def get_tosca_template(tosca_template_dict):
return ToscaTemplate(yaml_dict_tpl=copy.deepcopy(tosca_template_dict)) start = time.time()
logger.info("Checking ToscaTemplate validity")
tt = ToscaTemplate(yaml_dict_tpl=copy.deepcopy(tosca_template_dict))
end = time.time()
elapsed = end - start
logger.info("Time elapsed: " + str(elapsed))
return tt
def get_tosca_template_dict_by_id(id): def get_tosca_template_dict_by_id(id):
...@@ -107,7 +113,7 @@ def save(file): ...@@ -107,7 +113,7 @@ def save(file):
# dictionary = yaml.load(file.stream) # dictionary = yaml.load(file.stream)
logger.info("tosca template: \n" + str(yaml.dump(dictionary))) logger.info("tosca template: \n" + str(yaml.dump(dictionary)))
# print(yaml.dump(dictionary)) # print(yaml.dump(dictionary))
tosca_template = ToscaTemplate(yaml_dict_tpl=copy.deepcopy(dictionary)) tosca_template = get_tosca_template(dictionary)
# all_custom_def = tosca_template.nodetemplates[0].custom_def # all_custom_def = tosca_template.nodetemplates[0].custom_def
tosca_template_model = ToscaTemplateModel.from_dict(dictionary) tosca_template_model = ToscaTemplateModel.from_dict(dictionary)
doc_id = tosca_templates_db.insert(dictionary) doc_id = tosca_templates_db.insert(dictionary)
...@@ -390,7 +396,7 @@ def get_node_type_name(id, node_name): ...@@ -390,7 +396,7 @@ def get_node_type_name(id, node_name):
def update(id, tosca_template_dict): def update(id, tosca_template_dict):
tosca_template = ToscaTemplate(yaml_dict_tpl=copy.deepcopy(tosca_template_dict)) tosca_template = get_tosca_template(tosca_template_dict)
tosca_template_model = ToscaTemplateModel.from_dict(tosca_template_dict) tosca_template_model = ToscaTemplateModel.from_dict(tosca_template_dict)
doc_id = tosca_templates_db.update(tosca_template_dict, doc_ids=[int(id)]) doc_id = tosca_templates_db.update(tosca_template_dict, doc_ids=[int(id)])
return doc_id return doc_id
......
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