[WIFI-3041] create a new EquipmentCustomerChangedEvent to handle status and alarm migration

This commit is contained in:
Thomas-Leung2021
2021-07-16 10:44:23 -04:00
parent 799b243cc4
commit c75d44ff03
5 changed files with 189 additions and 122 deletions

View File

@@ -10,7 +10,7 @@ import com.telecominfraproject.wlan.core.model.json.JsonDeserializationUtils;
public enum EquipmentChangeType {
All(0), ChannelsOnly(1), CellSizeAttributesOnly(2), ApImpacting(3), blinkLEDs(4), UNSUPPORTED(-1);
All(0), ChannelsOnly(1), CellSizeAttributesOnly(2), ApImpacting(3), blinkLEDs(4), CustomerOnly(5), UNSUPPORTED(-1);
private final int id;
private static final Map<Integer, EquipmentChangeType> ELEMENTS = new HashMap<>();

View File

@@ -0,0 +1,41 @@
package com.telecominfraproject.wlan.equipment.models.events;
import com.telecominfraproject.wlan.equipment.models.Equipment;
public class EquipmentCustomerChangedEvent extends EquipmentChangedEvent {
private static final long serialVersionUID = 4650302079238674307L;
private Equipment existingEquipment; // old equipment
private Equipment equipment; // new configured equipment
public EquipmentCustomerChangedEvent(Equipment existingEquipment, Equipment equipment) {
super(equipment);
setEquipmentChangeType(EquipmentChangeType.CustomerOnly);
this.setExistingEquipment(existingEquipment);
this.setEquipment(equipment);
}
/**
* Constructor used by JSON
*/
@SuppressWarnings("unused")
private EquipmentCustomerChangedEvent() {
super();
}
public Equipment getExistingEquipment() {
return existingEquipment;
}
public void setExistingEquipment(Equipment existingEquipment) {
this.existingEquipment = existingEquipment;
}
public Equipment getEquipment() {
return equipment;
}
public void setEquipment(Equipment equipment) {
this.equipment = equipment;
}
}

View File

@@ -20,8 +20,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.telecominfraproject.wlan.alarm.AlarmServiceInterface;
import com.telecominfraproject.wlan.alarm.models.Alarm;
import com.telecominfraproject.wlan.cloudeventdispatcher.CloudEventDispatcherInterface;
import com.telecominfraproject.wlan.core.model.equipment.EquipmentType;
import com.telecominfraproject.wlan.core.model.equipment.RadioType;
@@ -53,13 +51,10 @@ import com.telecominfraproject.wlan.equipment.models.events.EquipmentBlinkLEDsEv
import com.telecominfraproject.wlan.equipment.models.events.EquipmentCellSizeAttributesChangedEvent;
import com.telecominfraproject.wlan.equipment.models.events.EquipmentChangedEvent;
import com.telecominfraproject.wlan.equipment.models.events.EquipmentChannelsChangedEvent;
import com.telecominfraproject.wlan.equipment.models.events.EquipmentCustomerChangedEvent;
import com.telecominfraproject.wlan.equipment.models.events.EquipmentRemovedEvent;
import com.telecominfraproject.wlan.server.exceptions.ConfigurationException;
import com.telecominfraproject.wlan.systemevent.models.SystemEvent;
import com.telecominfraproject.wlan.status.StatusServiceInterface;
import com.telecominfraproject.wlan.status.models.Status;
import com.telecominfraproject.wlan.status.models.StatusDataType;
/**
* @author dtoptygin
@@ -78,8 +73,7 @@ public class EquipmentController {
@Autowired private EquipmentDatastore equipmentDatastore;
@Autowired private CloudEventDispatcherInterface cloudEventDispatcher;
@Autowired private StatusServiceInterface statusServiceInterface;
@Autowired private AlarmServiceInterface alarmServiceInterface;
/**
* Creates new Equipment.
*
@@ -292,36 +286,12 @@ public class EquipmentController {
} else if (existingApElementConfig != null && existingApElementConfig.isBlinkAllLEDs() != updatedApElementConfig.isBlinkAllLEDs()) {
LOG.debug("Updated BlinkingLEDs {}", ret);
event = new EquipmentBlinkLEDsEvent(ret);
}
else {
} else if (equipment.getCustomerId() != existingEquipment.getCustomerId()) {
event = new EquipmentCustomerChangedEvent(existingEquipment, ret);
} else {
event = new EquipmentChangedEvent(ret);
}
publishEvent(event);
// when customerId changes, we keep the EQUIPMENT_ADMIN and PROTOCOL status of the AP (which requires the existing data)
if (equipment.getCustomerId() != existingEquipment.getCustomerId()) {
Status status = statusServiceInterface.getOrNull(existingEquipment.getCustomerId(), existingEquipment.getId(), StatusDataType.EQUIPMENT_ADMIN);
if (status != null) {
status.setCustomerId(equipment.getCustomerId());
statusServiceInterface.update(status);
}
status = statusServiceInterface.getOrNull(existingEquipment.getCustomerId(), existingEquipment.getId(), StatusDataType.PROTOCOL);
if (status != null) {
status.setCustomerId(equipment.getCustomerId());
statusServiceInterface.update(status);
}
// Alarms has to move to new customerId as well
List<Alarm> oldCustomerAlarms = alarmServiceInterface.get(existingEquipment.getCustomerId(), Set.of(existingEquipment.getId()), null);
if (!oldCustomerAlarms.isEmpty()) {
oldCustomerAlarms.stream().forEach(a -> {
a.setCustomerId(equipment.getCustomerId());
Alarm alarm = alarmServiceInterface.create(a);
LOG.debug("Move an alarm to new customer {}", alarm);
});
}
alarmServiceInterface.delete(existingEquipment.getCustomerId(), existingEquipment.getId());
}
return ret;
}

View File

@@ -1,97 +1,111 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.telecominfraproject.wlan</groupId>
<artifactId>tip-wlan-cloud-root-pom</artifactId>
<version>1.2.0-SNAPSHOT</version>
<relativePath>../../wlan-cloud-root</relativePath>
</parent>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.telecominfraproject.wlan</groupId>
<artifactId>tip-wlan-cloud-root-pom</artifactId>
<version>1.2.0-SNAPSHOT</version>
<relativePath>../../wlan-cloud-root</relativePath>
</parent>
<artifactId>provisioning-sp</artifactId>
<name>provisioning-sp</name>
<description>Stream Processors for provisioning events.</description>
<dependencies>
<dependency>
<artifactId>base-stream-consumer</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<artifactId>provisioning-sp</artifactId>
<name>provisioning-sp</name>
<description>Stream Processors for provisioning events.</description>
<dependency>
<artifactId>service-metric-models</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependencies>
<dependency>
<artifactId>base-stream-consumer</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>system-event-models</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>service-metric-models</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>base-models</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>routing-service-interface</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>equipment-gateway-service-interface</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>system-event-models</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>equipment-service-interface</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>base-models</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>location-service-interface</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>routing-service-interface</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>profile-service-interface</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>client-service-interface</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<!-- models used by the application logic of the stream processor -->
<dependency>
<artifactId>equipment-models</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>profile-models</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>equipment-gateway-service-interface</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>location-models</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>equipment-service-interface</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
</dependencies>
<dependency>
<artifactId>location-service-interface</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>profile-service-interface</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>client-service-interface</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>alarm-service-interface</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>status-service-interface</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<!-- models used by the application logic of the stream processor -->
<dependency>
<artifactId>equipment-models</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>profile-models</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>location-models</artifactId>
<groupId>com.telecominfraproject.wlan</groupId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@@ -13,6 +13,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.telecominfraproject.wlan.alarm.AlarmServiceInterface;
import com.telecominfraproject.wlan.alarm.models.Alarm;
import com.telecominfraproject.wlan.core.model.json.BaseJsonModel;
import com.telecominfraproject.wlan.core.model.pagination.PaginationContext;
import com.telecominfraproject.wlan.core.model.pagination.PaginationResponse;
@@ -25,6 +27,7 @@ import com.telecominfraproject.wlan.equipment.models.events.EquipmentApImpacting
import com.telecominfraproject.wlan.equipment.models.events.EquipmentBlinkLEDsEvent;
import com.telecominfraproject.wlan.equipment.models.events.EquipmentCellSizeAttributesChangedEvent;
import com.telecominfraproject.wlan.equipment.models.events.EquipmentChannelsChangedEvent;
import com.telecominfraproject.wlan.equipment.models.events.EquipmentCustomerChangedEvent;
import com.telecominfraproject.wlan.equipment.models.events.EquipmentRemovedEvent;
import com.telecominfraproject.wlan.equipmentgateway.models.CEGWBaseCommand;
import com.telecominfraproject.wlan.equipmentgateway.models.CEGWBlinkRequest;
@@ -39,6 +42,9 @@ import com.telecominfraproject.wlan.profile.models.Profile;
import com.telecominfraproject.wlan.profile.models.events.ProfileAddedEvent;
import com.telecominfraproject.wlan.profile.models.events.ProfileChangedEvent;
import com.telecominfraproject.wlan.profile.models.events.ProfileRemovedEvent;
import com.telecominfraproject.wlan.status.StatusServiceInterface;
import com.telecominfraproject.wlan.status.models.Status;
import com.telecominfraproject.wlan.status.models.StatusDataType;
import com.telecominfraproject.wlan.stream.StreamProcessor;
import com.telecominfraproject.wlan.systemevent.models.SystemEvent;
import com.telecominfraproject.wlan.systemevent.models.SystemEventRecord;
@@ -65,6 +71,10 @@ public class EquipmentConfigPushTrigger extends StreamProcessor {
private ProfileServiceInterface profileServiceInterface;
@Autowired
private EquipmentServiceInterface equipmentServiceInterface;
@Autowired
private StatusServiceInterface statusServiceInterface;
@Autowired
private AlarmServiceInterface alarmServiceInterface;
@Override
protected boolean acceptMessage(QueuedStreamMessage message) {
@@ -77,7 +87,7 @@ public class EquipmentConfigPushTrigger extends StreamProcessor {
|| ser.getDetails() instanceof EquipmentChannelsChangedEvent || ser.getDetails() instanceof EquipmentCellSizeAttributesChangedEvent
|| ser.getDetails() instanceof EquipmentRemovedEvent || ser.getDetails() instanceof ProfileAddedEvent
|| ser.getDetails() instanceof ProfileChangedEvent || ser.getDetails() instanceof ProfileRemovedEvent
|| ser.getDetails() instanceof LocationChangedApImpactingEvent);
|| ser.getDetails() instanceof LocationChangedApImpactingEvent || ser.getDetails() instanceof EquipmentCustomerChangedEvent);
} else {
ret = false;
}
@@ -121,6 +131,8 @@ public class EquipmentConfigPushTrigger extends StreamProcessor {
case "LocationChangedApImpactingEvent":
process((LocationChangedApImpactingEvent) se);
break;
case "EquipmentCustomerChangedEvent":
process((EquipmentCustomerChangedEvent) se);
default:
process(mdl);
}
@@ -235,6 +247,36 @@ public class EquipmentConfigPushTrigger extends StreamProcessor {
}
private void process(EquipmentCustomerChangedEvent model) {
LOG.info("Processing EquipmentCustomerChangedEvent {}", model.getPayload().getId());
Equipment existingEquipment = model.getExistingEquipment();
Equipment equipment = model.getEquipment();
// when customerId changes, we keep the EQUIPMENT_ADMIN and PROTOCOL status of the AP
Status status = statusServiceInterface.getOrNull(existingEquipment.getCustomerId(), existingEquipment.getId(), StatusDataType.EQUIPMENT_ADMIN);
if (status != null) {
status.setCustomerId(equipment.getCustomerId());
statusServiceInterface.update(status);
}
status = statusServiceInterface.getOrNull(existingEquipment.getCustomerId(), existingEquipment.getId(), StatusDataType.PROTOCOL);
if (status != null) {
status.setCustomerId(equipment.getCustomerId());
statusServiceInterface.update(status);
}
// Alarms has to move to new customerId as well
List<Alarm> oldCustomerAlarms = alarmServiceInterface.get(existingEquipment.getCustomerId(), Set.of(existingEquipment.getId()), null);
if (!oldCustomerAlarms.isEmpty()) {
oldCustomerAlarms.stream().forEach(a -> {
a.setCustomerId(equipment.getCustomerId());
Alarm alarm = alarmServiceInterface.create(a);
LOG.debug("Move an alarm to new customer {}", alarm);
});
}
alarmServiceInterface.delete(existingEquipment.getCustomerId(), existingEquipment.getId());
}
private void process(BaseJsonModel model) {
LOG.warn("Unprocessed model: {}", model);
}