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");
}
}
}
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");
}
}
}
Aggregations