Search in sources :

Example 1 with BuildServiceFactory

use of io.dekorate.BuildServiceFactory in project dekorate by dekorateio.

the class KubernetesExtension method startProject.

private void startProject(ExtensionContext context, Project project) throws InterruptedException {
    LOGGER.info("Starting project at " + project.getRoot());
    KubernetesIntegrationTestConfig config = getKubernetesIntegrationTestConfig(context);
    KubernetesClient client = getKubernetesClient(context);
    KubernetesList list = getKubernetesResources(context, project);
    if (hasKubernetesConfig(project) && hasImageConfig(project)) {
        ImageConfiguration imageConfig = getImageConfig(project).get();
        BuildService buildService = null;
        try {
            BuildServiceFactory buildServiceFactory = BuildServiceFactories.find(project, imageConfig).orElseThrow(() -> new IllegalStateException("No applicable BuildServiceFactory found."));
            buildService = buildServiceFactory.create(project, imageConfig, list.getItems());
        } catch (Exception e) {
            throw DekorateException.launderThrowable("Failed to lookup BuildService.", e);
        }
        // and thus the tests MUST follow.
        if (imageConfig.isAutoPushEnabled()) {
            buildService.prepare();
            buildService.build();
            buildService.push();
        } else if (imageConfig.isAutoBuildEnabled()) {
            buildService.prepare();
            buildService.build();
        } else if (config.isBuildEnabled()) {
            buildService.prepare();
            buildService.build();
        }
    }
    if (config.isDeployEnabled()) {
        list.getItems().stream().forEach(i -> {
            client.resourceList(i).createOrReplace();
            LOGGER.info("Created: " + i.getKind() + " name:" + i.getMetadata().getName() + ".");
        });
        List<HasMetadata> waitables = list.getItems().stream().filter(i -> i instanceof Deployment || i instanceof Pod || i instanceof ReplicaSet || i instanceof ReplicationController).collect(Collectors.toList());
        long started = System.currentTimeMillis();
        LOGGER.info("Waiting until ready (" + config.getReadinessTimeout() + " ms)...");
        waitUntilCondition(context, waitables, i -> Readiness.getInstance().isReady(i), config.getReadinessTimeout(), TimeUnit.MILLISECONDS);
        long ended = System.currentTimeMillis();
        LOGGER.info("Waited: " + (ended - started) + " ms.");
        // Display the item status
        waitables.stream().map(r -> client.resource(r).fromServer().get()).forEach(i -> {
            if (!Readiness.getInstance().isReady(i)) {
                readinessFailed(context);
                LOGGER.warning(i.getKind() + ":" + i.getMetadata().getName() + " not ready!");
            }
        });
        if (hasReadinessFailed(context)) {
            throw new IllegalStateException("Readiness Failed");
        }
    }
}
Also used : WithEvents(io.dekorate.testing.WithEvents) WithProject(io.dekorate.testing.WithProject) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) Arrays(java.util.Arrays) Project(io.dekorate.project.Project) WithKubernetesClient(io.dekorate.testing.WithKubernetesClient) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) KubernetesIntegrationTestConfig(io.dekorate.testing.config.KubernetesIntegrationTestConfig) VersionInfo(io.fabric8.kubernetes.client.VersionInfo) TestWatcher(org.junit.jupiter.api.extension.TestWatcher) DekorateException(io.dekorate.DekorateException) Logger(io.dekorate.Logger) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) WithPod(io.dekorate.testing.WithPod) LoggerFactory(io.dekorate.LoggerFactory) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) BuildServiceFactories(io.dekorate.BuildServiceFactories) Pod(io.fabric8.kubernetes.api.model.Pod) BuildService(io.dekorate.BuildService) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ConditionEvaluationResult(org.junit.jupiter.api.extension.ConditionEvaluationResult) BeforeAllCallback(org.junit.jupiter.api.extension.BeforeAllCallback) ExecutionCondition(org.junit.jupiter.api.extension.ExecutionCondition) AfterAllCallback(org.junit.jupiter.api.extension.AfterAllCallback) ImageConfiguration(io.dekorate.kubernetes.config.ImageConfiguration) BuildServiceFactory(io.dekorate.BuildServiceFactory) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Readiness(io.fabric8.kubernetes.client.internal.readiness.Readiness) WithImageConfig(io.dekorate.testing.WithImageConfig) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) WithKubernetesClient(io.dekorate.testing.WithKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) WithPod(io.dekorate.testing.WithPod) Pod(io.fabric8.kubernetes.api.model.Pod) KubernetesIntegrationTestConfig(io.dekorate.testing.config.KubernetesIntegrationTestConfig) BuildService(io.dekorate.BuildService) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) DekorateException(io.dekorate.DekorateException) ImageConfiguration(io.dekorate.kubernetes.config.ImageConfiguration) BuildServiceFactory(io.dekorate.BuildServiceFactory) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet)

Example 2 with BuildServiceFactory

use of io.dekorate.BuildServiceFactory in project dekorate by dekorateio.

the class OpenshiftExtension method startProject.

