Search in sources :

Example 91 with ConfigurationException

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

the class MidoNetElement method configure.

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    super.configure(name, params);
    String routerIdValue = _configDao.getValue(Config.MidoNetProviderRouterId.key());
    if (routerIdValue != null)
        _providerRouterId = UUID.fromString(routerIdValue);
    String value = _configDao.getValue(Config.MidoNetAPIServerAddress.key());
    if (value == null) {
        throw new ConfigurationException("Could not find midonet API location in config");
    }
    if (this.api == null) {
        s_logger.info("midonet API server address is  " + value);
        setMidonetApi(new MidonetApi(value));
        this.api.enableLogging();
    }
    return true;
}
Also used : ConfigurationException(javax.naming.ConfigurationException) MidonetApi(org.midonet.client.MidonetApi)

Example 92 with ConfigurationException

use of javax.naming.ConfigurationException in project jdk8u_jdk by JetBrains.

the class StartTlsRequest method wrapException.

/*
     * Wrap an exception, thrown while attempting to load the StartTlsResponse
     * class, in a configuration exception.
     */
private ConfigurationException wrapException(Exception e) {
    ConfigurationException ce = new ConfigurationException("Cannot load implementation of javax.naming.ldap.StartTlsResponse");
    ce.setRootCause(e);
    return ce;
}
Also used : ConfigurationException(javax.naming.ConfigurationException)

Example 93 with ConfigurationException

use of javax.naming.ConfigurationException in project narayana by jbosstm.

the class JNDIManager method bindJTATransactionSynchronizationRegistryImplementation.

/**
 * Bind the currently configured TransactionSynchronizationRegistry implementation to the passed in
 * JNDI context.
 * @param initialContext
 * @throws javax.naming.NamingException
 */
public static void bindJTATransactionSynchronizationRegistryImplementation(InitialContext initialContext) throws javax.naming.NamingException {
    /**
     * Look up and instantiate an instance of the configured TransactionSynchronizationRegistry implementation *
     */
    String tsrImplementation = jtaPropertyManager.getJTAEnvironmentBean().getTransactionSynchronizationRegistryClassName();
    Object tsr = null;
    try {
        tsr = Class.forName(tsrImplementation).newInstance();
    } catch (Exception e) {
        NamingException namingException = new ConfigurationException(jtaLogger.i18NLogger.get_utils_JNDIManager_tsr1());
        namingException.setRootCause(e);
        throw namingException;
    }
    /**
     * Bind the TransactionSynchronizationRegistry to the appropriate JNDI context *
     */
    initialContext.rebind(getTransactionSynchronizationRegistryJNDIName(), tsr);
}
Also used : ConfigurationException(javax.naming.ConfigurationException) NamingException(javax.naming.NamingException) ConfigurationException(javax.naming.ConfigurationException) NamingException(javax.naming.NamingException)

Example 94 with ConfigurationException

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

the class LibvirtComputingResource method getDeveloperProperties.

private Map<String, Object> getDeveloperProperties() throws ConfigurationException {
    final File file = PropertiesUtil.findConfigFile("developer.properties");
    if (file == null) {
        throw new ConfigurationException("Unable to find developer.properties.");
    }
    logger.info("developer.properties found at " + file.getAbsolutePath());
    try {
        final Properties properties = PropertiesUtil.loadFromFile(file);
        final String startMac = (String) properties.get("private.macaddr.start");
        if (startMac == null) {
            throw new ConfigurationException("Developers must specify start mac for private ip range");
        }
        final String startIp = (String) properties.get("private.ipaddr.start");
        if (startIp == null) {
            throw new ConfigurationException("Developers must specify start ip for private ip range");
        }
        final Map<String, Object> params = PropertiesUtil.toMap(properties);
        String endIp = (String) properties.get("private.ipaddr.end");
        if (endIp == null) {
            endIp = getEndIpFromStartIp(startIp, 16);
            params.put("private.ipaddr.end", endIp);
        }
        return params;
    } catch (final FileNotFoundException ex) {
        throw new CloudRuntimeException("Cannot find the file: " + file.getAbsolutePath(), ex);
    } catch (final IOException ex) {
        throw new CloudRuntimeException("IOException in reading " + file.getAbsolutePath(), ex);
    }
}
Also used : ConfigurationException(javax.naming.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File)

Example 95 with ConfigurationException

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

the class LibvirtCreatePrivateTemplateFromVolumeCommandWrapper method execute.

