Search in sources :

Example 16 with DownloadAnswer

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);
}
Also used : DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer)

Example 17 with DownloadAnswer

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;
}
Also used : DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer)

Example 18 with DownloadAnswer

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();
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MockVolumeVO(com.cloud.simulator.MockVolumeVO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 19 with DownloadAnswer

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);
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) MockVolumeVO(com.cloud.simulator.MockVolumeVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 20 with DownloadAnswer

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);
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeVO(com.cloud.storage.VolumeVO) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Aggregations

DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)21 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)5 PrimaryStorageDownloadAnswer (com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer)4 NfsTO (com.cloud.agent.api.to.NfsTO)4 MockVolumeVO (com.cloud.simulator.MockVolumeVO)4 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)4 DownloadCommand (org.apache.cloudstack.storage.command.DownloadCommand)4 VolumeVO (com.cloud.storage.VolumeVO)3 Date (java.util.Date)3 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)3 VolumeDataStoreVO (org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)3 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)2 SwiftTO (com.cloud.agent.api.to.SwiftTO)2 MockSecStorageVO (com.cloud.simulator.MockSecStorageVO)2 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)2 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)2 URISyntaxException (java.net.URISyntaxException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 ConfigurationException (javax.naming.ConfigurationException)2