Merge pull request #12612 from thingsboard/feature/gateway-dashboard-auto-branch
Resolve gateway dashboard branch automatically
This commit is contained in:
commit
8472e4f74e
@ -17,6 +17,7 @@ package org.thingsboard.server.service.entitiy.dashboard;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -30,6 +31,7 @@ import org.thingsboard.server.dao.widget.WidgetsBundleService;
|
||||
import org.thingsboard.server.queue.discovery.PartitionService;
|
||||
import org.thingsboard.server.queue.util.AfterStartUp;
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent;
|
||||
import org.thingsboard.server.service.install.ProjectInfo;
|
||||
import org.thingsboard.server.service.sync.GitSyncService;
|
||||
import org.thingsboard.server.service.sync.vc.GitRepository.FileType;
|
||||
import org.thingsboard.server.service.sync.vc.GitRepository.RepoFile;
|
||||
@ -51,10 +53,11 @@ public class DashboardSyncService {
|
||||
private final ImageService imageService;
|
||||
private final WidgetsBundleService widgetsBundleService;
|
||||
private final PartitionService partitionService;
|
||||
private final ProjectInfo projectInfo;
|
||||
|
||||
@Value("${transport.gateway.dashboard.sync.repository_url:}")
|
||||
private String repoUrl;
|
||||
@Value("${transport.gateway.dashboard.sync.branch:main}")
|
||||
@Value("${transport.gateway.dashboard.sync.branch:}")
|
||||
private String branch;
|
||||
@Value("${transport.gateway.dashboard.sync.fetch_frequency:24}")
|
||||
private int fetchFrequencyHours;
|
||||
@ -64,6 +67,9 @@ public class DashboardSyncService {
|
||||
|
||||
@AfterStartUp(order = AfterStartUp.REGULAR_SERVICE)
|
||||
public void init() throws Exception {
|
||||
if (StringUtils.isBlank(branch)) {
|
||||
branch = "release/" + projectInfo.getProjectVersion();
|
||||
}
|
||||
gitSyncService.registerSync(REPO_KEY, repoUrl, branch, TimeUnit.HOURS.toMillis(fetchFrequencyHours), this::update);
|
||||
}
|
||||
|
||||
|
||||
@ -19,7 +19,6 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.info.BuildProperties;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -33,12 +32,11 @@ import java.util.List;
|
||||
@RequiredArgsConstructor
|
||||
public class DefaultDatabaseSchemaSettingsService implements DatabaseSchemaSettingsService {
|
||||
|
||||
private static final String CURRENT_PRODUCT = "CE";
|
||||
// This list should include all versions which are compatible for the upgrade.
|
||||
// The compatibility cycle usually breaks when we have some scripts written in Java that may not work after new release.
|
||||
private static final List<String> SUPPORTED_VERSIONS_FOR_UPGRADE = List.of("3.8.0", "3.8.1");
|
||||
|
||||
private final BuildProperties buildProperties;
|
||||
private final ProjectInfo projectInfo;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Value("${install.upgrade.from_version:}")
|
||||
@ -60,8 +58,8 @@ public class DefaultDatabaseSchemaSettingsService implements DatabaseSchemaSetti
|
||||
}
|
||||
|
||||
String product = getProductFromDb();
|
||||
if (!CURRENT_PRODUCT.equals(product)) {
|
||||
onSchemaSettingsError(String.format("Upgrade failed: can't upgrade ThingsBoard %s database using ThingsBoard %s.", product, CURRENT_PRODUCT));
|
||||
if (!projectInfo.getProductType().equals(product)) {
|
||||
onSchemaSettingsError(String.format("Upgrade failed: can't upgrade ThingsBoard %s database using ThingsBoard %s.", product, projectInfo.getProductType()));
|
||||
}
|
||||
|
||||
if (dbSchemaVersion.equals(getPackageSchemaVersion())) {
|
||||
@ -87,7 +85,7 @@ public class DefaultDatabaseSchemaSettingsService implements DatabaseSchemaSetti
|
||||
public void createSchemaSettings() {
|
||||
Long schemaVersion = getSchemaVersionFromDb();
|
||||
if (schemaVersion == null) {
|
||||
jdbcTemplate.execute("INSERT INTO tb_schema_settings (schema_version, product) VALUES (" + getPackageSchemaVersionForDb() + ", '" + CURRENT_PRODUCT + "')");
|
||||
jdbcTemplate.execute("INSERT INTO tb_schema_settings (schema_version, product) VALUES (" + getPackageSchemaVersionForDb() + ", '" + projectInfo.getProductType() + "')");
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,7 +97,7 @@ public class DefaultDatabaseSchemaSettingsService implements DatabaseSchemaSetti
|
||||
@Override
|
||||
public String getPackageSchemaVersion() {
|
||||
if (packageSchemaVersion == null) {
|
||||
packageSchemaVersion = buildProperties.getVersion().replaceAll("[^\\d.]", "");
|
||||
packageSchemaVersion = projectInfo.getProjectVersion();
|
||||
}
|
||||
return packageSchemaVersion;
|
||||
}
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright © 2016-2024 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.install;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.boot.info.BuildProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ProjectInfo {
|
||||
|
||||
private final BuildProperties buildProperties;
|
||||
|
||||
public String getProjectVersion() {
|
||||
return buildProperties.getVersion().replaceAll("[^\\d.]", "");
|
||||
}
|
||||
|
||||
public String getProductType() {
|
||||
return "CE";
|
||||
}
|
||||
|
||||
}
|
||||
@ -1271,7 +1271,7 @@ transport:
|
||||
# URL of gateways dashboard repository
|
||||
repository_url: "${TB_GATEWAY_DASHBOARD_SYNC_REPOSITORY_URL:https://github.com/thingsboard/gateway-management-extensions-dist.git}"
|
||||
# Branch of gateways dashboard repository to work with
|
||||
branch: "${TB_GATEWAY_DASHBOARD_SYNC_BRANCH:main}"
|
||||
branch: "${TB_GATEWAY_DASHBOARD_SYNC_BRANCH:}"
|
||||
# Fetch frequency in hours for gateways dashboard repository
|
||||
fetch_frequency: "${TB_GATEWAY_DASHBOARD_SYNC_FETCH_FREQUENCY:24}"
|
||||
|
||||
|
||||
@ -450,7 +450,7 @@ public class GitRepository {
|
||||
}
|
||||
ObjectId result = git.getRepository().resolve(rev);
|
||||
if (result == null) {
|
||||
throw new IllegalArgumentException("Failed to parse git revision string: \"" + rev + "\"");
|
||||
throw new IllegalArgumentException("Failed to resolve '" + rev + "'");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user