Search in sources :

Example 6 with ClusterAccess

use of io.fabric8.maven.core.access.ClusterAccess in project fabric8-maven-plugin by fabric8io.

the class WatchMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        return;
    }
    clusterAccess = new ClusterAccess(namespace);
    kubernetes = clusterAccess.createDefaultClient(log);
    super.execute();
}
Also used : ClusterAccess(io.fabric8.maven.core.access.ClusterAccess)

Example 7 with ClusterAccess

use of io.fabric8.maven.core.access.ClusterAccess 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 8 with ClusterAccess

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

use of io.fabric8.maven.core.access.ClusterAccess 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 10 with ClusterAccess

use of io.fabric8.maven.core.access.ClusterAccess in project fabric8-maven-plugin by fabric8io.

the class ClusterAccessTest method createClientTestKubernetes.

@Test
public void createClientTestKubernetes() throws Exception {
    RootPaths rootpaths = new RootPaths();
    rootpaths.setPaths(paths);
    mockServer.expect().get().withPath("/").andReturn(200, rootpaths).always();
    ClusterAccess clusterAccess = new ClusterAccess(null, client);
    Client outputClient = clusterAccess.createDefaultClient(logger);
    assertTrue(outputClient instanceof KubernetesClient);
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) RootPaths(io.fabric8.kubernetes.api.model.RootPaths) Client(io.fabric8.kubernetes.client.Client) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Test(org.junit.Test)

Aggregations

ClusterAccess (io.fabric8.maven.core.access.ClusterAccess)6 Test (org.junit.Test)6 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)5 RootPaths (io.fabric8.kubernetes.api.model.RootPaths)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)3 DockerBuildService (io.fabric8.maven.core.service.kubernetes.DockerBuildService)3 OpenshiftBuildService (io.fabric8.maven.core.service.openshift.OpenshiftBuildService)3 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 Controller (io.fabric8.kubernetes.api.Controller)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 Client (io.fabric8.kubernetes.client.Client)2 File (java.io.File)2 IOException (java.io.IOException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 KubernetesHelper.createIntOrString (io.fabric8.kubernetes.api.KubernetesHelper.createIntOrString)1 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)1 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)1 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)1