Search in sources :

Example 26 with BadServerResponse

use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.

the class NotAValidCommand method testOvsCreateTunnelCommandSuccess.

@Test
public void testOvsCreateTunnelCommandSuccess() {
    final String bridge = "tunnel";
    final Connection conn = Mockito.mock(Connection.class);
    final Network network = Mockito.mock(Network.class);
    final OvsCreateTunnelCommand createTunnel = new OvsCreateTunnelCommand("127.0.0.1", 1, 1l, 2l, 1l, "127.0.1.1", "net01", "cd84c713-f448-48c9-ba25-e6740d4a9003");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(citrixResourceBase.findOrCreateTunnelNetwork(conn, createTunnel.getNetworkName())).thenReturn(network);
        when(network.getBridge(conn)).thenReturn(bridge);
        when(citrixResourceBase.callHostPlugin(conn, "ovstunnel", "create_tunnel", "bridge", bridge, "remote_ip", createTunnel.getRemoteIp(), "key", createTunnel.getKey().toString(), "from", createTunnel.getFrom().toString(), "to", createTunnel.getTo().toString(), "cloudstack-network-id", createTunnel.getNetworkUuid())).thenReturn("SUCCESS:0");
    } catch (final BadServerResponse e) {
        fail(e.getMessage());
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    final Answer answer = wrapper.execute(createTunnel, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    verify(citrixResourceBase, times(1)).configureTunnelNetwork(conn, createTunnel.getNetworkId(), createTunnel.getFrom(), createTunnel.getNetworkName());
    assertTrue(answer.getResult());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) OvsCreateTunnelCommand(com.cloud.agent.api.OvsCreateTunnelCommand) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 27 with BadServerResponse

use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.

the class CitrixOvsSetTagAndFlowCommandWrapper method execute.

@Override
public Answer execute(final OvsSetTagAndFlowCommand command, final CitrixResourceBase citrixResourceBase) {
    citrixResourceBase.setIsOvs(true);
    final Connection conn = citrixResourceBase.getConnection();
    try {
        final Network nw = citrixResourceBase.setupvSwitchNetwork(conn);
        final String bridge = nw.getBridge(conn);
        /*
             * If VM is domainRouter, this will try to set flow and tag on its
             * none guest network nic. don't worry, it will fail silently at
             * host plugin side
             */
        final String result = citrixResourceBase.callHostPlugin(conn, "ovsgre", "ovs_set_tag_and_flow", "bridge", bridge, "vmName", command.getVmName(), "tag", command.getTag(), "vlans", command.getVlans(), "seqno", command.getSeqNo());
        s_logger.debug("set flow for " + command.getVmName() + " " + result);
        if (result != null && result.equalsIgnoreCase("SUCCESS")) {
            return new OvsSetTagAndFlowAnswer(command, true, result);
        } else {
            return new OvsSetTagAndFlowAnswer(command, false, result);
        }
    } catch (final BadServerResponse e) {
        s_logger.error("Failed to set tag and flow", e);
    } catch (final XenAPIException e) {
        s_logger.error("Failed to set tag and flow", e);
    } catch (final XmlRpcException e) {
        s_logger.error("Failed to set tag and flow", e);
    }
    return new OvsSetTagAndFlowAnswer(command, false, "EXCEPTION");
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Network(com.xensource.xenapi.Network) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) OvsSetTagAndFlowAnswer(com.cloud.agent.api.OvsSetTagAndFlowAnswer) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 28 with BadServerResponse

use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.

the class XenServerStorageProcessor method deleteVolume.

@Override
public Answer deleteVolume(final DeleteCommand cmd) {
    final DataTO volume = cmd.getData();
    final Connection conn = hypervisorResource.getConnection();
    String errorMsg = null;
    try {
        final VDI vdi = VDI.getByUuid(conn, volume.getPath());
        for (VDI svdi : vdi.getSnapshots(conn)) {
            deleteVDI(conn, svdi);
        }
        deleteVDI(conn, vdi);
        return new Answer(null);
    } catch (final BadServerResponse e) {
        s_logger.debug("Failed to delete volume", e);
        errorMsg = e.toString();
    } catch (final XenAPIException e) {
        s_logger.debug("Failed to delete volume", e);
        errorMsg = e.toString();
    } catch (final XmlRpcException e) {
        s_logger.debug("Failed to delete volume", e);
        errorMsg = e.toString();
    }
    return new Answer(null, false, errorMsg);
}
Also used : CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) Answer(com.cloud.agent.api.Answer) IntroduceObjectAnswer(org.apache.cloudstack.storage.command.IntroduceObjectAnswer) DettachAnswer(org.apache.cloudstack.storage.command.DettachAnswer) SnapshotAndCopyAnswer(org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) DataTO(com.cloud.agent.api.to.DataTO) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) VDI(com.xensource.xenapi.VDI) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 29 with BadServerResponse

