Skip to content

Commit

Permalink
Update plugin-api to 4.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
fdaugan committed Jan 7, 2024
1 parent bc62873 commit 2d24259
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 40 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.ligoj.api</groupId>
<artifactId>plugin-parent</artifactId>
<version>4.1.1</version>
<version>4.1.3</version>
<relativePath />
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ public interface VmExecutionRepository extends RestRepository<VmExecution, Integ
* @param node The node identifier to filter.
* @return The schedules linked to the related node or sub-node.
*/
@Query("SELECT ve FROM VmExecution ve INNER JOIN FETCH ve.subscription AS s "
+ "INNER JOIN s.node AS n WHERE (n.id = :node OR n.id LIKE CONCAT(:node, ':%'))"
+ " AND ve.id = (SELECT MAX(CAST(ve.id as Integer)) FROM VmExecution v WHERE v.subscription = s)")
@Query("""
FROM VmExecution ve INNER JOIN FETCH ve.subscription AS s
INNER JOIN s.node AS n WHERE (n.id = :node OR n.id LIKE CONCAT(:node, ':%'))
AND ve.id = (SELECT MAX(CAST(v.id as Integer)) FROM VmExecution v WHERE v.subscription = s GROUP BY v.subscription)
""")
List<VmExecution> findAllByNodeLast(String node);

/**
* Return all executions related to given subscription and ordered from the most to the least recent date.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,20 @@
*/
package org.ligoj.app.plugin.vm.execution;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.text.ParseException;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import jakarta.transaction.Transactional;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

import org.apache.commons.lang3.StringUtils;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.FastDateFormat;
import org.ligoj.app.dao.SubscriptionRepository;
import org.ligoj.app.model.Subscription;
import org.ligoj.app.plugin.vm.VmResource;
import org.ligoj.app.plugin.vm.dao.VmExecutionRepository;
import org.ligoj.app.plugin.vm.dao.VmExecutionStatusRepository;
import org.ligoj.app.plugin.vm.dao.VmScheduleRepository;
import org.ligoj.app.plugin.vm.model.VmExecution;
import org.ligoj.app.plugin.vm.model.VmExecutionStatus;
import org.ligoj.app.plugin.vm.model.VmOperation;
import org.ligoj.app.plugin.vm.model.VmSchedule;
import org.ligoj.app.plugin.vm.model.VmStatus;
import org.ligoj.app.plugin.vm.model.*;
import org.ligoj.app.resource.ServicePluginLocator;
import org.ligoj.app.resource.plugin.AbstractToolPluginResource;
import org.ligoj.app.resource.subscription.LongTaskRunnerSubscription;
Expand All @@ -50,8 +27,12 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import java.io.*;
import java.text.ParseException;
import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/**
* VM Execution task runner.
Expand Down Expand Up @@ -233,7 +214,7 @@ public Response downloadNodeSchedulesReport(@PathParam("node") final String node
final var schedules = vmScheduleRepository.findAllByNode(node, securityHelper.getLogin());

// Get all last execution related to given node, Key is the subscription identifier
final Map<Integer, VmExecution> lastExecutions = vmExecutionRepository.findAllByNodeLast(node).stream()
final var lastExecutions = vmExecutionRepository.findAllByNodeLast(node).stream()
.collect(Collectors.toMap(e -> e.getSubscription().getId(), Function.identity()));

// Get all last executions of all schedules
Expand All @@ -244,11 +225,11 @@ public Response downloadNodeSchedulesReport(@PathParam("node") final String node
* Write all executions related to given subscription, from the oldest to the newest.
*/
private void writeHistory(final OutputStream output, Collection<VmExecution> executions) throws IOException {
final Writer writer = new BufferedWriter(new OutputStreamWriter(output, "cp1252"));
final var writer = new BufferedWriter(new OutputStreamWriter(output, "cp1252"));
final var df = FastDateFormat.getInstance("yyyy/MM/dd HH:mm:ss");
writer.write(COMMON_CSV_HEADER
+ ";dateHMS;timestamp;previousState;operation;vm;trigger;succeed;statusText;errorText");
for (final VmExecution execution : executions) {
for (final var execution : executions) {
writeCommon(writer, execution.getSubscription());
writeExecutionStatus(writer, execution, df);
}
Expand All @@ -262,7 +243,7 @@ private void writeHistory(final OutputStream output, Collection<VmExecution> exe
*/
private void writeSchedules(final OutputStream output, Collection<VmSchedule> schedules,
final Map<Integer, VmExecution> lastExecutions) throws IOException {
final Writer writer = new BufferedWriter(new OutputStreamWriter(output, "cp1252"));
final var writer = new BufferedWriter(new OutputStreamWriter(output, "cp1252"));
final var df = FastDateFormat.getInstance("yyyy/MM/dd HH:mm:ss");
final var now = DateUtils.newCalendar().getTime();
writer.write(COMMON_CSV_HEADER
Expand Down Expand Up @@ -319,15 +300,15 @@ private void writeExecutionStatus(final Writer writer, final VmExecution executi
writer.write(';');
writer.write(execution.getOperation().name());
writer.write(';');
writer.write(StringUtils.defaultString(execution.getVm(), ""));
writer.write(Objects.toString(execution.getVm(), ""));
writer.write(';');
writer.write(execution.getTrigger());
writer.write(';');
writer.write(String.valueOf(execution.isSucceed()));
writer.write(';');
writer.write(StringUtils.defaultString(execution.getStatusText(), ""));
writer.write(Objects.toString(execution.getStatusText(), ""));
writer.write(';');
writer.write(StringUtils.defaultString(execution.getError(), ""));
writer.write(Objects.toString(execution.getError(), ""));
}

/**
Expand Down

0 comments on commit 2d24259

Please sign in to comment.