-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial REST API. Add configuration for build-driver
- Loading branch information
Showing
13 changed files
with
370 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
java-components/driver/src/main/java/com/redhat/hacbs/driver/dto/BuildResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.redhat.hacbs.driver.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder(builderClassName = "Builder") | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public record BuildResponse(String pipelineId, String namespace) { | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
java-components/driver/src/main/java/com/redhat/hacbs/driver/dto/CancelRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.redhat.hacbs.driver.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder(builderClassName = "Builder") | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public record CancelRequest(String pipelineId, String namespace) { | ||
|
||
} |
89 changes: 89 additions & 0 deletions
89
java-components/driver/src/main/java/com/redhat/hacbs/driver/endpoints/Public.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2021 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.redhat.hacbs.driver.endpoints; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import org.jboss.pnc.api.dto.ComponentVersion; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.redhat.hacbs.driver.Driver; | ||
import com.redhat.hacbs.driver.dto.BuildRequest; | ||
import com.redhat.hacbs.driver.dto.BuildResponse; | ||
import com.redhat.hacbs.driver.util.Info; | ||
|
||
import io.smallrye.common.annotation.RunOnVirtualThread; | ||
|
||
/** | ||
* Endpoint to start/cancel the build. | ||
* | ||
* @author <a href="mailto:[email protected]">Matej Lazar</a> | ||
*/ | ||
@Path("/") | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public class Public { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(Public.class); | ||
|
||
@Inject | ||
Driver driver; | ||
|
||
@Inject | ||
Info info; | ||
|
||
@POST | ||
@Path("/build") | ||
@RunOnVirtualThread | ||
// public CompletionStage<BuildResponse> build(BuildRequest buildRequest) { | ||
public BuildResponse build(BuildRequest buildRequest) { | ||
logger.info("Requested project build: {}", buildRequest.projectName()); | ||
var result = driver.create(buildRequest); | ||
logger.info("### Got {}", result); | ||
return result; | ||
} | ||
|
||
// TODO: Is delete possible in konflux? | ||
// | ||
// /** | ||
// * Cancel the build execution. | ||
// */ | ||
// @PUT | ||
// @Path("/cancel") | ||
// public CompletionStage<Response> cancel(BuildCancelRequest buildCancelRequest) { | ||
// logger.info("Requested cancel: {}", buildCancelRequest.getBuildExecutionId()); | ||
// return driver.cancel(buildCancelRequest).thenApply((r) -> Response.status(r.getCode()).build()); | ||
// } | ||
|
||
@Path("/version") | ||
@GET | ||
@RunOnVirtualThread | ||
public ComponentVersion getVersion() { | ||
var r = info.getVersion(); | ||
logger.info("Requested version {}", r); | ||
return r; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
java-components/driver/src/main/java/com/redhat/hacbs/driver/util/Info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.redhat.hacbs.driver.util; | ||
|
||
import jakarta.enterprise.context.RequestScoped; | ||
import jakarta.inject.Inject; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.jboss.pnc.api.dto.ComponentVersion; | ||
|
||
import io.quarkus.info.BuildInfo; | ||
import io.quarkus.info.GitInfo; | ||
|
||
@RequestScoped | ||
public class Info { | ||
|
||
@ConfigProperty(name = "quarkus.application.name") | ||
String name; | ||
|
||
@Inject | ||
GitInfo gitInfo; | ||
|
||
@Inject | ||
BuildInfo buildInfo; | ||
|
||
public ComponentVersion getVersion() { | ||
return ComponentVersion.builder() | ||
.name(name) | ||
.builtOn(buildInfo.time().toZonedDateTime()) | ||
.commit(gitInfo.latestCommitId()) | ||
.version(buildInfo.version()) | ||
.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.