Search in sources :

Example 61 with ConfigurationException

use of javax.naming.ConfigurationException in project cloudstack by apache.

the class NfsSecondaryStorageResource method copyLocalToNfs.

protected void copyLocalToNfs(File localFile, File isoFile, DataStoreTO destData) throws ConfigurationException, IOException {
    String scriptsDir = "scripts/storage/secondary";
    String createVolScr = Script.findScript(scriptsDir, "createvolume.sh");
    if (createVolScr == null) {
        throw new ConfigurationException("Unable to find createvolume.sh");
    }
    s_logger.info("createvolume.sh found in " + createVolScr);
    int installTimeoutPerGig = 180 * 60 * 1000;
    int imgSizeGigs = (int) Math.ceil(localFile.length() * 1.0d / (1024 * 1024 * 1024));
    // add one just in case
    imgSizeGigs++;
    long timeout = imgSizeGigs * installTimeoutPerGig;
    Script scr = new Script(createVolScr, timeout, s_logger);
    scr.add("-s", Integer.toString(imgSizeGigs));
    scr.add("-n", isoFile.getName());
    scr.add("-t", getRootDir(destData.getUrl(), _nfsVersion) + "/" + isoFile.getParent());
    scr.add("-f", localFile.getAbsolutePath());
    scr.add("-d", "configDrive");
    String result;
    result = scr.execute();
    if (result != null) {
        // script execution failure
        throw new CloudRuntimeException("Failed to run script " + createVolScr);
    }
}
Also used : Script(com.cloud.utils.script.Script) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 62 with ConfigurationException

use of javax.naming.ConfigurationException in project cloudstack by apache.

the class NfsSecondaryStorageResource method execute.

private Answer execute(HandleConfigDriveIsoCommand cmd) {
    if (cmd.isCreate()) {
        if (cmd.getIsoData() == null) {
            return new HandleConfigDriveIsoAnswer(cmd, "Invalid config drive ISO data");
        }
        String nfsMountPoint = getRootDir(cmd.getDestStore().getUrl(), _nfsVersion);
        File isoFile = new File(nfsMountPoint, cmd.getIsoFile());
        if (isoFile.exists()) {
            s_logger.debug("config drive iso already exists");
        }
        Path tempDir = null;
        try {
            tempDir = java.nio.file.Files.createTempDirectory(ConfigDrive.CONFIGDRIVEDIR);
            File tmpIsoFile = ConfigDriveBuilder.base64StringToFile(cmd.getIsoData(), tempDir.toAbsolutePath().toString(), cmd.getIsoFile());
            copyLocalToNfs(tmpIsoFile, new File(cmd.getIsoFile()), cmd.getDestStore());
        } catch (IOException | ConfigurationException e) {
            return new HandleConfigDriveIsoAnswer(cmd, "Failed due to exception: " + e.getMessage());
        } finally {
            try {
                if (tempDir != null) {
                    FileUtils.deleteDirectory(tempDir.toFile());
                }
            } catch (IOException ioe) {
                s_logger.warn("Failed to delete ConfigDrive temporary directory: " + tempDir.toString(), ioe);
            }
        }
        return new HandleConfigDriveIsoAnswer(cmd, NetworkElement.Location.SECONDARY, "Successfully saved config drive at secondary storage");
    } else {
        DataStoreTO dstore = cmd.getDestStore();
        if (dstore instanceof NfsTO) {
            NfsTO nfs = (NfsTO) dstore;
            String relativeTemplatePath = new File(cmd.getIsoFile()).getPath();
            String nfsMountPoint = getRootDir(nfs.getUrl(), _nfsVersion);
            File tmpltPath = new File(nfsMountPoint, relativeTemplatePath);
            try {
                Files.deleteIfExists(tmpltPath.toPath());
            } catch (IOException e) {
                return new HandleConfigDriveIsoAnswer(cmd, e);
            }
            return new HandleConfigDriveIsoAnswer(cmd);
        } else {
            return new HandleConfigDriveIsoAnswer(cmd, "Not implemented yet");
        }
    }
}
Also used : Path(java.nio.file.Path) HandleConfigDriveIsoAnswer(com.cloud.agent.api.HandleConfigDriveIsoAnswer) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) ConfigurationException(javax.naming.ConfigurationException) IOException(java.io.IOException) File(java.io.File) S3Utils.putFile(com.cloud.utils.storage.S3.S3Utils.putFile) NfsTO(com.cloud.agent.api.to.NfsTO)

Example 63 with ConfigurationException

use of javax.naming.ConfigurationException in project cloudstack by apache.

the class NfsSecondaryStorageResource method copySnapshotToTemplateFromNfsToNfsXenserver.

