Commit 58ea4650 by Suma S

Merge pull request #112 from hortonworks/master

Merging from master to DAL
parents d3c05341 3b9e1b2f
...@@ -616,9 +616,9 @@ ...@@ -616,9 +616,9 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-lang</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang</artifactId> <artifactId>commons-lang3</artifactId>
<version>2.4</version> <version>3.4</version>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
......
...@@ -126,8 +126,8 @@ ...@@ -126,8 +126,8 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-lang</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang</artifactId> <artifactId>commons-lang3</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
package org.apache.hadoop.metadata.typesystem.types; package org.apache.hadoop.metadata.typesystem.types;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.apache.hadoop.metadata.typesystem.types.utils.TypesUtil; import org.apache.hadoop.metadata.typesystem.types.utils.TypesUtil;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterMethod;
......
...@@ -104,6 +104,11 @@ ...@@ -104,6 +104,11 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>com.tinkerpop.blueprints</groupId> <groupId>com.tinkerpop.blueprints</groupId>
<artifactId>blueprints-core</artifactId> <artifactId>blueprints-core</artifactId>
</dependency> </dependency>
......
...@@ -39,6 +39,7 @@ public final class Main { ...@@ -39,6 +39,7 @@ public final class Main {
private static final String APP_PATH = "app"; private static final String APP_PATH = "app";
private static final String APP_PORT = "port"; private static final String APP_PORT = "port";
private static final String METADATA_HOME = "metadata.home"; private static final String METADATA_HOME = "metadata.home";
private static final String METADATA_LOG_DIR = "metadata.log.dir";
/** /**
* Prevent users from constructing this. * Prevent users from constructing this.
...@@ -87,6 +88,9 @@ public final class Main { ...@@ -87,6 +88,9 @@ public final class Main {
if (System.getProperty(METADATA_HOME) == null) { if (System.getProperty(METADATA_HOME) == null) {
System.setProperty(METADATA_HOME, "target"); System.setProperty(METADATA_HOME, "target");
} }
if (System.getProperty(METADATA_LOG_DIR) == null) {
System.setProperty(METADATA_LOG_DIR, "target/logs");
}
} }
public static String getProjectVersion(PropertiesConfiguration buildConfiguration) { public static String getProjectVersion(PropertiesConfiguration buildConfiguration) {
......
...@@ -298,7 +298,7 @@ public class RexsterGraphResource { ...@@ -298,7 +298,7 @@ public class RexsterGraphResource {
String message = "Edge with [" + edgeId + "] cannot be found."; String message = "Edge with [" + edgeId + "] cannot be found.";
LOG.info(message); LOG.info(message);
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND) throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
.entity(JSONObject.quote(message)).build()); .entity(Servlets.escapeJsonString(message)).build());
} }
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
...@@ -389,7 +389,7 @@ public class RexsterGraphResource { ...@@ -389,7 +389,7 @@ public class RexsterGraphResource {
countOnly = false; countOnly = false;
} else { } else {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST) throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST)
.entity(JSONObject.quote(directionSegment + " segment was invalid.")) .entity(Servlets.escapeJsonString(directionSegment + " segment was invalid."))
.build()); .build());
} }
} }
......
...@@ -18,9 +18,12 @@ ...@@ -18,9 +18,12 @@
package org.apache.hadoop.metadata.web.util; package org.apache.hadoop.metadata.web.util;
import com.google.common.base.Preconditions;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.metadata.MetadataServiceClient; import org.apache.hadoop.metadata.MetadataServiceClient;
import org.apache.hadoop.metadata.ParamChecker;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -38,6 +41,8 @@ import java.io.StringWriter; ...@@ -38,6 +41,8 @@ import java.io.StringWriter;
*/ */
public final class Servlets { public final class Servlets {
public static final String QUOTE = "\"";
private static final Logger LOG = LoggerFactory.getLogger(Servlets.class); private static final Logger LOG = LoggerFactory.getLogger(Servlets.class);
private Servlets() { private Servlets() {
/* singleton */ /* singleton */
...@@ -117,7 +122,7 @@ public final class Servlets { ...@@ -117,7 +122,7 @@ public final class Servlets {
public static Response getErrorResponse(String message, Response.Status status) { public static Response getErrorResponse(String message, Response.Status status) {
JSONObject errorJson = new JSONObject(); JSONObject errorJson = new JSONObject();
Object errorEntity = JSONObject.quote(message); Object errorEntity = Servlets.escapeJsonString(message);
try { try {
errorJson.put(MetadataServiceClient.ERROR, errorEntity); errorJson.put(MetadataServiceClient.ERROR, errorEntity);
errorEntity = errorJson; errorEntity = errorJson;
...@@ -140,4 +145,9 @@ public final class Servlets { ...@@ -140,4 +145,9 @@ public final class Servlets {
public static String getRequestId() { public static String getRequestId() {
return Thread.currentThread().getName(); return Thread.currentThread().getName();
} }
public static String escapeJsonString(String inputStr) {
ParamChecker.notNull(inputStr, "Input String cannot be null");
return StringEscapeUtils.escapeJson(inputStr);
}
} }
...@@ -21,6 +21,7 @@ package org.apache.hadoop.metadata.web.resources; ...@@ -21,6 +21,7 @@ package org.apache.hadoop.metadata.web.resources;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.WebResource;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.hadoop.metadata.MetadataServiceClient; import org.apache.hadoop.metadata.MetadataServiceClient;
import org.apache.hadoop.metadata.typesystem.Referenceable; import org.apache.hadoop.metadata.typesystem.Referenceable;
import org.apache.hadoop.metadata.typesystem.Struct; import org.apache.hadoop.metadata.typesystem.Struct;
...@@ -231,8 +232,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -231,8 +232,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON)
.method(HttpMethod.GET, ClientResponse.class); .method(HttpMethod.GET, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Assert.assertEquals(clientResponse.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
Response.Status.BAD_REQUEST.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class); String responseAsString = clientResponse.getEntity(String.class);
Assert.assertNotNull(responseAsString); Assert.assertNotNull(responseAsString);
...@@ -349,8 +349,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -349,8 +349,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON)
.method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON); .method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON);
Assert.assertEquals(clientResponse.getStatus(), Assert.assertEquals(clientResponse.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
Response.Status.BAD_REQUEST.getStatusCode());
} }
@Test (dependsOnMethods = "testAddTrait") @Test (dependsOnMethods = "testAddTrait")
...@@ -389,17 +388,45 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -389,17 +388,45 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON)
.method(HttpMethod.DELETE, ClientResponse.class); .method(HttpMethod.DELETE, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Assert.assertEquals(clientResponse.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
Response.Status.BAD_REQUEST.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class); String responseAsString = clientResponse.getEntity(String.class);
Assert.assertNotNull(responseAsString); Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(MetadataServiceClient.ERROR)); Assert.assertNotNull(response.get(MetadataServiceClient.ERROR));
Assert.assertEquals(response.getString(MetadataServiceClient.ERROR), "trait=" + traitName + " should be defined in type system before it can be deleted");
Assert.assertNotNull(response.get(MetadataServiceClient.STACKTRACE)); Assert.assertNotNull(response.get(MetadataServiceClient.STACKTRACE));
} }
private String random() {
return RandomStringUtils.random(10);
}
@Test
public void testUTF8() throws Exception {
String classType = random();
String attrName = random();
String attrValue = random();
HierarchicalTypeDefinition<ClassType> classTypeDefinition =
TypesUtil.createClassTypeDef(classType, ImmutableList.<String>of(),
TypesUtil.createUniqueRequiredAttrDef(attrName, DataTypes.STRING_TYPE));
TypesDef typesDef = TypeUtils.getTypesDef(ImmutableList.<EnumTypeDefinition>of(),
ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(),
ImmutableList.of(classTypeDefinition));
createType(typesDef);
Referenceable instance = new Referenceable(classType);
instance.set(attrName, attrValue);
Id guid = createInstance(instance);
ClientResponse response = getEntityDefinition(guid._getId());
String definition = getEntityDefinition(response);
Referenceable getReferenceable = InstanceSerialization.fromJsonReferenceable(definition, true);
Assert.assertEquals(getReferenceable.get(attrName), attrValue);
}
private void createHiveTypes() throws Exception { private void createHiveTypes() throws Exception {
HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = HierarchicalTypeDefinition<ClassType> databaseTypeDefinition =
TypesUtil.createClassTypeDef(DATABASE_TYPE, TypesUtil.createClassTypeDef(DATABASE_TYPE,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment