Skip to content

Commit

Permalink
include versioning to AgentMappingController
Browse files Browse the repository at this point in the history
  • Loading branch information
EddeCCC committed Oct 31, 2023
1 parent 8118390 commit c0b50c8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import rocks.inspectit.ocelot.file.FileManager;
import rocks.inspectit.ocelot.file.accessor.git.RevisionAccess;
import rocks.inspectit.ocelot.file.versioning.Branch;
import rocks.inspectit.ocelot.mappings.model.AgentMapping;

Expand Down Expand Up @@ -93,13 +92,26 @@ public synchronized void setSourceBranch(String sourceBranch) {
}

/**
* Returns an unmodifiable representation of the current agent mappings list.
* The method returns the agent mappings from the workspace branch to always show the current changes.
* Returns an unmodifiable representation of the agent mappings list.
*
* @param version The id of the version, which should be listed.
* If it is empty, the latest workspace version is used.
* Can be 'live' fir listing the latest live version.
*
* @return A list of {@link AgentMapping}
*/
public synchronized List<AgentMapping> getAgentMappings(String version) {
if (version == null) {
return serializer.readAgentMappings(fileManager.getWorkspaceRevision());
} else if (version.equals("live")) {
return serializer.readAgentMappings(fileManager.getLiveRevision());
} else {
return serializer.readAgentMappings(fileManager.getCommitWithId(version));
}
}

public synchronized List<AgentMapping> getAgentMappings() {
return serializer.readAgentMappings(fileManager.getWorkspaceRevision());
return getAgentMappings(null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import com.google.common.annotations.VisibleForTesting;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class DirectoryController extends FileBaseController {
@Operation(summary = "List directory contents", description = "Can be used to get a list of the contents of a given directory. In addition, the branch can be specified which will be used as basis for the listing.")
@Parameter(name = "Path", description = "The part of the url after /directories/ define the path to the directory whose contents shall be read.")
@GetMapping(value = "directories/**")
public Collection<FileInfo> listContents(@Parameter(description = "The id of the version which should be listed. If it is empty, the lastest workspace version is used. Can be 'live' fir listing the latest live version.") @RequestParam(value = "version", required = false) String commitId, HttpServletRequest request) {
public Collection<FileInfo> listContents(@Parameter(description = "The id of the version which should be listed. If it is empty, the latest workspace version is used. Can be 'live' for listing the latest live version.") @RequestParam(value = "version", required = false) String commitId, HttpServletRequest request) {
String path = RequestUtil.getRequestSubPath(request);

if (commitId == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package rocks.inspectit.ocelot.rest.mappings;

import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import rocks.inspectit.ocelot.file.versioning.Branch;
import rocks.inspectit.ocelot.mappings.AgentMappingManager;
import rocks.inspectit.ocelot.mappings.model.AgentMapping;
import rocks.inspectit.ocelot.rest.AbstractBaseController;
Expand All @@ -22,8 +22,6 @@
import java.util.stream.Collectors;

import static com.google.common.base.Preconditions.checkArgument;
import static rocks.inspectit.ocelot.file.versioning.Branch.LIVE;
import static rocks.inspectit.ocelot.file.versioning.Branch.WORKSPACE;

/**
* Controller for managing the agent mappings.
Expand All @@ -44,8 +42,9 @@ public class AgentMappingController extends AbstractBaseController {
* @return List of {@link AgentMapping}s.
*/
@GetMapping(value = "mappings")
public List<AgentMapping> getMappings() {
return mappingManager.getAgentMappings();
public List<AgentMapping> getMappings(@Parameter(description = "The id of the version which should be listed. If it is empty, the lastest workspace version is used. Can be 'live' for listing the latest live version.") @RequestParam(value = "version", required = false) String commitId) {
List<AgentMapping> agentMappings = mappingManager.getAgentMappings(commitId);
return agentMappings;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public class GetMappings {
@Test
public void successfullyGetAgentMappings() {
List<AgentMapping> dummyList = new ArrayList<>();
when(mappingManager.getAgentMappings()).thenReturn(dummyList);
when(mappingManager.getAgentMappings(any())).thenReturn(dummyList);

List<AgentMapping> result = controller.getMappings();
List<AgentMapping> result = controller.getMappings(null);

verify(mappingManager).getAgentMappings();
verify(mappingManager).getAgentMappings(null);
verifyNoMoreInteractions(mappingManager);
assertThat(result).isSameAs(dummyList);
}
Expand Down Expand Up @@ -164,4 +164,4 @@ public void addMappingAfter() throws IOException {
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
}
}
}
}

0 comments on commit c0b50c8

Please sign in to comment.