use of com.linkedin.data.ByteString in project voldemort by voldemort.
the class R2Store method get.
@Override
public List<Versioned<byte[]>> get(ByteArray key, byte[] transforms) throws VoldemortException {
List<Versioned<byte[]>> resultList = new ArrayList<Versioned<byte[]>>();
String base64Key = RestUtils.encodeVoldemortKey(key.get());
RestRequestBuilder rb = null;
try {
rb = new RestRequestBuilder(new URI(this.restBootstrapURL + "/" + getName() + "/" + base64Key));
String timeoutStr = Long.toString(this.config.getTimeoutConfig().getOperationTimeout(VoldemortOpCode.GET_OP_CODE));
rb.setHeader("Accept", MULTIPART_CONTENT_TYPE);
RestResponse response = fetchGetResponse(rb, timeoutStr);
final ByteString entity = response.getEntity();
if (entity != null) {
resultList = parseGetResponse(entity);
} else {
if (logger.isDebugEnabled()) {
logger.debug("Did not get any response!");
}
}
} catch (ExecutionException e) {
if (e.getCause() instanceof RestException) {
RestException exception = (RestException) e.getCause();
if (logger.isDebugEnabled()) {
logger.debug("REST EXCEPTION STATUS : " + exception.getResponse().getStatus());
}
} else {
throw new VoldemortException("Unknown HTTP request execution exception: " + e.getMessage(), e);
}
} catch (InterruptedException e) {
if (logger.isDebugEnabled()) {
logger.debug("Operation interrupted : " + e.getMessage(), e);
}
throw new VoldemortException("Operation interrupted exception: " + e.getMessage(), e);
} catch (URISyntaxException e) {
throw new VoldemortException("Illegal HTTP URL" + e.getMessage(), e);
}
return resultList;
}
use of com.linkedin.data.ByteString in project voldemort by voldemort.
the class CoordinatorAdminClient method getStoreClientConfigString.
public String getStoreClientConfigString(List<String> storeNames, String coordinatorUrl) {
try {
// Create the REST request
StringBuilder URIStringBuilder = new StringBuilder().append(coordinatorUrl).append(URL_SEPARATOR).append(STORE_CLIENT_CONFIG_OPS).append(URL_SEPARATOR).append(Joiner.on(",").join(storeNames));
RestRequestBuilder requestBuilder = new RestRequestBuilder(new URI(URIStringBuilder.toString()));
String timeoutStr = Long.toString(this.config.getTimeoutConfig().getOperationTimeout(VoldemortOpCode.GET_OP_CODE));
requestBuilder.setMethod(requestType.GET.toString());
requestBuilder.setHeader(RestMessageHeaders.X_VOLD_REQUEST_TIMEOUT_MS, timeoutStr);
requestBuilder = setCommonRequestHeader(requestBuilder);
RestRequest request = requestBuilder.build();
Future<RestResponse> future = client.restRequest(request);
// This will block
RestResponse response = future.get();
ByteString entity = response.getEntity();
return entity.asString("UTF-8");
} catch (Exception e) {
if (e.getCause() instanceof RestException) {
return ((RestException) e.getCause()).getResponse().getEntity().asString("UTF-8");
}
handleRequestAndResponseException(e);
}
return null;
}
use of com.linkedin.data.ByteString in project voldemort by voldemort.
the class CoordinatorAdminClient method deleteStoreClientConfig.
public boolean deleteStoreClientConfig(List<String> storeNames, String coordinatorUrl) {
String responseMessage = null;
Boolean success = false;
try {
// Create the REST request
StringBuilder URIStringBuilder = new StringBuilder().append(coordinatorUrl).append(URL_SEPARATOR).append(STORE_CLIENT_CONFIG_OPS).append(URL_SEPARATOR).append(Joiner.on(",").join(storeNames));
RestRequestBuilder requestBuilder = new RestRequestBuilder(new URI(URIStringBuilder.toString()));
String timeoutStr = Long.toString(this.config.getTimeoutConfig().getOperationTimeout(VoldemortOpCode.GET_OP_CODE));
// Create a HTTP POST request
requestBuilder.setMethod(requestType.DELETE.toString());
requestBuilder.setHeader(RestMessageHeaders.X_VOLD_REQUEST_TIMEOUT_MS, timeoutStr);
requestBuilder = setCommonRequestHeader(requestBuilder);
RestRequest request = requestBuilder.build();
Future<RestResponse> future = client.restRequest(request);
// This will block
RestResponse response = future.get();
final ByteString entity = response.getEntity();
if (entity == null) {
if (logger.isDebugEnabled()) {
logger.debug("Empty response !");
}
responseMessage = "Received empty response from " + coordinatorUrl;
} else {
responseMessage = entity.asString("UTF-8");
success = true;
}
} catch (Exception e) {
if (e.getCause() instanceof RestException) {
responseMessage = ((RestException) e.getCause()).getResponse().getEntity().asString("UTF-8");
} else {
responseMessage = "An exception other than RestException happens!";
}
handleRequestAndResponseException(e);
} finally {
System.out.println(responseMessage);
}
return success;
}
use of com.linkedin.data.ByteString in project rest.li by linkedin.
the class TestMapTemplate method testBytesMap.
@Test
public void testBytesMap() {
MapDataSchema schema = (MapDataSchema) DataTemplateUtil.parseSchema("{ \"type\" : \"map\", \"values\" : \"bytes\" }");
Map<String, ByteString> input = asMap("one", ByteString.copyAvroString("1", false), "three", ByteString.copyAvroString("3", false), "five", ByteString.copyAvroString("5", false), "seven", ByteString.copyAvroString("7", false), "eleven", ByteString.copyAvroString("11", false));
Map<String, ByteString> adds = asMap("thirteen", ByteString.copyAvroString("13", false), "seventeen", ByteString.copyAvroString("17", false), "nineteen", ByteString.copyAvroString("19", false));
Map<String, Object> badInput = asMap("boolean", true, "integer", 99, "long", 999L, "float", 88.0f, "double", 888.0, "data", "\u0100", "object", new Object(), "null", null, "array", new StringArray(), "record", new FooRecord());
Map<String, Object> badOutput = asMap("boolean", true, "integer", 99, "long", 999L, "float", 88.0f, "double", 888.0, "data", "\u0100", "map", new DataMap(), "list", new DataList());
testMap(BytesMap.class, schema, input, adds);
testMapBadInput(BytesMap.class, schema, input, badInput, badOutput);
}
use of com.linkedin.data.ByteString in project rest.li by linkedin.
the class TestDynamicRecordTemplate method TestPrimitiveFieldsOnDynamicRecord.
@Test
public void TestPrimitiveFieldsOnDynamicRecord() {
DynamicFoo foo = new DynamicFoo();
foo.setBoolean(true);
Assert.assertEquals(true, foo.getBoolean());
foo.setInt(54);
Assert.assertEquals(54, foo.getInt());
foo.setFloat(5.67F);
Assert.assertEquals(5.67F, foo.getFloat());
foo.setDouble(4.45);
Assert.assertEquals(4.45, foo.getDouble());
foo.setLong(12345L);
Assert.assertEquals(12345L, foo.getLong());
ByteString byteString = ByteString.copyAvroString("someString", false);
foo.setBytes(byteString);
Assert.assertEquals(byteString, foo.getBytes());
foo.setString("myString");
Assert.assertEquals("myString", foo.getString());
foo.setEnum(TestRecordAndUnionTemplate.EnumType.BANANA);
Assert.assertEquals(TestRecordAndUnionTemplate.EnumType.BANANA, foo.getEnum());
}
Aggregations