Package com.cloud.agent.api.to

Examples of com.cloud.agent.api.to.S3TO


                addS3Cmd.getHttpsFlag(), addS3Cmd.getConnectionTimeout(),
                addS3Cmd.getMaxErrorRetry(), addS3Cmd.getSocketTimeout(), now());

        this.validateFields(s3VO);

        final S3TO s3 = s3VO.toS3TO();
        this.verifyConnection(s3);
        this.verifyBuckets(s3);

        return this.s3Dao.persist(s3VO);
View Full Code Here


    }

    @Override
    public void deleteTemplate(final Long templateId, final Long accountId) {

        final S3TO s3 = getS3TO();

        if (s3 == null) {
            final String errorMessage = "Delete Template Failed: No S3 configuration defined.";
            LOGGER.error(errorMessage);
            throw new CloudRuntimeException(errorMessage);
        }

        final VMTemplateS3VO vmTemplateS3VO = vmTemplateS3Dao
                .findOneByS3Template(s3.getId(), templateId);
        if (vmTemplateS3VO == null) {
            final String errorMessage = format(
                    "Delete Template Failed: Unable to find Template %1$s in S3.",
                    templateId);
            LOGGER.error(errorMessage);
View Full Code Here

                    templateId);
            LOGGER.error(errorMessage);
            return errorMessage;
        }

        final S3TO s3 = getS3TO(templateS3VO.getS3Id());
        if (s3 == null) {
            final String errorMessage = format(
                    "Failed to download template id %1$s from S3 because S3 id %2$s does not exist.",
                    templateId, templateS3VO);
            LOGGER.error(errorMessage);
View Full Code Here

            }
            return;

        }

        final S3TO s3 = getS3TO();

        if (s3 == null) {
            LOGGER.warn(format(
                    "Unable to propagate template id %1$s across all zones because S3 is enabled, but not configured.",
                    templateId));
View Full Code Here

    }

    @Override
    public Long chooseZoneForTemplateExtract(VMTemplateVO template) {

        final S3TO s3 = getS3TO();

        if (s3 == null) {
            return null;
        }
View Full Code Here

        if (!isS3Enabled()) {
            return;
        }

        final S3TO s3 = getS3TO();
        if (s3 == null) {
            LOGGER.warn("S3 Template Sync Failed: Attempt to sync templates with S3, but no S3 instance defined.");
            return;
        }

        final HostVO secondaryHost = this.hostDao.findById(templateHostRef
                .getHostId());
        if (secondaryHost == null) {
            throw new CloudRuntimeException(format(
                    "Unable to find secondary storage host id %1$s.",
                    templateHostRef.getHostId()));
        }

        final Long dataCenterId = secondaryHost.getDataCenterId();
        final Long accountId = template.getAccountId();

        try {

            executeWithNoWaitLock(determineLockId(accountId, templateId),
                    new Callable<Void>() {

                @Override
                public Void call() throws Exception {

                    final UploadTemplateToS3FromSecondaryStorageCommand cmd = new UploadTemplateToS3FromSecondaryStorageCommand(
                            s3, secondaryHost.getStorageUrl(),
                            dataCenterId, accountId, templateId);

                    final Answer answer = agentManager.sendToSSVM(
                            dataCenterId, cmd);
                    if (answer == null || !answer.getResult()) {

                        final String reason = answer != null ? answer
                                .getDetails()
                                : "S3 template sync failed due to an unspecified error.";
                                throw new CloudRuntimeException(
                                        format("Failed to upload template id %1$s to S3 from secondary storage due to %2$s.",
                                                templateId, reason));

                    }

                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format(
                                "Creating VMTemplateS3VO instance using template id %1s.",
                                templateId));
                    }

                    final VMTemplateS3VO vmTemplateS3VO = new VMTemplateS3VO(
                            s3.getId(), templateId, now(),
                            templateHostRef.getSize(), templateHostRef
                            .getPhysicalSize());

                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Persisting %1$s",
View Full Code Here

    @Override
    public DataStoreTO getStoreTO(DataStore store) {
        ImageStoreImpl imgStore = (ImageStoreImpl) store;
        Map<String, String> details = _imageStoreDetailsDao.getDetails(imgStore.getId());
        return new S3TO(imgStore.getId(), imgStore.getUuid(), details.get(ApiConstants.S3_ACCESS_KEY),
                details.get(ApiConstants.S3_SECRET_KEY), details.get(ApiConstants.S3_END_POINT),
                details.get(ApiConstants.S3_BUCKET_NAME), details.get(ApiConstants.S3_HTTPS_FLAG) == null ? false
                        : Boolean.parseBoolean(details.get(ApiConstants.S3_HTTPS_FLAG)),
                details.get(ApiConstants.S3_CONNECTION_TIMEOUT) == null ? null : Integer.valueOf(details
                        .get(ApiConstants.S3_CONNECTION_TIMEOUT)),
View Full Code Here

    @Override
    public String createEntityExtractUrl(DataStore store, String installPath, ImageFormat format, DataObject dataObject) {
        // for S3, no need to do anything, just return template url for
        // extract template. but we need to set object acl as public_read to
        // make the url accessible
        S3TO s3 = (S3TO)getStoreTO(store);
        String key = installPath;

        s_logger.info("Generating pre-signed s3 entity extraction URL.");
        Date expiration = new Date();
        long milliSeconds = expiration.getTime();
       
        // get extract url expiration interval set in global configuration (in seconds)
        String urlExpirationInterval = _configDao.getValue(Config.ExtractURLExpirationInterval.toString());
        int expirationInterval = NumbersUtil.parseInt(urlExpirationInterval, 14400);
        milliSeconds += 1000 * expirationInterval; // expired after configured interval (in milliseconds)
        expiration.setTime(milliSeconds);

        URL s3url = S3Utils.generatePresignedUrl(s3, s3.getBucketName(), key, expiration);

        s_logger.info("Pre-Signed URL = " + s3url.toString());

        return s3url.toString();
    }
View Full Code Here

        if (destDataStore instanceof NfsTO
                && destDataStore.getRole() == DataStoreRole.ImageCache) {
            NfsTO destImageStore = (NfsTO) destDataStore;
            if (srcDataStore instanceof S3TO) {
                S3TO s3 = (S3TO) srcDataStore;
                return copyFromS3ToNfs(cmd, srcData, s3, destData, destImageStore);
            } else if (srcDataStore instanceof SwiftTO) {
                return copyFromSwiftToNfs(cmd, srcData, (SwiftTO)srcDataStore, destData, destImageStore);
            }
        }
View Full Code Here

        final DataTO destData = cmd.getDestTO();
        DataStoreTO srcDataStore = srcData.getDataStore();
        NfsTO srcStore = (NfsTO) srcDataStore;
        DataStoreTO destDataStore = destData.getDataStore();

        final S3TO s3 = (S3TO) destDataStore;

        try {
            final String templatePath = determineStorageTemplatePath(srcStore.getUrl(), srcData.getPath());

            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Found " + srcData.getObjectType() + " from directory " + templatePath
                        + " to upload to S3.");
            }

            final String bucket = s3.getBucketName();
            File srcFile = _storage.getFile(templatePath);
            // guard the case where templatePath does not have file extension, since we are not completely sure
            // about hypervisor, so we check each extension
            if (!srcFile.exists()) {
                srcFile = _storage.getFile(templatePath + ".qcow2");
                if (!srcFile.exists()) {
                    srcFile = _storage.getFile(templatePath + ".vhd");
                    if (!srcFile.exists()) {
                        srcFile = _storage.getFile(templatePath + ".ova");
                        if (!srcFile.exists()) {
                            return new CopyCmdAnswer("Can't find src file:" + templatePath);
                        }
                    }
                }
            }

            long srcSize = srcFile.length();
            ImageFormat format = getTemplateFormat(srcFile.getName());
            String key = destData.getPath() + S3Utils.SEPARATOR + srcFile.getName();
            if (!s3.getSingleUpload(srcSize)){
                mputFile(s3, srcFile, bucket, key);
            } else{
                putFile(s3, srcFile, bucket, key);
            }
View Full Code Here

TOP

Related Classes of com.cloud.agent.api.to.S3TO

Copyright © 2018 www.massapicom. 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.