Skip to content

Commit

Permalink
ComponentGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
K0K0V0K committed Nov 24, 2024
1 parent ea443ec commit 07f75a6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 70 deletions.
33 changes: 33 additions & 0 deletions src/main/java/koko/yayu/controller/AppController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.TreeMap;
import java.util.stream.Collectors;

import koko.yayu.component.ComponentGenerator;
import koko.yayu.service.RMApiService;
import koko.yayu.util.YayuUtil;
import org.json.JSONObject;
Expand Down Expand Up @@ -39,6 +40,38 @@ public String index(Model model, @RequestParam(defaultValue = "") String order)
public String appDetails(Model model, @PathVariable String appId) {
JSONObject resp = RMApiService.getApp(appId);
model.addAttribute("props", resp);

model.addAttribute("info", ComponentGenerator.create()
.setTitle("Info - " + appId)
.setColor("is-info")
.addField( "/applicationType")
.addField( "/name")
.addField( "/applicationTags")
.addField( "/queue")
.addField( "/user")
.addField( "/state")
.addField( "/finalStatus")
.addField( "/startedTime")
.addField( "/finishedTime")
.generate(resp)
);

model.addAttribute("capacity", ComponentGenerator.create()
.setTitle("Capacity")
.setColor("is-info")
.addField("/allocatedMB")
.addField("/allocatedVCores")
.addField("/memorySeconds")
.addField("/vcoreSeconds")
.addField("/preemptedResourceVCores", "Preempted vCores")
.addField("/preemptedResourceMB", "Preempted Memory MB")
.addField("/preemptedVcoreSeconds")
.addField("/preemptedMemorySeconds")
.addField("/priority")
.generate(resp)
);


List<JSONObject> attempts = RMApiService.getAttempts(appId);
model.addAttribute("attempts", attempts);
return "app-details";
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/koko/yayu/util/YayuUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Expand Down Expand Up @@ -34,7 +35,10 @@ public static Function<JSONObject, List<JSONObject>> jsonListMapper(String ... p
return jsonObject -> {
JSONObject re = jsonObject;
for (int i = 0; i < paths.length - 1; ++i) {
re = re.getJSONObject(paths[i]);
re = re.optJSONObject(paths[i]);
if (re == null) {
return Collections.emptyList();
}
}
JSONArray array = re.optJSONArray(paths[paths.length - 1]);
return array != null
Expand Down
81 changes: 12 additions & 69 deletions src/main/resources/templates/app-details.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -9,68 +9,10 @@

<div class="columns">
<div class="column is-4 is-offset-1">
<article class="panel is-link">
<p class="panel-heading">Info - ${props.id}</p>
<a class="panel-block">
Application Type: ${props.applicationType}
</a>
<a class="panel-block">
Name: ${props.name}
</a>
<a class="panel-block">
Application Tags: ${props.applicationTags}
</a>
<a class="panel-block">
Queue: ${props.queue}
</a>
<a class="panel-block">
User: ${props.user}
</a>
<a class="panel-block">
State: ${props.state}
</a>
<a class="panel-block">
Final Status: ${props.finalStatus}
</a>
<a class="panel-block">
Start: ${time(props.startedTime)}
</a>
<a class="panel-block">
Finish: ${time(props.finishedTime)}
</a>
</article>
${info}
</div>
<div class="column is-6">
<article class="panel is-info">
<p class="panel-heading">Capacity</p>
<a class="panel-block">
Allocated Memory: ${props.allocatedMB} MB
</a>
<a class="panel-block">
Allocated vCores: ${props.allocatedVCores}
</a>
<a class="panel-block">
Memory seconds: ${props.memorySeconds}
</a>
<a class="panel-block">
vCore seconds: ${props.vcoreSeconds}
</a>
<a class="panel-block">
Preempted VCores: ${props.preemptedResourceVCores}
</a>
<a class="panel-block">
Preempted Memory: ${props.preemptedResourceMB} MB
</a>
<a class="panel-block">
Preempted vCore Seconds: ${props.preemptedVcoreSeconds}
</a>
<a class="panel-block">
Preempted Memory Seconds: ${props.preemptedMemorySeconds}
</a>
<a class="panel-block">
Priority: ${props.priority}
</a>
</article>
${capacity}
</div>
</div>

Expand Down Expand Up @@ -104,15 +46,16 @@
</tr>
</thead>
<tbody>
<#list attempts as attempt>
<tr>
<td>${attempt.id}</td>
<td>${attempt.appAttemptState}</td>
<td>${attempt.containerId}</td>
<td>${time(attempt.startTime)}</td>
<td>${time(attempt.finishedTime)}</td>
</tr>
</#list>
${attempts}
<#-- <#list attempts as attempt>-->
<#-- <tr>-->
<#-- <td>${attempt.id}</td>-->
<#-- <td>${attempt.appAttemptState}</td>-->
<#-- <td>${attempt.containerId}</td>-->
<#-- <td>${time(attempt.startTime)}</td>-->
<#-- <td>${time(attempt.finishedTime)}</td>-->
<#-- </tr>-->
<#-- </#list>-->
</tbody>
</table>
</a>
Expand Down

0 comments on commit 07f75a6

Please sign in to comment.