Search in sources :

Example 1 with PodOperationContext

use of io.fabric8.kubernetes.client.dsl.internal.PodOperationContext in project kubernetes-client by fabric8io.

the class BaseOperationTest method testSimpleFieldQueryParamConcatenation.

@Test
void testSimpleFieldQueryParamConcatenation() {
    Map<String, String> fieldsMap = new HashMap<>();
    fieldsMap.put("yesKey1", "yesValue1");
    fieldsMap.put("yesKey2", "yesValue2");
    PodOperationsImpl operation = new PodOperationsImpl(new PodOperationContext(), new OperationContext());
    operation = (PodOperationsImpl) operation.withFields(fieldsMap).withField("yesKey2", "overrideValue2").withoutField("noKey1", "noValue1").withoutField("noKey2", "noValue2");
    final String fieldQueryParam = operation.getFieldQueryParam();
    // Use contains to not be depending on map key/value pair ordering
    assertThat(fieldQueryParam, containsString("yesKey1=yesValue1"));
    assertThat(fieldQueryParam, containsString("yesKey2=overrideValue2"));
    assertThat(fieldQueryParam, containsString("noKey1!=noValue1"));
    assertThat(fieldQueryParam, containsString("noKey2!=noValue2"));
}
Also used : OperationContext(io.fabric8.kubernetes.client.dsl.internal.OperationContext) PodOperationContext(io.fabric8.kubernetes.client.dsl.internal.PodOperationContext) HashMap(java.util.HashMap) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PodOperationsImpl(io.fabric8.kubernetes.client.dsl.internal.core.v1.PodOperationsImpl) PodOperationContext(io.fabric8.kubernetes.client.dsl.internal.PodOperationContext) Test(org.junit.jupiter.api.Test)

Example 2 with PodOperationContext

use of io.fabric8.kubernetes.client.dsl.internal.PodOperationContext in project kubernetes-client by fabric8io.

the class BaseOperationTest method testFilterContextModification.

@Test
void testFilterContextModification() {
    PodOperationsImpl operation = new PodOperationsImpl(new PodOperationContext(), new OperationContext());
    operation.withField("x", "y");
    // should not modify the existing context
    assertTrue(Utils.isNullOrEmpty(operation.getFieldQueryParam()));
}
Also used : OperationContext(io.fabric8.kubernetes.client.dsl.internal.OperationContext) PodOperationContext(io.fabric8.kubernetes.client.dsl.internal.PodOperationContext) PodOperationsImpl(io.fabric8.kubernetes.client.dsl.internal.core.v1.PodOperationsImpl) PodOperationContext(io.fabric8.kubernetes.client.dsl.internal.PodOperationContext) Test(org.junit.jupiter.api.Test)

Example 3 with PodOperationContext

use of io.fabric8.kubernetes.client.dsl.internal.PodOperationContext in project kubernetes-client by fabric8io.

the class PodUpload method uploadDirectory.

private static boolean uploadDirectory(HttpClient client, PodOperationContext context, OperationSupport operationSupport, Path pathToUpload) throws IOException, InterruptedException {
    final String command = String.format("mkdir -p %1$s && base64 -d - | tar -C %1$s -xzf -", shellQuote(context.getDir()));
    final PodUploadWebSocketListener podUploadWebSocketListener = initWebSocket(buildCommandUrl(command, context, operationSupport), client);
    try (final PipedOutputStream pos = new PipedOutputStream();
        final PipedInputStream pis = new PipedInputStream(pos);
        final Base64.OutputStream b64Out = new Base64.OutputStream(pos, Base64.ENCODE);
        final GZIPOutputStream gzip = new GZIPOutputStream(b64Out)) {
        podUploadWebSocketListener.waitUntilReady(operationSupport.getConfig().getRequestConfig().getUploadConnectionTimeout());
        final Callable<?> readFiles = () -> {
            try (final TarArchiveOutputStream tar = new TarArchiveOutputStream(gzip)) {
                tar.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
                for (File file : pathToUpload.toFile().listFiles()) {
                    addFileToTar(null, file, tar);
                }
                tar.flush();
            }
            return null;
        };
        final ExecutorService es = Executors.newSingleThreadExecutor();
        Future<?> readFilesFuture = es.submit(readFiles);
        InputStreamPumper.transferTo(pis, podUploadWebSocketListener::send);
        podUploadWebSocketListener.waitUntilComplete(operationSupport.getConfig().getRequestConfig().getUploadRequestTimeout());
        try {
            readFilesFuture.get(100, TimeUnit.SECONDS);
            return true;
        } catch (ExecutionException ex) {
            if (ex.getCause() instanceof IOException) {
                throw (IOException) ex.getCause();
            }
            throw new IOException(ex.getMessage(), ex.getCause());
        } catch (TimeoutException e) {
            return false;
        } finally {
            es.shutdown();
        }
    }
}
Also used : Base64(io.fabric8.kubernetes.client.utils.internal.Base64) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) PipedOutputStream(java.io.PipedOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) IOException(java.io.IOException) GZIPOutputStream(java.util.zip.GZIPOutputStream) ExecutorService(java.util.concurrent.ExecutorService) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) ExecutionException(java.util.concurrent.ExecutionException) File(java.io.File) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with PodOperationContext

use of io.fabric8.kubernetes.client.dsl.internal.PodOperationContext in project kubernetes-client by fabric8io.

the class BaseOperationTest method testSkippingFieldNotMatchingNullValues.

@Test
void testSkippingFieldNotMatchingNullValues() {
    PodOperationsImpl operation = new PodOperationsImpl(new PodOperationContext(), new OperationContext());
    operation = (PodOperationsImpl) operation.withField("key1", "value1").withoutField("key2", "value2").withoutField("key2", null).withoutField("key2", "").withoutField("key2", "value3").withoutField("key10", "value11").withoutField("key10", // Once more to make sure no accidental trailing comma is added
    "");
    assertThat(operation.getFieldQueryParam(), is(equalTo("key1=value1,key2!=value2,key2!=value3,key10!=value11")));
}
Also used : OperationContext(io.fabric8.kubernetes.client.dsl.internal.OperationContext) PodOperationContext(io.fabric8.kubernetes.client.dsl.internal.PodOperationContext) PodOperationsImpl(io.fabric8.kubernetes.client.dsl.internal.core.v1.PodOperationsImpl) PodOperationContext(io.fabric8.kubernetes.client.dsl.internal.PodOperationContext) Test(org.junit.jupiter.api.Test)

Aggregations

OperationContext (io.fabric8.kubernetes.client.dsl.internal.OperationContext)3 PodOperationContext (io.fabric8.kubernetes.client.dsl.internal.PodOperationContext)3 PodOperationsImpl (io.fabric8.kubernetes.client.dsl.internal.core.v1.PodOperationsImpl)3 Test (org.junit.jupiter.api.Test)3 Base64 (io.fabric8.kubernetes.client.utils.internal.Base64)1 File (java.io.File)1 IOException (java.io.IOException)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 TimeoutException (java.util.concurrent.TimeoutException)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 TarArchiveOutputStream (org.apache.commons.compress.archivers.tar.TarArchiveOutputStream)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1