Esempio n. 1
0
    def _create_plugin(self, plg_repr, compute_resource):
        """
        Private utility method to register/add a new plugin into the system.
        """
        meta_data = {
            'name': plg_repr.pop('name'),
            'stars': plg_repr.pop('stars', 0),
            'public_repo': plg_repr.pop('public_repo', ''),
            'license': plg_repr.pop('license', ''),
            'type': plg_repr.pop('type'),
            'icon': plg_repr.pop('icon', ''),
            'category': plg_repr.pop('category', ''),
            'authors': plg_repr.pop('authors', '')
        }
        parameters_data = plg_repr.pop('parameters')

        # check whether plugin_name does not exist and validate the plugin meta data
        try:
            meta = PluginMeta.objects.get(name=meta_data['name'])
            meta_serializer = PluginMetaSerializer(meta, data=meta_data)
        except PluginMeta.DoesNotExist:
            meta_serializer = PluginMetaSerializer(data=meta_data)
        meta_serializer.is_valid(raise_exception=True)

        # validate the plugin's versioned data
        plg_serializer = PluginSerializer(data=plg_repr)
        plg_serializer.is_valid(raise_exception=True)

        # collect and validate parameters
        parameters_serializers = []
        for parameter in parameters_data:
            default = parameter.pop('default', None)
            parameter_serializer = PluginParameterSerializer(data=parameter)
            parameter_serializer.is_valid(raise_exception=True)
            serializer_dict = {
                'serializer': parameter_serializer,
                'default_serializer': None
            }
            if default is not None:
                param_type = parameter['type']
                default_param_serializer = DEFAULT_PARAMETER_SERIALIZERS[
                    param_type](data={
                        'value': default
                    })
                default_param_serializer.is_valid(raise_exception=True)
                serializer_dict[
                    'default_serializer'] = default_param_serializer
            parameters_serializers.append(serializer_dict)

        # if no validation errors at this point then save to the DB

        pl_meta = meta_serializer.save()
        plugin = plg_serializer.save(meta=pl_meta,
                                     compute_resources=[compute_resource])
        for param_serializer_dict in parameters_serializers:
            param = param_serializer_dict['serializer'].save(plugin=plugin)
            if param_serializer_dict['default_serializer'] is not None:
                param_serializer_dict['default_serializer'].save(
                    plugin_param=param)
        return plugin
Esempio n. 2
0
 def add_pipeline(self, args):
     """
     Register/add a new plugin to the system.
     """
     timeout = 30
     if args.storetimeout:
         timeout = args.storetimeout
     plg_repr = self.get_plugin_representation_from_store(args.name, args.storeurl,
                                                          args.storeusername,
                                                          args.storepassword, timeout)
     parameters_data = plg_repr['parameters']
     del plg_repr['parameters']
     plg_serializer = PluginSerializer(data=plg_repr)
     plg_serializer.is_valid(raise_exception=True)
     (compute_resource, tf) = ComputeResource.objects.get_or_create(
         compute_resource_identifier=args.computeresource)
     plugin = plg_serializer.save(compute_resource=compute_resource)
     # collect parameters and validate and save them to the DB
     for parameter in parameters_data:
         default = parameter['default'] if 'default' in parameter else None
         del parameter['default']
         parameter_serializer = PluginParameterSerializer(data=parameter)
         parameter_serializer.is_valid(raise_exception=True)
         param = parameter_serializer.save(plugin=plugin)
         if default is not None:
             default_param_serializer = DEFAULT_PARAMETER_SERIALIZERS[param.type](
                 data={'value': default})
             default_param_serializer.is_valid(raise_exception=True)
             default_param_serializer.save(plugin_param=param)
