Skip to content

No GenericResources in ServiceSpec.TaskTemplate.Resources.Reservations #2320

Closed
@johnflavin-fw

Description

@johnflavin-fw

I'm migrating some code that was written using https://github.com/spotify/docker-client over to docker-java. I've found a part of the Docker API that was supported in the spotify client but I can't see a way to use it in docker-java: when creating a service I want to be able to define GenericResources (NamedResourceSpec or DiscreteResourceSpec) in ServiceSpec.TaskTemplate.Resources.Reservations.

Using the spotify client, this is the type of thing I could do

final Map<String, String> genericResources;  // Assume this is defined somewhere
final List<ResourceSpec> resourceSpecs = genericResources.entrySet().stream()
                .map(entry -> StringUtils.isNumeric(entry.getValue()) ?
                        ResourceSpec.DiscreteResourceSpec.builder().kind(entry.getKey()).value(Integer.parseInt(entry.getValue())).build() :
                        ResourceSpec.NamedResourceSpec.builder().kind(entry.getKey()).value(entry.getValue()).build())
                .collect(Collectors.toList());
final ResourceRequirements resourceRequirements =
        ResourceRequirements.builder()
                .reservations(Reservations.builder()
                        .resources(resourceSpecs)
                        .build())
                .build();
final TaskSpec taskSpec = TaskSpec.builder()
                .resources(resourceRequirements)
                .build();
final ServiceSpec serviceSpec = ServiceSpec.builder()
                .taskTemplate(taskSpec)
                .build();
// then pass this to the client to create a service

In the docker-java client I can do similar things, but I can't see a way to pass generic resources to the task spec.

new TaskSpec().withResources(
        new ResourceRequirements().withReservations(
                new ResourceSpecs().with...?  // There is nothing here that takes generic resources
        )
);

I do see abstract class GenericResource<T> and its concrete implementations NamedResourceSpec and DiscreteResourceSpec in com.github.dockerjava.api.model. But it looks to me like those are only used to deserialize Task responses received from the API, not used to create new services in a TaskSpec.

Also NamedResourceSpec and DiscreteResourceSpec are both marked @Deprecated but I can't understand why. That annotation was added to those classes in #1635 but I can't see it mentioned in any of the commits or the discussion.

Is there some reason this isn't supported? It is part of the docker API and has been for quite some time. Alternatively, is there a workaround I could do to inject these generic resource specs directly into the API calls before they are sent? (I'm still getting used to the new(-to-me) way of working with docker-java, so I don't know what low-level tricks I can pull.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions