Commit d74c445b authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Add a hack to make questionnaires work

The problem is that we deploy Deployment, but questionnaire is bound to
a DeploymentState. To make this work (barely) I added the following
behaviour: Once a user PATCHs a DeploymentStates questionnaire the
DeploymentState is published by acting like it is a ServiceDeployment.
This works as long as the client just executes deployments (and does not
try to gain insight into the backend state by watching the incoming

I'm not happy with this hack.
parent f1054f5a
...@@ -451,6 +451,16 @@ class DeploymentState(models.Model): ...@@ -451,6 +451,16 @@ class DeploymentState(models.Model):
def user_credentials(self): def user_credentials(self):
return self.user.credentials return self.user.credentials
# hack for deployment of questionnaire
def broker_exchange(self):
return 'services'
# hack for deployment of questionnaire
def routing_key(self):
@classmethod @classmethod
def get_state_item(cls, user, site, service, deployments=[]): def get_state_item(cls, user, site, service, deployments=[]):
try: try:
...@@ -536,6 +546,24 @@ class DeploymentState(models.Model): ...@@ -536,6 +546,24 @@ class DeploymentState(models.Model):
elif self.state == FAILED or self.state == REJECTED or self.state == QUESTIONNAIRE: elif self.state == FAILED or self.state == REJECTED or self.state == QUESTIONNAIRE:
self._set_state(NOT_DEPLOYED) self._set_state(NOT_DEPLOYED)
# call when the questionnaire has changed
def questionnaire_changed(self):
if self.state == QUESTIONNAIRE:
# hack from hell:
# we have deploy the questionnaire.
# so we act like this DeploymentState is a ServiceDeployment
# what could go wrong??
from .serializers.clients import DeploymentStateSerializer
msg = dumps(DeploymentStateSerializer(self).data)
from .brokers import RabbitMQInstance
# #
# DeploymentState.user_deploy # DeploymentState.user_deploy
def user_deploy(self): def user_deploy(self):
...@@ -100,3 +100,37 @@ class DeploymentSerializer(PolymorphicSerializer): ...@@ -100,3 +100,37 @@ class DeploymentSerializer(PolymorphicSerializer):
deployments.VODeployment: VODeploymentSerializer, deployments.VODeployment: VODeploymentSerializer,
deployments.ServiceDeployment: ServiceDeploymentSerializer, deployments.ServiceDeployment: ServiceDeploymentSerializer,
} }
# this mimicks the ServiceDeploymentSerializer
# we need this hack to make the deployment of questionnaire data work
class DeploymentStateSerializer(serializers.ModelSerializer):
id = serializers.SerializerMethodField('get_deployment_id')
resourcetype = serializers.SerializerMethodField('get_resource_type')
user = UserSerializer()
service = ServiceSerializer()
questionnaire = JSONField()
class Meta:
model = deployments.DeploymentState
# dirty hack to have the same id as our parent deployment
def get_deployment_id(self, obj):
dep = obj.deployments.get(
except deployments.Deployment.DoesNotExist:
dep = obj.deployments.get(
def get_resource_type(self, obj):
return 'ServiceDeployment'
...@@ -21,6 +21,7 @@ AUTHENTICATION_CLASSES = (BasicAuthentication, ) ...@@ -21,6 +21,7 @@ AUTHENTICATION_CLASSES = (BasicAuthentication, )
# The client fetches pending tasks # The client fetches pending tasks
# TODO this does nothing for questionnaires
class DeploymentsView(generics.ListAPIView): class DeploymentsView(generics.ListAPIView):
authentication_classes = AUTHENTICATION_CLASSES authentication_classes = AUTHENTICATION_CLASSES
serializer_class = clients.DeploymentSerializer serializer_class = clients.DeploymentSerializer
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