Search in sources :

Example 46 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class ActivateStorageDomainCommand method executeCommand.

@Override
protected void executeCommand() {
    if (isCinderStorageDomain()) {
        activateCinderStorageDomain();
        return;
    }
    final StoragePoolIsoMap map = storagePoolIsoMapDao.get(new StoragePoolIsoMapId(getParameters().getStorageDomainId(), getParameters().getStoragePoolId()));
    // Master domain must not go through the Activating status.
    changeStorageDomainStatusInTransaction(map, (getStorageDomain().getStorageDomainType() == StorageDomainType.Master) ? StorageDomainStatus.Locked : StorageDomainStatus.Activating);
    freeLock();
    log.info("ActivateStorage Domain. Before Connect all hosts to pool. Time: {}", new Date());
    List<Pair<Guid, Boolean>> hostsConnectionResults = connectHostsInUpToDomainStorageServer();
    if (isAllHostConnectionFailed(hostsConnectionResults)) {
        log.error("Cannot connect storage server, aborting Storage Domain activation.");
        setSucceeded(false);
        return;
    }
    syncStorageDomainInfo(hostsConnectionResults);
    runVdsCommand(VDSCommandType.ActivateStorageDomain, new ActivateStorageDomainVDSCommandParameters(getStoragePool().getId(), getStorageDomain().getId()));
    log.info("ActivateStorage Domain. After Connect all hosts to pool. Time: {}", new Date());
    TransactionSupport.executeInNewTransaction(() -> {
        map.setStatus(StorageDomainStatus.Active);
        storagePoolIsoMapDao.updateStatus(map.getId(), map.getStatus());
        if (getStorageDomain().getStorageDomainType() == StorageDomainType.Master) {
            calcStoragePoolStatusByDomainsStatus();
        }
        return null;
    });
    refreshAllVdssInPool();
    log.info("ActivateStorage Domain. After change storage pool status in vds. Time: {}", new Date());
    if (getStorageDomain().getStorageDomainType() == StorageDomainType.ISO) {
        isoDomainListSynchronizer.refresheIsoDomainWhenActivateDomain(getStorageDomain().getId(), getStoragePool().getId());
    }
    setSucceeded(true);
}
Also used : StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) ActivateStorageDomainVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.ActivateStorageDomainVDSCommandParameters) Date(java.util.Date) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 47 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class AddStorageDomainCommand method connectStorage.

protected Pair<Boolean, Integer> connectStorage() {
    String connectionId = getStorageDomain().getStorage();
    StorageServerConnections connection = storageServerConnectionDao.get(connectionId);
    Map<String, String> result = (Map<String, String>) runVdsCommand(VDSCommandType.ConnectStorageServer, new StorageServerConnectionManagementVDSParameters(getParameters().getVdsId(), Guid.Empty, connection.getStorageType(), new ArrayList<>(Collections.singletonList(connection)))).getReturnValue();
    return new Pair<>(storageHelperDirector.getItem(connection.getStorageType()).isConnectSucceeded(result, Collections.singletonList(connection)), Integer.parseInt(result.values().iterator().next()));
}
Also used : StorageServerConnections(org.ovirt.engine.core.common.businessentities.StorageServerConnections) StorageServerConnectionManagementVDSParameters(org.ovirt.engine.core.common.vdscommands.StorageServerConnectionManagementVDSParameters) ArrayList(java.util.ArrayList) Map(java.util.Map) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 48 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class AttachStorageDomainToPoolCommand method executeCommand.

