use of io.cdap.common.http.HttpResponse in project cdap by caskdata.
the class WorkflowStatsSLAHttpHandlerTest method testCompare.
@Test
public void testCompare() throws Exception {
deploy(WorkflowApp.class, 200);
String workflowName = "FunWorkflow";
String mapreduceName = "ClassicWordCount";
String sparkName = "SparkWorkflowTest";
WorkflowId workflowProgram = WORKFLOW_APP.workflow(workflowName);
ProgramId mapreduceProgram = WORKFLOW_APP.mr(mapreduceName);
ProgramId sparkProgram = WORKFLOW_APP.spark(sparkName);
ArtifactId artifactId = WORKFLOW_APP.getNamespaceId().artifact("testArtifact", "1.0").toApiArtifactId();
List<RunId> workflowRunIdList = setupRuns(workflowProgram, mapreduceProgram, sparkProgram, store, 2, artifactId);
RunId workflowRun1 = workflowRunIdList.get(0);
RunId workflowRun2 = workflowRunIdList.get(1);
String request = String.format("%s/namespaces/%s/apps/%s/workflows/%s/runs/%s/compare?other-run-id=%s", Constants.Gateway.API_VERSION_3, Id.Namespace.DEFAULT.getId(), WorkflowApp.class.getSimpleName(), workflowProgram.getProgram(), workflowRun1.getId(), workflowRun2.getId());
HttpResponse response = doGet(request);
Collection<WorkflowStatsComparison.ProgramNodes> workflowStatistics = readResponse(response, new TypeToken<Collection<WorkflowStatsComparison.ProgramNodes>>() {
}.getType());
Assert.assertNotNull(workflowStatistics.iterator().next());
Assert.assertEquals(2, workflowStatistics.size());
for (WorkflowStatsComparison.ProgramNodes node : workflowStatistics) {
if (node.getProgramType() == ProgramType.MAPREDUCE) {
Assert.assertEquals(38L, (long) node.getWorkflowProgramDetailsList().get(0).getMetrics().get(TaskCounter.MAP_INPUT_RECORDS.name()));
}
}
}
use of io.cdap.common.http.HttpResponse in project cdap by caskdata.
the class RemotePreviewRequestFetcher method fetch.
@Override
public Optional<PreviewRequest> fetch() throws IOException, UnauthorizedException {
HttpRequest request = remoteClientInternal.requestBuilder(HttpMethod.POST, "requests/pull").withBody(ByteBuffer.wrap(pollerInfoProvider.get())).build();
HttpResponse httpResponse = remoteClientInternal.execute(request);
if (httpResponse.getResponseCode() == 200) {
PreviewRequest previewRequest = GSON.fromJson(httpResponse.getResponseBodyAsString(), PreviewRequest.class);
if (previewRequest != null && previewRequest.getPrincipal() != null) {
SecurityRequestContext.setUserId(previewRequest.getPrincipal().getName());
SecurityRequestContext.setUserCredential(previewRequest.getPrincipal().getFullCredential());
}
return Optional.ofNullable(previewRequest);
}
throw new IOException(String.format("Received status code:%s and body: %s", httpResponse.getResponseCode(), httpResponse.getResponseBodyAsString(Charsets.UTF_8)));
}
use of io.cdap.common.http.HttpResponse in project cdap by caskdata.
the class RemoteArtifactManager method getArtifactLocation.
@Override
protected Location getArtifactLocation(ArtifactInfo artifactInfo, @Nullable String artifactNamespace) throws IOException, UnauthorizedException {
String namespace;
if (ArtifactScope.SYSTEM.equals(artifactInfo.getScope())) {
namespace = NamespaceId.SYSTEM.getNamespace();
} else if (artifactNamespace != null) {
namespace = artifactNamespace;
} else {
namespace = namespaceId.getNamespace();
}
// If ArtifactLocalizerClient is set, use it to get the cached location of artifact.
if (artifactLocalizerClient != null) {
ArtifactId artifactId = new ArtifactId(namespace, artifactInfo.getName(), artifactInfo.getVersion());
try {
// artifact ClassLoader only.
return Locations.toLocation(artifactLocalizerClient.getUnpackedArtifactLocation(artifactId));
} catch (ArtifactNotFoundException e) {
throw new IOException(String.format("Artifact %s is not found", artifactId), e);
}
}
HttpRequest.Builder requestBuilder = remoteClientInternal.requestBuilder(HttpMethod.GET, String.format("namespaces/%s/artifacts/%s/versions/%s/location", namespace, artifactInfo.getName(), artifactInfo.getVersion()));
HttpResponse httpResponse = remoteClientInternal.execute(requestBuilder.build());
if (httpResponse.getResponseCode() == HttpResponseStatus.NOT_FOUND.code()) {
throw new IOException("Could not get artifact detail, endpoint not found");
}
if (httpResponse.getResponseCode() != 200) {
throw new IOException(String.format("Exception while getting artifacts list %s", httpResponse.getResponseBodyAsString()));
}
String path = httpResponse.getResponseBodyAsString();
Location location = Locations.getLocationFromAbsolutePath(locationFactory, path);
if (!location.exists()) {
throw new IOException(String.format("Artifact location does not exist %s for artifact %s version %s", path, artifactInfo.getName(), artifactInfo.getVersion()));
}
return location;
}
use of io.cdap.common.http.HttpResponse in project cdap by caskdata.
the class RemoteArtifactRepositoryReader method getArtifactDetails.
@Override
public List<ArtifactDetail> getArtifactDetails(ArtifactRange range, int limit, ArtifactSortOrder order) throws Exception {
String url = String.format("namespaces/%s/artifacts/%s/versions?lower=%s&upper=%s&limit=%d&order=%s", range.getNamespace(), range.getName(), range.getLower().toString(), range.getUpper().toString(), limit, order.name());
HttpRequest.Builder requestBuilder = remoteClient.requestBuilder(HttpMethod.GET, url);
HttpResponse httpResponse = execute(requestBuilder.build());
List<ArtifactDetail> details = GSON.fromJson(httpResponse.getResponseBodyAsString(), ARTIFACT_DETAIL_LIST_TYPE);
List<ArtifactDetail> detailList = new ArrayList<>();
for (ArtifactDetail detail : details) {
detailList.add(new ArtifactDetail(new ArtifactDescriptor(detail.getDescriptor().getNamespace(), detail.getDescriptor().getArtifactId(), getArtifactLocation(detail.getDescriptor())), detail.getMeta()));
}
return detailList;
}
use of io.cdap.common.http.HttpResponse in project cdap by caskdata.
the class RemoteArtifactRepositoryReader method getArtifact.
/**
* Fetches {@link ArtifactDetail} from {@link AppLifecycleHttpHandler}
* <p>
* Note that {@link Location} in {@link ArtifactDescriptor} doesn't get transported over, we need to instantiate it
* based on the location URI in the received {@link ArtifactDetail} to construct a complete {@link ArtifactDetail}.
*/
@Override
public ArtifactDetail getArtifact(Id.Artifact artifactId) throws Exception {
HttpResponse httpResponse;
String url = String.format("namespaces/%s/artifacts/%s/versions/%s", artifactId.getNamespace().getId(), artifactId.getName(), artifactId.getVersion());
HttpRequest.Builder requestBuilder = remoteClient.requestBuilder(HttpMethod.GET, url);
httpResponse = execute(requestBuilder.build());
ArtifactDetail detail = GSON.fromJson(httpResponse.getResponseBodyAsString(), ARTIFACT_DETAIL_TYPE);
return new ArtifactDetail(new ArtifactDescriptor(detail.getDescriptor().getNamespace(), detail.getDescriptor().getArtifactId(), getArtifactLocation(detail.getDescriptor())), detail.getMeta());
}
Aggregations