use of com.xensource.xenapi.Types.BadServerResponse in project cosmic by MissionCriticalCloud.
the class XenServerConnectionPool method loginWithPassword.
protected Session loginWithPassword(final Connection conn, final String username, final Queue<String> password, final String version) throws BadServerResponse, XenAPIException, XmlRpcException {
Session s = null;
boolean logged_in = false;
Exception ex = null;
while (!logged_in) {
try {
s = Session.loginWithPassword(conn, username, password.peek(), APIVersion.latest().toString());
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;
}
}
}
}
return s;
}
use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.
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 deleteVolume.
@Override
public Answer deleteVolume(final DeleteCommand cmd) {
final DataTO volume = cmd.getData();
final Connection conn = hypervisorResource.getConnection();
String errorMsg = null;
try {
final VDI vdi = VDI.getByUuid(conn, volume.getPath());
deleteVDI(conn, vdi);
return new Answer(null);
} catch (final BadServerResponse e) {
s_logger.debug("Failed to delete volume", e);
errorMsg = e.toString();
} catch (final XenAPIException e) {
s_logger.debug("Failed to delete volume", e);
errorMsg = e.toString();
} catch (final XmlRpcException e) {
s_logger.debug("Failed to delete volume", e);
errorMsg = e.toString();
}
return new Answer(null, false, errorMsg);
}
use of com.xensource.xenapi.Types.BadServerResponse in project cosmic by MissionCriticalCloud.
the class Xenserver625StorageProcessor method createTemplateFromSnapshot2.
public Answer createTemplateFromSnapshot2(final CopyCommand cmd) {
final Connection conn = hypervisorResource.getConnection();
final SnapshotObjectTO snapshotObjTO = (SnapshotObjectTO) cmd.getSrcTO();
final TemplateObjectTO templateObjTO = (TemplateObjectTO) cmd.getDestTO();
if (!(snapshotObjTO.getDataStore() instanceof PrimaryDataStoreTO) || !(templateObjTO.getDataStore() instanceof NfsTO)) {
return null;
}
NfsTO destStore = null;
URI destUri = null;
try {
destStore = (NfsTO) templateObjTO.getDataStore();
destUri = new URI(destStore.getUrl());
} catch (final Exception ex) {
s_logger.debug("Invalid URI", ex);
return new CopyCmdAnswer("Invalid URI: " + ex.toString());
}
SR srcSr = null;
SR destSr = null;
final String destDir = templateObjTO.getPath();
VDI destVdi = null;
boolean result = false;
try {
final Map<String, String> srcDetails = cmd.getOptions();
final String iScsiName = srcDetails.get(DiskTO.IQN);
final String storageHost = srcDetails.get(DiskTO.STORAGE_HOST);
final String chapInitiatorUsername = srcDetails.get(DiskTO.CHAP_INITIATOR_USERNAME);
final String chapInitiatorSecret = srcDetails.get(DiskTO.CHAP_INITIATOR_SECRET);
srcSr = hypervisorResource.getIscsiSR(conn, iScsiName, storageHost, iScsiName, chapInitiatorUsername, chapInitiatorSecret, true);
final String destNfsPath = destUri.getHost() + ":" + destUri.getPath();
final String localDir = "/var/cloud_mount/" + UUID.nameUUIDFromBytes(destNfsPath.getBytes());
mountNfs(conn, destNfsPath, localDir);
makeDirectory(conn, localDir + "/" + destDir);
destSr = createFileSR(conn, localDir + "/" + destDir);
// there should only be one VDI in this SR
final VDI srcVdi = srcSr.getVDIs(conn).iterator().next();
destVdi = srcVdi.copy(conn, destSr);
final String nameLabel = "cloud-" + UUID.randomUUID().toString();
destVdi.setNameLabel(conn, nameLabel);
// scan makes XenServer pick up VDI physicalSize
destSr.scan(conn);
final String templateUuid = destVdi.getUuid(conn);
final String templateFilename = templateUuid + ".vhd";
final long virtualSize = destVdi.getVirtualSize(conn);
final long physicalSize = destVdi.getPhysicalUtilisation(conn);
// create the template.properties file
String templatePath = destNfsPath + "/" + destDir;
templatePath = templatePath.replaceAll("//", "/");
result = hypervisorResource.postCreatePrivateTemplate(conn, templatePath, templateFilename, templateUuid, nameLabel, null, physicalSize, virtualSize, templateObjTO.getId());
if (!result) {
throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir");
}
final TemplateObjectTO newTemplate = new TemplateObjectTO();
newTemplate.setPath(destDir + "/" + templateFilename);
newTemplate.setFormat(Storage.ImageFormat.VHD);
newTemplate.setHypervisorType(HypervisorType.XenServer);
newTemplate.setSize(virtualSize);
newTemplate.setPhysicalSize(physicalSize);
newTemplate.setName(templateUuid);
result = true;
return new CopyCmdAnswer(newTemplate);
// } catch (Exception ex) {
// s_logger.error("Failed to create a template from a snapshot",
// ex);
//
// return new
// CopyCmdAnswer("Failed to create a template from a snapshot: " +
// ex.toString());
} catch (final BadServerResponse e) {
s_logger.error("Failed to create a template from a snapshot due to incomprehensible server response", e);
return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString());
} catch (final XenAPIException e) {
s_logger.error("Failed to create a template from a snapshot due to xenapi error", e);
return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString());
} catch (final XmlRpcException e) {
s_logger.error("Failed to create a template from a snapshot due to rpc error", e);
return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString());
} finally {
if (!result) {
if (destVdi != null) {
try {
destVdi.destroy(conn);
} catch (final Exception e) {
s_logger.debug("Cleaned up leftover VDI on destination storage due to failure: ", e);
}
}
}
if (srcSr != null) {
hypervisorResource.removeSR(conn, srcSr);
}
if (destSr != null) {
hypervisorResource.removeSR(conn, destSr);
}
}
}
use of com.xensource.xenapi.Types.BadServerResponse in project cosmic by MissionCriticalCloud.
the class XenServerConnectionPool method join.
protected void join(final Connection conn, final String masterIp, final String username, final Queue<String> password) throws BadServerResponse, XenAPIException, XmlRpcException, Types.JoiningHostCannotContainSharedSrs {
boolean logged_in = false;
Exception ex = null;
while (!logged_in) {
try {
Pool.join(conn, masterIp, 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;
}
}
}
}
Aggregations