Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.wellch4n.oops.application.dto;

import java.time.Instant;

public record ApplicationEventView(
Instant time,
String type,
String resourceKind,
String resourceName,
String reason,
String message,
Integer count
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.github.wellch4n.oops.domain.application.ApplicationRuntimeSpec;
import com.github.wellch4n.oops.domain.environment.Environment;
import com.github.wellch4n.oops.application.dto.ApplicationEventView;
import com.github.wellch4n.oops.application.dto.ApplicationPodStatusView;
import com.github.wellch4n.oops.application.dto.DeploymentHealth;
import java.time.Instant;
import java.util.List;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

Expand All @@ -17,6 +19,8 @@ void applyRuntimeSpec(Environment environment,

List<ApplicationPodStatusView> getPodStatuses(Environment environment, String namespace, String applicationName);

List<ApplicationEventView> getEvents(Environment environment, String namespace, String applicationName, Instant since, int limit);

SseEmitter watchPodStatuses(Environment environment, String namespace, String applicationName);

void restartPod(Environment environment, String namespace, String podName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
import com.github.wellch4n.oops.domain.shared.ApplicationSourceType;
import com.github.wellch4n.oops.domain.shared.UserRole;
import com.github.wellch4n.oops.shared.exception.BizException;
import com.github.wellch4n.oops.application.dto.ApplicationEventView;
import com.github.wellch4n.oops.application.dto.ApplicationPodStatusView;
import com.github.wellch4n.oops.application.dto.ApplicationResourceView;
import com.github.wellch4n.oops.application.dto.ApplicationDto;
import com.github.wellch4n.oops.application.dto.ApplicationConfigDto;
import com.github.wellch4n.oops.application.dto.ClusterDomainView;
import com.github.wellch4n.oops.application.dto.ServiceHostConflictView;
import com.github.wellch4n.oops.application.dto.Page;
import java.time.Instant;
import java.util.stream.Collectors;
import org.springframework.dao.DataIntegrityViolationException;
import java.util.Collections;
Expand All @@ -46,6 +48,8 @@
@Service
public class ApplicationService {

private static final String ENVIRONMENT_NOT_FOUND = "Environment not found: ";

private final ApplicationRepository applicationRepository;
private final EnvironmentRepository environmentRepository;
private final UserService userService;
Expand Down Expand Up @@ -426,7 +430,7 @@ private ApplicationExpertConfig defaultExpertConfig(String namespace, String nam
public List<ApplicationResourceView> getApplicationResources(String namespace, String name, String environmentName) {
Environment environment = environmentRepository.findFirstByName(environmentName);
if (environment == null) {
throw new IllegalArgumentException("Environment not found: " + environmentName);
throw new IllegalArgumentException(ENVIRONMENT_NOT_FOUND + environmentName);
}
return applicationExpertConfigGateway.getApplicationResources(environment, namespace, name);
}
Expand Down Expand Up @@ -506,31 +510,44 @@ public Boolean updateApplicationServiceConfig(String namespace, String name, App
public List<ApplicationPodStatusView> getApplicationStatus(String namespace, String name, String environmentName) {
Environment environment = environmentRepository.findFirstByName(environmentName);
if (environment == null) {
throw new IllegalArgumentException("Environment not found: " + environmentName);
throw new IllegalArgumentException(ENVIRONMENT_NOT_FOUND + environmentName);
}
return applicationRuntimeGateway.getPodStatuses(environment, namespace, name);
}

public List<ApplicationEventView> getApplicationEvents(String namespace,
String name,
String environmentName,
Instant since,
Integer limit) {
Environment environment = environmentRepository.findFirstByName(environmentName);
if (environment == null) {
throw new IllegalArgumentException(ENVIRONMENT_NOT_FOUND + environmentName);
}
int effectiveLimit = limit == null ? 200 : Math.max(1, Math.min(limit, 500));
return applicationRuntimeGateway.getEvents(environment, namespace, name, since, effectiveLimit);
}

public String getCurrentImage(String namespace, String name, String environmentName) {
Environment environment = environmentRepository.findFirstByName(environmentName);
if (environment == null) {
throw new IllegalArgumentException("Environment not found: " + environmentName);
throw new IllegalArgumentException(ENVIRONMENT_NOT_FOUND + environmentName);
}
return applicationRuntimeGateway.findCurrentImage(environment, namespace, name);
}

public SseEmitter watchApplicationStatus(String namespace, String name, String environmentName) {
Environment environment = environmentRepository.findFirstByName(environmentName);
if (environment == null) {
throw new IllegalArgumentException("Environment not found: " + environmentName);
throw new IllegalArgumentException(ENVIRONMENT_NOT_FOUND + environmentName);
}
return applicationRuntimeGateway.watchPodStatuses(environment, namespace, name);
}

public Boolean restartApplication(String namespace, String name, String podName, String environmentName) {
Environment environment = environmentRepository.findFirstByName(environmentName);
if (environment == null) {
throw new IllegalArgumentException("Environment not found: " + environmentName);
throw new IllegalArgumentException(ENVIRONMENT_NOT_FOUND + environmentName);
}
applicationRuntimeGateway.restartPod(environment, namespace, podName);
return true;
Expand All @@ -540,7 +557,7 @@ public ClusterDomainView getClusterDomain(String namespace, String name, String
try {
Environment environment = environmentRepository.findFirstByName(environmentName);
if (environment == null) {
throw new IllegalArgumentException("Environment not found: " + environmentName);
throw new IllegalArgumentException(ENVIRONMENT_NOT_FOUND + environmentName);
}

String internalDomain = applicationRuntimeGateway.findInternalServiceDomain(environment, namespace, name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
@Service
public class PodFileSystemService {

private static final String ENVIRONMENT_NOT_FOUND = "Environment not found: ";

private final EnvironmentRepository environmentRepository;
private final PodFileSystemGateway podFileSystemGateway;
private final PodFileSystemProperties podFileSystemProperties;
Expand All @@ -32,7 +34,7 @@ public PodFileSystemService(EnvironmentRepository environmentRepository,
public List<PodFileEntry> listDirectory(String environmentName, String namespace, String podName, String container, String path) {
Environment environment = environmentRepository.findFirstByName(environmentName);
if (environment == null) {
throw new BizException("Environment not found: " + environmentName);
throw new BizException(ENVIRONMENT_NOT_FOUND + environmentName);
}
return listDirectory(environment, namespace, podName, container, path);
}
Expand All @@ -44,7 +46,7 @@ public List<PodFileEntry> listDirectory(Environment environment, String namespac
public long getFileSize(String environmentName, String namespace, String podName, String container, String path) {
Environment environment = environmentRepository.findFirstByName(environmentName);
if (environment == null) {
throw new BizException("Environment not found: " + environmentName);
throw new BizException(ENVIRONMENT_NOT_FOUND + environmentName);
}
return getFileSize(environment, namespace, podName, container, path);
}
Expand All @@ -56,7 +58,7 @@ public long getFileSize(Environment environment, String namespace, String podNam
public void streamFile(String environmentName, String namespace, String podName, String container, String path, OutputStream outputStream) {
Environment environment = environmentRepository.findFirstByName(environmentName);
if (environment == null) {
throw new BizException("Environment not found: " + environmentName);
throw new BizException(ENVIRONMENT_NOT_FOUND + environmentName);
}
streamFile(environment, namespace, podName, container, path, outputStream);
}
Expand All @@ -68,7 +70,7 @@ public void streamFile(Environment environment, String namespace, String podName
public void uploadFile(String environmentName, String namespace, String podName, String container, String path, InputStream inputStream) {
Environment environment = environmentRepository.findFirstByName(environmentName);
if (environment == null) {
throw new BizException("Environment not found: " + environmentName);
throw new BizException(ENVIRONMENT_NOT_FOUND + environmentName);
}
uploadFile(environment, namespace, podName, container, path, inputStream);
}
Expand All @@ -84,7 +86,7 @@ public void deletePath(Environment environment, String namespace, String podName
public void deletePath(String environmentName, String namespace, String podName, String container, String path) {
Environment environment = environmentRepository.findFirstByName(environmentName);
if (environment == null) {
throw new BizException("Environment not found: " + environmentName);
throw new BizException(ENVIRONMENT_NOT_FOUND + environmentName);
}
deletePath(environment, namespace, podName, container, path);
}
Expand All @@ -96,7 +98,7 @@ public void renamePath(Environment environment, String namespace, String podName
public void renamePath(String environmentName, String namespace, String podName, String container, String fromPath, String toPath) {
Environment environment = environmentRepository.findFirstByName(environmentName);
if (environment == null) {
throw new BizException("Environment not found: " + environmentName);
throw new BizException(ENVIRONMENT_NOT_FOUND + environmentName);
}
renamePath(environment, namespace, podName, container, fromPath, toPath);
}
Expand All @@ -108,7 +110,7 @@ public void createDirectory(Environment environment, String namespace, String po
public void createDirectory(String environmentName, String namespace, String podName, String container, String path) {
Environment environment = environmentRepository.findFirstByName(environmentName);
if (environment == null) {
throw new BizException("Environment not found: " + environmentName);
throw new BizException(ENVIRONMENT_NOT_FOUND + environmentName);
}
createDirectory(environment, namespace, podName, container, path);
}
Expand Down
Loading
Loading