use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.
the class UserVmManagerImpl method setupVmForPvlan.
@Override
public boolean setupVmForPvlan(final boolean add, final Long hostId, final NicProfile nic) {
if (!nic.getBroadCastUri().getScheme().equals("pvlan")) {
return false;
}
String op = "add";
if (!add) {
op = "delete";
}
final Network network = _networkDao.findById(nic.getNetworkId());
final Host host = _hostDao.findById(hostId);
final String networkTag = _networkModel.getNetworkTag(host.getHypervisorType(), network);
final PvlanSetupCommand cmd = PvlanSetupCommand.createVmSetup(op, nic.getBroadCastUri(), networkTag, nic.getMacAddress());
final Answer answer;
try {
answer = _agentMgr.send(hostId, cmd);
} catch (final OperationTimedoutException e) {
s_logger.warn("Timed Out", e);
return false;
} catch (final AgentUnavailableException e) {
s_logger.warn("Agent Unavailable ", e);
return false;
}
boolean result = true;
if (answer == null || !answer.getResult()) {
result = false;
}
return result;
}
use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.
the class UserVmManagerImpl method getVirtualMachineStatistics.
@Override
public HashMap<Long, VmStatsEntry> getVirtualMachineStatistics(final long hostId, final String hostName, final List<Long> vmIds) throws CloudRuntimeException {
final HashMap<Long, VmStatsEntry> vmStatsById = new HashMap<>();
if (vmIds.isEmpty()) {
return vmStatsById;
}
final List<String> vmNames = new ArrayList<>();
for (final Long vmId : vmIds) {
final UserVmVO vm = _vmDao.findById(vmId);
vmNames.add(vm.getInstanceName());
}
final Answer answer = _agentMgr.easySend(hostId, new GetVmStatsCommand(vmNames, _hostDao.findById(hostId).getGuid(), hostName));
if (answer == null || !answer.getResult()) {
s_logger.warn("Unable to obtain VM statistics.");
return null;
} else {
final HashMap<String, VmStatsEntry> vmStatsByName = ((GetVmStatsAnswer) answer).getVmStatsMap();
if (vmStatsByName == null) {
s_logger.warn("Unable to obtain VM statistics.");
return null;
}
for (final Map.Entry<String, VmStatsEntry> entry : vmStatsByName.entrySet()) {
vmStatsById.put(vmIds.get(vmNames.indexOf(entry.getKey())), entry.getValue());
}
}
return vmStatsById;
}
use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.
the class UserVmManagerImpl method getVmDiskStatistics.
@Override
public HashMap<Long, List<VmDiskStatsEntry>> getVmDiskStatistics(final long hostId, final String hostName, final List<Long> vmIds) throws CloudRuntimeException {
final HashMap<Long, List<VmDiskStatsEntry>> vmDiskStatsById = new HashMap<>();
if (vmIds.isEmpty()) {
return vmDiskStatsById;
}
final List<String> vmNames = new ArrayList<>();
for (final Long vmId : vmIds) {
final UserVmVO vm = _vmDao.findById(vmId);
vmNames.add(vm.getInstanceName());
}
final Answer answer = _agentMgr.easySend(hostId, new GetVmDiskStatsCommand(vmNames, _hostDao.findById(hostId).getGuid(), hostName));
if (answer == null || !answer.getResult()) {
s_logger.warn("Unable to obtain VM disk statistics.");
return null;
} else {
final HashMap<String, List<VmDiskStatsEntry>> vmDiskStatsByName = ((GetVmDiskStatsAnswer) answer).getVmDiskStatsMap();
if (vmDiskStatsByName == null) {
s_logger.warn("Unable to obtain VM disk statistics.");
return null;
}
for (final Map.Entry<String, List<VmDiskStatsEntry>> entry : vmDiskStatsByName.entrySet()) {
vmDiskStatsById.put(vmIds.get(vmNames.indexOf(entry.getKey())), entry.getValue());
}
}
return vmDiskStatsById;
}
use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.
the class UserVmManagerImpl method handleManagedStorage.
private void handleManagedStorage(final UserVmVO vm, final VolumeVO root) {
if (Volume.State.Allocated.equals(root.getState())) {
return;
}
final StoragePoolVO storagePool = _storagePoolDao.findById(root.getPoolId());
if (storagePool != null && storagePool.isManaged()) {
final Long hostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
if (hostId != null) {
final VolumeInfo volumeInfo = volFactory.getVolume(root.getId());
final Host host = _hostDao.findById(hostId);
final Command cmd;
if (host.getHypervisorType() == HypervisorType.XenServer) {
final DiskTO disk = new DiskTO(volumeInfo.getTO(), root.getDeviceId(), root.getPath(), root.getVolumeType());
// it's OK in this case to send a detach command to the host for a root volume as this
// will simply lead to the SR that supports the root volume being removed
cmd = new DettachCommand(disk, vm.getInstanceName());
final DettachCommand detachCommand = (DettachCommand) cmd;
detachCommand.setManaged(true);
detachCommand.setStorageHost(storagePool.getHostAddress());
detachCommand.setStoragePort(storagePool.getPort());
detachCommand.set_iScsiName(root.get_iScsiName());
} else {
throw new CloudRuntimeException("This hypervisor type is not supported on managed storage for this command.");
}
final Commands cmds = new Commands(Command.OnError.Stop);
cmds.addCommand(cmd);
try {
_agentMgr.send(hostId, cmds);
} catch (final Exception ex) {
throw new CloudRuntimeException(ex.getMessage());
}
if (!cmds.isSuccessful()) {
for (final Answer answer : cmds.getAnswers()) {
if (!answer.getResult()) {
s_logger.warn("Failed to reset vm due to: " + answer.getDetails());
throw new CloudRuntimeException("Unable to reset " + vm + " due to " + answer.getDetails());
}
}
}
// root.getPoolId() should be null if the VM we are detaching the disk from has never been started before
final DataStore dataStore = root.getPoolId() != null ? _dataStoreMgr.getDataStore(root.getPoolId(), DataStoreRole.Primary) : null;
volumeMgr.revokeAccess(volFactory.getVolume(root.getId()), host, dataStore);
}
}
}
use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.
the class NotAValidCommand method testGetVncPortCommand.
@Test
public void testGetVncPortCommand() {
final GetVncPortCommand vncPortCommand = new GetVncPortCommand(1l, "Test");
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(vncPortCommand, this.citrixResourceBase);
verify(this.citrixResourceBase, times(1)).getConnection();
assertFalse(answer.getResult());
}
Aggregations