Search in sources :

Example 6 with VsphereStoragePolicyVO

use of com.cloud.dc.VsphereStoragePolicyVO in project cloudstack by apache.

the class VmwareManagerImpl method importVsphereStoragePoliciesInternal.

public List<? extends VsphereStoragePolicy> importVsphereStoragePoliciesInternal(Long zoneId, Long vmwareDcId) {
    // Get DC associated with this zone
    VmwareDatacenterVO vmwareDatacenter = vmwareDcDao.findById(vmwareDcId);
    String vmwareDcName = vmwareDatacenter.getVmwareDatacenterName();
    String vCenterHost = vmwareDatacenter.getVcenterHost();
    String userName = vmwareDatacenter.getUser();
    String password = vmwareDatacenter.getPassword();
    List<PbmProfile> storageProfiles = null;
    try {
        s_logger.debug(String.format("Importing vSphere Storage Policies for the vmware DC %d in zone %d", vmwareDcId, zoneId));
        VmwareContext context = VmwareContextFactory.getContext(vCenterHost, userName, password);
        PbmProfileManagerMO profileManagerMO = new PbmProfileManagerMO(context);
        storageProfiles = profileManagerMO.getStorageProfiles();
        s_logger.debug(String.format("Import vSphere Storage Policies for the vmware DC %d in zone %d is successful", vmwareDcId, zoneId));
    } catch (Exception e) {
        String msg = String.format("Unable to list storage profiles from DC %s due to : %s", vmwareDcName, VmwareHelper.getExceptionMessage(e));
        s_logger.error(msg);
        throw new CloudRuntimeException(msg);
    }
    for (PbmProfile storageProfile : storageProfiles) {
        VsphereStoragePolicyVO storagePolicyVO = vsphereStoragePolicyDao.findByPolicyId(zoneId, storageProfile.getProfileId().getUniqueId());
        if (storagePolicyVO == null) {
            storagePolicyVO = new VsphereStoragePolicyVO(zoneId, storageProfile.getProfileId().getUniqueId(), storageProfile.getName(), storageProfile.getDescription());
            vsphereStoragePolicyDao.persist(storagePolicyVO);
        } else {
            storagePolicyVO.setDescription(storageProfile.getDescription());
            storagePolicyVO.setName(storageProfile.getName());
            vsphereStoragePolicyDao.update(storagePolicyVO.getId(), storagePolicyVO);
        }
    }
    List<VsphereStoragePolicyVO> allStoragePolicies = vsphereStoragePolicyDao.listAll();
    List<PbmProfile> finalStorageProfiles = storageProfiles;
    List<VsphereStoragePolicyVO> needToMarkRemoved = allStoragePolicies.stream().filter(existingPolicy -> !finalStorageProfiles.stream().anyMatch(storageProfile -> storageProfile.getProfileId().getUniqueId().equals(existingPolicy.getPolicyId()))).collect(Collectors.toList());
    for (VsphereStoragePolicyVO storagePolicy : needToMarkRemoved) {
        vsphereStoragePolicyDao.remove(storagePolicy.getId());
    }
    List<VsphereStoragePolicyVO> storagePolicies = vsphereStoragePolicyDao.listAll();
    return storagePolicies;
}
Also used : DiscoveredWithErrorException(com.cloud.exception.DiscoveredWithErrorException) NetworkModel(com.cloud.network.NetworkModel) HostDao(com.cloud.host.dao.HostDao) HypervisorGuruManager(com.cloud.hypervisor.HypervisorGuruManager) VmwareDatacenterZoneMap(com.cloud.hypervisor.vmware.VmwareDatacenterZoneMap) Transaction(com.cloud.utils.db.Transaction) ClusterType(com.cloud.org.Cluster.ClusterType) StringUtils(org.apache.commons.lang3.StringUtils) AgentManager(com.cloud.agent.AgentManager) DatacenterMO(com.cloud.hypervisor.vmware.mo.DatacenterMO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) VirtualSwitchType(com.cloud.hypervisor.vmware.mo.VirtualSwitchType) VMTemplatePoolDao(com.cloud.storage.dao.VMTemplatePoolDao) RemoveVmwareDcCmd(org.apache.cloudstack.api.command.admin.zone.RemoveVmwareDcCmd) Duration(java.time.Duration) Map(java.util.Map) VsphereStoragePolicy(com.cloud.dc.VsphereStoragePolicy) TrafficType(com.cloud.network.Networks.TrafficType) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) VmwareContextFactory(com.cloud.hypervisor.vmware.resource.VmwareContextFactory) AgentControlCommand(com.cloud.agent.api.AgentControlCommand) VmwareDatacenter(com.cloud.hypervisor.vmware.VmwareDatacenter) TransactionStatus(com.cloud.utils.db.TransactionStatus) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) FileUtil(com.cloud.utils.FileUtil) Executors(java.util.concurrent.Executors) Script(com.cloud.utils.script.Script) ConfigurationServer(com.cloud.server.ConfigurationServer) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) ImageStoreDetailsUtil(com.cloud.storage.ImageStoreDetailsUtil) AsyncJobManagerImpl(org.apache.cloudstack.framework.jobs.impl.AsyncJobManagerImpl) ClusterVSMMapDao(com.cloud.dc.dao.ClusterVSMMapDao) ManagementServerHostPeerDao(com.cloud.cluster.dao.ManagementServerHostPeerDao) HypervisorCapabilitiesDao(com.cloud.hypervisor.dao.HypervisorCapabilitiesDao) JavaStorageLayer(com.cloud.storage.JavaStorageLayer) NumbersUtil(com.cloud.utils.NumbersUtil) ManagerBase(com.cloud.utils.component.ManagerBase) DataCenterVO(com.cloud.dc.DataCenterVO) VirtualEthernetCardType(com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType) CiscoNexusVSMDeviceVO(com.cloud.network.CiscoNexusVSMDeviceVO) ArrayList(java.util.ArrayList) LegacyZoneDao(com.cloud.hypervisor.vmware.dao.LegacyZoneDao) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ClusterDao(com.cloud.dc.dao.ClusterDao) DomainRouterVO(com.cloud.vm.DomainRouterVO) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) UpdateVmwareDcCmd(org.apache.cloudstack.api.command.admin.zone.UpdateVmwareDcCmd) ClusterVO(com.cloud.dc.ClusterVO) VMInstanceDao(com.cloud.vm.dao.VMInstanceDao) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) VmwareCleanupMaid(com.cloud.hypervisor.vmware.VmwareCleanupMaid) VmwareDatacenterDao(com.cloud.hypervisor.vmware.dao.VmwareDatacenterDao) UserVmCloneSettingDao(com.cloud.vm.dao.UserVmCloneSettingDao) ClusterVSMMapVO(com.cloud.dc.ClusterVSMMapVO) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) IOException(java.io.IOException) DB(com.cloud.utils.db.DB) File(java.io.File) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) ClusterManager(com.cloud.cluster.ClusterManager) VmwareHelper(com.cloud.hypervisor.vmware.util.VmwareHelper) Command(com.cloud.agent.api.Command) Host(com.cloud.host.Host) AddVmwareDcCmd(org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd) ActionEvent(com.cloud.event.ActionEvent) ClusterDetailsDao(com.cloud.dc.ClusterDetailsDao) GlobalLock(com.cloud.utils.db.GlobalLock) ConfigurationDao(org.apache.cloudstack.framework.config.dao.ConfigurationDao) ResourceInUseException(com.cloud.exception.ResourceInUseException) StorageManager(com.cloud.storage.StorageManager) TemplateManager(com.cloud.template.TemplateManager) URLDecoder(java.net.URLDecoder) HypervisorHostHelper(com.cloud.hypervisor.vmware.mo.HypervisorHostHelper) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) DiscoveryException(com.cloud.exception.DiscoveryException) StoragePoolStatus(com.cloud.storage.StoragePoolStatus) Random(java.util.Random) StoragePool(com.cloud.storage.StoragePool) UriUtils(com.cloud.utils.UriUtils) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Cluster(com.cloud.org.Cluster) Logger(org.apache.log4j.Logger) StartupCommand(com.cloud.agent.api.StartupCommand) CommandExecLogDao(com.cloud.secstorage.CommandExecLogDao) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) URI(java.net.URI) Answer(com.cloud.agent.api.Answer) Config(com.cloud.configuration.Config) VmwareHostType(com.cloud.hypervisor.vmware.mo.VmwareHostType) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) PrimaryDataStoreDao(org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao) TransactionCallback(com.cloud.utils.db.TransactionCallback) UUID(java.util.UUID) Pair(com.cloud.utils.Pair) Instant(java.time.Instant) VsphereStoragePolicyVO(com.cloud.dc.VsphereStoragePolicyVO) HostFirewallSystemMO(com.cloud.hypervisor.vmware.mo.HostFirewallSystemMO) Collectors(java.util.stream.Collectors) CheckDataStoreStoragePolicyComplainceCommand(org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand) RemoteException(java.rmi.RemoteException) Status(com.cloud.host.Status) List(java.util.List) DataCenterDao(com.cloud.dc.dao.DataCenterDao) DiskControllerType(com.cloud.hypervisor.vmware.mo.DiskControllerType) AboutInfo(com.vmware.vim25.AboutInfo) VmwareDatacenterZoneMapVO(com.cloud.hypervisor.vmware.VmwareDatacenterZoneMapVO) BroadcastDomainType(com.cloud.network.Networks.BroadcastDomainType) DataStoreManager(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager) HashMap(java.util.HashMap) ListVsphereStoragePoliciesCmd(org.apache.cloudstack.api.command.admin.zone.ListVsphereStoragePoliciesCmd) ConfigurationException(javax.naming.ConfigurationException) EventTypes(com.cloud.event.EventTypes) CollectionUtils(com.amazonaws.util.CollectionUtils) Inject(javax.inject.Inject) ConfigKey(org.apache.cloudstack.framework.config.ConfigKey) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Listener(com.cloud.agent.Listener) ListVmwareDcsCmd(org.apache.cloudstack.api.command.admin.zone.ListVmwareDcsCmd) SshHelper(com.cloud.utils.ssh.SshHelper) PbmProfile(com.vmware.pbm.PbmProfile) CiscoNexusVSMDeviceDao(com.cloud.network.dao.CiscoNexusVSMDeviceDao) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) Configurable(org.apache.cloudstack.framework.config.Configurable) ListVsphereStoragePolicyCompatiblePoolsCmd(org.apache.cloudstack.api.command.admin.zone.ListVsphereStoragePolicyCompatiblePoolsCmd) ManagementServerNode(org.apache.cloudstack.utils.identity.ManagementServerNode) NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) HostVO(com.cloud.host.HostVO) VsphereStoragePolicyDao(com.cloud.dc.dao.VsphereStoragePolicyDao) MapUtils(org.apache.commons.collections.MapUtils) VmwareDatacenterZoneMapDao(com.cloud.hypervisor.vmware.dao.VmwareDatacenterZoneMapDao) CustomFieldConstants(com.cloud.hypervisor.vmware.mo.CustomFieldConstants) HostMO(com.cloud.hypervisor.vmware.mo.HostMO) Hypervisor(com.cloud.hypervisor.Hypervisor) LegacyZoneVO(com.cloud.hypervisor.vmware.LegacyZoneVO) FileInputStream(java.io.FileInputStream) PbmProfileManagerMO(com.cloud.hypervisor.vmware.mo.PbmProfileManagerMO) ImportVsphereStoragePoliciesCmd(org.apache.cloudstack.api.command.admin.zone.ImportVsphereStoragePoliciesCmd) HostDetailsDao(com.cloud.host.dao.HostDetailsDao) TimeUnit(java.util.concurrent.TimeUnit) TemplateJoinDao(com.cloud.api.query.dao.TemplateJoinDao) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VmwareTrafficLabel(com.cloud.network.VmwareTrafficLabel) VmwareDatacenterVO(com.cloud.hypervisor.vmware.VmwareDatacenterVO) VmwareDatacenterService(com.cloud.hypervisor.vmware.VmwareDatacenterService) DigestUtils(org.apache.commons.codec.digest.DigestUtils) StorageLayer(com.cloud.storage.StorageLayer) Collections(java.util.Collections) ManagementServerHost(org.apache.cloudstack.management.ManagementServerHost) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) PbmProfile(com.vmware.pbm.PbmProfile) VmwareDatacenterVO(com.cloud.hypervisor.vmware.VmwareDatacenterVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PbmProfileManagerMO(com.cloud.hypervisor.vmware.mo.PbmProfileManagerMO) DiscoveredWithErrorException(com.cloud.exception.DiscoveredWithErrorException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) ResourceInUseException(com.cloud.exception.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) DiscoveryException(com.cloud.exception.DiscoveryException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) RemoteException(java.rmi.RemoteException) ConfigurationException(javax.naming.ConfigurationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) VsphereStoragePolicyVO(com.cloud.dc.VsphereStoragePolicyVO)

Aggregations

VsphereStoragePolicyVO (com.cloud.dc.VsphereStoragePolicyVO)6 Answer (com.cloud.agent.api.Answer)3 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)3 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)3 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)3 ArrayList (java.util.ArrayList)3 CheckDataStoreStoragePolicyComplainceCommand (org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand)3 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)2 Pair (com.cloud.utils.Pair)2 CollectionUtils (com.amazonaws.util.CollectionUtils)1 AgentManager (com.cloud.agent.AgentManager)1 Listener (com.cloud.agent.Listener)1 AgentControlCommand (com.cloud.agent.api.AgentControlCommand)1 Command (com.cloud.agent.api.Command)1 GetStoragePoolCapabilitiesAnswer (com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer)1 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)1 GetVolumeStatsAnswer (com.cloud.agent.api.GetVolumeStatsAnswer)1 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)1 StartupCommand (com.cloud.agent.api.StartupCommand)1 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)1