Browse Source

Added postgres docker contrainer

Fixed build to run with sql enabled true
pull/158/head
volodymyr-babak 9 years ago
parent
commit
0e31cd4cb4
  1. 2
      application/src/main/java/org/thingsboard/server/ThingsboardServerApplication.java
  2. 10
      application/src/main/java/org/thingsboard/server/service/mail/DefaultMailService.java
  3. 6
      application/src/main/resources/thingsboard.yml
  4. 2
      dao/src/main/java/org/thingsboard/server/dao/cassandra/CassandraCluster.java
  5. 2
      dao/src/main/java/org/thingsboard/server/dao/component/CassandraBaseComponentDescriptorDao.java
  6. 46
      dao/src/main/java/org/thingsboard/server/dao/sql/attributes/JpaAttributesDao.java
  7. 9
      dao/src/main/java/org/thingsboard/server/dao/sql/component/JpaBaseComponentDescriptorDao.java
  8. 9
      dao/src/main/java/org/thingsboard/server/dao/sql/settings/JpaAdminSettingsDao.java
  9. 65
      dao/src/main/java/org/thingsboard/server/dao/sql/timeseries/JpaTimeseriesDao.java
  10. 2
      dao/src/main/java/org/thingsboard/server/dao/timeseries/CassandraBaseTimeseriesDao.java
  11. 9
      docker/.env
  12. 2
      docker/cassandra/Makefile
  13. 3
      docker/docker-compose.static.yml
  14. 8
      docker/docker-compose.yml
  15. 21
      docker/postgres/Dockerfile
  16. 10
      docker/postgres/Makefile
  17. 22
      docker/postgres/init-user-db.sh
  18. 2
      docker/tb-cassandra-schema/Makefile
  19. 2
      docker/tb/Makefile
  20. 2
      docker/zookeeper/Makefile
  21. 4
      pom.xml

2
application/src/main/java/org/thingsboard/server/ThingsboardServerApplication.java

@ -26,7 +26,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.Arrays; import java.util.Arrays;
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) @EnableAutoConfiguration
@SpringBootApplication @SpringBootApplication
@EnableSwagger2 @EnableSwagger2
@ComponentScan({"org.thingsboard.server"}) @ComponentScan({"org.thingsboard.server"})

10
application/src/main/java/org/thingsboard/server/service/mail/DefaultMailService.java

