Skip to content

Commit

Permalink
Reload cached mappings after workspace changes (#1649)
Browse files Browse the repository at this point in the history
  • Loading branch information
EddeCCC authored Feb 8, 2024
1 parent abe3368 commit cfdf4e6
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import rocks.inspectit.ocelot.config.model.InspectitServerSettings;
import rocks.inspectit.ocelot.events.AgentMappingsSourceBranchChangedEvent;
import rocks.inspectit.ocelot.events.WorkspaceChangedEvent;
import rocks.inspectit.ocelot.file.FileManager;
import rocks.inspectit.ocelot.file.accessor.AbstractFileAccessor;
import rocks.inspectit.ocelot.file.accessor.git.RevisionAccess;
Expand Down Expand Up @@ -83,14 +85,24 @@ public void postConstruct() throws IOException {
}

/**
* Read cached agent mappings to avoid long ymlMapper-processing time
* Read cached agent mappings to avoid long ymlMapper-processing time.
*
* @return List of current {@link AgentMapping}s representing the content of the given file
*/
public List<AgentMapping> readCachedAgentMappings(){
if(currentMappings != null) return currentMappings;
else return readAgentMappings(fileManager.getWorkspaceRevision());
}

/**
* Reload cached agent mappings, if any external changes have been detected in the workspace.
*/
@EventListener(WorkspaceChangedEvent.class)
public synchronized void reloadCachedAgentMappings() {
log.info("Reloading cached agent mappings");
currentMappings = readAgentMappings(fileManager.getWorkspaceRevision());
}

/**
* Reading a list of {@link AgentMapping}s from a Yaml file.
*
Expand Down Expand Up @@ -125,7 +137,9 @@ public void writeAgentMappings(List<AgentMapping> agentMappings) throws IOExcept

/**
* Sets the source branch, from which the agent mappings file will be read
*
* @param sourceBranch new source branch
*
* @return the set source branch
*/
public Branch setSourceBranch(Branch sourceBranch) {
Expand Down

0 comments on commit cfdf4e6

Please sign in to comment.