use of com.xensource.xenapi.Types.BadServerResponse in project cosmic by MissionCriticalCloud.
the class CitrixResourceBase method getHostVmStateReport.
protected HashMap<String, HostVmStateReportEntry> getHostVmStateReport(final Connection conn) {
// TODO : new VM sync model does not require a cluster-scope report, we
// need to optimize
// the report accordingly
final HashMap<String, HostVmStateReportEntry> vmStates = new HashMap<>();
Map<VM, VM.Record> vm_map = null;
for (int i = 0; i < 2; i++) {
try {
// USE THIS TO GET ALL VMS FROM
vm_map = VM.getAllRecords(conn);
// A CLUSTER
break;
} catch (XmlRpcException | XenAPIException e) {
s_logger.warn("Unable to get vms", e);
}
try {
Thread.sleep(1000);
} catch (final InterruptedException e) {
s_logger.warn("Caught (previously ignored) interrupted exception", e);
}
}
if (vm_map == null) {
return vmStates;
}
for (final VM.Record record : vm_map.values()) {
if (record.isControlDomain || record.isASnapshot || record.isATemplate) {
// Skip DOM0
continue;
}
final VmPowerState ps = record.powerState;
final Host host = record.residentOn;
String host_uuid = null;
if (!isRefNull(host)) {
try {
host_uuid = host.getUuid(conn);
} catch (final BadServerResponse e) {
s_logger.error("Failed to get host uuid for host " + host.toWireString(), e);
} catch (final XenAPIException e) {
s_logger.error("Failed to get host uuid for host " + host.toWireString(), e);
} catch (final XmlRpcException e) {
s_logger.error("Failed to get host uuid for host " + host.toWireString(), e);
}
if (host_uuid.equalsIgnoreCase(_host.getUuid())) {
vmStates.put(record.nameLabel, new HostVmStateReportEntry(convertToPowerState(ps), host_uuid));
}
}
}
return vmStates;
}
use of com.xensource.xenapi.Types.BadServerResponse in project cosmic by MissionCriticalCloud.
the class CitrixResourceBase method attachConfigDriveToMigratedVm.
public boolean attachConfigDriveToMigratedVm(final Connection conn, final String vmName, final String ipAddr) {
try {
s_logger.debug("Attaching config drive iso device for the VM " + vmName + " In host " + ipAddr);
final Set<VM> vms = VM.getByNameLabel(conn, vmName);
final SR sr = getSRByNameLabel(conn, _configDriveSRName + ipAddr);
// Here you will find only two vdis with the <vmname>.iso.
// one is from source host and second from dest host
final Set<VDI> vdis = VDI.getByNameLabel(conn, vmName + ".iso");
if (vdis.isEmpty()) {
s_logger.debug("Could not find config drive ISO: " + vmName);
return false;
}
VDI configdriveVdi = null;
for (final VDI vdi : vdis) {
final SR vdiSr = vdi.getSR(conn);
if (vdiSr.getUuid(conn).equals(sr.getUuid(conn))) {
// get this vdi to attach to vbd
configdriveVdi = vdi;
s_logger.debug("VDI for the config drive ISO " + vdi);
} else {
// delete the vdi in source host so that the <vmname>.iso file is get removed
s_logger.debug("Removing the source host VDI for the config drive ISO " + vdi);
vdi.destroy(conn);
}
}
if (configdriveVdi == null) {
s_logger.debug("Config drive ISO VDI is not found ");
return false;
}
for (final VM vm : vms) {
// create vbd
final VBD.Record cfgDriveVbdr = new VBD.Record();
cfgDriveVbdr.VM = vm;
cfgDriveVbdr.empty = true;
cfgDriveVbdr.bootable = false;
cfgDriveVbdr.userdevice = "autodetect";
cfgDriveVbdr.mode = Types.VbdMode.RO;
cfgDriveVbdr.type = Types.VbdType.CD;
final VBD cfgDriveVBD = VBD.create(conn, cfgDriveVbdr);
s_logger.debug("Inserting vbd " + configdriveVdi);
cfgDriveVBD.insert(conn, configdriveVdi);
break;
}
return true;
} catch (final BadServerResponse e) {
s_logger.warn("Failed to attach config drive ISO to the VM " + vmName + " In host " + ipAddr + " due to a bad server response.", e);
return false;
} catch (final XenAPIException e) {
s_logger.warn("Failed to attach config drive ISO to the VM " + vmName + " In host " + ipAddr + " due to a xapi problem.", e);
return false;
} catch (final XmlRpcException e) {
s_logger.warn("Failed to attach config drive ISO to the VM " + vmName + " In host " + ipAddr + " due to a problem in a remote call.", e);
return false;
}
}
use of com.xensource.xenapi.Types.BadServerResponse in project cosmic by MissionCriticalCloud.
the class XenServerStorageProcessor method directDownloadHttpTemplate.
protected Answer directDownloadHttpTemplate(final CopyCommand cmd, final DecodedDataObject srcObj, final DecodedDataObject destObj) {
final Connection conn = hypervisorResource.getConnection();
SR poolsr = null;
VDI vdi = null;
boolean result = false;
try {
if (destObj.getPath() == null) {
// need to create volume at first
}
vdi = VDI.getByUuid(conn, destObj.getPath());
if (vdi == null) {
throw new CloudRuntimeException("can't find volume: " + destObj.getPath());
}
final String destStoreUuid = destObj.getStore().getUuid();
final Set<SR> srs = SR.getByNameLabel(conn, destStoreUuid);
if (srs.size() != 1) {
throw new CloudRuntimeException("storage uuid: " + destStoreUuid + " is not unique");
}
poolsr = srs.iterator().next();
final VDI.Record vdir = vdi.getRecord(conn);
final String vdiLocation = vdir.location;
String pbdLocation = null;
if (destObj.getStore().getScheme().equalsIgnoreCase(DataStoreProtocol.NFS.toString())) {
pbdLocation = "/run/sr-mount/" + poolsr.getUuid(conn);
} else {
final Set<PBD> pbds = poolsr.getPBDs(conn);
if (pbds.size() != 1) {
throw new CloudRuntimeException("Don't how to handle multiple pbds:" + pbds.size() + " for sr: " + poolsr.getUuid(conn));
}
final PBD pbd = pbds.iterator().next();
final Map<String, String> deviceCfg = pbd.getDeviceConfig(conn);
pbdLocation = deviceCfg.get("location");
}
if (pbdLocation == null) {
throw new CloudRuntimeException("Can't get pbd location");
}
final String vdiPath = pbdLocation + "/" + vdiLocation + ".vhd";
// download a url into vdipath
// downloadHttpToLocalFile(vdiPath, template.getPath());
hypervisorResource.callHostPlugin(conn, "storagePlugin", "downloadTemplateFromUrl", "destPath", vdiPath, "srcUrl", srcObj.getPath());
result = true;
// return new CopyCmdAnswer(cmd, vdi.getUuid(conn));
} catch (final BadServerResponse e) {
s_logger.debug("Failed to download template", e);
} catch (final XenAPIException e) {
s_logger.debug("Failed to download template", e);
} catch (final XmlRpcException e) {
s_logger.debug("Failed to download template", e);
} catch (final Exception e) {
s_logger.debug("Failed to download template", e);
} finally {
if (!result && vdi != null) {
try {
vdi.destroy(conn);
} catch (final BadServerResponse e) {
s_logger.debug("Failed to cleanup newly created vdi");
} catch (final XenAPIException e) {
s_logger.debug("Failed to cleanup newly created vdi");
} catch (final XmlRpcException e) {
s_logger.debug("Failed to cleanup newly created vdi");
}
}
}
return new Answer(cmd, false, "Failed to download template");
}
use of com.xensource.xenapi.Types.BadServerResponse in project cosmic by MissionCriticalCloud.
the class XenServerStorageProcessor method deleteSnapshot.
@Override
public Answer deleteSnapshot(final DeleteCommand cmd) {
final SnapshotObjectTO snapshot = (SnapshotObjectTO) cmd.getData();
final DataStoreTO store = snapshot.getDataStore();
if (store.getRole() == DataStoreRole.Primary) {
final Connection conn = hypervisorResource.getConnection();
final VDI snapshotVdi = getVDIbyUuid(conn, snapshot.getPath());
if (snapshotVdi == null) {
return new Answer(null);
}
String errMsg = null;
try {
deleteVDI(conn, snapshotVdi);
} catch (final BadServerResponse e) {
s_logger.debug("delete snapshot failed:" + e.toString());
errMsg = e.toString();
} catch (final XenAPIException e) {
s_logger.debug("delete snapshot failed:" + e.toString());
errMsg = e.toString();
} catch (final XmlRpcException e) {
s_logger.debug("delete snapshot failed:" + e.toString());
errMsg = e.toString();
}
return new Answer(cmd, false, errMsg);
}
return new Answer(cmd, false, "unsupported storage type");
}
use of com.xensource.xenapi.Types.BadServerResponse in project cosmic by MissionCriticalCloud.
the class XenServerConnectionPool method slaveLocalLoginWithPassword.
protected Session slaveLocalLoginWithPassword(final Connection conn, final String username, final Queue<String> password) throws BadServerResponse, XenAPIException, XmlRpcException {
Session s = null;
boolean logged_in = false;
Exception ex = null;
while (!logged_in) {
try {
s = Session.slaveLocalLoginWithPassword(conn, username, password.peek());
logged_in = true;
} catch (final BadServerResponse e) {
logged_in = false;
ex = e;
} catch (final XenAPIException e) {
logged_in = false;
ex = e;
} catch (final XmlRpcException e) {
logged_in = false;
ex = e;
}
if (logged_in && conn != null) {
break;
} else {
if (password.size() > 1) {
password.remove();
continue;
} else {
// the last password did not work leave it and flag error
if (ex instanceof BadServerResponse) {
throw (BadServerResponse) ex;
} else if (ex instanceof XmlRpcException) {
throw (XmlRpcException) ex;
} else if (ex instanceof Types.SessionAuthenticationFailed) {
throw (Types.SessionAuthenticationFailed) ex;
} else if (ex instanceof XenAPIException) {
throw (XenAPIException) ex;
}
break;
}
}
}
return s;
}
Aggregations