Search in sources :

Example 76 with Answer

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

the class VirtualRoutingResource method applyConfig.

private Answer applyConfig(final NetworkElementCommand cmd, final List<ConfigItem> cfg) {
    if (cfg.isEmpty()) {
        return new Answer(cmd, true, "Nothing to do");
    }
    final List<ExecutionResult> results = new ArrayList<>();
    final List<String> details = new ArrayList<>();
    boolean finalResult = false;
    for (final ConfigItem configItem : cfg) {
        final long startTimestamp = System.currentTimeMillis();
        ExecutionResult result = applyConfigToVR(cmd.getRouterAccessIp(), configItem);
        if (s_logger.isDebugEnabled()) {
            final long elapsed = System.currentTimeMillis() - startTimestamp;
            s_logger.debug("Processing " + configItem + " took " + elapsed + "ms");
        }
        if (result == null) {
            result = new ExecutionResult(false, "null execution result");
        }
        results.add(result);
        details.add(configItem.getInfo() + (result.isSuccess() ? " - success: " : " - failed: ") + result.getDetails());
        finalResult = result.isSuccess();
    }
    // Not sure why this matters, but log it anyway
    if (cmd.getAnswersCount() != results.size()) {
        s_logger.warn("Expected " + cmd.getAnswersCount() + " answers while executing " + cmd.getClass().getSimpleName() + " but received " + results.size());
    }
    if (results.size() == 1) {
        return new Answer(cmd, finalResult, results.get(0).getDetails());
    } else {
        return new GroupAnswer(cmd, finalResult, results.size(), details.toArray(new String[details.size()]));
    }
}
Also used : GroupAnswer(com.cloud.legacymodel.communication.answer.GroupAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.legacymodel.communication.answer.CheckS2SVpnConnectionsAnswer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) GetDomRVersionAnswer(com.cloud.legacymodel.communication.answer.GetDomRVersionAnswer) ArrayList(java.util.ArrayList) ExecutionResult(com.cloud.legacymodel.ExecutionResult) GroupAnswer(com.cloud.legacymodel.communication.answer.GroupAnswer)

Example 77 with Answer

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

the class VirtualRoutingResource method executeRequest.

