use of io.fabric8.insight.metrics.model.Request in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceImpl method loadPatch.
@Override
public Patch loadPatch(PatchDetailsRequest request) throws PatchException {
File descriptor = new File(patchesDir, request.getPatchId() + ".patch");
try {
Patch patch = loadPatch(descriptor, true);
if (patch == null) {
return null;
}
Git repo = gitPatchRepository.findOrCreateMainGitRepository();
List<DiffEntry> diff = null;
if (request.isFiles() || request.isDiff()) {
// fetch the information from git
ObjectId commitId = repo.getRepository().resolve(patch.getManagedPatch().getCommitId());
RevCommit commit = new RevWalk(repo.getRepository()).parseCommit(commitId);
diff = gitPatchRepository.diff(repo, commit.getParent(0), commit);
}
if (request.isBundles()) {
// it's already in PatchData
}
if (request.isFiles() && diff != null) {
for (DiffEntry de : diff) {
DiffEntry.ChangeType ct = de.getChangeType();
String newPath = de.getNewPath();
String oldPath = de.getOldPath();
switch(ct) {
case ADD:
patch.getManagedPatch().getFilesAdded().add(newPath);
break;
case MODIFY:
patch.getManagedPatch().getFilesModified().add(newPath);
break;
case DELETE:
patch.getManagedPatch().getFilesRemoved().add(oldPath);
break;
}
}
}
if (request.isDiff() && diff != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DiffFormatter formatter = new DiffFormatter(baos);
formatter.setContext(4);
formatter.setRepository(repo.getRepository());
for (DiffEntry de : diff) {
formatter.format(de);
}
formatter.flush();
patch.getManagedPatch().setUnifiedDiff(new String(baos.toByteArray(), "UTF-8"));
}
return patch;
} catch (IOException | GitAPIException e) {
throw new PatchException(e.getMessage(), e);
}
}
use of io.fabric8.insight.metrics.model.Request in project fabric8 by jboss-fuse.
the class TcpGatewayHandler method handle.
@Override
public void handle(final NetSocket socket) {
NetClient client = null;
List<String> paths = serviceMap.getPaths();
TcpClientRequestFacade requestFacade = new TcpClientRequestFacade(socket);
String path = pathLoadBalancer.choose(paths, requestFacade);
if (path != null) {
List<ServiceDetails> services = serviceMap.getServices(path);
if (!services.isEmpty()) {
ServiceDetails serviceDetails = serviceLoadBalancer.choose(services, requestFacade);
if (serviceDetails != null) {
List<String> urlStrings = serviceDetails.getServices();
for (String urlString : urlStrings) {
if (Strings.notEmpty(urlString)) {
// lets create a client for this request...
try {
URI uri = new URI(urlString);
// URL url = new URL(urlString);
String urlProtocol = uri.getScheme();
if (Objects.equal(protocol, urlProtocol)) {
Handler<AsyncResult<NetSocket>> handler = new Handler<AsyncResult<NetSocket>>() {
public void handle(final AsyncResult<NetSocket> asyncSocket) {
socket.resume();
NetSocket clientSocket = asyncSocket.result();
Pump.createPump(clientSocket, socket).start();
Pump.createPump(socket, clientSocket).start();
}
};
client = createClient(socket, uri, handler);
break;
}
} catch (MalformedURLException e) {
LOG.warn("Failed to parse URL: " + urlString + ". " + e, e);
} catch (URISyntaxException e) {
LOG.warn("Failed to parse URI: " + urlString + ". " + e, e);
}
}
}
}
}
}
if (client == null) {
// fail to route
LOG.info("No service available for protocol " + protocol + " for paths " + paths);
socket.close();
}
}
use of io.fabric8.insight.metrics.model.Request in project fabric8 by jboss-fuse.
the class HttpGatewayHandler method handle.
@Override
public void handle(HttpServerRequest request) {
long callStart = System.nanoTime();
LOG.debug("Proxying request: {} {}", request.method(), request.uri());
// lets map the request URI to map to the service URI and then the renaming URI
// using mapping rules...
Map<String, MappedServices> mappingRules = httpGateway.getMappedServices();
try {
if (isMappingIndexRequest(request)) {
// lets return the JSON of all the results
doReturnIndex(request, mappingRules);
} else {
doRouteRequest(mappingRules, request);
}
CallDetailRecord cdr = new CallDetailRecord(System.nanoTime() - callStart, null);
httpGateway.addCallDetailRecord(cdr);
} catch (Throwable e) {
LOG.error("Caught: " + e, e);
CallDetailRecord cdr = new CallDetailRecord(System.nanoTime() - callStart, new Date() + ":" + e.getMessage());
httpGateway.addCallDetailRecord(cdr);
request.response().setStatusCode(404);
StringWriter buffer = new StringWriter();
e.printStackTrace(new PrintWriter(buffer));
request.response().setStatusMessage("Error: " + e + "\nStack Trace: " + buffer);
request.response().close();
}
}
use of io.fabric8.insight.metrics.model.Request in project vertx-openshift-it by cescoffier.
the class Http2IT method testGRPC.
@Test
public void testGRPC() throws Exception {
Assertions.assertThat(client).deployments().pods().isPodReadyForPeriod();
String host = securedUrlForRoute(client.routes().withName("hello").get()).getHost();
System.out.println("Host: " + host);
System.out.println("Port: " + 443);
ManagedChannel channel = VertxChannelBuilder.forAddress(vertx, host, 443).useSsl(options -> options.setSsl(true).setUseAlpn(true).setTrustAll(true)).build();
GreeterGrpc.GreeterVertxStub stub = GreeterGrpc.newVertxStub(channel);
HelloRequest request = HelloRequest.newBuilder().setName("OpenShift").build();
AtomicReference<String> result = new AtomicReference<>();
System.out.println("Sending request...");
stub.sayHello(request, asyncResponse -> {
System.out.println("Got result");
if (asyncResponse.succeeded()) {
System.out.println("Succeeded " + asyncResponse.result().getMessage());
result.set(asyncResponse.result().getMessage());
} else {
asyncResponse.cause().printStackTrace();
}
});
await().atMost(5, TimeUnit.MINUTES).untilAtomic(result, is(notNullValue()));
assertThat(result.get()).contains("Hello OpenShift");
}
use of io.fabric8.insight.metrics.model.Request in project syndesis by syndesisio.
the class KubernetesSupport method watchLog.
/*
* Feeds the controller of the given podName to the callback handler for processing.
*
* We do this instead of using the watchLog() feature of the k8s client lib because it really sucks due to:
* 1. You can't configure the timestamps option or the sinceTime option. Need to resume log downloads.
* 2. It seems to need extra threads..
* 3. It might be hiding some of the http failure conditions.
*
*/
protected void watchLog(String podName, Consumer<InputStream> handler, String sinceTime, Executor executor) throws IOException {
try {
PodOperationsImpl pod = (PodOperationsImpl) client.pods().withName(podName);
StringBuilder url = new StringBuilder().append(pod.getResourceUrl().toString()).append("/log?pretty=false&follow=true×tamps=true");
if (sinceTime != null) {
url.append("&sinceTime=");
}
Request request = new Request.Builder().url(new URL(url.toString())).get().build();
OkHttpClient clone = okHttpClient.newBuilder().readTimeout(0, TimeUnit.MILLISECONDS).build();
clone.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
LOG.info("Failure occurred getting controller for pod: {},", podName, e);
handler.accept(null);
}
@Override
public void onResponse(final Call call, final Response response) throws IOException {
executor.execute(() -> {
try {
if (response.code() == 200) {
handler.accept(response.body().byteStream());
} else {
LOG.info("Failure occurred while processing controller for pod: {}, http status: {}, details: {}", podName, response.code(), response.body().string());
handler.accept(null);
}
} catch (IOException e) {
LOG.error("Unexpected Error", e);
}
});
}
});
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") RuntimeException t) {
throw new IOException("Unexpected Error", t);
}
}
Aggregations