Skip to content

Commit fe6c4cb

Browse files
committed
Convert to use java records
1 parent f3e5c8e commit fe6c4cb

File tree

6 files changed

+27
-110
lines changed

6 files changed

+27
-110
lines changed

java-components/driver/pom.xml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,10 @@
2424
<groupId>io.quarkus</groupId>
2525
<artifactId>quarkus-oidc-client</artifactId>
2626
</dependency>
27-
<dependency>
28-
<groupId>io.quarkiverse.tektonclient</groupId>
29-
<artifactId>quarkus-tekton-client</artifactId>
30-
</dependency>
3127
<dependency>
3228
<groupId>io.quarkus</groupId>
3329
<artifactId>quarkus-openshift-client</artifactId>
3430
</dependency>
35-
<dependency>
36-
<groupId>io.quarkus</groupId>
37-
<artifactId>quarkus-kubernetes-client</artifactId>
38-
</dependency>
3931
<dependency>
4032
<groupId>io.quarkus</groupId>
4133
<artifactId>quarkus-rest-jackson</artifactId>
@@ -44,6 +36,10 @@
4436
<groupId>io.quarkus</groupId>
4537
<artifactId>quarkus-rest-client-jackson</artifactId>
4638
</dependency>
39+
<dependency>
40+
<groupId>io.quarkiverse.tektonclient</groupId>
41+
<artifactId>quarkus-tekton-client</artifactId>
42+
</dependency>
4743
<dependency>
4844
<groupId>org.apache.commons</groupId>
4945
<artifactId>commons-text</artifactId>

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,24 @@ public void create(BuildRequest buildRequest) {
6464
logger.info("Establishing token from Indy using clientId {}",
6565
ConfigProvider.getConfig().getConfigValue("quarkus.oidc.client-id").getValue());
6666
tokenResponseDTO = indyService.getAuthToken(
67-
new IndyTokenRequestDTO(buildRequest.getRepositoryBuildContentId()),
67+
new IndyTokenRequestDTO(buildRequest.repositoryBuildContentId()),
6868
"Bearer " + getFreshAccessToken());
6969
}
7070

7171
Map<String, String> templateProperties = new HashMap<>();
72-
templateProperties.put("ACCESS_TOKEN", tokenResponseDTO.getToken());
73-
templateProperties.put("BUILD_ID", buildRequest.getRepositoryBuildContentId());
74-
templateProperties.put("BUILD_SCRIPT", buildRequest.getBuildScript());
75-
templateProperties.put("BUILD_TOOL", buildRequest.getBuildTool());
76-
templateProperties.put("BUILD_TOOL_VERSION", buildRequest.getBuildToolVersion());
77-
templateProperties.put("JAVA_VERSION", buildRequest.getJavaVersion());
78-
templateProperties.put("MVN_REPO_DEPENDENCIES_URL", buildRequest.getRepositoryDependencyUrl());
79-
templateProperties.put("MVN_REPO_DEPLOY_URL", buildRequest.getRepositoryDeployUrl());
72+
templateProperties.put("ACCESS_TOKEN", tokenResponseDTO.token());
73+
templateProperties.put("BUILD_ID", buildRequest.repositoryBuildContentId());
74+
templateProperties.put("BUILD_SCRIPT", buildRequest.buildScript());
75+
templateProperties.put("BUILD_TOOL", buildRequest.buildTool());
76+
templateProperties.put("BUILD_TOOL_VERSION", buildRequest.buildToolVersion());
77+
templateProperties.put("JAVA_VERSION", buildRequest.javaVersion());
78+
templateProperties.put("MVN_REPO_DEPENDENCIES_URL", buildRequest.repositoryDependencyUrl());
79+
templateProperties.put("MVN_REPO_DEPLOY_URL", buildRequest.repositoryDeployUrl());
8080
templateProperties.put("QUAY_REPO", quayRepo);
81-
templateProperties.put("RECIPE_IMAGE", buildRequest.getRecipeImage());
81+
templateProperties.put("RECIPE_IMAGE", buildRequest.recipeImage());
8282
templateProperties.put("JVM_BUILD_SERVICE_REQPROCESSOR_IMAGE", processor);
83-
templateProperties.put("REVISION", buildRequest.getScmRevision());
84-
templateProperties.put("URL", buildRequest.getScmUrl());
83+
templateProperties.put("REVISION", buildRequest.scmRevision());
84+
templateProperties.put("URL", buildRequest.scmUrl());
8585

