Search in sources :

Example 31 with VolumeVO

use of com.cloud.storage.VolumeVO in project cloudstack by apache.

the class XenServerStorageMotionStrategy method updateVolumePathsAfterMigration.

private void updateVolumePathsAfterMigration(Map<VolumeInfo, DataStore> volumeToPool, List<VolumeObjectTO> volumeTos, Host srcHost) {
    for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
        VolumeInfo volumeInfo = entry.getKey();
        StoragePool storagePool = (StoragePool) entry.getValue();
        boolean updated = false;
        for (VolumeObjectTO volumeTo : volumeTos) {
            if (volumeInfo.getId() == volumeTo.getId()) {
                if (storagePool.isManaged()) {
                    handleManagedVolumePostMigration(volumeInfo, srcHost, volumeTo);
                } else {
                    VolumeVO volumeVO = volDao.findById(volumeInfo.getId());
                    Long oldPoolId = volumeVO.getPoolId();
                    volumeVO.setPath(volumeTo.getPath());
                    volumeVO.setFolder(storagePool.getPath());
                    volumeVO.setPodId(storagePool.getPodId());
                    volumeVO.setPoolId(storagePool.getId());
                    volumeVO.setLastPoolId(oldPoolId);
                    volDao.update(volumeInfo.getId(), volumeVO);
                }
                updated = true;
                break;
            }
        }
        if (!updated) {
            s_logger.error("The volume path wasn't updated for volume '" + volumeInfo + "' after it was migrated.");
        }
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) VolumeVO(com.cloud.storage.VolumeVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Example 32 with VolumeVO

use of com.cloud.storage.VolumeVO in project cloudstack by apache.

the class XenServerStorageMotionStrategy method handleManagedVolumePostMigration.

private void handleManagedVolumePostMigration(VolumeInfo volumeInfo, Host srcHost, VolumeObjectTO volumeTO) {
    final Map<String, String> details = new HashMap<>();
    details.put(DeleteStoragePoolCommand.DATASTORE_NAME, volumeInfo.get_iScsiName());
    final DeleteStoragePoolCommand cmd = new DeleteStoragePoolCommand();
    cmd.setDetails(details);
    cmd.setRemoveDatastore(true);
    final Answer answer = agentMgr.easySend(srcHost.getId(), cmd);
    if (answer == null || !answer.getResult()) {
        String errMsg = "Error interacting with host (related to DeleteStoragePoolCommand)" + (StringUtils.isNotBlank(answer.getDetails()) ? ": " + answer.getDetails() : "");
        s_logger.error(errMsg);
        throw new CloudRuntimeException(errMsg);
    }
    final PrimaryDataStoreDriver pdsd = (PrimaryDataStoreDriver) volumeInfo.getDataStore().getDriver();
    pdsd.revokeAccess(volumeInfo, srcHost, volumeInfo.getDataStore());
    VolumeDetailVO volumeDetailVo = new VolumeDetailVO(volumeInfo.getId(), PrimaryDataStoreDriver.BASIC_DELETE, Boolean.TRUE.toString(), false);
    volumeDetailsDao.persist(volumeDetailVo);
    pdsd.deleteAsync(volumeInfo.getDataStore(), volumeInfo, null);
    VolumeVO volumeVO = volDao.findById(volumeInfo.getId());
    volumeVO.setPath(volumeTO.getPath());
    volDao.update(volumeVO.getId(), volumeVO);
}
Also used : MigrateWithStorageCompleteAnswer(com.cloud.agent.api.MigrateWithStorageCompleteAnswer) MigrateWithStorageSendAnswer(com.cloud.agent.api.MigrateWithStorageSendAnswer) Answer(com.cloud.agent.api.Answer) MigrateWithStorageReceiveAnswer(com.cloud.agent.api.MigrateWithStorageReceiveAnswer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) VolumeVO(com.cloud.storage.VolumeVO) HashMap(java.util.HashMap) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand) VolumeDetailVO(com.cloud.storage.VolumeDetailVO)

Example 33 with VolumeVO

use of com.cloud.storage.VolumeVO in project cloudstack by apache.

the class RecreatableFencer method fenceOff.

@Override
public Boolean fenceOff(VirtualMachine vm, Host host) {
    VirtualMachine.Type type = vm.getType();
    if (type != VirtualMachine.Type.ConsoleProxy && type != VirtualMachine.Type.DomainRouter && type != VirtualMachine.Type.SecondaryStorageVm) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Don't know how to fence off " + type);
        }
        return null;
    }
    List<VolumeVO> vols = _volsDao.findByInstance(vm.getId());
    for (VolumeVO vol : vols) {
        if (!vol.isRecreatable()) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Unable to fence off volumes that are not recreatable: " + vol);
            }
            return null;
        }
        if (vol.getPoolType().isShared()) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Unable to fence off volumes that are shared: " + vol);
            }
            return null;
        }
    }
    return true;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 34 with VolumeVO

