From c75d44ff03853ffbca4e68c8f1d28a3f469556e9 Mon Sep 17 00:00:00 2001 From: Thomas-Leung2021 Date: Fri, 16 Jul 2021 10:44:23 -0400 Subject: [PATCH] [WIFI-3041] create a new EquipmentCustomerChangedEvent to handle status and alarm migration --- .../models/events/EquipmentChangeType.java | 2 +- .../events/EquipmentCustomerChangedEvent.java | 41 ++++ .../controller/EquipmentController.java | 40 +--- provisioning-sp/pom.xml | 184 ++++++++++-------- .../EquipmentConfigPushTrigger.java | 44 ++++- 5 files changed, 189 insertions(+), 122 deletions(-) create mode 100644 equipment-models/src/main/java/com/telecominfraproject/wlan/equipment/models/events/EquipmentCustomerChangedEvent.java diff --git a/equipment-models/src/main/java/com/telecominfraproject/wlan/equipment/models/events/EquipmentChangeType.java b/equipment-models/src/main/java/com/telecominfraproject/wlan/equipment/models/events/EquipmentChangeType.java index 85bc05da..0c59dd22 100644 --- a/equipment-models/src/main/java/com/telecominfraproject/wlan/equipment/models/events/EquipmentChangeType.java +++ b/equipment-models/src/main/java/com/telecominfraproject/wlan/equipment/models/events/EquipmentChangeType.java @@ -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 ELEMENTS = new HashMap<>(); diff --git a/equipment-models/src/main/java/com/telecominfraproject/wlan/equipment/models/events/EquipmentCustomerChangedEvent.java b/equipment-models/src/main/java/com/telecominfraproject/wlan/equipment/models/events/EquipmentCustomerChangedEvent.java new file mode 100644 index 00000000..c007cf49 --- /dev/null +++ b/equipment-models/src/main/java/com/telecominfraproject/wlan/equipment/models/events/EquipmentCustomerChangedEvent.java @@ -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; + } +} diff --git a/equipment-service/src/main/java/com/telecominfraproject/wlan/equipment/controller/EquipmentController.java b/equipment-service/src/main/java/com/telecominfraproject/wlan/equipment/controller/EquipmentController.java index b61886dc..29a6ecfa 100644 --- a/equipment-service/src/main/java/com/telecominfraproject/wlan/equipment/controller/EquipmentController.java +++ b/equipment-service/src/main/java/com/telecominfraproject/wlan/equipment/controller/EquipmentController.java @@ -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 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; } diff --git a/provisioning-sp/pom.xml b/provisioning-sp/pom.xml index f79b8c4b..dfd0e702 100644 --- a/provisioning-sp/pom.xml +++ b/provisioning-sp/pom.xml @@ -1,97 +1,111 @@ - - 4.0.0 - - com.telecominfraproject.wlan - tip-wlan-cloud-root-pom - 1.2.0-SNAPSHOT - ../../wlan-cloud-root - + + 4.0.0 + + com.telecominfraproject.wlan + tip-wlan-cloud-root-pom + 1.2.0-SNAPSHOT + ../../wlan-cloud-root + - provisioning-sp - provisioning-sp - Stream Processors for provisioning events. - - - - base-stream-consumer - com.telecominfraproject.wlan - 1.2.0-SNAPSHOT - + provisioning-sp + provisioning-sp + Stream Processors for provisioning events. - - service-metric-models - com.telecominfraproject.wlan - 1.2.0-SNAPSHOT - + + + base-stream-consumer + com.telecominfraproject.wlan + 1.2.0-SNAPSHOT + - - system-event-models - com.telecominfraproject.wlan - 1.2.0-SNAPSHOT - + + service-metric-models + com.telecominfraproject.wlan + 1.2.0-SNAPSHOT + - - base-models - com.telecominfraproject.wlan - 1.2.0-SNAPSHOT - - - - routing-service-interface - com.telecominfraproject.wlan - 1.2.0-SNAPSHOT - - - - equipment-gateway-service-interface - com.telecominfraproject.wlan - 1.2.0-SNAPSHOT - + + system-event-models + com.telecominfraproject.wlan + 1.2.0-SNAPSHOT + - - equipment-service-interface - com.telecominfraproject.wlan - 1.2.0-SNAPSHOT - + + base-models + com.telecominfraproject.wlan + 1.2.0-SNAPSHOT + - - location-service-interface - com.telecominfraproject.wlan - 1.2.0-SNAPSHOT - + + routing-service-interface + com.telecominfraproject.wlan + 1.2.0-SNAPSHOT + - - profile-service-interface - com.telecominfraproject.wlan - 1.2.0-SNAPSHOT - - - - client-service-interface - com.telecominfraproject.wlan - 1.2.0-SNAPSHOT - - - - - equipment-models - com.telecominfraproject.wlan - 1.2.0-SNAPSHOT - - - - profile-models - com.telecominfraproject.wlan - 1.2.0-SNAPSHOT - + + equipment-gateway-service-interface + com.telecominfraproject.wlan + 1.2.0-SNAPSHOT + - - location-models - com.telecominfraproject.wlan - 1.2.0-SNAPSHOT - + + equipment-service-interface + com.telecominfraproject.wlan + 1.2.0-SNAPSHOT + - + + location-service-interface + com.telecominfraproject.wlan + 1.2.0-SNAPSHOT + + + + profile-service-interface + com.telecominfraproject.wlan + 1.2.0-SNAPSHOT + + + + client-service-interface + com.telecominfraproject.wlan + 1.2.0-SNAPSHOT + + + + alarm-service-interface + com.telecominfraproject.wlan + 1.2.0-SNAPSHOT + + + + status-service-interface + com.telecominfraproject.wlan + 1.2.0-SNAPSHOT + + + + + equipment-models + com.telecominfraproject.wlan + 1.2.0-SNAPSHOT + + + + profile-models + com.telecominfraproject.wlan + 1.2.0-SNAPSHOT + + + + location-models + com.telecominfraproject.wlan + 1.2.0-SNAPSHOT + + + diff --git a/provisioning-sp/src/main/java/com/telecominfraproject/wlan/streams/provisioning/EquipmentConfigPushTrigger.java b/provisioning-sp/src/main/java/com/telecominfraproject/wlan/streams/provisioning/EquipmentConfigPushTrigger.java index 21dda710..4feaf495 100644 --- a/provisioning-sp/src/main/java/com/telecominfraproject/wlan/streams/provisioning/EquipmentConfigPushTrigger.java +++ b/provisioning-sp/src/main/java/com/telecominfraproject/wlan/streams/provisioning/EquipmentConfigPushTrigger.java @@ -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 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); }