Loading src/main/java/org/etsi/osl/metrico/model/Job.java +24 −13 Original line number Diff line number Diff line package org.etsi.osl.metrico.model; import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; import org.etsi.osl.tmf.pm628.model.ExecutionStateType; import org.hibernate.annotations.GenericGenerator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; Loading @@ -12,26 +15,33 @@ import java.util.concurrent.*; @Getter @Setter @Entity @Table(name = "MetJob") public class Job{ private Long id; @Id @GeneratedValue(generator = "UUID") @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator") private UUID uuid; private ExecutionStateType state; @JsonIgnore private boolean deleted = false; private final Runnable task; @Transient private final Runnable task = new Runnable() { @Override public void run() { } }; @Transient private ScheduledFuture<?> future; public Job(Runnable task) { this.task = task; public Job() { this.state = ExecutionStateType.PENDING; } Loading @@ -40,6 +50,8 @@ public class Job { private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); private static final Map<UUID, Job> jobs = new ConcurrentHashMap<>(); /** * Schedules a new job to be executed periodically. * <p> Loading @@ -57,10 +69,9 @@ public class Job { * @throws RejectedExecutionException if the task cannot be scheduled for execution */ public Job startJob(Runnable task, long initialDelay, long periodicDelay) { UUID jobId = UUID.randomUUID(); Job job = new Job(task); job.setUuid(jobId); Job job = new Job(); job.setState(ExecutionStateType.PENDING); UUID jobId = job.getUuid(); try { ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(task, initialDelay, periodicDelay, TimeUnit.SECONDS); job.setFuture(future); Loading src/main/java/org/etsi/osl/metrico/model/MonitoringJob.java 0 → 100644 +34 −0 Original line number Diff line number Diff line package org.etsi.osl.metrico.model; import jakarta.persistence.Entity; import lombok.Getter; import lombok.Setter; import org.springframework.format.annotation.DateTimeFormat; import java.time.OffsetDateTime; @Setter @Getter @Entity public class MonitoringJob extends Job{ @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) private OffsetDateTime startDateTime; @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) private OffsetDateTime endDateTime; private Integer executionInterval; public MonitoringJob(){ executionInterval = 10; } public MonitoringJob(OffsetDateTime startDateTime, OffsetDateTime endDateTime){ this.startDateTime = startDateTime; this.endDateTime = endDateTime; this.executionInterval = 10; } } Loading
src/main/java/org/etsi/osl/metrico/model/Job.java +24 −13 Original line number Diff line number Diff line package org.etsi.osl.metrico.model; import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; import org.etsi.osl.tmf.pm628.model.ExecutionStateType; import org.hibernate.annotations.GenericGenerator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; Loading @@ -12,26 +15,33 @@ import java.util.concurrent.*; @Getter @Setter @Entity @Table(name = "MetJob") public class Job{ private Long id; @Id @GeneratedValue(generator = "UUID") @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator") private UUID uuid; private ExecutionStateType state; @JsonIgnore private boolean deleted = false; private final Runnable task; @Transient private final Runnable task = new Runnable() { @Override public void run() { } }; @Transient private ScheduledFuture<?> future; public Job(Runnable task) { this.task = task; public Job() { this.state = ExecutionStateType.PENDING; } Loading @@ -40,6 +50,8 @@ public class Job { private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); private static final Map<UUID, Job> jobs = new ConcurrentHashMap<>(); /** * Schedules a new job to be executed periodically. * <p> Loading @@ -57,10 +69,9 @@ public class Job { * @throws RejectedExecutionException if the task cannot be scheduled for execution */ public Job startJob(Runnable task, long initialDelay, long periodicDelay) { UUID jobId = UUID.randomUUID(); Job job = new Job(task); job.setUuid(jobId); Job job = new Job(); job.setState(ExecutionStateType.PENDING); UUID jobId = job.getUuid(); try { ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(task, initialDelay, periodicDelay, TimeUnit.SECONDS); job.setFuture(future); Loading
src/main/java/org/etsi/osl/metrico/model/MonitoringJob.java 0 → 100644 +34 −0 Original line number Diff line number Diff line package org.etsi.osl.metrico.model; import jakarta.persistence.Entity; import lombok.Getter; import lombok.Setter; import org.springframework.format.annotation.DateTimeFormat; import java.time.OffsetDateTime; @Setter @Getter @Entity public class MonitoringJob extends Job{ @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) private OffsetDateTime startDateTime; @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) private OffsetDateTime endDateTime; private Integer executionInterval; public MonitoringJob(){ executionInterval = 10; } public MonitoringJob(OffsetDateTime startDateTime, OffsetDateTime endDateTime){ this.startDateTime = startDateTime; this.endDateTime = endDateTime; this.executionInterval = 10; } }