-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from thescouser89/dela
Add deliverables analyzer adapter
- Loading branch information
Showing
3 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
api/src/main/java/org/jboss/pnc/dingrogu/api/dto/adapter/DeliverablesAnalyzerDTO.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,19 @@ | ||
package org.jboss.pnc.dingrogu.api.dto.adapter; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.extern.jackson.Jacksonized; | ||
|
||
import java.util.List; | ||
|
||
@Jacksonized | ||
@Data | ||
@Builder | ||
public class DeliverablesAnalyzerDTO { | ||
String deliverablesAnalyzerUrl; | ||
|
||
String operationId; | ||
List<String> urls; | ||
String config; | ||
|
||
} |
88 changes: 88 additions & 0 deletions
88
...src/main/java/org/jboss/pnc/dingrogu/restadapter/adapter/DeliverablesAnalyzerAdapter.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,88 @@ | ||
package org.jboss.pnc.dingrogu.restadapter.adapter; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.jboss.pnc.api.deliverablesanalyzer.dto.AnalyzePayload; | ||
import org.jboss.pnc.api.dto.Request; | ||
import org.jboss.pnc.dingrogu.api.dto.adapter.DeliverablesAnalyzerDTO; | ||
import org.jboss.pnc.dingrogu.api.endpoint.AdapterEndpoint; | ||
import org.jboss.pnc.dingrogu.common.TaskHelper; | ||
import org.jboss.pnc.dingrogu.restadapter.client.DeliverablesAnalyzerClient; | ||
import org.jboss.pnc.rex.dto.ConfigurationDTO; | ||
import org.jboss.pnc.rex.dto.CreateTaskDTO; | ||
import org.jboss.pnc.rex.model.requests.StartRequest; | ||
import org.jboss.pnc.rex.model.requests.StopRequest; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
|
||
@ApplicationScoped | ||
public class DeliverablesAnalyzerAdapter implements Adapter<DeliverablesAnalyzerDTO> { | ||
|
||
@ConfigProperty(name = "dingrogu.url") | ||
String dingroguUrl; | ||
|
||
@Inject | ||
DeliverablesAnalyzerClient deliverablesAnalyzerClient; | ||
|
||
@Override | ||
public String getName() { | ||
return "deliverables-analyzer"; | ||
} | ||
|
||
@Override | ||
public void start(String correlationId, StartRequest startRequest) { | ||
DeliverablesAnalyzerDTO deliverablesAnalyzerDTO = (DeliverablesAnalyzerDTO) startRequest.getPayload(); | ||
|
||
String callbackUrl = AdapterEndpoint.getCallbackAdapterEndpoint(dingroguUrl, getName(), correlationId); | ||
Request callback = new Request(Request.Method.POST, URI.create(callbackUrl), null); | ||
|
||
// TODO: heartbeat | ||
AnalyzePayload payload = new AnalyzePayload( | ||
deliverablesAnalyzerDTO.getOperationId(), | ||
deliverablesAnalyzerDTO.getUrls(), | ||
deliverablesAnalyzerDTO.getConfig(), | ||
callback, | ||
null); | ||
|
||
deliverablesAnalyzerClient.analyze(deliverablesAnalyzerDTO.getDeliverablesAnalyzerUrl(), payload); | ||
} | ||
|
||
@Override | ||
public void callback(String correlationId, Object object) { | ||
// TODO: send reply back to rex | ||
|
||
} | ||
|
||
@Override | ||
public void cancel(String correlationId, StopRequest stopRequest) { | ||
// TODO | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public CreateTaskDTO generateRexTask( | ||
String adapterUrl, | ||
String correlationId, | ||
DeliverablesAnalyzerDTO deliverablesAnalyzerDTO) throws Exception { | ||
Request startRequest = new Request( | ||
Request.Method.POST, | ||
new URI(AdapterEndpoint.getStartAdapterEndpoint(adapterUrl, getName(), correlationId)), | ||
List.of(TaskHelper.getJsonHeader()), | ||
deliverablesAnalyzerDTO); | ||
|
||
Request cancelRequest = new Request( | ||
Request.Method.POST, | ||
new URI(AdapterEndpoint.getCancelAdapterEndpoint(adapterUrl, getName(), correlationId)), | ||
List.of(TaskHelper.getJsonHeader()), | ||
deliverablesAnalyzerDTO); | ||
|
||
return CreateTaskDTO.builder() | ||
.name(getName()) | ||
.remoteStart(startRequest) | ||
.remoteCancel(cancelRequest) | ||
.configuration(new ConfigurationDTO()) | ||
.build(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...r/src/main/java/org/jboss/pnc/dingrogu/restadapter/client/DeliverablesAnalyzerClient.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,23 @@ | ||
package org.jboss.pnc.dingrogu.restadapter.client; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import kong.unirest.core.HttpResponse; | ||
import kong.unirest.core.JsonNode; | ||
import kong.unirest.core.Unirest; | ||
import org.jboss.pnc.api.deliverablesanalyzer.dto.AnalyzePayload; | ||
|
||
@ApplicationScoped | ||
public class DeliverablesAnalyzerClient { | ||
|
||
public void analyze(String deliverablesAnalyzerUrl, AnalyzePayload request) { | ||
|
||
HttpResponse<JsonNode> response = Unirest.post(deliverablesAnalyzerUrl + "/api/analyze") | ||
.header("accept", "application/json") | ||
.body(request) | ||
.asJson(); | ||
|
||
if (!response.isSuccess()) { | ||
throw new RuntimeException("Request didn't go through"); | ||
} | ||
} | ||
} |