Search in sources :

Example 46 with VdsStatic

use of org.ovirt.engine.core.common.businessentities.VdsStatic in project ovirt-engine by oVirt.

the class ChangeVDSClusterCommand method executeCommand.

@Override
protected void executeCommand() {
    final Guid targetClusterId = getParameters().getClusterId();
    if (getSourceCluster().getId().equals(targetClusterId)) {
        setSucceeded(true);
        return;
    }
    // save the new cluster id
    TransactionSupport.executeInNewTransaction(() -> {
        VdsStatic staticData = getVds().getStaticData();
        getCompensationContext().snapshotEntity(staticData);
        // of the host is needed to reconfigure the firewall.
        if (targetCluster.getFirewallType() != getSourceCluster().getFirewallType()) {
            staticData.setReinstallRequired(true);
        }
        staticData.setClusterId(targetClusterId);
        vdsStaticDao.update(staticData);
        getCompensationContext().stateChanged();
        // remove the server from resource manager and add it back
        initializeVds();
        return null;
    });
    if (targetStoragePool != null && (getSourceCluster().getStoragePoolId() == null || !targetStoragePool.getId().equals(getSourceCluster().getStoragePoolId()))) {
        VdsActionParameters addVdsSpmIdParams = new VdsActionParameters(getVdsIdRef());
        addVdsSpmIdParams.setSessionId(getParameters().getSessionId());
        addVdsSpmIdParams.setCompensationEnabled(true);
        ActionReturnValue addVdsSpmIdReturn = runInternalAction(ActionType.AddVdsSpmId, addVdsSpmIdParams, cloneContext().withoutLock().withoutExecutionContext());
        if (!addVdsSpmIdReturn.getSucceeded()) {
            setSucceeded(false);
            getReturnValue().setFault(addVdsSpmIdReturn.getFault());
            return;
        }
    }
    if (getSourceCluster().supportsGlusterService() && clusterUtils.hasServers(getSourceCluster().getId())) {
        if (!glusterHostRemove(getSourceCluster().getId())) {
            setSucceeded(false);
            return;
        }
    }
    if (getTargetCluster().supportsGlusterService() && clusterUtils.hasMultipleServers(getTargetCluster().getId())) {
        if (!glusterHostAdd(getTargetCluster().getId())) {
            setSucceeded(false);
            return;
        }
    }
    if (getSourceCluster().getStoragePoolId() != null && (targetStoragePool == null || !getSourceCluster().getStoragePoolId().equals(targetStoragePool.getId()))) {
        vdsSpmIdMapDao.removeByVdsAndStoragePool(getVds().getId(), getSourceCluster().getStoragePoolId());
    }
    HostNetworkAttachmentsPersister persister = new HostNetworkAttachmentsPersister(this.networkAttachmentDao, getVdsId(), interfaceDao.getAllInterfacesForVds(getVdsId()), Collections.emptyList(), getTargetClusterNetworks());
    persister.persistNetworkAttachments();
    if (VDSStatus.PendingApproval != getVds().getStatus()) {
        configureNetworks();
    }
    setSucceeded(true);
}
Also used : VdsStatic(org.ovirt.engine.core.common.businessentities.VdsStatic) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) VdsActionParameters(org.ovirt.engine.core.common.action.VdsActionParameters) Guid(org.ovirt.engine.core.compat.Guid) HostNetworkAttachmentsPersister(org.ovirt.engine.core.vdsbroker.vdsbroker.HostNetworkAttachmentsPersister)

Example 47 with VdsStatic

use of org.ovirt.engine.core.common.businessentities.VdsStatic in project ovirt-engine by oVirt.

the class GetVdsStaticByNameQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    VdsStatic vds = vdsStaticDao.getByVdsName(getParameters().getName());
    getQueryReturnValue().setReturnValue(vds);
}
Also used : VdsStatic(org.ovirt.engine.core.common.businessentities.VdsStatic)

Example 48 with VdsStatic

use of org.ovirt.engine.core.common.businessentities.VdsStatic in project ovirt-engine by oVirt.

the class GlusterTasksSyncJob method updateVolumeBricksAndLock.

