Search in sources :

Example 61 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class XenServerResourceNewBase method initialize.

@Override
public StartupCommand[] initialize() throws IllegalArgumentException {
    final StartupCommand[] cmds = super.initialize();
    final Connection conn = getConnection();
    Pool pool;
    try {
        pool = Pool.getByUuid(conn, _host.getPool());
        final Pool.Record poolr = pool.getRecord(conn);
        final Host.Record masterRecord = poolr.master.getRecord(conn);
        if (_host.getUuid().equals(masterRecord.uuid)) {
            _listener = new VmEventListener(true);
        //
        // TODO disable event listener for now. Wait until everything else is ready
        //
        // _listener.start();
        } else {
            _listener = new VmEventListener(false);
        }
    } catch (final XenAPIException e) {
        throw new CloudRuntimeException("Unable to determine who is the master", e);
    } catch (final XmlRpcException e) {
        throw new CloudRuntimeException("Unable to determine who is the master", e);
    }
    return cmds;
}
Also used : StartupCommand(com.cloud.agent.api.StartupCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Pool(com.xensource.xenapi.Pool) Host(com.xensource.xenapi.Host) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 62 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class Connection method callTimeoutInSec.

public Object callTimeoutInSec(String method, Object[] params, int timeout, boolean debug) throws XmlRpcException {
    TimingOutCallback callback = new TimingOutCallback(timeout * 1000);
    Object[] mParams = new Object[params.length + 1];
    mParams[0] = method;
    for (int i = 0; i < params.length; i++) {
        mParams[i + 1] = params[i];
    }
    if (debug) {
        /*
             * some parameters including user password should not be printed in log
             */
        s_logger.debug("Call Ovm agent: " + Coder.toJson(mParams));
    }
    long startTime = System.currentTimeMillis();
    _client.executeAsync("OvmDispatch", mParams, callback);
    try {
        return callback.waitForResponse();
    } catch (TimingOutCallback.TimeoutException to) {
        throw to;
    } catch (Throwable e) {
        throw new XmlRpcException(-2, e.getMessage());
    } finally {
        long endTime = System.currentTimeMillis();
        // in secs
        long during = (endTime - startTime) / 1000;
        s_logger.debug("Ovm call " + method + " finished in " + String.valueOf(during) + " secs");
    }
}
Also used : TimingOutCallback(org.apache.xmlrpc.client.TimingOutCallback) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 63 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class OvmResourceBase method fillHostInfo.

protected void fillHostInfo(StartupRoutingCommand cmd) {
    try {
        OvmHost.Details hostDetails = OvmHost.getDetails(_conn);
        cmd.setName(hostDetails.name);
        cmd.setSpeed(hostDetails.cpuSpeed);
        cmd.setCpus(hostDetails.cpuNum);
        cmd.setMemory(hostDetails.freeMemory);
        cmd.setDom0MinMemory(hostDetails.dom0Memory);
        cmd.setGuid(_guid);
        cmd.setDataCenter(_zoneId.toString());
        cmd.setPod(_podId.toString());
        cmd.setCluster(_clusterId.toString());
        cmd.setVersion(OvmResourceBase.class.getPackage().getImplementationVersion());
        cmd.setHypervisorType(HypervisorType.Ovm);
        //TODO: introudce PIF
        cmd.setPrivateIpAddress(_ip);
        cmd.setStorageIpAddress(_ip);
        String defaultBridge = OvmBridge.getBridgeByIp(_conn, _ip);
        if (_publicNetworkName == null) {
            _publicNetworkName = defaultBridge;
        }
        if (_privateNetworkName == null) {
            _privateNetworkName = _publicNetworkName;
        }
        if (_guestNetworkName == null) {
            _guestNetworkName = _privateNetworkName;
        }
        Map<String, String> d = cmd.getHostDetails();
        d.put("public.network.device", _publicNetworkName);
        d.put("private.network.device", _privateNetworkName);
        d.put("guest.network.device", _guestNetworkName);
        cmd.setHostDetails(d);
        s_logger.debug(String.format("Add a OVM host(%s)", hostDetails.toJson()));
    } catch (XmlRpcException e) {
        s_logger.debug("XML RPC Exception" + e.getMessage(), e);
        throw new CloudRuntimeException("XML RPC Exception" + e.getMessage(), e);
    }
}
Also used : OvmHost(com.cloud.ovm.object.OvmHost) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 64 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class OvmResourceBase method execute.

protected GetVmStatsAnswer execute(GetVmStatsCommand cmd) {
    List<String> vmNames = cmd.getVmNames();
    HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>();
    for (String vmName : vmNames) {
        try {
            VmStatsEntry e = getVmStat(vmName);
            vmStatsNameMap.put(vmName, e);
        } catch (XmlRpcException e) {
            s_logger.debug("Get vm stat for " + vmName + " failed", e);
            continue;
        }
    }
    return new GetVmStatsAnswer(cmd, vmStatsNameMap);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) VmStatsEntry(com.cloud.agent.api.VmStatsEntry) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 65 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class OvmResourceBase method configure.

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    _name = name;
    try {
        _zoneId = Long.parseLong((String) params.get("zone"));
        _podId = Long.parseLong((String) params.get("pod"));
        _clusterId = Long.parseLong((String) params.get("cluster"));
        _ip = (String) params.get("ip");
        _username = (String) params.get("username");
        _password = (String) params.get("password");
        _guid = (String) params.get("guid");
        _privateNetworkName = (String) params.get("private.network.device");
        _publicNetworkName = (String) params.get("public.network.device");
        _guestNetworkName = (String) params.get("guest.network.device");
        _agentUserName = (String) params.get("agentusername");
        _agentPassword = (String) params.get("agentpassword");
    } catch (Exception e) {
        s_logger.debug("Configure " + _name + " failed", e);
        throw new ConfigurationException("Configure " + _name + " failed, " + e.toString());
    }
    if (_podId == null) {
        throw new ConfigurationException("Unable to get the pod");
    }
    if (_ip == null) {
        throw new ConfigurationException("Unable to get the host address");
    }
    if (_username == null) {
        throw new ConfigurationException("Unable to get the username");
    }
    if (_password == null) {
        throw new ConfigurationException("Unable to get the password");
    }
    if (_guid == null) {
        throw new ConfigurationException("Unable to get the guid");
    }
    if (_agentUserName == null) {
        throw new ConfigurationException("Unable to get agent user name");
    }
    if (_agentPassword == null) {
        throw new ConfigurationException("Unable to get agent password");
    }
    try {
        setupServer();
    } catch (Exception e) {
        s_logger.debug("Setup server failed, ip " + _ip, e);
        throw new ConfigurationException("Unable to setup server");
    }
    _conn = new Connection(_ip, _agentUserName, _agentPassword);
    try {
        OvmHost.registerAsMaster(_conn);
        OvmHost.registerAsVmServer(_conn);
        _bridges = OvmBridge.getAllBridges(_conn);
    } catch (XmlRpcException e) {
        s_logger.debug("Get bridges failed", e);
        throw new ConfigurationException("Cannot get bridges on host " + _ip + "," + e.getMessage());
    }
    if (_privateNetworkName != null && !_bridges.contains(_privateNetworkName)) {
        throw new ConfigurationException("Cannot find bridge " + _privateNetworkName + " on host " + _ip + ", all bridges are:" + _bridges);
    }
    if (_publicNetworkName != null && !_bridges.contains(_publicNetworkName)) {
        throw new ConfigurationException("Cannot find bridge " + _publicNetworkName + " on host " + _ip + ", all bridges are:" + _bridges);
    }
    if (_guestNetworkName != null && !_bridges.contains(_guestNetworkName)) {
        throw new ConfigurationException("Cannot find bridge " + _guestNetworkName + " on host " + _ip + ", all bridges are:" + _bridges);
    }
    /* set to false so each time ModifyStoragePoolCommand will re-setup heartbeat*/
    s_isHeartBeat = false;
    /*
        try {
            _canBridgeFirewall = canBridgeFirewall();
        } catch (XmlRpcException e) {
            s_logger.error("Failed to detect whether the host supports security groups.", e);
            _canBridgeFirewall = false;
        }
        */
    _canBridgeFirewall = false;
    s_logger.debug(_canBridgeFirewall ? "OVM host supports security groups." : "OVM host doesn't support security groups.");
    return true;
}
Also used : ConfigurationException(javax.naming.ConfigurationException) Connection(com.cloud.ovm.object.Connection) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(javax.naming.ConfigurationException) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Aggregations

XmlRpcException (org.apache.xmlrpc.XmlRpcException)100 XenAPIException (com.xensource.xenapi.Types.XenAPIException)75 Connection (com.xensource.xenapi.Connection)49 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)35 Answer (com.cloud.agent.api.Answer)33 IOException (java.io.IOException)27 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)26 Network (com.xensource.xenapi.Network)25 Test (org.junit.Test)25 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)22 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)21 Host (com.xensource.xenapi.Host)21 RebootAnswer (com.cloud.agent.api.RebootAnswer)20 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)20 HashMap (java.util.HashMap)20 VM (com.xensource.xenapi.VM)17 VDI (com.xensource.xenapi.VDI)16 ConfigurationException (javax.naming.ConfigurationException)16 SR (com.xensource.xenapi.SR)15 InternalErrorException (com.cloud.exception.InternalErrorException)13