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

Rename ..Task to ..State

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