This patch simplifies bgpvpn related code.
Change-Id: I36fdb996d4b20dfb1319ec11fe815a882b1bed85
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
*
*/
-public interface INeutronBgpvpnCRUD extends INeutronCRUD<NeutronBgpvpn>{
- /**
- * Applications call this interface method to determine if a particular
- * Bgpvpn object exists
- *
- * @param uuid
- * UUID of the Bgpvpn object
- * @return boolean
- */
-
- boolean bgpvpnExists(String uuid);
-
- /**
- * Applications call this interface method to return if a particular
- * Bgpvpn object exists
- *
- * @param uuid
- * UUID of the Bgpvpn object
- * @return {@link org.opendaylight.neutron.spi.NeutronBgpvpn}
- * OpenStack Bgpvpn class
- */
-
- NeutronBgpvpn getBgpvpn(String uuid);
-
- /**
- * Applications call this interface method to return all Bgpvpn objects
- *
- * @return List of OpenStackBgpvpn objects
- */
-
- List<NeutronBgpvpn> getAllBgpvpns();
-
- /**
- * Applications call this interface method to add a Bgpvpn object to the
- * concurrent map
- *
- * @param input
- * OpenStackBgpvpn object
- * @return boolean on whether the object was added or not
- */
-
- boolean addBgpvpn(NeutronBgpvpn input);
-
- /**
- * Applications call this interface method to remove a Bgpvpn object to the
- * concurrent map
- *
- * @param uuid
- * identifier for the bgpvpn object
- * @return boolean on whether the object was removed or not
- */
-
- boolean removeBgpvpn(String uuid);
-
- /**
- * Applications call this interface method to edit a Bgpvpn object
- *
- * @param uuid
- * identifier of the bgpvpn object
- * @param delta
- * OpenStackBgpvpn object containing changes to apply
- * @return boolean on whether the object was updated or not
- */
-
- boolean updateBgpvpn(String uuid, NeutronBgpvpn delta);
-
- /**
- * Applications call this interface method to determine if a Bgpvpn object
- * is use
- *
- * @param bgpvpnUUID
- * identifier of the bgpvpn object
- *
- * @return boolean on whether the bgpvpn is in use or not
- */
-
- boolean bgpvpnInUse(String bgpvpnUUID);
+public interface INeutronBgpvpnCRUD extends INeutronCRUD<NeutronBgpvpn> {
+ // Nothing Here.
+ // This class is defined to use reflection like INuetornBgpvpnCRUD.class
}
// sorting not supported
) {
INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
- List<NeutronBgpvpn> allBgpvpns = bgpvpnInterface.getAllBgpvpns();
+ List<NeutronBgpvpn> allBgpvpns = bgpvpnInterface.getAll();
List<NeutronBgpvpn> ans = new ArrayList<NeutronBgpvpn>();
Iterator<NeutronBgpvpn> i = allBgpvpns.iterator();
while (i.hasNext()) {
// return fields
@QueryParam("fields") List<String> fields
) {
- INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
- if (!bgpvpnInterface.bgpvpnExists(bgpvpnUUID)) {
- throw new ResourceNotFoundException(uuidNoExist());
- }
- if (fields.size() > 0) {
- NeutronBgpvpn ans = bgpvpnInterface.getBgpvpn(bgpvpnUUID);
- return Response.status(HttpURLConnection.HTTP_OK).entity(
- new NeutronBgpvpnRequest(extractFields(ans, fields))).build();
- } else {
- return Response.status(HttpURLConnection.HTTP_OK).entity(
- new NeutronBgpvpnRequest(bgpvpnInterface.getBgpvpn(bgpvpnUUID))).build();
- }
+ return show(bgpvpnUUID, fields);
}
/**
@ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
@ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
public Response createBgpvpns(final NeutronBgpvpnRequest input) {
- INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
- if (input.isSingleton()) {
- NeutronBgpvpn singleton = input.getSingleton();
-
- // add bgpvpn to MDSAL
- singleton.initDefaults();
- bgpvpnInterface.addBgpvpn(singleton);
- } else {
- // add items to MDSAL
- for (NeutronBgpvpn test : input.getBulk()) {
- test.initDefaults();
- bgpvpnInterface.addBgpvpn(test);
- }
- }
- return Response.status(HttpURLConnection.HTTP_CREATED).entity(input).build();
+ return create(input);
}
/**
* Updates a Bgpvpn */
+ @Override
+ protected void updateDelta(String uuid,
+ NeutronBgpvpn delta, NeutronBgpvpn original) {
+ //Fill in defaults if they're missing in update
+ delta.initDefaults();
+ delta.setID(uuid);
+ delta.setTenantID(original.getTenantID());
+ }
+
@Path("{bgpvpnUUID}")
@PUT
@Produces({ MediaType.APPLICATION_JSON })
public Response updateBgpvpn(
@PathParam("bgpvpnUUID") String bgpvpnUUID, final NeutronBgpvpnRequest input
) {
- INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
-
- NeutronBgpvpn updatedObject = input.getSingleton();
- NeutronBgpvpn original = bgpvpnInterface.getBgpvpn(bgpvpnUUID);
-
- /*
- * note: what we get appears to not be a delta but
- * rather an incomplete updated object. So we need to set
- * the ID to complete the object and then send that down
- * for folks to check
- */
-
- updatedObject.setID(bgpvpnUUID);
- updatedObject.setTenantID(original.getTenantID());
- //Fill in defaults if they're missing in update
- updatedObject.initDefaults();
-
- // update bgpvpn object
- bgpvpnInterface.updateBgpvpn(bgpvpnUUID, updatedObject);
-
- return Response.status(HttpURLConnection.HTTP_OK).entity(
- new NeutronBgpvpnRequest(bgpvpnInterface.getBgpvpn(bgpvpnUUID))).build();
+ return update(bgpvpnUUID, input);
}
/**
@ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
public Response deleteBgpvpn(
@PathParam("bgpvpnUUID") String bgpvpnUUID) {
- INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
-
- if (!bgpvpnInterface.removeBgpvpn(bgpvpnUUID)) {
- throw new InternalServerErrorException("Could not delete bgpvpn");
- }
- return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build();
+ return delete(bgpvpnUUID);
}
}
super(providerContext);
}
- @Override
- public boolean bgpvpnExists(String uuid) {
- return exists(uuid);
- }
-
- @Override
- public NeutronBgpvpn getBgpvpn(String uuid) {
- return get(uuid);
- }
-
@Override
protected List<Bgpvpn> getDataObjectList(Bgpvpns bgpvpns) {
return bgpvpns.getBgpvpn();
}
@Override
- public List<NeutronBgpvpn> getAllBgpvpns() {
- return getAll();
- }
-
- @Override
- public boolean addBgpvpn(NeutronBgpvpn input) {
- return add(input);
- }
-
- @Override
- public boolean removeBgpvpn(String uuid) {
- return remove(uuid);
- }
-
- @Override
- public boolean updateBgpvpn(String uuid, NeutronBgpvpn delta) {
- return update(uuid, delta);
+ public boolean inUse(String uuid) {
+ return !exists(uuid);
}
@Override
- public boolean bgpvpnInUse(String bgpvpnUUID) {
- return !exists(bgpvpnUUID);
- }
-
protected NeutronBgpvpn fromMd(Bgpvpn bgpvpn) {
NeutronBgpvpn result = new NeutronBgpvpn();
result.setAdminStateUp(bgpvpn.isAdminStateUp());
result.setBgpvpnName(bgpvpn.getName());
result.setAutoAggregate(bgpvpn.isAutoAggregate());
result.setStatus(bgpvpn.getStatus());
- result.setTenantID(bgpvpn.getTenantId().getValue().replace("-", ""));
+ result.setTenantID(bgpvpn.getTenantId());
result.setID(bgpvpn.getUuid().getValue());
if(bgpvpn.getVnid() != null) {
result.setVnid(bgpvpn.getVnid());
return result;
}
+ @Override
protected Bgpvpn toMd(NeutronBgpvpn bgpvpn) {
BgpvpnBuilder bgpvpnBuilder = new BgpvpnBuilder();
return bgpvpnBuilder.build();
}
+ @Override
protected Bgpvpn toMd(String uuid) {
BgpvpnBuilder bgpvpnBuilder = new BgpvpnBuilder();
bgpvpnBuilder.setUuid(toUuid(uuid));
.child(Bgpvpn.class, bgpvpn.getKey());
}
+ @Override
protected InstanceIdentifier<Bgpvpns> createInstanceIdentifier() {
return InstanceIdentifier.create(Neutron.class)
.child(Bgpvpns.class);