Commit 4eb164f79823f71b7d58a5248b7d5c55b7784a96
1 parent
5c0c9301
Fix for Windows installation and Alarm propagation
Showing
7 changed files
with
69 additions
and
16 deletions
... | ... | @@ -82,6 +82,8 @@ SET SQL_DATA_FOLDER=%BASE%\data\sql |
82 | 82 | SET jarfile=%BASE%\lib\${pkg.name}.jar |
83 | 83 | SET installDir=%BASE%\data |
84 | 84 | |
85 | +PUSHD %BASE%\conf | |
86 | + | |
85 | 87 | java -cp %jarfile% -Dloader.main=org.thingsboard.server.ThingsboardInstallApplication^ |
86 | 88 | -Dinstall.data_dir=%installDir%^ |
87 | 89 | -Dinstall.load_demo=%loadDemo%^ |
... | ... | @@ -92,8 +94,10 @@ java -cp %jarfile% -Dloader.main=org.thingsboard.server.ThingsboardInstallApplic |
92 | 94 | |
93 | 95 | if errorlevel 1 ( |
94 | 96 | @echo ThingsBoard installation failed! |
97 | + POPD | |
95 | 98 | exit /b %errorlevel% |
96 | 99 | ) |
100 | +POPD | |
97 | 101 | |
98 | 102 | %BASE%${pkg.name}.exe install |
99 | 103 | ... | ... |
... | ... | @@ -26,6 +26,8 @@ SET SQL_DATA_FOLDER=%BASE%\data\sql |
26 | 26 | SET jarfile=%BASE%\lib\${pkg.name}.jar |
27 | 27 | SET installDir=%BASE%\data |
28 | 28 | |
29 | +PUSHD %BASE%\conf | |
30 | + | |
29 | 31 | java -cp %jarfile% -Dloader.main=org.thingsboard.server.ThingsboardInstallApplication^ |
30 | 32 | -Dinstall.data_dir=%installDir%^ |
31 | 33 | -Dspring.jpa.hibernate.ddl-auto=none^ |
... | ... | @@ -36,8 +38,10 @@ java -cp %jarfile% -Dloader.main=org.thingsboard.server.ThingsboardInstallApplic |
36 | 38 | |
37 | 39 | if errorlevel 1 ( |
38 | 40 | @echo ThingsBoard upgrade failed! |
41 | + POPD | |
39 | 42 | exit /b %errorlevel% |
40 | 43 | ) |
44 | +POPD | |
41 | 45 | |
42 | 46 | @ECHO ThingsBoard upgraded successfully! |
43 | 47 | ... | ... |
... | ... | @@ -118,17 +118,23 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ |
118 | 118 | private Alarm createAlarm(Alarm alarm) throws InterruptedException, ExecutionException { |
119 | 119 | log.debug("New Alarm : {}", alarm); |
120 | 120 | Alarm saved = alarmDao.save(alarm); |
121 | - EntityRelationsQuery query = new EntityRelationsQuery(); | |
122 | - query.setParameters(new RelationsSearchParameters(saved.getOriginator(), EntitySearchDirection.TO, Integer.MAX_VALUE)); | |
123 | - List<EntityId> parentEntities = relationService.findByQuery(query).get().stream().map(r -> r.getFrom()).collect(Collectors.toList()); | |
124 | - for (EntityId parentId : parentEntities) { | |
125 | - createAlarmRelation(parentId, saved.getId(), saved.getStatus(), true); | |
126 | - } | |
127 | - createAlarmRelation(alarm.getOriginator(), saved.getId(), saved.getStatus(), true); | |
121 | + createAlarmRelations(saved); | |
128 | 122 | return saved; |
129 | 123 | } |
130 | 124 | |
131 | - protected ListenableFuture<Alarm> updateAlarm(Alarm update) { | |
125 | + private void createAlarmRelations(Alarm alarm) throws InterruptedException, ExecutionException { | |
126 | + if (alarm.isPropagate()) { | |
127 | + EntityRelationsQuery query = new EntityRelationsQuery(); | |
128 | + query.setParameters(new RelationsSearchParameters(alarm.getOriginator(), EntitySearchDirection.TO, Integer.MAX_VALUE)); | |
129 | + List<EntityId> parentEntities = relationService.findByQuery(query).get().stream().map(r -> r.getFrom()).collect(Collectors.toList()); | |
130 | + for (EntityId parentId : parentEntities) { | |
131 | + createAlarmRelation(parentId, alarm.getId(), alarm.getStatus(), true); | |
132 | + } | |
133 | + } | |
134 | + createAlarmRelation(alarm.getOriginator(), alarm.getId(), alarm.getStatus(), true); | |
135 | + } | |
136 | + | |
137 | + private ListenableFuture<Alarm> updateAlarm(Alarm update) { | |
132 | 138 | alarmDataValidator.validate(update); |
133 | 139 | return getAndUpdate(update.getId(), new Function<Alarm, Alarm>() { |
134 | 140 | @Nullable |
... | ... | @@ -146,8 +152,17 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ |
146 | 152 | private Alarm updateAlarm(Alarm oldAlarm, Alarm newAlarm) { |
147 | 153 | AlarmStatus oldStatus = oldAlarm.getStatus(); |
148 | 154 | AlarmStatus newStatus = newAlarm.getStatus(); |
155 | + boolean oldPropagate = oldAlarm.isPropagate(); | |
156 | + boolean newPropagate = newAlarm.isPropagate(); | |
149 | 157 | Alarm result = alarmDao.save(merge(oldAlarm, newAlarm)); |
150 | - if (oldStatus != newStatus) { | |
158 | + if (!oldPropagate && newPropagate) { | |
159 | + try { | |
160 | + createAlarmRelations(result); | |
161 | + } catch (InterruptedException | ExecutionException e) { | |
162 | + log.warn("Failed to update alarm relations [{}]", result, e); | |
163 | + throw new RuntimeException(e); | |
164 | + } | |
165 | + } else if (oldStatus != newStatus) { | |
151 | 166 | updateRelations(oldAlarm, oldStatus, newStatus); |
152 | 167 | } |
153 | 168 | return result; |
... | ... | @@ -315,16 +330,19 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ |
315 | 330 | existing.setStatus(alarm.getStatus()); |
316 | 331 | existing.setSeverity(alarm.getSeverity()); |
317 | 332 | existing.setDetails(alarm.getDetails()); |
333 | + existing.setPropagate(existing.isPropagate() || alarm.isPropagate()); | |
318 | 334 | return existing; |
319 | 335 | } |
320 | 336 | |
321 | 337 | private void updateRelations(Alarm alarm, AlarmStatus oldStatus, AlarmStatus newStatus) { |
322 | 338 | try { |
323 | - EntityRelationsQuery query = new EntityRelationsQuery(); | |
324 | - query.setParameters(new RelationsSearchParameters(alarm.getOriginator(), EntitySearchDirection.TO, Integer.MAX_VALUE)); | |
325 | - List<EntityId> parentEntities = relationService.findByQuery(query).get().stream().map(r -> r.getFrom()).collect(Collectors.toList()); | |
326 | - for (EntityId parentId : parentEntities) { | |
327 | - updateAlarmRelation(parentId, alarm.getId(), oldStatus, newStatus); | |
339 | + if (alarm.isPropagate()) { | |
340 | + EntityRelationsQuery query = new EntityRelationsQuery(); | |
341 | + query.setParameters(new RelationsSearchParameters(alarm.getOriginator(), EntitySearchDirection.TO, Integer.MAX_VALUE)); | |
342 | + List<EntityId> parentEntities = relationService.findByQuery(query).get().stream().map(r -> r.getFrom()).collect(Collectors.toList()); | |
343 | + for (EntityId parentId : parentEntities) { | |
344 | + updateAlarmRelation(parentId, alarm.getId(), oldStatus, newStatus); | |
345 | + } | |
328 | 346 | } |
329 | 347 | updateAlarmRelation(alarm.getOriginator(), alarm.getId(), oldStatus, newStatus); |
330 | 348 | } catch (ExecutionException | InterruptedException e) { | ... | ... |
... | ... | @@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
20 | 20 | import org.springframework.data.domain.PageRequest; |
21 | 21 | import org.springframework.data.repository.CrudRepository; |
22 | 22 | import org.springframework.stereotype.Component; |
23 | +import org.springframework.transaction.annotation.Transactional; | |
23 | 24 | import org.thingsboard.server.common.data.UUIDConverter; |
24 | 25 | import org.thingsboard.server.common.data.id.ComponentDescriptorId; |
25 | 26 | import org.thingsboard.server.common.data.page.TextPageLink; |
... | ... | @@ -102,11 +103,13 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp |
102 | 103 | } |
103 | 104 | |
104 | 105 | @Override |
106 | + @Transactional | |
105 | 107 | public void deleteById(ComponentDescriptorId componentId) { |
106 | 108 | removeById(componentId.getId()); |
107 | 109 | } |
108 | 110 | |
109 | 111 | @Override |
112 | + @Transactional | |
110 | 113 | public void deleteByClazz(String clazz) { |
111 | 114 | componentDescriptorRepository.deleteByClazz(clazz); |
112 | 115 | } | ... | ... |
... | ... | @@ -99,6 +99,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest { |
99 | 99 | long ts = System.currentTimeMillis(); |
100 | 100 | Alarm alarm = Alarm.builder().tenantId(tenantId).originator(childId) |
101 | 101 | .type(TEST_ALARM) |
102 | + .propagate(false) | |
102 | 103 | .severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK) |
103 | 104 | .startTs(ts).build(); |
104 | 105 | |
... | ... | @@ -121,6 +122,28 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest { |
121 | 122 | new TimePageLink(1, 0L, System.currentTimeMillis(), false) |
122 | 123 | ).build()).get(); |
123 | 124 | Assert.assertNotNull(alarms.getData()); |
125 | + Assert.assertEquals(0, alarms.getData().size()); | |
126 | + | |
127 | + created.setPropagate(true); | |
128 | + created = alarmService.createOrUpdateAlarm(created); | |
129 | + | |
130 | + // Check child relation | |
131 | + alarms = alarmService.findAlarms(AlarmQuery.builder() | |
132 | + .affectedEntityId(childId) | |
133 | + .status(AlarmStatus.ACTIVE_UNACK).pageLink( | |
134 | + new TimePageLink(1, 0L, System.currentTimeMillis(), false) | |
135 | + ).build()).get(); | |
136 | + Assert.assertNotNull(alarms.getData()); | |
137 | + Assert.assertEquals(1, alarms.getData().size()); | |
138 | + Assert.assertEquals(created, alarms.getData().get(0)); | |
139 | + | |
140 | + // Check parent relation | |
141 | + alarms = alarmService.findAlarms(AlarmQuery.builder() | |
142 | + .affectedEntityId(parentId) | |
143 | + .status(AlarmStatus.ACTIVE_UNACK).pageLink( | |
144 | + new TimePageLink(1, 0L, System.currentTimeMillis(), false) | |
145 | + ).build()).get(); | |
146 | + Assert.assertNotNull(alarms.getData()); | |
124 | 147 | Assert.assertEquals(1, alarms.getData().size()); |
125 | 148 | Assert.assertEquals(created, alarms.getData().get(0)); |
126 | 149 | ... | ... |