Search in sources :

Example 86 with Answer

use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.

the class AncientDataMotionStrategy method cloneVolume.

protected Answer cloneVolume(final DataObject template, final DataObject volume) {
    final CopyCommand cmd = new CopyCommand(template.getTO(), volume.getTO(), 0, VirtualMachineManager.ExecuteInSequence.value());
    try {
        final EndPoint ep = selector.select(volume.getDataStore());
        Answer answer = null;
        if (ep == null) {
            final String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
            s_logger.error(errMsg);
            answer = new Answer(cmd, false, errMsg);
        } else {
            answer = ep.sendMessage(cmd);
        }
        return answer;
    } catch (final Exception e) {
        s_logger.debug("Failed to send to storage pool", e);
        throw new CloudRuntimeException("Failed to send to storage pool", e);
    }
}
Also used : MigrateVolumeAnswer(com.cloud.legacymodel.communication.answer.MigrateVolumeAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CopyCommand(com.cloud.legacymodel.communication.command.CopyCommand) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException)

Example 87 with Answer

use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.

the class DefaultHostListener method hostConnect.

@Override
public boolean hostConnect(final long hostId, final long poolId) throws StorageConflictException {
    final StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
    final ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool);
    final Answer answer = agentMgr.easySend(hostId, cmd);
    if (answer == null) {
        throw new CloudRuntimeException("Unable to get an answer to the modify storage pool command" + pool.getId());
    }
    if (!answer.getResult()) {
        final String msg = "Unable to attach storage pool" + poolId + " to the host" + hostId;
        alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, pool.getDataCenterId(), pool.getPodId(), msg, msg);
        throw new CloudRuntimeException("Unable establish connection from storage head to storage pool " + pool.getId() + " due to " + answer.getDetails() + pool.getId());
    }
    assert (answer instanceof ModifyStoragePoolAnswer) : "Well, now why won't you actually return the ModifyStoragePoolAnswer when it's ModifyStoragePoolCommand? Pool=" + pool.getId() + "Host=" + hostId;
    final ModifyStoragePoolAnswer mspAnswer = (ModifyStoragePoolAnswer) answer;
    if (mspAnswer.getLocalDatastoreName() != null && pool.isShared()) {
        final String datastoreName = mspAnswer.getLocalDatastoreName();
        final List<StoragePoolVO> localStoragePools = this.primaryStoreDao.listLocalStoragePoolByPath(pool.getDataCenterId(), datastoreName);
        for (final StoragePoolVO localStoragePool : localStoragePools) {
            if (datastoreName.equals(localStoragePool.getPath())) {
                s_logger.warn("Storage pool: " + pool.getId() + " has already been added as local storage: " + localStoragePool.getName());
                throw new StorageConflictException("Cannot add shared storage pool: " + pool.getId() + " because it has already been added as local storage:" + localStoragePool.getName());
            }
        }
    }
    StoragePoolHostVO poolHost = storagePoolHostDao.findByPoolHost(pool.getId(), hostId);
    if (poolHost == null) {
        poolHost = new StoragePoolHostVO(pool.getId(), hostId, mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
        storagePoolHostDao.persist(poolHost);
    } else {
        poolHost.setLocalPath(mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
    }
    final StoragePoolVO poolVO = this.primaryStoreDao.findById(poolId);
    poolVO.setUsedBytes(mspAnswer.getPoolInfo().getCapacityBytes() - mspAnswer.getPoolInfo().getAvailableBytes());
    poolVO.setCapacityBytes(mspAnswer.getPoolInfo().getCapacityBytes());
    primaryStoreDao.update(pool.getId(), poolVO);
    s_logger.info("Connection established between storage pool " + pool + " and host " + hostId);
    return true;
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) ModifyStoragePoolAnswer(com.cloud.legacymodel.communication.answer.ModifyStoragePoolAnswer) StoragePool(com.cloud.legacymodel.storage.StoragePool) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ModifyStoragePoolAnswer(com.cloud.legacymodel.communication.answer.ModifyStoragePoolAnswer) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) StorageConflictException(com.cloud.legacymodel.exceptions.StorageConflictException) ModifyStoragePoolCommand(com.cloud.legacymodel.communication.command.ModifyStoragePoolCommand)

Example 88 with Answer

use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.

the class CitrixPvlanSetupCommandWrapper method execute.

