Search in sources :

Example 71 with Pair

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

the class XenServer610MigrateWithStorageReceiveCommandWrapper method execute.

@Override
public Answer execute(final MigrateWithStorageReceiveCommand command, final XenServer610Resource xenServer610Resource) {
    final Connection connection = xenServer610Resource.getConnection();
    final VirtualMachineTO vmSpec = command.getVirtualMachine();
    final List<Pair<VolumeTO, StorageFilerTO>> volumeToFiler = command.getVolumeToFiler();
    try {
        // In a cluster management server setup, the migrate with storage receive and send
        // commands and answers may have to be forwarded to another management server. This
        // happens when the host/resource on which the command has to be executed is owned
        // by the second management server. The serialization/deserialization of the command
        // and answers fails as the xapi SR and Network class type isn't understand by the
        // agent attache. Seriliaze the SR and Network objects here to a string and pass in
        // the answer object. It'll be deserialzed and object created in migrate with
        // storage send command execution.
        final Gson gson = new Gson();
        // Get a map of all the SRs to which the vdis will be migrated.
        final List<Pair<VolumeTO, Object>> volumeToSr = new ArrayList<>();
        for (final Pair<VolumeTO, StorageFilerTO> entry : volumeToFiler) {
            final StorageFilerTO storageFiler = entry.second();
            final SR sr = xenServer610Resource.getStorageRepository(connection, storageFiler.getUuid());
            volumeToSr.add(new Pair<>(entry.first(), sr));
        }
        // Get the list of networks to which the vifs will attach.
        final List<Pair<NicTO, Object>> nicToNetwork = new ArrayList<>();
        for (final NicTO nicTo : vmSpec.getNics()) {
            final Network network = xenServer610Resource.getNetwork(connection, nicTo);
            nicToNetwork.add(new Pair<>(nicTo, network));
        }
        final XsLocalNetwork nativeNetworkForTraffic = xenServer610Resource.getNativeNetworkForTraffic(connection, TrafficType.Storage, null);
        final Network network = nativeNetworkForTraffic.getNetwork();
        final XsHost xsHost = xenServer610Resource.getHost();
        final String uuid = xsHost.getUuid();
        final Map<String, String> other = new HashMap<>();
        other.put("live", "true");
        final Host host = Host.getByUuid(connection, uuid);
        final Map<String, String> token = host.migrateReceive(connection, network, other);
        return new MigrateWithStorageReceiveAnswer(command, volumeToSr, nicToNetwork, token);
    } catch (final CloudRuntimeException e) {
        s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e);
        return new MigrateWithStorageReceiveAnswer(command, e);
    } catch (final Exception e) {
        s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e);
        return new MigrateWithStorageReceiveAnswer(command, e);
    }
}
Also used : XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) HashMap(java.util.HashMap) Connection(com.xensource.xenapi.Connection) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Host(com.xensource.xenapi.Host) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) VirtualMachineTO(com.cloud.legacymodel.to.VirtualMachineTO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VolumeTO(com.cloud.legacymodel.to.VolumeTO) MigrateWithStorageReceiveAnswer(com.cloud.legacymodel.communication.answer.MigrateWithStorageReceiveAnswer) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Pair(com.cloud.legacymodel.utils.Pair) SR(com.xensource.xenapi.SR) NicTO(com.cloud.legacymodel.to.NicTO)

Example 72 with Pair

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

the class CitrixResourceBase method getControlDomain.

protected Pair<VM, VM.Record> getControlDomain(final Connection conn) throws XenAPIException, XmlRpcException {
    final Host host = Host.getByUuid(conn, this._host.getUuid());
    Set<VM> vms = null;
    vms = host.getResidentVMs(conn);
    for (final VM vm : vms) {
        if (vm.getIsControlDomain(conn)) {
            return new Pair<>(vm, vm.getRecord(conn));
        }
    }
    throw new CloudRuntimeException("Com'on no control domain?  What the crap?!#@!##$@");
}
Also used : CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VM(com.xensource.xenapi.VM) Host(com.xensource.xenapi.Host) Pair(com.cloud.legacymodel.utils.Pair)

Example 73 with Pair

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

the class XenServerGuru method getCommandHostDelegation.

@Override
public Pair<Boolean, Long> getCommandHostDelegation(final long hostId, final Command cmd) {
    LOGGER.debug("getCommandHostDelegation: " + cmd.getClass());
    if (cmd instanceof StorageSubSystemCommand) {
        final StorageSubSystemCommand c = (StorageSubSystemCommand) cmd;
        c.setExecuteInSequence(true);
    }
    if (cmd instanceof CopyCommand) {
        final CopyCommand cpyCommand = (CopyCommand) cmd;
        final DataTO srcData = cpyCommand.getSrcTO();
        final DataTO destData = cpyCommand.getDestTO();
        if (srcData.getHypervisorType() == HypervisorType.XenServer && srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.TEMPLATE) {
            final DataStoreTO srcStore = srcData.getDataStore();
            final DataStoreTO destStore = destData.getDataStore();
            if (srcStore instanceof NfsTO && destStore instanceof NfsTO) {
                HostVO host = hostDao.findById(hostId);
                final EndPoint ep = endPointSelector.selectHypervisorHost(new ZoneScope(host.getDataCenterId()));
                host = hostDao.findById(ep.getId());
                hostDao.loadDetails(host);
                final String hypervisorVersion = host.getHypervisorVersion();
                final String snapshotHotFixVersion = host.getDetail(XenserverConfigs.XS620HotFix);
                if (hypervisorVersion != null && !hypervisorVersion.equalsIgnoreCase("6.1.0")) {
                    if (!(hypervisorVersion.equalsIgnoreCase("6.2.0") && !(snapshotHotFixVersion != null && snapshotHotFixVersion.equalsIgnoreCase(XenserverConfigs.XSHotFix62ESP1004)))) {
                        return new Pair<>(Boolean.TRUE, new Long(ep.getId()));
                    }
                }
            }
        }
    }
    return new Pair<>(Boolean.FALSE, new Long(hostId));
}
Also used : ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) StorageSubSystemCommand(com.cloud.legacymodel.communication.command.StorageSubSystemCommand) DataTO(com.cloud.legacymodel.to.DataTO) CopyCommand(com.cloud.legacymodel.communication.command.CopyCommand) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) NfsTO(com.cloud.legacymodel.to.NfsTO) HostVO(com.cloud.host.HostVO) Pair(com.cloud.legacymodel.utils.Pair)

