Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. @CachePut(cacheNames = Constants.CACHE_NAME_ALL_COLLIBRA_ASSETS_BY_DOMAIN_ID_BACKUP, key = "#domainId")
  2. @HystrixCommand(fallbackMethod = "getAssetsFromBackup", commandKey = "getMetadataAssets", commandProperties = {
  3. @HystrixProperty(name = "execution.isolation.strategy", value = "SEMAPHORE")
  4. })
  5. public String getAssetsByDomain(String domainId) {
  6. String assets = null;
  7. try {
  8. Map<String, Object> queryParams = new HashMap<>();
  9. queryParams.put("domainId", domainId);
  10. queryParams.put("limit", Constants.COLLIBRA_GET_ALL_ASSETS_LIMIT);
  11. queryParams.put("offset", Constants.COLLIBRA_GET_ALL_ASSETS_OFFSET);
  12. ResponseEntity<String> response = collibraProxy.callCollibra(GET_ALL_ASSETS_ENDPOINT, HttpMethod.GET, null, queryParams);
  13. if (response.getStatusCode() == HttpStatus.OK) {
  14. assets = response.getBody();
  15. } else {
  16. throw new FGCollibException("Exception while getting OK response from Collibra: " + response.getStatusCode());
  17. }
  18. } catch (FGCollibException e) {
  19. logger.error("Error in getting assets from collibra for domainId {}", domainId, e);
  20. throw new FgException("Error getting response from collibra");
  21. }
  22. return assets;
  23. }
  24.  
  25. public String getAssetsFromBackup(String domainId) {
  26. try {
  27. logger.info("Executing fallback logic for collibra backup");
  28. CacheEntry entry = cacheService.get(Constants.CACHE_NAME_ALL_COLLIBRA_ASSETS_BY_DOMAIN_ID_BACKUP, domainId);
  29. if (entry != null) {
  30. return (String) entry.getV();
  31. }
  32. } catch (Exception e) {
  33. logger.error("Error in getting assets from collibra backup for domainId {}", domainId, e);
  34. }
  35. return null;
  36. }
  37.  
  38. private HystrixConcurrencyStrategy existingConcurrencyStrategy;
  39.  
  40. public SecurityContextConcurrencyStrategy(
  41. HystrixConcurrencyStrategy existingConcurrencyStrategy) {
  42. this.existingConcurrencyStrategy = existingConcurrencyStrategy;
  43. }
  44.  
  45. @Override
  46. public BlockingQueue<Runnable> getBlockingQueue(int maxQueueSize) {
  47. return existingConcurrencyStrategy != null
  48. ? existingConcurrencyStrategy.getBlockingQueue(maxQueueSize)
  49. : super.getBlockingQueue(maxQueueSize);
  50. }
  51.  
  52. @Override
  53. public <T> HystrixRequestVariable<T> getRequestVariable(
  54. HystrixRequestVariableLifecycle<T> rv) {
  55. return existingConcurrencyStrategy != null
  56. ? existingConcurrencyStrategy.getRequestVariable(rv)
  57. : super.getRequestVariable(rv);
  58. }
  59.  
  60. @Override
  61. public ThreadPoolExecutor getThreadPool(HystrixThreadPoolKey threadPoolKey,
  62. HystrixProperty<Integer> corePoolSize,
  63. HystrixProperty<Integer> maximumPoolSize,
  64. HystrixProperty<Integer> keepAliveTime, TimeUnit unit,
  65. BlockingQueue<Runnable> workQueue) {
  66. return existingConcurrencyStrategy != null
  67. ? existingConcurrencyStrategy.getThreadPool(threadPoolKey, corePoolSize,
  68. maximumPoolSize, keepAliveTime, unit, workQueue)
  69. : super.getThreadPool(threadPoolKey, corePoolSize, maximumPoolSize,
  70. keepAliveTime, unit, workQueue);
  71. }
  72.  
  73. @Override
  74. public <T> Callable<T> wrapCallable(Callable<T> callable) {
  75. return existingConcurrencyStrategy != null
  76. ? existingConcurrencyStrategy
  77. .wrapCallable(new DelegatingSecurityContextCallable<T>(callable))
  78. : super.wrapCallable(new DelegatingSecurityContextCallable<T>(callable));
  79. }
  80. }
  81.  
  82. @Configuration
  83. public class HystrixContextAutoConfiguration {
  84.  
  85. @Autowired(required = false)
  86. private List<HystrixCallableWrapper> wrappers = new ArrayList<>();
  87. @Autowired(required = false)
  88. private HystrixConcurrencyStrategy existingConcurrencyStrategy;
  89.  
  90. @PostConstruct
  91. public void init() {
  92. HystrixPlugins.reset();
  93. // Keeps references of existing Hystrix plugins.
  94. HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance()
  95. .getEventNotifier();
  96. HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance()
  97. .getMetricsPublisher();
  98. HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance()
  99. .getPropertiesStrategy();
  100. HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance()
  101. .getCommandExecutionHook();
  102.  
  103. HystrixPlugins.reset();
  104.  
  105. // Registers existing plugins excepts the Concurrent Strategy plugin.
  106. HystrixPlugins.getInstance().registerConcurrencyStrategy(
  107. new SecurityContextConcurrencyStrategy(existingConcurrencyStrategy));
  108. HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
  109. HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
  110. HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
  111. HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement