Search in sources :

Example 91 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.

the class Ovm3HypervisorNetwork method createVlanBridge.

private String createVlanBridge(String networkName, Integer vlanId) throws Ovm3ResourceException {
    if (vlanId < 1 || vlanId > 4094) {
        String msg = "Incorrect vlan " + vlanId + ", needs to be between 1 and 4094";
        LOGGER.error(msg);
        throw new CloudRuntimeException(msg);
    }
    Network net = new Network(c);
    /* figure out if our bridged vlan exists, if not then create */
    String brName = networkName + "." + vlanId.toString();
    try {
        String physInterface = net.getPhysicalByBridgeName(networkName);
        if (net.getInterfaceByName(brName) == null) {
            net.startOvsVlanBridge(brName, physInterface, vlanId);
        } else {
            LOGGER.debug("Interface " + brName + " already exists");
        }
    } catch (Ovm3ResourceException e) {
        String msg = "Unable to create vlan " + vlanId.toString() + " bridge for " + networkName;
        LOGGER.warn(msg + ": " + e);
        throw new CloudRuntimeException(msg + ":" + e.getMessage());
    }
    return brName;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.hypervisor.ovm3.objects.Network) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 92 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.

the class XcpServerDiscoverer method processConnect.

@Override
public void processConnect(com.cloud.host.Host agent, StartupCommand cmd, boolean forRebalance) throws ConnectionException {
    if (!(cmd instanceof StartupRoutingCommand)) {
        return;
    }
    long agentId = agent.getId();
    StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
    if (startup.getHypervisorType() != HypervisorType.XenServer) {
        s_logger.debug("Not XenServer so moving on.");
        return;
    }
    HostVO host = _hostDao.findById(agentId);
    ClusterVO cluster = _clusterDao.findById(host.getClusterId());
    if (cluster.getGuid() == null) {
        cluster.setGuid(startup.getPool());
        _clusterDao.update(cluster.getId(), cluster);
    } else if (!cluster.getGuid().equals(startup.getPool())) {
        String msg = "pool uuid for cluster " + cluster.getId() + " changed from " + cluster.getGuid() + " to " + startup.getPool();
        s_logger.warn(msg);
        throw new CloudRuntimeException(msg);
    }
    Map<String, String> details = startup.getHostDetails();
    String prodBrand = details.get("product_brand").trim();
    String prodVersion = details.get("product_version").trim();
    String hotfix = details.get(XenserverConfigs.XS620HotFix);
    String prodVersionTextShort = details.get("product_version_text_short");
    String resource = createServerResource(prodBrand, prodVersion, prodVersionTextShort, hotfix).getClass().getName();
    if (!resource.equals(host.getResource())) {
        String msg = "host " + host.getPrivateIpAddress() + " changed from " + host.getResource() + " to " + resource;
        s_logger.debug(msg);
        host.setResource(resource);
        host.setSetup(false);
        _hostDao.update(agentId, host);
        throw new HypervisorVersionChangedException(msg);
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Setting up host " + agentId);
    }
    HostEnvironment env = new HostEnvironment();
    SetupCommand setup = new SetupCommand(env);
    if (_setupMultipath) {
        setup.setMultipathOn();
    }
    if (!host.isSetup()) {
        setup.setNeedSetup(true);
    }
    try {
        Answer answer = _agentMgr.send(agentId, setup);
        if (answer != null && answer.getResult() && answer instanceof SetupAnswer) {
            host.setSetup(true);
            host.setLastPinged((System.currentTimeMillis() >> 10) - 5 * 60);
            host.setHypervisorVersion(prodVersion);
            _hostDao.update(host.getId(), host);
            if (((SetupAnswer) answer).needReconnect()) {
                throw new ConnectionException(false, "Reinitialize agent after setup.");
            }
            return;
        } else {
            s_logger.warn("Unable to setup agent " + agentId + " due to " + ((answer != null) ? answer.getDetails() : "return null"));
        }
    } catch (AgentUnavailableException e) {
        s_logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e);
    } catch (OperationTimedoutException e) {
        s_logger.warn("Unable to setup agent " + agentId + " because it timed out", e);
    }
    throw new ConnectionException(true, "Reinitialize agent after setup.");
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ClusterVO(com.cloud.dc.ClusterVO) HostEnvironment(com.cloud.host.HostEnvironment) SetupCommand(com.cloud.agent.api.SetupCommand) HostVO(com.cloud.host.HostVO) SetupAnswer(com.cloud.agent.api.SetupAnswer) HypervisorVersionChangedException(com.cloud.utils.exception.HypervisorVersionChangedException) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) SetupAnswer(com.cloud.agent.api.SetupAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) ConnectionException(com.cloud.exception.ConnectionException)

