Search in sources :

Example 36 with Pair

use of com.cloud.legacymodel.utils.Pair in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method destroyNetwork.

@Override
@DB
public boolean destroyNetwork(final long networkId, final ReservationContext context, final boolean forced) {
    final Account callerAccount = context.getAccount();
    NetworkVO network = _networksDao.findById(networkId);
    if (network == null) {
        s_logger.debug("Unable to find network with id: " + networkId);
        return false;
    }
    // Make sure that there are no user vms in the network that are not Expunged/Error
    final List<UserVmVO> userVms = _userVmDao.listByNetworkIdAndStates(networkId);
    for (final UserVmVO vm : userVms) {
        if (!(vm.getState() == VirtualMachine.State.Expunging && vm.getRemoved() != null)) {
            s_logger.warn("Can't delete the network, not all user vms are expunged. Vm " + vm + " is in " + vm.getState() + " state");
            return false;
        }
    }
    // Don't allow to delete network via api call when it has vms assigned to it
    final int nicCount = getActiveNicsInNetwork(networkId);
    if (nicCount > 0) {
        s_logger.debug("The network id=" + networkId + " has active Nics, but shouldn't.");
        // at this point we have already determined that there are no active user vms in network
        // if the op_networks table shows active nics, it's a bug in releasing nics updating op_networks
        _networksDao.changeActiveNicsBy(networkId, -1 * nicCount);
    }
    // In Basic zone, make sure that there are no non-removed console proxies and SSVMs using the network
    final Zone zone = _zoneRepository.findById(network.getDataCenterId()).orElse(null);
    if (zone.getNetworkType() == com.cloud.model.enumeration.NetworkType.Basic) {
        final List<VMInstanceVO> systemVms = _vmDao.listNonRemovedVmsByTypeAndNetwork(network.getId(), VirtualMachineType.ConsoleProxy, VirtualMachineType.SecondaryStorageVm);
        if (systemVms != null && !systemVms.isEmpty()) {
            s_logger.warn("Can't delete the network, not all consoleProxy/secondaryStorage vms are expunged");
            return false;
        }
    }
    // Shutdown network first
    shutdownNetwork(networkId, context, false);
    // get updated state for the network
    network = _networksDao.findById(networkId);
    if (network.getState() != Network.State.Allocated && network.getState() != Network.State.Setup && !forced) {
        s_logger.debug("Network is not not in the correct state to be destroyed: " + network.getState());
        return false;
    }
    boolean success = true;
    if (!cleanupNetworkResources(networkId, callerAccount, context.getCaller().getId())) {
        s_logger.warn("Unable to delete network id=" + networkId + ": failed to cleanup network resources");
        return false;
    }
    // get providers to destroy
    final List<Provider> providersToDestroy = getNetworkProviders(network.getId());
    for (final NetworkElement element : networkElements) {
        if (providersToDestroy.contains(element.getProvider())) {
            try {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Sending destroy to " + element);
                }
                if (!element.destroy(network, context)) {
                    success = false;
                    s_logger.warn("Unable to complete destroy of the network: failed to destroy network element " + element.getName());
                }
            } catch (final ResourceUnavailableException e) {
                s_logger.warn("Unable to complete destroy of the network due to element: " + element.getName(), e);
                success = false;
            } catch (final ConcurrentOperationException e) {
                s_logger.warn("Unable to complete destroy of the network due to element: " + element.getName(), e);
                success = false;
            } catch (final Exception e) {
                s_logger.warn("Unable to complete destroy of the network due to element: " + element.getName(), e);
                success = false;
            }
        }
    }
    if (success) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Network id=" + networkId + " is destroyed successfully, cleaning up corresponding resources now.");
        }
        final NetworkVO networkFinal = network;
        try {
            Transaction.execute(new TransactionCallbackNoReturn() {

                @Override
                public void doInTransactionWithoutResult(final TransactionStatus status) {
                    final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, networkFinal.getGuruName());
                    // Deleting sync networks
                    final List<NetworkVO> syncNetworks = _networksDao.listSyncNetworksByRelatedNetwork(networkId);
                    syncNetworks.forEach(syncNetwork -> removeAndShutdownSyncNetwork(syncNetwork.getId()));
                    guru.trash(networkFinal, _networkOfferingDao.findById(networkFinal.getNetworkOfferingId()));
                    if (!deleteVlansInNetwork(networkFinal.getId(), context.getCaller().getId(), callerAccount)) {
                        s_logger.warn("Failed to delete network " + networkFinal + "; was unable to cleanup corresponding ip ranges");
                        throw new CloudRuntimeException("Failed to delete network " + networkFinal + "; was unable to cleanup corresponding ip ranges");
                    } else {
                        // commit transaction only when ips and vlans for the network are released successfully
                        try {
                            stateTransitTo(networkFinal, Event.DestroyNetwork);
                        } catch (final NoTransitionException e) {
                            s_logger.debug(e.getMessage());
                        }
                        if (_networksDao.remove(networkFinal.getId())) {
                            final NetworkDomainVO networkDomain = _networkDomainDao.getDomainNetworkMapByNetworkId(networkFinal.getId());
                            if (networkDomain != null) {
                                _networkDomainDao.remove(networkDomain.getId());
                            }
                            final NetworkAccountVO networkAccount = _networkAccountDao.getAccountNetworkMapByNetworkId(networkFinal.getId());
                            if (networkAccount != null) {
                                _networkAccountDao.remove(networkAccount.getId());
                            }
                        }
                        final NetworkOffering ntwkOff = _entityMgr.findById(NetworkOffering.class, networkFinal.getNetworkOfferingId());
                        final boolean updateResourceCount = resourceCountNeedsUpdate(ntwkOff, networkFinal.getAclType());
                        if (updateResourceCount) {
                            _resourceLimitMgr.decrementResourceCount(networkFinal.getAccountId(), ResourceType.network, networkFinal.getDisplayNetwork());
                        }
                    }
                }
            });
            if (_networksDao.findById(network.getId()) == null) {
                // remove its related ACL permission
                final Pair<Class<?>, Long> networkMsg = new Pair<>(Network.class, networkFinal.getId());
                _messageBus.publish(_name, EntityManager.MESSAGE_REMOVE_ENTITY_EVENT, PublishScope.LOCAL, networkMsg);
            }
            return true;
        } catch (final CloudRuntimeException e) {
            s_logger.error("Failed to delete network", e);
            return false;
        }
    }
    return success;
}
Also used : PhysicalNetworkTrafficTypeDao(com.cloud.network.dao.PhysicalNetworkTrafficTypeDao) NetworkModel(com.cloud.network.NetworkModel) ConfigKey(com.cloud.framework.config.ConfigKey) HostDao(com.cloud.host.dao.HostDao) ConnectionException(com.cloud.legacymodel.exceptions.ConnectionException) VMNetworkMapVO(com.cloud.engine.cloud.entity.api.db.VMNetworkMapVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Nic(com.cloud.legacymodel.network.Nic) PodVlanMapDao(com.cloud.dc.dao.PodVlanMapDao) Scope(com.cloud.framework.config.ConfigKey.Scope) Transaction(com.cloud.utils.db.Transaction) TransactionCallbackWithExceptionNoReturn(com.cloud.utils.db.TransactionCallbackWithExceptionNoReturn) AgentManager(com.cloud.agent.AgentManager) PhysicalNetworkTrafficTypeVO(com.cloud.network.dao.PhysicalNetworkTrafficTypeVO) ReservationContext(com.cloud.vm.ReservationContext) VlanDao(com.cloud.dc.dao.VlanDao) Map(java.util.Map) NetworkServiceMapDao(com.cloud.network.dao.NetworkServiceMapDao) ZoneRepository(com.cloud.db.repository.ZoneRepository) PhysicalNetworkDao(com.cloud.network.dao.PhysicalNetworkDao) Host(com.cloud.legacymodel.dc.Host) PhysicalNetworkSetupInfo(com.cloud.legacymodel.network.PhysicalNetworkSetupInfo) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkGuru(com.cloud.network.guru.NetworkGuru) FirewallRule(com.cloud.legacymodel.network.FirewallRule) DataCenterVnetVO(com.cloud.dc.DataCenterVnetVO) NicTO(com.cloud.legacymodel.to.NicTO) TransactionStatus(com.cloud.utils.db.TransactionStatus) StartupCommand(com.cloud.legacymodel.communication.command.startup.StartupCommand) Set(java.util.Set) StaticNatRule(com.cloud.legacymodel.network.StaticNatRule) NetworkElement(com.cloud.network.element.NetworkElement) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) Executors(java.util.concurrent.Executors) ACLType(com.cloud.legacymodel.acl.ControlledEntity.ACLType) ReservationStrategy(com.cloud.legacymodel.network.Nic.ReservationStrategy) DataCenter(com.cloud.legacymodel.dc.DataCenter) PortForwardingRulesDao(com.cloud.network.rules.dao.PortForwardingRulesDao) StaticNatRuleImpl(com.cloud.network.rules.StaticNatRuleImpl) AccountDao(com.cloud.user.dao.AccountDao) AdapterBase(com.cloud.utils.component.AdapterBase) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) IpAddressManager(com.cloud.network.IpAddressManager) NumbersUtil(com.cloud.utils.NumbersUtil) ManagerBase(com.cloud.utils.component.ManagerBase) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) StateMachine2(com.cloud.legacymodel.statemachine.StateMachine2) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine) CallContext(com.cloud.context.CallContext) Zone(com.cloud.db.model.Zone) IpDeployer(com.cloud.network.element.IpDeployer) NetworkOfferingServiceMapDao(com.cloud.offerings.dao.NetworkOfferingServiceMapDao) NicProfile(com.cloud.vm.NicProfile) ArrayList(java.util.ArrayList) Purpose(com.cloud.legacymodel.network.FirewallRule.Purpose) LinkedHashMap(java.util.LinkedHashMap) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) VlanVO(com.cloud.dc.VlanVO) ConfigurationDao(com.cloud.framework.config.dao.ConfigurationDao) DomainRouterVO(com.cloud.vm.DomainRouterVO) BroadcastDomainType(com.cloud.model.enumeration.BroadcastDomainType) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) VMInstanceDao(com.cloud.vm.dao.VMInstanceDao) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) DomainRouterDao(com.cloud.vm.dao.DomainRouterDao) MessageBus(com.cloud.framework.messagebus.MessageBus) VirtualMachineType(com.cloud.model.enumeration.VirtualMachineType) Op(com.cloud.utils.db.SearchCriteria.Op) EntityManager(com.cloud.dao.EntityManager) UserVmDao(com.cloud.vm.dao.UserVmDao) HostStatus(com.cloud.legacymodel.dc.HostStatus) InsufficientVirtualNetworkCapacityException(com.cloud.legacymodel.exceptions.InsufficientVirtualNetworkCapacityException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) NicDao(com.cloud.vm.dao.NicDao) PhysicalNetwork(com.cloud.network.PhysicalNetwork) RemoteAccessVpn(com.cloud.network.RemoteAccessVpn) DB(com.cloud.utils.db.DB) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ManagedContextRunnable(com.cloud.common.managed.context.ManagedContextRunnable) InsufficientAddressCapacityException(com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException) GlobalLock(com.cloud.utils.db.GlobalLock) NetworkOfferingDetailsDao(com.cloud.offerings.dao.NetworkOfferingDetailsDao) RulesManager(com.cloud.network.rules.RulesManager) CheckNetworkAnswer(com.cloud.legacymodel.communication.answer.CheckNetworkAnswer) NicSecondaryIpDao(com.cloud.vm.dao.NicSecondaryIpDao) AggregatedCommandExecutor(com.cloud.network.element.AggregatedCommandExecutor) LoggerFactory(org.slf4j.LoggerFactory) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) Service(com.cloud.legacymodel.network.Network.Service) NetworkType(com.cloud.model.enumeration.NetworkType) Networks(com.cloud.network.Networks) NetworkAccountVO(com.cloud.network.dao.NetworkAccountVO) AlertManager(com.cloud.alert.AlertManager) StateMachine2Transitions(com.cloud.utils.fsm.StateMachine2Transitions) AgentControlAnswer(com.cloud.legacymodel.communication.answer.AgentControlAnswer) NetworkMigrationResponder(com.cloud.network.NetworkMigrationResponder) IllegalVirtualMachineException(com.cloud.legacymodel.exceptions.IllegalVirtualMachineException) DeploymentPlan(com.cloud.deploy.DeploymentPlan) VMNetworkMapDao(com.cloud.engine.cloud.entity.api.db.dao.VMNetworkMapDao) ResourceLimitService(com.cloud.user.ResourceLimitService) URI(java.net.URI) Vlan(com.cloud.legacymodel.dc.Vlan) Scheme(com.cloud.legacymodel.network.LoadBalancerContainer.Scheme) NetworkProfile(com.cloud.network.NetworkProfile) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) PublishScope(com.cloud.framework.messagebus.PublishScope) TrafficType(com.cloud.model.enumeration.TrafficType) VMInstanceVO(com.cloud.vm.VMInstanceVO) TransactionCallback(com.cloud.utils.db.TransactionCallback) DeployDestination(com.cloud.deploy.DeployDestination) IpAddress(com.cloud.network.IpAddress) VpcVirtualNetworkApplianceService(com.cloud.network.VpcVirtualNetworkApplianceService) AccountGuestVlanMapVO(com.cloud.network.dao.AccountGuestVlanMapVO) Command(com.cloud.legacymodel.communication.command.Command) AgentControlCommand(com.cloud.legacymodel.communication.command.agentcontrol.AgentControlCommand) NicVO(com.cloud.vm.NicVO) UUID(java.util.UUID) VpcManager(com.cloud.network.vpc.VpcManager) HypervisorType(com.cloud.model.enumeration.HypervisorType) PodVlanMapVO(com.cloud.dc.PodVlanMapVO) List(java.util.List) Provider(com.cloud.legacymodel.network.Network.Provider) NetworkDomainVO(com.cloud.network.dao.NetworkDomainVO) NetworkOfferingServiceMapVO(com.cloud.offerings.NetworkOfferingServiceMapVO) User(com.cloud.legacymodel.user.User) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) Answer(com.cloud.legacymodel.communication.answer.Answer) NetUtils(com.cloud.utils.net.NetUtils) NetworkServiceMapVO(com.cloud.network.dao.NetworkServiceMapVO) NetworkDomainDao(com.cloud.network.dao.NetworkDomainDao) DataCenterVnetDao(com.cloud.dc.dao.DataCenterVnetDao) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) ResourceType(com.cloud.legacymodel.configuration.Resource.ResourceType) Event(com.cloud.legacymodel.network.Network.Event) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) SearchBuilder(com.cloud.utils.db.SearchBuilder) StartupRoutingCommand(com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand) Configurable(com.cloud.framework.config.Configurable) HashMap(java.util.HashMap) UnsupportedServiceException(com.cloud.legacymodel.exceptions.UnsupportedServiceException) NetworkDao(com.cloud.network.dao.NetworkDao) ConfigurationException(javax.naming.ConfigurationException) Domain(com.cloud.legacymodel.domain.Domain) PortForwardingRuleVO(com.cloud.network.rules.PortForwardingRuleVO) JoinType(com.cloud.utils.db.JoinBuilder.JoinType) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Listener(com.cloud.agent.Listener) CheckNetworkCommand(com.cloud.legacymodel.communication.command.CheckNetworkCommand) IPAddressVO(com.cloud.network.dao.IPAddressVO) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkServiceProviderDao(com.cloud.network.dao.PhysicalNetworkServiceProviderDao) IPAddressDao(com.cloud.network.dao.IPAddressDao) GuestType(com.cloud.model.enumeration.GuestType) RedundantState(com.cloud.legacymodel.network.VirtualRouter.RedundantState) FirewallRulesDao(com.cloud.network.dao.FirewallRulesDao) NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) PublicIp(com.cloud.network.addr.PublicIp) Network(com.cloud.legacymodel.network.Network) ConfigurationManager(com.cloud.configuration.ConfigurationManager) LoadBalancingRulesManager(com.cloud.network.lb.LoadBalancingRulesManager) Logger(org.slf4j.Logger) Pair(com.cloud.legacymodel.utils.Pair) NetworkACLManager(com.cloud.network.vpc.NetworkACLManager) Account(com.cloud.legacymodel.user.Account) Capability(com.cloud.legacymodel.network.Network.Capability) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) PrivateIpDao(com.cloud.network.vpc.dao.PrivateIpDao) AccountGuestVlanMapDao(com.cloud.network.dao.AccountGuestVlanMapDao) NetworkOffering(com.cloud.offering.NetworkOffering) TimeUnit(java.util.concurrent.TimeUnit) UserVmVO(com.cloud.vm.UserVmVO) RemoteAccessVpnService(com.cloud.network.vpn.RemoteAccessVpnService) NetworkOfferingDao(com.cloud.offerings.dao.NetworkOfferingDao) NetworkAccountDao(com.cloud.network.dao.NetworkAccountDao) Vpc(com.cloud.legacymodel.network.vpc.Vpc) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) FirewallManager(com.cloud.network.rules.FirewallManager) NicSecondaryIpVO(com.cloud.vm.dao.NicSecondaryIpVO) Comparator(java.util.Comparator) Collections(java.util.Collections) Account(com.cloud.legacymodel.user.Account) UserVmVO(com.cloud.vm.UserVmVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) NetworkElement(com.cloud.network.element.NetworkElement) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) NetworkDomainVO(com.cloud.network.dao.NetworkDomainVO) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.legacymodel.utils.Pair) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkOffering(com.cloud.offering.NetworkOffering) Zone(com.cloud.db.model.Zone) NetworkGuru(com.cloud.network.guru.NetworkGuru) VMInstanceVO(com.cloud.vm.VMInstanceVO) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) ConnectionException(com.cloud.legacymodel.exceptions.ConnectionException) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) InsufficientVirtualNetworkCapacityException(com.cloud.legacymodel.exceptions.InsufficientVirtualNetworkCapacityException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) InsufficientAddressCapacityException(com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) IllegalVirtualMachineException(com.cloud.legacymodel.exceptions.IllegalVirtualMachineException) UnsupportedServiceException(com.cloud.legacymodel.exceptions.UnsupportedServiceException) ConfigurationException(javax.naming.ConfigurationException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) NetworkAccountVO(com.cloud.network.dao.NetworkAccountVO) DB(com.cloud.utils.db.DB)

