This is an automated email from the ASF dual-hosted git repository. marat pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-karavan.git
commit 1be80ca42f98f3ff0c3093b45683aeac3873f21f Author: Marat Gubaidullin <ma...@talismancloud.io> AuthorDate: Thu Oct 24 09:00:02 2024 -0400 Project Improvements --- .../camel/karavan/api/ProjectFileResource.java | 24 +++++- .../apache/camel/karavan/api/ProjectResource.java | 6 +- .../org/apache/camel/karavan/model/Project.java | 1 + .../apache/camel/karavan/model/ProjectCommit.java | 90 ++++++++++++++++++++++ .../camel/karavan/model/ProjectFileCommitDiff.java | 52 +++++++++++++ .../camel/karavan/service/ProjectService.java | 16 ++-- 6 files changed, 179 insertions(+), 10 deletions(-) diff --git a/karavan-app/src/main/java/org/apache/camel/karavan/api/ProjectFileResource.java b/karavan-app/src/main/java/org/apache/camel/karavan/api/ProjectFileResource.java index f8310f08..fc5bdf42 100644 --- a/karavan-app/src/main/java/org/apache/camel/karavan/api/ProjectFileResource.java +++ b/karavan-app/src/main/java/org/apache/camel/karavan/api/ProjectFileResource.java @@ -16,6 +16,7 @@ */ package org.apache.camel.karavan.api; +import io.vertx.core.json.JsonObject; import jakarta.inject.Inject; import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; @@ -86,8 +87,8 @@ public class ProjectFileResource { @Produces(MediaType.APPLICATION_JSON) @Path("/templates/beans") public List<ProjectFile> getBeanTemplates() throws Exception { - return codeService.getBeanTemplateNames().stream() - .map(s -> karavanCache.getProjectFile(Project.Type.templates.name(), s)) + return karavanCache.getProjectFiles(Project.Type.templates.name()).stream() + .filter(file -> file.getName().endsWith(CodeService.BEAN_TEMPLATE_SUFFIX_FILENAME)) .toList(); } @@ -125,4 +126,23 @@ public class ProjectFileResource { false ); } + + @POST + @Produces(MediaType.APPLICATION_JSON) + @Path("/copy/{project}") + public Response copy(@PathParam("project") String project, JsonObject copy) throws Exception { + var projectId = URLDecoder.decode(project, StandardCharsets.UTF_8); + var from = copy.getString("from"); + var to = copy.getString("to"); + var tofile = karavanCache.getProjectFile(projectId, to); + if (tofile == null) { + var file = karavanCache.getProjectFile(projectId, from); + var copyFile = file.copy(); + copyFile.setName(to); + karavanCache.saveProjectFile(copyFile, false, false); + return Response.ok().build(); + } else { + return Response.notModified().build(); + } + } } \ No newline at end of file diff --git a/karavan-app/src/main/java/org/apache/camel/karavan/api/ProjectResource.java b/karavan-app/src/main/java/org/apache/camel/karavan/api/ProjectResource.java index dfba7c04..4f2babaa 100644 --- a/karavan-app/src/main/java/org/apache/camel/karavan/api/ProjectResource.java +++ b/karavan-app/src/main/java/org/apache/camel/karavan/api/ProjectResource.java @@ -27,7 +27,7 @@ import org.apache.camel.karavan.docker.DockerService; import org.apache.camel.karavan.kubernetes.KubernetesService; import org.apache.camel.karavan.model.CamelStatus; import org.apache.camel.karavan.model.CamelStatusValue; -import org.apache.camel.karavan.model.PodContainerStatus; +import org.apache.camel.karavan.model.ContainerType; import org.apache.camel.karavan.model.Project; import org.apache.camel.karavan.service.ConfigService; import org.apache.camel.karavan.service.GitService; @@ -99,8 +99,8 @@ public class ProjectResource extends AbstractApiResource { if (deleteContainers) { LOGGER.info("Deleting containers"); Response res1 = devModeResource.deleteDevMode(projectId, true); - Response res2 = containerResource.deleteContainer(projectId, PodContainerStatus.ContainerType.devmode.name(), projectId); - Response res3 = containerResource.deleteContainer(projectId, PodContainerStatus.ContainerType.project.name(), projectId); + Response res2 = containerResource.deleteContainer(projectId, ContainerType.devmode.name(), projectId); + Response res3 = containerResource.deleteContainer(projectId, ContainerType.project.name(), projectId); LOGGER.info("Deleting deployments"); Response res4 = infrastructureResource.deleteDeployment(null, projectId); } diff --git a/karavan-app/src/main/java/org/apache/camel/karavan/model/Project.java b/karavan-app/src/main/java/org/apache/camel/karavan/model/Project.java index 3821a0c5..2bfb815b 100644 --- a/karavan-app/src/main/java/org/apache/camel/karavan/model/Project.java +++ b/karavan-app/src/main/java/org/apache/camel/karavan/model/Project.java @@ -28,6 +28,7 @@ public class Project { templates, kamelets, configuration, + services, normal, } diff --git a/karavan-app/src/main/java/org/apache/camel/karavan/model/ProjectCommit.java b/karavan-app/src/main/java/org/apache/camel/karavan/model/ProjectCommit.java new file mode 100644 index 00000000..44278009 --- /dev/null +++ b/karavan-app/src/main/java/org/apache/camel/karavan/model/ProjectCommit.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.karavan.model; + +import java.util.ArrayList; +import java.util.List; + +public class ProjectCommit { + private String id; + private String projectId; + private String authorName; + private String authorEmail; + private String message; + private List<ProjectFileCommitDiff> diffs = new ArrayList<>(); + + public ProjectCommit() { + } + + public ProjectCommit(String id, String projectId, String authorName, String authorEmail, String message, List<ProjectFileCommitDiff> diffs) { + this.id = id; + this.projectId = projectId; + this.authorName = authorName; + this.authorEmail = authorEmail; + this.message = message; + this.diffs = diffs; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getProjectId() { + return projectId; + } + + public void setProjectId(String projectId) { + this.projectId = projectId; + } + + public String getAuthorName() { + return authorName; + } + + public void setAuthorName(String authorName) { + this.authorName = authorName; + } + + public String getAuthorEmail() { + return authorEmail; + } + + public void setAuthorEmail(String authorEmail) { + this.authorEmail = authorEmail; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public List<ProjectFileCommitDiff> getDiffs() { + return diffs; + } + + public void setDiffs(List<ProjectFileCommitDiff> diffs) { + this.diffs = diffs; + } +} diff --git a/karavan-app/src/main/java/org/apache/camel/karavan/model/ProjectFileCommitDiff.java b/karavan-app/src/main/java/org/apache/camel/karavan/model/ProjectFileCommitDiff.java new file mode 100644 index 00000000..38c118ca --- /dev/null +++ b/karavan-app/src/main/java/org/apache/camel/karavan/model/ProjectFileCommitDiff.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.karavan.model; + +public class ProjectFileCommitDiff { + private String changeType; + private String newPath; + private String oldPath; + private String diff; + + + public ProjectFileCommitDiff() { + } + + public ProjectFileCommitDiff(String changeType, String newPath, String oldPath, String diff) { + this.changeType = changeType; + this.newPath = newPath; + this.oldPath = oldPath; + this.diff = diff; + } + + public String getChangeType() { + return changeType; + } + + public String getNewPath() { + return newPath; + } + + public String getOldPath() { + return oldPath; + } + + public String getDiff() { + return diff; + } +} diff --git a/karavan-app/src/main/java/org/apache/camel/karavan/service/ProjectService.java b/karavan-app/src/main/java/org/apache/camel/karavan/service/ProjectService.java index b3fa8e0d..25c07faa 100644 --- a/karavan-app/src/main/java/org/apache/camel/karavan/service/ProjectService.java +++ b/karavan-app/src/main/java/org/apache/camel/karavan/service/ProjectService.java @@ -93,7 +93,7 @@ public class ProjectService { } } - public String runProjectWithJBangOptions(Project project, String jBangOptions) throws Exception { + public String runProjectWithJBangOptions(Project project, String jBangOptions, Map<String, String> labels, Map<String, String> envVars) throws Exception { String containerName = project.getProjectId(); PodContainerStatus status = karavanCache.getDevModePodContainerStatus(project.getProjectId(), environment); if (status == null) { @@ -107,10 +107,10 @@ public class ProjectService { String projectDevmodeImage = codeService.getProjectDevModeImage(project.getProjectId()); if (ConfigService.inKubernetes()) { String deploymentFragment = codeService.getDeploymentFragment(project.getProjectId()); - kubernetesService.runDevModeContainer(project, jBangOptions, files, projectDevmodeImage, deploymentFragment); + kubernetesService.runDevModeContainer(project, jBangOptions, files, projectDevmodeImage, deploymentFragment, labels, envVars); } else { DockerComposeService compose = getProjectDockerComposeService(project.getProjectId()); - dockerForKaravan.runProjectInDevMode(project.getProjectId(), jBangOptions, compose, files, projectDevmodeImage); + dockerForKaravan.runProjectInDevMode(project.getProjectId(), jBangOptions, compose, files, projectDevmodeImage, labels, envVars); } return containerName; } else { @@ -180,12 +180,18 @@ public class ProjectService { } } - public String getDevServiceCode() { - List<ProjectFile> files = karavanCache.getProjectFiles(Project.Type.configuration.name()); + public String getDockerDevServiceCode() { + List<ProjectFile> files = karavanCache.getProjectFiles(Project.Type.services.name()); Optional<ProjectFile> file = files.stream().filter(f -> f.getName().equals(DEV_SERVICES_FILENAME)).findFirst(); return file.orElse(new ProjectFile()).getCode(); } + public String getKubernetesDevServiceCode(String name) { + List<ProjectFile> files = karavanCache.getProjectFiles(Project.Type.services.name()); + Optional<ProjectFile> file = files.stream().filter(f -> f.getName().equals(name + ".yaml")).findFirst(); + return file.orElse(new ProjectFile()).getCode(); + } + public DockerComposeService getProjectDockerComposeService(String projectId) { String composeTemplate = codeService.getDockerComposeFileForProject(projectId); String composeCode = codeService.replaceEnvWithRuntimeProperties(composeTemplate);