use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.

the class XenServerConnectionPool method slaveLocalLoginWithPassword.

protected Session slaveLocalLoginWithPassword(Connection conn, String username, Queue<String> password) throws BadServerResponse, XenAPIException, XmlRpcException {
    Session s = null;
    boolean logged_in = false;
    Exception ex = null;
    while (!logged_in) {
        try {
            s = Session.slaveLocalLoginWithPassword(conn, username, password.peek());
            logged_in = true;
        } catch (BadServerResponse e) {
            logged_in = false;
            ex = e;
        } catch (XenAPIException e) {
            logged_in = false;
            ex = e;
        } catch (XmlRpcException e) {
            logged_in = false;
            ex = e;
        }
        if (logged_in && conn != null) {
            break;
        } else {
            if (password.size() > 1) {
                password.remove();
                continue;
            } else {
                // the last password did not work leave it and flag error
                if (ex instanceof BadServerResponse) {
                    throw (BadServerResponse) ex;
                } else if (ex instanceof XmlRpcException) {
                    throw (XmlRpcException) ex;
                } else if (ex instanceof Types.SessionAuthenticationFailed) {
                    throw (Types.SessionAuthenticationFailed) ex;
                } else if (ex instanceof XenAPIException) {
                    throw (XenAPIException) ex;
                }
                break;
            }
        }
    }
    return s;
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) XmlRpcClientException(org.apache.xmlrpc.client.XmlRpcClientException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Session(com.xensource.xenapi.Session) SSLSession(javax.net.ssl.SSLSession)

Example 30 with BadServerResponse

use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.

the class XenServerConnectionPool method loginWithPassword.

protected Session loginWithPassword(Connection conn, String username, Queue<String> password, String version) throws BadServerResponse, XenAPIException, XmlRpcException {
    Session s = null;
    boolean logged_in = false;
    Exception ex = null;
    while (!logged_in) {
        try {
            s = Session.loginWithPassword(conn, username, password.peek(), APIVersion.latest().toString());
            logged_in = true;
        } catch (BadServerResponse e) {
            logged_in = false;
            ex = e;
        } catch (XenAPIException e) {
            logged_in = false;
            ex = e;
        } catch (XmlRpcException e) {
            logged_in = false;
            ex = e;
        }
        if (logged_in && conn != null) {
            break;
        } else {
            if (password.size() > 1) {
                password.remove();
                continue;
            } else {
                // the last password did not work leave it and flag error
                if (ex instanceof BadServerResponse) {
                    throw (BadServerResponse) ex;
                } else if (ex instanceof XmlRpcException) {
                    throw (XmlRpcException) ex;
                } else if (ex instanceof Types.SessionAuthenticationFailed) {
                    throw (Types.SessionAuthenticationFailed) ex;
                } else if (ex instanceof XenAPIException) {
                    throw (XenAPIException) ex;
                }
            }
        }
    }
    return s;
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) XmlRpcClientException(org.apache.xmlrpc.client.XmlRpcClientException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Session(com.xensource.xenapi.Session) SSLSession(javax.net.ssl.SSLSession)

Aggregations

BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)36 XenAPIException (com.xensource.xenapi.Types.XenAPIException)36 XmlRpcException (org.apache.xmlrpc.XmlRpcException)36 Connection (com.xensource.xenapi.Connection)25 Answer (com.cloud.agent.api.Answer)20 Network (com.xensource.xenapi.Network)14 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)14 Test (org.junit.Test)13 VDI (com.xensource.xenapi.VDI)12 RebootAnswer (com.cloud.agent.api.RebootAnswer)11 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)11 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)11 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 SR (com.xensource.xenapi.SR)8 FileNotFoundException (java.io.FileNotFoundException)6 IOException (java.io.IOException)6 KeyManagementException (java.security.KeyManagementException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 XmlRpcClientException (org.apache.xmlrpc.client.XmlRpcClientException)6