Package org.apache.cloudstack.storage.command

Examples of org.apache.cloudstack.storage.command.CopyCmdAnswer


            downloadDirectory.mkdirs();
            File destFile = SwiftUtil.getObject(swiftTO, downloadDirectory, srcData.getPath());
            return postProcessing(destFile,downloadPath,destPath,srcData,destData);
        } catch (Exception e) {
            s_logger.debug("Failed to copy swift to nfs", e);
            return new CopyCmdAnswer(e.toString());
        }
    }
View Full Code Here


            downloadDirectory.mkdirs();

            if (!downloadDirectory.exists()) {
                final String errMsg = "Unable to create directory " + downloadPath + " to copy from S3 to cache.";
                s_logger.error(errMsg);
                return new CopyCmdAnswer(errMsg);
            } else {
                s_logger.debug("Directory " + downloadPath + " already exists");
            }

            File destFile = S3Utils.getFile(s3, s3.getBucketName(), srcData.getPath(), downloadDirectory,
                    new FileNamingStrategy() {
                @Override
                public String determineFileName(final String key) {
                    return substringAfterLast(key, S3Utils.SEPARATOR);
                }
            });

            if (destFile == null) {
                return new CopyCmdAnswer("Can't find template");
            }

            return postProcessing(destFile,downloadPath,destPath,srcData,destData);
        } catch (Exception e) {

            final String errMsg = format("Failed to download" + "due to $2%s", e.getMessage());
            s_logger.error(errMsg, e);
            return new CopyCmdAnswer(errMsg);
        }
    }
View Full Code Here

            command.add("-n", templateName);
            command.add("-t", destPath);
            String result = command.execute();

            if (result != null && !result.equalsIgnoreCase("")) {
                return new CopyCmdAnswer(result);
            }

            Map<String, Object> params = new HashMap<String, Object>();
            params.put(StorageLayer.InstanceConfigKey, _storage);
            Processor processor = new VhdProcessor();

            processor.configure("Vhd Processor", params);
            FormatInfo info = processor.process(destPath, null, templateUuid);

            TemplateLocation loc = new TemplateLocation(_storage, destPath);
            loc.create(1, true, templateUuid);
            loc.addFormat(info);
            loc.save();
            TemplateProp prop = loc.getTemplateInfo();
            TemplateObjectTO newTemplate = new TemplateObjectTO();
            newTemplate.setPath(destData.getPath() + File.separator + templateName);
            newTemplate.setFormat(ImageFormat.VHD);
            newTemplate.setSize(prop.getSize());
            newTemplate.setPhysicalSize(prop.getPhysicalSize());
            newTemplate.setName(templateUuid);
            return new CopyCmdAnswer(newTemplate);
        } catch (ConfigurationException e) {
            s_logger.debug("Failed to create template from snapshot: " + e.toString());
            errMsg = e.toString();
        } catch (InternalErrorException e) {
            s_logger.debug("Failed to create template from snapshot: " + e.toString());
            errMsg = e.toString();
        } catch (IOException e) {
            s_logger.debug("Failed to create template from snapshot: " + e.toString());
            errMsg = e.toString();
        }

        return new CopyCmdAnswer(errMsg);
    }
View Full Code Here

                TemplateObjectTO newTemplate = new TemplateObjectTO();
                newTemplate.setPath(destData.getPath() + File.separator + fileName);
                newTemplate.setFormat(srcFormat);
                newTemplate.setSize(prop.getSize());
                newTemplate.setPhysicalSize(prop.getPhysicalSize());
                return new CopyCmdAnswer(newTemplate);
            } catch (ConfigurationException e) {
                s_logger.debug("Failed to create template:" + e.toString());
                return new CopyCmdAnswer(e.toString());
            } catch (IOException e) {
                s_logger.debug("Failed to create template:" + e.toString());
                return new CopyCmdAnswer(e.toString());
            } catch (InternalErrorException e) {
                s_logger.debug("Failed to create template:" + e.toString());
                return new CopyCmdAnswer(e.toString());
            }
        }

        return new CopyCmdAnswer("");
    }
