use of com.cloud.agent.api.storage.DownloadAnswer in project cloudstack by apache.
the class DownloadErrorState method onEntry.
@Override
public void onEntry(String prevState, DownloadEvent event, Object evtObj) {
super.onEntry(prevState, event, evtObj);
if (event == DownloadEvent.DISCONNECT) {
getDownloadListener().logDisconnect();
getDownloadListener().cancelStatusTask();
getDownloadListener().cancelTimeoutTask();
DownloadAnswer answer = new DownloadAnswer("Storage agent or storage VM disconnected", Status.DOWNLOAD_ERROR);
getDownloadListener().callback(answer);
getDownloadListener().log("Entering download error state because the storage host disconnected", Level.WARN);
} else if (event == DownloadEvent.TIMEOUT_CHECK) {
DownloadAnswer answer = new DownloadAnswer("Timeout waiting for response from storage host", Status.DOWNLOAD_ERROR);
getDownloadListener().callback(answer);
getDownloadListener().log("Entering download error state: timeout waiting for response from storage host", Level.WARN);
}
getDownloadListener().setDownloadInactive(Status.DOWNLOAD_ERROR);
}
use of com.cloud.agent.api.storage.DownloadAnswer in project cloudstack by apache.
the class DownloadListener method processAnswers.
@Override
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
boolean processed = false;
if (answers != null & answers.length > 0) {
if (answers[0] instanceof DownloadAnswer) {
final DownloadAnswer answer = (DownloadAnswer) answers[0];
if (getJobId() == null) {
setJobId(answer.getJobId());
} else if (!getJobId().equalsIgnoreCase(answer.getJobId())) {
//TODO
return false;
}
transition(DownloadEvent.DOWNLOAD_ANSWER, answer);
processed = true;
}
}
return processed;
}
use of com.cloud.agent.api.storage.DownloadAnswer in project cloudstack by apache.
the class MockStorageManagerImpl method DownloadProcess.
@Override
public DownloadAnswer DownloadProcess(DownloadProgressCommand cmd) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
String volumeId = cmd.getJobId();
MockVolumeVO volume = _mockVolumeDao.findById(Long.parseLong(volumeId));
if (volume == null) {
return new DownloadAnswer("Can't find the downloading volume", Status.ABANDONED);
}
long size = Math.min(volume.getSize() + DEFAULT_TEMPLATE_SIZE / 5, DEFAULT_TEMPLATE_SIZE);
volume.setSize(size);
double volumeSize = volume.getSize();
double pct = volumeSize / DEFAULT_TEMPLATE_SIZE;
if (pct >= 1.0) {
volume.setStatus(Status.DOWNLOADED);
_mockVolumeDao.update(volume.getId(), volume);
txn.commit();
return new DownloadAnswer(cmd.getJobId(), 100, cmd, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED, volume.getPath(), volume.getName());
} else {
_mockVolumeDao.update(volume.getId(), volume);
txn.commit();
return new DownloadAnswer(cmd.getJobId(), (int) (pct * 100.0), cmd, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS, volume.getPath(), volume.getName());
}
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error during download job " + cmd.getJobId(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
use of com.cloud.agent.api.storage.DownloadAnswer in project cloudstack by apache.
the class MockStorageManagerImpl method Download.
@Override
public DownloadAnswer Download(DownloadCommand cmd) {
MockSecStorageVO ssvo = null;
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
ssvo = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
if (ssvo == null) {
return new DownloadAnswer("can't find secondary storage", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error accessing secondary storage " + cmd.getSecUrl(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
MockVolumeVO volume = new MockVolumeVO();
volume.setPoolId(ssvo.getId());
volume.setName(cmd.getName());
volume.setPath(ssvo.getMountPoint() + cmd.getName());
volume.setSize(0);
volume.setType(MockVolumeType.TEMPLATE);
volume.setStatus(Status.DOWNLOAD_IN_PROGRESS);
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
volume = _mockVolumeDao.persist(volume);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when saving volume " + volume, ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new DownloadAnswer(String.valueOf(volume.getId()), 0, "Downloading", Status.DOWNLOAD_IN_PROGRESS, cmd.getName(), cmd.getName(), volume.getSize(), volume.getSize(), null);
}
use of com.cloud.agent.api.storage.DownloadAnswer in project cloudstack by apache.
the class VolumeObject method processEvent.
@Override
public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answer) {
try {
if (dataStore.getRole() == DataStoreRole.Primary) {
if (answer instanceof CopyCmdAnswer) {
CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
VolumeVO vol = volumeDao.findById(getId());
VolumeObjectTO newVol = (VolumeObjectTO) cpyAnswer.getNewData();
vol.setPath(newVol.getPath());
if (newVol.getSize() != null) {
vol.setSize(newVol.getSize());
}
if (newVol.getFormat() != null) {
vol.setFormat(newVol.getFormat());
}
vol.setPoolId(getDataStore().getId());
volumeDao.update(vol.getId(), vol);
} else if (answer instanceof CreateObjectAnswer) {
CreateObjectAnswer createAnswer = (CreateObjectAnswer) answer;
VolumeObjectTO newVol = (VolumeObjectTO) createAnswer.getData();
VolumeVO vol = volumeDao.findById(getId());
vol.setPath(newVol.getPath());
if (newVol.getSize() != null) {
vol.setSize(newVol.getSize());
}
vol.setPoolId(getDataStore().getId());
if (newVol.getFormat() != null) {
vol.setFormat(newVol.getFormat());
}
volumeDao.update(vol.getId(), vol);
}
} else {
// image store or imageCache store
if (answer instanceof DownloadAnswer) {
DownloadAnswer dwdAnswer = (DownloadAnswer) answer;
VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
volStore.setInstallPath(dwdAnswer.getInstallPath());
volStore.setChecksum(dwdAnswer.getCheckSum());
volumeStoreDao.update(volStore.getId(), volStore);
} else if (answer instanceof CopyCmdAnswer) {
CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
VolumeObjectTO newVol = (VolumeObjectTO) cpyAnswer.getNewData();
volStore.setInstallPath(newVol.getPath());
if (newVol.getSize() != null) {
volStore.setSize(newVol.getSize());
}
volumeStoreDao.update(volStore.getId(), volStore);
}
}
} catch (RuntimeException ex) {
if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
objectInStoreMgr.deleteIfNotReady(this);
}
throw ex;
}
this.processEvent(event);
}
Aggregations