Skip to content

Commit

Permalink
format using wildfly-core xml
Browse files Browse the repository at this point in the history
  • Loading branch information
laDok8 committed Mar 1, 2023
1 parent 2ee7862 commit d414034
Show file tree
Hide file tree
Showing 17 changed files with 468 additions and 554 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import java.util.function.Function;
import java.util.stream.Collectors;

public class ConfigMapBuilder extends AbstractBuilder<ConfigMap, ConfigMapBuilder>
implements EnvironmentConfiguration {
public class ConfigMapBuilder extends AbstractBuilder<ConfigMap, ConfigMapBuilder> implements EnvironmentConfiguration {
private final Map<String, String> config = new HashMap<>();
private Function<String, String> nameTransformationFunction = Function.identity();

Expand All @@ -17,14 +16,9 @@ public ConfigMapBuilder(String name) {

@Override
public ConfigMap build() {
return new io.fabric8.kubernetes.api.model.ConfigMapBuilder()
.withMetadata(metadataBuilder().build())
.withData(
config.entrySet().stream()
.collect(
Collectors.toMap(
x -> nameTransformationFunction.apply(x.getKey()),
Map.Entry::getValue)))
return new io.fabric8.kubernetes.api.model.ConfigMapBuilder().withMetadata(metadataBuilder().build())
.withData(config.entrySet().stream()
.collect(Collectors.toMap(x -> nameTransformationFunction.apply(x.getKey()), Map.Entry::getValue)))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,16 @@ protected void buildStrategy(BuildStrategyBuilder builder) {
// source image
if (StringUtils.isNotBlank(imageStreamName)) {
if (StringUtils.isNotBlank(imageStreamTag)) {
strategyBuilder
.withNewFrom()
.withKind("ImageStreamTag")
.withName(imageStreamName + ":" + imageStreamTag)
strategyBuilder.withNewFrom().withKind("ImageStreamTag").withName(imageStreamName + ":" + imageStreamTag)
.endFrom();
} else {
strategyBuilder
.withNewFrom()
.withKind("ImageStream")
.withName(imageStreamName)
.endFrom();
strategyBuilder.withNewFrom().withKind("ImageStream").withName(imageStreamName).endFrom();
}
if (StringUtils.isNotBlank(imageStreamNamespace)) {
strategyBuilder.getFrom().setNamespace(imageStreamNamespace);
}
} else if (StringUtils.isNotBlank(dockerImageUrl)) {
strategyBuilder
.withNewFrom()
.withKind("DockerImage")
.withName(dockerImageUrl)
.endFrom();
strategyBuilder.withNewFrom().withKind("DockerImage").withName(dockerImageUrl).endFrom();
}

// forcePull STI image, OSE default is false
Expand All @@ -107,10 +96,8 @@ protected void buildStrategy(BuildStrategyBuilder builder) {
strategyBuilder.withIncremental(incremental);

// build environment
strategyBuilder.withEnv(
env.entrySet().stream()
.map(entry -> new EnvVar(entry.getKey(), entry.getValue(), null))
.collect(Collectors.toList()));
strategyBuilder.withEnv(env.entrySet().stream().map(entry -> new EnvVar(entry.getKey(), entry.getValue(), null))
.collect(Collectors.toList()));

builder.withSourceStrategy(strategyBuilder.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public String getClaimName() {

@Override
protected void addVolumeParameters(VolumeBuilder builder) {
builder.withNewPersistentVolumeClaim()
.withClaimName(getClaimName())
.endPersistentVolumeClaim();
builder.withNewPersistentVolumeClaim().withClaimName(getClaimName()).endPersistentVolumeClaim();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public DefaultStatefulAuxiliary(String symbolicName, String dataDir) {
this(symbolicName, dataDir, null);
}

public DefaultStatefulAuxiliary(
String symbolicName, String dataDir, PersistentVolumeClaim pvc) {
public DefaultStatefulAuxiliary(String symbolicName, String dataDir, PersistentVolumeClaim pvc) {
super(symbolicName);
this.dataDir = dataDir;
this.persistentVolClaim = pvc;
Expand Down
35 changes: 6 additions & 29 deletions builder/src/main/java/cz/xtf/builder/db/MySQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ public MySQL(boolean withLivenessProbe, boolean withReadinessProbe) {
}

public MySQL(boolean withLivenessProbe, boolean withReadinessProbe, boolean withStartupProbe) {
super(
"MYSQL",
"/var/lib/mysql/data",
withLivenessProbe,
withReadinessProbe,
withStartupProbe,
true);
super("MYSQL", "/var/lib/mysql/data", withLivenessProbe, withReadinessProbe, withStartupProbe, true);
}

public MySQL(PersistentVolumeClaim pvc) {
Expand All @@ -31,18 +25,8 @@ public MySQL(PersistentVolumeClaim pvc, boolean withLivenessProbe, boolean withR
super("MYSQL", "/var/lib/mysql/data", pvc, withLivenessProbe, withReadinessProbe);
}

public MySQL(
PersistentVolumeClaim pvc,
boolean withLivenessProbe,
boolean withReadinessProbe,
boolean withStartupProbe) {
super(
"MYSQL",
"/var/lib/mysql/data",
pvc,
withLivenessProbe,
withReadinessProbe,
withStartupProbe);
public MySQL(PersistentVolumeClaim pvc, boolean withLivenessProbe, boolean withReadinessProbe, boolean withStartupProbe) {
super("MYSQL", "/var/lib/mysql/data", pvc, withLivenessProbe, withReadinessProbe, withStartupProbe);
}

public MySQL(String username, String password, String dbName) {
Expand All @@ -61,16 +45,9 @@ public int getPort() {

@Override
protected ProbeSettings getProbeSettings() {
return new ProbeSettings(
30,
String.valueOf(getPort()),
5,
"MYSQL_PWD=\"$MYSQL_PASSWORD\" mysql -h 127.0.0.1 -u $MYSQL_USER -D $MYSQL_DATABASE"
+ " -e 'SELECT 1'",
5,
"MYSQL_PWD=\"$MYSQL_PASSWORD\" mysql -h 127.0.0.1 -u $MYSQL_USER -D $MYSQL_DATABASE"
+ " -e 'SELECT 1'",
10,
return new ProbeSettings(30, String.valueOf(getPort()), 5,
"MYSQL_PWD=\"$MYSQL_PASSWORD\" mysql -h 127.0.0.1 -u $MYSQL_USER -D $MYSQL_DATABASE" + " -e 'SELECT 1'", 5,
"MYSQL_PWD=\"$MYSQL_PASSWORD\" mysql -h 127.0.0.1 -u $MYSQL_USER -D $MYSQL_DATABASE" + " -e 'SELECT 1'", 10,
10);
}

Expand Down
25 changes: 5 additions & 20 deletions core/src/main/java/cz/xtf/core/bm/BinaryBuildFromFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,13 @@
@Slf4j
public class BinaryBuildFromFile extends BinaryBuild {

public BinaryBuildFromFile(
String builderImage, Path path, Map<String, String> envProperties, String id) {
public BinaryBuildFromFile(String builderImage, Path path, Map<String, String> envProperties, String id) {
super(builderImage, path, envProperties, id);
}

protected void configureBuildStrategy(
BuildConfigSpecBuilder builder, String builderImage, List<EnvVar> env) {
builder.withNewStrategy()
.withType("Source")
.withNewSourceStrategy()
.withEnv(env)
.withForcePull(true)
.withNewFrom()
.withKind("DockerImage")
.withName(builderImage)
.endFrom()
.endSourceStrategy()
.endStrategy();
protected void configureBuildStrategy(BuildConfigSpecBuilder builder, String builderImage, List<EnvVar> env) {
builder.withNewStrategy().withType("Source").withNewSourceStrategy().withEnv(env).withForcePull(true).withNewFrom()
.withKind("DockerImage").withName(builderImage).endFrom().endSourceStrategy().endStrategy();
}

protected String getImage(BuildConfig bc) {
Expand All @@ -57,11 +46,7 @@ public void build(OpenShift openShift) {
if (fileName.matches(".*(\\.\\w+)$")) {
fileName = "ROOT" + fileName.replaceFirst(".*(\\.\\w+)$", "$1");
}
openShift
.buildConfigs()
.withName(bc.getMetadata().getName())
.instantiateBinary()
.asFile(fileName)
openShift.buildConfigs().withName(bc.getMetadata().getName()).instantiateBinary().asFile(fileName)
.fromFile(getPath().toFile());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,12 @@

public class BinaryBuildFromFileAsInputStream extends BinaryBuildFromFile {

public BinaryBuildFromFileAsInputStream(
String builderImage, Path path, Map<String, String> envProperties, String id) {
public BinaryBuildFromFileAsInputStream(String builderImage, Path path, Map<String, String> envProperties, String id) {
super(builderImage, path, envProperties, id);
}

protected void configureBuildStrategy(
BuildConfigSpecBuilder builder, String builderImage, List<EnvVar> env) {
builder.withNewStrategy()
.withType("Source")
.withNewSourceStrategy()
.withEnv(env)
.withForcePull(true)
.withNewFrom()
.withKind("ImageStreamTag")
.withName(builderImage)
.endFrom()
.endSourceStrategy()
.endStrategy();
protected void configureBuildStrategy(BuildConfigSpecBuilder builder, String builderImage, List<EnvVar> env) {
builder.withNewStrategy().withType("Source").withNewSourceStrategy().withEnv(env).withForcePull(true).withNewFrom()
.withKind("ImageStreamTag").withName(builderImage).endFrom().endSourceStrategy().endStrategy();
}
}
19 changes: 4 additions & 15 deletions core/src/main/java/cz/xtf/core/bm/BinaryDockerBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,14 @@

@Slf4j
public class BinaryDockerBuild extends BinaryBuildFromSources {
public BinaryDockerBuild(
String builderImage, Path path, Map<String, String> envProperties, String id) {
public BinaryDockerBuild(String builderImage, Path path, Map<String, String> envProperties, String id) {
super(builderImage, path, envProperties, id);
}

@Override
protected void configureBuildStrategy(
BuildConfigSpecBuilder builder, String builderImage, List<EnvVar> env) {
builder.withNewStrategy()
.withType("Docker")
.withNewDockerStrategy()
.withEnv(env)
.withForcePull(true)
.withNewFrom()
.withKind("DockerImage")
.withName(builderImage)
.endFrom()
.endDockerStrategy()
.endStrategy();
protected void configureBuildStrategy(BuildConfigSpecBuilder builder, String builderImage, List<EnvVar> env) {
builder.withNewStrategy().withType("Docker").withNewDockerStrategy().withEnv(env).withForcePull(true).withNewFrom()
.withKind("DockerImage").withName(builderImage).endFrom().endDockerStrategy().endStrategy();
}

@Override
Expand Down
19 changes: 4 additions & 15 deletions core/src/main/java/cz/xtf/core/bm/BinarySourceBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,14 @@

@Slf4j
public class BinarySourceBuild extends BinaryBuildFromSources {
public BinarySourceBuild(
String builderImage, Path path, Map<String, String> envProperties, String id) {
public BinarySourceBuild(String builderImage, Path path, Map<String, String> envProperties, String id) {
super(builderImage, path, envProperties, id);
}

@Override
protected void configureBuildStrategy(
BuildConfigSpecBuilder builder, String builderImage, List<EnvVar> env) {
builder.withNewStrategy()
.withType("Source")
.withNewSourceStrategy()
.withEnv(env)
.withForcePull(true)
.withNewFrom()
.withKind("DockerImage")
.withName(builderImage)
.endFrom()
.endSourceStrategy()
.endStrategy();
protected void configureBuildStrategy(BuildConfigSpecBuilder builder, String builderImage, List<EnvVar> env) {
builder.withNewStrategy().withType("Source").withNewSourceStrategy().withEnv(env).withForcePull(true).withNewFrom()
.withKind("DockerImage").withName(builderImage).endFrom().endSourceStrategy().endStrategy();
}

@Override
Expand Down
26 changes: 9 additions & 17 deletions core/src/main/java/cz/xtf/core/bm/BuildManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,13 @@ public BuildManager(OpenShift openShift) {
// Error from server (Forbidden): namespaces "<name>" is forbidden: User "<user>"
// cannot
// patch resource "namespaces" in API group "" in the namespace "<name>"
OpenShifts.admin(openShift.getNamespace())
.namespaces()
.withName(openShift.getNamespace())
.edit(
new Visitor<NamespaceBuilder>() {
@Override
public void visit(NamespaceBuilder builder) {
builder.editMetadata()
.addToLabels(OpenShift.XTF_MANAGED_LABEL, "true");
}
});
OpenShifts.admin(openShift.getNamespace()).namespaces().withName(openShift.getNamespace())
.edit(new Visitor<NamespaceBuilder>() {
@Override
public void visit(NamespaceBuilder builder) {
builder.editMetadata().addToLabels(OpenShift.XTF_MANAGED_LABEL, "true");
}
});
} catch (KubernetesClientException e) {
// We weren't able to assign a label to the new project. Let's just print warning
// since this
Expand All @@ -54,12 +50,8 @@ public void visit(NamespaceBuilder builder) {
// permissions since
// some projects using XTF are executed on OCP instances without 'admin' accounts
// available.
log.warn(
"Couldn't assign label '"
+ OpenShift.XTF_MANAGED_LABEL
+ "' to the new project '"
+ openShift.getNamespace()
+ "'. Possible cause are insufficient permissions.");
log.warn("Couldn't assign label '" + OpenShift.XTF_MANAGED_LABEL + "' to the new project '"
+ openShift.getNamespace() + "'. Possible cause are insufficient permissions.");
log.debug(e.getMessage());
}
}
Expand Down
21 changes: 7 additions & 14 deletions core/src/main/java/cz/xtf/core/config/BackwardCompatibility.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@ class BackwardCompatibility {
static void updateProperties() {
BackwardCompatibility.setIfAbsentAndNotNull(OpenShiftConfig.OPENSHIFT_URL, ocpUrl());
BackwardCompatibility.setIfAbsentAndNotNull(OpenShiftConfig.OPENSHIFT_TOKEN, token());
BackwardCompatibility.setIfAbsentAndNotNull(
OpenShiftConfig.OPENSHIFT_NAMESPACE, namespace());
BackwardCompatibility.setIfAbsentAndNotNull(
OpenShiftConfig.OPENSHIFT_MASTER_USERNAME, masterUsername());
BackwardCompatibility.setIfAbsentAndNotNull(
OpenShiftConfig.OPENSHIFT_MASTER_PASSWORD, masterPassword());
BackwardCompatibility.setIfAbsentAndNotNull(
OpenShiftConfig.OPENSHIFT_ADMIN_USERNAME, adminUsername());
BackwardCompatibility.setIfAbsentAndNotNull(
OpenShiftConfig.OPENSHIFT_ADMIN_PASSWORD, adminPassword());
BackwardCompatibility.setIfAbsentAndNotNull(
OpenShiftConfig.OPENSHIFT_ROUTE_DOMAIN, routeDomain());
BackwardCompatibility.setIfAbsentAndNotNull(OpenShiftConfig.OPENSHIFT_NAMESPACE, namespace());
BackwardCompatibility.setIfAbsentAndNotNull(OpenShiftConfig.OPENSHIFT_MASTER_USERNAME, masterUsername());
BackwardCompatibility.setIfAbsentAndNotNull(OpenShiftConfig.OPENSHIFT_MASTER_PASSWORD, masterPassword());
BackwardCompatibility.setIfAbsentAndNotNull(OpenShiftConfig.OPENSHIFT_ADMIN_USERNAME, adminUsername());
BackwardCompatibility.setIfAbsentAndNotNull(OpenShiftConfig.OPENSHIFT_ADMIN_PASSWORD, adminPassword());
BackwardCompatibility.setIfAbsentAndNotNull(OpenShiftConfig.OPENSHIFT_ROUTE_DOMAIN, routeDomain());
}

private static void setIfAbsentAndNotNull(String property, String value) {
Expand Down Expand Up @@ -85,8 +79,7 @@ private static String routeDomain() {
String configRouteDomain = XTFConfig.get("xtf.config.route_domain");
String systemEnvDomain = System.getenv().get("DOMAIN");

return configDomain != null
? "apps." + configDomain
return configDomain != null ? "apps." + configDomain
: (systemEnvDomain != null ? "apps." + systemEnvDomain : configRouteDomain);
}
}
6 changes: 2 additions & 4 deletions core/src/main/java/cz/xtf/core/config/WaitingConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ public static long timeout() {
}

public static Level level() {
return Level.valueOf(
XTFConfig.get(WAITING_LOG_LEVEL, WAITING_LOG_LEVEL_DEFAULT).toUpperCase());
return Level.valueOf(XTFConfig.get(WAITING_LOG_LEVEL, WAITING_LOG_LEVEL_DEFAULT).toUpperCase());
}

public static long timeoutCleanup() {
return Long.parseLong(
XTFConfig.get(WAITING_TIMEOUT_CLEANUP, WAITING_TIMEOUT_CLEANUP_DEFAULT));
return Long.parseLong(XTFConfig.get(WAITING_TIMEOUT_CLEANUP, WAITING_TIMEOUT_CLEANUP_DEFAULT));
}

public static long buildTimeout() {
Expand Down
Loading

0 comments on commit d414034

Please sign in to comment.