@Override
protected void executeCommand() {
    if (isCinderStorageDomain()) {
        handleCinderDomain();
        return;
    }
    if (getStoragePool().getStatus() == StoragePoolStatus.Uninitialized) {
        StoragePoolWithStoragesParameter parameters = new StoragePoolWithStoragesParameter(getStoragePool(), Collections.singletonList(getStorageDomain().getId()), getParameters().getSessionId());
        parameters.setIsInternal(true);
        parameters.setTransactionScopeOption(TransactionScopeOption.Suppress);
        ActionReturnValue returnValue = runInternalAction(ActionType.AddStoragePoolWithStorages, parameters, getContext().clone().withoutCompensationContext());
        setSucceeded(returnValue.getSucceeded());
        if (!returnValue.getSucceeded()) {
            getReturnValue().setFault(returnValue.getFault());
        }
    } else {
        map = storagePoolIsoMapDao.get(new StoragePoolIsoMapId(getStorageDomain().getId(), getParameters().getStoragePoolId()));
        if (map == null) {
            executeInNewTransaction(() -> {
                map = new StoragePoolIsoMap(getStorageDomain().getId(), getParameters().getStoragePoolId(), StorageDomainStatus.Locked);
                storagePoolIsoMapDao.save(map);
                getCompensationContext().snapshotNewEntity(map);
                getCompensationContext().stateChanged();
                return null;
            });
            List<Pair<Guid, Boolean>> hostsConnectionResults = connectHostsInUpToDomainStorageServer();
            if (isAllHostConnectionFailed(hostsConnectionResults)) {
                log.error("Cannot connect storage connection server, aborting attach storage domain operation.");
                setSucceeded(false);
                return;
            }
            // Forcibly detach only data storage domains.
            if (getStorageDomain().getStorageDomainType() == StorageDomainType.Data) {
                @SuppressWarnings("unchecked") Pair<StorageDomainStatic, Guid> domainFromIrs = (Pair<StorageDomainStatic, Guid>) runVdsCommand(VDSCommandType.HSMGetStorageDomainInfo, new HSMGetStorageDomainInfoVDSCommandParameters(getVdsId(), getParameters().getStorageDomainId())).getReturnValue();
                // If the storage domain is already related to another Storage Pool, detach it by force.
                Guid storagePoolId = domainFromIrs.getSecond();
                if (storagePoolId != null) {
                    // Master domain version is not relevant since force remove at
                    // DetachStorageDomainVdsCommand does not use it.
                    // Storage pool id can be empty
                    DetachStorageDomainVDSCommandParameters detachParams = new DetachStorageDomainVDSCommandParameters(getStoragePoolIdFromVds(), getParameters().getStorageDomainId(), Guid.Empty, 0);
                    detachParams.setForce(true);
                    detachParams.setDetachFromOldStoragePool(true);
                    try {
                        runVdsCommand(VDSCommandType.DetachStorageDomain, detachParams);
                    } catch (EngineException e) {
                        log.warn("Detaching Storage Domain '{}' from it's previous storage pool '{}'" + " has failed. The meta data of the Storage Domain might still" + " indicate that it is attached to a different Storage Pool.", getParameters().getStorageDomainId(), Guid.Empty, 0);
                        throw e;
                    }
                }
                if (diskProfileDao.getAllForStorageDomain(getStorageDomain().getId()).isEmpty()) {
                    createDefaultDiskProfile();
                }
            }
            runVdsCommand(VDSCommandType.AttachStorageDomain, new AttachStorageDomainVDSCommandParameters(getParameters().getStoragePoolId(), getParameters().getStorageDomainId()));
            final List<OvfEntityData> unregisteredEntitiesFromOvfDisk = new ArrayList<>();
            if (getStorageDomain().getStorageDomainType().isDataDomain()) {
                List<OvfEntityData> returnValueFromStorageOvfDisk = getEntitiesFromStorageOvfDisk(getParameters().getStorageDomainId(), getStoragePoolIdFromVds());
                unregisteredEntitiesFromOvfDisk.addAll(returnValueFromStorageOvfDisk);
            }
            List<DiskImage> ovfStoreDiskImages = getAllOVFDisks(getParameters().getStorageDomainId(), getStoragePoolIdFromVds());
            executeInNewTransaction(() -> {
                final StorageDomainType sdType = getStorageDomain().getStorageDomainType();
                map.setStatus(StorageDomainStatus.Maintenance);
                storagePoolIsoMapDao.updateStatus(map.getId(), map.getStatus());
                if (sdType == StorageDomainType.Master) {
                    calcStoragePoolStatusByDomainsStatus();
                }
                if (getStorageDomain().getStorageDomainType().isDataDomain()) {
                    registerAllOvfDisks(ovfStoreDiskImages, getParameters().getStorageDomainId());
                    // Update unregistered entities
                    for (OvfEntityData ovf : unregisteredEntitiesFromOvfDisk) {
                        unregisteredOVFDataDao.removeEntity(ovf.getEntityId(), getParameters().getStorageDomainId());
                        unregisteredOVFDataDao.saveOVFData(ovf);
                        log.info("Adding OVF data of entity id '{}' and entity name '{}'", ovf.getEntityId(), ovf.getEntityName());
                    }
                    initUnregisteredDisksToDB(getParameters().getStorageDomainId());
                }
                // upgrade the domain format to the storage pool format
                updateStorageDomainFormatIfNeeded(getStorageDomain());
                return null;
            });
            if (getParameters().getActivate()) {
                attemptToActivateDomain();
            }
            setSucceeded(true);
        }
    }
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) AttachStorageDomainVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.AttachStorageDomainVDSCommandParameters) DetachStorageDomainVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.DetachStorageDomainVDSCommandParameters) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) EngineException(org.ovirt.engine.core.common.errors.EngineException) ArrayList(java.util.ArrayList) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) HSMGetStorageDomainInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainInfoVDSCommandParameters) Guid(org.ovirt.engine.core.compat.Guid) StoragePoolWithStoragesParameter(org.ovirt.engine.core.common.action.StoragePoolWithStoragesParameter) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 49 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class DeactivateStorageDomainCommand method deactivateCinderStorageDomain.

