-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add callback/notification #5
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 13 additions & 0 deletions
13
src/main/java/org/jboss/pnc/konfluxbuilddriver/dto/BuildCompleted.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,13 @@ | ||
package org.jboss.pnc.konfluxbuilddriver.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder(builderClassName = "Builder") | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public record BuildCompleted( | ||
String status, | ||
String buildId) { | ||
|
||
} |
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
18 changes: 18 additions & 0 deletions
18
src/main/java/org/jboss/pnc/konfluxbuilddriver/dto/PipelineNotification.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,18 @@ | ||
package org.jboss.pnc.konfluxbuilddriver.dto; | ||
|
||
import org.jboss.pnc.api.dto.Request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
import lombok.Builder; | ||
|
||
// TODO: This is a direct copy of the same class in jvm-build-service. Both need moved to pnc-api to | ||
// avoid clashes and duplication. | ||
@Builder(builderClassName = "Builder") | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public record PipelineNotification( | ||
String status, | ||
String buildId, | ||
Request completionCallback) { | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/org/jboss/pnc/konfluxbuilddriver/endpoints/Internal.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,37 @@ | ||
package org.jboss.pnc.konfluxbuilddriver.endpoints; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.PUT; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import org.jboss.pnc.konfluxbuilddriver.Driver; | ||
import org.jboss.pnc.konfluxbuilddriver.dto.PipelineNotification; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import io.smallrye.common.annotation.RunOnVirtualThread; | ||
|
||
/** | ||
* Endpoint to receive build result from the build agent. | ||
*/ | ||
@Path("/internal") | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public class Internal { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(Internal.class); | ||
|
||
@Inject | ||
Driver driver; | ||
|
||
@PUT | ||
@Path("/completed") | ||
@RunOnVirtualThread | ||
public void buildExecutionCompleted(PipelineNotification notification) { | ||
logger.info("Build completed, taskId: {}; status: {}.", notification.buildId(), notification.status()); | ||
driver.completed(notification); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -15,4 +15,6 @@ public interface Configuration { | |
String resolverTarget(); | ||
|
||
String indyProxyEnabled(); | ||
|
||
String selfBaseUrl(); | ||
} |
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
45 changes: 45 additions & 0 deletions
45
src/test/java/org/jboss/pnc/konfluxbuilddriver/WireMockExtensions.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,45 @@ | ||
package org.jboss.pnc.konfluxbuilddriver; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.put; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; | ||
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; | ||
|
||
import java.util.Map; | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
import com.github.tomakehurst.wiremock.common.ConsoleNotifier; | ||
|
||
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; | ||
|
||
public class WireMockExtensions implements QuarkusTestResourceLifecycleManager { | ||
private WireMockServer wireMockServer; | ||
|
||
@Override | ||
public Map<String, String> start() { | ||
wireMockServer = new WireMockServer(wireMockConfig().notifier(new ConsoleNotifier(true))); | ||
wireMockServer.start(); | ||
|
||
wireMockServer.stubFor( | ||
put(urlEqualTo("/invoker")) | ||
.withRequestBody( | ||
equalToJson("{\"status\":\"Succeeded\",\"buildId\":\"1234\"}")) | ||
.willReturn(aResponse() | ||
.withStatus(200))); | ||
|
||
return Map.of("quarkus.rest-client.wiremockextensions.url", wireMockServer.baseUrl()); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
if (wireMockServer != null) { | ||
wireMockServer.stop(); | ||
} | ||
} | ||
|
||
@Override | ||
public void inject(TestInjector testInjector) { | ||
testInjector.injectIntoFields(wireMockServer, new TestInjector.MatchesType(WireMockServer.class)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems the "internal/completed" REST api calls the Driver's "completed()" method which calls the "internal/completed" endpoint again... would this be an infinite loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I missed this. The
build
endpoint takes a callback (to call back to PNC). That callback is embedded into the pipeline which is then passed to thePipelineNotification
so the driver completed method should be instead calling the very first callback, not the internal endpoint.