Commit 6f9ac66863000dab25eb22b9e418e7b6147c6850
Committed by
Andrew Shvayka
1 parent
289d3b93
Refactoring: Introduced Edge License service. Remove web dependency from dao
Showing
7 changed files
with
143 additions
and
96 deletions
@@ -27,6 +27,7 @@ import org.springframework.http.MediaType; | @@ -27,6 +27,7 @@ import org.springframework.http.MediaType; | ||
27 | import org.springframework.security.core.Authentication; | 27 | import org.springframework.security.core.Authentication; |
28 | import org.springframework.security.core.context.SecurityContextHolder; | 28 | import org.springframework.security.core.context.SecurityContextHolder; |
29 | import org.springframework.web.bind.annotation.ExceptionHandler; | 29 | import org.springframework.web.bind.annotation.ExceptionHandler; |
30 | +import org.thingsboard.server.cluster.TbClusterService; | ||
30 | import org.thingsboard.server.common.data.Customer; | 31 | import org.thingsboard.server.common.data.Customer; |
31 | import org.thingsboard.server.common.data.Dashboard; | 32 | import org.thingsboard.server.common.data.Dashboard; |
32 | import org.thingsboard.server.common.data.DashboardInfo; | 33 | import org.thingsboard.server.common.data.DashboardInfo; |
@@ -122,12 +123,12 @@ import org.thingsboard.server.queue.provider.TbQueueProducerProvider; | @@ -122,12 +123,12 @@ import org.thingsboard.server.queue.provider.TbQueueProducerProvider; | ||
122 | import org.thingsboard.server.queue.util.TbCoreComponent; | 123 | import org.thingsboard.server.queue.util.TbCoreComponent; |
123 | import org.thingsboard.server.service.action.RuleEngineEntityActionService; | 124 | import org.thingsboard.server.service.action.RuleEngineEntityActionService; |
124 | import org.thingsboard.server.service.component.ComponentDiscoveryService; | 125 | import org.thingsboard.server.service.component.ComponentDiscoveryService; |
126 | +import org.thingsboard.server.service.edge.EdgeLicenseService; | ||
125 | import org.thingsboard.server.service.edge.EdgeNotificationService; | 127 | import org.thingsboard.server.service.edge.EdgeNotificationService; |
126 | import org.thingsboard.server.service.edge.rpc.EdgeRpcService; | 128 | import org.thingsboard.server.service.edge.rpc.EdgeRpcService; |
127 | import org.thingsboard.server.service.lwm2m.LwM2MServerSecurityInfoRepository; | 129 | import org.thingsboard.server.service.lwm2m.LwM2MServerSecurityInfoRepository; |
128 | import org.thingsboard.server.service.ota.OtaPackageStateService; | 130 | import org.thingsboard.server.service.ota.OtaPackageStateService; |
129 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; | 131 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; |
130 | -import org.thingsboard.server.cluster.TbClusterService; | ||
131 | import org.thingsboard.server.service.resource.TbResourceService; | 132 | import org.thingsboard.server.service.resource.TbResourceService; |
132 | import org.thingsboard.server.service.security.model.SecurityUser; | 133 | import org.thingsboard.server.service.security.model.SecurityUser; |
133 | import org.thingsboard.server.service.security.permission.AccessControlService; | 134 | import org.thingsboard.server.service.security.permission.AccessControlService; |
@@ -274,6 +275,9 @@ public abstract class BaseController { | @@ -274,6 +275,9 @@ public abstract class BaseController { | ||
274 | @Autowired(required = false) | 275 | @Autowired(required = false) |
275 | protected EdgeRpcService edgeGrpcService; | 276 | protected EdgeRpcService edgeGrpcService; |
276 | 277 | ||
278 | + @Autowired(required = false) | ||
279 | + protected EdgeLicenseService edgeLicenseService; | ||
280 | + | ||
277 | @Autowired | 281 | @Autowired |
278 | protected RuleEngineEntityActionService ruleEngineEntityActionService; | 282 | protected RuleEngineEntityActionService ruleEngineEntityActionService; |
279 | 283 |
@@ -572,7 +572,7 @@ public class EdgeController extends BaseController { | @@ -572,7 +572,7 @@ public class EdgeController extends BaseController { | ||
572 | public ResponseEntity<JsonNode> checkInstance(@RequestBody JsonNode request) throws ThingsboardException { | 572 | public ResponseEntity<JsonNode> checkInstance(@RequestBody JsonNode request) throws ThingsboardException { |
573 | log.debug("Checking instance [{}]", request); | 573 | log.debug("Checking instance [{}]", request); |
574 | try { | 574 | try { |
575 | - return edgeService.checkInstance(request); | 575 | + return edgeLicenseService.checkInstance(request); |
576 | } catch (Exception e) { | 576 | } catch (Exception e) { |
577 | log.error("Error occurred: [{}]", e.getMessage(), e); | 577 | log.error("Error occurred: [{}]", e.getMessage(), e); |
578 | throw new ThingsboardException(e, ThingsboardErrorCode.SUBSCRIPTION_VIOLATION); | 578 | throw new ThingsboardException(e, ThingsboardErrorCode.SUBSCRIPTION_VIOLATION); |
@@ -585,7 +585,7 @@ public class EdgeController extends BaseController { | @@ -585,7 +585,7 @@ public class EdgeController extends BaseController { | ||
585 | @RequestParam String releaseDate) throws ThingsboardException { | 585 | @RequestParam String releaseDate) throws ThingsboardException { |
586 | log.debug("Activating instance [{}], [{}]", licenseSecret, releaseDate); | 586 | log.debug("Activating instance [{}], [{}]", licenseSecret, releaseDate); |
587 | try { | 587 | try { |
588 | - return edgeService.activateInstance(licenseSecret, releaseDate); | 588 | + return edgeLicenseService.activateInstance(licenseSecret, releaseDate); |
589 | } catch (Exception e) { | 589 | } catch (Exception e) { |
590 | log.error("Error occurred: [{}]", e.getMessage(), e); | 590 | log.error("Error occurred: [{}]", e.getMessage(), e); |
591 | throw new ThingsboardException(e, ThingsboardErrorCode.SUBSCRIPTION_VIOLATION); | 591 | throw new ThingsboardException(e, ThingsboardErrorCode.SUBSCRIPTION_VIOLATION); |
application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeLicenseService.java
0 → 100644
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard 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 | + * http://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 | +package org.thingsboard.server.service.edge; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.JsonNode; | ||
19 | +import lombok.extern.slf4j.Slf4j; | ||
20 | +import org.apache.http.HttpHost; | ||
21 | +import org.apache.http.conn.ssl.DefaultHostnameVerifier; | ||
22 | +import org.apache.http.impl.client.CloseableHttpClient; | ||
23 | +import org.apache.http.impl.client.HttpClients; | ||
24 | +import org.springframework.beans.factory.annotation.Value; | ||
25 | +import org.springframework.http.ResponseEntity; | ||
26 | +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; | ||
27 | +import org.springframework.http.client.SimpleClientHttpRequestFactory; | ||
28 | +import org.springframework.stereotype.Service; | ||
29 | +import org.springframework.web.client.RestTemplate; | ||
30 | +import org.thingsboard.server.queue.util.TbCoreComponent; | ||
31 | + | ||
32 | +import javax.annotation.PostConstruct; | ||
33 | +import java.net.InetSocketAddress; | ||
34 | +import java.net.Proxy; | ||
35 | +import java.util.HashMap; | ||
36 | +import java.util.Map; | ||
37 | + | ||
38 | +import static org.apache.commons.lang3.StringUtils.isNotEmpty; | ||
39 | + | ||
40 | +@Service | ||
41 | +@TbCoreComponent | ||
42 | +@Slf4j | ||
43 | +public class DefaultEdgeLicenseService implements EdgeLicenseService { | ||
44 | + | ||
45 | + private RestTemplate restTemplate; | ||
46 | + | ||
47 | + private static final String EDGE_LICENSE_SERVER_ENDPOINT = "https://license.thingsboard.io"; | ||
48 | + | ||
49 | + @Value("${edges.enabled:false}") | ||
50 | + private boolean edgesEnabled; | ||
51 | + | ||
52 | + @PostConstruct | ||
53 | + public void init() { | ||
54 | + if (edgesEnabled) { | ||
55 | + initRestTemplate(); | ||
56 | + } | ||
57 | + } | ||
58 | + | ||
59 | + @Override | ||
60 | + public ResponseEntity<JsonNode> checkInstance(JsonNode request) { | ||
61 | + return this.restTemplate.postForEntity(EDGE_LICENSE_SERVER_ENDPOINT + "/api/license/checkInstance", request, JsonNode.class); | ||
62 | + } | ||
63 | + | ||
64 | + @Override | ||
65 | + public ResponseEntity<JsonNode> activateInstance(String edgeLicenseSecret, String releaseDate) { | ||
66 | + Map<String, String> params = new HashMap<>(); | ||
67 | + params.put("licenseSecret", edgeLicenseSecret); | ||
68 | + params.put("releaseDate", releaseDate); | ||
69 | + return this.restTemplate.postForEntity(EDGE_LICENSE_SERVER_ENDPOINT + "/api/license/activateInstance?licenseSecret={licenseSecret}&releaseDate={releaseDate}", null, JsonNode.class, params); | ||
70 | + } | ||
71 | + | ||
72 | + private void initRestTemplate() { | ||
73 | + boolean jdkHttpClientEnabled = isNotEmpty(System.getProperty("tb.proxy.jdk")) && System.getProperty("tb.proxy.jdk").equalsIgnoreCase("true"); | ||
74 | + boolean systemProxyEnabled = isNotEmpty(System.getProperty("tb.proxy.system")) && System.getProperty("tb.proxy.system").equalsIgnoreCase("true"); | ||
75 | + boolean proxyEnabled = isNotEmpty(System.getProperty("tb.proxy.host")) && isNotEmpty(System.getProperty("tb.proxy.port")); | ||
76 | + if (jdkHttpClientEnabled) { | ||
77 | + log.warn("Going to use plain JDK Http Client!"); | ||
78 | + SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); | ||
79 | + if (proxyEnabled) { | ||
80 | + log.warn("Going to use Proxy Server: [{}:{}]", System.getProperty("tb.proxy.host"), System.getProperty("tb.proxy.port")); | ||
81 | + factory.setProxy(new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(System.getProperty("tb.proxy.host"), Integer.parseInt(System.getProperty("tb.proxy.port"))))); | ||
82 | + } | ||
83 | + | ||
84 | + this.restTemplate = new RestTemplate(new SimpleClientHttpRequestFactory()); | ||
85 | + } else { | ||
86 | + CloseableHttpClient httpClient; | ||
87 | + HttpComponentsClientHttpRequestFactory requestFactory; | ||
88 | + if (systemProxyEnabled) { | ||
89 | + log.warn("Going to use System Proxy Server!"); | ||
90 | + httpClient = HttpClients.createSystem(); | ||
91 | + requestFactory = new HttpComponentsClientHttpRequestFactory(); | ||
92 | + requestFactory.setHttpClient(httpClient); | ||
93 | + this.restTemplate = new RestTemplate(requestFactory); | ||
94 | + } else if (proxyEnabled) { | ||
95 | + log.warn("Going to use Proxy Server: [{}:{}]", System.getProperty("tb.proxy.host"), System.getProperty("tb.proxy.port")); | ||
96 | + httpClient = HttpClients.custom().setSSLHostnameVerifier(new DefaultHostnameVerifier()).setProxy(new HttpHost(System.getProperty("tb.proxy.host"), Integer.parseInt(System.getProperty("tb.proxy.port")), "https")).build(); | ||
97 | + requestFactory = new HttpComponentsClientHttpRequestFactory(); | ||
98 | + requestFactory.setHttpClient(httpClient); | ||
99 | + this.restTemplate = new RestTemplate(requestFactory); | ||
100 | + } else { | ||
101 | + httpClient = HttpClients.custom().setSSLHostnameVerifier(new DefaultHostnameVerifier()).build(); | ||
102 | + requestFactory = new HttpComponentsClientHttpRequestFactory(); | ||
103 | + requestFactory.setHttpClient(httpClient); | ||
104 | + this.restTemplate = new RestTemplate(requestFactory); | ||
105 | + } | ||
106 | + } | ||
107 | + } | ||
108 | +} | ||
109 | + | ||
110 | + |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard 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 | + * http://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 | +package org.thingsboard.server.service.edge; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.JsonNode; | ||
19 | +import org.springframework.http.ResponseEntity; | ||
20 | + | ||
21 | +public interface EdgeLicenseService { | ||
22 | + | ||
23 | + ResponseEntity<JsonNode> checkInstance(JsonNode request); | ||
24 | + | ||
25 | + ResponseEntity<JsonNode> activateInstance(String licenseSecret, String releaseDate); | ||
26 | +} |
@@ -82,11 +82,6 @@ | @@ -82,11 +82,6 @@ | ||
82 | <scope>provided</scope> | 82 | <scope>provided</scope> |
83 | </dependency> | 83 | </dependency> |
84 | <dependency> | 84 | <dependency> |
85 | - <groupId>org.springframework</groupId> | ||
86 | - <artifactId>spring-web</artifactId> | ||
87 | - <scope>provided</scope> | ||
88 | - </dependency> | ||
89 | - <dependency> | ||
90 | <groupId>com.datastax.oss</groupId> | 85 | <groupId>com.datastax.oss</groupId> |
91 | <artifactId>java-driver-core</artifactId> | 86 | <artifactId>java-driver-core</artifactId> |
92 | <scope>provided</scope> | 87 | <scope>provided</scope> |
@@ -15,9 +15,7 @@ | @@ -15,9 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.edge; | 16 | package org.thingsboard.server.dao.edge; |
17 | 17 | ||
18 | -import com.fasterxml.jackson.databind.JsonNode; | ||
19 | import com.google.common.util.concurrent.ListenableFuture; | 18 | import com.google.common.util.concurrent.ListenableFuture; |
20 | -import org.springframework.http.ResponseEntity; | ||
21 | import org.thingsboard.server.common.data.EntitySubtype; | 19 | import org.thingsboard.server.common.data.EntitySubtype; |
22 | import org.thingsboard.server.common.data.edge.Edge; | 20 | import org.thingsboard.server.common.data.edge.Edge; |
23 | import org.thingsboard.server.common.data.edge.EdgeInfo; | 21 | import org.thingsboard.server.common.data.edge.EdgeInfo; |
@@ -86,9 +84,5 @@ public interface EdgeService { | @@ -86,9 +84,5 @@ public interface EdgeService { | ||
86 | 84 | ||
87 | PageData<EdgeId> findRelatedEdgeIdsByEntityId(TenantId tenantId, EntityId entityId, PageLink pageLink); | 85 | PageData<EdgeId> findRelatedEdgeIdsByEntityId(TenantId tenantId, EntityId entityId, PageLink pageLink); |
88 | 86 | ||
89 | - ResponseEntity<JsonNode> checkInstance(JsonNode request); | ||
90 | - | ||
91 | - ResponseEntity<JsonNode> activateInstance(String licenseSecret, String releaseDate); | ||
92 | - | ||
93 | String findMissingToRelatedRuleChains(TenantId tenantId, EdgeId edgeId); | 87 | String findMissingToRelatedRuleChains(TenantId tenantId, EdgeId edgeId); |
94 | } | 88 | } |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.edge; | 16 | package org.thingsboard.server.dao.edge; |
17 | 17 | ||
18 | -import com.fasterxml.jackson.databind.JsonNode; | ||
19 | import com.fasterxml.jackson.databind.ObjectMapper; | 18 | import com.fasterxml.jackson.databind.ObjectMapper; |
20 | import com.fasterxml.jackson.databind.node.ArrayNode; | 19 | import com.fasterxml.jackson.databind.node.ArrayNode; |
21 | import com.fasterxml.jackson.databind.node.ObjectNode; | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
@@ -24,23 +23,14 @@ import com.google.common.util.concurrent.Futures; | @@ -24,23 +23,14 @@ import com.google.common.util.concurrent.Futures; | ||
24 | import com.google.common.util.concurrent.ListenableFuture; | 23 | import com.google.common.util.concurrent.ListenableFuture; |
25 | import com.google.common.util.concurrent.MoreExecutors; | 24 | import com.google.common.util.concurrent.MoreExecutors; |
26 | import lombok.extern.slf4j.Slf4j; | 25 | import lombok.extern.slf4j.Slf4j; |
27 | -import org.apache.http.HttpHost; | ||
28 | -import org.apache.http.conn.ssl.DefaultHostnameVerifier; | ||
29 | -import org.apache.http.impl.client.CloseableHttpClient; | ||
30 | -import org.apache.http.impl.client.HttpClients; | ||
31 | import org.hibernate.exception.ConstraintViolationException; | 26 | import org.hibernate.exception.ConstraintViolationException; |
32 | import org.springframework.beans.factory.annotation.Autowired; | 27 | import org.springframework.beans.factory.annotation.Autowired; |
33 | -import org.springframework.beans.factory.annotation.Value; | ||
34 | import org.springframework.cache.Cache; | 28 | import org.springframework.cache.Cache; |
35 | import org.springframework.cache.CacheManager; | 29 | import org.springframework.cache.CacheManager; |
36 | import org.springframework.cache.annotation.CacheEvict; | 30 | import org.springframework.cache.annotation.CacheEvict; |
37 | import org.springframework.cache.annotation.Cacheable; | 31 | import org.springframework.cache.annotation.Cacheable; |
38 | -import org.springframework.http.ResponseEntity; | ||
39 | -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; | ||
40 | -import org.springframework.http.client.SimpleClientHttpRequestFactory; | ||
41 | import org.springframework.stereotype.Service; | 32 | import org.springframework.stereotype.Service; |
42 | import org.springframework.util.StringUtils; | 33 | import org.springframework.util.StringUtils; |
43 | -import org.springframework.web.client.RestTemplate; | ||
44 | import org.thingsboard.server.common.data.Customer; | 34 | import org.thingsboard.server.common.data.Customer; |
45 | import org.thingsboard.server.common.data.EntitySubtype; | 35 | import org.thingsboard.server.common.data.EntitySubtype; |
46 | import org.thingsboard.server.common.data.EntityType; | 36 | import org.thingsboard.server.common.data.EntityType; |
@@ -74,20 +64,14 @@ import org.thingsboard.server.dao.tenant.TenantDao; | @@ -74,20 +64,14 @@ import org.thingsboard.server.dao.tenant.TenantDao; | ||
74 | import org.thingsboard.server.dao.user.UserService; | 64 | import org.thingsboard.server.dao.user.UserService; |
75 | 65 | ||
76 | import javax.annotation.Nullable; | 66 | import javax.annotation.Nullable; |
77 | -import javax.annotation.PostConstruct; | ||
78 | -import java.net.InetSocketAddress; | ||
79 | -import java.net.Proxy; | ||
80 | import java.util.ArrayList; | 67 | import java.util.ArrayList; |
81 | import java.util.Arrays; | 68 | import java.util.Arrays; |
82 | import java.util.Collections; | 69 | import java.util.Collections; |
83 | import java.util.Comparator; | 70 | import java.util.Comparator; |
84 | -import java.util.HashMap; | ||
85 | import java.util.List; | 71 | import java.util.List; |
86 | -import java.util.Map; | ||
87 | import java.util.Optional; | 72 | import java.util.Optional; |
88 | import java.util.stream.Collectors; | 73 | import java.util.stream.Collectors; |
89 | 74 | ||
90 | -import static org.apache.commons.lang3.StringUtils.isNotEmpty; | ||
91 | import static org.thingsboard.server.common.data.CacheConstants.EDGE_CACHE; | 75 | import static org.thingsboard.server.common.data.CacheConstants.EDGE_CACHE; |
92 | import static org.thingsboard.server.dao.DaoUtil.toUUIDs; | 76 | import static org.thingsboard.server.dao.DaoUtil.toUUIDs; |
93 | import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | 77 | import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; |
@@ -108,10 +92,6 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic | @@ -108,10 +92,6 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic | ||
108 | 92 | ||
109 | private static final int DEFAULT_PAGE_SIZE = 1000; | 93 | private static final int DEFAULT_PAGE_SIZE = 1000; |
110 | 94 | ||
111 | - private RestTemplate restTemplate; | ||
112 | - | ||
113 | - private static final String EDGE_LICENSE_SERVER_ENDPOINT = "https://license.thingsboard.io"; | ||
114 | - | ||
115 | @Autowired | 95 | @Autowired |
116 | private EdgeDao edgeDao; | 96 | private EdgeDao edgeDao; |
117 | 97 | ||
@@ -133,16 +113,6 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic | @@ -133,16 +113,6 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic | ||
133 | @Autowired | 113 | @Autowired |
134 | private RelationService relationService; | 114 | private RelationService relationService; |
135 | 115 | ||
136 | - @Value("${edges.enabled:false}") | ||
137 | - private boolean edgesEnabled; | ||
138 | - | ||
139 | - @PostConstruct | ||
140 | - public void init() { | ||
141 | - if (edgesEnabled) { | ||
142 | - initRestTemplate(); | ||
143 | - } | ||
144 | - } | ||
145 | - | ||
146 | @Override | 116 | @Override |
147 | public Edge findEdgeById(TenantId tenantId, EdgeId edgeId) { | 117 | public Edge findEdgeById(TenantId tenantId, EdgeId edgeId) { |
148 | log.trace("Executing findEdgeById [{}]", edgeId); | 118 | log.trace("Executing findEdgeById [{}]", edgeId); |
@@ -545,19 +515,6 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic | @@ -545,19 +515,6 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic | ||
545 | } | 515 | } |
546 | 516 | ||
547 | @Override | 517 | @Override |
548 | - public ResponseEntity<JsonNode> checkInstance(JsonNode request) { | ||
549 | - return this.restTemplate.postForEntity(EDGE_LICENSE_SERVER_ENDPOINT + "/api/license/checkInstance", request, JsonNode.class); | ||
550 | - } | ||
551 | - | ||
552 | - @Override | ||
553 | - public ResponseEntity<JsonNode> activateInstance(String edgeLicenseSecret, String releaseDate) { | ||
554 | - Map<String, String> params = new HashMap<>(); | ||
555 | - params.put("licenseSecret", edgeLicenseSecret); | ||
556 | - params.put("releaseDate", releaseDate); | ||
557 | - return this.restTemplate.postForEntity(EDGE_LICENSE_SERVER_ENDPOINT + "/api/license/activateInstance?licenseSecret={licenseSecret}&releaseDate={releaseDate}", null, JsonNode.class, params); | ||
558 | - } | ||
559 | - | ||
560 | - @Override | ||
561 | public String findMissingToRelatedRuleChains(TenantId tenantId, EdgeId edgeId) { | 518 | public String findMissingToRelatedRuleChains(TenantId tenantId, EdgeId edgeId) { |
562 | List<RuleChain> edgeRuleChains = findEdgeRuleChains(tenantId, edgeId); | 519 | List<RuleChain> edgeRuleChains = findEdgeRuleChains(tenantId, edgeId); |
563 | List<RuleChainId> edgeRuleChainIds = edgeRuleChains.stream().map(IdBased::getId).collect(Collectors.toList()); | 520 | List<RuleChainId> edgeRuleChainIds = edgeRuleChains.stream().map(IdBased::getId).collect(Collectors.toList()); |
@@ -602,43 +559,4 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic | @@ -602,43 +559,4 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic | ||
602 | } while (pageData != null && pageData.hasNext()); | 559 | } while (pageData != null && pageData.hasNext()); |
603 | return result; | 560 | return result; |
604 | } | 561 | } |
605 | - | ||
606 | - private void initRestTemplate() { | ||
607 | - boolean jdkHttpClientEnabled = isNotEmpty(System.getProperty("tb.proxy.jdk")) && System.getProperty("tb.proxy.jdk").equalsIgnoreCase("true"); | ||
608 | - boolean systemProxyEnabled = isNotEmpty(System.getProperty("tb.proxy.system")) && System.getProperty("tb.proxy.system").equalsIgnoreCase("true"); | ||
609 | - boolean proxyEnabled = isNotEmpty(System.getProperty("tb.proxy.host")) && isNotEmpty(System.getProperty("tb.proxy.port")); | ||
610 | - if (jdkHttpClientEnabled) { | ||
611 | - log.warn("Going to use plain JDK Http Client!"); | ||
612 | - SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); | ||
613 | - if (proxyEnabled) { | ||
614 | - log.warn("Going to use Proxy Server: [{}:{}]", System.getProperty("tb.proxy.host"), System.getProperty("tb.proxy.port")); | ||
615 | - factory.setProxy(new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(System.getProperty("tb.proxy.host"), Integer.parseInt(System.getProperty("tb.proxy.port"))))); | ||
616 | - } | ||
617 | - | ||
618 | - this.restTemplate = new RestTemplate(new SimpleClientHttpRequestFactory()); | ||
619 | - } else { | ||
620 | - CloseableHttpClient httpClient; | ||
621 | - HttpComponentsClientHttpRequestFactory requestFactory; | ||
622 | - if (systemProxyEnabled) { | ||
623 | - log.warn("Going to use System Proxy Server!"); | ||
624 | - httpClient = HttpClients.createSystem(); | ||
625 | - requestFactory = new HttpComponentsClientHttpRequestFactory(); | ||
626 | - requestFactory.setHttpClient(httpClient); | ||
627 | - this.restTemplate = new RestTemplate(requestFactory); | ||
628 | - } else if (proxyEnabled) { | ||
629 | - log.warn("Going to use Proxy Server: [{}:{}]", System.getProperty("tb.proxy.host"), System.getProperty("tb.proxy.port")); | ||
630 | - httpClient = HttpClients.custom().setSSLHostnameVerifier(new DefaultHostnameVerifier()).setProxy(new HttpHost(System.getProperty("tb.proxy.host"), Integer.parseInt(System.getProperty("tb.proxy.port")), "https")).build(); | ||
631 | - requestFactory = new HttpComponentsClientHttpRequestFactory(); | ||
632 | - requestFactory.setHttpClient(httpClient); | ||
633 | - this.restTemplate = new RestTemplate(requestFactory); | ||
634 | - } else { | ||
635 | - httpClient = HttpClients.custom().setSSLHostnameVerifier(new DefaultHostnameVerifier()).build(); | ||
636 | - requestFactory = new HttpComponentsClientHttpRequestFactory(); | ||
637 | - requestFactory.setHttpClient(httpClient); | ||
638 | - this.restTemplate = new RestTemplate(requestFactory); | ||
639 | - } | ||
640 | - } | ||
641 | - | ||
642 | - } | ||
643 | - | ||
644 | } | 562 | } |