eclipse-tractusx / tractusx-edc

Apache License 2.0
44 stars 54 forks source link

HTTP 500 on /v2/edrs/request with sortField #1380

Closed arnoweiss closed 4 months ago

arnoweiss commented 5 months ago

Describe the bug

When trying to sort for the createdAt property of an EDR, the Consumer Control Plane returns HTTP 500.

To Reproduce

  1. Provider: Create passable contract definition
  2. Consumer: Negotiate, trigger transfer into EDR cache. Twice.
  3. Execute POST /v2/edrs/request with body:
    {
    "@context": {
    "@vocab": "https://w3id.org/edc/v0.0.1/ns/"
    },
    "@type": "QuerySpec",
    "offset": 0,
    "limit": 10,
    "sortOrder": "DESC",
    "sortField": "createdAt",
    "filterExpression": [
    {
      "operandLeft": "assetId",
      "operator": "=",
      "operandRight": "27832ff3-11d7-45c9-9b95-fbaadd43db8a"
    },
    {
      "operandLeft": "providerId",
      "operator": "=",
      "operandRight": "BPNL00000007RF54"
    }
    ]
    }
  4. Behold HTTP 500 response
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" />
        <title>Error 500 Internal Server Error</title>
    </head>
    <body>
        <h2>HTTP ERROR 500 Internal Server Error</h2>
        <table>
            <tr>
                <th>URI:</th>
                <td>/management/v2/edrs/request</td>
            </tr>
            <tr>
                <th>STATUS:</th>
                <td>500</td>
            </tr>
            <tr>
                <th>MESSAGE:</th>
                <td>Internal Server Error</td>
            </tr>
            <tr>
                <th>SERVLET:</th>
                <td>EDC-management</td>
            </tr>
        </table>
    </body>
    </html>

Expected behavior

HTTP 200 with the relevant EDRs sorted by creation timestamp. Similar scenarios:

Screenshots/Error Messages

Control Plane Logs

SEVERE 2024-06-26T07:46:01.422176612 JerseyExtension: Unexpected exception caught
org.eclipse.edc.spi.EdcException: Cannot sort by createdAt because the field does not exist
    at org.eclipse.edc.transaction.local.LocalTransactionContext.execute(LocalTransactionContext.java:81)
    at org.eclipse.edc.edr.store.index.SqlEndpointDataReferenceEntryIndex.query(SqlEndpointDataReferenceEntryIndex.java:63)
    at org.eclipse.edc.edr.store.EndpointDataReferenceStoreImpl.lambda$query$2(EndpointDataReferenceStoreImpl.java:58)
    at org.eclipse.edc.transaction.local.LocalTransactionContext.execute(LocalTransactionContext.java:74)
    at org.eclipse.edc.edr.store.EndpointDataReferenceStoreImpl.query(EndpointDataReferenceStoreImpl.java:58)
    at org.eclipse.tractusx.edc.api.edr.v2.EdrCacheApiController.requestEdrEntries(EdrCacheApiController.java:130)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:146)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:189)
    at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:219)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:93)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:478)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:400)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:81)
    at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:263)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:266)
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:242)
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:697)
    at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:394)
    at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:358)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:312)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:529)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1381)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:484)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1303)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:192)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
    at org.eclipse.jetty.server.Server.handle(Server.java:563)
    at org.eclipse.jetty.server.HttpChannel$RequestDispatchable.dispatch(HttpChannel.java:1598)
    at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:753)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:501)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:287)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:314)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
    at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
    at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:421)
    at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:390)
    at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:277)
    at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.run(AdaptiveExecutionStrategy.java:199)
    at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:411)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:969)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1194)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1149)
    at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: Cannot sort by createdAt because the field does not exist
    at org.eclipse.edc.sql.translation.SqlQueryStatement.parseSortField(SqlQueryStatement.java:171)
    at org.eclipse.edc.sql.translation.SqlQueryStatement.initialize(SqlQueryStatement.java:161)
    at org.eclipse.edc.sql.translation.SqlQueryStatement.<init>(SqlQueryStatement.java:74)
    at org.eclipse.edc.sql.translation.SqlQueryStatement.<init>(SqlQueryStatement.java:58)
    at org.eclipse.edc.edr.store.index.sql.schema.BaseSqlDialectStatements.createQuery(BaseSqlDialectStatements.java:78)
    at org.eclipse.edc.edr.store.index.SqlEndpointDataReferenceEntryIndex.lambda$query$1(SqlEndpointDataReferenceEntryIndex.java:66)
    at org.eclipse.edc.transaction.local.LocalTransactionContext.execute(LocalTransactionContext.java:74)
    ... 57 more

Context Information

Possible Implementation

This may be an upstream issue. The relevant class (EndpointDataReferenceEntry) indeed has no createdAt field. Other payloads (such as IdResponse) have it. Yet, the createdAt property is correctly returned if the sortField and sortProperty are not set in the QuerySpec request.

wolf4ood commented 5 months ago

Hi @arnoweiss

i would not consider this a bug, this is a feature request of sorting by createdAt property. It could be that the sorting option is not available on that field in upstream EDC. I would consider this as enhancement and raise the request in upstream EDC

wolf4ood commented 5 months ago

Raised also on upstream EDC

arnoweiss commented 5 months ago

Thanks! What feels buggy is that the case isn't handled (leading to HTTP 500) and the inconsistency between /v2/edrs/request and /v2/policydefinitions/request. That's why I'd leave it open and see if the feature upstream fixes that behavior.

wolf4ood commented 5 months ago

Yeah, i understand that feels buggy, but imho it's a missing feature (sorting by a field) instead of a wrong behavior :)

wolf4ood commented 4 months ago

Hi @arnoweiss

it has been implemented in upstream EDC in this PR

https://github.com/eclipse-edc/Connector/pull/4337

I guess it will be available in the next TX-EDC release

wolf4ood commented 4 months ago

Hey @arnoweiss

closing this. The upstream https://github.com/eclipse-edc/Connector/pull/4337 has been included in upstream 0.8.0 and therefore in the tractusx-edc 0.8.0-rc1