protected Answer copySnapshotToTemplateFromNfsToNfsXenserver(CopyCommand cmd, SnapshotObjectTO srcData, NfsTO srcDataStore, TemplateObjectTO destData, NfsTO destDataStore) {
    String srcMountPoint = getRootDir(srcDataStore.getUrl(), _nfsVersion);
    String snapshotPath = srcData.getPath();
    int index = snapshotPath.lastIndexOf("/");
    String snapshotName = snapshotPath.substring(index + 1);
    if (!snapshotName.startsWith("VHD-") && !snapshotName.endsWith(".vhd")) {
        snapshotName = snapshotName + ".vhd";
    }
    snapshotPath = snapshotPath.substring(0, index);
    snapshotPath = srcMountPoint + File.separator + snapshotPath;
    String destMountPoint = getRootDir(destDataStore.getUrl(), _nfsVersion);
    String destPath = destMountPoint + File.separator + destData.getPath();
    String errMsg = null;
    try {
        _storage.mkdir(destPath);
        String templateUuid = UUID.randomUUID().toString();
        String templateName = templateUuid + ".vhd";
        Script command = new Script(createTemplateFromSnapshotXenScript, cmd.getWait() * 1000, s_logger);
        command.add("-p", snapshotPath);
        command.add("-s", snapshotName);
        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);
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) Script(com.cloud.utils.script.Script) OVAProcessor(com.cloud.storage.template.OVAProcessor) VhdProcessor(com.cloud.storage.template.VhdProcessor) QCOW2Processor(com.cloud.storage.template.QCOW2Processor) TARProcessor(com.cloud.storage.template.TARProcessor) Processor(com.cloud.storage.template.Processor) VmdkProcessor(com.cloud.storage.template.VmdkProcessor) RawImageProcessor(com.cloud.storage.template.RawImageProcessor) HashMap(java.util.HashMap) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException) ConfigurationException(javax.naming.ConfigurationException) TemplateLocation(com.cloud.storage.template.TemplateLocation) VhdProcessor(com.cloud.storage.template.VhdProcessor) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) FormatInfo(com.cloud.storage.template.Processor.FormatInfo) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 64 with ConfigurationException

use of javax.naming.ConfigurationException in project cosmic by MissionCriticalCloud.

the class AgentShell method parseCommand.

protected boolean parseCommand(final String[] args) throws ConfigurationException {
    final Properties commandLineProperties = PropertiesUtil.parse(Arrays.stream(args));
    logPropertiesFound(commandLineProperties);
    agentProperties.load(commandLineProperties);
    allProperties.putAll(convertPropertiesToStringObjectMap(commandLineProperties));
    final String guid = agentProperties.getGuid();
    if (guid == null && !agentProperties.isDeveloper()) {
        throw new ConfigurationException("Unable to find the guid");
    }
    return true;
}
Also used : ConfigurationException(javax.naming.ConfigurationException) Properties(java.util.Properties)

Example 65 with ConfigurationException

use of javax.naming.ConfigurationException in project cosmic by MissionCriticalCloud.

the class AgentShell method loadProperties.

public void loadProperties() throws ConfigurationException {
    final File file = PropertiesUtil.findConfigFile(FILE_NAME_AGENT_PROPERTIES);
    if (null == file) {
        throw new ConfigurationException("Unable to find agent.properties.");
    }
    logger.info("Found {} at {}", FILE_NAME_AGENT_PROPERTIES, file.getAbsolutePath());
    final Properties properties = loadPropertiesFromFile(file);
    allProperties.putAll(convertPropertiesToStringObjectMap(properties));
    agentProperties.load(properties);
}
Also used : ConfigurationException(javax.naming.ConfigurationException) Properties(java.util.Properties) File(java.io.File)

Aggregations

ConfigurationException (javax.naming.ConfigurationException)168 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)57 IOException (java.io.IOException)44 HashMap (java.util.HashMap)39 File (java.io.File)23 Map (java.util.Map)21 InternalErrorException (com.cloud.exception.InternalErrorException)19 Properties (java.util.Properties)19 StorageLayer (com.cloud.storage.StorageLayer)18 Processor (com.cloud.storage.template.Processor)17 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)17 Answer (com.cloud.agent.api.Answer)16 ServerResource (com.cloud.resource.ServerResource)16 TemplateLocation (com.cloud.storage.template.TemplateLocation)16 Script (com.cloud.utils.script.Script)16 FormatInfo (com.cloud.storage.template.Processor.FormatInfo)14 FileNotFoundException (java.io.FileNotFoundException)14 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)13 Host (com.cloud.host.Host)11 TransactionStatus (com.cloud.utils.db.TransactionStatus)11