Added events for snapshots, vmsnapshots, internalLB operations (#11230)

* Added events for snapshots, vmsnapshots, internalLB operations

* Update server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com>

* small fix

* Unit test - ArgumentMatchers change

Co-authored-by: dahn <daan.hoogland@gmail.com>

* Unit test - ArgumentMatchers change

Co-authored-by: dahn <daan.hoogland@gmail.com>

---------

Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com>
Co-authored-by: dahn <daan.hoogland@gmail.com>
This commit is contained in:
Harikrishna 2025-09-02 18:02:30 +05:30 committed by GitHub
parent 48648d4c45
commit fd46e61032
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 31 additions and 3 deletions

View File

@ -210,4 +210,9 @@ public class CreateSnapshotFromVMSnapshotCmd extends BaseAsyncCreateCmd {
}
return null;
}
@Override
public Long getApiResourceId() {
return getEntityId();
}
}

View File

@ -26,6 +26,8 @@ import java.util.Map;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import com.cloud.event.ActionEvent;
import com.cloud.event.EventTypes;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
@ -540,6 +542,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements In
}
@Override
@ActionEvent(eventType = EventTypes.EVENT_INTERNAL_LB_VM_STOP, eventDescription = "stopping internal LB VM", async = true)
public VirtualRouter stopInternalLbVm(final long vmId, final boolean forced, final Account caller, final long callerUserId) throws ConcurrentOperationException, ResourceUnavailableException {
final DomainRouterVO internalLbVm = _internalLbVmDao.findById(vmId);
if (internalLbVm == null || internalLbVm.getRole() != Role.INTERNAL_LB_VM) {
@ -928,6 +931,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements In
}
@Override
@ActionEvent(eventType = EventTypes.EVENT_INTERNAL_LB_VM_START, eventDescription = "starting internal LB VM", async = true)
public VirtualRouter startInternalLbVm(final long internalLbVmId, final Account caller, final long callerUserId) throws StorageUnavailableException, InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException {

View File

@ -16,6 +16,9 @@
// under the License.
package org.apache.cloudstack.internallbvmmgr;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.nullable;
import java.lang.reflect.Field;
@ -24,13 +27,15 @@ import java.util.List;
import javax.inject.Inject;
import com.cloud.event.ActionEventUtils;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.network.lb.InternalLoadBalancerVMService;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.BDDMockito;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ -82,6 +87,8 @@ public class InternalLBVMServiceTest extends TestCase {
@Inject
AccountDao _accountDao;
private MockedStatic<ActionEventUtils> actionEventUtilsMocked;
long validVmId = 1L;
long nonExistingVmId = 2L;
long nonInternalLbVmId = 3L;
@ -105,7 +112,7 @@ public class InternalLBVMServiceTest extends TestCase {
Mockito.when(_accountMgr.getSystemUser()).thenReturn(new UserVO(1));
Mockito.when(_accountMgr.getSystemAccount()).thenReturn(new AccountVO(2));
Mockito.when(_accountDao.findByIdIncludingRemoved(Matchers.anyLong())).thenReturn(new AccountVO(2));
Mockito.when(_accountDao.findByIdIncludingRemoved(anyLong())).thenReturn(new AccountVO(2));
CallContext.register(_accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
final DomainRouterVO validVm =
@ -120,11 +127,16 @@ public class InternalLBVMServiceTest extends TestCase {
Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(validVm);
Mockito.when(_domainRouterDao.findById(nonExistingVmId)).thenReturn(null);
Mockito.when(_domainRouterDao.findById(nonInternalLbVmId)).thenReturn(nonInternalLbVm);
actionEventUtilsMocked = Mockito.mockStatic(ActionEventUtils.class);
BDDMockito.given(ActionEventUtils.onStartedActionEvent(anyLong(), anyLong(), anyString(), anyString(), anyLong(), anyString(), anyBoolean(), anyLong()))
.willReturn(1L);
}
@Override
@After
public void tearDown() {
actionEventUtilsMocked.close();
CallContext.unregister();
}

View File

@ -1251,6 +1251,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
}
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_MAINTENANCE_CANCEL, eventDescription = "cancel maintenance for host", async = true)
public Host cancelMaintenance(final CancelMaintenanceCmd cmd) {
final Long hostId = cmd.getId();
@ -1274,6 +1276,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
}
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_HOST_RECONNECT, eventDescription = "reconnecting host", async = true)
public Host reconnectHost(ReconnectHostCmd cmd) throws AgentUnavailableException {
Long hostId = cmd.getId();
@ -1344,7 +1348,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
throw new CloudRuntimeException(err + e.getMessage());
}
ActionEventUtils.onStartedActionEvent(CallContext.current().getCallingUserId(), CallContext.current().getCallingAccountId(), EventTypes.EVENT_MAINTENANCE_PREPARE, "starting maintenance for host " + hostId, hostId, null, true, 0);
_agentMgr.pullAgentToMaintenance(hostId);
/* TODO: move below to listener */
@ -1472,6 +1475,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
}
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_MAINTENANCE_PREPARE, eventDescription = "prepare maintenance for host", async = true)
public Host maintain(final PrepareForMaintenanceCmd cmd) {
final Long hostId = cmd.getId();
final HostVO host = _hostDao.findById(hostId);

View File

@ -492,6 +492,8 @@ public class SnapshotManagerImpl extends MutualExclusiveIdsManagerBase implement
}
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_SNAPSHOT_CREATE, eventDescription = "creating snapshot from VM snapshot", async = true)
public Snapshot backupSnapshotFromVmSnapshot(Long snapshotId, Long vmId, Long volumeId, Long vmSnapshotId) {
VMInstanceVO vm = _vmDao.findById(vmId);
if (vm == null) {