<div dir="ltr"><div>To make sure this was feasable, I've created proof of concept PRs for pulpcore and pulp_file. All of the proposed changes are proofed, but not all work is done. For example, sync is implemented, but not publish.</div><div><ul><li><a href="https://github.com/pulp/pulp/pull/3394">https://github.com/pulp/pulp/pull/3394</a><br></li><li><a href="https://github.com/pulp/pulp_file/pull/61">https://github.com/pulp/pulp_file/pull/61</a><br></li></ul><div>I am very pleased with how it turned out, and I think it will make plugin writing even easier. I documented the design on a redmine issue. I encourage feedback/discussion on the issue.</div></div><div><br></div><div><a href="https://pulp.plan.io/issues/3522">https://pulp.plan.io/issues/3522</a><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 20, 2018 at 7:46 AM, Milan Kovacik <span dir="ltr"><<a href="mailto:mkovacik@redhat.com" target="_blank">mkovacik@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Fri, Mar 16, 2018 at 4:55 PM, Milan Kovacik <<a href="mailto:mkovacik@redhat.com">mkovacik@redhat.com</a>> wrote:<br>
><br>
><br>
><br>
> On Thu, Mar 15, 2018 at 9:21 PM, Austin Macdonald <<a href="mailto:austin@redhat.com">austin@redhat.com</a>> wrote:<br>
>><br>
>> I spoke with daviddavis about this and I would like to narrow the scope a bit. This discussion should be limited to endpoints that deploy tasks. The possibility for collisions that David pointed out regarding v3/content/<type>/ is real, but should be discussed separately because Content objects should follow the pattern of the other plugin defined objects. All of them are master/detail so the namespacing v3/plugin/<type>/content/ would go deeply against the grain.<br>
>><br>
>><br>
>> On Mar 15, 2018 10:53, "David Davis" <<a href="mailto:daviddavis@redhat.com">daviddavis@redhat.com</a>> wrote:<br>
>>><br>
>>> I have an amendment to this proposal. Instead of namespacing just the plugin task routes, I’d propose we namespace all plugin routes. Thus all plugin routes would be namespaced under something like “/api/v3/plugin/<plugin name>/“. For example, “/api/v3/content/file/” gets moved to “/api/v3/plugin/file/content/” and so on.<br>
>>><br>
>>><br>
>>> For task routes, plugins could still route to a pulpcore viewset/action:<br>
>>><br>
>>> User route: POST /api/v3/plugin/file/<wbr>repository_version/ add_content=[…]<br>
>>><br>
>>> Routes to: POST /api/v3/tasks plugin=file task=create_repository_version add_content=[…]<br>
>><br>
>><br>
>> AFAIK, we don't have a good mechanism for validating and re-routing endpoints quite like this. Instead, a view or viewset would be created, validation performed, and then a task is deployed. The task itself could be a vanilla task from pulpcore though. Another issue is that a POST to v3/plugin/file/repository_<wbr>version/ implies that the resultant repository_version is typed in some way. The created resource href would still take the form v3/repositories/1234/versions/<wbr>2/, so I think this is a little misleading.<br>
><br>
><br>
> +1 to generic Pulp concepts/objects staying outside of a plug-in namespace/path<br>
><br>
>><br>
>><br>
>> For the other endpoint:<br>
>>  /api/v3/tasks plugin=file task=create_repository_version add_content=[…]<br>
>><br>
>> There is a still the problem is that POST requests should not contain parameters that influence the allowable parameter set. For instance, plugin=python might require an additional parameter that is not allowed for the file plugin. In particular, this affects the auto-documented REST API.<br>
>><br>
>><br>
>> However, the concept in general could work. I've adapted David's suggestion and will present it side by side with the original idea. Note, this only applies to "actions", which are sync, publish, add/remove, and plugin-specific actions (including rich-dependency adding).<br>
>><br>
>> The difference between the two ideas is based in semantics. Both would deploy the same task functions.<br>
>><br>
>> "Action Based"<br>
>> POST v3/plugin/file/sync/<br>
>> Note that "sync" is singular. This is a file-plugin action to sync using the body parameters.<br>
><br>
><br>
> - 1 as this might imply mixing <synchronous> and <asynchronous> actions while all the time, asynchronous actions, such as the sync call, always create a task object; the user would be creating the task objects at one endpoint but deleting, filtering, tracking those at another.<br>
><br>
>><br>
>><br>
>> "Task Object Based"<br>
>> POST v3/tasks/file/syncs/<br>
>> Note that "syncs" is plural. This is a POST that creates a file-sync task object,.<br>
<br>
</span>Btw an interesting consequence of tasks not being objects in a file<br>
importer and publisher are these two issues:<br>
 - The parameters in the API schema for the sync and publish endpoints<br>
