use of io.fabric8.kubernetes.client.http.HttpClient 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.HttpClient in project kubernetes-client by fabric8io.
the class BuildConfigOperationsImplTest method testWriteShouldCompleteSuccessfully.
@Test
void testWriteShouldCompleteSuccessfully() throws IOException {
// Given
BuildConfigOperationsImpl impl = new BuildConfigOperationsImpl(new OpenshiftClientContext() {
@Override
public HttpClient getHttpClient() {
return httpClient;
}
@Override
public OpenShiftConfig getConfiguration() {
return config;
}
}) {
@Override
protected String getRecentEvents() {
throw new AssertionError();
}
};
HttpResponse<InputStream> response = Mockito.mock(HttpResponse.class, Mockito.CALLS_REAL_METHODS);
when(response.code()).thenReturn(200);
when(response.body()).thenReturn(new ByteArrayInputStream(new byte[0]));
when(httpClient.send(any(), eq(InputStream.class))).thenReturn(response);
impl.submitToApiServer(new ByteArrayInputStream(new byte[0]), 0);
Mockito.verify(response, Mockito.times(1)).body();
}
use of io.fabric8.kubernetes.client.http.HttpClient 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.HttpClient in project cloud-pipeline by epam.
the class PipelineExecutor method launchRootPod.
public void launchRootPod(String command, PipelineRun run, List<EnvVar> envVars, List<String> endpoints, String pipelineId, String nodeIdLabel, String secretName, String clusterId, boolean pullImage) {
try (KubernetesClient client = new DefaultKubernetesClient()) {
Map<String, String> labels = new HashMap<>();
labels.put("spawned_by", "pipeline-api");
labels.put("pipeline_id", pipelineId);
addWorkerLabel(clusterId, labels, run);
LOGGER.debug("Root pipeline task ID: {}", run.getPodId());
Map<String, String> nodeSelector = new HashMap<>();
if (preferenceManager.getPreference(SystemPreferences.CLUSTER_ENABLE_AUTOSCALING)) {
nodeSelector.put("runid", nodeIdLabel);
// id pod ip == pipeline id we have a root pod, otherwise we prefer to skip pod in autoscaler
if (run.getPodId().equals(pipelineId)) {
labels.put("type", "pipeline");
}
labels.put("runid", nodeIdLabel);
} else {
nodeSelector.put("skill", "luigi");
}
labels.putAll(getServiceLabels(endpoints));
OkHttpClient httpClient = HttpClientUtils.createHttpClient(client.getConfiguration());
ObjectMeta metadata = getObjectMeta(run, labels);
PodSpec spec = getPodSpec(run, envVars, secretName, nodeSelector, run.getDockerImage(), command, pullImage);
Pod pod = new Pod("v1", "Pod", metadata, spec, null);
Pod created = new PodOperationsImpl(httpClient, client.getConfiguration(), kubeNamespace).create(pod);
LOGGER.debug("Created POD: {}", created.toString());
}
}
use of io.fabric8.kubernetes.client.http.HttpClient 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