Example 74 with Pair

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

the class VMInstanceDaoImpl method listClusterIdsInZoneByVmCount.

@Override
public Pair<List<Long>, Map<Long, Double>> listClusterIdsInZoneByVmCount(final long zoneId, final long accountId) {
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    PreparedStatement pstmt = null;
    final List<Long> result = new ArrayList<>();
    final Map<Long, Double> clusterVmCountMap = new HashMap<>();
    final StringBuilder sql = new StringBuilder(ORDER_CLUSTERS_NUMBER_OF_VMS_FOR_ACCOUNT_PART1);
    sql.append("host.data_center_id = ?");
    sql.append(ORDER_CLUSTERS_NUMBER_OF_VMS_FOR_ACCOUNT_PART2);
    try {
        pstmt = txn.prepareAutoCloseStatement(sql.toString());
        pstmt.setLong(1, accountId);
        pstmt.setLong(2, zoneId);
        final ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            final Long clusterId = rs.getLong(1);
            result.add(clusterId);
            clusterVmCountMap.put(clusterId, rs.getDouble(2));
        }
        return new Pair<>(result, clusterVmCountMap);
    } catch (final SQLException e) {
        throw new CloudRuntimeException("DB Exception on: " + sql, e);
    }
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ResultSet(java.sql.ResultSet) Pair(com.cloud.legacymodel.utils.Pair)

Example 75 with Pair

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

the class VMInstanceDaoImpl method listClusterIdsInPodByVmCount.

@Override
public Pair<List<Long>, Map<Long, Double>> listClusterIdsInPodByVmCount(final long podId, final long accountId) {
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    PreparedStatement pstmt = null;
    final List<Long> result = new ArrayList<>();
    final Map<Long, Double> clusterVmCountMap = new HashMap<>();
    final StringBuilder sql = new StringBuilder(ORDER_CLUSTERS_NUMBER_OF_VMS_FOR_ACCOUNT_PART1);
    sql.append("host.pod_id = ?");
    sql.append(ORDER_CLUSTERS_NUMBER_OF_VMS_FOR_ACCOUNT_PART2);
    try {
        pstmt = txn.prepareAutoCloseStatement(sql.toString());
        pstmt.setLong(1, accountId);
        pstmt.setLong(2, podId);
        final ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            final Long clusterId = rs.getLong(1);
            result.add(clusterId);
            clusterVmCountMap.put(clusterId, rs.getDouble(2));
        }
        return new Pair<>(result, clusterVmCountMap);
    } catch (final SQLException e) {
        throw new CloudRuntimeException("DB Exception on: " + sql, e);
    }
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ResultSet(java.sql.ResultSet) 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