Search in sources :

Example 6 with NeutronRestApi

use of org.apache.cloudstack.network.opendaylight.api.NeutronRestApi in project cloudstack by apache.

the class NeutronRestApiMock method resourceHttpGetInstances.

@Test
public void resourceHttpGetInstances() throws NeutronRestApiException {
    NeutronRestApi newHttpGet = factory.getNeutronApi(GetMethod.class);
    assertTrue(httpGet == newHttpGet);
}
Also used : NeutronRestApi(org.apache.cloudstack.network.opendaylight.api.NeutronRestApi) Test(org.junit.Test)

Example 7 with NeutronRestApi

use of org.apache.cloudstack.network.opendaylight.api.NeutronRestApi in project cloudstack by apache.

the class NeutronRestApiMock method resourceHttpDeleteInstances.

@Test
public void resourceHttpDeleteInstances() throws NeutronRestApiException {
    NeutronRestApi newHttpDelete = factory.getNeutronApi(DeleteMethod.class);
    assertTrue(httpDelete == newHttpDelete);
}
Also used : NeutronRestApi(org.apache.cloudstack.network.opendaylight.api.NeutronRestApi) Test(org.junit.Test)

Example 8 with NeutronRestApi

use of org.apache.cloudstack.network.opendaylight.api.NeutronRestApi in project cloudstack by apache.

the class Action method executeGet.

public String executeGet(final String uri, final Map<String, String> parameters) throws NeutronRestApiException {
    try {
        validateCredentials();
    } catch (NeutronInvalidCredentialsException e) {
        throw new NeutronRestApiException("Invalid credentials!", e);
    }
    NeutronRestFactory factory = NeutronRestFactory.getInstance();
    NeutronRestApi neutronRestApi = factory.getNeutronApi(GetMethod.class);
    GetMethod getMethod = (GetMethod) neutronRestApi.createMethod(url, uri);
    try {
        getMethod.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE);
        String encodedCredentials = encodeCredentials();
        getMethod.setRequestHeader("Authorization", "Basic " + encodedCredentials);
        if (parameters != null && !parameters.isEmpty()) {
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(parameters.size());
            for (Entry<String, String> e : parameters.entrySet()) {
                nameValuePairs.add(new NameValuePair(e.getKey(), e.getValue()));
            }
            getMethod.setQueryString(nameValuePairs.toArray(new NameValuePair[0]));
        }
        neutronRestApi.executeMethod(getMethod);
        if (getMethod.getStatusCode() != HttpStatus.SC_OK) {
            String errorMessage = responseToErrorMessage(getMethod);
            getMethod.releaseConnection();
            s_logger.error("Failed to retrieve object : " + errorMessage);
            throw new NeutronRestApiException("Failed to retrieve object : " + errorMessage);
        }
        return getMethod.getResponseBodyAsString();
    } catch (NeutronRestApiException e) {
        s_logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e);
        throw new NeutronRestApiException("API call to Neutron Controller Failed", e);
    } catch (IOException e) {
        throw new NeutronRestApiException(e);
    } finally {
        getMethod.releaseConnection();
    }
}
Also used : NeutronRestFactory(org.apache.cloudstack.network.opendaylight.api.NeutronRestFactory) NeutronRestApi(org.apache.cloudstack.network.opendaylight.api.NeutronRestApi) NameValuePair(org.apache.commons.httpclient.NameValuePair) NeutronInvalidCredentialsException(org.apache.cloudstack.network.opendaylight.api.NeutronInvalidCredentialsException) GetMethod(org.apache.commons.httpclient.methods.GetMethod) ArrayList(java.util.ArrayList) NeutronRestApiException(org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException) IOException(java.io.IOException)

Example 9 with NeutronRestApi

use of org.apache.cloudstack.network.opendaylight.api.NeutronRestApi in project cloudstack by apache.

the class NeutronRestApiMock method resourceHttpPutInstances.

@Test
public void resourceHttpPutInstances() throws NeutronRestApiException {
    NeutronRestApi newHttpPut = factory.getNeutronApi(PutMethod.class);
    assertTrue(httpPut == newHttpPut);
}
Also used : NeutronRestApi(org.apache.cloudstack.network.opendaylight.api.NeutronRestApi) Test(org.junit.Test)

Aggregations

NeutronRestApi (org.apache.cloudstack.network.opendaylight.api.NeutronRestApi)9 NeutronInvalidCredentialsException (org.apache.cloudstack.network.opendaylight.api.NeutronInvalidCredentialsException)5 NeutronRestApiException (org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException)5 NeutronRestFactory (org.apache.cloudstack.network.opendaylight.api.NeutronRestFactory)5 Test (org.junit.Test)4 IOException (java.io.IOException)3 PutMethod (org.apache.commons.httpclient.methods.PutMethod)2 ArrayList (java.util.ArrayList)1 NameValuePair (org.apache.commons.httpclient.NameValuePair)1 DeleteMethod (org.apache.commons.httpclient.methods.DeleteMethod)1 GetMethod (org.apache.commons.httpclient.methods.GetMethod)1 PostMethod (org.apache.commons.httpclient.methods.PostMethod)1