public Answer executeRequest(final NetworkElementCommand cmd) {
    boolean aggregated = false;
    final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    final Lock lock;
    if (this._vrLockMap.containsKey(routerName)) {
        lock = this._vrLockMap.get(routerName);
    } else {
        lock = new ReentrantLock();
        this._vrLockMap.put(routerName, lock);
    }
    lock.lock();
    try {
        final ExecutionResult rc = this._vrDeployer.prepareCommand(cmd);
        if (!rc.isSuccess()) {
            s_logger.error("Failed to prepare VR command due to " + rc.getDetails());
            return new Answer(cmd, false, rc.getDetails());
        }
        assert cmd.getRouterAccessIp() != null : "Why there is no access IP for VR?";
        if (cmd.isQuery()) {
            return executeQueryCommand(cmd);
        }
        if (cmd instanceof AggregationControlCommand) {
            return execute((AggregationControlCommand) cmd);
        }
        if (this._vrAggregateCommandsSet.containsKey(routerName)) {
            this._vrAggregateCommandsSet.get(routerName).add(cmd);
            aggregated = true;
            // TODO: Deal with group answer as well
            return new Answer(cmd);
        }
        final List<ConfigItem> cfg = generateCommandCfg(cmd);
        if (cfg == null) {
            return Answer.createUnsupportedCommandAnswer(cmd);
        }
        return applyConfig(cmd, cfg);
    } catch (final IllegalArgumentException e) {
        return new Answer(cmd, false, e.getMessage());
    } finally {
        lock.unlock();
        if (!aggregated) {
            final ExecutionResult rc = this._vrDeployer.cleanupCommand(cmd);
            if (!rc.isSuccess()) {
                s_logger.error("Failed to cleanup VR command due to " + rc.getDetails());
            }
        }
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) GroupAnswer(com.cloud.legacymodel.communication.answer.GroupAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.legacymodel.communication.answer.CheckS2SVpnConnectionsAnswer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) GetDomRVersionAnswer(com.cloud.legacymodel.communication.answer.GetDomRVersionAnswer) AggregationControlCommand(com.cloud.legacymodel.communication.command.AggregationControlCommand) ExecutionResult(com.cloud.legacymodel.ExecutionResult) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Example 78 with Answer

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

the class ServerResourceBase method createErrorAnswer.

protected Answer createErrorAnswer(final Command cmd, final String msg, final Throwable th) {
    final StringWriter writer = new StringWriter();
    if (msg != null) {
        writer.append(msg);
    }
    writer.append("===>Stack<===");
    th.printStackTrace(new PrintWriter(writer));
    return new Answer(cmd, false, writer.toString());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 79 with Answer

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

the class DefaultVMSnapshotStrategy method deleteVMSnapshot.

@Override
public boolean deleteVMSnapshot(final VMSnapshot vmSnapshot) {
    final UserVmVO userVm = userVmDao.findById(vmSnapshot.getVmId());
    final VMSnapshotVO vmSnapshotVO = (VMSnapshotVO) vmSnapshot;
    try {
        vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.ExpungeRequested);
    } catch (final NoTransitionException e) {
        s_logger.debug("Failed to change vm snapshot state with event ExpungeRequested");
        throw new CloudRuntimeException("Failed to change vm snapshot state with event ExpungeRequested: " + e.getMessage());
    }
    try {
        final Long hostId = vmSnapshotHelper.pickRunningHost(vmSnapshot.getVmId());
        final List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(vmSnapshot.getVmId());
        final String vmInstanceName = userVm.getInstanceName();
        final VMSnapshotTO parent = vmSnapshotHelper.getSnapshotWithParents(vmSnapshotVO).getParent();
        final VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(vmSnapshot.getId(), vmSnapshot.getName(), vmSnapshot.getType(), vmSnapshot.getCreated().getTime(), vmSnapshot.getDescription(), vmSnapshot.getCurrent(), parent, true);
        final GuestOSVO guestOS = guestOSDao.findById(userVm.getGuestOSId());
        final DeleteVMSnapshotCommand deleteSnapshotCommand = new DeleteVMSnapshotCommand(vmInstanceName, vmSnapshotTO, volumeTOs, guestOS.getDisplayName());
        final Answer answer = agentMgr.send(hostId, deleteSnapshotCommand);
        if (answer != null && answer.getResult()) {
            processAnswer(vmSnapshotVO, userVm, answer, hostId);
            return true;
        } else {
            final String errMsg = (answer == null) ? null : answer.getDetails();
            s_logger.error("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + errMsg);
            throw new CloudRuntimeException("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + errMsg);
        }
    } catch (final OperationTimedoutException | AgentUnavailableException e) {
        throw new CloudRuntimeException("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + e.getMessage());
    }
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) GuestOSVO(com.cloud.storage.GuestOSVO) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) DeleteVMSnapshotAnswer(com.cloud.legacymodel.communication.answer.DeleteVMSnapshotAnswer) RevertToVMSnapshotAnswer(com.cloud.legacymodel.communication.answer.RevertToVMSnapshotAnswer) CreateVMSnapshotAnswer(com.cloud.legacymodel.communication.answer.CreateVMSnapshotAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) VMSnapshotTO(com.cloud.legacymodel.to.VMSnapshotTO) DeleteVMSnapshotCommand(com.cloud.legacymodel.communication.command.DeleteVMSnapshotCommand) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO)

Example 80 with Answer

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

the class VolumeServiceImpl method resizeVolumeOnHypervisor.

@Override
public void resizeVolumeOnHypervisor(final long volumeId, final long newSize, final long destHostId, final String instanceName) {
    final String errMsg = "Resize command failed";
    try {
        Answer answer = null;
        final Host destHost = _hostDao.findById(destHostId);
        final EndPoint ep = RemoteHostEndPoint.getHypervisorHostEndPoint(destHost);
        if (ep != null) {
            final VolumeVO volume = volDao.findById(volumeId);
            final PrimaryDataStore primaryDataStore = this.dataStoreMgr.getPrimaryDataStore(volume.getPoolId());
            final ResizeVolumeCommand resizeCmd = new ResizeVolumeCommand(volume.getPath(), new StorageFilerTO(primaryDataStore), volume.getSize(), newSize, true, instanceName);
            answer = ep.sendMessage(resizeCmd);
        } else {
            throw new CloudRuntimeException("Could not find a remote endpoint to send command to. Check if host or SSVM is down.");
        }
        if (answer == null || !answer.getResult()) {
            throw new CloudRuntimeException(answer != null ? answer.getDetails() : errMsg);
        }
    } catch (final Exception e) {
        throw new CloudRuntimeException(errMsg, e);
    }
}
Also used : ListVolumeAnswer(com.cloud.legacymodel.communication.answer.ListVolumeAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ResizeVolumeCommand(com.cloud.legacymodel.communication.command.ResizeVolumeCommand) Host(com.cloud.legacymodel.dc.Host) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore)

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