private void deactivateCinderStorageDomain() {
    List<Pair<Guid, Boolean>> hostsConnectionResults = disconnectHostsInUpToDomainStorageServer();
    for (Pair<Guid, Boolean> pair : hostsConnectionResults) {
        if (!pair.getSecond()) {
            log.error("Failed to deactivate Cinder storage domain '{}' due to secrets un-registration failure.", getStorageDomain().getName());
            StoragePoolIsoMap map = storagePoolIsoMapDao.get(new StoragePoolIsoMapId(getParameters().getStorageDomainId(), getParameters().getStoragePoolId()));
            map.setStatus(StorageDomainStatus.Inactive);
            storagePoolIsoMapDao.updateStatus(map.getId(), map.getStatus());
            return;
        }
    }
    cinderStorageHelper.deactivateCinderDomain(getParameters().getStorageDomainId(), getParameters().getStoragePoolId());
    setSucceeded(true);
}
Also used : StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) Guid(org.ovirt.engine.core.compat.Guid) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 50 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class DeactivateStorageDomainCommand method getExclusiveLocks.

@Override
protected Map<String, Pair<String, String>> getExclusiveLocks() {
    StorageDomain storageDomain = getStorageDomain();
    if (storageDomain != null) {
        Map<String, Pair<String, String>> locks = new HashMap<>();
        locks.put(storageDomain.getId().toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.STORAGE, EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED));
        if (storageDomain.getStorageDomainType() == StorageDomainType.Master) {
            locks.put(storageDomain.getStoragePoolId().toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.POOL, EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED));
        }
        return locks;
    }
    return null;
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) HashMap(java.util.HashMap) Pair(org.ovirt.engine.core.common.utils.Pair)

Aggregations

Pair (org.ovirt.engine.core.common.utils.Pair)147 ArrayList (java.util.ArrayList)61 Guid (org.ovirt.engine.core.compat.Guid)61 HashMap (java.util.HashMap)30 VDS (org.ovirt.engine.core.common.businessentities.VDS)26 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)25 Test (org.junit.Test)24 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)19 List (java.util.List)16 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)16 Map (java.util.Map)13 EngineLock (org.ovirt.engine.core.utils.lock.EngineLock)13 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)12 VM (org.ovirt.engine.core.common.businessentities.VM)12 HashSet (java.util.HashSet)10 VmInit (org.ovirt.engine.core.common.businessentities.VmInit)10 VmInitNetwork (org.ovirt.engine.core.common.businessentities.VmInitNetwork)10 EngineException (org.ovirt.engine.core.common.errors.EngineException)9 Callable (java.util.concurrent.Callable)8 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)8