Example 37 with Pair

use of com.cloud.legacymodel.utils.Pair in project cosmic by MissionCriticalCloud.

the class VmWorkJobHandlerProxy method handleVmWorkJob.

@Override
public Pair<JobInfo.Status, String> handleVmWorkJob(final VmWork work) throws CloudException {
    final Method method = getHandlerMethod(work.getClass());
    if (method != null) {
        try {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Execute VM work job: " + work.getClass().getName() + _gsonLogger.toJson(work));
            }
            final Object obj = method.invoke(_target, work);
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Done executing VM work job: " + work.getClass().getName() + _gsonLogger.toJson(work));
            }
            assert (obj instanceof Pair);
            return (Pair<JobInfo.Status, String>) obj;
        } catch (final InvocationTargetException e) {
            final Throwable cause = e.getCause();
            s_logger.error("Invocation exception, caused by: " + cause);
            // we need to re-throw the real exception here
            if (cause != null && cause instanceof Exception) {
                s_logger.info("Rethrow exception " + cause);
                throw new CloudException("Caught exception while handling a VmWorkJob", cause);
            }
            throw new CloudException("Caught exception while handling a VmWorkJob", e);
        } catch (final IllegalAccessException e) {
            throw new CloudException("Caught exception while handling a VmWorkJob", e);
        }
    } else {
        s_logger.error("Unable to find handler for VM work job: " + work.getClass().getName() + _gsonLogger.toJson(work));
        final RuntimeException ex = new RuntimeException("Unable to find handler for VM work job: " + work.getClass().getName());
        return new Pair<>(JobInfo.Status.FAILED, JobSerializerHelper.toObjectSerializedString(ex));
    }
}
Also used : JobInfo(com.cloud.jobs.JobInfo) Method(java.lang.reflect.Method) CloudException(com.cloud.legacymodel.exceptions.CloudException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CloudException(com.cloud.legacymodel.exceptions.CloudException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Pair(com.cloud.legacymodel.utils.Pair)

Example 38 with Pair

use of com.cloud.legacymodel.utils.Pair in project cosmic by MissionCriticalCloud.

the class StoragePoolHostDaoImpl method getDatacenterStoragePoolHostInfo.

@Override
public List<Pair<Long, Integer>> getDatacenterStoragePoolHostInfo(final long dcId, final boolean sharedOnly) {
    final ArrayList<Pair<Long, Integer>> l = new ArrayList<>();
    final String sql = sharedOnly ? SHARED_STORAGE_POOL_HOST_INFO : STORAGE_POOL_HOST_INFO;
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    PreparedStatement pstmt = null;
    try {
        pstmt = txn.prepareAutoCloseStatement(sql);
        pstmt.setLong(1, dcId);
        final ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            l.add(new Pair<>(rs.getLong(1), rs.getInt(2)));
        }
    } catch (final SQLException e) {
        s_logger.debug("SQLException: ", e);
    }
    return l;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Pair(com.cloud.legacymodel.utils.Pair)

Example 39 with Pair

use of com.cloud.legacymodel.utils.Pair in project cosmic by MissionCriticalCloud.

the class VolumeServiceImpl method registerVolumeForPostUpload.

@Override
public Pair<EndPoint, DataObject> registerVolumeForPostUpload(final VolumeInfo volume, final DataStore store) {
    final EndPoint ep = _epSelector.select(store);
    if (ep == null) {
        final String errorMessage = "There is no secondary storage VM for image store " + store.getName();
        s_logger.warn(errorMessage);
        throw new CloudRuntimeException(errorMessage);
    }
    final DataObject volumeOnStore = store.create(volume);
    return new Pair<>(ep, volumeOnStore);
}
Also used : DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) Pair(com.cloud.legacymodel.utils.Pair)

Example 40 with Pair

use of com.cloud.legacymodel.utils.Pair in project cosmic by MissionCriticalCloud.

the class AbstractHyperVisorStorageMotionStrategy method buildVolumeMapping.

protected List<Pair<VolumeTO, StorageFilerTO>> buildVolumeMapping(final Map<VolumeInfo, DataStore> volumeToPool) {
    final List<Pair<VolumeTO, StorageFilerTO>> volumeToFilerto = new ArrayList<>();
    for (final Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
        final VolumeInfo volume = entry.getKey();
        final StoragePool storagePool = storagePoolDao.findById(volume.getPoolId());
        final VolumeTO volumeTo = new VolumeTO(volume.getId(), volume.getVolumeType(), storagePool.getPoolType(), storagePool.getUuid(), volume.getName(), volume.getFolder(), volume.getPath(), volume.getSize(), volume.getChainInfo(), volume.getFormat(), volume.getProvisioningType());
        final StorageFilerTO filerTo = new StorageFilerTO((StoragePool) entry.getValue());
        volumeToFilerto.add(new Pair<>(volumeTo, filerTo));
    }
    return volumeToFilerto;
}
Also used : VolumeTO(com.cloud.legacymodel.to.VolumeTO) StoragePool(com.cloud.legacymodel.storage.StoragePool) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) Map(java.util.Map) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) Pair(com.cloud.legacymodel.utils.Pair)

Aggregations

Pair (com.cloud.legacymodel.utils.Pair)139 ArrayList (java.util.ArrayList)87 List (java.util.List)64 Account (com.cloud.legacymodel.user.Account)49 Filter (com.cloud.utils.db.Filter)48 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)38 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)27 HashMap (java.util.HashMap)27 Ternary (com.cloud.legacymodel.utils.Ternary)23 ListProjectResourcesCriteria (com.cloud.projects.Project.ListProjectResourcesCriteria)22 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)20 SSHKeyPair (com.cloud.legacymodel.user.SSHKeyPair)16 TemplateFilter (com.cloud.legacymodel.storage.VirtualMachineTemplate.TemplateFilter)13 Map (java.util.Map)13 DB (com.cloud.utils.db.DB)11 DomainVO (com.cloud.domain.DomainVO)10 VolumeVO (com.cloud.storage.VolumeVO)10 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)9 Network (com.cloud.legacymodel.network.Network)9 ResourceTagVO (com.cloud.tags.ResourceTagVO)9