Search in sources :

Example 1 with GetStoragePoolCapabilitiesAnswer

use of com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer in project cloudstack by apache.

the class VmwareResource method execute.

protected Answer execute(GetStoragePoolCapabilitiesCommand cmd) {
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
        HostMO host = (HostMO) hyperHost;
        StorageFilerTO pool = cmd.getPool();
        ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, pool.getUuid());
        if (morDatastore == null) {
            morDatastore = hyperHost.mountDatastore((pool.getType() == StoragePoolType.VMFS || pool.getType() == StoragePoolType.PreSetup || pool.getType() == StoragePoolType.DatastoreCluster), pool.getHost(), pool.getPort(), pool.getPath(), pool.getUuid().replace("-", ""), true);
        }
        assert (morDatastore != null);
        DatastoreMO dsMo = new DatastoreMO(getServiceContext(), morDatastore);
        GetStoragePoolCapabilitiesAnswer answer = new GetStoragePoolCapabilitiesAnswer(cmd);
        boolean hardwareAccelerationSupportForDataStore = getHardwareAccelerationSupportForDataStore(host.getMor(), dsMo.getName());
        Map<String, String> poolDetails = answer.getPoolDetails();
        poolDetails.put(Storage.Capability.HARDWARE_ACCELERATION.toString(), String.valueOf(hardwareAccelerationSupportForDataStore));
        answer.setPoolDetails(poolDetails);
        answer.setResult(true);
        return answer;
    } catch (Throwable e) {
        GetStoragePoolCapabilitiesAnswer answer = new GetStoragePoolCapabilitiesAnswer(cmd);
        answer.setResult(false);
        answer.setDetails(createLogMessageException(e, cmd));
        return answer;
    }
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) GetStoragePoolCapabilitiesAnswer(com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer)

Example 2 with GetStoragePoolCapabilitiesAnswer

use of com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer in project cloudstack by apache.

the class StorageManagerImpl method updateStorageCapabilities.

/**
 * @param poolId - Storage pool id for pool to update.
 * @param failOnChecks - If true, throw an error if pool type and state checks fail.
 */
@Override
public void updateStorageCapabilities(Long poolId, boolean failOnChecks) {
    StoragePoolVO pool = _storagePoolDao.findById(poolId);
    if (pool == null) {
        throw new CloudRuntimeException("Primary storage not found for id: " + poolId);
    }
    // Only checking NFS for now - required for disk provisioning type support for vmware.
    if (pool.getPoolType() != StoragePoolType.NetworkFilesystem) {
        if (failOnChecks) {
            throw new CloudRuntimeException("Storage capabilities update only supported on NFS storage mounted.");
        }
        return;
    }
    if (pool.getStatus() != StoragePoolStatus.Initialized && pool.getStatus() != StoragePoolStatus.Up) {
        if (failOnChecks) {
            throw new CloudRuntimeException("Primary storage is not in the right state to update capabilities");
        }
        return;
    }
    HypervisorType hypervisor = pool.getHypervisor();
    if (hypervisor == null) {
        if (pool.getClusterId() != null) {
            ClusterVO cluster = _clusterDao.findById(pool.getClusterId());
            hypervisor = cluster.getHypervisorType();
        }
    }
    if (!HypervisorType.VMware.equals(hypervisor)) {
        if (failOnChecks) {
            throw new CloudRuntimeException("Storage capabilities update only supported on VMWare.");
        }
        return;
    }
    // find the host
    List<Long> poolIds = new ArrayList<Long>();
    poolIds.add(pool.getId());
    List<Long> hosts = _storagePoolHostDao.findHostsConnectedToPools(poolIds);
    if (hosts.size() > 0) {
        GetStoragePoolCapabilitiesCommand cmd = new GetStoragePoolCapabilitiesCommand();
        cmd.setPool(new StorageFilerTO(pool));
        GetStoragePoolCapabilitiesAnswer answer = (GetStoragePoolCapabilitiesAnswer) _agentMgr.easySend(hosts.get(0), cmd);
        if (answer.getPoolDetails() != null && answer.getPoolDetails().containsKey(Storage.Capability.HARDWARE_ACCELERATION.toString())) {
            StoragePoolDetailVO hardwareAccelerationSupported = _storagePoolDetailsDao.findDetail(pool.getId(), Storage.Capability.HARDWARE_ACCELERATION.toString());
            if (hardwareAccelerationSupported == null) {
                StoragePoolDetailVO storagePoolDetailVO = new StoragePoolDetailVO(pool.getId(), Storage.Capability.HARDWARE_ACCELERATION.toString(), answer.getPoolDetails().get(Storage.Capability.HARDWARE_ACCELERATION.toString()), false);
                _storagePoolDetailsDao.persist(storagePoolDetailVO);
            } else {
                hardwareAccelerationSupported.setValue(answer.getPoolDetails().get(Storage.Capability.HARDWARE_ACCELERATION.toString()));
                _storagePoolDetailsDao.update(hardwareAccelerationSupported.getId(), hardwareAccelerationSupported);
            }
        } else {
            if (answer != null && !answer.getResult()) {
                s_logger.error("Failed to update storage pool capabilities: " + answer.getDetails());
                if (failOnChecks) {
                    throw new CloudRuntimeException(answer.getDetails());
                }
            }
        }
    }
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) ClusterVO(com.cloud.dc.ClusterVO) GetStoragePoolCapabilitiesCommand(com.cloud.agent.api.GetStoragePoolCapabilitiesCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ArrayList(java.util.ArrayList) StoragePoolDetailVO(org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) GetStoragePoolCapabilitiesAnswer(com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer)

Aggregations

GetStoragePoolCapabilitiesAnswer (com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer)2 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)2 GetStoragePoolCapabilitiesCommand (com.cloud.agent.api.GetStoragePoolCapabilitiesCommand)1 ClusterVO (com.cloud.dc.ClusterVO)1 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)1 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)1 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)1 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)1 ArrayList (java.util.ArrayList)1 StoragePoolDetailVO (org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO)1 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)1