diff --git a/applications/backlog-server/src/main/java/io/pivotal/pal/tracker/backlog/App.java b/applications/backlog-server/src/main/java/io/pivotal/pal/tracker/backlog/App.java index f44ff6e..5cf0cc1 100644 --- a/applications/backlog-server/src/main/java/io/pivotal/pal/tracker/backlog/App.java +++ b/applications/backlog-server/src/main/java/io/pivotal/pal/tracker/backlog/App.java @@ -7,6 +7,8 @@ import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; @@ -31,8 +33,21 @@ public static void main(String[] args) { @Bean ProjectClient projectClient( RestOperations restOperations, - @Value("${registration.server.endpoint}") String registrationEndpoint + @Value("${registration.server.endpoint}") String registrationEndpoint, ProjectInfoRedisRepository redisRepository ) { - return new ProjectClient(restOperations, registrationEndpoint); + return new ProjectClient(restOperations, registrationEndpoint, redisRepository); } + +// @Bean +// JedisConnectionFactory jedisConnectionFactory() { +// return new JedisConnectionFactory(); +// } +// +// @Bean +// public RedisTemplate redisTemplate() { +// RedisTemplate template = new RedisTemplate<>(); +// template.setConnectionFactory(jedisConnectionFactory()); +// return template; +// } + } diff --git a/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectClient.java b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectClient.java index f0f9736..9884ca8 100644 --- a/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectClient.java +++ b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectClient.java @@ -3,7 +3,6 @@ import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import org.springframework.web.client.RestOperations; - import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -13,24 +12,22 @@ public class ProjectClient { private final String endpoint; private ConcurrentMap projectInfoCache = new ConcurrentHashMap<>(); -// private Jedis jedis = new Jedis(); - - + private ProjectInfoRedisRepository redisRepository; - public ProjectClient(RestOperations restOperations, String registrationServerEndpoint) { + public ProjectClient(RestOperations restOperations, String registrationServerEndpoint, ProjectInfoRedisRepository redisRepository) { this.restOperations = restOperations; this.endpoint = registrationServerEndpoint; + this.redisRepository = redisRepository; } @HystrixCommand(fallbackMethod = "getProjectFromCache") public ProjectInfo getProject(long projectId) { ProjectInfo projectInfo = restOperations.getForObject(endpoint + "/projects/" + projectId, ProjectInfo.class); -// jedis.set(String.valueOf(projectId), projectInfo); -// projectInfoCache.put(); + redisRepository.save(projectInfo); return projectInfo; } public ProjectInfo getProjectFromCache(long projectId) { - return projectInfoCache.get(projectId); + return redisRepository.findById(projectId).get(); } } diff --git a/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectInfo.java b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectInfo.java index a937e4e..1754779 100644 --- a/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectInfo.java +++ b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectInfo.java @@ -1,11 +1,17 @@ package io.pivotal.pal.tracker.backlog; +import org.springframework.data.annotation.Id; +import org.springframework.data.redis.core.RedisHash; + import java.io.Serializable; +@RedisHash("ProjectInfo") public class ProjectInfo implements Serializable { private static final long serialVersionUID = -8243145428016231L; + @Id + private Long id; public final boolean active; private ProjectInfo() { @@ -38,4 +44,12 @@ public String toString() { "active=" + active + '}'; } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } } diff --git a/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectInfoRedisRepository.java b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectInfoRedisRepository.java index f537bdb..a0a846a 100644 --- a/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectInfoRedisRepository.java +++ b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectInfoRedisRepository.java @@ -1,4 +1,8 @@ package io.pivotal.pal.tracker.backlog; -public class ProjectInfoRedisRepository { +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ProjectInfoRedisRepository extends CrudRepository { } diff --git a/manifest-backlog.yml b/manifest-backlog.yml index b93c014..cac7091 100644 --- a/manifest-backlog.yml +++ b/manifest-backlog.yml @@ -15,3 +15,4 @@ applications: - tracker-service-registry - tracker-circuit-breaker-dashboard - tracker-sso + - redisCache