Search in sources :

Example 6 with GetStorageStatsAnswer

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

the class NfsSecondaryStorageResource method execute.

protected GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) {
    DataStoreTO store = cmd.getStore();
    if (store instanceof S3TO || store instanceof SwiftTO) {
        long infinity = Integer.MAX_VALUE;
        return new GetStorageStatsAnswer(cmd, infinity, 0L);
    }
    String rootDir = getRootDir(((NfsTO) store).getUrl(), cmd.getNfsVersion());
    final long usedSize = getUsedSize(rootDir);
    final long totalSize = getTotalSize(rootDir);
    if (usedSize == -1 || totalSize == -1) {
        return new GetStorageStatsAnswer(cmd, "Unable to get storage stats");
    } else {
        return new GetStorageStatsAnswer(cmd, totalSize, usedSize);
    }
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) SwiftTO(com.cloud.agent.api.to.SwiftTO) S3TO(com.cloud.agent.api.to.S3TO)

Example 7 with GetStorageStatsAnswer

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

the class StorageManagerImpl method getStoragePoolStats.

private GetStorageStatsAnswer getStoragePoolStats(StoragePool pool, GetStorageStatsCommand cmd) {
    GetStorageStatsAnswer answer = null;
    DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName());
    DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();
    PrimaryDataStoreDriver primaryStoreDriver = (PrimaryDataStoreDriver) storeDriver;
    Pair<Long, Long> storageStats = primaryStoreDriver.getStorageStats(pool);
    if (storageStats == null) {
        answer = new GetStorageStatsAnswer((GetStorageStatsCommand) cmd, "Failed to get storage stats for pool: " + pool.getId());
    } else {
        answer = new GetStorageStatsAnswer((GetStorageStatsCommand) cmd, storageStats.first(), storageStats.second());
    }
    return answer;
}
Also used : GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) DataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver) GetStorageStatsCommand(com.cloud.agent.api.GetStorageStatsCommand)

Example 8 with GetStorageStatsAnswer

use of com.cloud.agent.api.GetStorageStatsAnswer in project cosmic by MissionCriticalCloud.

the class LibvirtGetStorageStatsCommandWrapper method execute.

@Override
public Answer execute(final GetStorageStatsCommand command, final LibvirtComputingResource libvirtComputingResource) {
    try {
        final KvmStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
        final KvmStoragePool sp = storagePoolMgr.getStoragePool(command.getPooltype(), command.getStorageId(), true);
        return new GetStorageStatsAnswer(command, sp.getCapacity(), sp.getUsed());
    } catch (final CloudRuntimeException e) {
        return new GetStorageStatsAnswer(command, e.toString());
    }
}
Also used : GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) KvmStoragePool(com.cloud.hypervisor.kvm.storage.KvmStoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) KvmStoragePoolManager(com.cloud.hypervisor.kvm.storage.KvmStoragePoolManager)

Example 9 with GetStorageStatsAnswer

use of com.cloud.agent.api.GetStorageStatsAnswer in project cosmic by MissionCriticalCloud.

the class CitrixGetStorageStatsCommandWrapper method execute.

@Override
public Answer execute(final GetStorageStatsCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    try {
        final Set<SR> srs = SR.getByNameLabel(conn, command.getStorageId());
        if (srs.size() != 1) {
            final String msg = "There are " + srs.size() + " storageid: " + command.getStorageId();
            s_logger.warn(msg);
            return new GetStorageStatsAnswer(command, msg);
        }
        final SR sr = srs.iterator().next();
        sr.scan(conn);
        final long capacity = sr.getPhysicalSize(conn);
        final long used = sr.getPhysicalUtilisation(conn);
        return new GetStorageStatsAnswer(command, capacity, used);
    } catch (final XenAPIException e) {
        final String msg = "GetStorageStats Exception:" + e.toString() + "host:" + citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId();
        s_logger.warn(msg);
        return new GetStorageStatsAnswer(command, msg);
    } catch (final XmlRpcException e) {
        final String msg = "GetStorageStats Exception:" + e.getMessage() + "host:" + citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId();
        s_logger.warn(msg);
        return new GetStorageStatsAnswer(command, msg);
    } catch (final Exception e) {
        final String msg = "GetStorageStats Exception:" + e.getMessage() + "host:" + citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId();
        s_logger.warn(msg);
        return new GetStorageStatsAnswer(command, msg);
    }
}
Also used : GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) SR(com.xensource.xenapi.SR)

