Esempio n. 1
0
    def start(self) -> None:
        """
        Starts the service for this session, ensuring that the
        ``workstation_image`` is ready to be used and that
        ``WORKSTATIONS_MAXIMUM_SESSIONS`` has not been reached in this region.

        Raises
        ------
        ComponentException
            If the service cannot be started.
        """
        try:
            if not self.workstation_image.ready:
                raise ComponentException("Workstation image was not ready")

            if (Session.objects.all().filter(
                    status__in=[Session.RUNNING, Session.STARTED],
                    region=self.region,
            ).count() >= settings.WORKSTATIONS_MAXIMUM_SESSIONS):
                raise ComponentException("Too many sessions are running")

            self.service.start(
                http_port=self.workstation_image.http_port,
                websocket_port=self.workstation_image.websocket_port,
                hostname=self.hostname,
                environment=self.environment,
            )
            self.update_status(status=self.STARTED)
        except Exception:
            self.update_status(status=self.FAILED)
            raise
    def _create_file_result(self, reader, job):
        output_file = Path(self.output_path)
        try:
            file = get_file(container=reader, src=output_file)
        except NotFound:
            raise ComponentException(
                f"The evaluation or algorithm failed for an unknown reason as "
                f"file {self.output_path} was not produced. Please contact the "
                f"organisers for assistance.")

        if self.save_in_object_store:
            civ = ComponentInterfaceValue.objects.create(interface=self)
            try:
                civ.file = File(file, name=str(output_file.name))
                civ.full_clean()
                civ.save()
            except ValidationError:
                raise ComponentException("Invalid filetype.")
        else:
            try:
                result = json.loads(
                    file.read().decode(),
                    parse_constant=lambda x: None,  # Removes -inf, inf and NaN
                )
            except JSONDecodeError as e:
                raise ComponentException(
                    f"Could not decode json file: {e.msg}")

            civ = ComponentInterfaceValue.objects.create(interface=self,
                                                         value=result)

        job.outputs.add(civ)
Esempio n. 3
0
    def _create_json_result(self, reader, job):
        try:
            result = get_file(container=reader, src=Path(self.output_path))
        except NotFound:
            # The container exited without error, but no results file was
            # produced. This shouldn't happen, but does with poorly programmed
            # evaluation containers.
            raise ComponentException(
                "The evaluation failed for an unknown reason as no results "
                "file was produced. Please contact the organisers for "
                "assistance."
            )

        try:
            result = json.loads(
                result.read().decode(),
                parse_constant=lambda x: None,  # Removes -inf, inf and NaN
            )
        except JSONDecodeError as e:
            raise ComponentException(f"Could not decode results file: {e.msg}")

        civ = ComponentInterfaceValue.objects.create(
            interface=self, value=result
        )
        job.outputs.add(civ)