예제 #1
0
파일: views.py 프로젝트: ctc-oss/scale
    def post_impl(self, request):
        """Validates a new Strike process and returns any warnings discovered

        :param request: the HTTP POST request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        name = rest_util.parse_string(request, 'name')
        configuration = rest_util.parse_dict(request, 'configuration')

        rest_util.parse_string(request, 'title', required=False)
        rest_util.parse_string(request, 'description', required=False)

        # Validate the Strike configuration
        try:
            config = StrikeConfigurationV2(
                configuration, do_validate=True).get_configuration()
            warnings = config.validate()
        except InvalidStrikeConfiguration as ex:
            logger.exception('Unable to validate new Strike process: %s', name)
            raise BadParameter(unicode(ex))

        results = [{'id': w.key, 'details': w.details} for w in warnings]
        return Response({'warnings': results})
예제 #2
0
    def get_v5_strike_configuration_as_dict(self):
        """Returns the v5 configuration for this Strike process as a dict

        :returns: The configuration for this Strike process
        :rtype: dict
        """

        return StrikeConfigurationV2(
            self.configuration).get_configuration().get_dict()
예제 #3
0
    def test_conversion_from_1_0(self):
        """Tests calling StrikeConfigurationV6.validate() after converting from schema version 1.0"""

        old_config = {
            'version':
            '1.0',
            'transfer_suffix':
            '_tmp',
            'mount':
            'host:/my/path',
            'files_to_ingest': [{
                'filename_regex': '.*txt',
                'data_types': ['one', 'two'],
                'workspace_path': os.path.join('my', 'path'),
                'workspace_name': self.new_workspace.name,
            }],
        }

        strike_config = StrikeConfigurationV2(old_config).get_configuration()
        strike_config.validate()

        auto_workspace = Workspace.objects.get(name__contains='auto')
        new_config = {
            'version':
            '2.0',
            'workspace':
            auto_workspace.name,
            'monitor': {
                'type': 'dir-watcher',
                'transfer_suffix': '_tmp'
            },
            'files_to_ingest': [{
                'filename_regex': '.*txt',
                'data_types': ['one', 'two'],
                'new_file_path': os.path.join('my', 'path'),
                'new_workspace': self.new_workspace.name,
            }]
        }
        self.assertDictEqual(strike_config.configuration, new_config)

        auto_workspace_config = {
            'version': '1.0',
            'broker': {
                'type': 'host',
                'host_path': '/my/path'
            }
        }
        self.assertDictEqual(auto_workspace.json_config, auto_workspace_config)
예제 #4
0
    def test_bare_min(self):
        """Tests calling StrikeConfigurationV6 constructor with bare minimum JSON"""

        # No exception is success
        StrikeConfigurationV2(
            {
                'workspace': self.workspace.name,
                'monitor': {
                    'type': 'dir-watcher',
                    'transfer_suffix': '_tmp',
                },
                'files_to_ingest': [{
                    'filename_regex': '.*txt'
                }],
            },
            do_validate=True)
예제 #5
0
    def test_validate_mismatched_monitor_type(self):
        """Tests calling StrikeConfigurationV6.validate() with a monitor type that does not match the broker type"""

        config = {
            'workspace': self.workspace.name,
            'monitor': {
                'type': 's3',
                'sqs_name': 'my-sqs',
            },
            'files_to_ingest': [{
                'filename_regex': '.*txt',
            }],
        }

        configuration = StrikeConfigurationV2(config).get_configuration()
        self.assertRaises(InvalidStrikeConfiguration, configuration.validate)
예제 #6
0
    def test_validate_bad_monitor_type(self):
        """Tests calling StrikeConfigurationV6.validate() with a bad monitor type"""

        config = {
            'workspace': self.workspace.name,
            'monitor': {
                'type': 'BAD',
                'transfer_suffix': '_tmp',
            },
            'files_to_ingest': [{
                'filename_regex': '.*txt',
            }],
        }

        configuration = StrikeConfigurationV2(config).get_configuration()
        self.assertRaises(InvalidStrikeConfiguration, configuration.validate)
예제 #7
0
파일: views.py 프로젝트: ctc-oss/scale
    def create_impl(self, request):
        """Creates a new Strike process and returns a link to the detail URL

        :param request: the HTTP POST request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        name = rest_util.parse_string(request, 'name')
        title = rest_util.parse_string(request, 'title', required=False)
        description = rest_util.parse_string(request,
                                             'description',
                                             required=False)
        configuration = rest_util.parse_dict(request, 'configuration')

        config = None
        try:
            if configuration:
                config = StrikeConfigurationV2(
                    configuration, do_validate=True).get_configuration()
        except InvalidStrikeConfiguration as ex:
            raise BadParameter('Strike configuration invalid: %s' %
                               unicode(ex))

        try:
            strike = Strike.objects.create_strike(name, title, description,
                                                  config)
        except InvalidStrikeConfiguration as ex:
            raise BadParameter('Strike configuration invalid: %s' %
                               unicode(ex))

        # Fetch the full strike process with details
        try:
            strike = Strike.objects.get_details(strike.id)
        except Strike.DoesNotExist:
            raise Http404

        serializer = StrikeDetailsSerializerV5(strike)
        strike_url = reverse('strike_details_view',
                             args=[strike.id],
                             request=request)
        return Response(serializer.data,
                        status=status.HTTP_201_CREATED,
                        headers=dict(location=strike_url))
