Commit 05dfb120 authored by George Tziavas's avatar George Tziavas
Browse files

added model for mon job

parent f65cbfcc
Loading
Loading
Loading
Loading
+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;

@@ -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;
    }

@@ -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>
@@ -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);
+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;
    }

}