Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,9 @@ public Long getSyncObjId() {
}
return null;
}

@Override
public Long getApiResourceId() {
return getEntityId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
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;
Expand Down Expand Up @@ -540,6 +542,7 @@ public boolean destroyInternalLbVm(final long vmId, final Account caller, final
}

@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) {
Expand Down Expand Up @@ -928,6 +931,7 @@ protected boolean sendCommandsToInternalLbVm(final VirtualRouter internalLbVm, f
}

@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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,13 +27,16 @@

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.BDDMockito;
import org.mockito.Matchers;
Copy link

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import 'org.mockito.Matchers' is deprecated. Use 'org.mockito.ArgumentMatchers' instead, which is already imported.

Suggested change
import org.mockito.Matchers;

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harikrishna-patnala , does this make sense?
it requires line 116 to have a simple adjustment as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
Expand Down Expand Up @@ -82,6 +88,8 @@ public class InternalLBVMServiceTest extends TestCase {
@Inject
AccountDao _accountDao;

private MockedStatic<ActionEventUtils> actionEventUtilsMocked;

long validVmId = 1L;
long nonExistingVmId = 2L;
long nonInternalLbVmId = 3L;
Expand Down Expand Up @@ -120,11 +128,16 @@ public void setUp() {
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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,8 @@ public Cluster updateCluster(UpdateClusterCmd cmd) {
}

@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();

Expand All @@ -1274,6 +1276,8 @@ public Host cancelMaintenance(final CancelMaintenanceCmd cmd) {
}

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_HOST_RECONNECT, eventDescription = "reconnecting host", async = true)
public Host reconnectHost(ReconnectHostCmd cmd) throws AgentUnavailableException {
Long hostId = cmd.getId();

Expand Down Expand Up @@ -1344,7 +1348,6 @@ private boolean doMaintain(final long hostId) {
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 */
Expand Down Expand Up @@ -1472,6 +1475,8 @@ public boolean maintain(final long hostId) throws AgentUnavailableException {
}

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_MAINTENANCE_PREPARE, eventDescription = "maintenance for host", async = true)
Comment thread
harikrishna-patnala marked this conversation as resolved.
Outdated
public Host maintain(final PrepareForMaintenanceCmd cmd) {
final Long hostId = cmd.getId();
final HostVO host = _hostDao.findById(hostId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,8 @@ public Snapshot archiveSnapshot(Long snapshotId) {
}

@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) {
Expand Down
Loading