Esempio n. 3
0
    def modify_pipeline(self, args):
        """
        Modify an existing/registered plugin and add the current date as a new plugin
        modification date.
        """
        plugin = self.get_plugin(args.name)
        compute_resource = None
        plg_repr = None
        if args.computeresource:
            (compute_resource, tf) = ComputeResource.objects.get_or_create(
                compute_resource_identifier=args.computeresource)
        if args.storeurl:
            timeout = 30
            if args.storetimeout:
                timeout = args.storetimeout
            plg_repr = self.get_plugin_representation_from_store(args.name, args.storeurl,
                                                                 args.storeusername,
                                                                 args.storepassword,
                                                                 timeout)
        if plg_repr:
            parameters_data = plg_repr['parameters']
            del plg_repr['parameters']
            plg_serializer = PluginSerializer(plugin, data=plg_repr)
            plg_serializer.is_valid(raise_exception=True)
            plugin = plg_serializer.save(compute_resource=compute_resource)
            # collect existing and new parameters and validate and save them to the DB
            db_parameters = plugin.parameters.all()
            for parameter in parameters_data:
                default = parameter['default'] if 'default' in parameter else None
                del parameter['default']
                db_param = [p for p in db_parameters if p.name == parameter['name']]
                if db_param:
                    parameter_serializer = PluginParameterSerializer(db_param[0],
                                                                     data=parameter)
                else:
                    parameter_serializer = PluginParameterSerializer(data=parameter)
                parameter_serializer.is_valid(raise_exception=True)
                param = parameter_serializer.save(plugin=plugin)
                if default is not None:
                    db_default = param.get_default()
                    if db_default is not None: # check if there is already a default in DB
                        default_param_serializer = DEFAULT_PARAMETER_SERIALIZERS[
                            param.type](db_default, data={'value': default})
                    else:
                        default_param_serializer = DEFAULT_PARAMETER_SERIALIZERS[
                            param.type](data={'value': default})
                    default_param_serializer.is_valid(raise_exception=True)
                    default_param_serializer.save(plugin_param=param)
        elif compute_resource:
            plg_serializer = PluginSerializer(plugin)
            plugin = plg_serializer.save(compute_resource=compute_resource)

        if plg_repr or compute_resource:
            plugin.modification_date = timezone.now()
            plugin.save()
Esempio n. 4
0
    def add_plugin(self, args):
        """
        Register/add a new plugin to the system.
        """
        plg_repr = self.get_plugin_representation_from_store(
            args.name, args.storeurl, args.version, args.storeusername,
            args.storepassword, args.storetimeout)
        parameters_data = plg_repr['parameters']
        del plg_repr['parameters']
        plg_serializer = PluginSerializer(data=plg_repr)
        plg_serializer.is_valid(raise_exception=True)

        # collect and validate parameters
        parameters_serializers = []
        for parameter in parameters_data:
            default = parameter.pop('default', None)
            parameter_serializer = PluginParameterSerializer(data=parameter)
            parameter_serializer.is_valid(raise_exception=True)
            serializer_dict = {
                'serializer': parameter_serializer,
                'default_serializer': None
            }
            if default is not None:
                param_type = parameter['type']
                default_param_serializer = DEFAULT_PARAMETER_SERIALIZERS[
                    param_type](data={
                        'value': default
                    })
                default_param_serializer.is_valid(raise_exception=True)
                serializer_dict[
                    'default_serializer'] = default_param_serializer
            parameters_serializers.append(serializer_dict)

        # if no validation errors at this point then save to the DB
        (compute_resource, tf) = ComputeResource.objects.get_or_create(
            compute_resource_identifier=args.computeresource)
        plugin = plg_serializer.save(compute_resource=compute_resource)
        for param_serializer_dict in parameters_serializers:
            param = param_serializer_dict['serializer'].save(plugin=plugin)
            if param_serializer_dict['default_serializer'] is not None:
                param_serializer_dict['default_serializer'].save(
                    plugin_param=param)
