@Override public BackendInternal getBackend() { BackendInternal backend = mock(BackendInternal.class); when(backend.runInternalQuery( eq(VdcQueryType.GetVmsFromExportDomain), any(VdcQueryParametersBase.class))) .thenReturn(createVmQueryResult()); when(backend.runInternalQuery( eq(VdcQueryType.IsVmWithSameNameExist), any(VdcQueryParametersBase.class))) .thenReturn(createDuplicateResult()); return backend; }
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 boolean vdsUpEvent(final VDS vds) { HostStoragePoolParametersBase params = new HostStoragePoolParametersBase(vds); boolean isSucceeded = backend.runInternalAction(VdcActionType.InitVdsOnUp, params).getSucceeded(); if (isSucceeded) { ThreadPoolUtil.execute( new Runnable() { @Override public void run() { try { // migrate vms that its their default vds and failback // is on List<VmStatic> vmsToMigrate = DbFacade.getInstance().getVmStaticDao().getAllWithFailbackByVds(vds.getId()); if (!vmsToMigrate.isEmpty()) { CommandContext ctx = new CommandContext(new EngineContext()); ctx.getExecutionContext().setMonitored(true); backend.runInternalMultipleActions( VdcActionType.MigrateVmToServer, new ArrayList<>(createMigrateVmToServerParametersList(vmsToMigrate, vds)), ctx); } } catch (RuntimeException e) { log.error("Failed to initialize Vds on up: {}", e.getMessage()); log.error("Exception", e); } } }); } return isSucceeded; }
@Override public void handleVdsMaintenanceTimeout(Guid vdsId) { // try to put the host to Maintenance again. backend.runInternalAction( VdcActionType.MaintenanceNumberOfVdss, new MaintenanceNumberOfVdssParameters(Arrays.asList(vdsId), true)); }
private boolean runQuery(HttpServletResponse response, String sessionID) { boolean returnValue = false; log.debug("Calling ValidateSession query"); VdcQueryReturnValue queryReturnValue = backend.runInternalQuery( VdcQueryType.ValidateSession, new VdcQueryParametersBase(sessionID)); if (queryReturnValue != null) { returnValue = queryReturnValue.getSucceeded(); if (returnValue) { DbUser user = queryReturnValue.getReturnValue(); // We get the user name only in case the validation succeeded, and the user is an // administrator if (user.isAdmin()) { log.debug("Getting user name"); printUPNToResponse(response, getUPN(user)); } else { log.error("User '{}' is not authorized to perform operation", user.getLoginName()); returnValue = false; } } } else { log.error("Got NULL from backend.RunQuery"); } return returnValue; }
protected void expectDetach(BackendInternal backend, Guid id, Guid poolId) { VdcReturnValueBase ret = new VdcReturnValueBase(); ret.setSucceeded(true); when(backend.runInternalAction( eq(VdcActionType.DetachStorageDomainFromPool), any(DetachStorageDomainFromPoolParameters.class))) .thenReturn(ret); }
@Override public boolean connectHostToDomainsInActiveOrUnknownStatus(VDS vds) { StoragePool sp = storagePoolDao.get(vds.getStoragePoolId()); ConnectHostToStoragePoolServersParameters params = new ConnectHostToStoragePoolServersParameters(sp, vds, false); return backend .runInternalAction(VdcActionType.ConnectHostToStoragePoolServers, params) .getSucceeded(); }
private void processOnVmStopInternal(final Collection<Guid> vmIds, final Guid hostId) { for (Guid vmId : vmIds) { backend.runInternalAction( VdcActionType.ProcessDownVm, new ProcessDownVmParameters(vmId, true)); } HostDeviceManager hostDeviceManager = Injector.get(HostDeviceManager.class); hostDeviceManager.refreshHostIfAnyVmHasHostDevices(vmIds, hostId); }
@Override public void addExternallyManagedVms(List<VmStatic> externalVmList) { for (VmStatic currVm : externalVmList) { AddVmParameters params = new AddVmParameters(currVm); VdcReturnValueBase returnValue = backend.runInternalAction( VdcActionType.AddVmFromScratch, params, ExecutionHandler.createInternalJobContext()); if (!returnValue.getSucceeded()) { log.debug("Failed adding Externally managed VM '{}'", currVm.getName()); } } }
@Override public EventResult storageDomainNotOperational(Guid storageDomainId, Guid storagePoolId) { StorageDomainPoolParametersBase parameters = new StorageDomainPoolParametersBase(storageDomainId, storagePoolId); parameters.setIsInternal(true); parameters.setInactive(true); boolean isSucceeded = backend .runInternalAction( VdcActionType.DeactivateStorageDomain, parameters, ExecutionHandler.createInternalJobContext()) .getSucceeded(); return new EventResult(isSucceeded, EventType.DOMAINNOTOPERATIONAL); }
@Override public void vdsNonOperational( Guid vdsId, NonOperationalReason reason, boolean logCommand, Guid domainId, Map<String, String> customLogValues) { ExecutionHandler.updateSpecificActionJobCompleted(vdsId, VdcActionType.MaintenanceVds, false); SetNonOperationalVdsParameters tempVar = new SetNonOperationalVdsParameters(vdsId, reason, customLogValues); tempVar.setStorageDomainId(domainId); tempVar.setShouldBeLogged(logCommand); backend.runInternalAction( VdcActionType.SetNonOperationalVds, tempVar, ExecutionHandler.createInternalJobContext()); }
@Override public void storagePoolStatusChange( Guid storagePoolId, StoragePoolStatus status, AuditLogType auditLogType, EngineError error, TransactionScopeOption transactionScopeOption) { SetStoragePoolStatusParameters tempVar = new SetStoragePoolStatusParameters(storagePoolId, status, auditLogType); tempVar.setError(error); if (transactionScopeOption != null) { tempVar.setTransactionScopeOption(transactionScopeOption); } backend.runInternalAction(VdcActionType.SetStoragePoolStatus, tempVar); }
/** * Check all the failing resources retrieved from the dao. * * @param dao the dao to get the list of failing resources from * @param actionType autorecovery action * @param paramsCallback a closure to create the parameters for the autorecovery action * @param filter a filter to select the recoverable resources * @param logMsg a user-readable name for the failing resource type */ <T extends BusinessEntity<Guid>> void check( final AutoRecoverDAO<T> dao, final VdcActionType actionType, final DoWithClosure<T, VdcActionParametersBase> paramsCallback, final FilterClosure<T> filter, final String logMsg) { if (!shouldPerformRecoveryOnType(logMsg)) { log.info("Autorecovering " + logMsg + " is disabled, skipping"); return; } log.debugFormat("Checking autorecoverable {0}", logMsg); final List<T> fails = filter.filter(dao.listFailedAutorecoverables()); if (fails.size() > 0) { final BackendInternal backend = getBackend(); log.info("Autorecovering " + fails.size() + " " + logMsg); for (final T fail : fails) { log.info("Autorecovering " + logMsg + " id: " + fail.getId() + getHostName(fail)); final VdcActionParametersBase actionParams = paramsCallback.doWith(fail); actionParams.setShouldBeLogged(true); backend.runInternalAction(actionType, actionParams); } } log.debugFormat("Checking autorecoverable {0} done", logMsg); }
@Override public EventResult masterDomainNotOperational( Guid storageDomainId, Guid storagePoolId, boolean isReconstructToInactiveDomains, boolean canReconstructToCurrentMaster) { VdcActionParametersBase parameters = new ReconstructMasterParameters( storagePoolId, storageDomainId, true, isReconstructToInactiveDomains, canReconstructToCurrentMaster); boolean isSucceeded = backend .runInternalAction( VdcActionType.ReconstructMasterDomain, parameters, ExecutionHandler.createInternalJobContext()) .getSucceeded(); return new EventResult(isSucceeded, EventType.RECONSTRUCT); }
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); } } }
protected VDSBrokerFrontend setUpVdsBroker(BackendInternal backend) { VDSBrokerFrontend vdsBroker = mock(VDSBrokerFrontend.class); when(backend.getResourceManager()).thenReturn(vdsBroker); return vdsBroker; }
@Override public void processOnCpuFlagsChange(Guid vdsId) { backend.runInternalAction( VdcActionType.HandleVdsCpuFlagsOrClusterChanged, new VdsActionParameters(vdsId)); }
@Test public void statusSetInMap() { Guid storageDomainId = Guid.newGuid(); Guid poolId = Guid.newGuid(); AttachStorageDomainToPoolParameters params = new AttachStorageDomainToPoolParameters(storageDomainId, poolId); AttachStorageDomainToPoolCommand<AttachStorageDomainToPoolParameters> cmd = spy(new AttachStorageDomainToPoolCommand<>(params)); doNothing().when(cmd).attemptToActivateDomain(); doReturn(Collections.emptyList()).when(cmd).connectHostsInUpToDomainStorageServer(); doReturn(isoMapDao).when(cmd).getStoragePoolIsoMapDao(); doReturn(storagePoolDao).when(cmd).getStoragePoolDao(); doReturn(vdsDao).when(cmd).getVdsDao(); doReturn(storageDomainDao).when(cmd).getStorageDomainDao(); doReturn(storageDomainStaticDao).when(cmd).getStorageDomainStaticDao(); doReturn(vdsBrokerFrontend).when(cmd).getVdsBroker(); StoragePool pool = new StoragePool(); pool.setId(poolId); pool.setStatus(StoragePoolStatus.Up); when(storagePoolDao.get(any(Guid.class))).thenReturn(pool); when(isoMapDao.get(any(StoragePoolIsoMapId.class))).thenReturn(map); when(storageDomainDao.getForStoragePool(any(Guid.class), any(Guid.class))) .thenReturn(new StorageDomain()); when(storageDomainStaticDao.get(any(Guid.class))).thenReturn(new StorageDomainStatic()); doReturn(pool.getId()).when(cmd).getStoragePoolIdFromVds(); doReturn(backendInternal).when(cmd).getBackend(); VdcReturnValueBase vdcReturnValue = new VdcReturnValueBase(); vdcReturnValue.setSucceeded(true); when(backendInternal.runInternalAction( any(VdcActionType.class), any(VdcActionParametersBase.class), any(CommandContext.class))) .thenReturn(vdcReturnValue); StorageDomainStatic storageDomain = new StorageDomainStatic(); storageDomain.setId(Guid.newGuid()); storageDomain.setStorageDomainType(StorageDomainType.ImportExport); mockGetStorageDomainInfoVdsCommand(storageDomain); mockAttachStorageDomainVdsCommand(); when(vdsDao.get(any(Guid.class))).thenReturn(vds); doReturn(Collections.emptyList()) .when(cmd) .getEntitiesFromStorageOvfDisk(storageDomainId, pool.getId()); doReturn(Collections.emptyList()).when(cmd).getAllOVFDisks(storageDomainId, pool.getId()); doAnswer( new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { map = (StoragePoolIsoMap) invocation.getArguments()[0]; return null; } }) .when(isoMapDao) .save(any(StoragePoolIsoMap.class)); cmd.setCompensationContext(mock(CompensationContext.class)); cmd.executeCommand(); assertNotNull(map); assertEquals(StorageDomainStatus.Maintenance, map.getStatus()); }
@Override public void handleVdsVersion(Guid vdsId) { backend.runInternalAction(VdcActionType.HandleVdsVersion, new VdsActionParameters(vdsId)); }