Commit 2be788f2 authored by Daniele Venzano's avatar Daniele Venzano

Merge branch 'ext/devel/small-fixes'

parents bb08bde9 df44a8ff
...@@ -165,6 +165,27 @@ Will return a JSON document like this:: ...@@ -165,6 +165,27 @@ Will return a JSON document like this::
It is a map with the execution IDs as keys and the full execution details as values. It is a map with the execution IDs as keys and the full execution details as values.
Starting from verion 0.7 of the API, the execution list can be filtered.
You need to pass via the URL (GET parameters) the criteria to be used for filtering, for example::
curl -u 'username:password' http://bf5:8080/api/<api_version>/execution?status=terminated\&limit=1
Valid criteria that can be used are:
* status: one of submitted, scheduled, starting, error, running, cleaning up, terminated
* name: execution mane
* user_id: user_id owning the execution (admin only)
* limit: limit the number of returned entries
* earlier_than_submit: all execution that where submitted earlier than this timestamp
* earlier_than_start: all execution that started earlier than this timestamp
* earlier_than_end: all execution that ended earlier than this timestamp
* later_than_submit: all execution that where submitted later than this timestamp
* later_than_start: all execution that started later than this timestamp
* later_than_end: all execution that started later than this timestamp
All timestamps should be passed as number of seconds since the epoch (UTC timezone).
Start execution Start execution
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^
......
...@@ -142,7 +142,7 @@ class ExecutionCollectionAPI(RequestHandler): ...@@ -142,7 +142,7 @@ class ExecutionCollectionAPI(RequestHandler):
All timestamps should be passed as number of seconds since the epoch (UTC timezone). All timestamps should be passed as number of seconds since the epoch (UTC timezone).
example: curl -u 'username:password' -X GET -H "Content-Type: application/json" -d '{"status":"terminated"}' http://bf5:8080/api/0.6/execution example: curl -u 'username:password' -X GET http://bf5:8080/api/0.6/execution?limit=1\&status=terminated
:return: :return:
""" """
......
...@@ -65,7 +65,10 @@ class Execution: ...@@ -65,7 +65,10 @@ class Execution:
self._status = d['status'] self._status = d['status']
self.error_message = d['error_message'] self.error_message = d['error_message']
self.size = self.description['size'] try:
self.size = self.description['size']
except KeyError:
self.size = self.description['priority'] # zapp format v2
self.termination_lock = threading.Lock() self.termination_lock = threading.Lock()
......
...@@ -31,6 +31,9 @@ class ResourceLimits: ...@@ -31,6 +31,9 @@ class ResourceLimits:
elif isinstance(data, ResourceLimits): elif isinstance(data, ResourceLimits):
self.min = data.min self.min = data.min
self.max = data.max self.max = data.max
elif isinstance(data, int):
self.min = data
self.max = data
else: else:
raise TypeError raise TypeError
self.unit = unit self.unit = unit
...@@ -113,14 +116,40 @@ class Service: ...@@ -113,14 +116,40 @@ class Service:
self.essential = d['essential'] self.essential = d['essential']
# Fields parsed from the JSON description # Fields parsed from the JSON description
self.image_name = self.description['image'] try:
self.image_name = self.description['image']
except KeyError:
self.image_name = self.description['docker_image'] # zapp description v2
self.is_monitor = self.description['monitor'] self.is_monitor = self.description['monitor']
self.startup_order = self.description['startup_order'] self.startup_order = self.description['startup_order']
self.environment = self.description['environment']
self.command = self.description['command'] try:
self.resource_reservation = ResourceReservation(self.description['resources']) self.environment = self.description['environment']
self.volumes = [VolumeDescriptionHostPath(v['path'], v['name'], v['read_only']) for v in self.description['volumes']] except KeyError:
self.replicas = self.description['replicas'] self.environment = []
try:
self.command = self.description['command']
except KeyError:
self.command = None
try:
self.resource_reservation = ResourceReservation(self.description['resources'])
except KeyError:
self.resource_reservation = ResourceReservation({'memory': self.description['required_resources']['memory'], 'cores': 0}) # ZApp description v2
try:
self.volumes = [VolumeDescriptionHostPath(v['path'], v['name'], v['read_only']) for v in self.description['volumes']]
except KeyError:
self.volumes = []
except TypeError:
self.volumes = [VolumeDescriptionHostPath(v[0], v[1], v[2]) for v in self.description['volumes']]
try:
self.replicas = self.description['replicas']
except KeyError:
self.replicas = 0
def serialize(self): def serialize(self):
"""Generates a dictionary that can be serialized in JSON.""" """Generates a dictionary that can be serialized in JSON."""
...@@ -186,7 +215,7 @@ class Service: ...@@ -186,7 +215,7 @@ class Service:
@property @property
def user_id(self): def user_id(self):
"""Getter for the user_id, that is actually taken form the parent execution.""" """Getter for the user_id, that is actually taken from the parent execution."""
execution = self.sql_manager.execution_list(only_one=True, id=self.execution_id) execution = self.sql_manager.execution_list(only_one=True, id=self.execution_id)
return execution.user_id return execution.user_id
......
...@@ -77,7 +77,7 @@ class KubernetesServiceConf: ...@@ -77,7 +77,7 @@ class KubernetesServiceConf:
for prt in ports: for prt in ports:
aux = self.conf['spec']['ports'] # type: List[Dict[str, str]] aux = self.conf['spec']['ports'] # type: List[Dict[str, str]]
aux[count]['name'] = 'http' aux[count]['name'] = 'http-' + str(count)
aux[count]['port'] = prt.number aux[count]['port'] = prt.number
aux[count]['targetPort'] = prt.number aux[count]['targetPort'] = prt.number
count += 1 count += 1
...@@ -184,6 +184,13 @@ class KubernetesReplicationControllerConf: ...@@ -184,6 +184,13 @@ class KubernetesReplicationControllerConf:
aux = self.conf['spec']['template'] # type: Dict aux = self.conf['spec']['template'] # type: Dict
aux['spec']['containers'][0]['resources']['limits']['cpu'] = corelimit aux['spec']['containers'][0]['resources']['limits']['cpu'] = corelimit
def set_spec_container_command(self, command):
"""Setter to set container command"""
aux = self.conf['spec']['template']
aux['spec']['containers'][0]['command'] = []
command_arr = command.split(" ")
aux['spec']['containers'][0]['command'] = command_arr
def set_spec_container_volumes(self, volumes: List[VolumeDescription], name: str): def set_spec_container_volumes(self, volumes: List[VolumeDescription], name: str):
"""Setter to set container volumes""" """Setter to set container volumes"""
aux = self.conf['spec']['template'] # type: Dict aux = self.conf['spec']['template'] # type: Dict
...@@ -261,6 +268,9 @@ class KubernetesClient: ...@@ -261,6 +268,9 @@ class KubernetesClient:
if len(service_instance.volumes) > 0: if len(service_instance.volumes) > 0:
config.set_spec_container_volumes(service_instance.volumes, service_instance.name) config.set_spec_container_volumes(service_instance.volumes, service_instance.name)
if service_instance.command is not None:
config.set_spec_container_command(service_instance.command)
info = {} info = {}
try: try:
......
...@@ -43,13 +43,13 @@ class KubernetesBackend(zoe_master.backends.base.BaseBackend): ...@@ -43,13 +43,13 @@ class KubernetesBackend(zoe_master.backends.base.BaseBackend):
"""Initializes Kubernetes backend starting the event monitoring thread.""" """Initializes Kubernetes backend starting the event monitoring thread."""
global _monitor, _checker global _monitor, _checker
_monitor = KubernetesMonitor(state) _monitor = KubernetesMonitor(state)
_checker = KubernetesStateSynchronizer(state) # _checker = KubernetesStateSynchronizer(state)
@classmethod @classmethod
def shutdown(cls): def shutdown(cls):
"""Performs a clean shutdown of the resources used by Swarm backend.""" """Performs a clean shutdown of the resources used by Swarm backend."""
_monitor.quit() _monitor.quit()
_checker.quit() # _checker.quit()
def spawn_service(self, service_instance: ServiceInstance): def spawn_service(self, service_instance: ServiceInstance):
"""Spawn a service, translating a Zoe Service into a Docker container.""" """Spawn a service, translating a Zoe Service into a Docker container."""
......
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