Skip to content

Commit 2ade806

Browse files
authored
chore(ps): restart types (#130)
1 parent 5f5f32e commit 2ade806

4 files changed

Lines changed: 28 additions & 22 deletions

File tree

rootfs/api/models/app.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,10 @@ def restart(self, **kwargs): # noqa
192192
"""
193193
deployments = []
194194
app_settings = self.appsettings_set.latest()
195-
if 'type' in kwargs and kwargs['type'] in self.structure:
196-
if self.structure[kwargs['type']] > 0:
197-
if kwargs['type'] in app_settings.canaries:
198-
deployments.append(self._get_job_id(kwargs['type'], True))
199-
deployments.append(self._get_job_id(kwargs['type'], False))
200-
else:
201-
for scale_type, count in self.structure.items():
202-
if count > 0:
203-
if scale_type in app_settings.canaries:
204-
deployments.append(self._get_job_id(kwargs['type'], True))
205-
deployments.append(self._get_job_id(scale_type, False))
195+
if self.structure[kwargs['type']] > 0:
196+
if kwargs['type'] in app_settings.canaries:
197+
deployments.append(self._get_job_id(kwargs['type'], True))
198+
deployments.append(self._get_job_id(kwargs['type'], False))
206199
try:
207200
tasks = [
208201
functools.partial(

rootfs/api/tests/test_pods.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -773,13 +773,15 @@ def test_restart_pods(self, mock_requests):
773773
response = self.client.post('/v2/apps/{}/pods/restart'.format(app_id))
774774
self.assertEqual(response.status_code, 204, response.data)
775775

776-
# restart only the workers
777-
response = self.client.post('/v2/apps/{}/pods/worker/restart'.format(app_id))
776+
# restart web and workers pods
777+
body = {"types": "web,worker"}
778+
response = self.client.post('/v2/apps/{}/pods/restart'.format(app_id), body)
778779
self.assertEqual(response.status_code, 204, response.data)
779780

780-
# restart only the web
781-
response = self.client.post('/v2/apps/{}/pods/web/restart'.format(app_id))
782-
self.assertEqual(response.status_code, 204, response.data)
781+
# restart invalid ptypes
782+
body = {"types": "web1"}
783+
response = self.client.post('/v2/apps/{}/pods/restart'.format(app_id), body)
784+
self.assertEqual(response.status_code, 400, response.data)
783785

784786
# restart only one of the web pods
785787
pods = application.list_pods(type='web')

rootfs/api/urls.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@
4949
re_path(
5050
r"^apps/(?P<id>{})/pods/restart/?$".format(settings.APP_URL_REGEX),
5151
views.PodViewSet.as_view({'post': 'restart'})),
52-
re_path(
53-
r"^apps/(?P<id>{})/pods/(?P<type>[-_\w.]+)/restart/?$".format(settings.APP_URL_REGEX),
54-
views.PodViewSet.as_view({'post': 'restart'})),
5552
# list pods
5653
re_path(
5754
r"^apps/(?P<id>{})/pods/?$".format(settings.APP_URL_REGEX),

rootfs/api/views.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,22 @@ def list(self, *args, **kwargs):
437437
pagination = {'results': data, 'count': len(data)}
438438
return Response(pagination, status=status.HTTP_200_OK)
439439

440-
def restart(self, *args, **kwargs):
441-
restart_app.delay(self.get_app(), **kwargs)
440+
def restart(self, request, *args, **kwargs):
441+
app = self.get_app()
442+
ptypes = []
443+
types = request.data.get("types", "").split(",")
444+
types = [ptype for ptype in set(types) if ptype != ""]
445+
if not types:
446+
# all ptypes need to restart
447+
ptypes = app.structure.keys()
448+
else:
449+
ptypes = [ptype for ptype in types if ptype in app.structure]
450+
invalid_ptypes = set(types) - set(ptypes)
451+
if len(invalid_ptypes) != 0:
452+
raise DryccException("process type {} is not included in procfile".
453+
format(','.join(invalid_ptypes)))
454+
for ptype in set(ptypes):
455+
restart_app.delay(self.get_app(), **{"type": ptype})
442456
return Response(status=status.HTTP_204_NO_CONTENT)
443457

444458
def describe(self, *args, **kwargs):
@@ -831,7 +845,7 @@ def path(self, request, *args, **kwargs):
831845
container_types = [_ for _ in path.keys()
832846
if _ not in volume.app.procfile_types]
833847
if container_types:
834-
raise DryccException("process type {} is not included in profile".
848+
raise DryccException("process type {} is not included in procfile".
835849
format(','.join(container_types)))
836850
if set(path.items()).issubset(set(volume.path.items())):
837851
raise DryccException("mount path not changed")

0 commit comments

Comments
 (0)