@Override
public Answer execute(final PvlanSetupCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    final String primaryPvlan = command.getPrimary();
    final String isolatedPvlan = command.getIsolated();
    final String op = command.getOp();
    final String dhcpName = command.getDhcpName();
    final String dhcpMac = command.getDhcpMac();
    final String dhcpIp = command.getDhcpIp();
    final String vmMac = command.getVmMac();
    final String networkTag = command.getNetworkTag();
    String nwNameLabel = null;
    try {
        final XsLocalNetwork nw = citrixResourceBase.getNativeNetworkForTraffic(conn, TrafficType.Guest, networkTag);
        if (nw == null) {
            s_logger.error("Network is not configured on the backend for pvlan " + primaryPvlan);
            throw new CloudRuntimeException("Network for the backend is not configured correctly for pvlan primary: " + primaryPvlan);
        }
        nwNameLabel = nw.getNetwork().getNameLabel(conn);
    } catch (final XenAPIException e) {
        s_logger.warn("Fail to get network", e);
        return new Answer(command, false, e.toString());
    } catch (final XmlRpcException e) {
        s_logger.warn("Fail to get network", e);
        return new Answer(command, false, e.toString());
    }
    String result = null;
    if (command.getType() == PvlanSetupCommand.Type.DHCP) {
        result = citrixResourceBase.callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-dhcp", "op", op, "nw-label", nwNameLabel, "primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "dhcp-name", dhcpName, "dhcp-ip", dhcpIp, "dhcp-mac", dhcpMac);
        if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) {
            s_logger.warn("Failed to program pvlan for dhcp server with mac " + dhcpMac);
            return new Answer(command, false, result);
        } else {
            s_logger.info("Programmed pvlan for dhcp server with mac " + dhcpMac);
        }
    } else if (command.getType() == PvlanSetupCommand.Type.VM) {
        result = citrixResourceBase.callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-vm", "op", op, "nw-label", nwNameLabel, "primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "vm-mac", vmMac);
        if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) {
            s_logger.warn("Failed to program pvlan for vm with mac " + vmMac);
            return new Answer(command, false, result);
        } else {
            s_logger.info("Programmed pvlan for vm with mac " + vmMac);
        }
    }
    return new Answer(command, true, result);
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 89 with Answer

use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.

the class CitrixRebootRouterCommandWrapper method execute.

@Override
public Answer execute(final RebootRouterCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    final RebootCommand rebootCommand = new RebootCommand(command.getVmName(), true);
    final Answer answer = wrapper.execute(rebootCommand, citrixResourceBase);
    if (answer.getResult()) {
        final String cnct = citrixResourceBase.connect(conn, command.getVmName(), command.getPrivateIpAddress());
        citrixResourceBase.networkUsage(conn, command.getPrivateIpAddress(), "create", null);
        if (cnct == null) {
            return answer;
        } else {
            return new Answer(command, false, cnct);
        }
    }
    return answer;
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) RebootCommand(com.cloud.legacymodel.communication.command.RebootCommand) Connection(com.xensource.xenapi.Connection)

Example 90 with Answer

use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.

the class CitrixUpdateHostPasswordCommandWrapper method execute.

@Override
public Answer execute(final UpdateHostPasswordCommand command, final CitrixResourceBase citrixResourceBase) {
    final String hostIp = command.getHostIp();
    final String username = command.getUsername();
    final String newPassword = command.getNewPassword();
    final XenServerUtilitiesHelper xenServerUtilitiesHelper = citrixResourceBase.getXenServerUtilitiesHelper();
    final String cmdLine = xenServerUtilitiesHelper.buildCommandLine(SCRIPT_CMD_PATH, VRScripts.UPDATE_HOST_PASSWD, username, newPassword);
    final Pair<Boolean, String> result;
    try {
        s_logger.debug("Executing command in Host: " + cmdLine);
        final String hostPassword = citrixResourceBase.getPwdFromQueue();
        result = xenServerUtilitiesHelper.executeSshWrapper(hostIp, 22, username, null, hostPassword, cmdLine.toString());
    } catch (final Exception e) {
        return new Answer(command, false, e.getMessage());
    }
    // Add new password to the queue.
    citrixResourceBase.replaceOldPasswdInQueue(newPassword);
    return new Answer(command, result.first(), result.second());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)342 Test (org.junit.Test)201 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)173 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)116 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)110 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)63 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)61 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)58 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)54 LibvirtException (org.libvirt.LibvirtException)53 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)53 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)48 Connection (com.xensource.xenapi.Connection)48 ArrayList (java.util.ArrayList)45 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)39 StoragePool (com.cloud.legacymodel.storage.StoragePool)38 Connect (org.libvirt.Connect)38 NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)29 CopyCmdAnswer (com.cloud.legacymodel.communication.answer.CopyCmdAnswer)29 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)27