use of com.cloud.storage.VolumeVO in project cloudstack by apache.

the class NetworkHelperImpl method startVirtualRouter.

@Override
public DomainRouterVO startVirtualRouter(final DomainRouterVO router, final User user, final Account caller, final Map<Param, Object> params) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
    if (router.getRole() != Role.VIRTUAL_ROUTER || !router.getIsRedundantRouter()) {
        return start(router, user, caller, params, null);
    }
    if (router.getState() == State.Running) {
        s_logger.debug("Redundant router " + router.getInstanceName() + " is already running!");
        return router;
    }
    // We will wait until VR is up or fail
    if (router.getState() == State.Starting) {
        return waitRouter(router);
    }
    final DataCenterDeployment plan = new DataCenterDeployment(0, null, null, null, null, null);
    DomainRouterVO result = null;
    assert router.getIsRedundantRouter();
    final List<Long> networkIds = _routerDao.getRouterNetworks(router.getId());
    DomainRouterVO routerToBeAvoid = null;
    if (networkIds.size() != 0) {
        final List<DomainRouterVO> routerList = _routerDao.findByNetwork(networkIds.get(0));
        for (final DomainRouterVO rrouter : routerList) {
            if (rrouter.getHostId() != null && rrouter.getIsRedundantRouter() && rrouter.getState() == State.Running) {
                if (routerToBeAvoid != null) {
                    throw new ResourceUnavailableException("Try to start router " + router.getInstanceName() + "(" + router.getId() + ")" + ", but there are already two redundant routers with IP " + router.getPublicIpAddress() + ", they are " + rrouter.getInstanceName() + "(" + rrouter.getId() + ") and " + routerToBeAvoid.getInstanceName() + "(" + routerToBeAvoid.getId() + ")", DataCenter.class, rrouter.getDataCenterId());
                }
                routerToBeAvoid = rrouter;
            }
        }
    }
    if (routerToBeAvoid == null) {
        return start(router, user, caller, params, null);
    }
    // We would try best to deploy the router to another place
    final int retryIndex = 5;
    final ExcludeList[] avoids = new ExcludeList[5];
    avoids[0] = new ExcludeList();
    avoids[0].addPod(routerToBeAvoid.getPodIdToDeployIn());
    avoids[1] = new ExcludeList();
    avoids[1].addCluster(_hostDao.findById(routerToBeAvoid.getHostId()).getClusterId());
    avoids[2] = new ExcludeList();
    final List<VolumeVO> volumes = _volumeDao.findByInstanceAndType(routerToBeAvoid.getId(), Volume.Type.ROOT);
    if (volumes != null && volumes.size() != 0) {
        avoids[2].addPool(volumes.get(0).getPoolId());
    }
    avoids[2].addHost(routerToBeAvoid.getHostId());
    avoids[3] = new ExcludeList();
    avoids[3].addHost(routerToBeAvoid.getHostId());
    avoids[4] = new ExcludeList();
    for (int i = 0; i < retryIndex; i++) {
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("Try to deploy redundant virtual router:" + router.getHostName() + ", for " + i + " time");
        }
        plan.setAvoids(avoids[i]);
        try {
            result = start(router, user, caller, params, plan);
        } catch (final InsufficientServerCapacityException ex) {
            result = null;
        }
        if (result != null) {
            break;
        }
    }
    return result;
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VolumeVO(com.cloud.storage.VolumeVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 35 with VolumeVO

use of com.cloud.storage.VolumeVO in project cloudstack by apache.

the class SnapshotManagerImpl method listSnapshots.

@Override
public Pair<List<? extends Snapshot>, Integer> listSnapshots(ListSnapshotsCmd cmd) {
    Long volumeId = cmd.getVolumeId();
    String name = cmd.getSnapshotName();
    Long id = cmd.getId();
    String keyword = cmd.getKeyword();
    String snapshotTypeStr = cmd.getSnapshotType();
    String intervalTypeStr = cmd.getIntervalType();
    Map<String, String> tags = cmd.getTags();
    Long zoneId = cmd.getZoneId();
    Account caller = CallContext.current().getCallingAccount();
    List<Long> permittedAccounts = new ArrayList<Long>();
    // Verify parameters
    if (volumeId != null) {
        VolumeVO volume = _volsDao.findById(volumeId);
        if (volume != null) {
            _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, volume);
        }
    }
    List<Long> ids = getIdsListFromCmd(cmd.getId(), cmd.getIds());
    Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(cmd.getDomainId(), cmd.isRecursive(), null);
    _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
    Long domainId = domainIdRecursiveListProject.first();
    Boolean isRecursive = domainIdRecursiveListProject.second();
    ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
    Filter searchFilter = new Filter(SnapshotVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal());
    SearchBuilder<SnapshotVO> sb = _snapshotDao.createSearchBuilder();
    _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    //exclude those Destroyed snapshot, not showing on UI
    sb.and("statusNEQ", sb.entity().getState(), SearchCriteria.Op.NEQ);
    sb.and("volumeId", sb.entity().getVolumeId(), SearchCriteria.Op.EQ);
    sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
    sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
    sb.and("idIN", sb.entity().getId(), SearchCriteria.Op.IN);
    sb.and("snapshotTypeEQ", sb.entity().getsnapshotType(), SearchCriteria.Op.IN);
    sb.and("snapshotTypeNEQ", sb.entity().getsnapshotType(), SearchCriteria.Op.NEQ);
    sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
    if (tags != null && !tags.isEmpty()) {
        SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
        for (int count = 0; count < tags.size(); count++) {
            tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
            tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
            tagSearch.cp();
        }
        tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
        sb.groupBy(sb.entity().getId());
        sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
    }
    SearchCriteria<SnapshotVO> sc = sb.create();
    _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    sc.setParameters("statusNEQ", Snapshot.State.Destroyed);
    if (volumeId != null) {
        sc.setParameters("volumeId", volumeId);
    }
    if (tags != null && !tags.isEmpty()) {
        int count = 0;
        sc.setJoinParameters("tagSearch", "resourceType", ResourceObjectType.Snapshot.toString());
        for (String key : tags.keySet()) {
            sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key);
            sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), tags.get(key));
            count++;
        }
    }
    if (zoneId != null) {
        sc.setParameters("dataCenterId", zoneId);
    }
    setIdsListToSearchCriteria(sc, ids);
    if (name != null) {
        sc.setParameters("name", "%" + name + "%");
    }
    if (id != null) {
        sc.setParameters("id", id);
    }
    if (keyword != null) {
        SearchCriteria<SnapshotVO> ssc = _snapshotDao.createSearchCriteria();
        ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        sc.addAnd("name", SearchCriteria.Op.SC, ssc);
    }
    if (snapshotTypeStr != null) {
        Type snapshotType = SnapshotVO.getSnapshotType(snapshotTypeStr);
        if (snapshotType == null) {
            throw new InvalidParameterValueException("Unsupported snapshot type " + snapshotTypeStr);
        }
        if (snapshotType == Type.RECURRING) {
            sc.setParameters("snapshotTypeEQ", Type.HOURLY.ordinal(), Type.DAILY.ordinal(), Type.WEEKLY.ordinal(), Type.MONTHLY.ordinal());
        } else {
            sc.setParameters("snapshotTypeEQ", snapshotType.ordinal());
        }
    } else if (intervalTypeStr != null && volumeId != null) {
        Type type = SnapshotVO.getSnapshotType(intervalTypeStr);
        if (type == null) {
            throw new InvalidParameterValueException("Unsupported snapstho interval type " + intervalTypeStr);
        }
        sc.setParameters("snapshotTypeEQ", type.ordinal());
    } else {
        // Show only MANUAL and RECURRING snapshot types
        sc.setParameters("snapshotTypeNEQ", Snapshot.Type.TEMPLATE.ordinal());
    }
    Pair<List<SnapshotVO>, Integer> result = _snapshotDao.searchAndCount(sc, searchFilter);
    return new Pair<List<? extends Snapshot>, Integer>(result.first(), result.second());
}
Also used : Account(com.cloud.user.Account) Ternary(com.cloud.utils.Ternary) ArrayList(java.util.ArrayList) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) ScopeType(com.cloud.storage.ScopeType) Type(com.cloud.storage.Snapshot.Type) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) ResourceType(com.cloud.configuration.Resource.ResourceType) IntervalType(com.cloud.utils.DateUtil.IntervalType) ResourceObjectType(com.cloud.server.ResourceTag.ResourceObjectType) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) SnapshotVO(com.cloud.storage.SnapshotVO) VolumeVO(com.cloud.storage.VolumeVO) Filter(com.cloud.utils.db.Filter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceTagVO(com.cloud.tags.ResourceTagVO) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair)

Aggregations

VolumeVO (com.cloud.storage.VolumeVO)156 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)44 ArrayList (java.util.ArrayList)39 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)36 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)30 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)26 HostVO (com.cloud.host.HostVO)24 VMInstanceVO (com.cloud.vm.VMInstanceVO)24 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)22 Account (com.cloud.user.Account)19 HashMap (java.util.HashMap)17 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)16 VolumeApiResult (org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult)16 StoragePool (com.cloud.storage.StoragePool)15 HostPodVO (com.cloud.dc.HostPodVO)14 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)13 Pair (com.cloud.utils.Pair)13 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)11 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)11 DiskOfferingVO (com.cloud.storage.DiskOfferingVO)11