Commit d74c445b authored by Lukas Burgey's avatar Lukas Burgey

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
Deployments)

I'm not happy with this hack.
parent f1054f5a
......@@ -451,6 +451,16 @@ class DeploymentState(models.Model):
def user_credentials(self):
return self.user.credentials
# hack for deployment of questionnaire
@property
def broker_exchange(self):
return 'services'
# hack for deployment of questionnaire
@property
def routing_key(self):
return self.service.name
@classmethod
def get_state_item(cls, user, site, service, deployments=[]):
try:
......@@ -536,6 +546,24 @@ class DeploymentState(models.Model):
elif self.state == FAILED or self.state == REJECTED or self.state == QUESTIONNAIRE:
self._set_state(NOT_DEPLOYED)
# call when the questionnaire has changed
def questionnaire_changed(self):
if self.state == QUESTIONNAIRE:
self._set_state(DEPLOYMENT_PENDING)
# 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
RabbitMQInstance.load().publish(
self,
msg,
)
#
# DeploymentState.user_deploy
def user_deploy(self):
......
......@@ -100,3 +100,37 @@ class DeploymentSerializer(PolymorphicSerializer):
deployments.VODeployment: VODeploymentSerializer,
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
fields = DEPLOYMENT_FIELDS + (
'service',
'questionnaire',
'resourcetype',
)
# dirty hack to have the same id as our parent deployment
def get_deployment_id(self, obj):
try:
dep = obj.deployments.get(
servicedeployment__service=obj.service,
)
return dep.id
except deployments.Deployment.DoesNotExist:
dep = obj.deployments.get(
vodeployment__services=obj.service,
)
return dep.id
def get_resource_type(self, obj):
return 'ServiceDeployment'
......@@ -21,6 +21,7 @@ AUTHENTICATION_CLASSES = (BasicAuthentication, )
# The client fetches pending tasks
# TODO this does nothing for questionnaires
class DeploymentsView(generics.ListAPIView):
authentication_classes = AUTHENTICATION_CLASSES
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