@ -66,9 +66,13 @@ public class DefaultMailService implements MailService {
@Override @Override
public void updateMailConfiguration() { public void updateMailConfiguration() {
AdminSettings settings = adminSettingsService.findAdminSettingsByKey("mail"); AdminSettings settings = adminSettingsService.findAdminSettingsByKey("mail");
JsonNode jsonConfig = settings.getJsonValue(); if (settings != null) {
mailSender = createMailSender(jsonConfig); JsonNode jsonConfig = settings.getJsonValue();
mailFrom = jsonConfig.get("mailFrom").asText(); 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) { private JavaMailSenderImpl createMailSender(JsonNode jsonConfig) {

6
application/src/main/resources/thingsboard.yml

@ -232,13 +232,13 @@ spring:
data: data:
jpa: jpa:
repositories: repositories:
enabled: "false" enabled: "true"
jpa: jpa:
show-sql: "false" show-sql: "false"
generate-ddl: "false" generate-ddl: "true"
database-platform: "org.hibernate.dialect.PostgreSQLDialect" database-platform: "org.hibernate.dialect.PostgreSQLDialect"
hibernate: hibernate:
ddl-auto: "none" ddl-auto: "create"
datasource: datasource:
driverClassName: "${SPRING_DRIVER_CLASS_NAME:org.postgresql.Driver}" driverClassName: "${SPRING_DRIVER_CLASS_NAME:org.postgresql.Driver}"
url: "${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/thingsboard}" url: "${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/thingsboard}"

2
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.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
@ -37,6 +38,7 @@ import java.util.List;
@Component @Component
@Slf4j @Slf4j
@Data @Data
@ConditionalOnProperty(prefix = "cassandra", value = "enabled", havingValue = "true")
public class CassandraCluster { public class CassandraCluster {
private static final String COMMA = ","; private static final String COMMA = ",";

2
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.querybuilder.Select;
import com.datastax.driver.core.utils.UUIDs; import com.datastax.driver.core.utils.UUIDs;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.id.ComponentDescriptorId; import org.thingsboard.server.common.data.id.ComponentDescriptorId;
import org.thingsboard.server.common.data.page.TextPageLink; import org.thingsboard.server.common.data.page.TextPageLink;
@ -45,6 +46,7 @@ import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
*/ */
@Component @Component
@Slf4j @Slf4j
@ConditionalOnProperty(prefix = "cassandra", value = "enabled", havingValue = "true", matchIfMissing = false)
public class CassandraBaseComponentDescriptorDao extends CassandraAbstractSearchTextDao<ComponentDescriptorEntity, ComponentDescriptor> implements ComponentDescriptorDao { public class CassandraBaseComponentDescriptorDao extends CassandraAbstractSearchTextDao<ComponentDescriptorEntity, ComponentDescriptor> implements ComponentDescriptorDao {
@Override @Override

46
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;
}
}

9
dao/src/main/java/org/thingsboard/server/dao/sql/component/JpaBaseComponentDescriptorDao.java

@ -57,11 +57,14 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp
@Override @Override
public Optional<ComponentDescriptor> saveIfNotExist(ComponentDescriptor component) { public Optional<ComponentDescriptor> saveIfNotExist(ComponentDescriptor component) {
if (component.getId() == null) {
component.setId(new ComponentDescriptorId(UUID.randomUUID()));
}
boolean exists = componentDescriptorRepository.findOne(component.getId().getId()) != null; boolean exists = componentDescriptorRepository.findOne(component.getId().getId()) != null;
if (exists) { if (!exists) {
return Optional.empty(); return Optional.of(save(component));
} }
return Optional.of(save(component)); return Optional.empty();
} }
@Override @Override

9
dao/src/main/java/org/thingsboard/server/dao/sql/settings/JpaAdminSettingsDao.java

@ -15,8 +15,11 @@
*/ */
package org.thingsboard.server.dao.sql.settings; package org.thingsboard.server.dao.sql.settings;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.AdminSettings; import org.thingsboard.server.common.data.AdminSettings;
import org.thingsboard.server.dao.DaoUtil; import org.thingsboard.server.dao.DaoUtil;
import org.thingsboard.server.dao.model.sql.AdminSettingsEntity; 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; import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_COLUMN_FAMILY_NAME;
/** @Component
* Created by Valerii Sosliuk on 5/6/2017. @Slf4j
*/ @ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true")
public class JpaAdminSettingsDao extends JpaAbstractDao<AdminSettingsEntity, AdminSettings> implements AdminSettingsDao{ public class JpaAdminSettingsDao extends JpaAbstractDao<AdminSettingsEntity, AdminSettings> implements AdminSettingsDao{
@Autowired @Autowired

65
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;
}
}

2
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 com.google.common.util.concurrent.ListenableFuture;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.id.EntityId; import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.kv.*; import org.thingsboard.server.common.data.kv.*;
@ -51,6 +52,7 @@ import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
*/ */
@Component @Component
@Slf4j @Slf4j
@ConditionalOnProperty(prefix = "cassandra", value = "enabled", havingValue = "true", matchIfMissing = false)
public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implements TimeseriesDao { public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implements TimeseriesDao {
//@Value("${cassandra.query.min_aggregation_step_ms}") //@Value("${cassandra.query.min_aggregation_step_ms}")

9
docker/.env

@ -1,7 +1,12 @@
# cassandra environment variables
CASSANDRA_DATA_DIR=/home/docker/cassandra_volume CASSANDRA_DATA_DIR=/home/docker/cassandra_volume
# cassandra schema container environment variables # cassandra schema environment variables
CREATE_SCHEMA=true CREATE_SCHEMA=true
ADD_SYSTEM_DATA=false ADD_SYSTEM_DATA=false
ADD_DEMO_DATA=false ADD_DEMO_DATA=false
CASSANDRA_URL=cassandra CASSANDRA_URL=cassandra
# postgres environment variables
POSTGRES_DATA_DIR=/home/docker/postgres_volume
POSTGRES_PASSWORD=postgres

2
docker/cassandra/Makefile

@ -7,4 +7,4 @@ build:
push: build push: build
docker push ${PROJECT}/${APP}:${VERSION} docker push ${PROJECT}/${APP}:${VERSION}
docker push ${PROJECT}/${APP}:latest docker push ${PROJECT}/${APP}:latest

3
docker/docker-compose.static.yml

@ -24,3 +24,6 @@ services:
zk: zk:
ports: ports:
- "2181:2181" - "2181:2181"
postgres:
ports:
- "5432:5432"

8
docker/docker-compose.yml

@ -46,3 +46,11 @@ services:
ports: ports:
- "2181" - "2181"
restart: always restart: always
postgres:
image: "thingsboard/postgres:1.2.4"
ports:
- "5432"
environment:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- "${POSTGRES_DATA_DIR}:/var/lib/postgresql/data"

21
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"]

10
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

22
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

2
docker/tb-cassandra-schema/Makefile

@ -11,4 +11,4 @@ build:
push: build push: build
docker push ${PROJECT}/${APP}:${VERSION} docker push ${PROJECT}/${APP}:${VERSION}
docker push ${PROJECT}/${APP}:latest docker push ${PROJECT}/${APP}:latest

2
docker/tb/Makefile

@ -9,4 +9,4 @@ build:
push: build push: build
docker push ${PROJECT}/${APP}:${VERSION} docker push ${PROJECT}/${APP}:${VERSION}
docker push ${PROJECT}/${APP}:latest docker push ${PROJECT}/${APP}:latest

2
docker/zookeeper/Makefile

@ -7,4 +7,4 @@ build:
push: build push: build
docker push ${PROJECT}/${APP}:${VERSION} docker push ${PROJECT}/${APP}:${VERSION}
docker push ${PROJECT}/${APP}:latest docker push ${PROJECT}/${APP}:latest

4
pom.xml

@ -484,6 +484,10 @@
<groupId>dom4j</groupId> <groupId>dom4j</groupId>
<artifactId>dom4j</artifactId> <artifactId>dom4j</artifactId>
</exclusion> </exclusion>
<exclusion>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
</exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency> <dependency>

Loading…
Cancel
Save