Skip to content

Commit

Permalink
Karavan Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mgubaidullin committed Oct 24, 2024
1 parent 2382e1d commit 051d8dd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,17 @@ public CamelStatus getCamelStatus(String key) {
return camelStatuses.get(key);
}

public List<CamelStatus> getCamelStatusesByEnv(CamelStatusValue.Name name) {
public List<CamelStatus> getCamelStatusesByName(CamelStatusValue.Name name) {
return getCopyCamelStatuses().stream().peek(cs -> {
var values = cs.getStatuses();
cs.setStatuses(values.stream().filter(v -> Objects.equals(v.getName(), name)).toList());
}).toList();
}

public List<CamelStatus> getCamelAllStatuses() {
return getCopyCamelStatuses();
}

public List<CamelStatus> getCamelStatusesByProjectAndEnv(String projectId, String env) {
return getCopyCamelStatuses().stream().filter(el -> Objects.equals(el.getProjectId(), projectId) && Objects.equals(el.getEnv(), env)).toList();
}
Expand Down Expand Up @@ -328,11 +332,11 @@ public void deleteAllCamelStatuses() {
}

public List<PodContainerStatus> getLoadedDevModeStatuses() {
return getCopyPodContainerStatuses().stream().filter(el -> Objects.equals(el.getType(), PodContainerStatus.ContainerType.devmode) && Objects.equals(el.getCodeLoaded(), true)).toList();
return getCopyPodContainerStatuses().stream().filter(el -> Objects.equals(el.getType(), ContainerType.devmode) && Objects.equals(el.getCodeLoaded(), true)).toList();
}

public List<PodContainerStatus> getDevModeStatuses() {
return getCopyPodContainerStatuses().stream().filter(el -> Objects.equals(el.getType(), PodContainerStatus.ContainerType.devmode)).toList();
return getCopyPodContainerStatuses().stream().filter(el -> Objects.equals(el.getType(), ContainerType.devmode)).toList();
}

public List<PodContainerStatus> getContainerStatusByEnv(String env) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class KaravanEvents {
public static final String CMD_RELOAD_PROJECT_CODE = "CMD_RELOAD_PROJECT_CODE";
public static final String CMD_DELETE_CONTAINER = "CMD_DELETE_CONTAINER";

public static final String CMD_RESTART_INFORMERS = "CMD_RESTART_INFORMERS";

public static final String POD_CONTAINER_UPDATED = "POD_CONTAINER_UPDATED";
public static final String POD_CONTAINER_DELETED = "POD_CONTAINER_DELETED";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public void tryStart() throws Exception {
addKameletsProject();
addTemplatesProject();
addConfigurationProject();
addServicesProject();
}
ready.set(true);
} else {
Expand All @@ -128,6 +129,8 @@ private void importAllProjects() {
project = new Project(Project.Type.kamelets.name(), "Custom Kamelets", repo.getCommitId(), repo.getLastCommitTimestamp(), Project.Type.kamelets);
} else if (folderName.equals(Project.Type.configuration.name())) {
project = new Project(Project.Type.configuration.name(), "Configuration", repo.getCommitId(), repo.getLastCommitTimestamp(), Project.Type.configuration);
} else if (folderName.equals(Project.Type.services.name())) {
project = new Project(Project.Type.services.name(), "Dev Services", repo.getCommitId(), repo.getLastCommitTimestamp(), Project.Type.services);
} else {
project = projectService.getProjectFromRepo(repo);
}
Expand Down Expand Up @@ -209,4 +212,31 @@ void addConfigurationProject() {
LOGGER.error("Error during configuration project creation", e);
}
}

void addServicesProject() {
try {
Project services = karavanCache.getProject(Project.Type.services.name());
if (services == null) {
LOGGER.info("Add dev services project");
services = new Project(Project.Type.services.name(), "Dev services", "", Instant.now().toEpochMilli(), Project.Type.services);
karavanCache.saveProject(services, true);

codeService.getDevServicesFiles().forEach((name, value) -> {
ProjectFile file = new ProjectFile(name, value, Project.Type.services.name(), Instant.now().toEpochMilli());
karavanCache.saveProjectFile(file, false, true);
});
} else {
codeService.getDevServicesFiles().forEach((name, value) -> {
ProjectFile f = karavanCache.getProjectFile(Project.Type.services.name(), name);
if (f == null) {
LOGGER.info("Add new service " + name);
ProjectFile file = new ProjectFile(name, value, Project.Type.services.name(), Instant.now().toEpochMilli());
karavanCache.saveProjectFile(file, false, true);
}
});
}
} catch (Exception e) {
LOGGER.error("Error during services project creation", e);
}
}
}

0 comments on commit 051d8dd

Please sign in to comment.