Skip to content

Commit f3a3e56

Browse files
committed
Improve logging. Refactor
1 parent 3747806 commit f3a3e56

File tree

4 files changed

+35
-29
lines changed

4 files changed

+35
-29
lines changed

java-components/cli/src/main/java/com/redhat/hacbs/cli/driver/Pipeline.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.redhat.hacbs.cli.driver;
22

3-
import java.io.IOException;
4-
53
import jakarta.enterprise.context.control.ActivateRequestContext;
64
import jakarta.inject.Inject;
75

@@ -30,8 +28,9 @@ public class Pipeline extends Base implements Runnable {
3028
@ActivateRequestContext // https://github.com/quarkusio/quarkus/issues/8758
3129
@Override
3230
public void run() {
33-
logger.info("### in here with driver {}", driver);
34-
driver.addValues(accessToken.orElse(""), quayRepo, processor);
31+
driver.setQuayRepo(quayRepo);
32+
driver.setProcessor(processor);
33+
driver.setAccessToken(accessToken.orElse(""));
3534

3635
BuildRequest request = BuildRequest.builder()
3736
.namespace(namespace)
@@ -46,11 +45,6 @@ public void run() {
4645
.repositoryBuildContentId("test-maven-konflux-int-0001")
4746
.recipeImage(recipeImage)
4847
.build();
49-
try {
50-
driver.create(request);
51-
} catch (IOException e) {
52-
throw new RuntimeException(e);
53-
}
54-
48+
driver.create(request);
5549
}
5650
}

java-components/driver/src/main/java/com/redhat/hacbs/driver/Driver.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import org.apache.commons.io.IOUtils;
1414
import org.apache.commons.text.StringSubstitutor;
15+
import org.eclipse.microprofile.config.ConfigProvider;
1516
import org.eclipse.microprofile.rest.client.inject.RestClient;
1617
import org.slf4j.Logger;
1718
import org.slf4j.LoggerFactory;
@@ -27,12 +28,15 @@
2728
import io.fabric8.kubernetes.client.KubernetesClient;
2829
import io.fabric8.tekton.pipeline.v1.PipelineRun;
2930
import io.quarkus.oidc.client.OidcClient;
31+
import lombok.Setter;
3032

3133
@RequestScoped
3234
public class Driver {
3335

3436
private static final Logger logger = LoggerFactory.getLogger(Driver.class);
3537

38+
private static final ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
39+
3640
@Inject
3741
OidcClient oidcClient;
3842

@@ -43,25 +47,26 @@ public class Driver {
4347
@Inject
4448
KubernetesClient client;
4549

46-
ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
47-
50+
@Setter
4851
private String accessToken;
49-
private String quayRepo;
50-
private String processor;
5152

52-
public void addValues(String accessToken, String quayRepo, String processor) {
53-
this.accessToken = accessToken;
54-
this.quayRepo = quayRepo;
55-
this.processor = processor;
56-
}
53+
@Setter
54+
private String quayRepo = "quay.io/redhat-user-workloads/konflux-jbs-pnc-tenant/jvm-build-service/build-request-processor:latest";
55+
56+
@Setter
57+
private String processor = "quay.io/redhat-user-workloads-stage/pnc-devel-tenant/pnc";
5758

58-
public void create(BuildRequest buildRequest) throws IOException {
59+
public void create(BuildRequest buildRequest) {
5960
IndyTokenResponseDTO tokenResponseDTO = new IndyTokenResponseDTO(accessToken);
6061

6162
if (isEmpty(accessToken)) {
63+
logger.info("Establishing token from Indy using clientId {}",
64+
ConfigProvider.getConfig().getConfigValue("quarkus.oidc.client-id").getValue());
6265
tokenResponseDTO = indyService.getAuthToken(
6366
new IndyTokenRequestDTO(buildRequest.getRepositoryBuildContentId()),
6467
"Bearer " + getFreshAccessToken());
68+
logger.debug("### new access token: {}", tokenResponseDTO.getToken()); // TODO: REMOVE
69+
6570
}
6671

6772
Map<String, String> templateProperties = new HashMap<>();
@@ -79,14 +84,17 @@ public void create(BuildRequest buildRequest) throws IOException {
7984
templateProperties.put("ACCESS_TOKEN", tokenResponseDTO.getToken());
8085
templateProperties.put("BUILD_ID", buildRequest.getRepositoryBuildContentId());
8186

82-
String pipeline = IOUtils.resourceToString("pipeline.yaml", StandardCharsets.UTF_8,
83-
Thread.currentThread().getContextClassLoader());
87+
String pipeline = "";
88+
try {
89+
pipeline = IOUtils.resourceToString("pipeline.yaml", StandardCharsets.UTF_8,
90+
Thread.currentThread().getContextClassLoader());
91+
} catch (IOException e) {
92+
// TODO: process
93+
}
8494

8595
PipelineRun run = createModelNode(pipeline, templateProperties, PipelineRun.class);
8696

8797
var created = client.resource(run).inNamespace(buildRequest.getNamespace()).create();
88-
89-
System.err.println("### " + created);
9098
}
9199

92100
/**
@@ -97,7 +105,7 @@ public void create(BuildRequest buildRequest) throws IOException {
97105
*/
98106
public String getFreshAccessToken() {
99107
var result = oidcClient.getTokens().await().indefinitely().getAccessToken();
100-
System.err.println("### result " + result);
108+
logger.debug("### access token: {}", result); // TODO: REMOVE
101109
return result;
102110
}
103111

java-components/driver/src/main/java/com/redhat/hacbs/driver/dto/BuildRequest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class BuildRequest {
1919
private final String buildToolVersion;
2020
private final String javaVersion;
2121

22+
// TODO: Is this related to the name of the project (i.e. name returned from /v2/projects/{id}) or the build-config
23+
private final String projectName;
2224
private final String scmUrl;
2325
// TODO: Do we need both?
2426
private final String scmRevision;

java-components/driver/src/main/resources/application.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
quarkus:
2+
application:
3+
name: konflux-build-driver
24
shutdown:
35
timeout: 300
4-
# log:
5-
# category:
6-
# "org.jboss.pnc":
7-
# level: DEBUG
6+
log:
7+
category:
8+
"com.redhat.hacbs":
9+
level: DEBUG
810
# console:
911
# format: "%d{HH:mm:ss,SSS} %-5p traceId=%X{traceId}, parentId=%X{parentId}, spanId=%X{spanId}, sampled=%X{sampled} [%c{3.}] (%t) %s%e mdc:[%X]%n"
1012
# http:

0 commit comments

Comments
 (0)