Example 93 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.

the class CitrixResourceBase method getManagementNetwork.

protected XsLocalNetwork getManagementNetwork(final Connection conn) throws XmlRpcException, XenAPIException {
    PIF mgmtPif = null;
    PIF.Record mgmtPifRec = null;
    final Host host = Host.getByUuid(conn, _host.getUuid());
    final Set<PIF> hostPifs = host.getPIFs(conn);
    for (final PIF pif : hostPifs) {
        final PIF.Record rec = pif.getRecord(conn);
        if (rec.management) {
            if (rec.VLAN != null && rec.VLAN != -1) {
                final String msg = new StringBuilder("Unsupported configuration.  Management network is on a VLAN.  host=").append(_host.getUuid()).append("; pif=").append(rec.uuid).append("; vlan=").append(rec.VLAN).toString();
                s_logger.warn(msg);
                throw new CloudRuntimeException(msg);
            }
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Management network is on pif=" + rec.uuid);
            }
            mgmtPif = pif;
            mgmtPifRec = rec;
            break;
        }
    }
    if (mgmtPif == null) {
        final String msg = "Unable to find management network for " + _host.getUuid();
        s_logger.warn(msg);
        throw new CloudRuntimeException(msg);
    }
    final Bond bond = mgmtPifRec.bondSlaveOf;
    if (!isRefNull(bond)) {
        final String msg = "Management interface is on slave(" + mgmtPifRec.uuid + ") of bond(" + bond.getUuid(conn) + ") on host(" + _host.getUuid() + "), please move management interface to bond!";
        s_logger.warn(msg);
        throw new CloudRuntimeException(msg);
    }
    final Network nk = mgmtPifRec.network;
    final Network.Record nkRec = nk.getRecord(conn);
    return new XsLocalNetwork(this, nk, nkRec, mgmtPif, mgmtPifRec);
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.xensource.xenapi.Network) Host(com.xensource.xenapi.Host) PIF(com.xensource.xenapi.PIF) Bond(com.xensource.xenapi.Bond)

Example 94 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.

the class CitrixResourceBase method setupServer.

/* return : if setup is needed */
public boolean setupServer(final Connection conn, final Host host) {
    final String packageVersion = CitrixResourceBase.class.getPackage().getImplementationVersion();
    final String version = this.getClass().getName() + "-" + (packageVersion == null ? Long.toString(System.currentTimeMillis()) : packageVersion);
    try {
        /* push patches to XenServer */
        final Host.Record hr = host.getRecord(conn);
        final Iterator<String> it = hr.tags.iterator();
        while (it.hasNext()) {
            final String tag = it.next();
            if (tag.startsWith("vmops-version-")) {
                if (tag.contains(version)) {
                    s_logger.info(logX(host, "Host " + hr.address + " is already setup."));
                    return false;
                } else {
                    it.remove();
                }
            }
        }
        final com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(hr.address, 22);
        try {
            sshConnection.connect(null, 60000, 60000);
            if (!sshConnection.authenticateWithPassword(_username, _password.peek())) {
                throw new CloudRuntimeException("Unable to authenticate");
            }
            final String cmd = "mkdir -p /opt/cloud/bin /var/log/cloud";
            if (!SSHCmdHelper.sshExecuteCmd(sshConnection, cmd)) {
                throw new CloudRuntimeException("Cannot create directory /opt/cloud/bin on XenServer hosts");
            }
            final SCPClient scp = new SCPClient(sshConnection);
            final List<File> files = getPatchFiles();
            if (files == null || files.isEmpty()) {
                throw new CloudRuntimeException("Can not find patch file");
            }
            for (final File file : files) {
                final String path = file.getParentFile().getAbsolutePath() + "/";
                final Properties props = PropertiesUtil.loadFromFile(file);
                for (final Map.Entry<Object, Object> entry : props.entrySet()) {
                    final String k = (String) entry.getKey();
                    final String v = (String) entry.getValue();
                    assert k != null && k.length() > 0 && v != null && v.length() > 0 : "Problems with " + k + "=" + v;
                    final String[] tokens = v.split(",");
                    String f = null;
                    if (tokens.length == 3 && tokens[0].length() > 0) {
                        if (tokens[0].startsWith("/")) {
                            f = tokens[0];
                        } else if (tokens[0].startsWith("~")) {
                            final String homedir = System.getenv("HOME");
                            f = homedir + tokens[0].substring(1) + k;
                        } else {
                            f = path + tokens[0] + '/' + k;
                        }
                    } else {
                        f = path + k;
                    }
                    final String directoryPath = tokens[tokens.length - 1];
                    f = f.replace('/', File.separatorChar);
                    String permissions = "0755";
                    if (tokens.length == 3) {
                        permissions = tokens[1];
                    } else if (tokens.length == 2) {
                        permissions = tokens[0];
                    }
                    if (!new File(f).exists()) {
                        s_logger.warn("We cannot locate " + f);
                        continue;
                    }
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Copying " + f + " to " + directoryPath + " on " + hr.address + " with permission " + permissions);
                    }
                    if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "mkdir -m 700 -p " + directoryPath)) {
                        s_logger.debug("Unable to create destination path: " + directoryPath + " on " + hr.address + ".");
                    }
                    try {
                        scp.put(f, directoryPath, permissions);
                    } catch (final IOException e) {
                        final String msg = "Unable to copy file " + f + " to path " + directoryPath + " with permissions  " + permissions;
                        s_logger.debug(msg);
                        throw new CloudRuntimeException("Unable to setup the server: " + msg, e);
                    }
                }
            }
        } catch (final IOException e) {
            throw new CloudRuntimeException("Unable to setup the server correctly", e);
        } finally {
            sshConnection.close();
        }
        hr.tags.add("vmops-version-" + version);
        host.setTags(conn, hr.tags);
        return true;
    } catch (final XenAPIException e) {
        final String msg = "XenServer setup failed due to " + e.toString();
        s_logger.warn(msg, e);
        throw new CloudRuntimeException("Unable to get host information " + e.toString(), e);
    } catch (final XmlRpcException e) {
        final String msg = "XenServer setup failed due to " + e.getMessage();
        s_logger.warn(msg, e);
        throw new CloudRuntimeException("Unable to get host information ", e);
    }
}
Also used : SCPClient(com.trilead.ssh2.SCPClient) Connection(com.xensource.xenapi.Connection) URLConnection(java.net.URLConnection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) IOException(java.io.IOException) Properties(java.util.Properties) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIObject(com.xensource.xenapi.XenAPIObject) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 95 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.

