@Override public ExtractResponse createExtractResponse(Long id, Long zoneId, Long accountId, String mode, String url) { ExtractResponse response = new ExtractResponse(); response.setObjectName("template"); VMTemplateVO template = ApiDBUtils.findTemplateById(id); response.setId(template.getUuid()); response.setName(template.getName()); if (zoneId != null) { DataCenter zone = ApiDBUtils.findZoneById(zoneId); response.setZoneId(zone.getUuid()); response.setZoneName(zone.getName()); } response.setMode(mode); response.setUrl(url); response.setState(Upload.Status.DOWNLOAD_URL_CREATED.toString()); Account account = ApiDBUtils.findAccountById(accountId); response.setAccountId(account.getUuid()); return response; }
@Override public void execute() { try { CallContext.current().setEventDetails(getEventDescription()); String uploadUrl = _templateService.extract(this); if (uploadUrl != null) { ExtractResponse response = _responseGenerator.createExtractResponse(id, zoneId, getEntityOwnerId(), mode, uploadUrl); response.setResponseName(getCommandName()); response.setObjectName("iso"); this.setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract ISO"); } } catch (InternalErrorException ex) { s_logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } }
public synchronized void updateDatabase(UploadAnswer answer) { if (answer.getErrorString().startsWith("553")) { answer.setErrorString(answer.getErrorString().concat("Please check if the file name already exists.")); } resultObj.setResultString(answer.getErrorString()); resultObj.setState(answer.getUploadStatus().toString()); resultObj.setUploadPercent(answer.getUploadPct()); if (answer.getUploadStatus() == Status.UPLOAD_IN_PROGRESS) { asyncMgr.updateAsyncJobAttachment(asyncJobId, type.toString(), 1L); asyncMgr.updateAsyncJobStatus(asyncJobId, JobInfo.Status.IN_PROGRESS.ordinal(), ApiSerializerHelper.toSerializedString(resultObj)); } else if (answer.getUploadStatus() == Status.UPLOADED) { resultObj.setResultString("Success"); asyncMgr.completeAsyncJob(asyncJobId, JobInfo.Status.SUCCEEDED, 1, ApiSerializerHelper.toSerializedString(resultObj)); } else { asyncMgr.completeAsyncJob(asyncJobId, JobInfo.Status.FAILED, 2, ApiSerializerHelper.toSerializedString(resultObj)); } UploadVO updateBuilder = uploadDao.createForUpdate(); updateBuilder.setUploadPercent(answer.getUploadPct()); updateBuilder.setUploadState(answer.getUploadStatus()); updateBuilder.setLastUpdated(new Date()); updateBuilder.setErrorString(answer.getErrorString()); updateBuilder.setJobId(answer.getJobId()); uploadDao.update(getUploadId(), updateBuilder); }
public UploadListener(DataStore host, Timer timerInput, UploadDao uploadDao, UploadVO uploadObj, UploadMonitorImpl uploadMonitor, UploadCommand cmd, Long accountId, String typeName, Type type, long eventId, long asyncJobId, AsyncJobManager asyncMgr) { sserver = host; this.uploadDao = uploadDao; this.uploadMonitor = uploadMonitor; this.cmd = cmd; uploadId = uploadObj.getId(); this.accountId = accountId; this.typeName = typeName; this.type = type; initStateMachine(); currState = getState(Status.NOT_UPLOADED.toString()); timer = timerInput; timeoutTask = new TimeoutTask(this); timer.schedule(timeoutTask, 3 * STATUS_POLL_INTERVAL); this.eventId = eventId; this.asyncJobId = asyncJobId; this.asyncMgr = asyncMgr; String extractId = null; if (type == Type.VOLUME) { extractId = ApiDBUtils.findVolumeById(uploadObj.getTypeId()).getUuid(); } else { extractId = ApiDBUtils.findTemplateById(uploadObj.getTypeId()).getUuid(); } resultObj = new ExtractResponse(extractId, typeName, ApiDBUtils.findAccountById(accountId).getUuid(), Status.NOT_UPLOADED.toString(), ApiDBUtils.findUploadById(uploadId) .getUuid()); resultObj.setResponseName(responseNameMap.get(type.toString())); updateDatabase(Status.NOT_UPLOADED, cmd.getUrl(), ""); }
public void updateDatabase(Status state, String uploadErrorString) { resultObj.setResultString(uploadErrorString); resultObj.setState(state.toString()); asyncMgr.updateAsyncJobAttachment(asyncJobId, type.toString(), 1L); asyncMgr.updateAsyncJobStatus(asyncJobId, JobInfo.Status.IN_PROGRESS.ordinal(), ApiSerializerHelper.toSerializedString(resultObj)); UploadVO vo = uploadDao.createForUpdate(); vo.setUploadState(state); vo.setLastUpdated(new Date()); vo.setErrorString(uploadErrorString); uploadDao.update(getUploadId(), vo); }
@Override public void execute() { try { CallContext.current().setEventDetails(getEventDescription()); String uploadUrl = _templateService.extract(this); if (uploadUrl != null) { ExtractResponse response = _responseGenerator.createExtractResponse(id, zoneId, getEntityOwnerId(), mode, uploadUrl); response.setResponseName(getCommandName()); this.setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract template"); } } catch (InternalErrorException ex) { s_logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } }
public void updateDatabase(Status state, String uploadUrl, String uploadErrorString) { resultObj.setResultString(uploadErrorString); resultObj.setState(state.toString()); asyncMgr.updateAsyncJobAttachment(asyncJobId, type.toString(), 1L); asyncMgr.updateAsyncJobStatus(asyncJobId, JobInfo.Status.IN_PROGRESS.ordinal(), ApiSerializerHelper.toSerializedString(resultObj)); UploadVO vo = uploadDao.createForUpdate(); vo.setUploadState(state); vo.setLastUpdated(new Date()); vo.setUploadUrl(uploadUrl); vo.setJobId(null); vo.setUploadPercent(0); vo.setErrorString(uploadErrorString); uploadDao.update(getUploadId(), vo); }
@Override public ExtractResponse createExtractResponse(Long uploadId, Long id, Long zoneId, Long accountId, String mode, String url) { ExtractResponse response = new ExtractResponse(); response.setObjectName("template"); VMTemplateVO template = ApiDBUtils.findTemplateById(id); response.setId(template.getUuid()); response.setName(template.getName()); if (zoneId != null) { DataCenter zone = ApiDBUtils.findZoneById(zoneId); response.setZoneId(zone.getUuid()); response.setZoneName(zone.getName()); } response.setMode(mode); if (uploadId == null) { // region-wide image store response.setUrl(url); response.setState(Upload.Status.DOWNLOAD_URL_CREATED.toString()); } else { UploadVO uploadInfo = ApiDBUtils.findUploadById(uploadId); response.setUploadId(uploadInfo.getUuid()); response.setState(uploadInfo.getUploadState().toString()); response.setUrl(uploadInfo.getUploadUrl()); } Account account = ApiDBUtils.findAccountById(accountId); response.setAccountId(account.getUuid()); return response; }
@Override public void execute() { CallContext.current().setEventDetails("Volume Id: " + this._uuidMgr.getUuid(Volume.class, getId())); String uploadUrl = _volumeService.extractVolume(this); if (uploadUrl != null) { ExtractResponse response = new ExtractResponse(); response.setResponseName(getCommandName()); response.setObjectName("volume"); Volume vol = _entityMgr.findById(Volume.class, id); response.setId(vol.getUuid()); response.setName(vol.getName()); DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId); response.setZoneId(zone.getUuid()); response.setZoneName(zone.getName()); response.setMode(mode); response.setState(Upload.Status.DOWNLOAD_URL_CREATED.toString()); Account account = _entityMgr.findById(Account.class, getEntityOwnerId()); response.setAccountId(account.getUuid()); response.setUrl(uploadUrl); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract volume"); } } }