private void startProject(ExtensionContext context, Project project) throws InterruptedException {
    LOGGER.info("Starting project at " + project.getRoot());
    OpenshiftIntegrationTestConfig config = getOpenshiftIntegrationTestConfig(context);
    KubernetesClient client = getKubernetesClient(context);
    KubernetesList list = getOpenshiftResources(context, project);
    OpenshiftConfig openshiftConfig = getOpenshiftConfig(project);
    ImageConfiguration imageConfiguration = ImageConfiguration.from(openshiftConfig);
    BuildService buildService = null;
    try {
        BuildServiceFactory buildServiceFactory = BuildServiceFactories.find(project, imageConfiguration).orElseThrow(() -> new IllegalStateException("No applicable BuildServiceFactory found."));
        buildService = buildServiceFactory.create(project, imageConfiguration, list.getItems());
    } catch (Exception e) {
        throw DekorateException.launderThrowable("Failed to lookup BuildService.", e);
    }
    if (config.isPushEnabled()) {
        buildService.prepare();
        buildService.build();
        buildService.push();
    } else if (config.isBuildEnabled()) {
        buildService.prepare();
        buildService.build();
    }
    if (config.isDeployEnabled()) {
        // Create the remaining resources.
        list.getItems().stream().filter(i -> !(i instanceof BuildConfig)).forEach(i -> {
            try {
                HasMetadata r = client.resource(i).fromServer().get();
                if (r == null) {
                    client.resource(i).apply();
                } else if (r instanceof ImageStream) {
                // let's not delete image streams at this point
                } else if (deleteAndWait(context, i, 1, TimeUnit.MINUTES)) {
                    client.resource(i).apply();
                }
            } catch (Exception e) {
                e.printStackTrace(System.err);
            }
            LOGGER.info("Created: " + i.getKind() + " name:" + i.getMetadata().getName() + ".");
        });
        List<HasMetadata> waitables = list.getItems().stream().filter(i -> i instanceof Deployment || i instanceof DeploymentConfig || i instanceof Pod || i instanceof ReplicaSet || i instanceof ReplicationController).collect(Collectors.toList());
        long started = System.currentTimeMillis();
        LOGGER.info("Waiting until ready (" + config.getReadinessTimeout() + " ms)...");
        waitUntilCondition(context, waitables, i -> OpenshiftReadiness.isReady(i), config.getReadinessTimeout(), TimeUnit.MILLISECONDS);
        long ended = System.currentTimeMillis();
        LOGGER.info("Waited: " + (ended - started) + " ms.");
        // Display the item status
        waitables.stream().map(r -> client.resource(r).fromServer().get()).forEach(i -> {
            if (!OpenshiftReadiness.isReady(i)) {
                readinessFailed(context);
                LOGGER.warning(i.getKind() + ":" + i.getMetadata().getName() + " not ready!");
            }
        });
        if (hasReadinessFailed(context)) {
            throw new IllegalStateException("Readiness Failed");
        }
    }
}
Also used : WithEvents(io.dekorate.testing.WithEvents) WithProject(io.dekorate.testing.WithProject) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) Arrays(java.util.Arrays) Project(io.dekorate.project.Project) OpenshiftIntegrationTestConfig(io.dekorate.testing.openshift.config.OpenshiftIntegrationTestConfig) WithKubernetesClient(io.dekorate.testing.WithKubernetesClient) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) OpenshiftConfig(io.dekorate.openshift.config.OpenshiftConfig) VersionInfo(io.fabric8.kubernetes.client.VersionInfo) TestWatcher(org.junit.jupiter.api.extension.TestWatcher) ImageStream(io.fabric8.openshift.api.model.ImageStream) DekorateException(io.dekorate.DekorateException) Logger(io.dekorate.Logger) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) WithPod(io.dekorate.testing.WithPod) Internal(io.dekorate.kubernetes.annotation.Internal) LoggerFactory(io.dekorate.LoggerFactory) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) BuildServiceFactories(io.dekorate.BuildServiceFactories) Pod(io.fabric8.kubernetes.api.model.Pod) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) BuildService(io.dekorate.BuildService) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) TimeUnit(java.util.concurrent.TimeUnit) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) List(java.util.List) ConditionEvaluationResult(org.junit.jupiter.api.extension.ConditionEvaluationResult) BeforeAllCallback(org.junit.jupiter.api.extension.BeforeAllCallback) ExecutionCondition(org.junit.jupiter.api.extension.ExecutionCondition) AfterAllCallback(org.junit.jupiter.api.extension.AfterAllCallback) ImageConfiguration(io.dekorate.kubernetes.config.ImageConfiguration) BuildServiceFactory(io.dekorate.BuildServiceFactory) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) WithKubernetesClient(io.dekorate.testing.WithKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) WithPod(io.dekorate.testing.WithPod) Pod(io.fabric8.kubernetes.api.model.Pod) BuildService(io.dekorate.BuildService) ImageStream(io.fabric8.openshift.api.model.ImageStream) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) OpenshiftConfig(io.dekorate.openshift.config.OpenshiftConfig) DekorateException(io.dekorate.DekorateException) OpenshiftIntegrationTestConfig(io.dekorate.testing.openshift.config.OpenshiftIntegrationTestConfig) ImageConfiguration(io.dekorate.kubernetes.config.ImageConfiguration) BuildServiceFactory(io.dekorate.BuildServiceFactory) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet)

Aggregations

BuildService (io.dekorate.BuildService)2 BuildServiceFactories (io.dekorate.BuildServiceFactories)2 BuildServiceFactory (io.dekorate.BuildServiceFactory)2 DekorateException (io.dekorate.DekorateException)2 Logger (io.dekorate.Logger)2 LoggerFactory (io.dekorate.LoggerFactory)2 ImageConfiguration (io.dekorate.kubernetes.config.ImageConfiguration)2 Project (io.dekorate.project.Project)2 WithEvents (io.dekorate.testing.WithEvents)2 WithKubernetesClient (io.dekorate.testing.WithKubernetesClient)2 WithPod (io.dekorate.testing.WithPod)2 WithProject (io.dekorate.testing.WithProject)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)2 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)2 ReplicaSet (io.fabric8.kubernetes.api.model.apps.ReplicaSet)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 VersionInfo (io.fabric8.kubernetes.client.VersionInfo)2