Skip to content

Commit

Permalink
refractor code using provided eclipse-format.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
laDok8 committed Mar 1, 2023
1 parent b9f4095 commit 2ee7862
Show file tree
Hide file tree
Showing 159 changed files with 4,494 additions and 2,625 deletions.
119 changes: 81 additions & 38 deletions builder/src/main/java/cz/xtf/builder/OpenShiftApplication.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package cz.xtf.builder;

import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

import cz.xtf.builder.builders.ApplicationBuilder;
import cz.xtf.builder.builders.DeploymentConfigBuilder;
import cz.xtf.core.openshift.OpenShift;
Expand All @@ -21,6 +17,9 @@
import io.fabric8.openshift.api.model.DeploymentConfig;
import io.fabric8.openshift.api.model.ImageStream;
import io.fabric8.openshift.api.model.Route;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;

@Slf4j
Expand All @@ -43,8 +42,8 @@ public class OpenShiftApplication {
private List<RoleBinding> roleBindings = new LinkedList<>();

/**
* @deprecated superseded by {@link #OpenShiftApplication(ApplicationBuilder, OpenShift)}
* Bring your own client is a preferred way to obtain OpenShiftApplication object
* @deprecated superseded by {@link #OpenShiftApplication(ApplicationBuilder, OpenShift)} Bring
* your own client is a preferred way to obtain OpenShiftApplication object
*/
@Deprecated
public OpenShiftApplication(ApplicationBuilder appBuilder) {
Expand Down Expand Up @@ -77,46 +76,90 @@ private void createResources() {

// keep the order of deployment
secrets = secrets.stream().map(openShift::createSecret).collect(Collectors.toList());
serviceAccounts = serviceAccounts.stream().map(openShift::createServiceAccount).collect(Collectors.toList());
imageStreams = imageStreams.stream().map(openShift::createImageStream).collect(Collectors.toList());
buildConfigs = buildConfigs.stream().map(openShift::createBuildConfig).collect(Collectors.toList());
persistentVolumeClaims = persistentVolumeClaims.stream().map(openShift::createPersistentVolumeClaim)
serviceAccounts = serviceAccounts.stream()
.map(openShift::createServiceAccount)
.collect(Collectors.toList());
imageStreams = imageStreams.stream()
.map(openShift::createImageStream)
.collect(Collectors.toList());
buildConfigs = buildConfigs.stream()
.map(openShift::createBuildConfig)
.collect(Collectors.toList());
persistentVolumeClaims = persistentVolumeClaims.stream()
.map(openShift::createPersistentVolumeClaim)
.collect(Collectors.toList());
services = services.stream().map(openShift::createService).collect(Collectors.toList());
final List<DeploymentConfig> syncDeployments = deploymentConfigs.stream()
.filter(x -> x.getMetadata().getLabels().containsKey(DeploymentConfigBuilder.SYNCHRONOUS_LABEL))
.sorted((dc1, dc2) -> {
final int labelDc1 = Integer
.parseInt(dc1.getMetadata().getLabels().get(DeploymentConfigBuilder.SYNCHRONOUS_LABEL));
final int labelDc2 = Integer
.parseInt(dc2.getMetadata().getLabels().get(DeploymentConfigBuilder.SYNCHRONOUS_LABEL));
return labelDc1 - labelDc2;
}).map(x -> {
final String syncId = x.getMetadata().getLabels().get(DeploymentConfigBuilder.SYNCHRONOUS_LABEL);
final DeploymentConfig dc = openShift.createDeploymentConfig(x);
.filter(
x -> x.getMetadata()
.getLabels()
.containsKey(
DeploymentConfigBuilder.SYNCHRONOUS_LABEL))
.sorted(
(dc1, dc2) -> {
final int labelDc1 = Integer.parseInt(
dc1.getMetadata()
.getLabels()
.get(
DeploymentConfigBuilder.SYNCHRONOUS_LABEL));
final int labelDc2 = Integer.parseInt(
dc2.getMetadata()
.getLabels()
.get(
DeploymentConfigBuilder.SYNCHRONOUS_LABEL));
return labelDc1 - labelDc2;
})
.map(
x -> {
final String syncId = x.getMetadata()
.getLabels()
.get(DeploymentConfigBuilder.SYNCHRONOUS_LABEL);
final DeploymentConfig dc = openShift.createDeploymentConfig(x);

if (dc.getSpec().getReplicas() > 0) {
try {
log.info("Waiting for a startup of pod with deploymentconfig '{}' ({} {})",
dc.getMetadata().getName(), DeploymentConfigBuilder.SYNCHRONOUS_LABEL, syncId);
openShift.waiters().areExactlyNPodsReady(dc.getSpec().getReplicas(), dc.getMetadata().getName())
.waitFor();
} catch (Exception e) {
throw new IllegalStateException(
"Timeout while waiting for deployment of " + dc.getMetadata().getName(), e);
}
}
return dc;
}).collect(Collectors.toList());
if (dc.getSpec().getReplicas() > 0) {
try {
log.info(
"Waiting for a startup of pod with"
+ " deploymentconfig '{}' ({} {})",
dc.getMetadata().getName(),
DeploymentConfigBuilder.SYNCHRONOUS_LABEL,
syncId);
openShift
.waiters()
.areExactlyNPodsReady(
dc.getSpec().getReplicas(),
dc.getMetadata().getName())
.waitFor();
} catch (Exception e) {
throw new IllegalStateException(
"Timeout while waiting for deployment of "
+ dc.getMetadata().getName(),
e);
}
}
return dc;
})
.collect(Collectors.toList());
deploymentConfigs = deploymentConfigs.stream()
.filter(x -> !x.getMetadata().getLabels().containsKey(DeploymentConfigBuilder.SYNCHRONOUS_LABEL))
.map(openShift::createDeploymentConfig).collect(Collectors.toList());
.filter(
x -> !x.getMetadata()
.getLabels()
.containsKey(
DeploymentConfigBuilder.SYNCHRONOUS_LABEL))
.map(openShift::createDeploymentConfig)
.collect(Collectors.toList());
deploymentConfigs.addAll(syncDeployments);
endpoints = endpoints.stream().map(openShift::createEndpoint).collect(Collectors.toList());
routes = routes.stream().map(openShift::createRoute).collect(Collectors.toList());
configMaps = configMaps.stream().map(openShift::createConfigMap).collect(Collectors.toList());
autoScalers = autoScalers.stream().map(openShift::createHorizontalPodAutoscaler).collect(Collectors.toList());
roles = roles.stream().map(r -> openShift.rbac().roles().create(r)).collect(Collectors.toList());
roleBindings = roleBindings.stream().map(openShift::createRoleBinding).collect(Collectors.toList());
autoScalers = autoScalers.stream()
.map(openShift::createHorizontalPodAutoscaler)
.collect(Collectors.toList());
roles = roles.stream()
.map(r -> openShift.rbac().roles().create(r))
.collect(Collectors.toList());
roleBindings = roleBindings.stream()
.map(openShift::createRoleBinding)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package cz.xtf.builder.builders;

import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;

public abstract class AbstractBuilder<T, R extends AbstractBuilder> {
private final String name;
private final ApplicationBuilder applicationBuilder;
Expand Down Expand Up @@ -64,7 +62,6 @@ public boolean equals(Object o) {
AbstractBuilder<?, ?> that = (AbstractBuilder<?, ?>) o;

return name.equals(that.name);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
package cz.xtf.builder.builders;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import cz.xtf.builder.OpenShiftApplication;
import cz.xtf.builder.db.OpenShiftAuxiliary;
import cz.xtf.core.bm.ManagedBuildReference;
Expand All @@ -25,6 +15,15 @@
import io.fabric8.openshift.api.model.DeploymentConfig;
import io.fabric8.openshift.api.model.ImageStream;
import io.fabric8.openshift.api.model.Route;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;

@Slf4j
Expand All @@ -34,9 +33,15 @@ public static ApplicationBuilder fromImage(String name, String imageUrl) {
return fromImage(name, imageUrl, Collections.EMPTY_MAP);
}

public static ApplicationBuilder fromImage(String name, String imageUrl, Map<String, String> labels) {
public static ApplicationBuilder fromImage(
String name, String imageUrl, Map<String, String> labels) {
ApplicationBuilder appBuilder = new ApplicationBuilder(name, labels);
appBuilder.deploymentConfig().onConfigurationChange().podTemplate().container().fromImage(imageUrl);
appBuilder
.deploymentConfig()
.onConfigurationChange()
.podTemplate()
.container()
.fromImage(imageUrl);

return appBuilder;
}
Expand All @@ -45,9 +50,15 @@ public static ApplicationBuilder fromManagedBuild(String name, ManagedBuildRefer
return fromManagedBuild(name, mbr, Collections.EMPTY_MAP);
}

public static ApplicationBuilder fromManagedBuild(String name, ManagedBuildReference mbr, Map<String, String> labels) {
public static ApplicationBuilder fromManagedBuild(
String name, ManagedBuildReference mbr, Map<String, String> labels) {
ApplicationBuilder appBuilder = new ApplicationBuilder(name, labels);
appBuilder.deploymentConfig().onImageChange().onConfigurationChange().podTemplate().container()
appBuilder
.deploymentConfig()
.onImageChange()
.onConfigurationChange()
.podTemplate()
.container()
.fromImage(mbr.getNamespace(), mbr.getStreamName());

return appBuilder;
Expand All @@ -57,12 +68,25 @@ public static ApplicationBuilder fromS2IBuild(String name, String imageUrl, Stri
return fromS2IBuild(name, imageUrl, gitRepo, Collections.EMPTY_MAP);
}

public static ApplicationBuilder fromS2IBuild(String name, String imageUrl, String gitRepo, Map<String, String> labels) {
public static ApplicationBuilder fromS2IBuild(
String name, String imageUrl, String gitRepo, Map<String, String> labels) {
ApplicationBuilder appBuilder = new ApplicationBuilder(name, labels);
appBuilder.buildConfig().onConfigurationChange().gitSource(gitRepo).setOutput(name).sti().forcePull(true)
appBuilder
.buildConfig()
.onConfigurationChange()
.gitSource(gitRepo)
.setOutput(name)
.sti()
.forcePull(true)
.fromDockerImage(imageUrl);
appBuilder.imageStream();
appBuilder.deploymentConfig().onImageChange().onConfigurationChange().podTemplate().container().fromImage(name);
appBuilder
.deploymentConfig()
.onImageChange()
.onConfigurationChange()
.podTemplate()
.container()
.fromImage(name);

return appBuilder;
}
Expand Down Expand Up @@ -283,7 +307,9 @@ public List<BuildConfig> buildBuildConfigs() {
}

public List<DeploymentConfig> buildDeploymentConfigs() {
return deployments.stream().map(DeploymentConfigBuilder::build).collect(Collectors.toList());
return deployments.stream()
.map(DeploymentConfigBuilder::build)
.collect(Collectors.toList());
}

public List<Service> buildServices() {
Expand All @@ -303,7 +329,9 @@ public List<RoleBinding> buildRoleBindings() {
}

public List<ConfigMap> buildConfigMaps() {
return configMaps.stream().map(ConfigMapWithPropertyFilesBuilder::build).collect(Collectors.toList());
return configMaps.stream()
.map(ConfigMapWithPropertyFilesBuilder::build)
.collect(Collectors.toList());
}

public List<Secret> buildSecrets() {
Expand All @@ -329,8 +357,8 @@ public List<HasMetadata> build() {
}

/**
* @deprecated superseded by {@link #buildApplication(OpenShift)}
* Bring your own client is a preferred way to obtain OpenShiftApplication object
* @deprecated superseded by {@link #buildApplication(OpenShift)} Bring your own client is a
* preferred way to obtain OpenShiftApplication object
*/
@Deprecated
public OpenShiftApplication buildApplication() {
Expand Down
Loading

0 comments on commit 2ee7862

Please sign in to comment.