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;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.core.type.TypeReference;
 | 
			
		||||
import lombok.RequiredArgsConstructor;
 | 
			
		||||
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.notification.info.NewPlatformVersionNotificationInfo;
 | 
			
		||||
import org.thingsboard.server.common.data.notification.info.NotificationInfo;
 | 
			
		||||
@ -44,7 +46,7 @@ public class NewPlatformVersionTriggerProcessor implements NotificationRuleTrigg
 | 
			
		||||
    @Override
 | 
			
		||||
    public NotificationInfo constructNotificationInfo(NewPlatformVersionTrigger trigger, NewPlatformVersionNotificationRuleTriggerConfig triggerConfig) {
 | 
			
		||||
        return NewPlatformVersionNotificationInfo.builder()
 | 
			
		||||
                .message("New version available - " + trigger.getMessage().getLatestVersion())
 | 
			
		||||
                .message(JacksonUtil.convertValue(trigger.getMessage(), new TypeReference<>() {}))
 | 
			
		||||
                .build();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -78,7 +78,7 @@ public class DefaultUpdateService implements UpdateService {
 | 
			
		||||
    @PostConstruct
 | 
			
		||||
    private void init() {
 | 
			
		||||
        version = buildProperties != null ? buildProperties.getVersion() : "unknown";
 | 
			
		||||
        updateMessage = new UpdateMessage(false, version, "", "");
 | 
			
		||||
        updateMessage = new UpdateMessage(false, version, "", "", "", "");
 | 
			
		||||
        if (updatesEnabled) {
 | 
			
		||||
            try {
 | 
			
		||||
                platform = System.getProperty("platform", "unknown");
 | 
			
		||||
@ -129,14 +129,8 @@ public class DefaultUpdateService implements UpdateService {
 | 
			
		||||
            request.put(PLATFORM_PARAM, platform);
 | 
			
		||||
            request.put(VERSION_PARAM, version);
 | 
			
		||||
            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 = new UpdateMessage(
 | 
			
		||||
                    response.get("updateAvailable").asBoolean(),
 | 
			
		||||
                    version,
 | 
			
		||||
                    "3.5.0",
 | 
			
		||||
                    "https://thingsboard.io/docs/user-guide/install/pe/upgrade-instructions"
 | 
			
		||||
            );
 | 
			
		||||
            updateMessage = restClient.postForObject(UPDATE_SERVER_BASE_URL + "/api/v2/thingsboard/updates", request, UpdateMessage.class);
 | 
			
		||||
            if (updateMessage.isUpdateAvailable() && !updateMessage.equals(prevUpdateMessage)) {
 | 
			
		||||
                notificationRuleProcessingService.process(TenantId.SYS_TENANT_ID, NewPlatformVersionTrigger.builder()
 | 
			
		||||
                        .message(updateMessage)
 | 
			
		||||
 | 
			
		||||
@ -24,13 +24,17 @@ import lombok.Data;
 | 
			
		||||
public class UpdateMessage {
 | 
			
		||||
 | 
			
		||||
    @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.")
 | 
			
		||||
    private final String currentVersion;
 | 
			
		||||
    @ApiModelProperty(position = 3, value = "Latest ThingsBoard version.")
 | 
			
		||||
    private final String latestVersion;
 | 
			
		||||
    @ApiModelProperty(position = 4, value = "Upgrade instructions URL.")
 | 
			
		||||
    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.Data;
 | 
			
		||||
import lombok.NoArgsConstructor;
 | 
			
		||||
import org.thingsboard.server.common.data.UpdateMessage;
 | 
			
		||||
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
@ -30,13 +31,11 @@ import static org.thingsboard.server.common.data.util.CollectionsUtil.mapOf;
 | 
			
		||||
@Builder
 | 
			
		||||
public class NewPlatformVersionNotificationInfo implements NotificationInfo {
 | 
			
		||||
 | 
			
		||||
    private String message;
 | 
			
		||||
    private Map<String, String> message;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Map<String, String> getTemplateData() {
 | 
			
		||||
        return mapOf(
 | 
			
		||||
                "message", message
 | 
			
		||||
        );
 | 
			
		||||
        return message;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user