Browse Source
# Conflicts: # dao/src/main/java/org/thingsboard/server/dao/sqlts/SqlTimeseriesLatestDao.javapull/5905/head
929 changed files with 31294 additions and 10980 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,71 @@ |
|||
-- |
|||
-- Copyright © 2016-2021 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. |
|||
-- |
|||
|
|||
CREATE TABLE IF NOT EXISTS entity_alarm ( |
|||
tenant_id uuid NOT NULL, |
|||
entity_type varchar(32), |
|||
entity_id uuid NOT NULL, |
|||
created_time bigint NOT NULL, |
|||
alarm_type varchar(255) NOT NULL, |
|||
customer_id uuid, |
|||
alarm_id uuid, |
|||
CONSTRAINT entity_alarm_pkey PRIMARY KEY (entity_id, alarm_id), |
|||
CONSTRAINT fk_entity_alarm_id FOREIGN KEY (alarm_id) REFERENCES alarm(id) ON DELETE CASCADE |
|||
); |
|||
|
|||
CREATE INDEX IF NOT EXISTS idx_alarm_tenant_status_created_time ON alarm(tenant_id, status, created_time DESC); |
|||
CREATE INDEX IF NOT EXISTS idx_entity_alarm_created_time ON entity_alarm(tenant_id, entity_id, created_time DESC); |
|||
CREATE INDEX IF NOT EXISTS idx_entity_alarm_alarm_id ON entity_alarm(alarm_id); |
|||
|
|||
INSERT INTO entity_alarm(tenant_id, entity_type, entity_id, created_time, alarm_type, customer_id, alarm_id) |
|||
SELECT tenant_id, |
|||
CASE |
|||
WHEN originator_type = 0 THEN 'TENANT' |
|||
WHEN originator_type = 1 THEN 'CUSTOMER' |
|||
WHEN originator_type = 2 THEN 'USER' |
|||
WHEN originator_type = 3 THEN 'DASHBOARD' |
|||
WHEN originator_type = 4 THEN 'ASSET' |
|||
WHEN originator_type = 5 THEN 'DEVICE' |
|||
WHEN originator_type = 6 THEN 'ALARM' |
|||
WHEN originator_type = 7 THEN 'RULE_CHAIN' |
|||
WHEN originator_type = 8 THEN 'RULE_NODE' |
|||
WHEN originator_type = 9 THEN 'ENTITY_VIEW' |
|||
WHEN originator_type = 10 THEN 'WIDGETS_BUNDLE' |
|||
WHEN originator_type = 11 THEN 'WIDGET_TYPE' |
|||
WHEN originator_type = 12 THEN 'TENANT_PROFILE' |
|||
WHEN originator_type = 13 THEN 'DEVICE_PROFILE' |
|||
WHEN originator_type = 14 THEN 'API_USAGE_STATE' |
|||
WHEN originator_type = 15 THEN 'TB_RESOURCE' |
|||
WHEN originator_type = 16 THEN 'OTA_PACKAGE' |
|||
WHEN originator_type = 17 THEN 'EDGE' |
|||
WHEN originator_type = 18 THEN 'RPC' |
|||
else 'UNKNOWN' |
|||
END, |
|||
originator_id, |
|||
created_time, |
|||
type, |
|||
customer_id, |
|||
id |
|||
FROM alarm |
|||
ON CONFLICT DO NOTHING; |
|||
|
|||
INSERT INTO entity_alarm(tenant_id, entity_type, entity_id, created_time, alarm_type, customer_id, alarm_id) |
|||
SELECT a.tenant_id, r.from_type, r.from_id, created_time, type, customer_id, id |
|||
FROM alarm a |
|||
INNER JOIN relation r ON r.relation_type_group = 'ALARM' and r.relation_type = 'ANY' and a.id = r.to_id |
|||
ON CONFLICT DO NOTHING; |
|||
|
|||
DELETE FROM relation r WHERE r.relation_type_group = 'ALARM'; |
|||
@ -0,0 +1,213 @@ |
|||
-- |
|||
-- Copyright © 2016-2021 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. |
|||
-- |
|||
|
|||
|
|||
CREATE OR REPLACE PROCEDURE update_profile_bootstrap() |
|||
LANGUAGE plpgsql AS |
|||
$$ |
|||
|
|||
BEGIN |
|||
|
|||
UPDATE device_profile |
|||
SET profile_data = jsonb_set( |
|||
profile_data, |
|||
'{transportConfiguration}', |
|||
get_bootstrap( |
|||
profile_data::jsonb #> '{transportConfiguration}', |
|||
subquery.publickey_bs, |
|||
subquery.publickey_lw, |
|||
profile_data::json #>> '{transportConfiguration, bootstrap, bootstrapServer, securityMode}', |
|||
profile_data::json #>> '{transportConfiguration, bootstrap, lwm2mServer, securityMode}'), |
|||
true) |
|||
FROM ( |
|||
SELECT id, |
|||
encode( |
|||
decode(profile_data::json #> '{transportConfiguration,bootstrap,bootstrapServer}' ->> |
|||
'serverPublicKey', 'hex')::bytea, 'base64') AS publickey_bs, |
|||
encode( |
|||
decode(profile_data::json #> '{transportConfiguration,bootstrap,lwm2mServer}' ->> |
|||
'serverPublicKey', 'hex')::bytea, 'base64') AS publickey_lw |
|||
FROM device_profile |
|||
WHERE transport_type = 'LWM2M' |
|||
) AS subquery |
|||
WHERE device_profile.id = subquery.id |
|||
AND subquery.publickey_bs IS NOT NULL |
|||
AND subquery.publickey_lw IS NOT NULL; |
|||
|
|||
END; |
|||
$$; |
|||
|
|||
CREATE OR REPLACE FUNCTION get_bootstrap(transport_configuration_in jsonb, publickey_bs text, |
|||
publickey_lw text, security_mode_bs text, |
|||
security_mode_lw text) RETURNS jsonb AS |
|||
$$ |
|||
|
|||
DECLARE |
|||
bootstrap_new jsonb; |
|||
bootstrap_in jsonb; |
|||
|
|||
BEGIN |
|||
|
|||
IF security_mode_lw IS NULL THEN |
|||
security_mode_lw := 'NO_SEC'; |
|||
END IF; |
|||
|
|||
IF security_mode_bs IS NULL THEN |
|||
security_mode_bs := 'NO_SEC'; |
|||
END IF; |
|||
|
|||
bootstrap_in := transport_configuration_in::jsonb #> '{bootstrap}'; |
|||
bootstrap_new := json_build_array( |
|||
json_build_object('shortServerId', bootstrap_in::json #> '{bootstrapServer}' -> 'serverId', |
|||
'securityMode', security_mode_bs, |
|||
'binding', bootstrap_in::json #> '{servers}' ->> 'binding', |
|||
'lifetime', bootstrap_in::json #> '{servers}' -> 'lifetime', |
|||
'notifIfDisabled', bootstrap_in::json #> '{servers}' -> 'notifIfDisabled', |
|||
'defaultMinPeriod', bootstrap_in::json #> '{servers}' -> 'defaultMinPeriod', |
|||
'host', bootstrap_in::json #> '{bootstrapServer}' ->> 'host', |
|||
'port', bootstrap_in::json #> '{bootstrapServer}' -> 'port', |
|||
'serverPublicKey', publickey_bs, |
|||
'bootstrapServerIs', true, |
|||
'clientHoldOffTime', bootstrap_in::json #> '{bootstrapServer}' -> 'clientHoldOffTime', |
|||
'bootstrapServerAccountTimeout', |
|||
bootstrap_in::json #> '{bootstrapServer}' -> 'bootstrapServerAccountTimeout' |
|||
), |
|||
json_build_object('shortServerId', bootstrap_in::json #> '{lwm2mServer}' -> 'serverId', |
|||
'securityMode', security_mode_lw, |
|||
'binding', bootstrap_in::json #> '{servers}' ->> 'binding', |
|||
'lifetime', bootstrap_in::json #> '{servers}' -> 'lifetime', |
|||
'notifIfDisabled', bootstrap_in::json #> '{servers}' -> 'notifIfDisabled', |
|||
'defaultMinPeriod', bootstrap_in::json #> '{servers}' -> 'defaultMinPeriod', |
|||
'host', bootstrap_in::json #> '{lwm2mServer}' ->> 'host', |
|||
'port', bootstrap_in::json #> '{lwm2mServer}' -> 'port', |
|||
'serverPublicKey', publickey_lw, |
|||
'bootstrapServerIs', false, |
|||
'clientHoldOffTime', bootstrap_in::json #> '{lwm2mServer}' -> 'clientHoldOffTime', |
|||
'bootstrapServerAccountTimeout', |
|||
bootstrap_in::json #> '{lwm2mServer}' -> 'bootstrapServerAccountTimeout' |
|||
) |
|||
); |
|||
RETURN jsonb_set( |
|||
transport_configuration_in, |
|||
'{bootstrap}', |
|||
bootstrap_new, |
|||
true) || '{"bootstrapServerUpdateEnable": true}'; |
|||
|
|||
END; |
|||
$$ LANGUAGE plpgsql; |
|||
|
|||
CREATE OR REPLACE PROCEDURE update_device_credentials_to_base64_and_bootstrap() |
|||
LANGUAGE plpgsql AS |
|||
$$ |
|||
|
|||
BEGIN |
|||
|
|||
UPDATE device_credentials |
|||
SET credentials_value = get_device_and_bootstrap(credentials_value::text) |
|||
WHERE credentials_type = 'LWM2M_CREDENTIALS'; |
|||
END; |
|||
$$; |
|||
|
|||
CREATE OR REPLACE FUNCTION get_device_and_bootstrap(IN credentials_value text, OUT credentials_value_new text) |
|||
LANGUAGE plpgsql AS |
|||
$$ |
|||
DECLARE |
|||
client_secret_key text; |
|||
client_public_key_or_id text; |
|||
client_key_value_object jsonb; |
|||
client_bootstrap_server_value_object jsonb; |
|||
client_bootstrap_server_object jsonb; |
|||
client_bootstrap_object jsonb; |
|||
|
|||
BEGIN |
|||
credentials_value_new := credentials_value; |
|||
IF credentials_value::jsonb #> '{client}' ->> 'securityConfigClientMode' = 'RPK' AND |
|||
NULLIF((credentials_value::jsonb #> '{client}' ->> 'key' ~ '^[0-9a-fA-F]+$')::text, 'false') = 'true' THEN |
|||
client_public_key_or_id := encode(decode(credentials_value::jsonb #> '{client}' ->> 'key', 'hex')::bytea, 'base64'); |
|||
client_key_value_object := json_build_object( |
|||
'endpoint', credentials_value::jsonb #> '{client}' ->> 'endpoint', |
|||
'securityConfigClientMode', credentials_value::jsonb #> '{client}' ->> 'securityConfigClientMode', |
|||
'key', client_public_key_or_id); |
|||
credentials_value_new := |
|||
credentials_value_new::jsonb || json_build_object('client', client_key_value_object)::jsonb; |
|||
END IF; |
|||
IF credentials_value::jsonb #> '{client}' ->> 'securityConfigClientMode' = 'X509' AND |
|||
NULLIF((credentials_value::jsonb #> '{client}' ->> 'cert' ~ '^[0-9a-fA-F]+$')::text, 'false') = 'true' THEN |
|||
client_public_key_or_id := |
|||
encode(decode(credentials_value::jsonb #> '{client}' ->> 'cert', 'hex')::bytea, 'base64'); |
|||
client_key_value_object := json_build_object( |
|||
'endpoint', credentials_value::jsonb #> '{client}' ->> 'endpoint', |
|||
'securityConfigClientMode', credentials_value::jsonb #> '{client}' ->> 'securityConfigClientMode', |
|||
'cert', client_public_key_or_id); |
|||
credentials_value_new := |
|||
credentials_value_new::jsonb || json_build_object('client', client_key_value_object)::jsonb; |
|||
END IF; |
|||
|
|||
IF credentials_value::jsonb #> '{bootstrap,lwm2mServer}' ->> 'securityMode' = 'RPK' OR |
|||
credentials_value::jsonb #> '{bootstrap,lwm2mServer}' ->> 'securityMode' = 'X509' THEN |
|||
IF NULLIF((credentials_value::jsonb #> '{bootstrap,lwm2mServer}' ->> 'clientSecretKey' ~ '^[0-9a-fA-F]+$')::text, |
|||
'false') = 'true' AND |
|||
NULLIF( |
|||
(credentials_value::jsonb #> '{bootstrap,lwm2mServer}' ->> 'clientPublicKeyOrId' ~ '^[0-9a-fA-F]+$')::text, |
|||
'false') = 'true' THEN |
|||
client_secret_key := |
|||
encode(decode(credentials_value::jsonb #> '{bootstrap,lwm2mServer}' ->> 'clientSecretKey', 'hex')::bytea, |
|||
'base64'); |
|||
client_public_key_or_id := encode( |
|||
decode(credentials_value::jsonb #> '{bootstrap,lwm2mServer}' ->> 'clientPublicKeyOrId', 'hex')::bytea, |
|||
'base64'); |
|||
client_bootstrap_server_value_object := jsonb_build_object( |
|||
'securityMode', credentials_value::jsonb #> '{bootstrap,lwm2mServer}' ->> 'securityMode', |
|||
'clientPublicKeyOrId', client_public_key_or_id, |
|||
'clientSecretKey', client_secret_key |
|||
); |
|||
client_bootstrap_server_object := jsonb_build_object('lwm2mServer', client_bootstrap_server_value_object::jsonb); |
|||
client_bootstrap_object := credentials_value_new::jsonb #> '{bootstrap}' || client_bootstrap_server_object::jsonb; |
|||
credentials_value_new := |
|||
jsonb_set(credentials_value_new::jsonb, '{bootstrap}', client_bootstrap_object::jsonb, false)::jsonb; |
|||
END IF; |
|||
END IF; |
|||
|
|||
IF credentials_value::jsonb #> '{bootstrap,bootstrapServer}' ->> 'securityMode' = 'RPK' OR |
|||
credentials_value::jsonb #> '{bootstrap,bootstrapServer}' ->> 'securityMode' = 'X509' THEN |
|||
IF NULLIF( |
|||
(credentials_value::jsonb #> '{bootstrap,bootstrapServer}' ->> 'clientSecretKey' ~ '^[0-9a-fA-F]+$')::text, |
|||
'false') = 'true' AND |
|||
NULLIF( |
|||
(credentials_value::jsonb #> '{bootstrap,bootstrapServer}' ->> 'clientPublicKeyOrId' ~ '^[0-9a-fA-F]+$')::text, |
|||
'false') = 'true' THEN |
|||
client_secret_key := |
|||
encode( |
|||
decode(credentials_value::jsonb #> '{bootstrap,bootstrapServer}' ->> 'clientSecretKey', 'hex')::bytea, |
|||
'base64'); |
|||
client_public_key_or_id := encode( |
|||
decode(credentials_value::jsonb #> '{bootstrap,bootstrapServer}' ->> 'clientPublicKeyOrId', 'hex')::bytea, |
|||
'base64'); |
|||
client_bootstrap_server_value_object := jsonb_build_object( |
|||
'securityMode', credentials_value::jsonb #> '{bootstrap,bootstrapServer}' ->> 'securityMode', |
|||
'clientPublicKeyOrId', client_public_key_or_id, |
|||
'clientSecretKey', client_secret_key |
|||
); |
|||
client_bootstrap_server_object := |
|||
jsonb_build_object('bootstrapServer', client_bootstrap_server_value_object::jsonb); |
|||
client_bootstrap_object := credentials_value_new::jsonb #> '{bootstrap}' || client_bootstrap_server_object::jsonb; |
|||
credentials_value_new := |
|||
jsonb_set(credentials_value_new::jsonb, '{bootstrap}', client_bootstrap_object::jsonb, false)::jsonb; |
|||
END IF; |
|||
END IF; |
|||
|
|||
END; |
|||
$$; |
|||
@ -0,0 +1,41 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.actors.ruleChain; |
|||
|
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.Getter; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.id.RuleChainId; |
|||
import org.thingsboard.server.common.data.id.RuleNodeId; |
|||
import org.thingsboard.server.common.msg.MsgType; |
|||
import org.thingsboard.server.common.msg.TbMsg; |
|||
|
|||
/** |
|||
* Created by ashvayka on 19.03.18. |
|||
*/ |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@ToString |
|||
public final class RuleChainInputMsg extends TbToRuleChainActorMsg { |
|||
|
|||
public RuleChainInputMsg(RuleChainId target, TbMsg tbMsg) { |
|||
super(tbMsg, target); |
|||
} |
|||
|
|||
@Override |
|||
public MsgType getMsgType() { |
|||
return MsgType.RULE_CHAIN_INPUT_MSG; |
|||
} |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.actors.ruleChain; |
|||
|
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.Getter; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.id.RuleChainId; |
|||
import org.thingsboard.server.common.data.id.RuleNodeId; |
|||
import org.thingsboard.server.common.msg.MsgType; |
|||
import org.thingsboard.server.common.msg.TbMsg; |
|||
|
|||
/** |
|||
* Created by ashvayka on 19.03.18. |
|||
*/ |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@ToString |
|||
public final class RuleChainOutputMsg extends TbToRuleChainActorMsg { |
|||
|
|||
@Getter |
|||
private final RuleNodeId targetRuleNodeId; |
|||
|
|||
@Getter |
|||
private final String relationType; |
|||
|
|||
public RuleChainOutputMsg(RuleChainId target, RuleNodeId targetRuleNodeId, String relationType, TbMsg tbMsg) { |
|||
super(tbMsg, target); |
|||
this.targetRuleNodeId = targetRuleNodeId; |
|||
this.relationType = relationType; |
|||
} |
|||
|
|||
@Override |
|||
public MsgType getMsgType() { |
|||
return MsgType.RULE_CHAIN_OUTPUT_MSG; |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.actors.ruleChain; |
|||
|
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.Getter; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.id.RuleChainId; |
|||
import org.thingsboard.server.common.msg.TbActorStopReason; |
|||
import org.thingsboard.server.common.msg.TbMsg; |
|||
import org.thingsboard.server.common.msg.TbRuleEngineActorMsg; |
|||
import org.thingsboard.server.common.msg.aware.RuleChainAwareMsg; |
|||
import org.thingsboard.server.common.msg.queue.RuleEngineException; |
|||
|
|||
@EqualsAndHashCode(callSuper = true) |
|||
@ToString |
|||
public abstract class TbToRuleChainActorMsg extends TbRuleEngineActorMsg implements RuleChainAwareMsg { |
|||
|
|||
@Getter |
|||
private final RuleChainId target; |
|||
|
|||
public TbToRuleChainActorMsg(TbMsg msg, RuleChainId target) { |
|||
super(msg); |
|||
this.target = target; |
|||
} |
|||
|
|||
@Override |
|||
public RuleChainId getRuleChainId() { |
|||
return target; |
|||
} |
|||
|
|||
@Override |
|||
public void onTbActorStopped(TbActorStopReason reason) { |
|||
String message = reason == TbActorStopReason.STOPPED ? String.format("Rule chain [%s] stopped", target.getId()) : String.format("Failed to initialize rule chain [%s]!", target.getId()); |
|||
msg.getCallback().onFailure(new RuleEngineException(message)); |
|||
} |
|||
} |
|||
@ -0,0 +1,71 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.controller; |
|||
|
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import com.fasterxml.jackson.databind.node.ObjectNode; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.info.BuildProperties; |
|||
import org.springframework.security.access.prepost.PreAuthorize; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestMethod; |
|||
import org.springframework.web.bind.annotation.ResponseBody; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
import springfox.documentation.annotations.ApiIgnore; |
|||
|
|||
import javax.annotation.PostConstruct; |
|||
|
|||
@ApiIgnore |
|||
@RestController |
|||
@TbCoreComponent |
|||
@RequestMapping("/api") |
|||
@Slf4j |
|||
public class SystemInfoController { |
|||
|
|||
@Autowired(required = false) |
|||
private BuildProperties buildProperties; |
|||
|
|||
@PostConstruct |
|||
public void init() { |
|||
JsonNode info = buildInfoObject(); |
|||
log.info("System build info: {}", info); |
|||
} |
|||
|
|||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|||
@RequestMapping(value = "/system/info", method = RequestMethod.GET) |
|||
@ResponseBody |
|||
public JsonNode getSystemVersionInfo() { |
|||
return buildInfoObject(); |
|||
} |
|||
|
|||
private JsonNode buildInfoObject() { |
|||
ObjectMapper objectMapper = new ObjectMapper(); |
|||
ObjectNode infoObject = objectMapper.createObjectNode(); |
|||
if (buildProperties != null) { |
|||
infoObject.put("version", buildProperties.getVersion()); |
|||
infoObject.put("artifact", buildProperties.getArtifact()); |
|||
infoObject.put("name", buildProperties.getName()); |
|||
} else { |
|||
infoObject.put("version", "unknown"); |
|||
} |
|||
return infoObject; |
|||
} |
|||
} |
|||
@ -1,70 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.lwm2m; |
|||
|
|||
|
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.eclipse.leshan.core.util.Hex; |
|||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
|||
import org.springframework.stereotype.Service; |
|||
import org.thingsboard.server.common.data.lwm2m.ServerSecurityConfig; |
|||
import org.thingsboard.server.common.transport.config.ssl.SslCredentials; |
|||
import org.thingsboard.server.transport.lwm2m.config.LwM2MSecureServerConfig; |
|||
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportBootstrapConfig; |
|||
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; |
|||
|
|||
@Slf4j |
|||
@Service |
|||
@RequiredArgsConstructor |
|||
@ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || '${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core'") |
|||
public class LwM2MServerSecurityInfoRepository { |
|||
|
|||
private final LwM2MTransportServerConfig serverConfig; |
|||
private final LwM2MTransportBootstrapConfig bootstrapConfig; |
|||
|
|||
public ServerSecurityConfig getServerSecurityInfo(boolean bootstrapServer) { |
|||
ServerSecurityConfig result = getServerSecurityConfig(bootstrapServer ? bootstrapConfig : serverConfig); |
|||
result.setBootstrapServerIs(bootstrapServer); |
|||
return result; |
|||
} |
|||
|
|||
private ServerSecurityConfig getServerSecurityConfig(LwM2MSecureServerConfig serverConfig) { |
|||
ServerSecurityConfig bsServ = new ServerSecurityConfig(); |
|||
bsServ.setServerId(serverConfig.getId()); |
|||
bsServ.setHost(serverConfig.getHost()); |
|||
bsServ.setPort(serverConfig.getPort()); |
|||
bsServ.setSecurityHost(serverConfig.getSecureHost()); |
|||
bsServ.setSecurityPort(serverConfig.getSecurePort()); |
|||
bsServ.setServerPublicKey(getPublicKey(serverConfig)); |
|||
return bsServ; |
|||
} |
|||
|
|||
private String getPublicKey(LwM2MSecureServerConfig config) { |
|||
try { |
|||
SslCredentials sslCredentials = config.getSslCredentials(); |
|||
if (sslCredentials != null) { |
|||
return Hex.encodeHexString(sslCredentials.getPublicKey().getEncoded()); |
|||
} |
|||
} catch (Exception e) { |
|||
log.trace("Failed to fetch public key from key store!", e); |
|||
|
|||
} |
|||
return ""; |
|||
} |
|||
|
|||
} |
|||
|
|||
@ -0,0 +1,24 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.lwm2m; |
|||
|
|||
import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.LwM2MServerSecurityConfigDefault; |
|||
|
|||
public interface LwM2MService { |
|||
|
|||
LwM2MServerSecurityConfigDefault getServerSecurityInfo(boolean bootstrapServer); |
|||
|
|||
} |
|||
@ -0,0 +1,99 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.lwm2m; |
|||
|
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.codec.binary.Base64; |
|||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
|||
import org.springframework.stereotype.Service; |
|||
import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.LwM2MServerSecurityConfigDefault; |
|||
import org.thingsboard.server.common.transport.config.ssl.SslCredentials; |
|||
import org.thingsboard.server.transport.lwm2m.config.LwM2MSecureServerConfig; |
|||
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportBootstrapConfig; |
|||
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; |
|||
|
|||
import java.util.Optional; |
|||
|
|||
@Slf4j |
|||
@Service |
|||
@RequiredArgsConstructor |
|||
@ConditionalOnExpression("('${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core') && '${transport.lwm2m.enabled:false}'=='true'") |
|||
public class LwM2MServiceImpl implements LwM2MService { |
|||
|
|||
private final LwM2MTransportServerConfig serverConfig; |
|||
private final Optional<LwM2MTransportBootstrapConfig> bootstrapConfig; |
|||
|
|||
@Override |
|||
public LwM2MServerSecurityConfigDefault getServerSecurityInfo(boolean bootstrapServer) { |
|||
LwM2MSecureServerConfig bsServerConfig = bootstrapServer ? bootstrapConfig.orElse(null) : serverConfig; |
|||
if (bsServerConfig!= null) { |
|||
LwM2MServerSecurityConfigDefault result = getServerSecurityConfig(bsServerConfig); |
|||
result.setBootstrapServerIs(bootstrapServer); |
|||
return result; |
|||
} |
|||
else { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
private LwM2MServerSecurityConfigDefault getServerSecurityConfig(LwM2MSecureServerConfig bsServerConfig) { |
|||
LwM2MServerSecurityConfigDefault bsServ = new LwM2MServerSecurityConfigDefault(); |
|||
bsServ.setShortServerId(bsServerConfig.getId()); |
|||
bsServ.setHost(bsServerConfig.getHost()); |
|||
bsServ.setPort(bsServerConfig.getPort()); |
|||
bsServ.setSecurityHost(bsServerConfig.getSecureHost()); |
|||
bsServ.setSecurityPort(bsServerConfig.getSecurePort()); |
|||
byte[] publicKeyBase64 = getPublicKey(bsServerConfig); |
|||
if (publicKeyBase64 == null) { |
|||
bsServ.setServerPublicKey(""); |
|||
} else { |
|||
bsServ.setServerPublicKey(Base64.encodeBase64String(publicKeyBase64)); |
|||
} |
|||
byte[] certificateBase64 = getCertificate(bsServerConfig); |
|||
if (certificateBase64 == null) { |
|||
bsServ.setServerCertificate(""); |
|||
} else { |
|||
bsServ.setServerCertificate(Base64.encodeBase64String(certificateBase64)); |
|||
} |
|||
return bsServ; |
|||
} |
|||
|
|||
private byte[] getPublicKey(LwM2MSecureServerConfig config) { |
|||
try { |
|||
SslCredentials sslCredentials = config.getSslCredentials(); |
|||
if (sslCredentials != null) { |
|||
return sslCredentials.getPublicKey().getEncoded(); |
|||
} |
|||
} catch (Exception e) { |
|||
log.trace("Failed to fetch public key from key store!", e); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
private byte[] getCertificate(LwM2MSecureServerConfig config) { |
|||
try { |
|||
SslCredentials sslCredentials = config.getSslCredentials(); |
|||
if (sslCredentials != null) { |
|||
return sslCredentials.getCertificateChain()[0].getEncoded(); |
|||
} |
|||
} catch (Exception e) { |
|||
log.trace("Failed to fetch certificate from key store!", e); |
|||
} |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,191 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.rule; |
|||
|
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Service; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.rule.engine.flow.TbRuleChainInputNode; |
|||
import org.thingsboard.rule.engine.flow.TbRuleChainInputNodeConfiguration; |
|||
import org.thingsboard.rule.engine.flow.TbRuleChainOutputNode; |
|||
import org.thingsboard.server.common.data.id.RuleChainId; |
|||
import org.thingsboard.server.common.data.id.RuleNodeId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.relation.EntityRelation; |
|||
import org.thingsboard.server.common.data.rule.RuleChain; |
|||
import org.thingsboard.server.common.data.rule.RuleChainMetaData; |
|||
import org.thingsboard.server.common.data.rule.RuleChainOutputLabelsUsage; |
|||
import org.thingsboard.server.common.data.rule.RuleChainUpdateResult; |
|||
import org.thingsboard.server.common.data.rule.RuleNode; |
|||
import org.thingsboard.server.common.data.rule.RuleNodeUpdateResult; |
|||
import org.thingsboard.server.dao.relation.RelationService; |
|||
import org.thingsboard.server.dao.rule.RuleChainService; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
|
|||
import java.util.Collections; |
|||
import java.util.Comparator; |
|||
import java.util.HashMap; |
|||
import java.util.HashSet; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.Set; |
|||
import java.util.TreeSet; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@RequiredArgsConstructor |
|||
@Service |
|||
@TbCoreComponent |
|||
@Slf4j |
|||
public class DefaultTbRuleChainService implements TbRuleChainService { |
|||
|
|||
private final RuleChainService ruleChainService; |
|||
private final RelationService relationService; |
|||
|
|||
@Override |
|||
public Set<String> getRuleChainOutputLabels(TenantId tenantId, RuleChainId ruleChainId) { |
|||
RuleChainMetaData metaData = ruleChainService.loadRuleChainMetaData(tenantId, ruleChainId); |
|||
Set<String> outputLabels = new TreeSet<>(); |
|||
for (RuleNode ruleNode : metaData.getNodes()) { |
|||
if (isOutputRuleNode(ruleNode)) { |
|||
outputLabels.add(ruleNode.getName()); |
|||
} |
|||
} |
|||
return outputLabels; |
|||
} |
|||
|
|||
@Override |
|||
public List<RuleChainOutputLabelsUsage> getOutputLabelUsage(TenantId tenantId, RuleChainId ruleChainId) { |
|||
List<RuleNode> ruleNodes = ruleChainService.findRuleNodesByTenantIdAndType(tenantId, TbRuleChainInputNode.class.getName(), ruleChainId.getId().toString()); |
|||
Map<RuleChainId, String> ruleChainNamesCache = new HashMap<>(); |
|||
// Additional filter, "just in case" the structure of the JSON configuration will change.
|
|||
var filteredRuleNodes = ruleNodes.stream().filter(node -> { |
|||
try { |
|||
TbRuleChainInputNodeConfiguration configuration = JacksonUtil.treeToValue(node.getConfiguration(), TbRuleChainInputNodeConfiguration.class); |
|||
return ruleChainId.getId().toString().equals(configuration.getRuleChainId()); |
|||
} catch (Exception e) { |
|||
log.warn("[{}][{}] Failed to decode rule node configuration", tenantId, ruleChainId, e); |
|||
return false; |
|||
} |
|||
}).collect(Collectors.toList()); |
|||
|
|||
|
|||
return filteredRuleNodes.stream() |
|||
.map(ruleNode -> { |
|||
RuleChainOutputLabelsUsage usage = new RuleChainOutputLabelsUsage(); |
|||
usage.setRuleNodeId(ruleNode.getId()); |
|||
usage.setRuleNodeName(ruleNode.getName()); |
|||
usage.setRuleChainId(ruleNode.getRuleChainId()); |
|||
List<EntityRelation> relations = ruleChainService.getRuleNodeRelations(tenantId, ruleNode.getId()); |
|||
if (relations != null && !relations.isEmpty()) { |
|||
usage.setLabels(relations.stream().map(EntityRelation::getType).collect(Collectors.toSet())); |
|||
} |
|||
return usage; |
|||
}) |
|||
.filter(usage -> usage.getLabels() != null) |
|||
.peek(usage -> { |
|||
String ruleChainName = ruleChainNamesCache.computeIfAbsent(usage.getRuleChainId(), |
|||
id -> ruleChainService.findRuleChainById(tenantId, id).getName()); |
|||
usage.setRuleChainName(ruleChainName); |
|||
}) |
|||
.sorted(Comparator |
|||
.comparing(RuleChainOutputLabelsUsage::getRuleChainName) |
|||
.thenComparing(RuleChainOutputLabelsUsage::getRuleNodeName)) |
|||
.collect(Collectors.toList()); |
|||
} |
|||
|
|||
@Override |
|||
public List<RuleChain> updateRelatedRuleChains(TenantId tenantId, RuleChainId ruleChainId, RuleChainUpdateResult result) { |
|||
Set<RuleChainId> ruleChainIds = new HashSet<>(); |
|||
log.debug("[{}][{}] Going to update links in related rule chains", tenantId, ruleChainId); |
|||
if (result.getUpdatedRuleNodes() == null || result.getUpdatedRuleNodes().isEmpty()) { |
|||
return Collections.emptyList(); |
|||
} |
|||
|
|||
Set<String> oldLabels = new HashSet<>(); |
|||
Set<String> newLabels = new HashSet<>(); |
|||
Set<String> confusedLabels = new HashSet<>(); |
|||
Map<String, String> updatedLabels = new HashMap<>(); |
|||
for (RuleNodeUpdateResult update : result.getUpdatedRuleNodes()) { |
|||
var oldNode = update.getOldRuleNode(); |
|||
var newNode = update.getNewRuleNode(); |
|||
if (isOutputRuleNode(newNode)) { |
|||
try { |
|||
oldLabels.add(oldNode.getName()); |
|||
newLabels.add(newNode.getName()); |
|||
if (!oldNode.getName().equals(newNode.getName())) { |
|||
String oldLabel = oldNode.getName(); |
|||
String newLabel = newNode.getName(); |
|||
if (updatedLabels.containsKey(oldLabel) && !updatedLabels.get(oldLabel).equals(newLabel)) { |
|||
confusedLabels.add(oldLabel); |
|||
log.warn("[{}][{}] Can't automatically rename the label from [{}] to [{}] due to conflict [{}]", tenantId, ruleChainId, oldLabel, newLabel, updatedLabels.get(oldLabel)); |
|||
} else { |
|||
updatedLabels.put(oldLabel, newLabel); |
|||
} |
|||
|
|||
} |
|||
} catch (Exception e) { |
|||
log.warn("[{}][{}][{}] Failed to decode rule node configuration", tenantId, ruleChainId, newNode.getId(), e); |
|||
} |
|||
} |
|||
} |
|||
// Remove all output labels that are renamed to two or more different labels, since we don't which new label to use;
|
|||
confusedLabels.forEach(updatedLabels::remove); |
|||
// Remove all output labels that are renamed but still present in the rule chain;
|
|||
newLabels.forEach(updatedLabels::remove); |
|||
if (!oldLabels.equals(newLabels)) { |
|||
ruleChainIds.addAll(updateRelatedRuleChains(tenantId, ruleChainId, updatedLabels)); |
|||
} |
|||
return ruleChainIds.stream().map(id -> ruleChainService.findRuleChainById(tenantId, id)).collect(Collectors.toList()); |
|||
} |
|||
|
|||
public Set<RuleChainId> updateRelatedRuleChains(TenantId tenantId, RuleChainId ruleChainId, Map<String, String> labelsMap) { |
|||
Set<RuleChainId> updatedRuleChains = new HashSet<>(); |
|||
List<RuleChainOutputLabelsUsage> usageList = getOutputLabelUsage(tenantId, ruleChainId); |
|||
for (RuleChainOutputLabelsUsage usage : usageList) { |
|||
labelsMap.forEach((oldLabel, newLabel) -> { |
|||
if (usage.getLabels().contains(oldLabel)) { |
|||
updatedRuleChains.add(usage.getRuleChainId()); |
|||
renameOutgoingLinks(tenantId, usage.getRuleNodeId(), oldLabel, newLabel); |
|||
} |
|||
}); |
|||
} |
|||
return updatedRuleChains; |
|||
} |
|||
|
|||
private void renameOutgoingLinks(TenantId tenantId, RuleNodeId ruleNodeId, String oldLabel, String newLabel) { |
|||
List<EntityRelation> relations = ruleChainService.getRuleNodeRelations(tenantId, ruleNodeId); |
|||
for (EntityRelation relation : relations) { |
|||
if (relation.getType().equals(oldLabel)) { |
|||
relationService.deleteRelation(tenantId, relation); |
|||
relation.setType(newLabel); |
|||
relationService.saveRelation(tenantId, relation); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private boolean isOutputRuleNode(RuleNode ruleNode) { |
|||
return isRuleNode(ruleNode, TbRuleChainOutputNode.class); |
|||
} |
|||
|
|||
private boolean isInputRuleNode(RuleNode ruleNode) { |
|||
return isRuleNode(ruleNode, TbRuleChainInputNode.class); |
|||
} |
|||
|
|||
private boolean isRuleNode(RuleNode ruleNode, Class<?> clazz) { |
|||
return ruleNode != null && ruleNode.getType().equals(clazz.getName()); |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.rule; |
|||
|
|||
import org.thingsboard.server.common.data.id.RuleChainId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.rule.RuleChain; |
|||
import org.thingsboard.server.common.data.rule.RuleChainOutputLabelsUsage; |
|||
import org.thingsboard.server.common.data.rule.RuleChainUpdateResult; |
|||
|
|||
import java.util.List; |
|||
import java.util.Set; |
|||
|
|||
public interface TbRuleChainService { |
|||
|
|||
Set<String> getRuleChainOutputLabels(TenantId tenantId, RuleChainId ruleChainId); |
|||
|
|||
List<RuleChainOutputLabelsUsage> getOutputLabelUsage(TenantId tenantId, RuleChainId ruleChainId); |
|||
|
|||
List<RuleChain> updateRelatedRuleChains(TenantId tenantId, RuleChainId ruleChainId, RuleChainUpdateResult result); |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.transport; |
|||
|
|||
enum BasicCredentialsValidationResult {HASH_MISMATCH, PASSWORD_MISMATCH, VALID} |
|||
@ -0,0 +1,257 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.actors; |
|||
|
|||
import org.junit.jupiter.api.Test; |
|||
import org.junit.jupiter.api.extension.ExtendWith; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
|||
import org.springframework.boot.test.mock.mockito.MockBean; |
|||
import org.springframework.data.redis.core.RedisTemplate; |
|||
import org.springframework.test.context.ContextConfiguration; |
|||
import org.springframework.test.context.TestPropertySource; |
|||
import org.springframework.test.context.junit.jupiter.SpringExtension; |
|||
import org.thingsboard.rule.engine.api.MailService; |
|||
import org.thingsboard.rule.engine.api.SmsService; |
|||
import org.thingsboard.rule.engine.api.sms.SmsSenderFactory; |
|||
import org.thingsboard.server.actors.service.ActorService; |
|||
import org.thingsboard.server.cluster.TbClusterService; |
|||
import org.thingsboard.server.common.transport.util.DataDecodingEncodingService; |
|||
import org.thingsboard.server.dao.asset.AssetService; |
|||
import org.thingsboard.server.dao.attributes.AttributesService; |
|||
import org.thingsboard.server.dao.audit.AuditLogService; |
|||
import org.thingsboard.server.dao.cassandra.CassandraCluster; |
|||
import org.thingsboard.server.dao.customer.CustomerService; |
|||
import org.thingsboard.server.dao.dashboard.DashboardService; |
|||
import org.thingsboard.server.dao.device.ClaimDevicesService; |
|||
import org.thingsboard.server.dao.device.DeviceService; |
|||
import org.thingsboard.server.dao.edge.EdgeEventService; |
|||
import org.thingsboard.server.dao.edge.EdgeService; |
|||
import org.thingsboard.server.dao.entityview.EntityViewService; |
|||
import org.thingsboard.server.dao.event.EventService; |
|||
import org.thingsboard.server.dao.nosql.CassandraBufferedRateReadExecutor; |
|||
import org.thingsboard.server.dao.nosql.CassandraBufferedRateWriteExecutor; |
|||
import org.thingsboard.server.dao.ota.OtaPackageService; |
|||
import org.thingsboard.server.dao.relation.RelationService; |
|||
import org.thingsboard.server.dao.resource.ResourceService; |
|||
import org.thingsboard.server.dao.rule.RuleChainService; |
|||
import org.thingsboard.server.dao.rule.RuleNodeStateService; |
|||
import org.thingsboard.server.dao.tenant.TbTenantProfileCache; |
|||
import org.thingsboard.server.dao.tenant.TenantProfileService; |
|||
import org.thingsboard.server.dao.tenant.TenantService; |
|||
import org.thingsboard.server.dao.timeseries.TimeseriesService; |
|||
import org.thingsboard.server.dao.user.UserService; |
|||
import org.thingsboard.server.queue.discovery.PartitionService; |
|||
import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
|||
import org.thingsboard.server.queue.usagestats.TbApiUsageClient; |
|||
import org.thingsboard.server.service.apiusage.TbApiUsageStateService; |
|||
import org.thingsboard.server.service.component.ComponentDiscoveryService; |
|||
import org.thingsboard.server.service.edge.rpc.EdgeRpcService; |
|||
import org.thingsboard.server.service.executors.DbCallbackExecutorService; |
|||
import org.thingsboard.server.service.executors.ExternalCallExecutorService; |
|||
import org.thingsboard.server.service.executors.SharedEventLoopGroupService; |
|||
import org.thingsboard.server.service.mail.MailExecutorService; |
|||
import org.thingsboard.server.service.profile.TbDeviceProfileCache; |
|||
import org.thingsboard.server.service.rpc.TbCoreDeviceRpcService; |
|||
import org.thingsboard.server.service.rpc.TbRpcService; |
|||
import org.thingsboard.server.service.rpc.TbRuleEngineDeviceRpcService; |
|||
import org.thingsboard.server.service.script.JsInvokeService; |
|||
import org.thingsboard.server.service.session.DeviceSessionCacheService; |
|||
import org.thingsboard.server.service.sms.SmsExecutorService; |
|||
import org.thingsboard.server.service.state.DeviceStateService; |
|||
import org.thingsboard.server.service.telemetry.AlarmSubscriptionService; |
|||
import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService; |
|||
import org.thingsboard.server.service.transport.TbCoreToTransportService; |
|||
|
|||
import static org.assertj.core.api.Assertions.assertThat; |
|||
|
|||
@ExtendWith(SpringExtension.class) |
|||
@ContextConfiguration(classes = ActorSystemContext.class) |
|||
@EnableConfigurationProperties |
|||
@TestPropertySource(properties = { |
|||
"cache.type=caffeine", |
|||
}) |
|||
public class ActorSystemContextTest { |
|||
|
|||
@Autowired |
|||
ActorSystemContext ctx; |
|||
|
|||
@MockBean |
|||
private TbApiUsageStateService apiUsageStateService; |
|||
|
|||
@MockBean |
|||
private TbApiUsageClient apiUsageClient; |
|||
|
|||
@MockBean |
|||
private TbServiceInfoProvider serviceInfoProvider; |
|||
|
|||
@MockBean |
|||
private ActorService actorService; |
|||
|
|||
@MockBean |
|||
private ComponentDiscoveryService componentService; |
|||
|
|||
@MockBean |
|||
private DataDecodingEncodingService encodingService; |
|||
|
|||
@MockBean |
|||
private DeviceService deviceService; |
|||
|
|||
@MockBean |
|||
private TbTenantProfileCache tenantProfileCache; |
|||
|
|||
@MockBean |
|||
private TbDeviceProfileCache deviceProfileCache; |
|||
|
|||
@MockBean |
|||
private AssetService assetService; |
|||
|
|||
@MockBean |
|||
private DashboardService dashboardService; |
|||
|
|||
@MockBean |
|||
private TenantService tenantService; |
|||
|
|||
@MockBean |
|||
private TenantProfileService tenantProfileService; |
|||
|
|||
@MockBean |
|||
private CustomerService customerService; |
|||
|
|||
@MockBean |
|||
private UserService userService; |
|||
|
|||
@MockBean |
|||
private RuleChainService ruleChainService; |
|||
|
|||
@MockBean |
|||
private RuleNodeStateService ruleNodeStateService; |
|||
|
|||
@MockBean |
|||
private PartitionService partitionService; |
|||
|
|||
@MockBean |
|||
private TbClusterService clusterService; |
|||
|
|||
@MockBean |
|||
private TimeseriesService tsService; |
|||
|
|||
@MockBean |
|||
private AttributesService attributesService; |
|||
|
|||
@MockBean |
|||
private EventService eventService; |
|||
|
|||
@MockBean |
|||
private RelationService relationService; |
|||
|
|||
@MockBean |
|||
private AuditLogService auditLogService; |
|||
|
|||
@MockBean |
|||
private EntityViewService entityViewService; |
|||
|
|||
@MockBean |
|||
private TelemetrySubscriptionService tsSubService; |
|||
|
|||
@MockBean |
|||
private AlarmSubscriptionService alarmService; |
|||
|
|||
@MockBean |
|||
private JsInvokeService jsSandbox; |
|||
|
|||
@MockBean |
|||
private MailExecutorService mailExecutor; |
|||
|
|||
@MockBean |
|||
private SmsExecutorService smsExecutor; |
|||
|
|||
@MockBean |
|||
private DbCallbackExecutorService dbCallbackExecutor; |
|||
|
|||
@MockBean |
|||
private ExternalCallExecutorService externalCallExecutorService; |
|||
|
|||
@MockBean |
|||
private SharedEventLoopGroupService sharedEventLoopGroupService; |
|||
|
|||
@MockBean |
|||
private MailService mailService; |
|||
|
|||
@MockBean |
|||
private SmsService smsService; |
|||
|
|||
@MockBean |
|||
private SmsSenderFactory smsSenderFactory; |
|||
|
|||
@MockBean |
|||
private ClaimDevicesService claimDevicesService; |
|||
|
|||
@MockBean |
|||
private JsInvokeStats jsInvokeStats; |
|||
|
|||
@MockBean |
|||
private DeviceStateService deviceStateService; |
|||
|
|||
@MockBean |
|||
private DeviceSessionCacheService deviceSessionCacheService; |
|||
|
|||
@MockBean |
|||
private TbCoreToTransportService tbCoreToTransportService; |
|||
|
|||
@MockBean |
|||
private TbRuleEngineDeviceRpcService tbRuleEngineDeviceRpcService; |
|||
|
|||
@MockBean |
|||
private TbCoreDeviceRpcService tbCoreDeviceRpcService; |
|||
|
|||
@MockBean |
|||
private EdgeService edgeService; |
|||
|
|||
@MockBean |
|||
private EdgeEventService edgeEventService; |
|||
|
|||
@MockBean |
|||
private EdgeRpcService edgeRpcService; |
|||
|
|||
@MockBean |
|||
private ResourceService resourceService; |
|||
|
|||
@MockBean |
|||
private OtaPackageService otaPackageService; |
|||
|
|||
@MockBean |
|||
private TbRpcService tbRpcService; |
|||
|
|||
@MockBean |
|||
private CassandraCluster cassandraCluster; |
|||
|
|||
@MockBean |
|||
private CassandraBufferedRateReadExecutor cassandraBufferedRateReadExecutor; |
|||
|
|||
@MockBean |
|||
private CassandraBufferedRateWriteExecutor cassandraBufferedRateWriteExecutor; |
|||
|
|||
@MockBean |
|||
private RedisTemplate<String, Object> redisTemplate; |
|||
|
|||
@Test |
|||
void givenCaffeineCache_whenInit_thenIsLocalCacheTrue() { |
|||
assertThat(ctx.getCacheType()).isEqualTo("caffeine"); |
|||
assertThat(ctx.isLocalCacheType()).as("caffeine is the local cache type").isTrue(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.controller; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.junit.After; |
|||
import org.junit.Before; |
|||
import org.thingsboard.server.queue.memory.InMemoryStorage; |
|||
|
|||
@Slf4j |
|||
public abstract class AbstractInMemoryStorageTest { |
|||
|
|||
@Before |
|||
public void setUpInMemoryStorage() { |
|||
log.info("set up InMemoryStorage"); |
|||
cleanupInMemStorage(); |
|||
} |
|||
|
|||
@After |
|||
public void tearDownInMemoryStorage() { |
|||
log.info("tear down InMemoryStorage"); |
|||
cleanupInMemStorage(); |
|||
} |
|||
|
|||
public static void cleanupInMemStorage() { |
|||
InMemoryStorage.getInstance().cleanup(); |
|||
} |
|||
|
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue