Improved Platform Updates Service
This commit is contained in:
parent
b1884f675a
commit
9165faa341
@ -15,8 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.server.service.notification.rule.trigger;
|
package org.thingsboard.server.service.notification.rule.trigger;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.thingsboard.common.util.JacksonUtil;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.common.data.notification.info.NewPlatformVersionNotificationInfo;
|
import org.thingsboard.server.common.data.notification.info.NewPlatformVersionNotificationInfo;
|
||||||
import org.thingsboard.server.common.data.notification.info.NotificationInfo;
|
import org.thingsboard.server.common.data.notification.info.NotificationInfo;
|
||||||
@ -44,7 +46,7 @@ public class NewPlatformVersionTriggerProcessor implements NotificationRuleTrigg
|
|||||||
@Override
|
@Override
|
||||||
public NotificationInfo constructNotificationInfo(NewPlatformVersionTrigger trigger, NewPlatformVersionNotificationRuleTriggerConfig triggerConfig) {
|
public NotificationInfo constructNotificationInfo(NewPlatformVersionTrigger trigger, NewPlatformVersionNotificationRuleTriggerConfig triggerConfig) {
|
||||||
return NewPlatformVersionNotificationInfo.builder()
|
return NewPlatformVersionNotificationInfo.builder()
|
||||||
.message("New version available - " + trigger.getMessage().getLatestVersion())
|
.message(JacksonUtil.convertValue(trigger.getMessage(), new TypeReference<>() {}))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -78,7 +78,7 @@ public class DefaultUpdateService implements UpdateService {
|
|||||||
@PostConstruct
|
@PostConstruct
|
||||||
private void init() {
|
private void init() {
|
||||||
version = buildProperties != null ? buildProperties.getVersion() : "unknown";
|
version = buildProperties != null ? buildProperties.getVersion() : "unknown";
|
||||||
updateMessage = new UpdateMessage(false, version, "", "");
|
updateMessage = new UpdateMessage(false, version, "", "", "", "");
|
||||||
if (updatesEnabled) {
|
if (updatesEnabled) {
|
||||||
try {
|
try {
|
||||||
platform = System.getProperty("platform", "unknown");
|
platform = System.getProperty("platform", "unknown");
|
||||||
@ -129,14 +129,8 @@ public class DefaultUpdateService implements UpdateService {
|
|||||||
request.put(PLATFORM_PARAM, platform);
|
request.put(PLATFORM_PARAM, platform);
|
||||||
request.put(VERSION_PARAM, version);
|
request.put(VERSION_PARAM, version);
|
||||||
request.put(INSTANCE_ID_PARAM, instanceId.toString());
|
request.put(INSTANCE_ID_PARAM, instanceId.toString());
|
||||||
JsonNode response = restClient.postForObject(UPDATE_SERVER_BASE_URL + "/api/thingsboard/updates", request, JsonNode.class);
|
|
||||||
UpdateMessage prevUpdateMessage = updateMessage;
|
UpdateMessage prevUpdateMessage = updateMessage;
|
||||||
updateMessage = new UpdateMessage(
|
updateMessage = restClient.postForObject(UPDATE_SERVER_BASE_URL + "/api/v2/thingsboard/updates", request, UpdateMessage.class);
|
||||||
response.get("updateAvailable").asBoolean(),
|
|
||||||
version,
|
|
||||||
"3.5.0",
|
|
||||||
"https://thingsboard.io/docs/user-guide/install/pe/upgrade-instructions"
|
|
||||||
);
|
|
||||||
if (updateMessage.isUpdateAvailable() && !updateMessage.equals(prevUpdateMessage)) {
|
if (updateMessage.isUpdateAvailable() && !updateMessage.equals(prevUpdateMessage)) {
|
||||||
notificationRuleProcessingService.process(TenantId.SYS_TENANT_ID, NewPlatformVersionTrigger.builder()
|
notificationRuleProcessingService.process(TenantId.SYS_TENANT_ID, NewPlatformVersionTrigger.builder()
|
||||||
.message(updateMessage)
|
.message(updateMessage)
|
||||||
|
|||||||
@ -24,13 +24,17 @@ import lombok.Data;
|
|||||||
public class UpdateMessage {
|
public class UpdateMessage {
|
||||||
|
|
||||||
@ApiModelProperty(position = 1, value = "'True' if new platform update is available.")
|
@ApiModelProperty(position = 1, value = "'True' if new platform update is available.")
|
||||||
private final boolean isUpdateAvailable;
|
private final boolean updateAvailable;
|
||||||
@ApiModelProperty(position = 2, value = "Current ThingsBoard version.")
|
@ApiModelProperty(position = 2, value = "Current ThingsBoard version.")
|
||||||
private final String currentVersion;
|
private final String currentVersion;
|
||||||
@ApiModelProperty(position = 3, value = "Latest ThingsBoard version.")
|
@ApiModelProperty(position = 3, value = "Latest ThingsBoard version.")
|
||||||
private final String latestVersion;
|
private final String latestVersion;
|
||||||
@ApiModelProperty(position = 4, value = "Upgrade instructions URL.")
|
@ApiModelProperty(position = 4, value = "Upgrade instructions URL.")
|
||||||
private final String upgradeInstructionsUrl;
|
private final String upgradeInstructionsUrl;
|
||||||
|
@ApiModelProperty(position = 5, value = "Current ThingsBoard version release notes URL.")
|
||||||
|
private final String currentVersionReleaseNotesUrl;
|
||||||
|
@ApiModelProperty(position = 6, value = "Latest ThingsBoard version release notes URL.")
|
||||||
|
private final String latestVersionReleaseNotesUrl;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.thingsboard.server.common.data.UpdateMessage;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -30,13 +31,11 @@ import static org.thingsboard.server.common.data.util.CollectionsUtil.mapOf;
|
|||||||
@Builder
|
@Builder
|
||||||
public class NewPlatformVersionNotificationInfo implements NotificationInfo {
|
public class NewPlatformVersionNotificationInfo implements NotificationInfo {
|
||||||
|
|
||||||
private String message;
|
private Map<String, String> message;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> getTemplateData() {
|
public Map<String, String> getTemplateData() {
|
||||||
return mapOf(
|
return message;
|
||||||
"message", message
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user