private void setupMock() throws Exception { vdsBrokerFrontend = mock(VDSBrokerFrontend.class); clusterUtils = mock(ClusterUtils.class); vdsDaoMock = mock(VdsDao.class); vdsGroupDaoMock = mock(VdsGroupDao.class); dbUtils = mock(GlusterDBUtils.class); backendInternal = mock(BackendInternal.class); doReturn(vdsBrokerFrontend).when(getQuery()).getResourceManager(); doReturn(clusterUtils).when(getQuery()).getClusterUtils(); doReturn(dbUtils).when(getQuery()).getDbUtils(); doReturn(getVds(VDSStatus.Up)).when(clusterUtils).getUpServer(CLUSTER_ID); doReturn(backendInternal).when(getQuery()).getBackend(); VDSReturnValue returnValue = getVDSReturnValue(); when(vdsBrokerFrontend.RunVdsCommand( eq(VDSCommandType.GlusterServersList), any(VDSParametersBase.class))) .thenReturn(returnValue); VdcQueryReturnValue vdcReturnValue = getVdcReturnValue(); when(backendInternal.runInternalQuery( eq(VdcQueryType.GetServerSSHKeyFingerprint), any(VdcQueryParametersBase.class), any(EngineContext.class))) .thenReturn(vdcReturnValue); doReturn(params.getClusterId()).when(getQueryParameters()).getClusterId(); doReturn(true).when(getQueryParameters()).isServerKeyFingerprintRequired(); doReturn(vdsDaoMock).when(clusterUtils).getVdsDao(); doReturn(vdsGroupDaoMock).when(getQuery()).getVdsGroupDao(); doReturn(serversList).when(vdsDaoMock).getAllForVdsGroup(CLUSTER_ID); }
@Override public void removeAsyncRunningCommand(Guid vmId) { IVdsAsyncCommand command = vdsBroker.removeAsyncRunningCommand(vmId); if (command != null) { command.reportCompleted(); } }
@Override public void runningSucceded(Guid vmId) { IVdsAsyncCommand command = vdsBroker.getAsyncCommandForVm(vmId); if (command != null) { command.runningSucceded(); } }
private void expectGetDeviceList() { VDSReturnValue returnValue = new VDSReturnValue(); returnValue.setSucceeded(true); returnValue.setReturnValue(setUpLunsFromDeviceList()); when(vdsBrokerFrontendMock.runVdsCommand( eq(VDSCommandType.GetDeviceList), any(GetDeviceListVDSCommandParameters.class))) .thenReturn(returnValue); }
protected VDSBrokerFrontend expectRemove(VDSBrokerFrontend vdsBroker) { VDSReturnValue ret = new VDSReturnValue(); ret.setSucceeded(true); when(vdsBroker.RunVdsCommand( eq(VDSCommandType.RemoveVG), any(RemoveVGVDSCommandParameters.class))) .thenReturn(ret); return vdsBroker; }
private void mockAttachStorageDomainVdsCommand() { VDSReturnValue returnValue = new VDSReturnValue(); returnValue.setSucceeded(true); when(vdsBrokerFrontend.runVdsCommand( eq(VDSCommandType.AttachStorageDomain), any(AttachStorageDomainVDSCommandParameters.class))) .thenReturn(returnValue); }
@Override public void processOnVmPoweringUp(Guid vmId) { IVdsAsyncCommand command = vdsBroker.getAsyncCommandForVm(vmId); if (command != null) { command.onPowerringUp(); } }
protected VDSBrokerFrontend expectFormat(VDSBrokerFrontend vdsBroker, boolean failure) { VDSReturnValue ret = new VDSReturnValue(); ret.setSucceeded(!failure); when(vdsBroker.RunVdsCommand( eq(VDSCommandType.FormatStorageDomain), any(FormatStorageDomainVDSCommandParameters.class))) .thenReturn(ret); return vdsBroker; }
private void mockGetStorageDomainInfoVdsCommand(StorageDomainStatic storageDomain) { Pair<StorageDomainStatic, Guid> pairResult = new Pair<>(storageDomain, null); VDSReturnValue returnValueForGetStorageDomainInfo = new VDSReturnValue(); returnValueForGetStorageDomainInfo.setSucceeded(true); returnValueForGetStorageDomainInfo.setReturnValue(pairResult); when(vdsBrokerFrontend.runVdsCommand( eq(VDSCommandType.HSMGetStorageDomainInfo), any(HSMGetStorageDomainInfoVDSCommandParameters.class))) .thenReturn(returnValueForGetStorageDomainInfo); }
protected Map<String, LUNs> getLunsFromDeviceMap(StorageType storageType) { Map<String, LUNs> lunsMap = new HashMap<>(); if (getParameters().getId() == null) { return lunsMap; } VDSBrokerFrontend vdsBrokerFrontend = getVdsBroker(); GetDeviceListVDSCommandParameters parameters = new GetDeviceListVDSCommandParameters(getParameters().getId(), storageType); List<LUNs> lunsList = (List<LUNs>) vdsBrokerFrontend .RunVdsCommand(VDSCommandType.GetDeviceList, parameters) .getReturnValue(); for (LUNs lun : lunsList) { lunsMap.put(lun.getLUN_id(), lun); } return lunsMap; }
@Override public void rerun(Guid vmId) { final IVdsAsyncCommand command = vdsBroker.getAsyncCommandForVm(vmId); if (command != null) { // The command will be invoked in a different VDS in its rerun method, so we're calling // its rerun method from a new thread so that it won't be executed within our current VDSM // lock ThreadPoolUtil.execute( new Runnable() { @Override public void run() { command.rerun(); } }); } }
private void mockBackend(boolean succeeded, EngineError errorCode) { doReturn(backend).when(cmd).getBackend(); doNothing().when(cmd).startSubStep(); doReturn(asyncTaskToBeReturned).when(cmd).handleTaskReturn(asyncTaskToBeReturned); doNothing().when(cmd).updateBricksWithTaskID(asyncTaskToBeReturned); VDSReturnValue vdsReturnValue = new VDSReturnValue(); vdsReturnValue.setReturnValue(asyncTaskToBeReturned); vdsReturnValue.setSucceeded(succeeded); if (!succeeded) { vdsReturnValue.setVdsError(new VDSError(errorCode, "")); } when(vdsBrokerFrontend.runVdsCommand( eq(VDSCommandType.StartRemoveGlusterVolumeBricks), argThat(anyGlusterVolumeRemoveBricksVDSParameters()))) .thenReturn(vdsReturnValue); }
/** Test query execution */ private void internalExecuteQuery() { // Run 'GetDeviceList' command VDSReturnValue returnValue = new VDSReturnValue(); returnValue.setSucceeded(true); returnValue.setReturnValue(lunsInput); when(vdsBrokerFrontendMock.RunVdsCommand( eq(VDSCommandType.GetDeviceList), any(GetDeviceListVDSCommandParameters.class))) .thenReturn(returnValue); // Return 'lunsFromDb' when(lunDaoMock.getAll()).thenReturn(lunsFromDb); // Execute command getQuery().executeQueryCommand(); // Assert the query's results List<LUNs> lunsActual = getQuery().getQueryReturnValue().getReturnValue(); assertEquals(lunsExpected, lunsActual); }
private void processStorageOnVdsInactive(final VDS vds) { // Clear the problematic timers since the VDS is in maintenance so it doesn't make sense to // check it // anymore. if (!Guid.Empty.equals(vds.getStoragePoolId())) { // when vds is being moved to maintenance, this is the part in which we disconnect it from the // pool // and the storage server. it should be synced with the host autorecovery mechanism to try to // avoid // leaving the host with storage/pool connection when it's on maintenance. EngineLock lock = new EngineLock( Collections.singletonMap( vds.getId().toString(), new Pair<>( LockingGroup.VDS_POOL_AND_STORAGE_CONNECTIONS.toString(), EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED.toString())), null); try { LockManagerFactory.getLockManager().acquireLockWait(lock); clearDomainCache(vds); stopGlusterServices(vds); StoragePool storage_pool = storagePoolDao.get(vds.getStoragePoolId()); if (StoragePoolStatus.Uninitialized != storage_pool.getStatus()) { vdsBroker.runVdsCommand( VDSCommandType.DisconnectStoragePool, new DisconnectStoragePoolVDSCommandParameters( vds.getId(), vds.getStoragePoolId(), vds.getVdsSpmId())); HostStoragePoolParametersBase params = new HostStoragePoolParametersBase(storage_pool, vds); backend.runInternalAction(VdcActionType.DisconnectHostFromStoragePoolServers, params); } } finally { LockManagerFactory.getLockManager().releaseLock(lock); } } }