|
1 | | -/* |
2 | | - * Copyright 2018 The Feast Authors |
3 | | - * |
4 | | - * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | - * you may not use this file except in compliance with the License. |
6 | | - * You may obtain a copy of the License at |
7 | | - * |
8 | | - * https://www.apache.org/licenses/LICENSE-2.0 |
9 | | - * |
10 | | - * Unless required by applicable law or agreed to in writing, software |
11 | | - * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | - * See the License for the specific language governing permissions and |
14 | | - * limitations under the License. |
15 | | - * |
16 | | - */ |
17 | | - |
18 | | -package feast.serving.config; |
19 | | - |
20 | | -import com.google.common.util.concurrent.ListeningExecutorService; |
21 | | -import com.google.common.util.concurrent.MoreExecutors; |
22 | | -import feast.core.StoreProto.Store; |
23 | | -import feast.serving.service.spec.CachedSpecService; |
24 | | -import feast.serving.service.spec.CoreSpecService; |
25 | | -import feast.serving.service.serving.ServingService; |
26 | | -import feast.serving.service.serving.RedisServingService; |
27 | | -import feast.serving.service.spec.SpecService; |
28 | | -import io.opentracing.Tracer; |
29 | | -import io.opentracing.contrib.concurrent.TracedExecutorService; |
30 | | -import java.util.List; |
31 | | -import java.util.concurrent.ExecutorService; |
32 | | -import java.util.concurrent.Executors; |
33 | | -import java.util.concurrent.ScheduledExecutorService; |
34 | | -import java.util.concurrent.TimeUnit; |
35 | | -import lombok.extern.slf4j.Slf4j; |
36 | | -import org.springframework.beans.factory.annotation.Autowired; |
37 | | -import org.springframework.beans.factory.annotation.Value; |
38 | | -import org.springframework.context.annotation.Bean; |
39 | | -import org.springframework.context.annotation.Configuration; |
40 | | -import org.springframework.http.converter.HttpMessageConverter; |
41 | | -import org.springframework.http.converter.protobuf.ProtobufJsonFormatHttpMessageConverter; |
42 | | -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
43 | | -import redis.clients.jedis.JedisPool; |
44 | | -import redis.clients.jedis.JedisPoolConfig; |
45 | | - |
46 | | -/** |
47 | | - * Global bean configuration. |
48 | | - */ |
49 | | -@Slf4j |
50 | | -@Configuration |
51 | | -public class ServingApiConfiguration implements WebMvcConfigurer { |
52 | | - |
53 | | - @Autowired |
54 | | - private ProtobufJsonFormatHttpMessageConverter protobufConverter; |
55 | | - |
56 | | - private ScheduledExecutorService scheduledExecutorService = |
57 | | - Executors.newSingleThreadScheduledExecutor(); |
58 | | - |
59 | | - @Bean |
60 | | - public AppConfig getAppConfig( |
61 | | - @Value("${feast.redispool.maxsize}") int redisPoolMaxSize, |
62 | | - @Value("${feast.redispool.maxidle}") int redisPoolMaxIdle, |
63 | | - @Value("${feast.maxentity}") int maxEntityPerBatch, |
64 | | - @Value("${feast.timeout}") int timeout) { |
65 | | - return AppConfig.builder() |
66 | | - .maxEntityPerBatch(maxEntityPerBatch) |
67 | | - .redisMaxPoolSize(redisPoolMaxSize) |
68 | | - .redisMaxIdleSize(redisPoolMaxIdle) |
69 | | - .timeout(timeout) |
70 | | - .build(); |
71 | | - } |
72 | | - |
73 | | - @Bean |
74 | | - public SpecService getCoreServiceSpecStorage( |
75 | | - @Value("${feast.store.id}") String storeId, |
76 | | - @Value("${feast.core.host}") String coreServiceHost, |
77 | | - @Value("${feast.core.grpc.port}") String coreServicePort, |
78 | | - @Value("${feast.cacheDurationMinute}") int cacheDurationMinute) { |
79 | | - final CachedSpecService cachedSpecStorage = |
80 | | - new CachedSpecService(new CoreSpecService(coreServiceHost, Integer.parseInt(coreServicePort)), |
81 | | - storeId); |
82 | | - |
83 | | - // reload all specs including new ones periodically |
84 | | - scheduledExecutorService.schedule( |
85 | | - cachedSpecStorage::populateCache, cacheDurationMinute, TimeUnit.MINUTES); |
86 | | - |
87 | | - // load all specs during start up |
88 | | - try { |
89 | | - cachedSpecStorage.populateCache(); |
90 | | - } catch (Exception e) { |
91 | | - log.error("Unable to preload feast's spec"); |
92 | | - } |
93 | | - return cachedSpecStorage; |
94 | | - } |
95 | | - |
96 | | - @Bean |
97 | | - public ServingService getFeastServing( |
98 | | - @Value("${feast.store.id}") String storeId, |
99 | | - @Value("${feast.core.host}") String coreServiceHost, |
100 | | - @Value("${feast.core.grpc.port}") String coreServicePort, |
101 | | - AppConfig appConfig, |
102 | | - Tracer tracer) { |
103 | | - CoreSpecService coreSpecService = new CoreSpecService(coreServiceHost, Integer.parseInt(coreServicePort)); |
104 | | - Store store = coreSpecService.getStoreDetails(storeId); |
105 | | - |
106 | | - switch (store.getType()) { |
107 | | - case REDIS: |
108 | | - JedisPoolConfig poolConfig = new JedisPoolConfig(); |
109 | | - poolConfig.setMaxTotal(appConfig.getRedisMaxPoolSize()); |
110 | | - poolConfig.setMaxIdle(appConfig.getRedisMaxIdleSize()); |
111 | | - JedisPool jedisPool = new JedisPool(poolConfig, store.getRedisConfig().getHost(), |
112 | | - store.getRedisConfig().getPort()); |
113 | | - return new RedisServingService(jedisPool, tracer); |
114 | | - case BIGQUERY: |
115 | | - // TODO: Implement connection to BigQuery |
116 | | - return null; |
117 | | - default: |
118 | | - return null; |
119 | | - } |
120 | | - } |
121 | | - |
122 | | - @Bean |
123 | | - public ListeningExecutorService getExecutorService( |
124 | | - Tracer tracer, @Value("${feast.threadpool.max}") int maxPoolSize) { |
125 | | - |
126 | | - ExecutorService executor = Executors.newFixedThreadPool(maxPoolSize); |
127 | | - return MoreExecutors.listeningDecorator(new TracedExecutorService(executor, tracer)); |
128 | | - } |
129 | | - |
130 | | - @Bean |
131 | | - ProtobufJsonFormatHttpMessageConverter protobufHttpMessageConverter() { |
132 | | - return new ProtobufJsonFormatHttpMessageConverter(); |
133 | | - } |
134 | | - |
135 | | - @Override |
136 | | - public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { |
137 | | - converters.add(protobufConverter); |
138 | | - } |
139 | | -} |
| 1 | +// /* |
| 2 | +// * Copyright 2018 The Feast Authors |
| 3 | +// * |
| 4 | +// * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// * you may not use this file except in compliance with the License. |
| 6 | +// * You may obtain a copy of the License at |
| 7 | +// * |
| 8 | +// * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// * |
| 10 | +// * Unless required by applicable law or agreed to in writing, software |
| 11 | +// * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// * See the License for the specific language governing permissions and |
| 14 | +// * limitations under the License. |
| 15 | +// * |
| 16 | +// */ |
| 17 | +// |
| 18 | +// package feast.serving.config; |
| 19 | +// |
| 20 | +// import com.google.common.util.concurrent.ListeningExecutorService; |
| 21 | +// import com.google.common.util.concurrent.MoreExecutors; |
| 22 | +// import feast.serving.service.spec.CachedSpecService; |
| 23 | +// import feast.serving.service.spec.CoreSpecService; |
| 24 | +// import feast.serving.service.spec.SpecService; |
| 25 | +// import io.opentracing.Tracer; |
| 26 | +// import io.opentracing.contrib.concurrent.TracedExecutorService; |
| 27 | +// import java.util.List; |
| 28 | +// import java.util.concurrent.ExecutorService; |
| 29 | +// import java.util.concurrent.Executors; |
| 30 | +// import java.util.concurrent.ScheduledExecutorService; |
| 31 | +// import java.util.concurrent.TimeUnit; |
| 32 | +// import lombok.extern.slf4j.Slf4j; |
| 33 | +// import org.springframework.beans.factory.annotation.Value; |
| 34 | +// import org.springframework.context.annotation.Bean; |
| 35 | +// import org.springframework.context.annotation.Configuration; |
| 36 | +// import org.springframework.http.converter.HttpMessageConverter; |
| 37 | +// import org.springframework.http.converter.protobuf.ProtobufJsonFormatHttpMessageConverter; |
| 38 | +// import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
| 39 | +// |
| 40 | +// // Global bean configuration. |
| 41 | +// @Slf4j |
| 42 | +// @Configuration |
| 43 | +// public class ServingApiConfiguration implements WebMvcConfigurer { |
| 44 | +// private final ProtobufJsonFormatHttpMessageConverter protobufConverter; |
| 45 | +// // private ScheduledExecutorService scheduledExecutorService = |
| 46 | +// // Executors.newSingleThreadScheduledExecutor(); |
| 47 | +// |
| 48 | +// public ServingApiConfiguration(ProtobufJsonFormatHttpMessageConverter protobufConverter) { |
| 49 | +// this.protobufConverter = protobufConverter; |
| 50 | +// } |
| 51 | +// |
| 52 | +// @Bean |
| 53 | +// public AppConfig getAppConfig( |
| 54 | +// @Value("${feast.redispool.maxsize}") int redisPoolMaxSize, |
| 55 | +// @Value("${feast.redispool.maxidle}") int redisPoolMaxIdle, |
| 56 | +// @Value("${feast.maxentity}") int maxEntityPerBatch, |
| 57 | +// @Value("${feast.timeout}") int timeout) { |
| 58 | +// return AppConfig.builder() |
| 59 | +// .maxEntityPerBatch(maxEntityPerBatch) |
| 60 | +// .redisMaxPoolSize(redisPoolMaxSize) |
| 61 | +// .redisMaxIdleSize(redisPoolMaxIdle) |
| 62 | +// .timeout(timeout) |
| 63 | +// .build(); |
| 64 | +// } |
| 65 | +// |
| 66 | +// @Bean |
| 67 | +// public SpecService getCoreServiceSpecStorage( |
| 68 | +// @Value("${feast.store.id}") String storeId, |
| 69 | +// @Value("${feast.core.host}") String coreServiceHost, |
| 70 | +// @Value("${feast.core.grpc.port}") String coreServicePort, |
| 71 | +// @Value("${feast.cacheDurationMinute}") int cacheDurationMinute) { |
| 72 | +// final CachedSpecService cachedSpecStorage = |
| 73 | +// new CachedSpecService( |
| 74 | +// new CoreSpecService(coreServiceHost, Integer.parseInt(coreServicePort)), storeId); |
| 75 | +// |
| 76 | +// // reload all specs including new ones periodically |
| 77 | +// // scheduledExecutorService.schedule( |
| 78 | +// // cachedSpecStorage::populateCache, cacheDurationMinute, TimeUnit.MINUTES); |
| 79 | +// |
| 80 | +// // load all specs during start up |
| 81 | +// try { |
| 82 | +// cachedSpecStorage.populateCache(); |
| 83 | +// } catch (Exception e) { |
| 84 | +// log.error("Unable to preload feast's spec"); |
| 85 | +// } |
| 86 | +// return cachedSpecStorage; |
| 87 | +// } |
| 88 | +// |
| 89 | +// // @Bean |
| 90 | +// // public ServingService getFeastServing( |
| 91 | +// // @Value("${feast.store.id}") String storeId, |
| 92 | +// // @Value("${feast.core.host}") String coreServiceHost, |
| 93 | +// // @Value("${feast.core.grpc.port}") String coreServicePort, |
| 94 | +// // AppConfig appConfig, |
| 95 | +// // Tracer tracer) { |
| 96 | +// // CoreSpecService coreSpecService = new CoreSpecService(coreServiceHost, |
| 97 | +// // Integer.parseInt(coreServicePort)); |
| 98 | +// // Store store = coreSpecService.getStoreDetails(storeId); |
| 99 | +// // |
| 100 | +// // switch (store.getType()) { |
| 101 | +// // case REDIS: |
| 102 | +// // JedisPoolConfig poolConfig = new JedisPoolConfig(); |
| 103 | +// // poolConfig.setMaxTotal(appConfig.getRedisMaxPoolSize()); |
| 104 | +// // poolConfig.setMaxIdle(appConfig.getRedisMaxIdleSize()); |
| 105 | +// // JedisPool jedisPool = new JedisPool(poolConfig, store.getRedisConfig().getHost(), |
| 106 | +// // store.getRedisConfig().getPort()); |
| 107 | +// // return new RedisServingService(jedisPool, tracer); |
| 108 | +// // case BIGQUERY: |
| 109 | +// // // TODO: Implement connection to BigQuery |
| 110 | +// // return null; |
| 111 | +// // default: |
| 112 | +// // return null; |
| 113 | +// // } |
| 114 | +// // } |
| 115 | +// |
| 116 | +// @Bean |
| 117 | +// public ListeningExecutorService getExecutorService( |
| 118 | +// Tracer tracer, @Value("${feast.threadpool.max}") int maxPoolSize) { |
| 119 | +// |
| 120 | +// ExecutorService executor = Executors.newFixedThreadPool(maxPoolSize); |
| 121 | +// return MoreExecutors.listeningDecorator(new TracedExecutorService(executor, tracer)); |
| 122 | +// } |
| 123 | +// |
| 124 | +// @Bean |
| 125 | +// ProtobufJsonFormatHttpMessageConverter protobufHttpMessageConverter() { |
| 126 | +// return new ProtobufJsonFormatHttpMessageConverter(); |
| 127 | +// } |
| 128 | +// |
| 129 | +// @Override |
| 130 | +// public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { |
| 131 | +// converters.add(protobufConverter); |
| 132 | +// } |
| 133 | +// } |
0 commit comments