Search in sources :

Example 26 with ConfigurationException

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

the class BaremetalPingPxeResource method execute.

protected PreparePxeServerAnswer execute(PreparePxeServerCommand cmd) {
    com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_ip, 22);
    try {
        sshConnection.connect(null, 60000, 60000);
        if (!sshConnection.authenticateWithPassword(_username, _password)) {
            s_logger.debug("SSH Failed to authenticate");
            throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password));
        }
        String script = String.format("python /usr/bin/prepare_tftp_bootfile.py restore %1$s %2$s %3$s %4$s %5$s %6$s %7$s %8$s %9$s %10$s %11$s", _tftpDir, cmd.getMac(), _storageServer, _share, _dir, cmd.getTemplate(), _cifsUserName, _cifsPassword, cmd.getIp(), cmd.getNetMask(), cmd.getGateWay());
        if (!SSHCmdHelper.sshExecuteCmd(sshConnection, script)) {
            return new PreparePxeServerAnswer(cmd, "prepare PING at " + _ip + " failed, command:" + script);
        }
        s_logger.debug("Prepare Ping PXE server successfully");
        return new PreparePxeServerAnswer(cmd);
    } catch (Exception e) {
        s_logger.debug("Prepare PING pxe server failed", e);
        return new PreparePxeServerAnswer(cmd, e.getMessage());
    } finally {
        if (sshConnection != null) {
            sshConnection.close();
        }
    }
}
Also used : ConfigurationException(javax.naming.ConfigurationException) PreparePxeServerAnswer(com.cloud.agent.api.baremetal.PreparePxeServerAnswer) ConfigurationException(javax.naming.ConfigurationException)

Example 27 with ConfigurationException

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

the class Ovm3HypervisorSupport method setupServer.

/**
     * setupServer:
     * Add the cloudstack plugin and setup the agent.
     * Add the ssh keys to the host.
     *
     * @param c
     * @throws IOException
     */
public Boolean setupServer(String key) throws IOException {
    LOGGER.debug("Setup all bits on agent: " + config.getAgentHostname());
    /* version dependent patching ? */
    try {
        com.trilead.ssh2.Connection sshConnection = SSHCmdHelper.acquireAuthorizedConnection(config.getAgentIp(), config.getAgentSshUserName(), config.getAgentSshPassword());
        if (sshConnection == null) {
            throw new ConfigurationException(String.format("Unable to " + "connect to server(IP=%1$s, username=%2$s, " + "password=%3$s", config.getAgentIp(), config.getAgentSshUserName(), config.getAgentSshPassword()));
        }
        SCPClient scp = new SCPClient(sshConnection);
        String userDataScriptDir = "scripts/vm/hypervisor/ovm3/";
        String userDataScriptPath = Script.findScript("", userDataScriptDir);
        if (userDataScriptPath == null) {
            throw new ConfigurationException("Can not find " + userDataScriptDir);
        }
        String mkdir = "mkdir -p " + config.getAgentScriptsDir();
        if (!SSHCmdHelper.sshExecuteCmd(sshConnection, mkdir)) {
            throw new ConfigurationException("Failed " + mkdir + " on " + config.getAgentHostname());
        }
        for (String script : config.getAgentScripts()) {
            script = userDataScriptPath + "/" + script;
            scp.put(script, config.getAgentScriptsDir(), "0755");
        }
        String prepareCmd = String.format(config.getAgentScriptsDir() + "/" + config.getAgentScript() + " --ssl=" + c.getUseSsl() + " " + "--port=" + c.getPort());
        if (!SSHCmdHelper.sshExecuteCmd(sshConnection, prepareCmd)) {
            throw new ConfigurationException("Failed to insert module on " + config.getAgentHostname());
        } else {
            /* because of OVM 3.3.1 (might be 2000) */
            Thread.sleep(5000);
        }
        CloudstackPlugin cSp = new CloudstackPlugin(c);
        cSp.ovsUploadSshKey(config.getAgentSshKeyFileName(), FileUtils.readFileToString(getSystemVMKeyFile(key)));
        cSp.dom0CheckStorageHealthCheck(config.getAgentScriptsDir(), config.getAgentCheckStorageScript(), config.getCsHostGuid(), config.getAgentStorageCheckTimeout(), config.getAgentStorageCheckInterval());
    } catch (Exception es) {
        LOGGER.error("Unexpected exception ", es);
        String msg = "Unable to install module in agent";
        throw new CloudRuntimeException(msg);
    }
    return true;
}
Also used : SCPClient(com.trilead.ssh2.SCPClient) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 28 with ConfigurationException

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

