Пример #1
0
 def _update_resources(self, resources_instance, validated_data):
     if self._has_resources(validated_data):
         resources = JobResourcesSerializer(instance=resources_instance,
                                            data=self._get_resources(validated_data))
         resources.is_valid(raise_exception=True)
         return resources.save()
     return None
Пример #2
0
 def _create_resources(self, validated_data):
     if self._has_resources(validated_data):
         resources = JobResourcesSerializer(
             data=self._get_resources(validated_data))
         resources.is_valid(raise_exception=True)
         return resources.save()
     return None
Пример #3
0
class ExperimentJobSerializer(serializers.ModelSerializer):
    uuid = fields.UUIDField(format='hex', read_only=True)
    experiment = fields.SerializerMethodField()
    experiment_name = fields.SerializerMethodField()
    resources = JobResourcesSerializer(required=False)
    started_at = fields.DateTimeField(read_only=True)
    finished_at = fields.DateTimeField(read_only=True)

    class Meta:
        model = ExperimentJob
        fields = (
            'uuid',
            'unique_name',
            'sequence',
            'role',
            'experiment',
            'experiment_name',
            'last_status',
            'is_running',
            'is_done',
            'created_at',
            'updated_at',
            'started_at',
            'finished_at',
            'resources',
        )

    def get_experiment(self, obj):
        return obj.experiment.uuid.hex

    def get_experiment_name(self, obj):
        return obj.experiment.unique_name
Пример #4
0
class ExperimentJobSerializer(serializers.ModelSerializer):
    uuid = fields.UUIDField(format='hex', read_only=True)
    resources = JobResourcesSerializer(required=False)
    started_at = fields.DateTimeField(read_only=True)
    finished_at = fields.DateTimeField(read_only=True)

    class Meta:
        model = ExperimentJob
        extra_kwargs = {'experiment': {'read_only': True}}
        fields = ('id', 'uuid', 'unique_name', 'role', 'experiment',
                  'last_status', 'created_at', 'updated_at', 'started_at',
                  'finished_at', 'resources', 'node_scheduled', 'pod_id')
Пример #5
0
class JobSerializer(serializers.ModelSerializer):
    cpu = fields.DictField(allow_null=True)
    memory = fields.DictField(allow_null=True)
    gpu = fields.DictField(allow_null=True)
    resources = JobResourcesSerializer(read_only=True)

    class Meta:
        fields = ('image', 'resources', 'cpu', 'memory', 'gpu')
        extra_kwargs = {
            'cpu': {
                'write_only': True
            },
            'memory': {
                'write_only': True
            },
            'gpu': {
                'write_only': True
            }
        }

    @staticmethod
    def _has_resources(validated_data):
        cpu = validated_data['cpu']
        memory = validated_data['memory']
        gpu = validated_data['gpu']
        if cpu is None and memory is None and gpu is None:
            return False
        return True

    @staticmethod
    def _get_resources(validated_data):
        cpu = validated_data['cpu']
        memory = validated_data['memory']
        gpu = validated_data['gpu']
        return {'cpu': cpu, 'memory': memory, 'gpu': gpu}

    def _create_resources(self, validated_data):
        if self._has_resources(validated_data):
            resources = JobResourcesSerializer(
                data=self._get_resources(validated_data))
            resources.is_valid(raise_exception=True)
            return resources.save()
        return None

    def _update_resources(self, resources_instance, validated_data):
        if self._has_resources(validated_data):
            resources = JobResourcesSerializer(
                instance=resources_instance,
                data=self._get_resources(validated_data))
            resources.is_valid(raise_exception=True)
            return resources.save()
        return None