public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answer) {
try {
if (getDataStore().getRole() == DataStoreRole.Primary) {
if (answer instanceof CopyCmdAnswer) {
CopyCmdAnswer cpyAnswer = (CopyCmdAnswer)answer;
TemplateObjectTO newTemplate = (TemplateObjectTO)cpyAnswer.getNewData();
VMTemplateStoragePoolVO templatePoolRef = templatePoolDao.findByPoolTemplate(getDataStore().getId(), getId());
templatePoolRef.setDownloadPercent(100);
templatePoolRef.setDownloadState(Status.DOWNLOADED);
templatePoolRef.setLocalDownloadPath(newTemplate.getPath());
templatePoolRef.setInstallPath(newTemplate.getPath());
templatePoolDao.update(templatePoolRef.getId(), templatePoolRef);
}
} else if (getDataStore().getRole() == DataStoreRole.Image || getDataStore().getRole() == DataStoreRole.ImageCache) {
if (answer instanceof CopyCmdAnswer) {
CopyCmdAnswer cpyAnswer = (CopyCmdAnswer)answer;
TemplateObjectTO newTemplate = (TemplateObjectTO)cpyAnswer.getNewData();
TemplateDataStoreVO templateStoreRef = templateStoreDao.findByStoreTemplate(getDataStore().getId(), getId());
templateStoreRef.setInstallPath(newTemplate.getPath());
templateStoreRef.setDownloadPercent(100);
templateStoreRef.setDownloadState(Status.DOWNLOADED);
templateStoreRef.setSize(newTemplate.getSize());
if (newTemplate.getPhysicalSize() != null) {
templateStoreRef.setPhysicalSize(newTemplate.getPhysicalSize());
}
templateStoreDao.update(templateStoreRef.getId(), templateStoreRef);
if (getDataStore().getRole() == DataStoreRole.Image) {
VMTemplateVO templateVO = imageDao.findById(getId());
if (newTemplate.getFormat() != null) {
templateVO.setFormat(newTemplate.getFormat());
}
if (newTemplate.getName() != null) {
// For template created from snapshot, template name is determine by resource code.
templateVO.setUniqueName(newTemplate.getName());
}
templateVO.setSize(newTemplate.getSize());
imageDao.update(templateVO.getId(), templateVO);
}
}
}
objectInStoreMgr.update(this, event);