the class Ovm3StoragePool method takeOwnership33x.

/**
     * If you don't own the host you can't fiddle with it.
     *
     * @param pool
     * @throws ConfigurationException
     */
/* FIXME: Placeholders for now, implement later!!!! */
private void takeOwnership33x(Pool pool) throws ConfigurationException {
    try {
        LOGGER.debug("Take ownership of host " + config.getAgentHostname());
        String event = "http://localhost:10024/event";
        String stats = "http://localhost:10024/stats";
        String mgrCert = "None";
        String signCert = "None";
        pool.takeOwnership33x(config.getAgentOwnedByUuid(), event, stats, mgrCert, signCert);
    } catch (Ovm3ResourceException e) {
        String msg = "Failed to take ownership of host " + config.getAgentHostname();
        LOGGER.error(msg);
        throw new ConfigurationException(msg);
    }
}
Also used : ConfigurationException(javax.naming.ConfigurationException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 29 with ConfigurationException

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

the class Ovm3Discoverer method find.

@Override
public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI url, String username, String password, List<String> hostTags) throws DiscoveryException {
    Connection c = null;
    CheckUrl(url);
    if (clusterId == null) {
        String msg = "must specify cluster Id when add host";
        LOGGER.info(msg);
        throw new DiscoveryException(msg);
    }
    if (podId == null) {
        String msg = "must specify pod Id when add host";
        LOGGER.info(msg);
        throw new DiscoveryException(msg);
    }
    ClusterVO cluster = clusterDao.findById(clusterId);
    if (cluster == null || (cluster.getHypervisorType() != HypervisorType.Ovm3)) {
        String msg = "invalid cluster id or cluster is not for Ovm3 hypervisors";
        LOGGER.info(msg);
        throw new DiscoveryException(msg);
    } else {
        LOGGER.debug("cluster: " + cluster);
    }
    String agentUsername = _params.get("agentusername");
    if (agentUsername == null) {
        String msg = "Agent user name must be specified";
        LOGGER.info(msg);
        throw new DiscoveryException(msg);
    }
    String agentPassword = _params.get("agentpassword");
    if (agentPassword == null) {
        String msg = "Agent password must be specified";
        LOGGER.info(msg);
        throw new DiscoveryException(msg);
    }
    String agentPort = _params.get("agentport");
    if (agentPort == null) {
        String msg = "Agent port must be specified";
        LOGGER.info(msg);
        throw new DiscoveryException(msg);
    }
    try {
        String hostname = url.getHost();
        InetAddress ia = InetAddress.getByName(hostname);
        String hostIp = ia.getHostAddress();
        String guid = UUID.nameUUIDFromBytes(hostIp.getBytes("UTF8")).toString();
        if (checkIfExisted(guid)) {
            String msg = "The host " + hostIp + " has been added before";
            LOGGER.info(msg);
            throw new DiscoveryException(msg);
        }
        LOGGER.debug("Ovm3 discover is going to disover host having guid " + guid);
        ClusterVO clu = clusterDao.findById(clusterId);
        if (clu.getGuid() == null) {
            clu.setGuid(UUID.randomUUID().toString());
        }
        clusterDao.update(clusterId, clu);
        Map<String, String> clusterDetails = clusterDetailsDao.findDetails(clusterId);
        String ovm3vip = (clusterDetails.get("ovm3vip") == null) ? "" : clusterDetails.get("ovm3vip");
        String ovm3pool = (clusterDetails.get("ovm3pool") == null) ? "false" : clusterDetails.get("ovm3pool");
        String ovm3cluster = (clusterDetails.get("ovm3cluster") == null) ? "false" : clusterDetails.get("ovm3cluster");
        /* should perhaps only make this connect to the agent port ? */
        com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(hostIp, 22);
        sshConnection.connect(null, 60000, 60000);
        sshConnection = SSHCmdHelper.acquireAuthorizedConnection(hostIp, username, password);
        if (sshConnection == null) {
            String msg = "Cannot Ssh to Ovm3 host(IP=" + hostIp + ", username=" + username + ", password=*******), discovery failed";
            LOGGER.warn(msg);
            throw new DiscoveryException(msg);
        }
        Map<String, String> details = new HashMap<String, String>();
        Ovm3HypervisorResource ovmResource = new Ovm3HypervisorResource();
        details.put("ip", hostIp);
        details.put("host", hostname);
        details.put("username", username);
        details.put("password", password);
        details.put("zone", Long.toString(dcId));
        details.put("guid", guid);
        details.put("pod", Long.toString(podId));
        details.put("cluster", Long.toString(clusterId));
        details.put("agentusername", agentUsername);
        details.put("agentpassword", agentPassword);
        details.put("agentport", agentPort.toString());
        details.put("ovm3vip", ovm3vip);
        details.put("ovm3pool", ovm3pool);
        details.put("ovm3cluster", ovm3cluster);
        if (publicNetworkDevice != null) {
            details.put("public.network.device", publicNetworkDevice);
        }
        if (privateNetworkDevice != null) {
            details.put("private.network.device", privateNetworkDevice);
        }
        if (guestNetworkDevice != null) {
            details.put("guest.network.device", guestNetworkDevice);
        }
        if (storageNetworkDevice != null) {
            details.put("storage.network.device", storageNetworkDevice);
        }
        Map<String, Object> params = new HashMap<String, Object>();
        params.putAll(details);
        ovmResource.configure(hostname, params);
        ovmResource.start();
        c = new Connection(hostIp, Integer.parseInt(agentPort), agentUsername, agentPassword);
        /* After resource start, we are able to execute our agent api */
        Linux host = new Linux(c);
        details.put("agentVersion", host.getAgentVersion());
        details.put(HostInfo.HOST_OS_KERNEL_VERSION, host.getHostKernelRelease());
        details.put(HostInfo.HOST_OS, host.getHostOs());
        details.put(HostInfo.HOST_OS_VERSION, host.getHostOsVersion());
        details.put(HostInfo.HYPERVISOR_VERSION, host.getHypervisorVersion());
        Map<Ovm3HypervisorResource, Map<String, String>> resources = new HashMap<Ovm3HypervisorResource, Map<String, String>>();
        resources.put(ovmResource, details);
        return resources;
    } catch (UnknownHostException e) {
        LOGGER.error("Host name resolve failed exception, Unable to discover Ovm3 host: " + url.getHost(), e);
        return null;
    } catch (ConfigurationException e) {
        LOGGER.error("Configure resource failed, Unable to discover Ovm3 host: " + url.getHost(), e);
        return null;
    } catch (IOException | Ovm3ResourceException e) {
        LOGGER.error("Unable to discover Ovm3 host: " + url.getHost(), e);
        return null;
    }
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) Connection(com.cloud.hypervisor.ovm3.objects.Connection) IOException(java.io.IOException) Linux(com.cloud.hypervisor.ovm3.objects.Linux) ConfigurationException(javax.naming.ConfigurationException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) DiscoveryException(com.cloud.exception.DiscoveryException) InetAddress(java.net.InetAddress) HashMap(java.util.HashMap) Map(java.util.Map)

