Search in sources :

Example 16 with ConfigurationException

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

the class LibvirtComputingResourceTest method testCreatePrivateTemplateFromSnapshotCommand.

@Test
public void testCreatePrivateTemplateFromSnapshotCommand() {
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
    final Long dcId = 1l;
    final Long accountId = 1l;
    final Long volumeId = 1l;
    final String backedUpSnapshotUuid = "/run/9a0afe7c-26a7-4585-bf87-abf82ae106d9/";
    final String backedUpSnapshotName = "snap";
    final String origTemplateInstallPath = "/install/path/";
    final Long newTemplateId = 2l;
    final String templateName = "templ";
    final int wait = 0;
    final CreatePrivateTemplateFromSnapshotCommand command = new CreatePrivateTemplateFromSnapshotCommand(pool, secondaryStoragePoolURL, dcId, accountId, volumeId, backedUpSnapshotUuid, backedUpSnapshotName, origTemplateInstallPath, newTemplateId, templateName, wait);
    final String templatePath = "/template/path";
    final String localPath = "/mnt/local";
    final String tmplName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
    final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
    final KVMStoragePool secondaryPool = Mockito.mock(KVMStoragePool.class);
    final KVMStoragePool snapshotPool = Mockito.mock(KVMStoragePool.class);
    final KVMPhysicalDisk snapshot = Mockito.mock(KVMPhysicalDisk.class);
    final StorageLayer storage = Mockito.mock(StorageLayer.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final TemplateLocation location = Mockito.mock(TemplateLocation.class);
    final Processor qcow2Processor = Mockito.mock(Processor.class);
    final FormatInfo info = Mockito.mock(FormatInfo.class);
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    String snapshotPath = command.getSnapshotUuid();
    final int index = snapshotPath.lastIndexOf("/");
    snapshotPath = snapshotPath.substring(0, index);
    when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath)).thenReturn(snapshotPool);
    when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl())).thenReturn(secondaryPool);
    when(snapshotPool.getPhysicalDisk(command.getSnapshotName())).thenReturn(snapshot);
    when(secondaryPool.getLocalPath()).thenReturn(localPath);
    when(libvirtComputingResource.getStorage()).thenReturn(storage);
    when(libvirtComputingResource.createTmplPath()).thenReturn(templatePath);
    when(libvirtComputingResource.getCmdsTimeout()).thenReturn(1);
    final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
    final String templateInstallFolder = "template/tmpl/" + templateFolder;
    final String tmplPath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
    when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(tmplName);
    try {
        when(libvirtUtilitiesHelper.buildQCOW2Processor(storage)).thenReturn(qcow2Processor);
        when(qcow2Processor.process(tmplPath, null, tmplName)).thenReturn(info);
    } catch (final ConfigurationException e) {
        fail(e.getMessage());
    } catch (final InternalErrorException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath);
    verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl());
}
Also used : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) StoragePool(com.cloud.storage.StoragePool) NfsStoragePool(com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool) StorageLayer(com.cloud.storage.StorageLayer) Processor(com.cloud.storage.template.Processor) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) InternalErrorException(com.cloud.exception.InternalErrorException) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) ConfigurationException(javax.naming.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TemplateLocation(com.cloud.storage.template.TemplateLocation) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) FormatInfo(com.cloud.storage.template.Processor.FormatInfo) Test(org.junit.Test)

Example 17 with ConfigurationException

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

the class VmwareServerDiscoverer method reloadResource.

@Override
public ServerResource reloadResource(HostVO host) {
    String resourceName = host.getResource();
    ServerResource resource = getResource(resourceName);
    if (resource != null) {
        _hostDao.loadDetails(host);
        HashMap<String, Object> params = buildConfigParams(host);
        try {
            resource.configure(host.getName(), params);
        } catch (ConfigurationException e) {
            s_logger.warn("Unable to configure resource due to " + e.getMessage());
            return null;
        }
        if (!resource.start()) {
            s_logger.warn("Unable to start the resource");
            return null;
        }
    }
    return resource;
}
Also used : ConfigurationException(javax.naming.ConfigurationException) ServerResource(com.cloud.resource.ServerResource)

Example 18 with ConfigurationException

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

