1818
1919import static com.cloud.event.EventTypes.EVENT_NIC_CREATE;
2020import static com.cloud.event.EventTypes.EVENT_NIC_DELETE;
21+ import static com.cloud.event.EventTypes.EVENT_VM_UPDATE;
2122import static com.cloud.hypervisor.Hypervisor.HypervisorType.Functionality;
2223import static com.cloud.storage.Volume.IOPS_LIMIT;
2324import static com.cloud.utils.NumbersUtil.toHumanReadableSize;
24- import static com.cloud.vm.VirtualMachineManager.Topics.VM_LIFECYCLE;
25+ import static com.cloud.vm.VirtualMachineManager.Topics.VM_ACTION;
26+ import static com.cloud.vm.VirtualMachineManager.Topics.VM_LIFECYCLE_STATE;
2527import static org.apache.cloudstack.api.ApiConstants.MAX_IOPS;
2628import static org.apache.cloudstack.api.ApiConstants.MIN_IOPS;
2729
163165import org.apache.commons.lang3.StringUtils;
164166import org.apache.commons.lang3.builder.ToStringBuilder;
165167import org.apache.commons.lang3.builder.ToStringStyle;
168+ import org.apache.logging.log4j.util.Strings;
166169import org.jetbrains.annotations.NotNull;
167170import org.jetbrains.annotations.Nullable;
168171import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -1554,7 +1557,7 @@ private void publishVmLifecycleMessageBus(UserVm instance, @Nullable VirtualMach
15541557 event.put(ApiConstants.OLD_STATE, oldState != null ? oldState : State.Unknown);
15551558 event.put(ApiConstants.NEW_STATE, newState);
15561559 event.put(ApiConstants.TIME_STAMP, System.currentTimeMillis());
1557- messageBus.publish(_name, VM_LIFECYCLE , PublishScope.GLOBAL, event);
1560+ messageBus.publish(_name, VM_LIFECYCLE_STATE , PublishScope.GLOBAL, event);
15581561 } catch (Exception ex) {
15591562 logger.warn("Failed to publish lifecycle event for Instance: {}", instance.getUuid(), ex);
15601563 }
@@ -1576,6 +1579,24 @@ private void publishNicEventMessageBus(Long instanceId, Long accountId, Long nic
15761579 }
15771580 }
15781581
1582+ private void publishVmHostNameUpdateMessageBus(long instanceId, String oldHostName, String hostName) {
1583+ if (Strings.isBlank(hostName) || oldHostName.equalsIgnoreCase(hostName)) {
1584+ return;
1585+ }
1586+ try {
1587+ Map<String, Object> event = new HashMap<>();
1588+ event.put(ApiConstants.EVENT_ID, UUID.randomUUID().toString());
1589+ event.put(ApiConstants.INSTANCE_ID, instanceId);
1590+ event.put(ApiConstants.OLD_HOST_NAME, oldHostName);
1591+ event.put(ApiConstants.HOST_NAME, hostName);
1592+ event.put(ApiConstants.EVENT_TYPE, EVENT_VM_UPDATE);
1593+ event.put(ApiConstants.TIME_STAMP, System.currentTimeMillis());
1594+ messageBus.publish(_name, VM_ACTION, PublishScope.GLOBAL, event);
1595+ } catch (Exception ex) {
1596+ logger.error("Failed to publish Instance action event for ID: {}", instanceId, ex);
1597+ }
1598+ }
1599+
15791600 /**
15801601 * Set NIC as default if VM has no default NIC
15811602 * @param vmInstance VM instance to be checked
@@ -2964,7 +2985,7 @@ protected void updateVmExtraConfig(UserVmVO userVm, String extraConfig, boolean
29642985 }
29652986
29662987 @Override
2967- @ActionEvent(eventType = EventTypes. EVENT_VM_UPDATE, eventDescription = "updating Vm")
2988+ @ActionEvent(eventType = EVENT_VM_UPDATE, eventDescription = "updating Vm")
29682989 public UserVm updateVirtualMachine(UpdateVMCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException {
29692990 validateInputsAndPermissionForUpdateVirtualMachineCommand(cmd);
29702991
@@ -3340,6 +3361,7 @@ public UserVm updateVirtualMachine(long id, String displayName, String group, Bo
33403361 }
33413362
33423363 if (State.Running == vm.getState()) {
3364+ publishVmHostNameUpdateMessageBus(vm.getId(), vm.getHostName(), hostName);
33433365 updateDns(vm, hostName);
33443366 }
33453367
0 commit comments