Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
*/
package org.apache.hadoop.ozone.container.keyvalue;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.LongNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.DeletedBlocksTransaction;
import org.apache.hadoop.hdds.utils.db.BatchOperation;
import org.apache.hadoop.hdds.utils.db.Table;
Expand All @@ -47,7 +47,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.fail;

/**
Expand All @@ -69,17 +68,17 @@ public void testRunDisabled(ContainerTestVersionInfo versionInfo)
// No system property set. Should not run.
System.clearProperty(KeyValueContainerMetadataInspector.SYSTEM_PROPERTY);
ContainerInspectorUtil.load();
assertNull(runInspectorAndGetReport(containerData));
assertTrue(runInspectorAndGetReport(containerData).isEmpty());
ContainerInspectorUtil.unload();

// Unloaded. Should not run even with system property.
System.setProperty(KeyValueContainerMetadataInspector.SYSTEM_PROPERTY,
KeyValueContainerMetadataInspector.Mode.INSPECT.toString());
assertNull(runInspectorAndGetReport(containerData));
assertTrue(runInspectorAndGetReport(containerData).isEmpty());

// Unloaded and no system property. Should not run.
System.clearProperty(KeyValueContainerMetadataInspector.SYSTEM_PROPERTY);
assertNull(runInspectorAndGetReport(containerData));
assertTrue(runInspectorAndGetReport(containerData).isEmpty());
}

@ContainerTestVersionInfo.ContainerTest
Expand Down Expand Up @@ -273,11 +272,11 @@ public void testIncorrectDeleteWithoutTransaction(
public void inspectThenRepairOnCorrectContainer(
KeyValueContainerData containerData) throws Exception {
// No output for correct containers.
assertNull(runInspectorAndGetReport(containerData,
KeyValueContainerMetadataInspector.Mode.INSPECT));
assertTrue(runInspectorAndGetReport(containerData,
KeyValueContainerMetadataInspector.Mode.INSPECT).isEmpty());

assertNull(runInspectorAndGetReport(containerData,
KeyValueContainerMetadataInspector.Mode.REPAIR));
assertTrue(runInspectorAndGetReport(containerData,
KeyValueContainerMetadataInspector.Mode.REPAIR).isEmpty());
}

/**
Expand Down Expand Up @@ -312,8 +311,9 @@ public void inspectThenRepairOnIncorrectContainer(
String containerState = containerData.getState().toString();

// First inspect the container.
JsonObject inspectJson = runInspectorAndGetReport(containerData,
KeyValueContainerMetadataInspector.Mode.INSPECT);
ObjectNode inspectJson =
(ObjectNode) runInspectorAndGetReport(containerData,
KeyValueContainerMetadataInspector.Mode.INSPECT);

checkJsonReportForIncorrectContainer(inspectJson,
containerState, createdBlocks, setBlocks, createdBytes, setBytes,
Expand All @@ -322,7 +322,7 @@ public void inspectThenRepairOnIncorrectContainer(
checkDbCounts(containerData, setBlocks, setBytes, deleteCount);

// Now repair the container.
JsonObject repairJson = runInspectorAndGetReport(containerData,
ObjectNode repairJson = (ObjectNode) runInspectorAndGetReport(containerData,
KeyValueContainerMetadataInspector.Mode.REPAIR);
checkJsonReportForIncorrectContainer(repairJson,
containerState, createdBlocks, setBlocks, createdBytes, setBytes,
Expand All @@ -333,38 +333,38 @@ public void inspectThenRepairOnIncorrectContainer(
}

@SuppressWarnings("checkstyle:ParameterNumber")
private void checkJsonReportForIncorrectContainer(JsonObject inspectJson,
private void checkJsonReportForIncorrectContainer(ObjectNode inspectJson,
String expectedContainerState, long createdBlocks,
long setBlocks, long createdBytes, long setBytes, long createdFiles,
long setPendingDeleteCount, long createdPendingDeleteCount,
boolean shouldRepair) {
// Check main container properties.
assertEquals(inspectJson.get("containerID").getAsLong(),
assertEquals(inspectJson.get("containerID").asLong(),
CONTAINER_ID);
assertEquals(inspectJson.get("containerState").getAsString(),
assertEquals(inspectJson.get("containerState").asText(),
expectedContainerState);

// Check DB metadata.
JsonObject jsonDbMetadata = inspectJson.getAsJsonObject("dBMetadata");
ObjectNode jsonDbMetadata = (ObjectNode) inspectJson.get("dBMetadata");
assertEquals(setBlocks,
jsonDbMetadata.get(OzoneConsts.BLOCK_COUNT).getAsLong());
jsonDbMetadata.get(OzoneConsts.BLOCK_COUNT).asLong());
assertEquals(setBytes,
jsonDbMetadata.get(OzoneConsts.CONTAINER_BYTES_USED).getAsLong());
jsonDbMetadata.get(OzoneConsts.CONTAINER_BYTES_USED).asLong());

// Check aggregate metadata values.
JsonObject jsonAggregates = inspectJson.getAsJsonObject("aggregates");
ObjectNode jsonAggregates = (ObjectNode) inspectJson.get("aggregates");
assertEquals(createdBlocks,
jsonAggregates.get("blockCount").getAsLong());
jsonAggregates.get("blockCount").asLong());
assertEquals(createdBytes,
jsonAggregates.get("usedBytes").getAsLong());
jsonAggregates.get("usedBytes").asLong());
assertEquals(createdPendingDeleteCount,
jsonAggregates.get("pendingDeleteBlocks").getAsLong());
jsonAggregates.get("pendingDeleteBlocks").asLong());

// Check chunks directory.
JsonObject jsonChunksDir = inspectJson.getAsJsonObject("chunksDirectory");
assertTrue(jsonChunksDir.get("present").getAsBoolean());
ObjectNode jsonChunksDir = (ObjectNode) inspectJson.get("chunksDirectory");
assertTrue(jsonChunksDir.get("present").asBoolean());
assertEquals(createdFiles,
jsonChunksDir.get("fileCount").getAsLong());
jsonChunksDir.get("fileCount").asLong());

// Check errors.
checkJsonErrorsReport(inspectJson, "dBMetadata.#BLOCKCOUNT",
Expand All @@ -376,48 +376,47 @@ private void checkJsonReportForIncorrectContainer(JsonObject inspectJson,
}

private void checkJsonErrorsReport(
JsonObject jsonReport, String propertyValue,
ObjectNode jsonReport, String propertyValue,
long correctExpected, long correctActual,
boolean correctRepair) {
if (correctExpected == correctActual) {
return;
}
checkJsonErrorsReport(jsonReport, propertyValue,
new JsonPrimitive(correctExpected),
new JsonPrimitive(correctActual),
LongNode.valueOf(correctExpected),
LongNode.valueOf(correctActual),
correctRepair);
}

/**
* Checks the erorr list in the provided JsonReport for an error matching
* the template passed in with the parameters.
*/
private void checkJsonErrorsReport(JsonObject jsonReport,
String propertyValue, JsonPrimitive correctExpected,
JsonPrimitive correctActual, boolean correctRepair) {
private void checkJsonErrorsReport(ObjectNode jsonReport,
String propertyValue,
JsonNode correctExpected,
JsonNode correctActual,
boolean correctRepair) {

assertFalse(jsonReport.get("correct").getAsBoolean());
assertFalse(jsonReport.get("correct").asBoolean());

JsonArray jsonErrors = jsonReport.getAsJsonArray("errors");
ArrayNode jsonErrors = (ArrayNode) jsonReport.get("errors");
boolean matchFound = false;
for (JsonElement jsonErrorElem: jsonErrors) {
JsonObject jsonErrorObject = jsonErrorElem.getAsJsonObject();
for (JsonNode jsonErrorElem: jsonErrors) {
ObjectNode jsonErrorObject = (ObjectNode) jsonErrorElem;
String thisProperty =
jsonErrorObject.get("property").getAsString();
jsonErrorObject.get("property").asText();

if (thisProperty.equals(propertyValue)) {
matchFound = true;

JsonPrimitive expectedJsonPrim =
jsonErrorObject.get("expected").getAsJsonPrimitive();
assertEquals(correctExpected, expectedJsonPrim);
JsonNode expectedJsonPrim = jsonErrorObject.get("expected");
assertEquals(correctExpected.longValue(), expectedJsonPrim.longValue());

JsonPrimitive actualJsonPrim =
jsonErrorObject.get("actual").getAsJsonPrimitive();
assertEquals(correctActual, actualJsonPrim);
JsonNode actualJsonPrim = jsonErrorObject.get("actual");
assertEquals(correctActual.longValue(), actualJsonPrim.longValue());

boolean repaired =
jsonErrorObject.get("repaired").getAsBoolean();
boolean repaired = jsonErrorObject.get("repaired").asBoolean();
assertEquals(correctRepair, repaired);
break;
}
Expand Down Expand Up @@ -496,20 +495,20 @@ void checkDbCounts(KeyValueContainerData containerData,
}
}

private JsonObject runInspectorAndGetReport(
private JsonNode runInspectorAndGetReport(
KeyValueContainerData containerData,
KeyValueContainerMetadataInspector.Mode mode) throws Exception {
System.setProperty(KeyValueContainerMetadataInspector.SYSTEM_PROPERTY,
mode.toString());
ContainerInspectorUtil.load();
JsonObject json = runInspectorAndGetReport(containerData);
JsonNode json = runInspectorAndGetReport(containerData);
ContainerInspectorUtil.unload();
System.clearProperty(KeyValueContainerMetadataInspector.SYSTEM_PROPERTY);

return json;
}

private JsonObject runInspectorAndGetReport(
private JsonNode runInspectorAndGetReport(
KeyValueContainerData containerData) throws Exception {
// Use an empty layout so the captured log has no prefix and can be
// parsed as json.
Expand All @@ -522,7 +521,9 @@ private JsonObject runInspectorAndGetReport(
String output = capturer.getOutput();
capturer.clearOutput();

return new Gson().fromJson(output, JsonObject.class);
ObjectMapper objectMapper = new ObjectMapper();
JsonNode node = objectMapper.readTree(output);
return node;
}

private KeyValueContainer createClosedContainer(int normalBlocks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
import java.util.Map;
import java.util.Properties;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import org.apache.hadoop.hdds.annotation.InterfaceAudience;
import org.apache.hadoop.hdds.annotation.InterfaceStability;
import org.apache.hadoop.hdds.server.http.HttpServer2;

import com.google.common.annotations.VisibleForTesting;
import com.google.gson.Gson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -145,12 +145,12 @@ public BadFormatException(String msg) {

private void processConfigTagRequest(HttpServletRequest request, String cmd,
Writer out) throws IOException {
Gson gson = new Gson();
ObjectMapper objectMapper = new ObjectMapper();
OzoneConfiguration config = getOzoneConfig();

switch (cmd) {
case "getOzoneTags":
out.write(gson.toJson(OzoneConfiguration.TAGS));
out.write(objectMapper.writeValueAsString(OzoneConfiguration.TAGS));
break;
case "getPropertyByTag":
String tags = request.getParameter("tags");
Expand All @@ -170,7 +170,7 @@ private void processConfigTagRequest(HttpServletRequest request, String cmd,
}
}
}
out.write(gson.toJsonTree(propMap).toString());
out.write(objectMapper.writeValueAsString(propMap));
break;
default:
throw new IllegalArgumentException(cmd + " is not a valid command.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package org.apache.hadoop.hdds.scm.container.common.helpers;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.DeletedBlocksTransactionInfo;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.DeletedBlocksTransaction;
import java.util.List;
Expand All @@ -31,8 +33,14 @@ public class DeletedBlocksTransactionInfoWrapper {
private final List<Long> localIdList;
private final int count;

public DeletedBlocksTransactionInfoWrapper(long txID, long containerID,
List<Long> localIdList, int count) {
// Used @JsonCreator to indicate that Jackson should use this constructor for
// deserialization
@JsonCreator
public DeletedBlocksTransactionInfoWrapper(
@JsonProperty("txID") long txID,
@JsonProperty("containerID") long containerID,
@JsonProperty("localIdList") List<Long> localIdList,
@JsonProperty("count") int count) {
this.txID = txID;
this.containerID = containerID;
this.localIdList = localIdList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.gson.Gson;
import org.apache.hadoop.hdds.server.http.HttpServer2;
import org.apache.hadoop.util.XMLUtils;
import org.eclipse.jetty.util.ajax.JSON;
Expand Down Expand Up @@ -109,8 +109,10 @@ public void testGetPropertyWithCmd() throws Exception {
conf.getObject(OzoneTestConfig.class);
// test cmd is getOzoneTags
String result = getResultWithCmd(conf, "getOzoneTags");
Gson gson = new Gson();
String tags = gson.toJson(OzoneConfiguration.TAGS);

ObjectMapper objectMapper = new ObjectMapper();
String tags = objectMapper.writeValueAsString(OzoneConfiguration.TAGS);

assertEquals(result, tags);
// cmd is getPropertyByTag
result = getResultWithCmd(conf, "getPropertyByTag");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ${S3G_ENDPOINT_URL} http://s3g:9878
Create Tenant Success with Cluster Admin
Run Keyword Kinit test user testuser testuser.keytab
${output} = Execute ozone tenant --verbose create tenantone
Should contain ${output} "tenantId": "tenantone"
Should contain ${output} "tenantId" : "tenantone"

Assign User Success with Cluster Admin
${output} = Execute ozone tenant --verbose user assign testuser --tenant=tenantone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
*/
package org.apache.hadoop.ozone.om.multitenant;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.kerby.util.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -215,14 +214,16 @@ public String getUserId(String userPrincipal) throws IOException {
String response = getResponseData(conn);
String userIDCreated = null;
try {
JsonObject jResonse = JsonParser.parseString(response).getAsJsonObject();
JsonArray userinfo = jResonse.get("vXUsers").getAsJsonArray();
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jResponse = objectMapper.readTree(response);
JsonNode userinfo = jResponse.path("vXUsers");
int numIndex = userinfo.size();

for (int i = 0; i < numIndex; ++i) {
if (userinfo.get(i).getAsJsonObject().get("name").getAsString()
.equals(userPrincipal)) {
userIDCreated =
userinfo.get(i).getAsJsonObject().get("id").getAsString();
JsonNode userNode = userinfo.get(i);
String name = userNode.path("name").asText();
if (name.equals(userPrincipal)) {
userIDCreated = userNode.path("id").asText();
break;
}
}
Expand All @@ -231,6 +232,7 @@ public String getUserId(String userPrincipal) throws IOException {
e.printStackTrace();
throw e;
}

return userIDCreated;
}

Expand All @@ -253,8 +255,9 @@ public String createUser(String userName, String password)
String userId;
try {
assert userInfo != null;
JsonObject jObject = JsonParser.parseString(userInfo).getAsJsonObject();
userId = jObject.get("id").getAsString();
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jNode = objectMapper.readTree(userInfo);
userId = jNode.get("id").asText();
LOG.debug("Ranger returned userId: {}", userId);
} catch (JsonParseException e) {
e.printStackTrace();
Expand Down
Loading