Search in sources :

Example 6 with PlatformMode

use of io.fabric8.maven.core.config.PlatformMode 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 7 with PlatformMode

use of io.fabric8.maven.core.config.PlatformMode in project fabric8-maven-plugin by fabric8io.

the class Fabric8ServiceHubTest method testObtainBuildService.

@Test
public void testObtainBuildService() {
    Fabric8ServiceHub hub = new Fabric8ServiceHub.Builder().clusterAccess(clusterAccess).log(logger).platformMode(PlatformMode.kubernetes).dockerServiceHub(dockerServiceHub).buildServiceConfig(buildServiceConfig).build();
    BuildService buildService = hub.getBuildService();
    assertNotNull(buildService);
    assertTrue(buildService instanceof DockerBuildService);
}
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) Test(org.junit.Test)

Example 8 with PlatformMode

use of io.fabric8.maven.core.config.PlatformMode 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 9 with PlatformMode

use of io.fabric8.maven.core.config.PlatformMode in project fabric8-maven-plugin by fabric8io.

the class DockerImageWatcher method watch.

@Override
public void watch(List<ImageConfiguration> configs, final Set<HasMetadata> resources, PlatformMode mode) {
    BuildService.BuildContext buildContext = getContext().getBuildContext();
    WatchService.WatchContext watchContext = getContext().getWatchContext();
    // add a image customizer
    watchContext = new WatchService.WatchContext.Builder(watchContext).imageCustomizer(new Task<ImageConfiguration>() {

        @Override
        public void execute(ImageConfiguration imageConfiguration) throws DockerAccessException, MojoExecutionException, MojoFailureException {
            buildImage(imageConfiguration);
        }
    }).containerRestarter(new Task<WatchService.ImageWatcher>() {

        @Override
        public void execute(WatchService.ImageWatcher imageWatcher) throws DockerAccessException, MojoExecutionException, MojoFailureException {
            restartContainer(imageWatcher, resources);
        }
    }).build();
    ServiceHub hub = getContext().getServiceHub();
    try {
        hub.getWatchService().watch(watchContext, buildContext, configs);
    } catch (Exception ex) {
        throw new RuntimeException("Error while watching", ex);
    }
}
Also used : Task(io.fabric8.maven.docker.util.Task) ServiceHub(io.fabric8.maven.docker.service.ServiceHub) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) BuildService(io.fabric8.maven.docker.service.BuildService) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) WatchService(io.fabric8.maven.docker.service.WatchService)

Aggregations

DockerBuildService (io.fabric8.maven.core.service.kubernetes.DockerBuildService)3 OpenshiftBuildService (io.fabric8.maven.core.service.openshift.OpenshiftBuildService)3 Test (org.junit.Test)3 PlatformMode (io.fabric8.maven.core.config.PlatformMode)2 Controller (io.fabric8.kubernetes.api.Controller)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 OpenShiftBuildStrategy (io.fabric8.maven.core.config.OpenShiftBuildStrategy)1 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)1 HandlerHub (io.fabric8.maven.core.handler.HandlerHub)1 PodLogService (io.fabric8.maven.core.service.PodLogService)1 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)1 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)1 BuildService (io.fabric8.maven.docker.service.BuildService)1 ServiceHub (io.fabric8.maven.docker.service.ServiceHub)1 WatchService (io.fabric8.maven.docker.service.WatchService)1 Logger (io.fabric8.maven.docker.util.Logger)1 Task (io.fabric8.maven.docker.util.Task)1 FromSelector (io.fabric8.maven.generator.api.FromSelector)1 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)1