Commit c0b42137 authored by Spiros Koulouzis's avatar Spiros Koulouzis

added debug messages

parent 632cb1d3
......@@ -17,22 +17,22 @@ description: >
topology_template:
node_templates:
mysql:
mongo:
type: tosca.nodes.ARTICONF.Container.Application.Docker
properties:
ports:
- "3306:3306"
- "27017:27017"
volumes:
- db_data:/var/lib/mysql
- db-data:/data/db
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
ROOT_PASSWORD: somewordpress
DATABASE: db
USER: user
PASSWORD: passwd
artifacts:
image:
type: tosca.artifacts.Deployment.Image.Container.Docker
file: mysql:5.7
file: mongo:3
repository: docker_hub
......@@ -40,27 +40,27 @@ topology_template:
type: tosca.nodes.ARTICONF.Container.Application.Docker
properties:
ports:
- "8000:80"
- "30000:80"
volumes:
- /etc/hostname:/etc/host_hostname:ro
- /var/run/docker.sock:/var/run/docker.sock
environment:
publish: "127.0.0.1:8000:80"
publish: "127.0.0.1:30000:80"
artifacts:
image:
type: tosca.artifacts.Deployment.Image.Container.Docker
file: gliderlabs/logspout:latest
repository: docker_hub
repository: docker_hub
policies:
- scalability:
type: tosca.policies.ARTICONF.Performance.CPU
targets: [ mysql ]
targets: [ mongo ]
properties:
constraint_name: cpu_load
max_value: 90
- faultTolerance:
type: tosca.policies.ARTICONF.FaultTolerance
targets: [ mysql ]
targets: [ mongo ]
properties:
level: 1
{"owner":"user","creationDate":1580735228286,"toscaTemplate":{"tosca_definitions_version":"tosca_simple_yaml_1_0","tosca_default_namespace":null,"template_name":null,"topology_template":{"description":null,"inputs":null,"node_templates":{"compute":{"properties":{"disk_size":"50000 MB","mem_size":"6000 MB","num_cores":2.0,"os":"Ubuntu 18.04","user_name":"vm_user"},"interfaces":{"Standard":{"create":"dumy.yaml"}},"type":"tosca.nodes.ARTICONF.VM.Compute","attributes":{"user_key_pair":{"protocol":"ssh","keys":{"public_key":"c3NoLXJzYSBBQUFBQjNOemFDMXljMkVB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ZFluU0FGWU9pZDhzOGtDUVFDNHhxbW5xa294U09wZldyTGZ2L3IyR3k3WApGQ3FKRW1oN2hMRDl0aHh1MDluNEpZSm1ralVEb3BDTnZ3VXJ3ckI5YUVPZnV2MmNEMHpMOCtIMjZzaFhBa0JtCmppZ0RMMzF0OG1zc09zbTBveWJvUHdGVlB6Yitua2ZSUGxNV1lsekJuYzJBVU5nK1QyMnB4elppaE1neFJ3V3AKM1hLdUdtSkpVY2d5ZERqWXdKMmhBa0FjR1l2RDhZL0l1SkpFZXcwMy8xRURmWXY0ekpnLzZmSzdReWZhQ2diZQpPWElYSkx1bFdaL3dCcEJyVXRXcmpzeC9vQXVWc09KaVgycnZ6dFN2NXF3NwotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo="}},"public_ip":"192.168.1.10","role":"master","node_type":"t2.medium","root_key_pair":{"protocol":"ssh","keys":{"public_key":"cHVibGljS2V5LWYzMDQ5YTY5LWYwNDktNDFkZC04ZDkwLTQyYzhjOTAxOTg1Nw==","private_key":"LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFcFFJQkFBS0NBUUVBdGJmZ0E0dGF5aGtXQnNpcEN1dFNmb0VuUW5EUjlEUlNDTUkxNEkzN05XUWdORzg2azV6YTlSM01PUXNsCitOcE1neUVDM2d2NGIvbXhvcGwvSzQwdjg5Z2d2WE82Qm1RYXZQaStycHEydVFjUG9HNVRiUmt5K05JcG5QcnZQUGs2V09qTTdKd3YKNE9Qa1lPaERlT1dIdTBkNW5JNjBYY055alBKaGh3S0JpM1IyVTRYV1p1Q0ZOU256V1lGeXhuNWlLcGFEcXBPVHBJaGxKVEFGdmZEQQplVzRja3VudEo5Z0JBbTFSbHEvSTRsMGhtYlNjTFdsRzhaVmduaXlKY215YmZrK3RNVVNhdHNkWnZ6MWtJanJ3c1VzRWQvMEZqY29GCm41THNnZE9rZDJLZHFtaThuT3lJSFVEREdDUFlxZytHc3prdzR1LzZnVURVWFhtUX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VZyLzNGZlZUTQpjNEZxSHlkRkZuNTYrcEUySFoyVk1NZ1UrRTgxT1pETzZhNTR1cU1RNGs3TDRnSWNhbFUvZnU0U0dVMFE3S21UQUkwazY0ZVVUdzk0CjljM1Vhd3RWenlHcWcrbGY3TkdXYmhCWEFvR0FUNlFoRzBRZmRYTVVUYmJUOGRVM3VVZkFWTmxsMjBGSmk2Uy9zYlhDUUZBbnFSSWgKL2NrYjJKcDljR1JQdGJhUTZTOEUyU1F5V3BJRlU3L0p5aXVIbEowMVIvMWNMalU2WTlVcTBUemdrK1hheFk2Y2hxckdOYVQ2ZmxHZQpwK01aMVh3VGlwcHZFNzJseFQrRzhib1dhVjVGQ3ltUWJQWUl2VnJCdU5ON2Uya0NnWUVBanlEa0N2U2UyN0tIRXpUVVdlVjg4RDZYCnM4bXNIb3FCdVZIbXpxd0hXOGNURS9id1lCVmgvc2ZVd1VyNCtNRERKUkJMUU4yWFdWVEwwZEUwMkwzQjlVSTI1L0R4MUVaVW5IYnIKVlZZbFB5cjdDWXpzVnZBMGVmeFhBOUdJMEUwUUFBaFo0YTBabWNxRTZoSytRSEJ6K1NiUUxXZzhld24xeFNkRHVQNVFrS0k9Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0t"}},"host_name":"vm0"}},"compute_1":{"properties":{"disk_size":"50000 MB","mem_size":"6000 MB","num_cores":2.0,"os":"Ubuntu 18.04","user_name":"vm_user"},"interfaces":{"Standard":{"create":"dumy.yaml"}},"type":"tosca.nodes.ARTICONF.VM.Compute","attributes":{"user_key_pair":{"protocol":"ssh","keys":{"public_key":"c3NoLXJzYSBBQUFBQjNOemFDMXljMkVBQUFBREFRQUJBQUFBZ1FEUlhTTElrMzV5S2YxSmdiMkxPdmhHdXJyR1lGVW1uam0wc01pVXVOQ00wVWwvMUJNRlFCVDRpZWFyQkZkVElyamR6Mno0YWx2OHBiUDB5WWFZeXFRZndXS3V0U0xwclBTREszMjF0Ym5NNHdoaitqVkJwcGlqSDV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VlB6Yitua2ZSUGxNV1lsekJuYzJBVU5nK1QyMnB4elppaE1neFJ3V3AKM1hLdUdtSkpVY2d5ZERqWXdKMmhBa0FjR1l2RDhZL0l1SkpFZXcwMy8xRURmWXY0ekpnLzZmSzdReWZhQ2diZQpPWElYSkx1bFdaL3dCcEJyVXRXcmpzeC9vQXVWc09KaVgycnZ6dFN2NXF3NwotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo="}},"public_ip":"192.168.1.11","role":"worker","node_type":"t2.medium","root_key_pair":{"protocol":"ssh","keys":{"public_key":"cHVibGljS2V5LWYzMDQ5YTY5LWYwNDktNDFkZC04ZDkwLTQyYzhjOTAxOTg1Nw==","private_key":"LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFcFFJQkFBS0NBUUVBdGJmZ0E0dGF5aGtXQnNpcEN1dFNmb0VuUW5EUjlEUlNDTUkxNEkzN05XUWdORzg2azV6YTlSM01PUXNsCitOcE1neUVDM2d2NGIvbXhvcGwvSzQwdjg5Z2d2WE82Qm1RYXZQaStycHEydVFjUG9HNVRiUmt5K05JcG5QcnZQUGs2V09qTTdKd3YKNE9Qa1lPaERlT1dIdTBkNW5JNjBYY055alBKaGh3S0JpM1IyVTRYV1p1Q0ZOU256V1lGeXhuNWlLcGFEcXBPVHBJaGxKVEFGdmZEQQplVzRja3VudEo5Z0JBbTFSbHEvSTRsMGhtYlNjTFdsRzhaVmduaXlKY215YmZrK3RNVVNhdHNkWnZ6MWtJanJ3c1VzRWQvMEZqY29GCm41THNnZE9rZDJLZHFtaThuT3lJSFVEREdDUFlxZytHc3prdzR1LzZnVURVWFhtUXJMeHkyd0lEQVFBQkFvSUJBUUNjektycHBBZVYKTjR4QUVrbDYrSTlZUlUyQkVTUzVXYVFubHAweXhKQ3RBMWFlcUJPZFo4MnZrQ1MyWEI1SjJ1UUdpaWVWUGpNRFBDdkJLRDRKY0d5ZQpOaklhQjQvUEQvWGFkYkRqclBCYU8vT0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mJUOGRVM3VVZkFWTmxsMjBGSmk2Uy9zYlhDUUZBbnFSSWgKL2NrYjJKcDljR1JQdGJhUTZTOEUyU1F5V3BJRlU3L0p5aXVIbEowMVIvMWNMalU2WTlVcTBUemdrK1hheFk2Y2hxckdOYVQ2ZmxHZQpwK01aMVh3VGlwcHZFNzJseFQrRzhib1dhVjVGQ3ltUWJQWUl2VnJCdU5ON2Uya0NnWUVBanlEa0N2U2UyN0tIRXpUVVdlVjg4RDZYCnM4bXNIb3FCdVZIbXpxd0hXOGNURS9id1lCVmgvc2ZVd1VyNCtNRERKUkJMUU4yWFdWVEwwZEUwMkwzQjlVSTI1L0R4MUVaVW5IYnIKVlZZbFB5cjdDWXpzVnZBMGVmeFhBOUdJMEUwUUFBaFo0YTBabWNxRTZoSytRSEJ6K1NiUUxXZzhld24xeFNkRHVQNVFrS0k9Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0t"}},"host_name":"vm1"}},"kubernetes":{"properties":{"min_masters_num":1,"min_workers_num":1},"requirements":[{"host":{"capability":"tosca.capabilities.ARTICONF.VM.topology","node":"topology","relationship":"tosca.relationships.HostedOn"}}],"interfaces":{"Kubernetes":{"create":{"inputs":{"playbook":"https://raw.githubusercontent.com/skoulouzis/CONF/DRIP_3.0/ansible_playbooks/create_k8s.yml"}},"install":{"inputs":{"playbook":"https://raw.githubusercontent.com/skoulouzis/CONF/DRIP_3.0/ansible_playbooks/install_k8s.yml"}}}},"type":"tosca.nodes.ARTICONF.Orchestrator.Kubernetes"},"logspout":{"properties":{"environment":{"publish":"127.0.0.1:8000:80"},"ports":["8000:80"],"volumes":["/etc/hostname:/etc/host_hostname:ro","/var/run/docker.sock:/var/run/docker.sock"]},"requirements":[{"host":{"capability":"tosca.capabilities.ARTICONF.Orchestrator","node":"kubernetes","relationship":"tosca.relationships.HostedOn"}}],"type":"tosca.nodes.ARTICONF.Container.Application.Docker","artifacts":{"image":{"file":"gliderlabs/logspout:latest","repository":"docker_hub","type":"tosca.artifacts.Deployment.Image.Container.Docker"}}},"mysql":{"properties":{"environment":{"MYSQL_DATABASE":"wordpress","MYSQL_PASSWORD":"wordpress","MYSQL_ROOT_PASSWORD":"somewordpress","MYSQL_USER":"wordpress"},"ports":["3306:3306"],"volumes":["db_data:/var/lib/mysql"]},"requirements":[{"host":{"capability":"tosca.capabilities.ARTICONF.Orchestrator","node":"kubernetes","relationship":"tosca.relationships.HostedOn"}}],"type":"tosca.nodes.ARTICONF.Container.Application.Docker","artifacts":{"image":{"file":"mysql:5.7","repository":"docker_hub","type":"tosca.artifacts.Deployment.Image.Container.Docker"}}},"topology":{"properties":{"domain":"Frankfurt","provider":"EC2"},"requirements":[{"vm":{"capability":"tosca.capabilities.ARTICONF.VM","node":"compute","relationship":"tosca.relationships.DependsOn"}},{"vm":{"capability":"tosca.capabilities.ARTICONF.VM","node":"compute_1","relationship":"tosca.relationships.DependsOn"}}],"interfaces":{"CloudsStorm":{"provision":{"inputs":{"code_type":"SEQ","object_type":"SubTopology"}}}},"type":"tosca.nodes.ARTICONF.VM.topology","attributes":{"credential":{"cloud_provider_name":"EC2","keys":{"aws_access_key_id":"XXXXXXXXXXXXX"},"token":"XXXXXXXX","token_type":"access_key"},"status":"running"}}},"relationship_templates":null,"outputs":null,"groups":null,"substitution_mappings":null,"policies":[{"scalability":{"properties":{"constraint_name":"cpu_load","max_value":90},"targets":["mysql"],"type":"tosca.policies.ARTICONF.Performance.CPU"}},{"faultTolerance":{"properties":{"level":1},"targets":["mysql"],"type":"tosca.policies.ARTICONF.FaultTolerance"}}]},"template_author":null,"template_version":null,"description":"TOSCA example","imports":[{"nodes":"https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/nodes.yaml"},{"data":"https://raw.githubusercontent.com/skoulouzis/CONF/DRIP_3.0/TOSCA/types/data.yml"},{"capabilities":"https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/capabilities.yaml"},{"policies":"https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/policies.yaml"},{"interfaces":"https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/interfaces.yml"}],"dsl_definitions":null,"node_types":null,"relationship_types":null,"relationship_templates":null,"capability_types":null,"artifact_types":null,"data_types":null,"interface_types":null,"policy_types":null,"group_types":null,"repositories":null}}
......@@ -82,9 +82,11 @@ public class ToscaHelper {
String ymlStr = objectMapper.writeValueAsString(toscaTemplate);
File toscaTemplateFile = File.createTempFile("temp-toscaTemplate", ".yml");
FileUtils.writeByteArrayToFile(toscaTemplateFile, ymlStr.getBytes());
Logger.getLogger(ToscaHelper.class.getName()).log(Level.INFO, "Uploading ToscaTemplate to sure-tosca service....");
String resp = api.uploadToscaTemplate(toscaTemplateFile);
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 {
......
......@@ -83,4 +83,8 @@ public class Message implements Serializable {
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):
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"))
# 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)
......
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
import yaml
......@@ -5,6 +6,18 @@ import yaml
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):
dockers = []
node_templates = tosca_template_json['topology_template']['node_templates']
......@@ -15,47 +28,84 @@ def get_dockers(tosca_template_json):
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):
k8s_services = []
k8s_deployments = []
definitions = {}
for docker in dockers:
docker_name = next(iter(docker))
k8s_service = {'apiVersion': 'v1', 'kind': 'Service'}
labels = {'app': docker_name}
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_service = create_service_definition(docker_name, docker)
k8s_services.append(k8s_service)
# -----------------------------------------------------------
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}
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
deployment = create_deployment_definition(docker_name, docker)
k8s_deployments.append(deployment)
# print(yaml.dump(deployment))
definitions['services'] = k8s_services
......@@ -63,6 +113,35 @@ def get_k8s_definitions(dockers):
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):
dockers = get_dockers(tosca_template_json)
k8s_definitions = get_k8s_definitions(dockers)
......@@ -70,23 +149,20 @@ def write_ansible_k8s_files(tosca_template_json, tmp_path):
deployments = k8s_definitions['deployments']
i = 0
tasks = []
pip_task = {'name': 'install kubernetes'}
modules = ['setuptools', 'kubernetes', 'pkg_resources']
pip = {'name': modules}
pip_task['pip'] = pip
pip_task = create_pip_task()
tasks.append(pip_task)
namespace_task = create_namespace_task()
tasks.append(namespace_task)
for services_def in services:
task = {'name': 'Create a Service object' + str(i)}
k8s = {'state': 'present', 'definition': services_def}
task['k8s'] = k8s
task = create_service_task(i, services_def)
i += 1
tasks.append(task)
i = 0
for deployments_def in deployments:
task = {'name': 'Create a deployment object' + str(i)}
k8s = {'state': 'present', 'definition': deployments_def}
task['k8s'] = k8s
task = create_deployment_task(i, deployments_def)
i += 1
tasks.append(task)
......@@ -98,4 +174,5 @@ def write_ansible_k8s_files(tosca_template_json, tmp_path):
with open(ansible_playbook_path, 'w') as file:
documents = yaml.dump(ansible_playbook, file)
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;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.*;
import java.util.logging.Level;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
......@@ -47,6 +48,7 @@ public class DeployerApiController implements DeployerApi {
return new ResponseEntity<>(planedYemplateId, HttpStatus.OK);
} catch (Exception ex) {
java.util.logging.Logger.getLogger(DeployerApiController.class.getName()).log(Level.SEVERE, null, ex);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
......
......@@ -2,6 +2,7 @@ package nl.uva.sne.drip.api;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.*;
import java.util.logging.Level;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
......@@ -45,8 +46,10 @@ public class PlannerApiController implements PlannerApi {
String planedYemplateId = dripService.plan(id);
return new ResponseEntity<>(planedYemplateId, HttpStatus.OK);
} catch (ApiException ex) {
java.util.logging.Logger.getLogger(PlannerApiController.class.getName()).log(Level.SEVERE, null, ex);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (Exception ex) {
java.util.logging.Logger.getLogger(PlannerApiController.class.getName()).log(Level.SEVERE, null, ex);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
......
......@@ -49,8 +49,10 @@ public class ProvisionerApiController implements ProvisionerApi {
String planedYemplateId = dripService.provision(id);
return new ResponseEntity<>(planedYemplateId, HttpStatus.OK);
} catch (ApiException ex) {
java.util.logging.Logger.getLogger(ProvisionerApiController.class.getName()).log(Level.SEVERE, null, ex);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (Exception ex) {
java.util.logging.Logger.getLogger(ProvisionerApiController.class.getName()).log(Level.SEVERE, null, ex);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
......
......@@ -57,6 +57,7 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
return new ResponseEntity<>(ymlStr, HttpStatus.OK);
} catch (IOException 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);
} catch (NotFoundException ex) {
java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.SEVERE, null, ex);
......@@ -78,6 +79,7 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
return new ResponseEntity<>(id, HttpStatus.OK);
} catch (IOException 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);
}
}
......@@ -93,6 +95,7 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
String id = toscaTemplateService.saveFile(file);
return new ResponseEntity<>(id, HttpStatus.OK);
} 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);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
......
......@@ -16,6 +16,7 @@ import javax.validation.constraints.*;
import javax.validation.Valid;
import javax.servlet.http.HttpServletRequest;
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")
......@@ -44,6 +45,7 @@ public class UserApiController implements UserApi {
return new ResponseEntity<>(objectMapper.readValue("\"\"", String.class), HttpStatus.NOT_IMPLEMENTED);
} catch (IOException 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);
}
}
......@@ -59,6 +61,7 @@ public class UserApiController implements UserApi {
return new ResponseEntity<>(objectMapper.readValue("\"\"", String.class), HttpStatus.NOT_IMPLEMENTED);
} catch (IOException 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);
}
}
......@@ -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);
} catch (IOException 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);
}
}
......
......@@ -128,7 +128,6 @@ public class DRIPService {
}
private ToscaTemplate setProvisionOperation(ToscaTemplate toscaTemplate, String operation) throws IOException, JsonProcessingException, ApiException, Exception {
// helper.uploadToscaTemplate(toscaTemplate);
List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates();
for (NodeTemplateMap vmTopologyMap : vmTopologies) {
Map<String, Object> provisionerInterface = helper.getProvisionerInterfaceFromVMTopology(vmTopologyMap);
......
......@@ -27,6 +27,8 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
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.ToscaHelper;
import nl.uva.sne.drip.model.cloud.storm.CloudsStormVM;
......@@ -139,7 +141,7 @@ class CloudStormService {
topTopology.setTopologies(cloudsStormSubTopology);
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;
}
......@@ -156,7 +158,7 @@ class CloudStormService {
Set<PosixFilePermission> perms = new HashSet<>();
perms.add(PosixFilePermission.OWNER_READ);
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;
}
......@@ -216,6 +218,7 @@ class CloudStormService {
}
}
}
Logger.getLogger(CloudStormService.class.getName()).log(Level.INFO, "Found best matching VM: " + bestMatchingVM);
return bestMatchingVM;
}
......@@ -238,6 +241,7 @@ class CloudStormService {
CloudCredentialDB cloudStormCredentials = new CloudCredentialDB();
cloudStormCredentials.setCloudCreds(cloudStormCredentialList);
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 {
......
......@@ -61,15 +61,16 @@ public class Consumer extends DefaultConsumer {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException, FileNotFoundException, JsonProcessingException {
Message responceMessage = null;
AMQP.BasicProperties replyProps = new AMQP.BasicProperties.Builder()
.correlationId(properties.getCorrelationId())
.build();
try {
//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()
.correlationId(properties.getCorrelationId())
.build();
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;
File tempInputDir = new File(tempInputDirPath);
......@@ -80,21 +81,27 @@ public class Consumer extends DefaultConsumer {
CloudStormService service = new CloudStormService(this.properties, message.getToscaTemplate());
ToscaTemplate toscaTemplate = service.execute();
Message responceMessage = new Message();
responceMessage = new Message();
responceMessage.setCreationDate(System.currentTimeMillis());
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);
logger.log(Level.INFO, "Sending Response: '{'0'}'{0}", response);
channel.basicPublish("", properties.getReplyTo(), replyProps, response.getBytes("UTF-8"));
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):
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):
......@@ -107,7 +113,7 @@ def save(file):
# dictionary = yaml.load(file.stream)
logger.info("tosca template: \n" + str(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
tosca_template_model = ToscaTemplateModel.from_dict(dictionary)
doc_id = tosca_templates_db.insert(dictionary)
......@@ -390,7 +396,7 @@ def get_node_type_name(id, node_name):
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)
doc_id = tosca_templates_db.update(tosca_template_dict, doc_ids=[int(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