8686
PipelineRun pipelineRun = null;
8787
try {
@@ -104,17 +104,16 @@ public void create(BuildRequest buildRequest) {
104104
.editFirstTaskRunSpec()
105105
.editFirstStepSpec()
106106
.editComputeResources()
107-
.addToLimits("memory", new Quantity(buildRequest.getPodMemoryOverride()))
108-
.addToRequests("memory", new Quantity(buildRequest.getPodMemoryOverride()))
107+
.addToLimits("memory", new Quantity(buildRequest.podMemoryOverride()))
108+
.addToRequests("memory", new Quantity(buildRequest.podMemoryOverride()))
109109
.endComputeResources()
110110
.endStepSpec()
111111
.endTaskRunSpec()
112112
.endSpec().build();
113113

114114
System.err.println("### Got p " + pipelineRun);
115-
// PipelineRun run = createModelNode(pipeline, templateProperties, PipelineRun.class);
116-
//run.getSpec().setParams();
117-
var created = client.resource(pipelineRun).inNamespace(buildRequest.getNamespace()).create();
115+
var created = client.resource(pipelineRun).inNamespace(buildRequest.namespace()).create();
116+
System.err.println("### Got c " + created);
118117
}
119118

120119
/**

java-components/driver/src/main/java/com/redhat/hacbs/driver/clients/IndyService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public interface IndyService {
4545
@Produces(MediaType.APPLICATION_JSON)
4646
@Consumes(MediaType.APPLICATION_JSON)
4747
@POST
48-
public IndyTokenResponseDTO getAuthToken(
48+
IndyTokenResponseDTO getAuthToken(
4949
IndyTokenRequestDTO indyTokenRequestDTO,
5050
@HeaderParam("Authorization") String accessToken);
5151
}
Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,13 @@
1-
/**
2-
* JBoss, Home of Professional Open Source.
3-
* Copyright 2021 Red Hat, Inc., and individual contributors
4-
* as indicated by the @author tags.
5-
*
6-
* Licensed under the Apache License, Version 2.0 (the "License");
7-
* you may not use this file except in compliance with the License.
8-
* You may obtain a copy of the License at
9-
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
12-
* Unless required by applicable law or agreed to in writing, software
13-
* distributed under the License is distributed on an "AS IS" BASIS,
14-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15-
* See the License for the specific language governing permissions and
16-
* limitations under the License.
17-
*/
181
package com.redhat.hacbs.driver.clients;
192

203
import com.fasterxml.jackson.annotation.JsonProperty;
214

22-
import lombok.AllArgsConstructor;
235
import lombok.Builder;
24-
import lombok.Data;
25-
import lombok.extern.jackson.Jacksonized;
266

277
/**
288
* DTO of the Indy token endpoint request
299
*/
30-
@Jacksonized
3110
@Builder
32-
@Data
33-
@AllArgsConstructor
34-
public class IndyTokenRequestDTO {
11+
public record IndyTokenRequestDTO(@JsonProperty("build-id") String buildId) {
3512

36-
@JsonProperty("build-id")
37-
private String buildId;
3813
}
Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,11 @@
1-
/**
2-
* JBoss, Home of Professional Open Source.
3-
* Copyright 2021 Red Hat, Inc., and individual contributors
4-
* as indicated by the @author tags.
5-
*
6-
* Licensed under the Apache License, Version 2.0 (the "License");
7-
* you may not use this file except in compliance with the License.
8-
* You may obtain a copy of the License at
9-
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
12-
* Unless required by applicable law or agreed to in writing, software
13-
* distributed under the License is distributed on an "AS IS" BASIS,
14-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15-
* See the License for the specific language governing permissions and
16-
* limitations under the License.
17-
*/
181
package com.redhat.hacbs.driver.clients;
192

20-
import lombok.AllArgsConstructor;
213
import lombok.Builder;
22-
import lombok.Data;
23-
import lombok.extern.jackson.Jacksonized;
244

255
/**
266
* DTO of the Indy token endpoint response
277
*/
28-
@Jacksonized
298
@Builder
30-
@Data
31-
@AllArgsConstructor
32-
public class IndyTokenResponseDTO {
9+
public record IndyTokenResponseDTO(String token) {
3310

34-
private String token;
3511
}

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

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,12 @@
33
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
44

55
import lombok.Builder;
6-
import lombok.Data;
7-
import lombok.RequiredArgsConstructor;
8-
import lombok.extern.jackson.Jacksonized;
96

10-
@RequiredArgsConstructor
11-
@Data
12-
@Jacksonized
137
@Builder(builderClassName = "Builder")
148
@JsonIgnoreProperties(ignoreUnknown = true)
15-
public class BuildRequest {
9+
public record BuildRequest(String recipeImage, String buildTool, String buildToolVersion, String javaVersion,
10+
String projectName, String scmUrl, String scmRevision, String buildScript,
11+
String repositoryDependencyUrl, String repositoryDeployUrl, String repositoryBuildContentId,
12+
String namespace, String podMemoryOverride) {
1613

17-
private final String recipeImage;
18-
private final String buildTool;
19-
private final String buildToolVersion;
20-
private final String javaVersion;
21-
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;
24-
private final String scmUrl;
25-
// TODO: Do we need both?
26-
private final String scmRevision;
27-
// private final String scmTag;
28-
29-
private final String buildScript;
30-
31-
// TODO: Are we currently using this? How does PNC pass this?
32-
// private final String workingDirectory;
33-
34-
private final String repositoryDependencyUrl;
35-
36-
private final String repositoryDeployUrl;
37-
38-
private final String repositoryBuildContentId;
39-
40-
private final String namespace;
41-
42-
private final String podMemoryOverride;
4314
}

0 commit comments

Comments
 (0)