224 changed files with 5179 additions and 1114 deletions
@ -1,10 +1,10 @@ |
|||||
______ __ _ ____ __ |
_____ _ _ ____ _ |
||||
/_ __/ / /_ (_) ____ ____ _ _____ / __ ) ____ ____ _ _____ ____/ / |
|_ _| |__ (_)_ __ __ _ ___| __ ) ___ __ _ _ __ __| | |
||||
/ / / __ \ / / / __ \ / __ `/ / ___/ / __ | / __ \ / __ `/ / ___/ / __ / |
| | | '_ \| | '_ \ / _` / __| _ \ / _ \ / _` | '__/ _` | |
||||
/ / / / / / / / / / / / / /_/ / (__ ) / /_/ / / /_/ // /_/ / / / / /_/ / |
| | | | | | | | | | (_| \__ \ |_) | (_) | (_| | | | (_| | |
||||
/_/ /_/ /_/ /_/ /_/ /_/ \__, / /____/ /_____/ \____/ \__,_/ /_/ \__,_/ |
|_| |_| |_|_|_| |_|\__, |___/____/ \___/ \__,_|_| \__,_| |
||||
/____/ |
|___/ |
||||
|
|
||||
=================================================== |
=========================================================== |
||||
:: ${application.title} :: ${application.formatted-version} |
:: ${application.title} :: ${application.formatted-version} |
||||
=================================================== |
=========================================================== |
||||
|
|||||
@ -0,0 +1,156 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2025 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.edge; |
||||
|
|
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.junit.jupiter.api.Assertions; |
||||
|
import org.junit.jupiter.api.BeforeAll; |
||||
|
import org.junit.jupiter.api.DisplayName; |
||||
|
import org.junit.jupiter.api.TestInstance; |
||||
|
import org.junit.jupiter.params.ParameterizedTest; |
||||
|
import org.junit.jupiter.params.provider.MethodSource; |
||||
|
import org.thingsboard.common.util.JacksonUtil; |
||||
|
import org.thingsboard.rule.engine.action.TbSaveToCustomCassandraTableNode; |
||||
|
import org.thingsboard.rule.engine.api.NodeConfiguration; |
||||
|
import org.thingsboard.rule.engine.api.TbNode; |
||||
|
import org.thingsboard.rule.engine.aws.lambda.TbAwsLambdaNode; |
||||
|
import org.thingsboard.rule.engine.filter.TbCheckRelationNode; |
||||
|
import org.thingsboard.rule.engine.flow.TbAckNode; |
||||
|
import org.thingsboard.rule.engine.math.TbMathNode; |
||||
|
import org.thingsboard.rule.engine.metadata.CalculateDeltaNode; |
||||
|
import org.thingsboard.rule.engine.metadata.TbGetTelemetryNode; |
||||
|
import org.thingsboard.rule.engine.rest.TbSendRestApiCallReplyNode; |
||||
|
import org.thingsboard.rule.engine.telemetry.TbMsgAttributesNode; |
||||
|
import org.thingsboard.rule.engine.telemetry.TbMsgTimeseriesNode; |
||||
|
import org.thingsboard.server.common.data.rule.RuleChainMetaData; |
||||
|
import org.thingsboard.server.common.data.rule.RuleNode; |
||||
|
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
||||
|
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
||||
|
|
||||
|
import java.lang.reflect.Constructor; |
||||
|
import java.util.List; |
||||
|
import java.util.Optional; |
||||
|
import java.util.stream.Stream; |
||||
|
|
||||
|
import static org.thingsboard.server.service.edge.EdgeMsgConstructorUtils.EXCLUDED_NODES_BY_EDGE_VERSION; |
||||
|
import static org.thingsboard.server.service.edge.EdgeMsgConstructorUtils.IGNORED_PARAMS_BY_EDGE_VERSION; |
||||
|
|
||||
|
@Slf4j |
||||
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS) |
||||
|
public class EdgeMsgConstructorUtilsTest { |
||||
|
|
||||
|
private static final int CONFIGURATION_VERSION = 5; |
||||
|
|
||||
|
static Stream<EdgeVersion> provideEdgeVersions() { |
||||
|
return Stream.of( |
||||
|
EdgeVersion.V_4_0_0, |
||||
|
EdgeVersion.V_3_9_0, |
||||
|
EdgeVersion.V_3_8_0, |
||||
|
EdgeVersion.V_3_7_0 |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
private static final RuleChainMetaData RULE_CHAIN_META_DATA = new RuleChainMetaData(); |
||||
|
private static final List<TbNode> TEST_NODES = |
||||
|
List.of( |
||||
|
new TbSaveToCustomCassandraTableNode(), |
||||
|
new TbMsgAttributesNode(), |
||||
|
new TbMsgTimeseriesNode(), |
||||
|
new TbSendRestApiCallReplyNode(), |
||||
|
new TbAwsLambdaNode(), |
||||
|
|
||||
|
new TbMathNode(), |
||||
|
new CalculateDeltaNode(), |
||||
|
new TbAckNode(), |
||||
|
new TbCheckRelationNode(), |
||||
|
new TbGetTelemetryNode() |
||||
|
); |
||||
|
|
||||
|
@BeforeAll |
||||
|
static void setUp() { |
||||
|
List<RuleNode> ruleNodes = TEST_NODES.stream() |
||||
|
.map(node -> { |
||||
|
RuleNode ruleNode = new RuleNode(); |
||||
|
ruleNode.setName(node.getClass().getName()); |
||||
|
ruleNode.setType(node.getClass().getName()); |
||||
|
ruleNode.setConfigurationVersion(CONFIGURATION_VERSION); |
||||
|
ruleNode.setConfiguration(JacksonUtil.valueToTree(createDefaultConfiguration(node))); |
||||
|
return ruleNode; |
||||
|
}) |
||||
|
.toList(); |
||||
|
|
||||
|
RULE_CHAIN_META_DATA.setFirstNodeIndex(0); |
||||
|
RULE_CHAIN_META_DATA.setNodes(ruleNodes); |
||||
|
} |
||||
|
|
||||
|
private static NodeConfiguration<?> createDefaultConfiguration(TbNode node) { |
||||
|
try { |
||||
|
org.thingsboard.rule.engine.api.RuleNode annotation = node.getClass().getAnnotation(org.thingsboard.rule.engine.api.RuleNode.class); |
||||
|
Constructor<?> constructor = annotation.configClazz().getConstructor(); |
||||
|
NodeConfiguration<?> configInstance = (NodeConfiguration<?>) constructor.newInstance(); |
||||
|
|
||||
|
return configInstance.defaultConfiguration(); |
||||
|
} catch (Exception e) { |
||||
|
throw new RuntimeException("Exception during creating RuleNodeConfiguration for node - " + node, e); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@ParameterizedTest(name = "Test Sanitize Metadata For Edge: {0}") |
||||
|
@MethodSource("provideEdgeVersions") |
||||
|
@DisplayName("Test Sanitize Metadata For Legacy Edge Version") |
||||
|
public void testSanitizeMetadataForLegacyEdgeVersion(EdgeVersion edgeVersion) { |
||||
|
// WHEN
|
||||
|
List<RuleNode> ruleNodes = sanitizeMetadataForLegacyEdgeVersion(edgeVersion); |
||||
|
|
||||
|
// THEN
|
||||
|
ruleNodes.forEach(ruleNode -> { |
||||
|
checkUpdateNodeConfigurationsForLegacyEdge(ruleNode, edgeVersion); |
||||
|
checkRemoveExcludedNodesForLegacyEdge(ruleNode, edgeVersion); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private List<RuleNode> sanitizeMetadataForLegacyEdgeVersion(EdgeVersion edgeVersion) { |
||||
|
String metadataUpdateMsg = EdgeMsgConstructorUtils.constructRuleChainMetadataUpdatedMsg( |
||||
|
UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, |
||||
|
RULE_CHAIN_META_DATA, |
||||
|
edgeVersion |
||||
|
).getEntity(); |
||||
|
|
||||
|
RuleChainMetaData updatedMetaData = JacksonUtil.fromString(metadataUpdateMsg, RuleChainMetaData.class, true); |
||||
|
Assertions.assertNotNull(updatedMetaData, "RuleChainMetaData should not be null after update."); |
||||
|
|
||||
|
return updatedMetaData.getNodes(); |
||||
|
} |
||||
|
|
||||
|
private void checkUpdateNodeConfigurationsForLegacyEdge(RuleNode ruleNode, EdgeVersion edgeVersion) { |
||||
|
if (IGNORED_PARAMS_BY_EDGE_VERSION.containsKey(edgeVersion) && IGNORED_PARAMS_BY_EDGE_VERSION.get(edgeVersion).containsKey(ruleNode.getType())) { |
||||
|
String ignoredParam = IGNORED_PARAMS_BY_EDGE_VERSION.get(edgeVersion).get(ruleNode.getType()); |
||||
|
|
||||
|
Assertions.assertFalse(ruleNode.getConfiguration().has(ignoredParam), |
||||
|
String.format("RuleNode '%s' for EdgeVersion '%s' should ignore '%s' config parameter.", ruleNode.getName(), edgeVersion, ignoredParam)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void checkRemoveExcludedNodesForLegacyEdge(RuleNode ruleNode, EdgeVersion edgeVersion) { |
||||
|
boolean isNodeExcluded = Optional.ofNullable(EXCLUDED_NODES_BY_EDGE_VERSION.get(edgeVersion)) |
||||
|
.map(excludedNodes -> !excludedNodes.contains(ruleNode.getType())) |
||||
|
.orElse(true); |
||||
|
|
||||
|
Assertions.assertTrue(isNodeExcluded, |
||||
|
String.format("For EdgeVersion '%s', ruleNode '%s' should not be included.", edgeVersion, ruleNode.getType())); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,92 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2025 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.edqs.stats; |
||||
|
|
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.thingsboard.server.common.data.ObjectType; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.query.EntityCountQuery; |
||||
|
import org.thingsboard.server.common.data.query.EntityDataQuery; |
||||
|
import org.thingsboard.server.common.stats.EdqsStatsService; |
||||
|
import org.thingsboard.server.common.stats.StatsFactory; |
||||
|
import org.thingsboard.server.common.stats.StatsTimer; |
||||
|
import org.thingsboard.server.common.stats.StatsType; |
||||
|
|
||||
|
import java.util.concurrent.ConcurrentHashMap; |
||||
|
import java.util.concurrent.TimeUnit; |
||||
|
import java.util.concurrent.atomic.AtomicInteger; |
||||
|
|
||||
|
@Service |
||||
|
@Slf4j |
||||
|
@ConditionalOnExpression("'${queue.edqs.api.supported:true}' == 'true' && '${queue.edqs.stats.enabled:true}' == 'true'") |
||||
|
public class DefaultEdqsStatsService implements EdqsStatsService { |
||||
|
|
||||
|
private final StatsFactory statsFactory; |
||||
|
|
||||
|
@Value("${queue.edqs.stats.slow_query_threshold:3000}") |
||||
|
private int slowQueryThreshold; |
||||
|
|
||||
|
private final ConcurrentHashMap<ObjectType, AtomicInteger> objectCounters = new ConcurrentHashMap<>(); |
||||
|
private final StatsTimer dataQueryTimer; |
||||
|
private final StatsTimer countQueryTimer; |
||||
|
|
||||
|
private DefaultEdqsStatsService(StatsFactory statsFactory) { |
||||
|
this.statsFactory = statsFactory; |
||||
|
dataQueryTimer = statsFactory.createTimer(StatsType.EDQS, "entityDataQueryTimer"); |
||||
|
countQueryTimer = statsFactory.createTimer(StatsType.EDQS, "entityCountQueryTimer"); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void reportAdded(ObjectType objectType) { |
||||
|
getObjectCounter(objectType).incrementAndGet(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void reportRemoved(ObjectType objectType) { |
||||
|
getObjectCounter(objectType).decrementAndGet(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void reportDataQuery(TenantId tenantId, EntityDataQuery query, long timingNanos) { |
||||
|
double timingMs = timingNanos / 1000_000.0; |
||||
|
if (timingMs < slowQueryThreshold) { |
||||
|
log.debug("[{}] Executed data query in {} ms: {}", tenantId, timingMs, query); |
||||
|
} else { |
||||
|
log.warn("[{}] Executed slow data query in {} ms: {}", tenantId, timingMs, query); |
||||
|
} |
||||
|
dataQueryTimer.record(timingNanos, TimeUnit.NANOSECONDS); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void reportCountQuery(TenantId tenantId, EntityCountQuery query, long timingNanos) { |
||||
|
double timingMs = timingNanos / 1000_000.0; |
||||
|
if (timingMs < slowQueryThreshold) { |
||||
|
log.debug("[{}] Executed count query in {} ms: {}", tenantId, timingMs, query); |
||||
|
} else { |
||||
|
log.warn("[{}] Executed slow count query in {} ms: {}", tenantId, timingMs, query); |
||||
|
} |
||||
|
countQueryTimer.record(timingNanos, TimeUnit.NANOSECONDS); |
||||
|
} |
||||
|
|
||||
|
private AtomicInteger getObjectCounter(ObjectType objectType) { |
||||
|
return objectCounters.computeIfAbsent(objectType, type -> |
||||
|
statsFactory.createGauge("edqsObjectsCount", new AtomicInteger(), "objectType", type.name())); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -1,81 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2025 The Thingsboard Authors |
|
||||
* |
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||
* you may not use this file except in compliance with the License. |
|
||||
* You may obtain a copy of the License at |
|
||||
* |
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||
* |
|
||||
* Unless required by applicable law or agreed to in writing, software |
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||
* See the License for the specific language governing permissions and |
|
||||
* limitations under the License. |
|
||||
*/ |
|
||||
package org.thingsboard.server.edqs.stats; |
|
||||
|
|
||||
import lombok.AllArgsConstructor; |
|
||||
import lombok.Getter; |
|
||||
import lombok.RequiredArgsConstructor; |
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
|
||||
import org.springframework.stereotype.Service; |
|
||||
import org.thingsboard.server.common.data.ObjectType; |
|
||||
import org.thingsboard.server.common.data.edqs.EdqsEventType; |
|
||||
import org.thingsboard.server.common.data.id.TenantId; |
|
||||
import org.thingsboard.server.common.stats.StatsFactory; |
|
||||
import org.thingsboard.server.common.stats.StatsType; |
|
||||
import org.thingsboard.server.queue.edqs.EdqsComponent; |
|
||||
|
|
||||
import java.util.concurrent.ConcurrentHashMap; |
|
||||
import java.util.concurrent.atomic.AtomicInteger; |
|
||||
import java.util.stream.Collectors; |
|
||||
|
|
||||
@EdqsComponent |
|
||||
@Service |
|
||||
@Slf4j |
|
||||
@RequiredArgsConstructor |
|
||||
@ConditionalOnProperty(name = "queue.edqs.stats.enabled", havingValue = "true", matchIfMissing = true) |
|
||||
public class EdqsStatsService { |
|
||||
|
|
||||
private final ConcurrentHashMap<TenantId, EdqsStats> statsMap = new ConcurrentHashMap<>(); |
|
||||
private final StatsFactory statsFactory; |
|
||||
|
|
||||
public void reportEvent(TenantId tenantId, ObjectType objectType, EdqsEventType eventType) { |
|
||||
statsMap.computeIfAbsent(tenantId, id -> new EdqsStats(tenantId, statsFactory)) |
|
||||
.reportEvent(objectType, eventType); |
|
||||
} |
|
||||
|
|
||||
@Getter |
|
||||
@AllArgsConstructor |
|
||||
static class EdqsStats { |
|
||||
|
|
||||
private final TenantId tenantId; |
|
||||
private final ConcurrentHashMap<ObjectType, AtomicInteger> entityCounters = new ConcurrentHashMap<>(); |
|
||||
private final StatsFactory statsFactory; |
|
||||
|
|
||||
private AtomicInteger getOrCreateObjectCounter(ObjectType objectType) { |
|
||||
return entityCounters.computeIfAbsent(objectType, |
|
||||
type -> statsFactory.createGauge(StatsType.EDQS.getName() + "_object_count", new AtomicInteger(), |
|
||||
"tenantId", tenantId.toString(), "objectType", type.name())); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public String toString() { |
|
||||
return entityCounters.entrySet().stream() |
|
||||
.map(counters -> counters.getKey().name()+ " total = [" + counters.getValue() + "]") |
|
||||
.collect(Collectors.joining(", ")); |
|
||||
} |
|
||||
|
|
||||
public void reportEvent(ObjectType objectType, EdqsEventType eventType) { |
|
||||
AtomicInteger objectCounter = getOrCreateObjectCounter(objectType); |
|
||||
if (eventType == EdqsEventType.UPDATED){ |
|
||||
objectCounter.incrementAndGet(); |
|
||||
} else if (eventType == EdqsEventType.DELETED) { |
|
||||
objectCounter.decrementAndGet(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -0,0 +1,41 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2025 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.common.stats; |
||||
|
|
||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.thingsboard.server.common.data.ObjectType; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.query.EntityCountQuery; |
||||
|
import org.thingsboard.server.common.data.query.EntityDataQuery; |
||||
|
|
||||
|
@Service |
||||
|
@ConditionalOnMissingBean(value = EdqsStatsService.class, ignored = DummyEdqsStatsService.class) |
||||
|
public class DummyEdqsStatsService implements EdqsStatsService { |
||||
|
|
||||
|
@Override |
||||
|
public void reportAdded(ObjectType objectType) {} |
||||
|
|
||||
|
@Override |
||||
|
public void reportRemoved(ObjectType objectType) {} |
||||
|
|
||||
|
@Override |
||||
|
public void reportDataQuery(TenantId tenantId, EntityDataQuery query, long timingNanos) {} |
||||
|
|
||||
|
@Override |
||||
|
public void reportCountQuery(TenantId tenantId, EntityCountQuery query, long timingNanos) {} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2025 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.common.stats; |
||||
|
|
||||
|
import org.thingsboard.server.common.data.ObjectType; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.query.EntityCountQuery; |
||||
|
import org.thingsboard.server.common.data.query.EntityDataQuery; |
||||
|
|
||||
|
public interface EdqsStatsService { |
||||
|
|
||||
|
void reportAdded(ObjectType objectType); |
||||
|
|
||||
|
void reportRemoved(ObjectType objectType); |
||||
|
|
||||
|
void reportDataQuery(TenantId tenantId, EntityDataQuery query, long timingNanos); |
||||
|
|
||||
|
void reportCountQuery(TenantId tenantId, EntityCountQuery query, long timingNanos); |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,78 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2025 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.common.util; |
||||
|
|
||||
|
import net.objecthunter.exp4j.function.Function; |
||||
|
import net.objecthunter.exp4j.function.Functions; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
public class ExpressionFunctionsUtil { |
||||
|
|
||||
|
public static final List<Function> userDefinedFunctions = new ArrayList<>(); |
||||
|
|
||||
|
static { |
||||
|
userDefinedFunctions.add( |
||||
|
new Function("ln") { |
||||
|
@Override |
||||
|
public double apply(double... args) { |
||||
|
return Math.log(args[0]); |
||||
|
} |
||||
|
} |
||||
|
); |
||||
|
userDefinedFunctions.add( |
||||
|
new Function("lg") { |
||||
|
@Override |
||||
|
public double apply(double... args) { |
||||
|
return Math.log10(args[0]); |
||||
|
} |
||||
|
} |
||||
|
); |
||||
|
userDefinedFunctions.add( |
||||
|
new Function("logab", 2) { |
||||
|
@Override |
||||
|
public double apply(double... args) { |
||||
|
return Math.log(args[1]) / Math.log(args[0]); |
||||
|
} |
||||
|
} |
||||
|
); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("sin")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("cos")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("tan")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("cot")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("log")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("log2")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("log10")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("log1p")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("abs")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("acos")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("asin")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("atan")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("cbrt")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("floor")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("sinh")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("sqrt")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("tanh")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("cosh")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("ceil")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("pow")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("exp")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("expm1")); |
||||
|
userDefinedFunctions.add(Functions.getBuiltinFunction("signum")); |
||||
|
} |
||||
|
|
||||
|
} |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue