Search in sources :

Example 1 with Logger

use of io.fabric8.arquillian.kubernetes.log.Logger in project docker-maven-plugin by fabric8io.

the class DockerAssemblyManager method verifyGivenDockerfile.

// visible for testing
void verifyGivenDockerfile(File dockerFile, BuildImageConfiguration buildConfig, FixedStringSearchInterpolator interpolator, Logger log) throws IOException {
    AssemblyConfiguration assemblyConfig = buildConfig.getAssemblyConfiguration();
    if (assemblyConfig == null) {
        return;
    }
    String name = assemblyConfig.getName();
    for (String keyword : new String[] { "ADD", "COPY" }) {
        List<String[]> lines = DockerFileUtil.extractLines(dockerFile, keyword, interpolator);
        for (String[] line : lines) {
            if (!line[0].startsWith("#")) {
                // Skip command flags like --chown
                int i;
                for (i = 1; i < line.length; i++) {
                    String component = line[i];
                    if (!component.startsWith("--")) {
                        break;
                    }
                }
                // contains an ADD/COPY ... targetDir .... All good.
                if (i < line.length && line[i].contains(name)) {
                    return;
                }
            }
        }
    }
    log.warn("Dockerfile %s does not contain an ADD or COPY directive to include assembly created at %s. Ignoring assembly.", dockerFile.getPath(), name);
}
Also used : AssemblyConfiguration(io.fabric8.maven.docker.config.AssemblyConfiguration)

Example 2 with Logger

use of io.fabric8.arquillian.kubernetes.log.Logger in project docker-maven-plugin by fabric8io.

the class LogMatchCallbackTest method matchingPartitialLineSucceeds.

@Test(expected = LogCallback.DoneException.class)
public void matchingPartitialLineSucceeds() throws Exception {
    final String patterString = "waiting for connections";
    final LogMatchCallback logMatchCallback = new LogMatchCallback(logger, callback, patterString);
    new Expectations() {

        {
            callback.matched();
            times = 1;
        }
    };
    logMatchCallback.log(1, new Timestamp(), "2017-11-21T12:44:43.678+0000 I NETWORK  [initandlisten] waiting for connections on port 27017");
}
Also used : Expectations(mockit.Expectations) Timestamp(io.fabric8.maven.docker.util.Timestamp) Test(org.junit.Test)

Example 3 with Logger

use of io.fabric8.arquillian.kubernetes.log.Logger in project docker-maven-plugin by fabric8io.

the class LogMatchCallbackTest method matchingLinesNonConformantToThePatternFails.

@Test
public void matchingLinesNonConformantToThePatternFails() throws Exception {
    final String patterString = "The start has started right now";
    final LogMatchCallback logMatchCallback = new LogMatchCallback(logger, callback, patterString);
    new Expectations() {

        {
            callback.matched();
            times = 0;
        }
    };
    logMatchCallback.log(1, new Timestamp(), "LOG:  database system is ready to accept connections");
}
Also used : Expectations(mockit.Expectations) Timestamp(io.fabric8.maven.docker.util.Timestamp) Test(org.junit.Test)

Example 4 with Logger

use of io.fabric8.arquillian.kubernetes.log.Logger in project fabric8-maven-plugin by fabric8io.

the class PortForwardServiceTest method testSimpleScenario.

@Test
public void testSimpleScenario() throws Exception {
    // Cannot test more complex scenarios due to errors in mockwebserver
    OpenShiftMockServer mockServer = new OpenShiftMockServer(false);
    Pod pod1 = new PodBuilder().withNewMetadata().withName("mypod").addToLabels("mykey", "myvalue").withResourceVersion("1").endMetadata().withNewStatus().withPhase("run").endStatus().build();
    PodList pods1 = new PodListBuilder().withItems(pod1).withNewMetadata().withResourceVersion("1").endMetadata().build();
    mockServer.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=mykey%3Dmyvalue").andReturn(200, pods1).always();
    mockServer.expect().get().withPath("/api/v1/namespaces/test/pods").andReturn(200, pods1).always();
    mockServer.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=mykey%3Dmyvalue&watch=true").andUpgradeToWebSocket().open().waitFor(1000).andEmit(new WatchEvent(pod1, "MODIFIED")).done().always();
    mockServer.expect().get().withPath("/api/v1/namespaces/test/pods?resourceVersion=1&watch=true").andUpgradeToWebSocket().open().waitFor(1000).andEmit(new WatchEvent(pod1, "MODIFIED")).done().always();
    OpenShiftClient client = mockServer.createOpenShiftClient();
    PortForwardService service = new PortForwardService(clientToolsService, logger, client) {

        @Override
        public ProcessUtil.ProcessExecutionContext forwardPortAsync(Logger externalProcessLogger, String pod, int remotePort, int localPort) throws Fabric8ServiceException {
            return new ProcessUtil.ProcessExecutionContext(process, Collections.<Thread>emptyList(), logger);
        }
    };
    try (Closeable c = service.forwardPortAsync(logger, new LabelSelectorBuilder().withMatchLabels(Collections.singletonMap("mykey", "myvalue")).build(), 8080, 9000)) {
        Thread.sleep(3000);
    }
}
Also used : LabelSelectorBuilder(io.fabric8.kubernetes.api.model.LabelSelectorBuilder) PodList(io.fabric8.kubernetes.api.model.PodList) Pod(io.fabric8.kubernetes.api.model.Pod) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Closeable(java.io.Closeable) Logger(io.fabric8.maven.docker.util.Logger) ProcessUtil(io.fabric8.maven.core.util.ProcessUtil) PodListBuilder(io.fabric8.kubernetes.api.model.PodListBuilder) OpenShiftMockServer(io.fabric8.openshift.client.server.mock.OpenShiftMockServer) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) WatchEvent(io.fabric8.kubernetes.api.model.WatchEvent) Test(org.junit.Test)

Example 5 with Logger

use of io.fabric8.arquillian.kubernetes.log.Logger in project fabric8-maven-plugin by fabric8io.

the class OpenshiftBuildServiceTest method testFailedBuild.

@Test(expected = Fabric8ServiceException.class)
public void testFailedBuild() throws Exception {
    BuildService.BuildServiceConfig config = defaultConfig.build();
    WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, false, 50, false, false);
    OpenShiftMockServer mockServer = collector.getMockServer();
    OpenShiftClient client = mockServer.createOpenShiftClient();
    OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
    service.build(image);
}
Also used : OpenShiftMockServer(io.fabric8.openshift.client.server.mock.OpenShiftMockServer) BuildService(io.fabric8.maven.core.service.BuildService) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)47 File (java.io.File)26 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)20 Verifications (mockit.Verifications)17 ArrayList (java.util.ArrayList)15 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)12 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)10 IOException (java.io.IOException)9 Expectations (mockit.Expectations)9 URL (java.net.URL)8 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)7 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)6 ResourceValidator (io.fabric8.maven.core.util.validator.ResourceValidator)6 AssemblyConfiguration (io.fabric8.maven.docker.config.AssemblyConfiguration)6 Logger (io.fabric8.maven.docker.util.Logger)6 MojoParameters (io.fabric8.maven.docker.util.MojoParameters)6 Properties (java.util.Properties)6 Util.readAsString (io.fabric8.arquillian.utils.Util.readAsString)5 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)5 Pod (io.fabric8.kubernetes.api.model.Pod)5