[ 
https://issues.apache.org/jira/browse/YARN-11874?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18030927#comment-18030927
 ] 

ASF GitHub Bot commented on YARN-11874:
---------------------------------------

slfan1989 commented on code in PR #8033:
URL: https://github.com/apache/hadoop/pull/8033#discussion_r2442882495


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/jsonprovider/JsonProviderFeature.java:
##########
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.yarn.server.resourcemanager.webapp.jsonprovider;
+
+import javax.ws.rs.core.Feature;
+import javax.ws.rs.core.FeatureContext;
+
+import org.glassfish.jersey.CommonProperties;
+
+/**
+ * A JAX-RS {@link Feature} that registers custom MOXy JSON providers
+ * for handling serialization and deserialization of JSON with or without
+ * root elements.
+ * <p>
+ * This feature disables MOXy's automatic provider discovery to ensure
+ * that the custom providers {@link IncludeRootJSONProvider} and
+ * {@link ExcludeRootJSONProvider} are used explicitly with defined priorities.
+ * </p>
+ *
+ * <p>Configuration details:</p>
+ * <ul>
+ *   <li>Disables automatic MOXy JSON feature discovery by setting
+ *       {@link 
org.glassfish.jersey.CommonProperties#MOXY_JSON_FEATURE_DISABLE} to {@code 
true}.</li>
+ *   <li>Registers {@link IncludeRootJSONProvider} with priority {@code 
2001}.</li>
+ *   <li>Registers {@link ExcludeRootJSONProvider} with priority {@code 
2002}.</li>
+ * </ul>
+ *
+ * @see IncludeRootJSONProvider
+ * @see ExcludeRootJSONProvider
+ * @see org.glassfish.jersey.CommonProperties#MOXY_JSON_FEATURE_DISABLE
+ */
+public class JsonProviderFeature implements Feature {
+
+  /**
+   * Configures the feature by registering the custom JSON providers
+   * and disabling MOXy auto-discovery.
+   *
+   * @param context the {@link FeatureContext} provided by the JAX-RS runtime
+   * @return {@code true} to indicate that the feature was successfully 
configured
+   */
+  @Override
+  public boolean configure(FeatureContext context) {
+    //Auto discovery should be disabled to ensure the custom providers will be 
used
+    context.property(CommonProperties.MOXY_JSON_FEATURE_DISABLE, true);

Review Comment:
   Looks like `2001` and `2002` are priority values that control the provider 
order, right?
   Maybe we could add a short comment to explain their meaning — it would make 
the intent clearer for future contributors.



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/resources/webapp/configmutation-absolute-hierarchy-after-update.json:
##########
@@ -59,15 +59,13 @@
                 "vCores" : 0,
                 "resourceInformations" : {
                   "resourceInformation" : [ {
-                    "attributes" : "",

Review Comment:
   Rather than deleting `"attributes": ""`, we should change it back to 
`"attributes": { }` to maintain the expected JSON format.



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHA.java:
##########
@@ -178,7 +175,8 @@ private void checkActiveRMWebServices() throws 
JSONException {
         .get(Response.class);
     assertEquals(MediaType.APPLICATION_JSON_TYPE + ";" + JettyUtils.UTF_8,
         response.getMediaType().toString());
-    JSONObject json = response.readEntity(JSONObject.class);

Review Comment:
   Any chance we can keep this pattern?
   
   I find `response.readEntity(JSONObject.class);` cleaner and more intuitive — 
it’s also how things worked back in Jersey 1.





> ResourceManager REST api scheduler info contains @xsi.type instead of type
> --------------------------------------------------------------------------
>
>                 Key: YARN-11874
>                 URL: https://issues.apache.org/jira/browse/YARN-11874
>             Project: Hadoop YARN
>          Issue Type: Bug
>          Components: yarn
>    Affects Versions: 3.5.0
>            Reporter: Bence Kosztolnik
>            Assignee: Bence Kosztolnik
>            Priority: Major
>              Labels: pull-request-available
>
> *Problem statement:*
> The /ws/v1/cluster/scheduler returns with invalid response
> {code:java}
> {
>     "scheduler": {
>         "schedulerInfo": {
>                  "@xsi.type":"fifoScheduler",
>                  "capacity":1,
>                  ...
> {code}
> instead of this:
> {code:java}
> {
>     "scheduler": {
>         "schedulerInfo": {
>                  "type":"fifoScheduler",
>                  "capacity":1,
>                  ...
> {code}
> source: 
> https://hadoop.apache.org/docs/stable/hadoop-yarn/hadoop-yarn-site/ResourceManagerRest.html#Cluster_Scheduler_API
> *Repro:*
> 1) Modify the TestRMWebServices#verifyClusterSchedulerFifo and add the line
> {code:java}
>     assertTrue(info.has("type"),  "incorrect type of element: " + info);
> {code}
> 2) Run the testClusterSchedulerFifo test, it will fail
> *Possible root cause:*
> I think during the jersey2 upgrade when 
> *org.apache.hadoop.yarn.server.resourcemanager.webapp.JAXBContextResolver* 
> was modified with replacement of *com.sun.jersey.api.json.JSONJAXBContext* to 
> *org.glassfish.jersey.jettison.JettisonJaxbContext* we changed the 
> behaviourment how we convert the XML models to JSON in the REST API.
> https://github.com/apache/hadoop/blob/06d36f5a6a1a01d159bef75b22ca2845e8c90bad/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/JAXBContextResolver.java#L158
> *Other failures:*
> When we generate a UI list with only one element it will be converted to json 
> object instead of list with single element.
> For example the doc says
> {noformat}
> queues        array of queues(JSON)/zero or more queue objects(XML)
> {noformat}
> in context of schedulerInfo object, but if we have just one queue it wont be 
> an array, just a simple queue object.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to