Search in sources :

Example 86 with CloudRuntimeException

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

the class BaremetalKickStartServiceImpl method getVirtualRouter.

private DomainRouterVO getVirtualRouter(Network network) {
    List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), VirtualRouter.Role.VIRTUAL_ROUTER);
    if (routers.isEmpty()) {
        throw new CloudRuntimeException(String.format("cannot find any running virtual router on network[id:%s, uuid:%s]", network.getId(), network.getUuid()));
    }
    if (routers.size() > 1) {
        throw new CloudRuntimeException(String.format("baremetal hasn't supported redundant router yet"));
    }
    DomainRouterVO vr = routers.get(0);
    if (!Hypervisor.HypervisorType.VMware.equals(vr.getHypervisorType())) {
        throw new CloudRuntimeException(String.format("baremetal only support vmware virtual router, but get %s", vr.getHypervisorType()));
    }
    return vr;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 87 with CloudRuntimeException

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

the class BaremetalKickStartServiceImpl method parseKickstartUrl.

private List<String> parseKickstartUrl(VirtualMachineProfile profile) {
    String tpl = profile.getTemplate().getUrl();
    assert tpl != null : "How can a null template get here!!!";
    String[] tpls = tpl.split(";");
    CloudRuntimeException err = new CloudRuntimeException(String.format("template url[%s] is not correctly encoded. it must be in format of ks=http_link_to_kickstartfile;kernel=nfs_path_to_pxe_kernel;initrd=nfs_path_to_pxe_initrd", tpl));
    if (tpls.length != 3) {
        throw err;
    }
    String ks = null;
    String kernel = null;
    String initrd = null;
    for (String t : tpls) {
        String[] kv = t.split("=");
        if (kv.length != 2) {
            throw err;
        }
        if (kv[0].equals("ks")) {
            ks = kv[1];
        } else if (kv[0].equals("kernel")) {
            kernel = kv[1];
        } else if (kv[0].equals("initrd")) {
            initrd = kv[1];
        } else {
            throw err;
        }
    }
    return Arrays.asList(ks, kernel, initrd);
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 88 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException 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 89 with CloudRuntimeException

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

the class Ovm3StoragePool method createRepo.

/**
     * Create primary storage, which is a repository in OVM. Pooling is part of
     * this too and clustering should be in the future.
     *
     * @param cmd
     * @return
     * @throws XmlRpcException
     */
private boolean createRepo(StorageFilerTO cmd) throws XmlRpcException {
    String basePath = config.getAgentOvmRepoPath();
    Repository repo = new Repository(c);
    String primUuid = repo.deDash(cmd.getUuid());
    String ovsRepo = basePath + "/" + primUuid;
    /* should add port ? */
    String mountPoint = String.format("%1$s:%2$s", cmd.getHost(), cmd.getPath());
    String msg;
    if (cmd.getType() == StoragePoolType.NetworkFilesystem) {
        Boolean repoExists = false;
        /* base repo first */
        try {
            repo.mountRepoFs(mountPoint, ovsRepo);
        } catch (Ovm3ResourceException e) {
            LOGGER.debug("Unable to mount NFS repository " + mountPoint + " on " + ovsRepo + " requested for " + config.getAgentHostname() + ": " + e.getMessage());
        }
        try {
            repo.addRepo(mountPoint, ovsRepo);
            repoExists = true;
        } catch (Ovm3ResourceException e) {
            LOGGER.debug("NFS repository " + mountPoint + " on " + ovsRepo + " not found creating repo: " + e.getMessage());
        }
        if (!repoExists) {
            try {
                /*
                     * a mount of the NFS fs by the createrepo actually
                     * generates a null if it is already mounted... -sigh-
                     */
                repo.createRepo(mountPoint, ovsRepo, primUuid, "OVS Repository");
            } catch (Ovm3ResourceException e) {
                msg = "NFS repository " + mountPoint + " on " + ovsRepo + " create failed!";
                LOGGER.debug(msg);
                throw new CloudRuntimeException(msg + " " + e.getMessage(), e);
            }
        }
        /* add base pooling first */
        if (config.getAgentInOvm3Pool()) {
            try {
                msg = "Configuring " + config.getAgentHostname() + "(" + config.getAgentIp() + ") for pool";
                LOGGER.debug(msg);
                setupPool(cmd);
                msg = "Configured host for pool";
                /* add clustering after pooling */
                if (config.getAgentInOvm3Cluster()) {
                    msg = "Setup " + config.getAgentHostname() + "(" + config.getAgentIp() + ")  for cluster";
                    LOGGER.debug(msg);
                /* setup cluster */
                /*
                         * From cluster.java
                         * configure_server_for_cluster(cluster conf, fs, mount,
                         * fsuuid, poolfsbaseuuid)
                         */
                /* create_cluster(poolfsuuid,) */
                }
            } catch (Ovm3ResourceException e) {
                msg = "Unable to setup pool on  " + config.getAgentHostname() + "(" + config.getAgentIp() + ") for " + ovsRepo;
                throw new CloudRuntimeException(msg + " " + e.getMessage(), e);
            }
        } else {
            msg = "no way dude I can't stand for this";
            LOGGER.debug(msg);
        }
        /*
             * this is to create the .generic_fs_stamp else we're not allowed to
             * create any data\disks on this thing
             */
        try {
            URI uri = new URI(cmd.getType() + "://" + cmd.getHost() + ":" + +cmd.getPort() + cmd.getPath() + "/VirtualMachines");
            setupNfsStorage(uri, cmd.getUuid());
        } catch (Exception e) {
            msg = "NFS mount " + mountPoint + " on " + config.getAgentSecStoragePath() + "/" + cmd.getUuid() + " create failed!";
            throw new CloudRuntimeException(msg + " " + e.getMessage(), e);
        }
    } else {
        msg = "NFS repository " + mountPoint + " on " + ovsRepo + " create failed, was type " + cmd.getType();
        LOGGER.debug(msg);
        return false;
    }
    try {
        /* systemvm iso is imported here */
        prepareSecondaryStorageStore(ovsRepo, cmd.getUuid(), cmd.getHost());
    } catch (Exception e) {
        msg = "systemvm.iso copy failed to " + ovsRepo;
        LOGGER.debug(msg, e);
        return false;
    }
    return true;
}
Also used : Repository(com.cloud.hypervisor.ovm3.objects.Repository) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) URI(java.net.URI) ConfigurationException(javax.naming.ConfigurationException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 90 with CloudRuntimeException

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

the class Ovm3StoragePool method prepareSecondaryStorageStore.

/**
     * Copy the systemvm.iso in if it doesn't exist or the size differs.
     *
     * @param storageUrl
     * @param poolUuid
     * @param host
     */
private void prepareSecondaryStorageStore(String storageUrl, String poolUuid, String host) {
    String mountPoint = storageUrl;
    GlobalLock lock = GlobalLock.getInternLock("prepare.systemvm");
    try {
        /* double check */
        if (config.getAgentHasMaster() && config.getAgentInOvm3Pool()) {
            LOGGER.debug("Skip systemvm iso copy, leave it to the master");
            return;
        }
        if (lock.lock(3600)) {
            try {
                /*
                     * save src iso real name for reuse, so we don't depend on
                     * other happy little accidents.
                     */
                File srcIso = getSystemVMPatchIsoFile();
                String destPath = mountPoint + "/ISOs/";
                try {
                    StoragePlugin sp = new StoragePlugin(c);
                    FileProperties fp = sp.storagePluginGetFileInfo(poolUuid, host, destPath + "/" + srcIso.getName());
                    if (fp.getSize() != srcIso.getTotalSpace()) {
                        LOGGER.info(" System VM patch ISO file already exists: " + srcIso.getAbsolutePath().toString() + ", destination: " + destPath);
                    }
                } catch (Exception e) {
                    LOGGER.info("Copy System VM patch ISO file to secondary storage. source ISO: " + srcIso.getAbsolutePath() + ", destination: " + destPath);
                    try {
                        /* Perhaps use a key instead ? */
                        SshHelper.scpTo(c.getIp(), 22, config.getAgentSshUserName(), null, config.getAgentSshPassword(), destPath, srcIso.getAbsolutePath().toString(), "0644");
                    } catch (Exception es) {
                        LOGGER.error("Unexpected exception ", es);
                        String msg = "Unable to copy systemvm ISO on secondary storage. src location: " + srcIso.toString() + ", dest location: " + destPath;
                        LOGGER.error(msg);
                        throw new CloudRuntimeException(msg, es);
                    }
                }
            } finally {
                lock.unlock();
            }
        }
    } finally {
        lock.releaseRef();
    }
}
Also used : GlobalLock(com.cloud.utils.db.GlobalLock) FileProperties(com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) File(java.io.File) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin) ConfigurationException(javax.naming.ConfigurationException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

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