use of io.fabric8.kubernetes.client.http.HttpRequest in project kubernetes-client by fabric8io.
the class LogWatchCallback method callAndWait.
public LogWatchCallback callAndWait(HttpClient client, URL url) {
HttpRequest request = client.newHttpRequestBuilder().url(url).build();
HttpClient clone = client.newBuilder().readTimeout(0, TimeUnit.MILLISECONDS).build();
CompletableFuture<HttpResponse<InputStream>> future = clone.sendAsync(request, InputStream.class).whenComplete(this);
if (!Utils.waitUntilReady(future, config.getRequestTimeout(), TimeUnit.MILLISECONDS)) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("Log watch request has not been opened within: {} millis.", config.getRequestTimeout());
}
}
return this;
}
use of io.fabric8.kubernetes.client.http.HttpRequest in project kubernetes-client by fabric8io.
the class BuildConfigOperationsImplTest method setUp.
@BeforeEach
public void setUp() {
this.httpClient = Mockito.mock(HttpClient.class, Mockito.RETURNS_DEEP_STUBS);
HttpRequest response = Mockito.mock(HttpRequest.class, Mockito.CALLS_REAL_METHODS);
when(response.method()).thenReturn("POST");
when(response.uri()).thenReturn(URI.create("https://localhost:8443/"));
when(this.httpClient.newBuilder().readTimeout(anyLong(), any()).writeTimeout(anyLong(), any()).build()).thenReturn(httpClient);
when(this.httpClient.newHttpRequestBuilder().post(any(), any(), anyLong()).header(any(), any()).uri(any(String.class)).build()).thenReturn(response);
this.config = new OpenShiftConfigBuilder().withMasterUrl("https://localhost:8443/").build();
}
use of io.fabric8.kubernetes.client.http.HttpRequest in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class OMB method deployWorkers.
/**
* Deploy workers to run producers and consumers.
*
* @param workers The number of workers to deploy.
* @return List of worker hostnames.
*/
public List<String> deployWorkers(int workers) throws Exception {
LOGGER.info("Deploying {} workers, container memory: {}, cpu: {}", workers, workerContainerMemory, workerCpu);
// we are now on java 11 which defaults to https://www.eclipse.org/openj9/docs/xxusecontainersupport/ and -XX:+PreferContainerQuotaForCPUCount
String jvmOpts = String.format("-XX:+ExitOnOutOfMemoryError");
List<Future<Void>> futures = new ArrayList<>();
List<Node> nodes = ombCluster.getWorkerNodes();
ExecutorService executorService = Executors.newFixedThreadPool(N_THREADS);
try {
for (int i = 0; i < workers; i++) {
String name = String.format("worker-%d", i);
final int nodeIdx = i % nodes.size();
futures.add(executorService.submit(() -> {
workerNames.add(name);
createWorker(jvmOpts, name, this.useSingleNode ? nodes.get(0) : nodes.get(nodeIdx));
return null;
}));
}
} finally {
executorService.shutdown();
awaitAllFutures(futures);
}
LOGGER.info("Collecting hosts");
TreeMap<Integer, String> sortedHostnames = new TreeMap<>();
ombCluster.kubeClient().client().adapt(OpenShiftClient.class).routes().inNamespace(Constants.OMB_NAMESPACE).withLabel("app", "worker").list().getItems().forEach(r -> {
String host = r.getSpec().getHost();
if (host == null || host.isEmpty()) {
throw new IllegalStateException("Host node not defined");
}
sortedHostnames.put(workerNames.indexOf(r.getMetadata().getLabels().get("app.kubernetes.io/name")), String.format("http://%s", host));
});
List<String> hostnames = new ArrayList<>(sortedHostnames.values());
LOGGER.info("Waiting for worker pods to run");
// Wait until workers are running
List<Pod> pods = ombCluster.kubeClient().client().pods().inNamespace(Constants.OMB_NAMESPACE).withLabel("app", "worker").list().getItems();
while (pods.size() != workers) {
pods = ombCluster.kubeClient().client().pods().inNamespace(Constants.OMB_NAMESPACE).withLabel("app", "worker").list().getItems();
LOGGER.info("Found {} pods, expecting {}", pods.size(), workers);
Thread.sleep(5000);
}
CompletableFuture<?>[] ready = new CompletableFuture<?>[pods.size()];
for (int i = 0; i < pods.size(); i++) {
Pod pod = pods.get(i);
ready[i] = TestUtils.asyncWaitFor("pod ready", 1_000, 600_000, () -> ombCluster.kubeClient().client().pods().inNamespace(Constants.OMB_NAMESPACE).withName(pod.getMetadata().getName()).isReady());
}
CompletableFuture.allOf(ready).get();
HttpClient client = HttpClient.newHttpClient();
List<URI> notReady = hostnames.stream().map(u -> u + "/counters-stats").map(URI::create).collect(Collectors.toList());
do {
Iterator<URI> itr = notReady.iterator();
LOGGER.info("Awaiting {} OMB endpoint(s) to become ready.", notReady.size());
while (itr.hasNext()) {
HttpRequest request = HttpRequest.newBuilder().uri(itr.next()).timeout(Duration.ofSeconds(10)).GET().build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
itr.remove();
}
}
Thread.sleep(1000);
} while (!notReady.isEmpty());
LOGGER.info("Deployed {} workers: {}", workers, hostnames);
return hostnames;
}
use of io.fabric8.kubernetes.client.http.HttpRequest in project cryostat by cryostatio.
the class OpenShiftAuthManagerTest method shouldReturnLogoutRedirectUrl.
@Test
void shouldReturnLogoutRedirectUrl() throws Exception {
Mockito.when(fs.readFile(Paths.get(Config.KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH))).thenReturn(new BufferedReader(new StringReader(SERVICE_ACCOUNT_TOKEN)));
Resource<OAuthAccessToken> token = Mockito.mock(Resource.class);
NonNamespaceOperation<OAuthAccessToken, OAuthAccessTokenList, Resource<OAuthAccessToken>> tokens = Mockito.mock(NonNamespaceOperation.class);
Mockito.when(client.oAuthAccessTokens()).thenReturn(tokens);
Mockito.when(tokens.withName(Mockito.anyString())).thenReturn(token);
Mockito.when(token.delete()).thenReturn(true);
HttpRequest<Buffer> req = Mockito.mock(HttpRequest.class);
HttpResponse<Buffer> resp = Mockito.mock(HttpResponse.class);
Mockito.when(webClient.get(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString())).thenReturn(req);
Mockito.when(req.putHeader(Mockito.anyString(), Mockito.anyString())).thenReturn(req);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock args) throws Throwable {
AsyncResult<HttpResponse<Buffer>> asyncResult = Mockito.mock(AsyncResult.class);
Mockito.when(asyncResult.result()).thenReturn(resp);
Mockito.when(resp.bodyAsJsonObject()).thenReturn(OAUTH_METADATA);
((Handler<AsyncResult<HttpResponse<Buffer>>>) args.getArgument(0)).handle(asyncResult);
return null;
}
}).when(req).send(Mockito.any());
String logoutRedirectUrl = mgr.logout(() -> "Bearer myToken").get();
MatcherAssert.assertThat(logoutRedirectUrl, Matchers.equalTo(EXPECTED_LOGOUT_REDIRECT_URL));
}
use of io.fabric8.kubernetes.client.http.HttpRequest in project fabric8 by jboss-fuse.
the class JolokiaFabricConnector method connect.
/**
* connects to a fabric
*/
public void connect() {
if (this.j4p != null || this.fabricServiceFacade != null) {
disconnect();
}
this.j4p = J4pClient.url(this.url).user(this.userName).password(this.password).build();
/* This needs further investigation...
DefaultHttpClient httpClient = (DefaultHttpClient) j4p.getHttpClient();
httpClient.setRedirectStrategy(new DefaultRedirectStrategy() {
@Override
public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
return true;
}
});
*/
this.fabricServiceFacade = new FabricServiceFacade(this);
this.fabricMBeanFacade = new FabricMBean(this);
}
Aggregations