Search in sources :

Example 1 with OpenshiftBuildService

use of io.fabric8.maven.core.service.openshift.OpenshiftBuildService 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)

Example 2 with OpenshiftBuildService

use of io.fabric8.maven.core.service.openshift.OpenshiftBuildService in project fabric8-maven-plugin by fabric8io.

the class OpenshiftBuildServiceTest method testSuccessfulSecondBuild.

@Test
public void testSuccessfulSecondBuild() throws Exception {
    int nTries = 0;
    boolean bTestComplete = false;
    do {
        try {
            nTries++;
            BuildService.BuildServiceConfig config = defaultConfig.build();
            WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, true, 50, true, true);
            OpenShiftMockServer mockServer = collector.getMockServer();
            OpenShiftClient client = mockServer.createOpenShiftClient();
            OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
            service.build(image);
            assertTrue(mockServer.getRequestCount() > 8);
            collector.assertEventsRecordedInOrder("build-config-check", "patch-build-config", "pushed");
            collector.assertEventsNotRecorded("new-build-config");
            bTestComplete = true;
        } catch (Fabric8ServiceException exception) {
            Throwable rootCause = getRootCause(exception);
            logger.warn("A problem encountered while running test {}, retrying..", exception.getMessage());
            // Let's wait for a while, and then retry again
            if (rootCause != null && rootCause instanceof IOException) {
                continue;
            }
        }
    } while (nTries < MAX_TIMEOUT_RETRIES && !bTestComplete);
}
Also used : OpenShiftMockServer(io.fabric8.openshift.client.server.mock.OpenShiftMockServer) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) BuildService(io.fabric8.maven.core.service.BuildService) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with OpenshiftBuildService

use of io.fabric8.maven.core.service.openshift.OpenshiftBuildService in project fabric8-maven-plugin by fabric8io.

the class Fabric8ServiceHub method init.

private void init() {
    Objects.requireNonNull(clusterAccess, "clusterAccess");
    Objects.requireNonNull(log, "log");
    this.resolvedMode = clusterAccess.resolvePlatformMode(platformMode, log);
    if (resolvedMode != PlatformMode.kubernetes && resolvedMode != PlatformMode.openshift) {
        throw new IllegalArgumentException("Unknown platform mode " + platformMode + " resolved as " + resolvedMode);
    }
    this.client = clusterAccess.createDefaultClient(log);
    if (this.controller == null) {
        this.controller = new Controller(this.client);
        this.controller.setThrowExceptionOnError(true);
    }
    // Lazily building services
    this.services.putIfAbsent(ClientToolsService.class, new LazyBuilder<ClientToolsService>() {

        @Override
        protected ClientToolsService build() {
            return new ClientToolsService(controller, log);
        }
    });
    this.services.putIfAbsent(PortForwardService.class, new LazyBuilder<PortForwardService>() {

        @Override
        protected PortForwardService build() {
            return new PortForwardService(getClientToolsService(), log, client);
        }
    });
    this.services.putIfAbsent(BuildService.class, new LazyBuilder<BuildService>() {

        @Override
        protected BuildService build() {
            BuildService buildService;
            // Creating platform-dependent services
            if (resolvedMode == PlatformMode.openshift) {
                // Openshift services
                buildService = new OpenshiftBuildService((OpenShiftClient) client, log, dockerServiceHub, buildServiceConfig);
            } else {
                // Kubernetes services
                buildService = new DockerBuildService(dockerServiceHub, buildServiceConfig);
            }
            return buildService;
        }
    });
    this.services.putIfAbsent(ArtifactResolverService.class, new LazyBuilder<ArtifactResolverService>() {

        @Override
        protected ArtifactResolverService build() {
            return new ArtifactResolverServiceMavenImpl(repositorySystem, mavenProject);
        }
    });
}
Also used : OpenshiftBuildService(io.fabric8.maven.core.service.openshift.OpenshiftBuildService) DockerBuildService(io.fabric8.maven.core.service.kubernetes.DockerBuildService) DockerBuildService(io.fabric8.maven.core.service.kubernetes.DockerBuildService) OpenshiftBuildService(io.fabric8.maven.core.service.openshift.OpenshiftBuildService) Controller(io.fabric8.kubernetes.api.Controller)

Example 4 with OpenshiftBuildService

use of io.fabric8.maven.core.service.openshift.OpenshiftBuildService in project fabric8-maven-plugin by fabric8io.

the class Fabric8ServiceHubTest method testObtainOpenshiftBuildService.

