Search in sources :

Example 6 with NeutronNetworkWrapper

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

the class NeutronNetworksNorthboundAction method findNetworkById.

@SuppressWarnings("unchecked")
public <T> T findNetworkById(final String networkId) throws NeutronRestApiException {
    String uri = NeutronNorthboundEnum.NETWORK_PARAM_URI.getUri();
    uri = MessageFormat.format(uri, networkId);
    String bodystring = executeGet(uri, Collections.<String, String>emptyMap());
    Type returnType = new TypeToken<NeutronNetworkWrapper>() {
    }.getType();
    T returnValue = (T) gsonNeutronNetwork.fromJson(bodystring, returnType);
    return returnValue;
}
Also used : Type(java.lang.reflect.Type) NeutronNetworkWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper)

Example 7 with NeutronNetworkWrapper

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

the class NeutronNetworksNorthboundAction method createNeutronNetwork.

@SuppressWarnings("unchecked")
public <T> T createNeutronNetwork(final NeutronNetworkWrapper newNetworkWrapper) throws NeutronRestApiException {
    try {
        String uri = NeutronNorthboundEnum.NETWORKS_URI.getUri();
        StringRequestEntity entity = new StringRequestEntity(gsonNeutronNetwork.toJson(newNetworkWrapper), JSON_CONTENT_TYPE, null);
        String bodystring = executePost(uri, entity);
        T result = (T) gsonNeutronNetwork.fromJson(bodystring, TypeToken.get(NeutronNetworkWrapper.class).getType());
        return result;
    } catch (UnsupportedEncodingException e) {
        throw new NeutronRestApiException("Failed to encode json request body", e);
    }
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NeutronRestApiException(org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException) NeutronNetworkWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper)

Example 8 with NeutronNetworkWrapper

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

the class NeutronNetworkAdapterTest method gsonNeutronNetworkUnmarshalingTest.

@Test
public <T> void gsonNeutronNetworkUnmarshalingTest() throws NeutronRestApiException {
    NeutronNetwork network = new NeutronNetwork();
    network.setId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0"));
    network.setName("test_gre");
    network.setNetworkType("test");
    network.setSegmentationId(1001);
    network.setShared(true);
    network.setTenantId("wilder");
    NeutronNetworkWrapper networkWrapper = new NeutronNetworkWrapper();
    networkWrapper.setNetwork(network);
    NeutronNetworkWrapper returnValue = (NeutronNetworkWrapper) gsonNeutronNetwork.fromJson(jsonString, TypeToken.get(networkWrapper.getClass()).getType());
    Assert.assertNotNull(returnValue);
    Assert.assertEquals("test_gre", returnValue.getNetwork().getName());
}
Also used : NeutronNetwork(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork) NeutronNetworkWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper) Test(org.junit.Test)

Aggregations

NeutronNetworkWrapper (org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper)8 NeutronNetwork (org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork)5 Test (org.junit.Test)5 NeutronNetworksNorthboundAction (org.apache.cloudstack.network.opendaylight.api.resources.NeutronNetworksNorthboundAction)4 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 NeutronRestApiException (org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException)2 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)2 Type (java.lang.reflect.Type)1 Random (java.util.Random)1 ConfigureNetworkAnswer (org.apache.cloudstack.network.opendaylight.agent.responses.ConfigureNetworkAnswer)1