是否可以使用Spring Cloud DataFlow Java Rest客户端获取所有流的列表?

发布于 2025-01-18 21:08:40 字数 794 浏览 6 评论 0原文

我正在使用 Spring Cloud Dataflow Java Rest 客户端 (https:/ /docs.spring.io/spring-cloud-dataflow/docs/current/api/)并希望使用它来检索所有当前部署的流。

获取 StreamOperations 对象并从中获取流列表非常简单:

val template = DataFlowTemplate(<someUri>)
val streamOperations = template.streamOperations()
val streamDefinitionResources = streamOperations.list()

上面的 streamDefinitionResources 实际上是一个 PagedModel ,它使用 2000 的页面大小保存结果的第一页。

但是,我没有看到任何方法来迭代所有页面以使用 java Rest 客户端获取所有流(即,没有通过 StreamOperations 或 StreamDefinitionResource 类提供的分页支持)。

是否可以仅使用 java Rest 客户端获取所有流?我错过了什么吗?

I'm using the spring cloud dataflow java rest client (https://docs.spring.io/spring-cloud-dataflow/docs/current/api/) and want to use it to retrieve all currently deployed streams.

It's easy enough to get a StreamOperations object and get a list of streams from it:

val template = DataFlowTemplate(<someUri>)
val streamOperations = template.streamOperations()
val streamDefinitionResources = streamOperations.list()

The streamDefinitionResources in the above is actually a PagedModel<StreamDefinitionResource>, that holds the first page of results using a page size of 2000.

I don't, however, see any way to iterate through all the pages to get all the streams using the java rest client (i.e. there's no paging support available via the StreamOperations or StreamDefinitionResource classes).

Is it possible to get all the streams using only the java rest client? Am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遥远的绿洲 2025-01-25 21:08:40

摘要

PagedModel 有一个 getNextLink() 方法,可用于手动遍历结果的“下一页”。

详细信息

底层 Dataflow REST API 支持通过页码和大小请求参数进行分页,并返回 HAL 响应,其中包含指向下一页和上一页的_链接

例如,给定 10 个流定义,此 HTTP 请求:

GET localhost:9393/streams/definitions?page=0&size=2

返回以下响应:

{
  _embedded: {
    streamDefinitionResourceList: [
      {
        name: "ticktock1",
        dslText: "time | log",
        originalDslText: "time | log",
        status: "undeployed",
        description: "",
        statusDescription: "The app or group is known to the system, but is not currently deployed",
        _links: {
          self: {
            href: "http://localhost:9393/streams/definitions/ticktock1"
          }
        }
      },
      {
        name: "ticktock2",
        dslText: "time | log",
        originalDslText: "time | log",
        status: "undeployed",
        description: "",
        statusDescription: "The app or group is known to the system, but is not currently deployed",
        _links: {
          self: {
            href: "http://localhost:9393/streams/definitions/ticktock2"
          }
        }
      }
    ]
  },
  _links: {
    first: {
      href: "http://localhost:9393/streams/definitions?page=0&size=2"
    },
    self: {
      href: "http://localhost:9393/streams/definitions?page=0&size=2"
    },
    next: {
      href: "http://localhost:9393/streams/definitions?page=1&size=2"
    },
    last: {
      href: "http://localhost:9393/streams/definitions?page=4&size=2"
    }
  },
  page: {
    size: 2,
    totalElements: 10,
    totalPages: 5,
    number: 0
  }
}

Dataflow Java REST 客户端在 PagedModel 响应中公开此 HAL 响应,该响应提供 getNextLink()代码>方法。

警告 1) 但是,当前的实现(正如您所指出的)被硬编码为 2000 的页面大小。这意味着只有超过 2000 流定义,您才会看到此行为。

注意事项 2) 另一点需要注意的是,不会自动处理链接到“下一页”的遍历,您需要手动调用链接 URL 来检索下一页。

假设 StreamOperations.list 接受页面大小参数,代码可能如下所示:

