Search in sources :

Example 6 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project CloudStack-archive by CloudStack-extras.

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.");
    }
    s_logger.info("developer.properties found at " + file.getAbsolutePath());
    Properties properties = new Properties();
    try {
        properties.load(new FileInputStream(file));
        String startMac = (String) properties.get("private.macaddr.start");
        if (startMac == null) {
            throw new ConfigurationException("Developers must specify start mac for private ip range");
        }
        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) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 7 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method saveProperties.

private void saveProperties(Map<String, Object> params) throws ConfigurationException {
    final File file = PropertiesUtil.findConfigFile("agent.properties");
    if (file == null) {
        throw new ConfigurationException("Unable to find agent.properties.");
    }
    s_logger.info("agent.properties found at " + file.getAbsolutePath());
    try {
        Properties _properties = new Properties();
        _properties.load(new FileInputStream(file));
        Set<String> names = _properties.stringPropertyNames();
        for (String key : params.keySet()) {
            if (!names.contains(key)) {
                _properties.setProperty(key, (String) params.get(key));
            }
        }
        _properties.store(new FileOutputStream(file), "");
    } 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) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 8 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project CloudStack-archive by CloudStack-extras.

the class LibvirtStorageAdaptor method createFileBasedStoragePool.

public StoragePool createFileBasedStoragePool(Connect conn, String localStoragePath, String uuid) {
    if (!(_storageLayer.exists(localStoragePath) && _storageLayer.isDirectory(localStoragePath))) {
        return null;
    }
    File path = new File(localStoragePath);
    if (!(path.canWrite() && path.canRead() && path.canExecute())) {
        return null;
    }
    StoragePool pool = null;
    try {
        pool = conn.storagePoolLookupByUUIDString(uuid);
    } catch (LibvirtException e) {
    }
    if (pool == null) {
        LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(poolType.DIR, uuid, uuid, null, null, localStoragePath);
        try {
            pool = conn.storagePoolDefineXML(spd.toString(), 0);
            pool.create(0);
        } catch (LibvirtException e) {
            if (pool != null) {
                try {
                    pool.destroy();
                    pool.undefine();
                } catch (LibvirtException e1) {
                }
                pool = null;
            }
            throw new CloudRuntimeException(e.toString());
        }
    }
    try {
        StoragePoolInfo spi = pool.getInfo();
        if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
            pool.create(0);
        }
    } catch (LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
    return pool;
}
Also used : StoragePool(org.libvirt.StoragePool) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolInfo(org.libvirt.StoragePoolInfo) LibvirtStoragePoolDef(com.cloud.agent.resource.computing.LibvirtStoragePoolDef) File(java.io.File)

Example 9 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project CloudStack-archive by CloudStack-extras.

the class LibvirtStorageAdaptor method getStoragePoolByUri.

@Override
public KVMStoragePool getStoragePoolByUri(String uri) {
    URI storageUri = null;
    try {
        storageUri = new URI(uri);
    } catch (URISyntaxException e) {
        throw new CloudRuntimeException(e.toString());
    }
    String sourcePath = null;
    String uuid = null;
    String sourceHost = "";
    StoragePoolType protocal = null;
    if (storageUri.getScheme().equalsIgnoreCase("nfs")) {
        sourcePath = storageUri.getPath();
        sourcePath = sourcePath.replace("//", "/");
        sourceHost = storageUri.getHost();
        uuid = UUID.randomUUID().toString();
        protocal = StoragePoolType.NetworkFilesystem;
    }
    return createStoragePool(uuid, sourceHost, sourcePath, protocal);
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolType(com.cloud.storage.Storage.StoragePoolType) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 10 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project CloudStack-archive by CloudStack-extras.

the class LibvirtStorageAdaptor method getPhysicalDisk.

@Override
public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, KVMStoragePool pool) {
    LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
    try {
        StorageVol vol = this.getVolume(libvirtPool.getPool(), volumeUuid);
        KVMPhysicalDisk disk;
        LibvirtStorageVolumeDef voldef = getStorageVolumeDef(libvirtPool.getPool().getConnect(), vol);
        disk = new KVMPhysicalDisk(vol.getPath(), vol.getName(), pool);
        disk.setSize(vol.getInfo().allocation);
        disk.setVirtualSize(vol.getInfo().capacity);
        if (voldef.getFormat() == null) {
            disk.setFormat(pool.getDefaultFormat());
        } else if (voldef.getFormat() == LibvirtStorageVolumeDef.volFormat.QCOW2) {
            disk.setFormat(KVMPhysicalDisk.PhysicalDiskFormat.QCOW2);
        } else if (voldef.getFormat() == LibvirtStorageVolumeDef.volFormat.RAW) {
            disk.setFormat(KVMPhysicalDisk.PhysicalDiskFormat.RAW);
        }
        return disk;
    } catch (LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
}
Also used : StorageVol(org.libvirt.StorageVol) LibvirtStorageVolumeDef(com.cloud.agent.resource.computing.LibvirtStorageVolumeDef) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1279 PreparedStatement (java.sql.PreparedStatement)320 SQLException (java.sql.SQLException)320 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)236 ResultSet (java.sql.ResultSet)217 ArrayList (java.util.ArrayList)217 ConfigurationException (javax.naming.ConfigurationException)171 HashMap (java.util.HashMap)129 DB (com.cloud.utils.db.DB)118 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)115 IOException (java.io.IOException)95 HostVO (com.cloud.host.HostVO)94 Answer (com.cloud.agent.api.Answer)84 Account (com.cloud.user.Account)84 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)82 URISyntaxException (java.net.URISyntaxException)82 ActionEvent (com.cloud.event.ActionEvent)70 TransactionStatus (com.cloud.utils.db.TransactionStatus)65 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)63 InternalErrorException (com.cloud.exception.InternalErrorException)57