예제 #8
0
    def test_validate_workspace_not_active(self):
        """Tests calling StrikeConfigurationV6.validate() with a new workspace that is not active"""

        config = {
            'workspace':
            self.workspace.name,
            'monitor': {
                'type': 'dir-watcher',
                'transfer_suffix': '_tmp',
            },
            'files_to_ingest': [{
                'filename_regex': '.*txt',
                'new_workspace': self.inactive_workspace.name,
            }],
        }

        configuration = StrikeConfigurationV2(config).get_configuration()
        self.assertRaises(InvalidStrikeConfiguration, configuration.validate)
예제 #9
0
    def test_successful_all(self):
        """Tests calling StrikeConfigurationV6 constructor successfully with all information"""

        config = {
            'workspace':
            self.workspace.name,
            'monitor': {
                'type': 'dir-watcher',
                'transfer_suffix': '_tmp',
            },
            'files_to_ingest': [{
                'filename_regex': '.*txt',
                'data_types': ['one', 'two'],
                'new_file_path': os.path.join('my', 'path'),
                'new_workspace': self.workspace.name,
            }],
        }
        # No exception is success
        StrikeConfigurationV2(config)
예제 #10
0
    def test_successful(self):
        """Tests calling StrikeManager.create_strike() successfully"""

        config = {
            'version':
            '1.0',
            'mount':
            'host:/my/path',
            'transfer_suffix':
            '_tmp',
            'files_to_ingest': [{
                'filename_regex': 'foo',
                'workspace_path': 'my/path',
                'workspace_name': self.workspace.name,
            }]
        }

        config = StrikeConfigurationV2(config).get_configuration()
        strike = Strike.objects.create_strike('my_name', 'my_title',
                                              'my_description', config)
        self.assertEqual(strike.job.status, 'QUEUED')
예제 #11
0
파일: views.py 프로젝트: ctc-oss/scale
    def patch_impl(self, request, strike_id):
        """Edits an existing Strike process and returns the updated details

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param strike_id: The ID of the Strike process
        :type strike_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        title = rest_util.parse_string(request, 'title', required=False)
        description = rest_util.parse_string(request,
                                             'description',
                                             required=False)
        configuration = rest_util.parse_dict(request,
                                             'configuration',
                                             required=False)

        config = None
        try:
            if configuration:
                config = StrikeConfigurationV2(
                    configuration, do_validate=True).get_configuration()
        except InvalidStrikeConfiguration as ex:
            raise BadParameter('Strike configuration invalid: %s' %
                               unicode(ex))

        try:
            Strike.objects.edit_strike(strike_id, title, description, config)

            strike = Strike.objects.get_details(strike_id)
        except Strike.DoesNotExist:
            raise Http404
        except InvalidStrikeConfiguration as ex:
            logger.exception('Unable to edit Strike process: %s', strike_id)
            raise BadParameter(unicode(ex))

        serializer = self.get_serializer(strike)
        return Response(serializer.data)