View Full Code Here

            if (destDataStore instanceof NfsTO) {
                return copySnapshotToTemplateFromNfsToNfs(cmd, (SnapshotObjectTO) srcData, (NfsTO) srcDataStore,
                        (TemplateObjectTO) destData, (NfsTO) destDataStore);
            } else if (destDataStore instanceof SwiftTO) {
                //create template on the same data store
                CopyCmdAnswer answer = (CopyCmdAnswer)copySnapshotToTemplateFromNfsToNfs(cmd, (SnapshotObjectTO) srcData, (NfsTO) srcDataStore,
                        (TemplateObjectTO) destData, (NfsTO) srcDataStore);
                if (!answer.getResult()) {
                    return answer;
                }
                s_logger.debug("starting copy template to swift");
                DataTO newTemplate = answer.getNewData();
                File templateFile = getFile(newTemplate.getPath(), ((NfsTO) srcDataStore).getUrl());
                SwiftTO swift = (SwiftTO)destDataStore;
                String containterName = SwiftUtil.getContainerName(destData.getObjectType().toString(), destData.getId());
                String swiftPath = SwiftUtil.putObject(swift, templateFile, containterName, templateFile.getName());
                //upload template.properties
                File properties = new File(templateFile.getParent() + File.separator + _tmpltpp);
                if (properties.exists()) {
                    SwiftUtil.putObject(swift, properties, containterName, _tmpltpp);
                }

                //clean up template data on staging area
                try {
                    DeleteCommand deleteCommand = new DeleteCommand(newTemplate);
                    execute(deleteCommand);
                } catch (Exception e) {
                    s_logger.debug("Failed to clean up staging area:", e);
               
               
                TemplateObjectTO template = new TemplateObjectTO();
                template.setPath(swiftPath);
                template.setSize(templateFile.length());
                template.setPhysicalSize(template.getSize());
                SnapshotObjectTO snapshot = (SnapshotObjectTO)srcData;
                template.setFormat(snapshot.getVolume().getFormat());
                return new CopyCmdAnswer(template);
            } else if (destDataStore instanceof S3TO) {
                //create template on the same data store
                CopyCmdAnswer answer = (CopyCmdAnswer)copySnapshotToTemplateFromNfsToNfs(cmd, (SnapshotObjectTO) srcData, (NfsTO) srcDataStore,
                        (TemplateObjectTO) destData, (NfsTO) srcDataStore);
                if (!answer.getResult()) {
                    return answer;
                }
                TemplateObjectTO newTemplate = (TemplateObjectTO)answer.getNewData();
                newTemplate.setDataStore(srcDataStore);
                CopyCommand newCpyCmd = new CopyCommand(newTemplate, destData, cmd.getWait(), cmd.executeInSequence());
                Answer result = copyFromNfsToS3(newCpyCmd);
                //clean up template data on staging area
                try {
                    DeleteCommand deleteCommand = new DeleteCommand(newTemplate);
                    execute(deleteCommand);
                } catch (Exception e) {
                    s_logger.debug("Failed to clean up staging area:", e);
               
                return result;
            }
        }
        s_logger.debug("Failed to create templat from snapshot");
        return new CopyCmdAnswer("Unsupported prototcol");
    }
View Full Code Here

        DataStoreTO destDataStore = destData.getDataStore();

        if (destDataStore instanceof S3TO) {
            return copyFromNfsToS3(cmd);
        } else {
            return new CopyCmdAnswer("unsupported ");
        }
    }
