feat: add deployment entity, repository, and status enums
This commit is contained in:
@@ -0,0 +1,88 @@
|
|||||||
|
package net.siegeln.cameleer.saas.deployment;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.JdbcTypeCode;
|
||||||
|
import org.hibernate.type.SqlTypes;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "deployments")
|
||||||
|
public class DeploymentEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.UUID)
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
@Column(name = "app_id", nullable = false)
|
||||||
|
private UUID appId;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private int version;
|
||||||
|
|
||||||
|
@Column(name = "image_ref", nullable = false, length = 500)
|
||||||
|
private String imageRef;
|
||||||
|
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
@Column(name = "desired_status", nullable = false, length = 20)
|
||||||
|
private DesiredStatus desiredStatus = DesiredStatus.RUNNING;
|
||||||
|
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
@Column(name = "observed_status", nullable = false, length = 20)
|
||||||
|
private ObservedStatus observedStatus = ObservedStatus.BUILDING;
|
||||||
|
|
||||||
|
@JdbcTypeCode(SqlTypes.JSON)
|
||||||
|
@Column(name = "orchestrator_metadata")
|
||||||
|
private Map<String, Object> orchestratorMetadata = Map.of();
|
||||||
|
|
||||||
|
@Column(name = "error_message", columnDefinition = "TEXT")
|
||||||
|
private String errorMessage;
|
||||||
|
|
||||||
|
@Column(name = "deployed_at")
|
||||||
|
private Instant deployedAt;
|
||||||
|
|
||||||
|
@Column(name = "stopped_at")
|
||||||
|
private Instant stoppedAt;
|
||||||
|
|
||||||
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private Instant createdAt;
|
||||||
|
|
||||||
|
@PrePersist
|
||||||
|
protected void onCreate() {
|
||||||
|
createdAt = Instant.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getId() { return id; }
|
||||||
|
public void setId(UUID id) { this.id = id; }
|
||||||
|
|
||||||
|
public UUID getAppId() { return appId; }
|
||||||
|
public void setAppId(UUID appId) { this.appId = appId; }
|
||||||
|
|
||||||
|
public int getVersion() { return version; }
|
||||||
|
public void setVersion(int version) { this.version = version; }
|
||||||
|
|
||||||
|
public String getImageRef() { return imageRef; }
|
||||||
|
public void setImageRef(String imageRef) { this.imageRef = imageRef; }
|
||||||
|
|
||||||
|
public DesiredStatus getDesiredStatus() { return desiredStatus; }
|
||||||
|
public void setDesiredStatus(DesiredStatus desiredStatus) { this.desiredStatus = desiredStatus; }
|
||||||
|
|
||||||
|
public ObservedStatus getObservedStatus() { return observedStatus; }
|
||||||
|
public void setObservedStatus(ObservedStatus observedStatus) { this.observedStatus = observedStatus; }
|
||||||
|
|
||||||
|
public Map<String, Object> getOrchestratorMetadata() { return orchestratorMetadata; }
|
||||||
|
public void setOrchestratorMetadata(Map<String, Object> orchestratorMetadata) { this.orchestratorMetadata = orchestratorMetadata; }
|
||||||
|
|
||||||
|
public String getErrorMessage() { return errorMessage; }
|
||||||
|
public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; }
|
||||||
|
|
||||||
|
public Instant getDeployedAt() { return deployedAt; }
|
||||||
|
public void setDeployedAt(Instant deployedAt) { this.deployedAt = deployedAt; }
|
||||||
|
|
||||||
|
public Instant getStoppedAt() { return stoppedAt; }
|
||||||
|
public void setStoppedAt(Instant stoppedAt) { this.stoppedAt = stoppedAt; }
|
||||||
|
|
||||||
|
public Instant getCreatedAt() { return createdAt; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package net.siegeln.cameleer.saas.deployment;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface DeploymentRepository extends JpaRepository<DeploymentEntity, UUID> {
|
||||||
|
List<DeploymentEntity> findByAppIdOrderByVersionDesc(UUID appId);
|
||||||
|
|
||||||
|
@Query("SELECT COALESCE(MAX(d.version), 0) FROM DeploymentEntity d WHERE d.appId = :appId")
|
||||||
|
int findMaxVersionByAppId(UUID appId);
|
||||||
|
|
||||||
|
Optional<DeploymentEntity> findByAppIdAndVersion(UUID appId, int version);
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package net.siegeln.cameleer.saas.deployment;
|
||||||
|
|
||||||
|
public enum DesiredStatus {
|
||||||
|
RUNNING, STOPPED
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package net.siegeln.cameleer.saas.deployment;
|
||||||
|
|
||||||
|
public enum ObservedStatus {
|
||||||
|
BUILDING, STARTING, RUNNING, FAILED, STOPPED
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user