@Test
public void testObtainOpenshiftBuildService() {
    Fabric8ServiceHub hub = new Fabric8ServiceHub.Builder().clusterAccess(clusterAccess).log(logger).platformMode(PlatformMode.openshift).dockerServiceHub(dockerServiceHub).buildServiceConfig(buildServiceConfig).build();
    BuildService buildService = hub.getBuildService();
    assertNotNull(buildService);
    assertTrue(buildService instanceof OpenshiftBuildService);
}
Also used : OpenshiftBuildService(io.fabric8.maven.core.service.openshift.OpenshiftBuildService) DockerBuildService(io.fabric8.maven.core.service.kubernetes.DockerBuildService) OpenshiftBuildService(io.fabric8.maven.core.service.openshift.OpenshiftBuildService) Test(org.junit.Test)

Example 5 with OpenshiftBuildService

use of io.fabric8.maven.core.service.openshift.OpenshiftBuildService in project fabric8-maven-plugin by fabric8io.

the class OpenshiftBuildServiceTest method checkTarPackage.

@Test
public void checkTarPackage() throws Exception {
    int nTries = 0;
    boolean bTestComplete = false;
    do {
        try {
            nTries++;
            BuildService.BuildServiceConfig config = defaultConfig.build();
            WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, true, 50, true, true);
            OpenShiftMockServer mockServer = collector.getMockServer();
            OpenShiftClient client = mockServer.createOpenShiftClient();
            final OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
            ImageConfiguration imageWithEnv = new ImageConfiguration.Builder(image).buildConfig(new BuildImageConfiguration.Builder(image.getBuildConfiguration()).env(Collections.singletonMap("FOO", "BAR")).build()).build();
            service.createBuildArchive(imageWithEnv);
            final List<ArchiverCustomizer> customizer = new LinkedList<>();
            new Verifications() {

                {
                    archiveService.createDockerBuildArchive(withInstanceOf(ImageConfiguration.class), withInstanceOf(MojoParameters.class), withCapture(customizer));
                    assertTrue(customizer.size() == 1);
                }
            };
            customizer.get(0).customize(tarArchiver);
            final List<File> file = new LinkedList<>();
            new Verifications() {

                {
                    String path;
                    tarArchiver.addFile(withCapture(file), path = withCapture());
                    assertEquals(".s2i/environment", path);
                }
            };
            assertEquals(1, file.size());
            List<String> lines;
            try (FileReader reader = new FileReader(file.get(0))) {
                lines = IOUtils.readLines(reader);
            }
            assertTrue(lines.contains("FOO=BAR"));
            bTestComplete = true;
        } catch (Fabric8ServiceException exception) {
            Throwable rootCause = getRootCause(exception);
            logger.warn("A problem encountered while running test {}, retrying..", exception.getMessage());
            // Let's wait for a while, and then retry again
            if (rootCause != null && rootCause instanceof IOException) {
                continue;
            }
        }
    } while (nTries < MAX_TIMEOUT_RETRIES && !bTestComplete);
}
Also used : BuildService(io.fabric8.maven.core.service.BuildService) ArchiverCustomizer(io.fabric8.maven.docker.assembly.ArchiverCustomizer) ImageStreamStatusBuilder(io.fabric8.openshift.api.model.ImageStreamStatusBuilder) BuildBuilder(io.fabric8.openshift.api.model.BuildBuilder) NamedTagEventListBuilder(io.fabric8.openshift.api.model.NamedTagEventListBuilder) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ImageStreamBuilder(io.fabric8.openshift.api.model.ImageStreamBuilder) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder) IOException(java.io.IOException) Verifications(mockit.Verifications) LinkedList(java.util.LinkedList) OpenShiftMockServer(io.fabric8.openshift.client.server.mock.OpenShiftMockServer) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) MojoParameters(io.fabric8.maven.docker.util.MojoParameters) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) FileReader(java.io.FileReader) File(java.io.File) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 BuildService (io.fabric8.maven.core.service.BuildService)4 DefaultOpenShiftClient (io.fabric8.openshift.client.DefaultOpenShiftClient)4 OpenShiftMockServer (io.fabric8.openshift.client.server.mock.OpenShiftMockServer)4 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)3 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)3 IOException (java.io.IOException)3 DockerBuildService (io.fabric8.maven.core.service.kubernetes.DockerBuildService)2 OpenshiftBuildService (io.fabric8.maven.core.service.openshift.OpenshiftBuildService)2 Controller (io.fabric8.kubernetes.api.Controller)1 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)1 ArchiverCustomizer (io.fabric8.maven.docker.assembly.ArchiverCustomizer)1 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)1 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)1 MojoParameters (io.fabric8.maven.docker.util.MojoParameters)1 BuildBuilder (io.fabric8.openshift.api.model.BuildBuilder)1 BuildConfigBuilder (io.fabric8.openshift.api.model.BuildConfigBuilder)1 ImageStreamBuilder (io.fabric8.openshift.api.model.ImageStreamBuilder)1 ImageStreamStatusBuilder (io.fabric8.openshift.api.model.ImageStreamStatusBuilder)1 NamedTagEventListBuilder (io.fabric8.openshift.api.model.NamedTagEventListBuilder)1