View Full Code Here

                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 = this.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);
            }

            DataTO retObj = null;
            if (destData.getObjectType() == DataObjectType.TEMPLATE) {
                TemplateObjectTO newTemplate = new TemplateObjectTO();
                newTemplate.setPath(key);
                newTemplate.setSize(getVirtualSize(srcFile, format));
                newTemplate.setPhysicalSize(srcFile.length());
                newTemplate.setFormat(format);
                retObj = newTemplate;
            } else if (destData.getObjectType() == DataObjectType.VOLUME) {
                VolumeObjectTO newVol = new VolumeObjectTO();
                newVol.setPath(key);
                newVol.setSize(srcFile.length());
                retObj = newVol;
            } else if (destData.getObjectType() == DataObjectType.SNAPSHOT) {
                SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
                newSnapshot.setPath(key);
                retObj = newSnapshot;
            }

            return new CopyCmdAnswer(retObj);
        } catch (Exception e) {
            s_logger.error("failed to upload" + srcData.getPath(), e);
            return new CopyCmdAnswer("failed to upload" + srcData.getPath() + e.toString());
        }
    }
View Full Code Here

                SR poolsr = null;
                Set<SR> srs = SR.getByNameLabel(conn, poolName);
                if (srs.size() != 1) {
                    String msg = "There are " + srs.size() + " SRs with same name: " + poolName;
                    s_logger.warn(msg);
                    return new CopyCmdAnswer(msg);
                } else {
                    poolsr = srs.iterator().next();
                }
                String pUuid = poolsr.getUuid(conn);
                boolean isISCSI = IsISCSI(poolsr.getType(conn));
                String uuid = copy_vhd_from_secondarystorage(conn, tmplpath, pUuid, wait);
                VDI tmpl = getVDIbyUuid(conn, uuid);
                VDI snapshotvdi = tmpl.snapshot(conn, new HashMap<String, String>());
                String snapshotUuid = snapshotvdi.getUuid(conn);
                snapshotvdi.setNameLabel(conn, "Template " + srcTemplate.getName());
                String parentuuid = getVhdParent(conn, pUuid, snapshotUuid, isISCSI);
                VDI parent = getVDIbyUuid(conn, parentuuid);
                Long phySize = parent.getPhysicalUtilisation(conn);
                tmpl.destroy(conn);
                poolsr.scan(conn);
                try{
                    Thread.sleep(5000);
                } catch (Exception e) {
                }

                TemplateObjectTO newVol = new TemplateObjectTO();
                newVol.setUuid(snapshotvdi.getUuid(conn));
                newVol.setPath(newVol.getUuid());
                newVol.setFormat(ImageFormat.VHD);
                return new CopyCmdAnswer(newVol);
            }
        }catch (Exception e) {
            String msg = "Catch Exception " + e.getClass().getName() + " for template + " + " due to " + e.toString();
            s_logger.warn(msg, e);
            return new CopyCmdAnswer(msg);
        }
        return new CopyCmdAnswer("not implemented yet");
    }
View Full Code Here

            VolumeObjectTO newVol = new VolumeObjectTO();
            newVol.setName(vdir.nameLabel);
            newVol.setSize(vdir.virtualSize);
            newVol.setPath(vdir.uuid);

            return new CopyCmdAnswer(newVol);
        } catch (Exception e) {
            s_logger.warn("Unable to create volume; Pool=" + pool + "; Disk: ", e);
            return new CopyCmdAnswer(e.toString());
        }
    }
View Full Code Here

                String uuid = copy_vhd_from_secondarystorage(conn, volumePath, srUuid, wait );
                VolumeObjectTO newVol = new VolumeObjectTO();
                newVol.setPath(uuid);
                newVol.setSize(srcVolume.getSize());

                return new CopyCmdAnswer(newVol);
            } catch (Exception e) {
                String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString();
                s_logger.warn(msg, e);
                return new CopyCmdAnswer(e.toString());
            }
        }

        s_logger.debug("unsupported protocol");
        return new CopyCmdAnswer("unsupported protocol");
    }
View Full Code Here

TOP

Related Classes of org.apache.cloudstack.storage.command.CopyCmdAnswer

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.