the class CitrixResourceBase method createLocalIsoSR.

public SR createLocalIsoSR(final Connection conn, final String srName) throws XenAPIException, XmlRpcException {
    // if config drive sr already exists then return
    SR sr = getSRByNameLabelandHost(conn, _configDriveSRName + _host.getIp());
    if (sr != null) {
        s_logger.debug("Config drive SR already exist, returing it");
        return sr;
    }
    try {
        final Map<String, String> deviceConfig = new HashMap<String, String>();
        final com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_host.getIp(), 22);
        try {
            sshConnection.connect(null, 60000, 60000);
            if (!sshConnection.authenticateWithPassword(_username, _password.peek())) {
                throw new CloudRuntimeException("Unable to authenticate");
            }
            final String cmd = "mkdir -p " + _configDriveIsopath;
            if (!SSHCmdHelper.sshExecuteCmd(sshConnection, cmd)) {
                throw new CloudRuntimeException("Cannot create directory configdrive_iso on XenServer hosts");
            }
        } catch (final IOException e) {
            throw new CloudRuntimeException("Unable to create iso folder", e);
        } finally {
            sshConnection.close();
        }
        s_logger.debug("Created the config drive SR " + srName + " folder path " + _configDriveIsopath);
        deviceConfig.put("location", _configDriveIsopath);
        deviceConfig.put("legacy_mode", "true");
        final Host host = Host.getByUuid(conn, _host.getUuid());
        final String type = SRType.ISO.toString();
        sr = SR.create(conn, host, deviceConfig, new Long(0), _configDriveIsopath, "iso", type, "iso", false, new HashMap<String, String>());
        sr.setNameLabel(conn, srName);
        sr.setNameDescription(conn, deviceConfig.get("location"));
        sr.scan(conn);
        s_logger.debug("Config drive ISO SR at the path " + _configDriveIsopath + " got created in host " + _host);
        return sr;
    } catch (final XenAPIException e) {
        final String msg = "createLocalIsoSR failed! mountpoint " + e.toString();
        s_logger.warn(msg, e);
        throw new CloudRuntimeException(msg, e);
    } catch (final Exception e) {
        final String msg = "createLocalIsoSR failed! mountpoint:  due to " + e.getMessage();
        s_logger.warn(msg, e);
        throw new CloudRuntimeException(msg, e);
    }
}
Also used : HashMap(java.util.HashMap) Connection(com.xensource.xenapi.Connection) URLConnection(java.net.URLConnection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) IOException(java.io.IOException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SR(com.xensource.xenapi.SR)

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