the class ManagementNetworkGuru method configure.

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    File configFile = PropertiesUtil.findConfigFile(configuration);
    FileInputStream inputFile = null;
    try {
        if (null == configFile) {
            throw new FileNotFoundException("Configuration file was not found!");
        }
        inputFile = new FileInputStream(configFile);
    } catch (FileNotFoundException e) {
        s_logger.error(e.getMessage());
        throw new ConfigurationException(e.getMessage());
    }
    final Properties configProps = new Properties();
    try {
        configProps.load(inputFile);
    } catch (IOException e) {
        s_logger.error(e.getMessage());
        throw new ConfigurationException(e.getMessage());
    } finally {
        closeAutoCloseable(inputFile, "error closing config file");
    }
    _mgmtCidr = configProps.getProperty("management.cidr");
    _mgmtGateway = configProps.getProperty("management.gateway");
    s_logger.info("Management network " + _mgmtCidr + " gateway: " + _mgmtGateway);
    return true;
}
Also used : ConfigurationException(javax.naming.ConfigurationException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 19 with ConfigurationException

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

the class ServerResourceBase method configure.

@Override
public boolean configure(final String name, Map<String, Object> params) throws ConfigurationException {
    _name = name;
    String publicNic = (String) params.get("public.network.device");
    if (publicNic == null) {
        publicNic = "xenbr1";
    }
    String privateNic = (String) params.get("private.network.device");
    if (privateNic == null) {
        privateNic = "xenbr0";
    }
    final String storageNic = (String) params.get("storage.network.device");
    final String storageNic2 = (String) params.get("storage.network.device.2");
    _privateNic = getNetworkInterface(privateNic);
    _publicNic = getNetworkInterface(publicNic);
    _storageNic = getNetworkInterface(storageNic);
    _storageNic2 = getNetworkInterface(storageNic2);
    if (_privateNic == null) {
        s_logger.warn("Nics are not specified in properties file/db, will try to autodiscover");
        Enumeration<NetworkInterface> nics = null;
        try {
            nics = NetworkInterface.getNetworkInterfaces();
            if (nics == null || !nics.hasMoreElements()) {
                throw new ConfigurationException("Private NIC is not configured");
            }
        } catch (final SocketException e) {
            throw new ConfigurationException("Private NIC is not configured");
        }
        while (nics.hasMoreElements()) {
            final NetworkInterface nic = nics.nextElement();
            final String nicName = nic.getName();
            //  try {
            if (//nic.isUp() &&
            !nic.isVirtual() && !nicName.startsWith("vnif") && !nicName.startsWith("vnbr") && !nicName.startsWith("peth") && !nicName.startsWith("vif") && !nicName.startsWith("virbr") && !nicName.contains(":")) {
                final String[] info = NetUtils.getNicParams(nicName);
                if (info != null && info[0] != null) {
                    _privateNic = nic;
                    s_logger.info("Designating private to be nic " + nicName);
                    break;
                }
            }
            //      } catch (final SocketException e) {
            //        s_logger.warn("Error looking at " + nicName, e);
            //  }
            s_logger.debug("Skipping nic " + nicName);
        }
        if (_privateNic == null) {
            throw new ConfigurationException("Private NIC is not configured");
        }
    }
    String[] infos = NetUtils.getNetworkParams(_privateNic);
    if (infos == null) {
        s_logger.warn("Incorrect details for private Nic during initialization of ServerResourceBase");
        return false;
    }
    params.put("host.ip", infos[0]);
    params.put("host.mac.address", infos[1]);
    return true;
}
Also used : SocketException(java.net.SocketException) ConfigurationException(javax.naming.ConfigurationException) NetworkInterface(java.net.NetworkInterface)

Example 20 with ConfigurationException

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

the class BaremetalDhcpdResource method configure.

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    com.trilead.ssh2.Connection sshConnection = null;
    try {
        super.configure(name, params);
        s_logger.debug(String.format("Trying to connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s)", _ip, _username, "******"));
        sshConnection = SSHCmdHelper.acquireAuthorizedConnection(_ip, _username, _password);
        if (sshConnection == null) {
            throw new ConfigurationException(String.format("Cannot connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******"));
        }
        if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "[ -f '/usr/sbin/dhcpd' ]")) {
            throw new ConfigurationException("Cannot find dhcpd.conf /etc/dhcpd.conf at  on " + _ip);
        }
        SCPClient scp = new SCPClient(sshConnection);
        String editHosts = "scripts/network/exdhcp/dhcpd_edithosts.py";
        String editHostsPath = Script.findScript("", editHosts);
        if (editHostsPath == null) {
            throw new ConfigurationException("Can not find script dnsmasq_edithosts.sh at " + editHosts);
        }
        scp.put(editHostsPath, "/usr/bin/", "0755");
        String prepareDhcpdScript = "scripts/network/exdhcp/prepare_dhcpd.sh";
        String prepareDhcpdScriptPath = Script.findScript("", prepareDhcpdScript);
        if (prepareDhcpdScriptPath == null) {
            throw new ConfigurationException("Can not find prepare_dhcpd.sh at " + prepareDhcpdScriptPath);
        }
        scp.put(prepareDhcpdScriptPath, "/usr/bin/", "0755");
        //TODO: tooooooooooooooo ugly here!!!
        String[] ips = _ip.split("\\.");
        ips[3] = "0";
        StringBuffer buf = new StringBuffer();
        int i;
        for (i = 0; i < ips.length - 1; i++) {
            buf.append(ips[i]).append(".");
        }
        buf.append(ips[i]);
        String subnet = buf.toString();
        String cmd = String.format("sh /usr/bin/prepare_dhcpd.sh %1$s", subnet);
        if (!SSHCmdHelper.sshExecuteCmd(sshConnection, cmd)) {
            throw new ConfigurationException("prepare Dhcpd at " + _ip + " failed, command:" + cmd);
        }
        s_logger.debug("Dhcpd resource configure successfully");
        return true;
    } catch (Exception e) {
        s_logger.debug("Dhcpd resource configure failed", e);
        throw new ConfigurationException(e.getMessage());
    } finally {
        SSHCmdHelper.releaseSshConnection(sshConnection);
    }
}
Also used : SCPClient(com.trilead.ssh2.SCPClient) ConfigurationException(javax.naming.ConfigurationException) ConfigurationException(javax.naming.ConfigurationException)

Aggregations

ConfigurationException (javax.naming.ConfigurationException)114 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)44 IOException (java.io.IOException)30 HashMap (java.util.HashMap)28 File (java.io.File)16 Map (java.util.Map)14 Properties (java.util.Properties)13 Answer (com.cloud.agent.api.Answer)12 InternalErrorException (com.cloud.exception.InternalErrorException)12 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)12 ServerResource (com.cloud.resource.ServerResource)11 FileNotFoundException (java.io.FileNotFoundException)11 Host (com.cloud.host.Host)10 Processor (com.cloud.storage.template.Processor)10 FileInputStream (java.io.FileInputStream)10 PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)9 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)9 StorageLayer (com.cloud.storage.StorageLayer)9 TemplateLocation (com.cloud.storage.template.TemplateLocation)9 TransactionStatus (com.cloud.utils.db.TransactionStatus)9