are incorrect [1]<br>
 - Not able to access documentation endpoint [2]<br>
<br>
In the former issue, the DRF isn't able to automatically figure out<br>
schema for e.g the `sync` endpoint of the file plug-in importer.<br>
The reason for it is even though the `sync` verb is attached to an<br>
importer object, the parameters passed in aren't supposed to be<br>
importer details so they shouldn't use the importer serializer to get<br>
e.g auto-documented.<br>
Moreover, the result of a call to this endpoint is supposed to be a<br>
task (json object), schema and serialization of which has to be<br>
repeated for the `sync` endpoint to some extent.<br>
Last but not least, it isn't clear whether the `sync` verb should<br>
belong to an importer or a repo, or something else as the call<br>
"responsibility" is spread somewhat between both and none.<br>
<br>
The latter issue is a consequence of the lack of support in DRF for<br>
what the `sync` verb requires documenting thru its schema, which IMO<br>
underlines the `sync` endpoint being odd, a misplaced task probably.<br>
<br>
Cheers,<br>
milan<br>
<br>
<br>
<br>
[1] <a href="https://pulp.plan.io/issues/3351" rel="noreferrer" target="_blank">https://pulp.plan.io/issues/<wbr>3351</a><br>
[2] <a href="https://pulp.plan.io/issues/3420" rel="noreferrer" target="_blank">https://pulp.plan.io/issues/<wbr>3420</a><br>
<div class="HOEnZb"><div class="h5"><br>
><br>
> + 1 for typed objects<br>
><br>
>     # adding content to a repo version (already mentioned by Austin but I like it)<br>
>     POST@v3/tasks/docker/content_<wbr>additions/<br>
><br>
>     # synchronize the Zoo repo<br>
>     pulp-admin create tasks rpm syncs --repo-id zoo --importer-id zoo-importer --sync-config-override '{"ssl": "false"}' --format=json | tee /tmp/inttest01_sync_task.json | pulp-admin track tasks --format json -<br>
><br>
>     # get all docker content additions tasks since yesterday<br>
>     pulp-admin list tasks docker content_additions --format=csv --fields=id,worker_id --filter=started_at__gt=<<wbr>yesterday><br>
><br>
>     # get all tasks since yesterday<br>
>     pulp-admin list tasks  --filter=started_at__gt=<<wbr>yesterday> --format=yaml<br>
><br>
>><br>
>> Discussion:<br>
>> Another consideration is "Where will a Live API live?". A benefit of David's proposal is that we would be providing plugins with a namespaced area to do whatever they need, from live api to actions. We probably would want to create this namespace for things like live apis even if we go in the tasks/file/syncs/ direction. The only downside of this part of David's proposal is that our endpoints will still be "action" verbs instead of nouns, and I am ok with that.<br>
><br>
><br>
> I'd suggest live API actions that create task object subclasses (generic Pulp concept) reside in namespaced tasks path; this would still allow the user to apply generic concepts<br>
>     POST@/v3/tasks/file/<wbr>frobnications/<br>
><br>
>     pulp-admin create tasks file frobications --foo=bar --format json | pulp-admin track tasks --format json --<br>
><br>
> Other live API endpoints (not creating task objects) might be kept under namespaces<br>
>     POST@v3/plugins/file/shake/<{<wbr>level: strong}<br>
><br>
> pulp-admin plugins file shake --level=strong<br>
><br>
>><br>
>> ______________________________<wbr>_________________<br>
>> Pulp-dev mailing list<br>
>> <a href="mailto:Pulp-dev@redhat.com">Pulp-dev@redhat.com</a><br>
>> <a href="https://www.redhat.com/mailman/listinfo/pulp-dev" rel="noreferrer" target="_blank">https://www.redhat.com/<wbr>mailman/listinfo/pulp-dev</a><br>
>><br>
><br>
> Cheers,<br>
> milan<br>
><br>
</div></div></blockquote></div><br></div>