Examples of DownloadAnswer


Examples of com.cloud.agent.api.storage.DownloadAnswer

        Request req = new Request(1, 1, cmd, true);

        req.logD("Debug for Download");


        DownloadAnswer answer = new DownloadAnswer("jobId", 50, "errorString", Status.ABANDONED, "filesystempath", "installpath", 10000000, 20000000, "chksum");
        Response resp = new Response(req, answer);
        resp.logD("Debug for Download");

    }
View Full Code Here

Examples of com.cloud.agent.api.storage.DownloadAnswer

        Mockito.when(template.getName()).thenReturn(UUID.randomUUID().toString());
        Mockito.when(template.getObjectType()).thenReturn(DataObjectType.TEMPLATE);

        DownloadCommand cmd = new DownloadCommand(template, 100000L);
        cmd.setCacheStore(cacheStore);
        DownloadAnswer answer = (DownloadAnswer)resource.executeRequest(cmd);
        Assert.assertTrue(answer.getResult());

        Mockito.when(template.getPath()).thenReturn(answer.getInstallPath());
        Mockito.when(template.getDataStore()).thenReturn(swift);
        //download swift:
        Mockito.when(cacheStore.getRole()).thenReturn(DataStoreRole.ImageCache);
        TemplateObjectTO destTemplate = Mockito.mock(TemplateObjectTO.class);
        Mockito.when(destTemplate.getPath()).thenReturn("template/1/2");
View Full Code Here

Examples of com.cloud.agent.api.storage.DownloadAnswer

        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);
    }
View Full Code Here

Examples of com.cloud.agent.api.storage.DownloadAnswer

        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);
View Full Code Here

Examples of com.cloud.agent.api.storage.DownloadAnswer

    }

    @Override
    public Answer executeRequest(Command cmd) {
        if (cmd instanceof DownloadProgressCommand) {
            return new DownloadAnswer(null, 100, cmd, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED, "dummyFS", "/dummy");
        } else if (cmd instanceof DownloadCommand) {
            return new DownloadAnswer(null, 100, cmd, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED, "dummyFS", "/dummy");
        } else if (cmd instanceof GetStorageStatsCommand) {
            return execute((GetStorageStatsCommand)cmd);
        } else if (cmd instanceof CheckHealthCommand) {
            return new CheckHealthAnswer((CheckHealthCommand)cmd, true);
        } else if (cmd instanceof ReadyCommand) {
View Full Code Here

Examples of com.cloud.agent.api.storage.DownloadAnswer

        if (isTemplateUpdateable(templateId, store.getId())) {
            if (template != null && template.getUri() != null) {
                initiateTemplateDownload(template, callback);
            } else {
                s_logger.info("Template url is null, cannot download");
                DownloadAnswer ans = new DownloadAnswer("Template url is null", Status.UNKNOWN);
                callback.complete(ans);
            }
        } else {
            s_logger.info("Template download is already in progress or already downloaded");
            DownloadAnswer ans =
                new DownloadAnswer("Template download is already in progress or already downloaded", Status.UNKNOWN);
            callback.complete(ans);
        }
    }
View Full Code Here

Examples of com.cloud.agent.api.storage.DownloadAnswer

        if (s_logger.isTraceEnabled()) {
            getDownloadListener().log("handleEvent, event type=" + event + ", curr state=" + getName(), Level.TRACE);
        }
        switch (event) {
            case DOWNLOAD_ANSWER:
                DownloadAnswer answer = (DownloadAnswer)eventObj;
                return handleAnswer(answer);
            case ABANDON_DOWNLOAD:
                return handleAbort();
            case TIMEOUT_CHECK:
                Date now = new Date();
View Full Code Here

Examples of com.cloud.agent.api.storage.DownloadAnswer

        _currState = getState(Status.NOT_DOWNLOADED.toString());
        this._timer = timer;
        _timeoutTask = new TimeoutTask(this);
        this._timer.schedule(_timeoutTask, 3 * STATUS_POLL_INTERVAL);
        _callback = callback;
        DownloadAnswer answer = new DownloadAnswer("", Status.NOT_DOWNLOADED);
        callback(answer);
    }
View Full Code Here

Examples of com.cloud.agent.api.storage.DownloadAnswer

    @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())) {
                    return false;//TODO
                }
                transition(DownloadEvent.DOWNLOAD_ANSWER, answer);
                processed = true;
            }
View Full Code Here

Examples of com.cloud.agent.api.storage.DownloadAnswer

        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);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.