@Override
public Answer execute(final CreatePrivateTemplateFromVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final String secondaryStorageUrl = command.getSecondaryStorageUrl();
    KvmStoragePool secondaryStorage = null;
    KvmStoragePool primary = null;
    final KvmStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
    try {
        final String templateFolder = command.getAccountId() + File.separator + command.getTemplateId() + File.separator;
        final String templateInstallFolder = "/template/tmpl/" + templateFolder;
        secondaryStorage = storagePoolMgr.getStoragePoolByUri(secondaryStorageUrl);
        try {
            primary = storagePoolMgr.getStoragePool(command.getPool().getType(), command.getPrimaryStoragePoolNameLabel());
        } catch (final CloudRuntimeException e) {
            if (e.getMessage().contains("not found")) {
                primary = storagePoolMgr.createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool().getUserInfo(), command.getPool().getType());
            } else {
                return new CreatePrivateTemplateAnswer(command, false, e.getMessage());
            }
        }
        final KvmPhysicalDisk disk = primary.getPhysicalDisk(command.getVolumePath());
        final String tmpltPath = secondaryStorage.getLocalPath() + File.separator + templateInstallFolder;
        final StorageLayer storage = libvirtComputingResource.getStorage();
        storage.mkdirs(tmpltPath);
        if (primary.getType() != StoragePoolType.RBD) {
            final String createTmplPath = libvirtComputingResource.createTmplPath();
            final int cmdsTimeout = libvirtComputingResource.getCmdsTimeout();
            final Script scriptCommand = new Script(createTmplPath, cmdsTimeout, s_logger);
            scriptCommand.add("-f", disk.getPath());
            scriptCommand.add("-t", tmpltPath);
            scriptCommand.add("-n", command.getUniqueName() + ".qcow2");
            final String result = scriptCommand.execute();
            if (result != null) {
                s_logger.debug("failed to create template: " + result);
                return new CreatePrivateTemplateAnswer(command, false, result);
            }
        } else {
            s_logger.debug("Converting RBD disk " + disk.getPath() + " into template " + command.getUniqueName());
            final QemuImgFile srcFile = new QemuImgFile(KvmPhysicalDisk.rbdStringBuilder(primary.getSourceHost(), primary.getSourcePort(), primary.getAuthUserName(), primary.getAuthSecret(), disk.getPath()));
            srcFile.setFormat(PhysicalDiskFormat.RAW);
            final QemuImgFile destFile = new QemuImgFile(tmpltPath + "/" + command.getUniqueName() + ".qcow2");
            destFile.setFormat(PhysicalDiskFormat.QCOW2);
            final QemuImg q = new QemuImg(0);
            try {
                q.convert(srcFile, destFile);
            } catch (final QemuImgException e) {
                s_logger.error("Failed to create new template while converting " + srcFile.getFileName() + " to " + destFile.getFileName() + " the error was: " + e.getMessage());
            }
            final File templateProp = new File(tmpltPath + "/template.properties");
            if (!templateProp.exists()) {
                templateProp.createNewFile();
            }
            String templateContent = "filename=" + command.getUniqueName() + ".qcow2" + System.getProperty("line.separator");
            final DateFormat dateFormat = new SimpleDateFormat("MM_dd_yyyy");
            final Date date = new Date();
            templateContent += "snapshot.name=" + dateFormat.format(date) + System.getProperty("line.separator");
            try (FileOutputStream templFo = new FileOutputStream(templateProp)) {
                templFo.write(templateContent.getBytes("UTF-8"));
                templFo.flush();
            } catch (final IOException ex) {
                s_logger.error("CreatePrivateTemplateAnswer:Exception:" + ex.getMessage());
            }
        }
        final Map<String, Object> params = new HashMap<>();
        params.put(StorageLayer.InstanceConfigKey, storage);
        final Processor qcow2Processor = new QCOW2Processor();
        qcow2Processor.configure("QCOW2 Processor", params);
        final FormatInfo info = qcow2Processor.process(tmpltPath, null, command.getUniqueName());
        final TemplateLocation loc = new TemplateLocation(storage, tmpltPath);
        loc.create(1, true, command.getUniqueName());
        loc.addFormat(info);
        loc.save();
        return new CreatePrivateTemplateAnswer(command, true, null, templateInstallFolder + command.getUniqueName() + ".qcow2", info.virtualSize, info.size, command.getUniqueName(), ImageFormat.QCOW2);
    } catch (final InternalErrorException e) {
        return new CreatePrivateTemplateAnswer(command, false, e.toString());
    } catch (final IOException e) {
        return new CreatePrivateTemplateAnswer(command, false, e.toString());
    } catch (final ConfigurationException e) {
        return new CreatePrivateTemplateAnswer(command, false, e.toString());
    } catch (final CloudRuntimeException e) {
        return new CreatePrivateTemplateAnswer(command, false, e.toString());
    } finally {
        if (secondaryStorage != null) {
            storagePoolMgr.deleteStoragePool(secondaryStorage.getType(), secondaryStorage.getUuid());
        }
    }
}
Also used : KvmStoragePool(com.cloud.hypervisor.kvm.storage.KvmStoragePool) StorageLayer(com.cloud.storage.StorageLayer) Processor(com.cloud.storage.template.Processor) QCOW2Processor(com.cloud.storage.template.QCOW2Processor) HashMap(java.util.HashMap) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TemplateLocation(com.cloud.storage.template.TemplateLocation) QemuImgException(com.cloud.utils.qemu.QemuImgException) KvmStoragePoolManager(com.cloud.hypervisor.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.hypervisor.kvm.storage.KvmPhysicalDisk) Script(com.cloud.utils.script.Script) IOException(java.io.IOException) InternalErrorException(com.cloud.exception.InternalErrorException) Date(java.util.Date) QemuImg(com.cloud.utils.qemu.QemuImg) QCOW2Processor(com.cloud.storage.template.QCOW2Processor) QemuImgFile(com.cloud.utils.qemu.QemuImgFile) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) FileOutputStream(java.io.FileOutputStream) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) FormatInfo(com.cloud.storage.template.Processor.FormatInfo) QemuImgFile(com.cloud.utils.qemu.QemuImgFile) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

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