private void updateVolumeBricksAndLock(Cluster cluster, GlusterAsyncTask task, final GlusterVolumeEntity vol) {
    try {
        // acquire lock on volume
        acquireLock(vol.getId());
        // update volume with task id
        volumeDao.updateVolumeTask(vol.getId(), task.getTaskId());
        if (GlusterTaskType.REMOVE_BRICK == task.getType()) {
            // update bricks associated with task id
            String[] bricks = task.getTaskParameters().getBricks();
            if (bricks != null) {
                List<GlusterBrickEntity> brickEntities = new ArrayList<>();
                for (String brick : bricks) {
                    String[] brickParts = brick.split(":", -1);
                    String hostnameOrIp = brickParts[0];
                    String brickDir = brickParts[1];
                    GlusterBrickEntity brickEntity = new GlusterBrickEntity();
                    VdsStatic server = glusterDBUtils.getServer(cluster.getId(), hostnameOrIp);
                    if (server == null) {
                        log.warn("Could not find server '{}' in cluster '{}'", hostnameOrIp, cluster.getId());
                    } else {
                        brickEntity.setServerId(server.getId());
                        brickEntity.setBrickDirectory(brickDir);
                        brickEntity.setAsyncTask(new GlusterAsyncTask());
                        brickEntity.getAsyncTask().setTaskId(task.getTaskId());
                        brickEntities.add(brickEntity);
                    }
                }
                brickDao.updateAllBrickTasksByHostIdBrickDirInBatch(brickEntities);
            }
        }
        logTaskStartedFromCLI(cluster, task, vol);
    } catch (Exception e) {
        log.error("Exception", e);
        // Release the lock only if there is any exception,
        // otherwise the lock will be released once the task is completed
        releaseLock(vol.getId());
        throw new EngineException(EngineError.GeneralException, e.getMessage());
    }
}
Also used : VdsStatic(org.ovirt.engine.core.common.businessentities.VdsStatic) GlusterBrickEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity) GlusterAsyncTask(org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask) ArrayList(java.util.ArrayList) EngineException(org.ovirt.engine.core.common.errors.EngineException) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Example 49 with VdsStatic

use of org.ovirt.engine.core.common.businessentities.VdsStatic in project ovirt-engine by oVirt.

the class GlusterCommandBase method updateBrickServerAndInterfaceName.

protected boolean updateBrickServerAndInterfaceName(GlusterBrickEntity brick, boolean addValidationMessage) {
    VdsStatic server = vdsStaticDao.get(brick.getServerId());
    if (server == null || !server.getClusterId().equals(getClusterId())) {
        if (addValidationMessage) {
            addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_INVALID_BRICK_SERVER_ID);
        }
        return false;
    }
    brick.setServerName(server.getHostName());
    // engine will get the gluster network, if present
    if (brick.getNetworkId() == null) {
        Network network = getGlusterNetwork();
        if (network != null) {
            brick.setNetworkId(network.getId());
            brick.setNetworkAddress(getGlusterNetworkAddress(server.getId(), network.getName()));
        }
    } else {
        // network id has been set, update the address
        Network network = networkDao.get(brick.getNetworkId());
        if (network != null) {
            brick.setNetworkAddress(getGlusterNetworkAddress(server.getId(), network.getName()));
        }
    }
    return true;
}
Also used : VdsStatic(org.ovirt.engine.core.common.businessentities.VdsStatic) Network(org.ovirt.engine.core.common.businessentities.network.Network)

Aggregations

VdsStatic (org.ovirt.engine.core.common.businessentities.VdsStatic)49 Test (org.junit.Test)10 Guid (org.ovirt.engine.core.compat.Guid)8 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 Objects (java.util.Objects)3 Before (org.junit.Before)3 HostProviderProxy (org.ovirt.engine.core.bll.host.provider.HostProviderProxy)3 VdsDynamic (org.ovirt.engine.core.common.businessentities.VdsDynamic)3 GlusterVolumeEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)3 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 StringUtils (org.apache.commons.lang.StringUtils)2 Host (org.ovirt.engine.api.model.Host)2