Commit 762f7dd8 authored by Lukas Burgey's avatar Lukas Burgey

Rename ..Task to ..State

parent ca3d7553
...@@ -40,7 +40,7 @@ class DeploymentsSerializer(serializers.Serializer): ...@@ -40,7 +40,7 @@ class DeploymentsSerializer(serializers.Serializer):
) )
class DeploymentTaskSerializer(serializers.Serializer): class DeploymentStateSerializer(serializers.Serializer):
id = serializers.IntegerField() id = serializers.IntegerField()
action = serializers.CharField() action = serializers.CharField()
user = UserSerializer() user = UserSerializer()
...@@ -49,7 +49,7 @@ class DeploymentTaskSerializer(serializers.Serializer): ...@@ -49,7 +49,7 @@ class DeploymentTaskSerializer(serializers.Serializer):
class SiteSerializer(serializers.Serializer): class SiteSerializer(serializers.Serializer):
tasks = DeploymentTaskSerializer(many=True) states = DeploymentStateSerializer(many=True)
class RabbitMQInstanceSerializer(serializers.ModelSerializer): class RabbitMQInstanceSerializer(serializers.ModelSerializer):
......
...@@ -4,6 +4,6 @@ from . import views ...@@ -4,6 +4,6 @@ from . import views
URLPATTERNS = [ URLPATTERNS = [
url(r'^deployments', views.DeploymentsView.as_view()), url(r'^deployments', views.DeploymentsView.as_view()),
url(r'^config', views.ConfigurationView.as_view()), url(r'^config', views.ConfigurationView.as_view()),
url(r'^ack/(?P<task_id>\d+)', views.AckView.as_view()), url(r'^ack/(?P<state_id>\d+)', views.AckView.as_view()),
url(r'^response', views.ResponseView.as_view()), url(r'^response', views.ResponseView.as_view()),
] ]
...@@ -3,7 +3,7 @@ import logging ...@@ -3,7 +3,7 @@ import logging
from rest_framework import generics, views from rest_framework import generics, views
from rest_framework.authentication import BasicAuthentication from rest_framework.authentication import BasicAuthentication
from rest_framework.response import Response from rest_framework.response import Response
from .serializers import DeploymentTaskSerializer, ServiceSerializer, RabbitMQInstanceSerializer from .serializers import DeploymentStateSerializer, ServiceSerializer, RabbitMQInstanceSerializer
from ..models import RabbitMQInstance from ..models import RabbitMQInstance
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
...@@ -15,10 +15,10 @@ AUTHENTICATION_CLASSES = (BasicAuthentication, ) ...@@ -15,10 +15,10 @@ AUTHENTICATION_CLASSES = (BasicAuthentication, )
class DeploymentsView(generics.ListAPIView): class DeploymentsView(generics.ListAPIView):
authentication_classes = AUTHENTICATION_CLASSES authentication_classes = AUTHENTICATION_CLASSES
serializer_class = DeploymentTaskSerializer serializer_class = DeploymentStateSerializer
def get_queryset(self): def get_queryset(self):
return self.request.user.site.tasks return self.request.user.site.states
# the client has to fetch the configuration (like services etc.) here # the client has to fetch the configuration (like services etc.) here
...@@ -42,15 +42,15 @@ class ConfigurationView(views.APIView): ...@@ -42,15 +42,15 @@ class ConfigurationView(views.APIView):
class AckView(views.APIView): class AckView(views.APIView):
authentication_classes = AUTHENTICATION_CLASSES authentication_classes = AUTHENTICATION_CLASSES
def delete(self, request, task_id=None): def delete(self, request, state_id=None):
# find the corresponding task for this item # find the corresponding state for this item
for item in request.user.site.task_items.all(): for item in request.user.site.state_items.all():
if item.task.id == int(task_id): if item.state.id == int(state_id):
item.success() item.success()
return Response({'ok': True}) return Response({'ok': True})
# this is no critical # this is no critical
LOGGER.info('%s executed the obsolete task#%s', request.user, task_id) LOGGER.info('%s executed the obsolete state#%s', request.user, state_id)
return Response({'ok': True}) return Response({'ok': True})
...@@ -60,33 +60,33 @@ class ResponseView(views.APIView): ...@@ -60,33 +60,33 @@ class ResponseView(views.APIView):
def post(self, request): def post(self, request):
output = request.data['output'] output = request.data['output']
status = output['status'] status = output['status']
task_id = request.data['id'] state_id = request.data['id']
LOGGER.debug('%s responded to task %s:\n%s', request.user, task_id, request.data) LOGGER.debug('%s responded to state %s:\n%s', request.user, state_id, request.data)
# find the corresponding task for this item # find the corresponding state for this item
task_item = None state_item = None
for item in request.user.site.task_items.all(): for item in request.user.site.state_items.all():
if item.task.id == int(task_id): if item.state.id == int(state_id):
task_item = item state_item = item
if task_item is not None: if state_item is not None:
if status == 'success': if status == 'success':
task_item.success( state_item.success(
credentials=request.data.output.get('credentials', None), credentials=request.data.output.get('credentials', None),
) )
return Response({}) return Response({})
elif status == 'fail': elif status == 'fail':
task_item.failed() state_item.failed()
return Response({}) return Response({})
elif status == 'reject': elif status == 'reject':
task_item.rejected(output['questionnaire']) state_item.rejected(output['questionnaire'])
return Response({}) return Response({})
LOGGER.info('%s executed the obsolete task#%s', request.user, task_id) LOGGER.info('%s executed the obsolete state#%s', request.user, state_id)
return Response( return Response(
data={'error': 'obsolete_task'}, data={'error': 'obsolete_state'},
status=500, status=500,
) )
...@@ -20,14 +20,14 @@ class ServiceSerializer(serializers.ModelSerializer): ...@@ -20,14 +20,14 @@ class ServiceSerializer(serializers.ModelSerializer):
exclude = [] exclude = []
class DeploymentTaskItemSerializer(serializers.ModelSerializer): class DeploymentStateItemSerializer(serializers.ModelSerializer):
service = ServiceSerializer() service = ServiceSerializer()
key = backend_serializers.SSHPublicKeySerializerB() key = backend_serializers.SSHPublicKeySerializerB()
site = SiteSerializer() site = SiteSerializer()
questionnaire = serializers.JSONField() questionnaire = serializers.JSONField()
class Meta: class Meta:
model = models.DeploymentTaskItem model = models.DeploymentStateItem
fields = [ fields = [
'action', 'action',
'key', 'key',
...@@ -39,11 +39,11 @@ class DeploymentTaskItemSerializer(serializers.ModelSerializer): ...@@ -39,11 +39,11 @@ class DeploymentTaskItemSerializer(serializers.ModelSerializer):
] ]
class DeploymentTaskSerializer(serializers.ModelSerializer): class DeploymentStateSerializer(serializers.ModelSerializer):
key = backend_serializers.SSHPublicKeySerializerB() key = backend_serializers.SSHPublicKeySerializerB()
service = ServiceSerializer() service = ServiceSerializer()
class Meta: class Meta:
model = models.DeploymentTask model = models.DeploymentState
fields = [ fields = [
'action', 'action',
'key', 'key',
...@@ -56,8 +56,8 @@ class DeploymentSerializer(serializers.Serializer): ...@@ -56,8 +56,8 @@ class DeploymentSerializer(serializers.Serializer):
service = ServiceSerializer() service = ServiceSerializer()
ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True) ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
ssh_keys_to_withdraw = backend_serializers.SSHPublicKeySerializer(many=True) ssh_keys_to_withdraw = backend_serializers.SSHPublicKeySerializer(many=True)
deploys = DeploymentTaskSerializer(many=True) deploys = DeploymentStateSerializer(many=True)
withdrawals = DeploymentTaskSerializer(many=True) withdrawals = DeploymentStateSerializer(many=True)
class Meta: class Meta:
model = models.Deployment model = models.Deployment
...@@ -76,8 +76,8 @@ class UserSerializer(serializers.ModelSerializer): ...@@ -76,8 +76,8 @@ class UserSerializer(serializers.ModelSerializer):
ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True) ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
deployments = DeploymentSerializer(many=True) deployments = DeploymentSerializer(many=True)
auth_groups = backend_serializers.AuthGroupSerializer(many=True) auth_groups = backend_serializers.AuthGroupSerializer(many=True)
deployment_tasks = DeploymentTaskSerializer(many=True) deployment_states = DeploymentStateSerializer(many=True)
deployment_task_items = DeploymentTaskItemSerializer(many=True) deployment_state_items = DeploymentStateItemSerializer(many=True)
class Meta: class Meta:
model = models.User model = models.User
...@@ -89,8 +89,8 @@ class UserSerializer(serializers.ModelSerializer): ...@@ -89,8 +89,8 @@ class UserSerializer(serializers.ModelSerializer):
'groups', 'groups',
'deployments', 'deployments',
'auth_groups', 'auth_groups',
'deployment_tasks', 'deployment_states',
'deployment_task_items', 'deployment_state_items',
] ]
......
...@@ -131,9 +131,9 @@ class DeploymentView(views.APIView): ...@@ -131,9 +131,9 @@ class DeploymentView(views.APIView):
class QuestionnaireView(views.APIView): class QuestionnaireView(views.APIView):
def post(self, request): def post(self, request):
task_item_id = request.query_params.get('id', '') state_item_id = request.query_params.get('id', '')
if task_item_id != '': if state_item_id != '':
item = models.DeploymentTaskItem.objects.filter(id=int(task_item_id)) item = models.DeploymentStateItem.objects.filter(id=int(state_item_id))
if item.exists(): if item.exists():
item.first().questionnaire_answered( item.first().questionnaire_answered(
answers=request.data, answers=request.data,
......
This diff is collapsed.
...@@ -114,11 +114,11 @@ class DeploymentTest(TestCase): ...@@ -114,11 +114,11 @@ class DeploymentTest(TestCase):
deployment = models.Deployment.get_deployment(user, service) deployment = models.Deployment.get_deployment(user, service)
self.assertIsNotNone(deployment) self.assertIsNotNone(deployment)
# no tasks exist yet # no states exist yet
self.assertFalse(deployment.deploys.exists()) self.assertFalse(deployment.deploys.exists())
self.assertFalse(deployment.withdrawals.exists()) self.assertFalse(deployment.withdrawals.exists())
models.DeploymentTask.construct_deployment_task( models.DeploymentState.construct_deployment_state(
deployment=deployment, deployment=deployment,
key=key, key=key,
) )
...@@ -127,7 +127,7 @@ class DeploymentTest(TestCase): ...@@ -127,7 +127,7 @@ class DeploymentTest(TestCase):
self.assertTrue(deployment.deploys.exists()) self.assertTrue(deployment.deploys.exists())
self.assertFalse(deployment.withdrawals.exists()) self.assertFalse(deployment.withdrawals.exists())
models.DeploymentTask.construct_withdrawal_task( models.DeploymentState.construct_withdrawal_state(
deployment=deployment, deployment=deployment,
key=key, key=key,
) )
...@@ -136,8 +136,8 @@ class DeploymentTest(TestCase): ...@@ -136,8 +136,8 @@ class DeploymentTest(TestCase):
self.assertTrue(deployment.withdrawals.exists()) self.assertTrue(deployment.withdrawals.exists())
# "execute" the withdrawals # "execute" the withdrawals
for task in deployment.withdrawals.all(): for state in deployment.withdrawals.all():
for item in task.task_items.all(): for item in state.state_items.all():
item.success() item.success()
self.assertFalse(deployment.deploys.exists()) self.assertFalse(deployment.deploys.exists())
......
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