Example 30 with ConfigurationException

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

the class XcpServerDiscoverer method find.

@Override
public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI url, String username, String password, List<String> hostTags) throws DiscoveryException {
    Map<CitrixResourceBase, Map<String, String>> resources = new HashMap<CitrixResourceBase, Map<String, String>>();
    Connection conn = null;
    if (!url.getScheme().equals("http")) {
        String msg = "urlString is not http so we're not taking care of the discovery for this: " + url;
        s_logger.debug(msg);
        return null;
    }
    if (clusterId == null) {
        String msg = "must specify cluster Id when add host";
        s_logger.debug(msg);
        throw new RuntimeException(msg);
    }
    if (podId == null) {
        String msg = "must specify pod Id when add host";
        s_logger.debug(msg);
        throw new RuntimeException(msg);
    }
    ClusterVO cluster = _clusterDao.findById(clusterId);
    if (cluster == null || cluster.getHypervisorType() != HypervisorType.XenServer) {
        if (s_logger.isInfoEnabled())
            s_logger.info("invalid cluster id or cluster is not for XenServer hypervisors");
        return null;
    }
    try {
        String hostname = url.getHost();
        InetAddress ia = InetAddress.getByName(hostname);
        String hostIp = ia.getHostAddress();
        Queue<String> pass = new LinkedList<String>();
        pass.add(password);
        conn = _connPool.getConnect(hostIp, username, pass);
        if (conn == null) {
            String msg = "Unable to get a connection to " + url;
            s_logger.debug(msg);
            throw new DiscoveryException(msg);
        }
        Set<Pool> pools = Pool.getAll(conn);
        Pool pool = pools.iterator().next();
        Pool.Record pr = pool.getRecord(conn);
        String poolUuid = pr.uuid;
        Map<Host, Host.Record> hosts = Host.getAllRecords(conn);
        String latestHotFix = "";
        if (poolHasHotFix(conn, hostIp, XenserverConfigs.XSHotFix62ESP1004)) {
            latestHotFix = XenserverConfigs.XSHotFix62ESP1004;
        } else if (poolHasHotFix(conn, hostIp, XenserverConfigs.XSHotFix62ESP1)) {
            latestHotFix = XenserverConfigs.XSHotFix62ESP1;
        }
        /*set cluster hypervisor type to xenserver*/
        ClusterVO clu = _clusterDao.findById(clusterId);
        if (clu.getGuid() == null) {
            setClusterGuid(clu, poolUuid);
        } else {
            List<HostVO> clusterHosts = _resourceMgr.listAllHostsInCluster(clusterId);
            if (clusterHosts != null && clusterHosts.size() > 0) {
                if (!clu.getGuid().equals(poolUuid)) {
                    String msg = "Please join the host " + hostIp + " to XS pool  " + clu.getGuid() + " through XC/XS before adding it through CS UI";
                    s_logger.warn(msg);
                    throw new DiscoveryException(msg);
                }
            } else {
                setClusterGuid(clu, poolUuid);
            }
        }
        // can not use this conn after this point, because this host may join a pool, this conn is retired
        if (conn != null) {
            try {
                Session.logout(conn);
            } catch (Exception e) {
                s_logger.debug("Caught exception during logout", e);
            }
            conn.dispose();
            conn = null;
        }
        poolUuid = clu.getGuid();
        _clusterDao.update(clusterId, clu);
        if (_checkHvm) {
            for (Map.Entry<Host, Host.Record> entry : hosts.entrySet()) {
                Host.Record record = entry.getValue();
                boolean support_hvm = false;
                for (String capability : record.capabilities) {
                    if (capability.contains("hvm")) {
                        support_hvm = true;
                        break;
                    }
                }
                if (!support_hvm) {
                    String msg = "Unable to add host " + record.address + " because it doesn't support hvm";
                    _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, podId, msg, msg);
                    s_logger.debug(msg);
                    throw new RuntimeException(msg);
                }
            }
        }
        for (Map.Entry<Host, Host.Record> entry : hosts.entrySet()) {
            Host.Record record = entry.getValue();
            String hostAddr = record.address;
            String prodVersion = CitrixHelper.getProductVersion(record);
            String xenVersion = record.softwareVersion.get("xen");
            String hostOS = record.softwareVersion.get("product_brand");
            if (hostOS == null) {
                hostOS = record.softwareVersion.get("platform_name");
            }
            String hostOSVer = prodVersion;
            String hostKernelVer = record.softwareVersion.get("linux");
            if (_resourceMgr.findHostByGuid(record.uuid) != null) {
                s_logger.debug("Skipping " + record.address + " because " + record.uuid + " is already in the database.");
                continue;
            }
            CitrixResourceBase resource = createServerResource(dcId, podId, record, latestHotFix);
            s_logger.info("Found host " + record.hostname + " ip=" + record.address + " product version=" + prodVersion);
            Map<String, String> details = new HashMap<String, String>();
            Map<String, Object> params = new HashMap<String, Object>();
            details.put("url", hostAddr);
            details.put("username", username);
            params.put("username", username);
            details.put("password", password);
            params.put("password", password);
            params.put("zone", Long.toString(dcId));
            params.put("guid", record.uuid);
            params.put("pod", podId.toString());
            params.put("cluster", clusterId.toString());
            params.put("pool", poolUuid);
            params.put("ipaddress", record.address);
            details.put(HostInfo.HOST_OS, hostOS);
            details.put(HostInfo.HOST_OS_VERSION, hostOSVer);
            details.put(HostInfo.HOST_OS_KERNEL_VERSION, hostKernelVer);
            details.put(HostInfo.HYPERVISOR_VERSION, xenVersion);
            String privateNetworkLabel = _networkMgr.getDefaultManagementTrafficLabel(dcId, HypervisorType.XenServer);
            String storageNetworkLabel = _networkMgr.getDefaultStorageTrafficLabel(dcId, HypervisorType.XenServer);
            if (!params.containsKey("private.network.device") && privateNetworkLabel != null) {
                params.put("private.network.device", privateNetworkLabel);
                details.put("private.network.device", privateNetworkLabel);
            }
            if (!params.containsKey("storage.network.device1") && storageNetworkLabel != null) {
                params.put("storage.network.device1", storageNetworkLabel);
                details.put("storage.network.device1", storageNetworkLabel);
            }
            DataCenterVO zone = _dcDao.findById(dcId);
            boolean securityGroupEnabled = zone.isSecurityGroupEnabled();
            params.put("securitygroupenabled", Boolean.toString(securityGroupEnabled));
            params.put("router.aggregation.command.each.timeout", _configDao.getValue(Config.RouterAggregationCommandEachTimeout.toString()));
            params.put("wait", Integer.toString(_wait));
            details.put("wait", Integer.toString(_wait));
            params.put("migratewait", _configDao.getValue(Config.MigrateWait.toString()));
            params.put(Config.XenServerMaxNics.toString().toLowerCase(), _configDao.getValue(Config.XenServerMaxNics.toString()));
            params.put(Config.XenServerHeartBeatTimeout.toString().toLowerCase(), _configDao.getValue(Config.XenServerHeartBeatTimeout.toString()));
            params.put(Config.XenServerHeartBeatInterval.toString().toLowerCase(), _configDao.getValue(Config.XenServerHeartBeatInterval.toString()));
            params.put(Config.InstanceName.toString().toLowerCase(), _instance);
            details.put(Config.InstanceName.toString().toLowerCase(), _instance);
            try {
                resource.configure("XenServer", params);
            } catch (ConfigurationException e) {
                _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, podId, "Unable to add " + record.address, "Error is " + e.getMessage());
                s_logger.warn("Unable to instantiate " + record.address, e);
                continue;
            }
            resource.start();
            resources.put(resource, details);
        }
    } catch (SessionAuthenticationFailed e) {
        throw new DiscoveredWithErrorException("Authentication error");
    } catch (XenAPIException e) {
        s_logger.warn("XenAPI exception", e);
        return null;
    } catch (XmlRpcException e) {
        s_logger.warn("Xml Rpc Exception", e);
        return null;
    } catch (UnknownHostException e) {
        s_logger.warn("Unable to resolve the host name", e);
        return null;
    } catch (Exception e) {
        s_logger.debug("other exceptions: " + e.toString(), e);
        return null;
    }
    return resources;
}
Also used : HashMap(java.util.HashMap) XenAPIException(com.xensource.xenapi.Types.XenAPIException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConfigurationException(javax.naming.ConfigurationException) Pool(com.xensource.xenapi.Pool) XenServerConnectionPool(com.cloud.hypervisor.xenserver.resource.XenServerConnectionPool) DiscoveryException(com.cloud.exception.DiscoveryException) DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) UnknownHostException(java.net.UnknownHostException) Connection(com.xensource.xenapi.Connection) DiscoveredWithErrorException(com.cloud.exception.DiscoveredWithErrorException) Host(com.xensource.xenapi.Host) LinkedList(java.util.LinkedList) HostVO(com.cloud.host.HostVO) DiscoveredWithErrorException(com.cloud.exception.DiscoveredWithErrorException) DiscoveryException(com.cloud.exception.DiscoveryException) ConnectionException(com.cloud.exception.ConnectionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) EntityExistsException(javax.persistence.EntityExistsException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ConfigurationException(javax.naming.ConfigurationException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HypervisorVersionChangedException(com.cloud.utils.exception.HypervisorVersionChangedException) UnknownHostException(java.net.UnknownHostException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException) CitrixResourceBase(com.cloud.hypervisor.xenserver.resource.CitrixResourceBase) SessionAuthenticationFailed(com.xensource.xenapi.Types.SessionAuthenticationFailed) Map(java.util.Map) HashMap(java.util.HashMap) InetAddress(java.net.InetAddress) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

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