thingsboard-memoizeit
Changes
dao/src/main/java/org/thingsboard/server/dao/component/CassandraBaseComponentDescriptorDao.java 2(+2 -0)
dao/src/main/java/org/thingsboard/server/dao/sql/component/JpaBaseComponentDescriptorDao.java 9(+6 -3)
docker/.env 9(+7 -2)
docker/cassandra/Makefile 2(+1 -1)
docker/docker-compose.static.yml 3(+3 -0)
docker/docker-compose.yml 8(+8 -0)
docker/postgres/Dockerfile 21(+21 -0)
docker/postgres/init-user-db.sh 22(+22 -0)
docker/postgres/Makefile 10(+10 -0)
docker/tb/Makefile 2(+1 -1)
docker/tb-cassandra-schema/Makefile 2(+1 -1)
docker/zookeeper/Makefile 2(+1 -1)
pom.xml 4(+4 -0)
Details
diff --git a/application/src/main/java/org/thingsboard/server/service/mail/DefaultMailService.java b/application/src/main/java/org/thingsboard/server/service/mail/DefaultMailService.java
index d4c0dec..f4dfb09 100644
--- a/application/src/main/java/org/thingsboard/server/service/mail/DefaultMailService.java
+++ b/application/src/main/java/org/thingsboard/server/service/mail/DefaultMailService.java
@@ -66,9 +66,13 @@ public class DefaultMailService implements MailService {
@Override
public void updateMailConfiguration() {
AdminSettings settings = adminSettingsService.findAdminSettingsByKey("mail");
- JsonNode jsonConfig = settings.getJsonValue();
- mailSender = createMailSender(jsonConfig);
- mailFrom = jsonConfig.get("mailFrom").asText();
+ if (settings != null) {
+ JsonNode jsonConfig = settings.getJsonValue();
+ mailSender = createMailSender(jsonConfig);
+ mailFrom = jsonConfig.get("mailFrom").asText();
+ } else {
+ throw new IncorrectParameterException("Failed to date mail configuration. Settings not found!");
+ }
}
private JavaMailSenderImpl createMailSender(JsonNode jsonConfig) {
diff --git a/application/src/main/java/org/thingsboard/server/ThingsboardServerApplication.java b/application/src/main/java/org/thingsboard/server/ThingsboardServerApplication.java
index 5e00ac4..b70d952 100644
--- a/application/src/main/java/org/thingsboard/server/ThingsboardServerApplication.java
+++ b/application/src/main/java/org/thingsboard/server/ThingsboardServerApplication.java
@@ -26,7 +26,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.Arrays;
-@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
+@EnableAutoConfiguration
@SpringBootApplication
@EnableSwagger2
@ComponentScan({"org.thingsboard.server"})
diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml
index 6bbce15..c797cf1 100644
--- a/application/src/main/resources/thingsboard.yml
+++ b/application/src/main/resources/thingsboard.yml
@@ -232,13 +232,13 @@ spring:
data:
jpa:
repositories:
- enabled: "false"
+ enabled: "true"
jpa:
show-sql: "false"
- generate-ddl: "false"
+ generate-ddl: "true"
database-platform: "org.hibernate.dialect.PostgreSQLDialect"
hibernate:
- ddl-auto: "none"
+ ddl-auto: "create"
datasource:
driverClassName: "${SPRING_DRIVER_CLASS_NAME:org.postgresql.Driver}"
url: "${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/thingsboard}"
diff --git a/dao/src/main/java/org/thingsboard/server/dao/cassandra/CassandraCluster.java b/dao/src/main/java/org/thingsboard/server/dao/cassandra/CassandraCluster.java
index efe05f8..6bffb3e 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/cassandra/CassandraCluster.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/cassandra/CassandraCluster.java
@@ -25,6 +25,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@@ -37,6 +38,7 @@ import java.util.List;
@Component
@Slf4j
@Data
+@ConditionalOnProperty(prefix = "cassandra", value = "enabled", havingValue = "true")
public class CassandraCluster {
private static final String COMMA = ",";
diff --git a/dao/src/main/java/org/thingsboard/server/dao/component/CassandraBaseComponentDescriptorDao.java b/dao/src/main/java/org/thingsboard/server/dao/component/CassandraBaseComponentDescriptorDao.java
index 0426a33..0c7984e 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/component/CassandraBaseComponentDescriptorDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/component/CassandraBaseComponentDescriptorDao.java
@@ -21,6 +21,7 @@ import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.datastax.driver.core.querybuilder.Select;
import com.datastax.driver.core.utils.UUIDs;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.id.ComponentDescriptorId;
import org.thingsboard.server.common.data.page.TextPageLink;
@@ -45,6 +46,7 @@ import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
*/
@Component
@Slf4j
+@ConditionalOnProperty(prefix = "cassandra", value = "enabled", havingValue = "true", matchIfMissing = false)
public class CassandraBaseComponentDescriptorDao extends CassandraAbstractSearchTextDao<ComponentDescriptorEntity, ComponentDescriptor> implements ComponentDescriptorDao {
@Override
diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/attributes/JpaAttributesDao.java b/dao/src/main/java/org/thingsboard/server/dao/sql/attributes/JpaAttributesDao.java
new file mode 100644
index 0000000..d4f1caa
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/sql/attributes/JpaAttributesDao.java
@@ -0,0 +1,46 @@
+package org.thingsboard.server.dao.sql.attributes;
+
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.ResultSetFuture;
+import com.google.common.util.concurrent.ListenableFuture;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.thingsboard.server.common.data.id.EntityId;
+import org.thingsboard.server.common.data.kv.AttributeKvEntry;
+import org.thingsboard.server.dao.attributes.AttributesDao;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+
+@Component
+@Slf4j
+@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true")
+public class JpaAttributesDao implements AttributesDao {
+
+ @Override
+ public ListenableFuture<Optional<AttributeKvEntry>> find(EntityId entityId, String attributeType, String attributeKey) {
+ return null;
+ }
+
+ @Override
+ public ListenableFuture<List<AttributeKvEntry>> find(EntityId entityId, String attributeType, Collection<String> attributeKey) {
+ return null;
+ }
+
+ @Override
+ public ListenableFuture<List<AttributeKvEntry>> findAll(EntityId entityId, String attributeType) {
+ return null;
+ }
+
+ @Override
+ public ResultSetFuture save(EntityId entityId, String attributeType, AttributeKvEntry attribute) {
+ return null;
+ }
+
+ @Override
+ public ListenableFuture<List<ResultSet>> removeAll(EntityId entityId, String scope, List<String> keys) {
+ return null;
+ }
+}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/component/JpaBaseComponentDescriptorDao.java b/dao/src/main/java/org/thingsboard/server/dao/sql/component/JpaBaseComponentDescriptorDao.java
index fec30b9..bbc442e 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/sql/component/JpaBaseComponentDescriptorDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/sql/component/JpaBaseComponentDescriptorDao.java
@@ -57,11 +57,14 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp
@Override
public Optional<ComponentDescriptor> saveIfNotExist(ComponentDescriptor component) {
+ if (component.getId() == null) {
+ component.setId(new ComponentDescriptorId(UUID.randomUUID()));
+ }
boolean exists = componentDescriptorRepository.findOne(component.getId().getId()) != null;
- if (exists) {
- return Optional.empty();
+ if (!exists) {
+ return Optional.of(save(component));
}
- return Optional.of(save(component));
+ return Optional.empty();
}
@Override
diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/settings/JpaAdminSettingsDao.java b/dao/src/main/java/org/thingsboard/server/dao/sql/settings/JpaAdminSettingsDao.java
index b1e2326..10dab03 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/sql/settings/JpaAdminSettingsDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/sql/settings/JpaAdminSettingsDao.java
@@ -15,8 +15,11 @@
*/
package org.thingsboard.server.dao.sql.settings;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.repository.CrudRepository;
+import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.AdminSettings;
import org.thingsboard.server.dao.DaoUtil;
import org.thingsboard.server.dao.model.sql.AdminSettingsEntity;
@@ -27,9 +30,9 @@ import java.util.UUID;
import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_COLUMN_FAMILY_NAME;
-/**
- * Created by Valerii Sosliuk on 5/6/2017.
- */
+@Component
+@Slf4j
+@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true")
public class JpaAdminSettingsDao extends JpaAbstractDao<AdminSettingsEntity, AdminSettings> implements AdminSettingsDao{
@Autowired
diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/timeseries/JpaTimeseriesDao.java b/dao/src/main/java/org/thingsboard/server/dao/sql/timeseries/JpaTimeseriesDao.java
new file mode 100644
index 0000000..e114d3d
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/sql/timeseries/JpaTimeseriesDao.java
@@ -0,0 +1,65 @@
+package org.thingsboard.server.dao.sql.timeseries;
+
+import com.datastax.driver.core.ResultSetFuture;
+import com.datastax.driver.core.Row;
+import com.google.common.util.concurrent.ListenableFuture;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.thingsboard.server.common.data.id.EntityId;
+import org.thingsboard.server.common.data.kv.TsKvEntry;
+import org.thingsboard.server.common.data.kv.TsKvQuery;
+import org.thingsboard.server.dao.timeseries.TimeseriesDao;
+
+import java.util.List;
+
+@Component
+@Slf4j
+@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true")
+public class JpaTimeseriesDao implements TimeseriesDao {
+
+ @Override
+ public long toPartitionTs(long ts) {
+ return 0;
+ }
+
+ @Override
+ public ListenableFuture<List<TsKvEntry>> findAllAsync(EntityId entityId, List<TsKvQuery> queries) {
+ return null;
+ }
+
+ @Override
+ public ResultSetFuture findLatest(EntityId entityId, String key) {
+ return null;
+ }
+
+ @Override
+ public ResultSetFuture findAllLatest(EntityId entityId) {
+ return null;
+ }
+
+ @Override
+ public ResultSetFuture save(EntityId entityId, long partition, TsKvEntry tsKvEntry) {
+ return null;
+ }
+
+ @Override
+ public ResultSetFuture savePartition(EntityId entityId, long partition, String key) {
+ return null;
+ }
+
+ @Override
+ public ResultSetFuture saveLatest(EntityId entityId, TsKvEntry tsKvEntry) {
+ return null;
+ }
+
+ @Override
+ public TsKvEntry convertResultToTsKvEntry(Row row) {
+ return null;
+ }
+
+ @Override
+ public List<TsKvEntry> convertResultToTsKvEntryList(List<Row> rows) {
+ return null;
+ }
+}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/timeseries/CassandraBaseTimeseriesDao.java b/dao/src/main/java/org/thingsboard/server/dao/timeseries/CassandraBaseTimeseriesDao.java
index d6c7443..4932e60 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/timeseries/CassandraBaseTimeseriesDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/timeseries/CassandraBaseTimeseriesDao.java
@@ -25,6 +25,7 @@ import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.kv.*;
@@ -51,6 +52,7 @@ import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
*/
@Component
@Slf4j
+@ConditionalOnProperty(prefix = "cassandra", value = "enabled", havingValue = "true", matchIfMissing = false)
public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implements TimeseriesDao {
//@Value("${cassandra.query.min_aggregation_step_ms}")
docker/.env 9(+7 -2)
diff --git a/docker/.env b/docker/.env
index 1c7e512..7fa0ea8 100644
--- a/docker/.env
+++ b/docker/.env
@@ -1,7 +1,12 @@
+# cassandra environment variables
CASSANDRA_DATA_DIR=/home/docker/cassandra_volume
-# cassandra schema container environment variables
+# cassandra schema environment variables
CREATE_SCHEMA=true
ADD_SYSTEM_DATA=false
ADD_DEMO_DATA=false
-CASSANDRA_URL=cassandra
\ No newline at end of file
+CASSANDRA_URL=cassandra
+
+# postgres environment variables
+POSTGRES_DATA_DIR=/home/docker/postgres_volume
+POSTGRES_PASSWORD=postgres
\ No newline at end of file
docker/cassandra/Makefile 2(+1 -1)
diff --git a/docker/cassandra/Makefile b/docker/cassandra/Makefile
index 15eb3ed..f277e9e 100644
--- a/docker/cassandra/Makefile
+++ b/docker/cassandra/Makefile
@@ -7,4 +7,4 @@ build:
push: build
docker push ${PROJECT}/${APP}:${VERSION}
- docker push ${PROJECT}/${APP}:latest
\ No newline at end of file
+ docker push ${PROJECT}/${APP}:latest
docker/docker-compose.static.yml 3(+3 -0)
diff --git a/docker/docker-compose.static.yml b/docker/docker-compose.static.yml
index 5471cb2..1071a75 100644
--- a/docker/docker-compose.static.yml
+++ b/docker/docker-compose.static.yml
@@ -24,3 +24,6 @@ services:
zk:
ports:
- "2181:2181"
+ postgres:
+ ports:
+ - "5432:5432"
\ No newline at end of file
docker/docker-compose.yml 8(+8 -0)
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
index 8367abc..29f1629 100644
--- a/docker/docker-compose.yml
+++ b/docker/docker-compose.yml
@@ -46,3 +46,11 @@ services:
ports:
- "2181"
restart: always
+ postgres:
+ image: "thingsboard/postgres:1.2.4"
+ ports:
+ - "5432"
+ environment:
+ - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
+ volumes:
+ - "${POSTGRES_DATA_DIR}:/var/lib/postgresql/data"
\ No newline at end of file
docker/postgres/Dockerfile 21(+21 -0)
diff --git a/docker/postgres/Dockerfile b/docker/postgres/Dockerfile
new file mode 100644
index 0000000..ab99775
--- /dev/null
+++ b/docker/postgres/Dockerfile
@@ -0,0 +1,21 @@
+#
+# Copyright © 2016-2017 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.
+#
+
+FROM postgres:9.6
+
+ADD init-user-db.sh /docker-entrypoint-initdb.d/init-user-db.sh
+
+CMD ["postgres"]
\ No newline at end of file
docker/postgres/init-user-db.sh 22(+22 -0)
diff --git a/docker/postgres/init-user-db.sh b/docker/postgres/init-user-db.sh
new file mode 100644
index 0000000..0efc89a
--- /dev/null
+++ b/docker/postgres/init-user-db.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+#
+# Copyright © 2016-2017 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.
+#
+
+set -e
+
+psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
+ CREATE DATABASE thingsboard;
+EOSQL
\ No newline at end of file
docker/postgres/Makefile 10(+10 -0)
diff --git a/docker/postgres/Makefile b/docker/postgres/Makefile
new file mode 100644
index 0000000..179eb6c
--- /dev/null
+++ b/docker/postgres/Makefile
@@ -0,0 +1,10 @@
+VERSION=1.2.4
+PROJECT=thingsboard
+APP=postgres
+
+build:
+ docker build --pull -t ${PROJECT}/${APP}:${VERSION} -t ${PROJECT}/${APP}:latest .
+
+push: build
+ docker push ${PROJECT}/${APP}:${VERSION}
+ docker push ${PROJECT}/${APP}:latest
docker/tb/Makefile 2(+1 -1)
diff --git a/docker/tb/Makefile b/docker/tb/Makefile
index 0d38e51..b12e5a6 100644
--- a/docker/tb/Makefile
+++ b/docker/tb/Makefile
@@ -9,4 +9,4 @@ build:
push: build
docker push ${PROJECT}/${APP}:${VERSION}
- docker push ${PROJECT}/${APP}:latest
\ No newline at end of file
+ docker push ${PROJECT}/${APP}:latest
docker/tb-cassandra-schema/Makefile 2(+1 -1)
diff --git a/docker/tb-cassandra-schema/Makefile b/docker/tb-cassandra-schema/Makefile
index 68625f4..2262c50 100644
--- a/docker/tb-cassandra-schema/Makefile
+++ b/docker/tb-cassandra-schema/Makefile
@@ -11,4 +11,4 @@ build:
push: build
docker push ${PROJECT}/${APP}:${VERSION}
- docker push ${PROJECT}/${APP}:latest
\ No newline at end of file
+ docker push ${PROJECT}/${APP}:latest
docker/zookeeper/Makefile 2(+1 -1)
diff --git a/docker/zookeeper/Makefile b/docker/zookeeper/Makefile
index 911c4f3..9ac2703 100644
--- a/docker/zookeeper/Makefile
+++ b/docker/zookeeper/Makefile
@@ -7,4 +7,4 @@ build:
push: build
docker push ${PROJECT}/${APP}:${VERSION}
- docker push ${PROJECT}/${APP}:latest
\ No newline at end of file
+ docker push ${PROJECT}/${APP}:latest
pom.xml 4(+4 -0)
diff --git a/pom.xml b/pom.xml
index dec1e44..5f87e1a 100755
--- a/pom.xml
+++ b/pom.xml
@@ -484,6 +484,10 @@
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>antlr</groupId>
+ <artifactId>antlr</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>