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()]));
}
}
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());
}
}
}
}
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());
}
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());
}
}
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);
}
}
Aggregations