Example 10 with GetStorageStatsAnswer

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

the class VmwareResource method execute.

protected Answer execute(GetStorageStatsCommand cmd) {
    try {
        VmwareContext context = getServiceContext();
        VmwareHypervisorHost hyperHost = getHyperHost(context);
        ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getStorageId());
        if (morDs != null) {
            long capacity = 0;
            long free = 0;
            if (cmd.getPooltype() == StoragePoolType.DatastoreCluster) {
                StoragepodMO datastoreClusterMo = new StoragepodMO(getServiceContext(), morDs);
                StoragePodSummary summary = datastoreClusterMo.getDatastoreClusterSummary();
                capacity = summary.getCapacity();
                free = summary.getFreeSpace();
            } else {
                DatastoreMO datastoreMo = new DatastoreMO(context, morDs);
                DatastoreSummary summary = datastoreMo.getDatastoreSummary();
                capacity = summary.getCapacity();
                free = summary.getFreeSpace();
            }
            long used = capacity - free;
            s_logger.debug(String.format("Datastore summary info: [storageId: %s, ], localPath: %s, poolType: %s, capacity: %s, free: %s, used: %s].", cmd.getStorageId(), cmd.getLocalPath(), cmd.getPooltype(), toHumanReadableSize(capacity), toHumanReadableSize(free), toHumanReadableSize(used)));
            if (capacity <= 0) {
                s_logger.warn("Something is wrong with vSphere NFS datastore, rebooting ESX(ESXi) host should help");
            }
            return new GetStorageStatsAnswer(cmd, capacity, used);
        } else {
            String msg = String.format("Could not find datastore for GetStorageStatsCommand: [storageId: %s, localPath: %s, poolType: %s].", cmd.getStorageId(), cmd.getLocalPath(), cmd.getPooltype());
            s_logger.error(msg);
            return new GetStorageStatsAnswer(cmd, msg);
        }
    } catch (Throwable e) {
        if (e instanceof RemoteException) {
            s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
            invalidateServiceContext();
        }
        String msg = String.format("Unable to execute GetStorageStatsCommand(storageId : [%s], localPath: [%s], poolType: [%s]) due to [%s]", cmd.getStorageId(), cmd.getLocalPath(), cmd.getPooltype(), VmwareHelper.getExceptionMessage(e));
        s_logger.error(msg, e);
        return new GetStorageStatsAnswer(cmd, msg);
    }
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) DatastoreSummary(com.vmware.vim25.DatastoreSummary) StoragepodMO(com.cloud.hypervisor.vmware.mo.StoragepodMO) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) StoragePodSummary(com.vmware.vim25.StoragePodSummary) RemoteException(java.rmi.RemoteException) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)12 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 GetStorageStatsCommand (com.cloud.agent.api.GetStorageStatsCommand)2 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)2 MockSecStorageVO (com.cloud.simulator.MockSecStorageVO)2 MockStoragePoolVO (com.cloud.simulator.MockStoragePoolVO)2 Connection (com.xensource.xenapi.Connection)2 SR (com.xensource.xenapi.SR)2 XenAPIException (com.xensource.xenapi.Types.XenAPIException)2 XmlRpcException (org.apache.xmlrpc.XmlRpcException)2 S3TO (com.cloud.agent.api.to.S3TO)1 SwiftTO (com.cloud.agent.api.to.SwiftTO)1 KVMStoragePool (com.cloud.hypervisor.kvm.storage.KVMStoragePool)1 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)1 KvmStoragePool (com.cloud.hypervisor.kvm.storage.KvmStoragePool)1 KvmStoragePoolManager (com.cloud.hypervisor.kvm.storage.KvmStoragePoolManager)1 Linux (com.cloud.hypervisor.ovm3.objects.Linux)1 Ovm3ResourceException (com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)1 StoragePlugin (com.cloud.hypervisor.ovm3.objects.StoragePlugin)1 StorageDetails (com.cloud.hypervisor.ovm3.objects.StoragePlugin.StorageDetails)1