Esempio n. 5
0
    def add_plugin(self, args):
        """
        Register/add a new plugin to the system.
        """
        plg_repr = self.get_plugin_representation_from_store(args.name, args.storeurl,
                                                             args.version,
                                                             args.storeusername,
                                                             args.storepassword,
                                                             args.storetimeout)
        parameters_data = plg_repr['parameters']
        del plg_repr['parameters']
        plg_serializer = PluginSerializer(data=plg_repr)
        plg_serializer.is_valid(raise_exception=True)

        # collect parameters and validate and save them to the DB
        parameters_serializers = []
        for parameter in parameters_data:
            default = None
            if 'default' in parameter:
                default = parameter['default']
                del parameter['default']
            parameter_serializer = PluginParameterSerializer(data=parameter)
            parameter_serializer.is_valid(raise_exception=True)
            serializer_dict = {'serializer': parameter_serializer,
                               'default_serializer': None}
            if default is not None:
                param_type = parameter['type']
                default_param_serializer = DEFAULT_PARAMETER_SERIALIZERS[param_type](
                    data={'value': default})
                default_param_serializer.is_valid(raise_exception=True)
                serializer_dict['default_serializer'] = default_param_serializer
            parameters_serializers.append(serializer_dict)

        # if no validation errors at this point then save to the DB
        (compute_resource, tf) = ComputeResource.objects.get_or_create(
            compute_resource_identifier=args.computeresource)
        plugin = plg_serializer.save(compute_resource=compute_resource)
        for param_serializer_dict in parameters_serializers:
            param = param_serializer_dict['serializer'].save(plugin=plugin)
            if param_serializer_dict['default_serializer'] is not None:
                param_serializer_dict['default_serializer'].save(plugin_param=param)
    def test_validate_validates_parameters_of_path_type_and_optional(self):
        """
        Test whether overriden validate method raises a ValidationError when
        a plugin parameter is optional anf of type 'path' or 'unextpath'.
        """
        with self.assertRaises(serializers.ValidationError):
            plg_param_serializer = PluginParameterSerializer()
            plg_param_serializer.validate({'optional': True, 'type': 'path'})
        with self.assertRaises(serializers.ValidationError):

            plg_param_serializer = PluginParameterSerializer()
            plg_param_serializer.validate({
                'optional': True,
                'type': 'unextpath'
            })
Esempio n. 7
0
    def modify_plugin(self, args):
        """
        Modify an existing/registered plugin and add the current date as a new plugin
        modification date.
        """
        plugin = self.get_plugin(args.name)
        compute_resource = None
        plg_repr = None
        if args.computeresource:
            (compute_resource, tf) = ComputeResource.objects.get_or_create(
                compute_resource_identifier=args.computeresource)
        if args.storeurl and args.storeusername and args.storepassword:
            timeout = 30
            if args.storetimeout:
                timeout = args.storetimeout
            plg_repr = self.get_plugin_representation_from_store(
                args.name, args.storeurl, args.storeusername,
                args.storepassword, timeout)
        if plg_repr:
            parameters_data = plg_repr['parameters']
            del plg_repr['parameters']
            plg_serializer = PluginSerializer(plugin, data=plg_repr)
            plg_serializer.is_valid(raise_exception=True)
            plugin = plg_serializer.save(compute_resource=compute_resource)
            # collect existing and new parameters and validate and save them to the DB
            db_parameters = plugin.parameters.all()
            for parameter in parameters_data:
                db_param = [
                    p for p in db_parameters if p.name == parameter['name']
                ]
                if db_param:
                    parameter_serializer = PluginParameterSerializer(
                        db_param[0], data=parameter)
                else:
                    parameter_serializer = PluginParameterSerializer(
                        data=parameter)
                parameter_serializer.is_valid(raise_exception=True)
                parameter_serializer.save(plugin=plugin)
        elif compute_resource:
            plg_serializer = PluginSerializer(plugin)
            plugin = plg_serializer.save(compute_resource=compute_resource)

        if plg_repr or compute_resource:
            plugin.modification_date = timezone.now()
            plugin.save()
Esempio n. 8
0
 def add_plugin(self, args):
     """
     Register/add a new plugin to the system.
     """
     timeout = 30
     if args.storetimeout:
         timeout = args.storetimeout
     plg_repr = self.get_plugin_representation_from_store(
         args.name, args.storeurl, args.storeusername, args.storepassword,
         timeout)
     parameters_data = plg_repr['parameters']
     del plg_repr['parameters']
     plg_serializer = PluginSerializer(data=plg_repr)
     plg_serializer.is_valid(raise_exception=True)
     (compute_resource, tf) = ComputeResource.objects.get_or_create(
         compute_resource_identifier=args.computeresource)
     plugin = plg_serializer.save(compute_resource=compute_resource)
     # collect parameters and validate and save them to the DB
     for parameter in parameters_data:
         parameter_serializer = PluginParameterSerializer(data=parameter)
         parameter_serializer.is_valid(raise_exception=True)
         parameter_serializer.save(plugin=plugin)