You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "wzhallright (via GitHub)" <gi...@apache.org> on 2023/12/05 09:14:20 UTC

[PR] HDDS-9831. Remove unnecessary logic in HddsConfServlet [ozone]

wzhallright opened a new pull request, #5733:
URL: https://github.com/apache/ozone/pull/5733

   ## What changes were proposed in this pull request?
   Remove unnecessary logic in HddsConfServlet.java.   
   `response.setContentType()` already defined in doGet()
   
   Please describe your PR in detail:
   
   
   
   ## What is the link to the Apache JIRA
   https://issues.apache.org/jira/browse/HDDS-9831
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-9831. Fix NPE and remove unnecessary logic in HddsConfServlet [ozone]

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #5733:
URL: https://github.com/apache/ozone/pull/5733#discussion_r1418691511


##########
hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/conf/TestHddsConfServlet.java:
##########
@@ -0,0 +1,318 @@
+/**
+ * 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.hdds.conf;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import com.google.gson.Gson;
+import org.apache.hadoop.http.HttpServer2;
+import org.apache.hadoop.thirdparty.com.google.common.base.Strings;
+import org.apache.hadoop.util.XMLUtils;
+import org.eclipse.jetty.util.ajax.JSON;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.mockito.Mockito;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.core.HttpHeaders;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Map;
+
+/** Test for {@link HddsConfServlet}. */
+public class TestHddsConfServlet {
+
+  private static final Map<String, String> TEST_PROPERTIES = new HashMap<>();
+  private static final Map<String, String> TEST_FORMATS = new HashMap<>();
+  private static final String TEST_KEY = "testconfservlet.key";
+  private static final String TEST_VAL = "testval";
+
+  @BeforeAll
+  public static void setup() {
+    TEST_PROPERTIES.put("test.key1", "value1");
+    TEST_PROPERTIES.put("test.key2", "value2");
+    TEST_PROPERTIES.put("test.key3", "value3");
+    TEST_FORMATS.put(HddsConfServlet.FORMAT_XML, "application/xml");
+    TEST_FORMATS.put(HddsConfServlet.FORMAT_JSON, "application/json");
+  }
+
+  @Test
+  public void testParseHeaders() throws Exception {
+    HashMap<String, String> verifyMap = new HashMap<String, String>();
+    verifyMap.put("text/plain", HddsConfServlet.FORMAT_XML);
+    verifyMap.put(null, HddsConfServlet.FORMAT_XML);
+    verifyMap.put("text/xml", HddsConfServlet.FORMAT_XML);
+    verifyMap.put("application/xml", HddsConfServlet.FORMAT_XML);
+    verifyMap.put("application/json", HddsConfServlet.FORMAT_JSON);
+
+    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+    for (Map.Entry<String, String> entry : verifyMap.entrySet()) {
+      String contenTypeActual = entry.getValue();
+      Mockito.when(request.getHeader(HttpHeaders.ACCEPT))
+          .thenReturn(entry.getKey());
+      assertEquals(contenTypeActual,
+          HddsConfServlet.parseAcceptHeader(request));
+    }
+  }
+
+  @Test
+  public void testGetProperty() throws Exception {
+    OzoneConfiguration conf = getPropertiesConf();
+    // list various of property names
+    String[] keys = new String[] {"test1.key1",
+        "test.unknown.key",
+        "",
+        "test.key2",
+        null};
+    for (Map.Entry<String, String> entry : TEST_FORMATS.entrySet()) {
+      for (String key : keys) {
+        verifyGetProperty(conf, entry.getKey(), key);
+      }
+    }
+  }
+
+  @Test
+  public void testGetPropertyWithCmd() throws Exception {
+    OzoneConfiguration conf = getPropertiesConf();
+    conf.getObject(OzoneTestConfig.class);

Review Comment:
   FYI `getObject` call is unnecessary here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-9831. Fix NPE and remove unnecessary logic in HddsConfServlet [ozone]

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #5733:
URL: https://github.com/apache/ozone/pull/5733#issuecomment-1845031085

   Thanks @wzhallright for the fix and adding test coverage for this class.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-9831. Fix NPE and remove unnecessary logic in HddsConfServlet [ozone]

Posted by "wzhallright (via GitHub)" <gi...@apache.org>.
wzhallright commented on PR #5733:
URL: https://github.com/apache/ozone/pull/5733#issuecomment-1844192910

   Usually I use Google Checkstyle to format the code locally, which leads to format confusion between different projects. I fixed checkstyle&findbugs. Please take a look again. Thanks! @adoroszlai 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-9831. Fix NPE and remove unnecessary logic in HddsConfServlet [ozone]

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai merged PR #5733:
URL: https://github.com/apache/ozone/pull/5733


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-9831. Remove unnecessary logic in HddsConfServlet [ozone]

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #5733:
URL: https://github.com/apache/ozone/pull/5733#issuecomment-1841806958

   Thanks @wzhallright for the patch.  Have you had a chance to test it, too?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-9831. Fix NPE and remove unnecessary logic in HddsConfServlet [ozone]

Posted by "wzhallright (via GitHub)" <gi...@apache.org>.
wzhallright commented on PR #5733:
URL: https://github.com/apache/ozone/pull/5733#issuecomment-1842515944

   @adoroszlai Oh, that's a great project. change junit to junit5. Thanks for review.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-9831. Fix NPE and remove unnecessary logic in HddsConfServlet [ozone]

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #5733:
URL: https://github.com/apache/ozone/pull/5733#issuecomment-1842631223

   Thanks @wzhallright for updating the patch.  Please take a look at checkstyle and findbugs failures:
   
   https://github.com/wzhallright/ozone/actions/runs/7112684316/job/19363113952#step:7:11
   
   https://github.com/wzhallright/ozone/actions/runs/7112684316/job/19363114525#step:7:11


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-9831. Remove unnecessary logic in HddsConfServlet [ozone]

Posted by "wzhallright (via GitHub)" <gi...@apache.org>.
wzhallright commented on PR #5733:
URL: https://github.com/apache/ozone/pull/5733#issuecomment-1842192973

   Thanks for review! @adoroszlai . Unit tests have been added, please take a look if you have time.   
   And fixed another hidden bug, if cmd is `getPropertyByTag` but not tags parameter in request, then throw NPE.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org