Search in sources :

Example 1 with StoragepodMO

use of com.cloud.hypervisor.vmware.mo.StoragepodMO in project cloudstack by apache.

the class VmwareResource method execute.

protected Answer execute(ModifyStoragePoolCommand cmd) {
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
        StorageFilerTO pool = cmd.getPool();
        if (pool.getType() != StoragePoolType.NetworkFilesystem && pool.getType() != StoragePoolType.VMFS && pool.getType() != StoragePoolType.PreSetup && pool.getType() != StoragePoolType.DatastoreCluster) {
            throw new Exception("Unsupported storage pool type " + pool.getType());
        }
        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);
        HypervisorHostHelper.createBaseFolder(dsMo, hyperHost, pool.getType());
        long capacity = 0;
        long available = 0;
        List<ModifyStoragePoolAnswer> childDatastoresModifyStoragePoolAnswers = new ArrayList<>();
        if (pool.getType() == StoragePoolType.DatastoreCluster) {
            StoragepodMO datastoreClusterMo = new StoragepodMO(getServiceContext(), morDatastore);
            StoragePodSummary dsClusterSummary = datastoreClusterMo.getDatastoreClusterSummary();
            capacity = dsClusterSummary.getCapacity();
            available = dsClusterSummary.getFreeSpace();
            List<ManagedObjectReference> childDatastoreMors = datastoreClusterMo.getDatastoresInDatastoreCluster();
            for (ManagedObjectReference childDsMor : childDatastoreMors) {
                DatastoreMO childDsMo = new DatastoreMO(getServiceContext(), childDsMor);
                Map<String, TemplateProp> tInfo = new HashMap<>();
                DatastoreSummary summary = childDsMo.getDatastoreSummary();
                ;
                ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd, summary.getCapacity(), summary.getFreeSpace(), tInfo);
                StoragePoolInfo poolInfo = answer.getPoolInfo();
                poolInfo.setName(summary.getName());
                String datastoreClusterPath = pool.getPath();
                int pathstartPosition = datastoreClusterPath.lastIndexOf('/');
                String datacenterName = datastoreClusterPath.substring(0, pathstartPosition + 1);
                String childPath = datacenterName + summary.getName();
                poolInfo.setHostPath(childPath);
                String uuid = childDsMo.getCustomFieldValue(CustomFieldConstants.CLOUD_UUID);
                if (uuid == null) {
                    uuid = UUID.nameUUIDFromBytes(((pool.getHost() + childPath)).getBytes()).toString();
                }
                poolInfo.setUuid(uuid);
                poolInfo.setLocalPath(cmd.LOCAL_PATH_PREFIX + File.separator + uuid);
                answer.setPoolInfo(poolInfo);
                answer.setPoolType(summary.getType());
                answer.setLocalDatastoreName(morDatastore.getValue());
                childDsMo.setCustomFieldValue(CustomFieldConstants.CLOUD_UUID, uuid);
                HypervisorHostHelper.createBaseFolderInDatastore(childDsMo, hyperHost.getHyperHostDatacenter());
                childDatastoresModifyStoragePoolAnswers.add(answer);
            }
        } else {
            HypervisorHostHelper.createBaseFolderInDatastore(dsMo, hyperHost.getHyperHostDatacenter());
            DatastoreSummary summary = dsMo.getDatastoreSummary();
            capacity = summary.getCapacity();
            available = summary.getFreeSpace();
        }
        Map<String, TemplateProp> tInfo = new HashMap<>();
        ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd, capacity, available, tInfo);
        answer.setDatastoreClusterChildren(childDatastoresModifyStoragePoolAnswers);
        if (cmd.getAdd() && (pool.getType() == StoragePoolType.VMFS || pool.getType() == StoragePoolType.PreSetup) && pool.getType() != StoragePoolType.DatastoreCluster) {
            answer.setPoolType(dsMo.getDatastoreType());
            answer.setLocalDatastoreName(morDatastore.getValue());
        }
        return answer;
    } catch (Throwable e) {
        return new Answer(cmd, false, createLogMessageException(e, cmd));
    }
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) HashMap(java.util.HashMap) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) ArrayList(java.util.ArrayList) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) SetupPersistentNetworkAnswer(com.cloud.agent.api.SetupPersistentNetworkAnswer) ModifyTargetsAnswer(com.cloud.agent.api.ModifyTargetsAnswer) MigrateVmToPoolAnswer(com.cloud.agent.api.MigrateVmToPoolAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) GetVmVncTicketAnswer(com.cloud.agent.api.GetVmVncTicketAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer) SetupAnswer(com.cloud.agent.api.SetupAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) GetVmNetworkStatsAnswer(com.cloud.agent.api.GetVmNetworkStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) CheckOnHostAnswer(com.cloud.agent.api.CheckOnHostAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) RevertToVMSnapshotAnswer(com.cloud.agent.api.RevertToVMSnapshotAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) AttachIsoAnswer(com.cloud.agent.api.AttachIsoAnswer) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) DeleteVMSnapshotAnswer(com.cloud.agent.api.DeleteVMSnapshotAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) GetStoragePoolCapabilitiesAnswer(com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) ReplugNicAnswer(com.cloud.agent.api.ReplugNicAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) GetUnmanagedInstancesAnswer(com.cloud.agent.api.GetUnmanagedInstancesAnswer) ValidateSnapshotAnswer(com.cloud.agent.api.ValidateSnapshotAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareUnmanageVMInstanceAnswer(com.cloud.agent.api.PrepareUnmanageVMInstanceAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) DatastoreSummary(com.vmware.vim25.DatastoreSummary) StoragePoolInfo(com.cloud.agent.api.StoragePoolInfo) StoragepodMO(com.cloud.hypervisor.vmware.mo.StoragepodMO) StoragePodSummary(com.vmware.vim25.StoragePodSummary) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 2 with StoragepodMO

use of com.cloud.hypervisor.vmware.mo.StoragepodMO 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)2 Answer (com.cloud.agent.api.Answer)1 AttachIsoAnswer (com.cloud.agent.api.AttachIsoAnswer)1 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)1 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)1 CheckNetworkAnswer (com.cloud.agent.api.CheckNetworkAnswer)1 CheckOnHostAnswer (com.cloud.agent.api.CheckOnHostAnswer)1 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)1 CreateVMSnapshotAnswer (com.cloud.agent.api.CreateVMSnapshotAnswer)1 CreateVolumeFromSnapshotAnswer (com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)1 DeleteVMSnapshotAnswer (com.cloud.agent.api.DeleteVMSnapshotAnswer)1 GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)1 GetStoragePoolCapabilitiesAnswer (com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer)1 GetUnmanagedInstancesAnswer (com.cloud.agent.api.GetUnmanagedInstancesAnswer)1 GetVmDiskStatsAnswer (com.cloud.agent.api.GetVmDiskStatsAnswer)1 GetVmNetworkStatsAnswer (com.cloud.agent.api.GetVmNetworkStatsAnswer)1 GetVmStatsAnswer (com.cloud.agent.api.GetVmStatsAnswer)1 GetVmVncTicketAnswer (com.cloud.agent.api.GetVmVncTicketAnswer)1 GetVncPortAnswer (com.cloud.agent.api.GetVncPortAnswer)1 GetVolumeStatsAnswer (com.cloud.agent.api.GetVolumeStatsAnswer)1