int pageSize = 2;
PagedModel<StreamDefinitionResource> pageOfStreamDefs = streamOperations().list(pageSize);
pageOfStreamDefs.getNextLink()
    .ifPresent((link) ->  someFunctionToInvokeAndProcessNextPage(link.getHref());

有关 REST API 参数的更多详细信息,请访问 此处

Summary

The PagedModel<StreamDefinitionResource> has a getNextLink() method that you can use to manually traverse the "next" page of results.

Details

The underlying Dataflow REST API supports paging via page number and size request parameters and returns HAL responses that include _links to the next and previous pages.

For example, given 10 stream definitions this HTTP request:

GET localhost:9393/streams/definitions?page=0&size=2

returns the following response:

{
  _embedded: {
    streamDefinitionResourceList: [
      {
        name: "ticktock1",
        dslText: "time | log",
        originalDslText: "time | log",
        status: "undeployed",
        description: "",
        statusDescription: "The app or group is known to the system, but is not currently deployed",
        _links: {
          self: {
            href: "http://localhost:9393/streams/definitions/ticktock1"
          }
        }
      },
      {
        name: "ticktock2",
        dslText: "time | log",
        originalDslText: "time | log",
        status: "undeployed",
        description: "",
        statusDescription: "The app or group is known to the system, but is not currently deployed",
        _links: {
          self: {
            href: "http://localhost:9393/streams/definitions/ticktock2"
          }
        }
      }
    ]
  },
  _links: {
    first: {
      href: "http://localhost:9393/streams/definitions?page=0&size=2"
    },
    self: {
      href: "http://localhost:9393/streams/definitions?page=0&size=2"
    },
    next: {
      href: "http://localhost:9393/streams/definitions?page=1&size=2"
    },
    last: {
      href: "http://localhost:9393/streams/definitions?page=4&size=2"
    }
  },
  page: {
    size: 2,
    totalElements: 10,
    totalPages: 5,
    number: 0
  }
}

The Dataflow Java REST client exposes this HAL response in the PagedModel<StreamDefinitionResource> response which provides a getNextLink() method.

Caveat 1) However, the current implementation (as you pointed out) is hardcoded to page size of 2000. This means you would not see this behavior until you had more than 2000 stream definitions.

Caveat 2) Another point to note is that traversal of the link to the "next" page is not automatically handled and you would need to manually invoke the links URL to retrieve the next page.

Assume the StreamOperations.list accepted a page size parameter the code could look something like this:

int pageSize = 2;
PagedModel<StreamDefinitionResource> pageOfStreamDefs = streamOperations().list(pageSize);
pageOfStreamDefs.getNextLink()
    .ifPresent((link) ->  someFunctionToInvokeAndProcessNextPage(link.getHref());

More details on the REST API parameters can be found here.

七分※倦醒 2025-01-25 21:08:40

我想我有点晚了,但我遇到了同样的问题并找到了解决方法。正如 onobc 所说,任何资源的 PagedModel 都有一个 getNextLink() 方法,该方法返回带有下一页地址的 Link
您可以使用 DataflowTemplate 中的相同 RestTemplate 来处理接下来的请求:

PagedModel<StreamDefinitionResource> streamDefPage = dataflowTemplate.streamOperations().list();
// Process page here
if (streamDefPage.getNextLink().isPresent()) {
    Link link = streamDefPage.getNextLink().get();
    PagedModel<StreamDefinitionResource> streamDefNextPage = dataflowTemplate.getRestTemplate().getForObject(link.getHref(), StreamDefinitionResource.Page.class);
    // Process next page here
}

等等。

希望这有帮助!

I guess I'm a bit late, but I had the same issue and found a workaround. As onobc said, the PagedModel of any resource has a getNextLink() method that returns a Link with the next page address.
You can use the same RestTemplate from DataflowTemplate to handle these next requests:

PagedModel<StreamDefinitionResource> streamDefPage = dataflowTemplate.streamOperations().list();
// Process page here
if (streamDefPage.getNextLink().isPresent()) {
    Link link = streamDefPage.getNextLink().get();
    PagedModel<StreamDefinitionResource> streamDefNextPage = dataflowTemplate.getRestTemplate().getForObject(link.getHref(), StreamDefinitionResource.Page.class);
    // Process next page here
}

And so on.

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文