mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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:
parent
48648d4c45
commit
fd46e61032
@ -210,4 +210,9 @@ public class CreateSnapshotFromVMSnapshotCmd extends BaseAsyncCreateCmd {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getApiResourceId() {
|
||||||
|
return getEntityId();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,8 @@ import java.util.Map;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.naming.ConfigurationException;
|
import javax.naming.ConfigurationException;
|
||||||
|
|
||||||
|
import com.cloud.event.ActionEvent;
|
||||||
|
import com.cloud.event.EventTypes;
|
||||||
import org.apache.cloudstack.context.CallContext;
|
import org.apache.cloudstack.context.CallContext;
|
||||||
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
|
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
|
||||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||||
@ -540,6 +542,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements In
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 {
|
public VirtualRouter stopInternalLbVm(final long vmId, final boolean forced, final Account caller, final long callerUserId) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||||
final DomainRouterVO internalLbVm = _internalLbVmDao.findById(vmId);
|
final DomainRouterVO internalLbVm = _internalLbVmDao.findById(vmId);
|
||||||
if (internalLbVm == null || internalLbVm.getRole() != Role.INTERNAL_LB_VM) {
|
if (internalLbVm == null || internalLbVm.getRole() != Role.INTERNAL_LB_VM) {
|
||||||
@ -928,6 +931,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements In
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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,
|
public VirtualRouter startInternalLbVm(final long internalLbVmId, final Account caller, final long callerUserId) throws StorageUnavailableException, InsufficientCapacityException,
|
||||||
ConcurrentOperationException, ResourceUnavailableException {
|
ConcurrentOperationException, ResourceUnavailableException {
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,9 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package org.apache.cloudstack.internallbvmmgr;
|
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 static org.mockito.ArgumentMatchers.nullable;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@ -24,13 +27,15 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import com.cloud.event.ActionEventUtils;
|
||||||
import org.apache.cloudstack.context.CallContext;
|
import org.apache.cloudstack.context.CallContext;
|
||||||
import org.apache.cloudstack.network.lb.InternalLoadBalancerVMService;
|
import org.apache.cloudstack.network.lb.InternalLoadBalancerVMService;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Matchers;
|
import org.mockito.BDDMockito;
|
||||||
|
import org.mockito.MockedStatic;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
@ -82,6 +87,8 @@ public class InternalLBVMServiceTest extends TestCase {
|
|||||||
@Inject
|
@Inject
|
||||||
AccountDao _accountDao;
|
AccountDao _accountDao;
|
||||||
|
|
||||||
|
private MockedStatic<ActionEventUtils> actionEventUtilsMocked;
|
||||||
|
|
||||||
long validVmId = 1L;
|
long validVmId = 1L;
|
||||||
long nonExistingVmId = 2L;
|
long nonExistingVmId = 2L;
|
||||||
long nonInternalLbVmId = 3L;
|
long nonInternalLbVmId = 3L;
|
||||||
@ -105,7 +112,7 @@ public class InternalLBVMServiceTest extends TestCase {
|
|||||||
|
|
||||||
Mockito.when(_accountMgr.getSystemUser()).thenReturn(new UserVO(1));
|
Mockito.when(_accountMgr.getSystemUser()).thenReturn(new UserVO(1));
|
||||||
Mockito.when(_accountMgr.getSystemAccount()).thenReturn(new AccountVO(2));
|
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());
|
CallContext.register(_accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
|
||||||
|
|
||||||
final DomainRouterVO validVm =
|
final DomainRouterVO validVm =
|
||||||
@ -120,11 +127,16 @@ public class InternalLBVMServiceTest extends TestCase {
|
|||||||
Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(validVm);
|
Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(validVm);
|
||||||
Mockito.when(_domainRouterDao.findById(nonExistingVmId)).thenReturn(null);
|
Mockito.when(_domainRouterDao.findById(nonExistingVmId)).thenReturn(null);
|
||||||
Mockito.when(_domainRouterDao.findById(nonInternalLbVmId)).thenReturn(nonInternalLbVm);
|
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
|
@Override
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
|
actionEventUtilsMocked.close();
|
||||||
CallContext.unregister();
|
CallContext.unregister();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1251,6 +1251,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@DB
|
||||||
|
@ActionEvent(eventType = EventTypes.EVENT_MAINTENANCE_CANCEL, eventDescription = "cancel maintenance for host", async = true)
|
||||||
public Host cancelMaintenance(final CancelMaintenanceCmd cmd) {
|
public Host cancelMaintenance(final CancelMaintenanceCmd cmd) {
|
||||||
final Long hostId = cmd.getId();
|
final Long hostId = cmd.getId();
|
||||||
|
|
||||||
@ -1274,6 +1276,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@DB
|
||||||
|
@ActionEvent(eventType = EventTypes.EVENT_HOST_RECONNECT, eventDescription = "reconnecting host", async = true)
|
||||||
public Host reconnectHost(ReconnectHostCmd cmd) throws AgentUnavailableException {
|
public Host reconnectHost(ReconnectHostCmd cmd) throws AgentUnavailableException {
|
||||||
Long hostId = cmd.getId();
|
Long hostId = cmd.getId();
|
||||||
|
|
||||||
@ -1344,7 +1348,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
throw new CloudRuntimeException(err + e.getMessage());
|
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);
|
_agentMgr.pullAgentToMaintenance(hostId);
|
||||||
|
|
||||||
/* TODO: move below to listener */
|
/* TODO: move below to listener */
|
||||||
@ -1472,6 +1475,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@DB
|
||||||
|
@ActionEvent(eventType = EventTypes.EVENT_MAINTENANCE_PREPARE, eventDescription = "prepare maintenance for host", async = true)
|
||||||
public Host maintain(final PrepareForMaintenanceCmd cmd) {
|
public Host maintain(final PrepareForMaintenanceCmd cmd) {
|
||||||
final Long hostId = cmd.getId();
|
final Long hostId = cmd.getId();
|
||||||
final HostVO host = _hostDao.findById(hostId);
|
final HostVO host = _hostDao.findById(hostId);
|
||||||
|
|||||||
@ -492,6 +492,8 @@ public class SnapshotManagerImpl extends MutualExclusiveIdsManagerBase implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
public Snapshot backupSnapshotFromVmSnapshot(Long snapshotId, Long vmId, Long volumeId, Long vmSnapshotId) {
|
||||||
VMInstanceVO vm = _vmDao.findById(vmId);
|
VMInstanceVO vm = _vmDao.findById(vmId);
|
||||||
if (vm == null) {
|
if (vm == null) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user