use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class DatasetInstanceHandlerTest method createInstance.
private HttpResponse createInstance(DatasetId instance, String typeName, @Nullable String description, @Nullable DatasetProperties props, @Nullable String ownerPrincipal) throws IOException {
DatasetInstanceConfiguration creationProperties;
if (props != null) {
creationProperties = new DatasetInstanceConfiguration(typeName, props.getProperties(), description, ownerPrincipal);
} else {
creationProperties = new DatasetInstanceConfiguration(typeName, null, description, ownerPrincipal);
}
HttpRequest request = HttpRequest.put(getUrl(instance.getNamespace(), "/data/datasets/" + instance.getEntityName())).withBody(GSON.toJson(creationProperties)).build();
return HttpRequests.execute(request);
}
use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class DatasetInstanceHandlerTest method validateGet.
private void validateGet(URL url, Integer... expected) throws IOException {
HttpRequest request = HttpRequest.get(url).build();
assertStatus(HttpRequests.execute(request).getResponseCode(), url, expected);
}
use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class SparkPageRankAppTest method test.
@Test
public void test() throws Exception {
// Deploy the SparkPageRankApp
ApplicationManager appManager = deployApplication(SparkPageRankApp.class);
// Send a stream events to the Stream
StreamManager streamManager = getStreamManager(SparkPageRankApp.BACKLINK_URL_STREAM);
streamManager.send(Joiner.on(" ").join(URL_1, URL_2));
streamManager.send(Joiner.on(" ").join(URL_1, URL_3));
streamManager.send(Joiner.on(" ").join(URL_2, URL_1));
streamManager.send(Joiner.on(" ").join(URL_3, URL_1));
// Start service
ServiceManager serviceManager = appManager.getServiceManager(SparkPageRankApp.SERVICE_HANDLERS).start();
// Wait for service to start since the Spark program needs it
serviceManager.waitForStatus(true);
// Start the SparkPageRankProgram
SparkManager sparkManager = appManager.getSparkManager(SparkPageRankApp.PageRankSpark.class.getSimpleName()).start();
sparkManager.waitForRun(ProgramRunStatus.COMPLETED, 60, TimeUnit.SECONDS);
// Run RanksCounter which will count the number of pages for a pr
MapReduceManager mapReduceManager = appManager.getMapReduceManager(SparkPageRankApp.RanksCounter.class.getSimpleName()).start();
mapReduceManager.waitForRun(ProgramRunStatus.COMPLETED, 3, TimeUnit.MINUTES);
//Query for rank
URL url = new URL(serviceManager.getServiceURL(15, TimeUnit.SECONDS), SparkPageRankApp.SparkPageRankServiceHandler.RANKS_PATH);
HttpRequest request = HttpRequest.post(url).withBody(("{\"" + SparkPageRankApp.SparkPageRankServiceHandler.URL_KEY + "\":\"" + URL_1 + "\"}")).build();
HttpResponse response = HttpRequests.execute(request);
Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
Assert.assertEquals(RANK, response.getResponseBodyAsString());
// Request total pages for a page rank and verify it
url = new URL(serviceManager.getServiceURL(15, TimeUnit.SECONDS), SparkPageRankApp.SparkPageRankServiceHandler.TOTAL_PAGES_PATH + "/" + RANK);
response = HttpRequests.execute(HttpRequest.get(url).build());
Assert.assertEquals(TOTAL_PAGES, response.getResponseBodyAsString());
}
use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class ServiceClient method storeRouteConfig.
/**
* Stores RouteConfig of a service with different application versions.
*
* @param serviceId {@link ServiceId} of the service with the application version part ignored
* @param routeConfig a Map of {@link String} application version and {@link Integer} percentage of
* traffic routed to the version.
*/
public void storeRouteConfig(ServiceId serviceId, Map<String, Integer> routeConfig) throws IOException, UnauthorizedException, UnauthenticatedException {
URL url = buildRouteConfigUrl(serviceId);
HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(routeConfig, MAP_STRING_INTEGER_TYPE)).build();
restClient.upload(request, config.getAccessToken());
}
use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class StreamClient method setTTL.
/**
* Sets the Time-to-Live (TTL) of a stream. TTL governs how long stream events are readable.
*
* @param stream ID of the stream
* @param ttlInSeconds desired TTL, in seconds
* @throws IOException if a network error occurred
* @throws StreamNotFoundException if the stream with the specified name was not found
*/
public void setTTL(StreamId stream, long ttlInSeconds) throws IOException, StreamNotFoundException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(stream.getParent(), String.format("streams/%s/properties", stream.getStream()));
HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(ImmutableMap.of("ttl", ttlInSeconds))).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new StreamNotFoundException(stream);
}
}
Aggregations