+++ /dev/null
-/*
- * Copyright (C) 2014 Red Hat, Inc. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.neutron.spi;
-
-import javax.xml.bind.annotation.XmlElement;
-import java.util.List;
-
-public class INeutronLoadBalancerPoolMemberRequest {
-
- /**
- * See OpenStack Network API v2.0 Reference for description of
- * http://docs.openstack.org/api/openstack-network/2.0/content/
- */
-
- @XmlElement(name = "member")
- NeutronLoadBalancerPoolMember singletonLoadBalancerPoolMember;
-
- @XmlElement(name = "members")
- List<NeutronLoadBalancerPoolMember> bulkRequest;
-
- INeutronLoadBalancerPoolMemberRequest() {
- }
-
- public INeutronLoadBalancerPoolMemberRequest(List<NeutronLoadBalancerPoolMember> bulk) {
- bulkRequest = bulk;
- singletonLoadBalancerPoolMember = null;
- }
-
- INeutronLoadBalancerPoolMemberRequest(NeutronLoadBalancerPoolMember group) {
- singletonLoadBalancerPoolMember = group;
- }
-
- public List<NeutronLoadBalancerPoolMember> getBulk() {
- return bulkRequest;
- }
-
- public NeutronLoadBalancerPoolMember getSingleton() {
- return singletonLoadBalancerPoolMember;
- }
-
- public boolean isSingleton() {
- return (singletonLoadBalancerPoolMember != null);
- }
-}
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.neutron.spi;
+
+import java.util.List;
+
+public interface INeutronMeteringLabelCRUD {
+
+ /**
+ * Applications call this interface method to determine if a particular
+ *NeutronMeteringLabel object exists
+ *
+ * @param uuid
+ * UUID of the NeutronMeteringLabel object
+ * @return boolean
+ */
+
+ public boolean neutronMeteringLabelExists(String uuid);
+
+ /**
+ * Applications call this interface method to return if a particular
+ * NeutronMeteringLabel object exists
+ *
+ * @param uuid
+ * UUID of the NeutronMeteringLabel object
+ * @return {@link org.opendaylight.neutron.neutron.spi.NeutronMeteringLabel}
+ * OpenStackNeutronMeteringLabel class
+ */
+
+ public NeutronMeteringLabel getNeutronMeteringLabel(String uuid);
+
+ /**
+ * Applications call this interface method to return all NeutronMeteringLabel objects
+ *
+ * @return List of OpenStackNetworks objects
+ */
+
+ public List<NeutronMeteringLabel> getAllNeutronMeteringLabels();
+
+ /**
+ * Applications call this interface method to add a NeutronMeteringLabel object to the
+ * concurrent map
+ *
+ * @param input
+ * OpenStackNetwork object
+ * @return boolean on whether the object was added or not
+ */
+
+ public boolean addNeutronMeteringLabel(NeutronMeteringLabel input);
+
+ /**
+ * Applications call this interface method to remove a Neutron NeutronMeteringLabel object to the
+ * concurrent map
+ *
+ * @param uuid
+ * identifier for the NeutronMeteringLabel object
+ * @return boolean on whether the object was removed or not
+ */
+
+ public boolean removeNeutronMeteringLabel(String uuid);
+
+ /**
+ * Applications call this interface method to edit a NeutronMeteringLabel object
+ *
+ * @param uuid
+ * identifier of the NeutronMeteringLabel object
+ * @param delta
+ * OpenStackNeutronMeteringLabel object containing changes to apply
+ * @return boolean on whether the object was updated or not
+ */
+
+ public boolean updateNeutronMeteringLabel(String uuid, NeutronMeteringLabel delta);
+
+ /**
+ * Applications call this interface method to see if a MAC address is in use
+ *
+ * @param uuid
+ * identifier of the NeutronMeteringLabel object
+ * @return boolean on whether the macAddress is already associated with a
+ * port or not
+ */
+
+ public boolean neutronMeteringLabelInUse(String uuid);
+
+}
return answer;
}
+ public static INeutronMeteringLabelCRUD getINeutronMeteringLabelCRUD(Object o) {
+ INeutronMeteringLabelCRUD answer = (INeutronMeteringLabelCRUD) getInstances(INeutronMeteringLabelCRUD.class, o);
+ return answer;
+ }
+
public static Object getInstances(Class<?> clazz,Object bundle) {
try {
BundleContext bCtx = FrameworkUtil.getBundle(bundle.getClass())
import java.io.Serializable;
+import java.util.Iterator;
+import java.util.List;
+
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
this.meteringLabelName = name;
}
- public String getMeteringTenantID() {
+ public String getMeteringLabelTenantID() {
return tenantID;
}
- public void setMeteringTenantID(String tenantID) {
+ public void setMeteringLabelTenantID(String tenantID) {
this.tenantID = tenantID;
}
- public String getMeteringDescription() {
+ public String getMeteringLabelDescription() {
return description;
}
- public void setMeteringDescription(String description) {
+ public void setMeteringLabelDescription(String description) {
this.description = description;
}
", tenant_id=" + tenantID + "]";
}
+ /**
+ * This method copies selected fields from the object and returns them
+ * as a new object, suitable for marshaling.
+ *
+ * @param fields
+ * List of attributes to be extracted
+ * @return a NeutronMeteringLabel object with only the selected fields
+ * populated
+ */
+ public NeutronMeteringLabel extractFields(List<String> fields) {
+ NeutronMeteringLabel ans = new NeutronMeteringLabel();
+ Iterator<String> i = fields.iterator();
+ while (i.hasNext()) {
+ String s = i.next();
+ if (s.equals("id")) {
+ ans.setMeteringLabelUUID(this.getMeteringLabelUUID());
+ }
+ if (s.equals("name")) {
+ ans.setMeteringLabelName(this.getMeteringLabelName());
+ }
+ if (s.equals("tenant_id")) {
+ ans.setMeteringLabelTenantID(this.getMeteringLabelTenantID());
+ }
+ if (s.equals("description")) {
+ ans.setMeteringLabelDescription(this.getMeteringLabelDescription());
+ }
+ }
+ return ans;
+ }
}
testObject.getMeteringLabelName());
Assert.assertEquals("NeutronMeteringLabel JAXB Test 3: Testing description failed",
- "Provides allowed address pairs", testObject.getMeteringDescription());
+ "Provides allowed address pairs", testObject.getMeteringLabelDescription());
Assert.assertEquals("NeutronMeteringLabel JAXB Test 4: Testing tenant_id failed",
- "9bacb3c5d39d41a79512987f338cf177", testObject.getMeteringTenantID());
+ "9bacb3c5d39d41a79512987f338cf177", testObject.getMeteringLabelTenantID());
} catch (Exception e) {
Assert.fail("Test failed");
}
@XmlElement(name="metering_label")
NeutronMeteringLabel singletonMeteringLabel;
+ @XmlElement(name="metering_labels")
+ List<NeutronMeteringLabel> bulkMeteringLabels;
+
NeutronMeteringLabelRequest() {
}
NeutronMeteringLabelRequest(NeutronMeteringLabel label) {
singletonMeteringLabel = label;
+ bulkMeteringLabels = null;
+ }
+
+ NeutronMeteringLabelRequest(List<NeutronMeteringLabel> bulk) {
+ bulkMeteringLabels = bulk;
+ singletonMeteringLabel = null;
}
public NeutronMeteringLabel getSingleton() {
return singletonMeteringLabel;
}
+
+ public boolean isSingleton() {
+ return (singletonMeteringLabel != null);
+ }
+
+ public List<NeutronMeteringLabel> getBulk() {
+ return bulkMeteringLabels;
+ }
}
import org.codehaus.enunciate.jaxrs.StatusCodes;
import org.codehaus.enunciate.jaxrs.TypeHint;
+import org.opendaylight.neutron.spi.INeutronMeteringLabelAware;
+import org.opendaylight.neutron.spi.INeutronMeteringLabelCRUD;
+import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
+import org.opendaylight.neutron.spi.NeutronMeteringLabel;
+
/**
* Neutron Northbound REST APIs for Metering Lables.<br>
* This class provides REST APIs for managing neutron metering labels
@Path("/metering/metering-labels")
public class NeutronMeteringLabelsNorthbound {
+ private NeutronMeteringLabel extractFields(NeutronMeteringLabel o, List<String> fields) {
+ return o.extractFields(fields);
+ }
+
@Context
UriInfo uriInfo;
@Produces({ MediaType.APPLICATION_JSON })
//@TypeHint(OpenStackNetworks.class)
@StatusCodes({
- @ResponseCode(code = 501, condition = "Not Implemented") })
+ @ResponseCode(code = 200, condition = "Operation successful"),
+ @ResponseCode(code = 401, condition = "Unauthorized"),
+ @ResponseCode(code = 501, condition = "Not Implemented"),
+ @ResponseCode(code = 503, condition = "No providers available") })
public Response listMeteringLabels(
+ // return fields
+ @QueryParam("fields") List<String> fields,
+ // filter fields
+ @QueryParam("id") String queryID,
+ @QueryParam("name") String queryName,
+ @QueryParam("tenant_id") String queryTenantID,
+ @QueryParam("description") String queryDescription
+ // pagination and sorting are TODO
) {
- throw new UnimplementedException("Unimplemented");
+ INeutronMeteringLabelCRUD labelInterface = NeutronCRUDInterfaces.getINeutronMeteringLabelCRUD(this);
+ if (labelInterface == null) {
+ throw new ServiceUnavailableException("NeutronMeteringLabel CRUD Interface "
+ + RestMessages.SERVICEUNAVAILABLE.toString());
+ }
+ List<NeutronMeteringLabel> allNeutronMeteringLabels = labelInterface.getAllNeutronMeteringLabels();
+ List<NeutronMeteringLabel> ans = new ArrayList<NeutronMeteringLabel>();
+ Iterator<NeutronMeteringLabel> i = allNeutronMeteringLabels.iterator();
+ while (i.hasNext()) {
+ NeutronMeteringLabel oSS = i.next();
+ if ((queryID == null || queryID.equals(oSS.getMeteringLabelUUID())) &&
+ (queryName == null || queryName.equals(oSS.getMeteringLabelName())) &&
+ (queryDescription == null || queryDescription.equals(oSS.getMeteringLabelDescription())) &&
+ (queryTenantID == null || queryTenantID.equals(oSS.getMeteringLabelTenantID()))) {
+ if (fields.size() > 0)
+ ans.add(extractFields(oSS,fields));
+ else
+ ans.add(oSS);
+ }
+ }
+ //TODO: apply pagination to results
+ return Response.status(200).entity(
+ new NeutronMeteringLabelRequest(ans)).build();
}
/**
@GET
@Produces({ MediaType.APPLICATION_JSON })
@StatusCodes({
- @ResponseCode(code = 501, condition = "Not Implemented") })
+ @ResponseCode(code = 200, condition = "Operation successful"),
+ @ResponseCode(code = 401, condition = "Unauthorized"),
+ @ResponseCode(code = 403, condition = "Forbidden"),
+ @ResponseCode(code = 404, condition = "Not Found"),
+ @ResponseCode(code = 501, condition = "Not Implemented"),
+ @ResponseCode(code = 503, condition = "No providers available") })
public Response showMeteringLabel(
- @PathParam("labelUUID") String labelUUID
- ) {
- throw new UnimplementedException("Unimplemented");
+ @PathParam("labelUUID") String labelUUID,
+ // return fields
+ @QueryParam("fields") List<String> fields) {
+ INeutronMeteringLabelCRUD labelInterface = NeutronCRUDInterfaces.getINeutronMeteringLabelCRUD(this);
+ if (labelInterface == null) {
+ throw new ServiceUnavailableException("MeteringLabel CRUD Interface "
+ + RestMessages.SERVICEUNAVAILABLE.toString());
+ }
+ if (!labelInterface.neutronMeteringLabelExists(labelUUID)) {
+ throw new ResourceNotFoundException("MeteringLabel UUID not found");
+ }
+ if (fields.size() > 0) {
+ NeutronMeteringLabel ans = labelInterface.getNeutronMeteringLabel(labelUUID);
+ return Response.status(200).entity(
+ new NeutronMeteringLabelRequest(extractFields(ans, fields))).build();
+ } else {
+ return Response.status(200).entity(
+ new NeutronMeteringLabelRequest(labelInterface.getNeutronMeteringLabel(labelUUID))).build();
+ }
}
/**
@Consumes({ MediaType.APPLICATION_JSON })
//@TypeHint(NeutronNetwork.class)
@StatusCodes({
- @ResponseCode(code = 501, condition = "Not Implemented") })
+ @ResponseCode(code = 201, condition = "Created"),
+ @ResponseCode(code = 400, condition = "Bad Request"),
+ @ResponseCode(code = 401, condition = "Unauthorized"),
+ @ResponseCode(code = 501, condition = "Not Implemented"),
+ @ResponseCode(code = 503, condition = "No providers available") })
public Response createMeteringLabel(final NeutronMeteringLabelRequest input) {
- throw new UnimplementedException("Unimplemented");
+ INeutronMeteringLabelCRUD meteringLabelInterface = NeutronCRUDInterfaces.getINeutronMeteringLabelCRUD(this);
+ if (meteringLabelInterface == null) {
+ throw new ServiceUnavailableException("MeteringLabel CRUD Interface "
+ + RestMessages.SERVICEUNAVAILABLE.toString());
+ }
+ if (input.isSingleton()) {
+ NeutronMeteringLabel singleton = input.getSingleton();
+
+ /*
+ * verify that the meteringLabel doesn't already exist (issue: is deeper inspection necessary?)
+ */
+ if (meteringLabelInterface.neutronMeteringLabelExists(singleton.getMeteringLabelUUID()))
+ throw new BadRequestException("meteringLabel UUID already exists");
+ Object[] instances = NeutronUtil.getInstances(INeutronMeteringLabelAware.class, this);
+ if (instances != null) {
+ if (instances.length > 0) {
+ for (Object instance : instances) {
+ INeutronMeteringLabelAware service = (INeutronMeteringLabelAware) instance;
+ int status = service.canCreateMeteringLabel(singleton);
+ if (status < 200 || status > 299)
+ return Response.status(status).build();
+ }
+ } else {
+ throw new ServiceUnavailableException("No providers registered. Please try again later");
+ }
+ } else {
+ throw new ServiceUnavailableException("Couldn't get providers list. Please try again later");
+ }
+
+ /*
+ * add meteringLabel to the cache
+ */
+ meteringLabelInterface.addNeutronMeteringLabel(singleton);
+ if (instances != null) {
+ for (Object instance : instances) {
+ INeutronMeteringLabelAware service = (INeutronMeteringLabelAware) instance;
+ service.neutronMeteringLabelCreated(singleton);
+ }
+ }
+ } else {
+
+ /*
+ * only singleton meteringLabel creates supported
+ */
+ throw new BadRequestException("Only singleton meteringLabel creates supported");
+ }
+ return Response.status(201).entity(input).build();
}
/**
@Path("{labelUUID}")
@DELETE
@StatusCodes({
- @ResponseCode(code = 501, condition = "Not Implemented") })
+ @ResponseCode(code = 204, condition = "No Content"),
+ @ResponseCode(code = 401, condition = "Unauthorized"),
+ @ResponseCode(code = 404, condition = "Not Found"),
+ @ResponseCode(code = 409, condition = "Conflict"),
+ @ResponseCode(code = 501, condition = "Not Implemented"),
+ @ResponseCode(code = 503, condition = "No providers available") })
public Response deleteMeteringLabel(
@PathParam("labelUUID") String labelUUID) {
- throw new UnimplementedException("Unimplemented");
+ INeutronMeteringLabelCRUD meteringLabelInterface = NeutronCRUDInterfaces.getINeutronMeteringLabelCRUD(this);
+ if (meteringLabelInterface == null) {
+ throw new ServiceUnavailableException("MeteringLabel CRUD Interface "
+ + RestMessages.SERVICEUNAVAILABLE.toString());
+ }
+
+ /*
+ * verify that the meteringLabel exists and is not in use before removing it
+ */
+ if (!meteringLabelInterface.neutronMeteringLabelExists(labelUUID))
+ throw new ResourceNotFoundException("MeteringLabel UUID not found");
+ NeutronMeteringLabel singleton = meteringLabelInterface.getNeutronMeteringLabel(labelUUID);
+ Object[] instances = NeutronUtil.getInstances(INeutronMeteringLabelAware.class, this);
+ if (instances != null) {
+ if (instances.length > 0) {
+ for (Object instance : instances) {
+ INeutronMeteringLabelAware service = (INeutronMeteringLabelAware) instance;
+ int status = service.canDeleteMeteringLabel(singleton);
+ if (status < 200 || status > 299)
+ return Response.status(status).build();
+ }
+ } else {
+ throw new ServiceUnavailableException("No providers registered. Please try again later");
+ }
+ } else {
+ throw new ServiceUnavailableException("Couldn't get providers list. Please try again later");
+ }
+ meteringLabelInterface.removeNeutronMeteringLabel(labelUUID);
+ if (instances != null) {
+ for (Object instance : instances) {
+ INeutronMeteringLabelAware service = (INeutronMeteringLabelAware) instance;
+ service.neutronMeteringLabelDeleted(singleton);
+ }
+ }
+ return Response.status(204).build();
}
}
import org.opendaylight.neutron.spi.INeutronLoadBalancerListenerCRUD;
import org.opendaylight.neutron.spi.INeutronLoadBalancerPoolCRUD;
import org.opendaylight.neutron.spi.INeutronLoadBalancerPoolMemberCRUD;
+import org.opendaylight.neutron.spi.INeutronMeteringLabelCRUD;
import org.opendaylight.neutron.spi.INeutronNetworkCRUD;
import org.opendaylight.neutron.spi.INeutronPortCRUD;
import org.opendaylight.neutron.spi.INeutronRouterCRUD;
NeutronLoadBalancerInterface neutronLoadBalancerInterface = new NeutronLoadBalancerInterface();
ServiceRegistration<INeutronLoadBalancerCRUD> neutronLoadBalancerInterfaceRegistration = context.registerService(INeutronLoadBalancerCRUD.class, neutronLoadBalancerInterface, null);
- if(neutronFirewallInterfaceRegistration != null) {
+ if(neutronLoadBalancerInterfaceRegistration != null) {
registrations.add(neutronLoadBalancerInterfaceRegistration);
}
registrations.add(neutronLoadBalancerPoolMemberInterfaceRegistration);
}
+ NeutronMeteringLabelInterface neutronMeteringLabelInterface = new NeutronMeteringLabelInterface();
+ ServiceRegistration<INeutronMeteringLabelCRUD> neutronMeteringLabelInterfaceRegistration = context.registerService(INeutronMeteringLabelCRUD.class, neutronMeteringLabelInterface, null);
+ if(neutronMeteringLabelInterfaceRegistration != null) {
+ registrations.add(neutronMeteringLabelInterfaceRegistration);
+ }
+
}
@Override
--- /dev/null
+/*
+ * Copyright IBM Corporation, 2013. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.neutron.transcriber;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.opendaylight.neutron.spi.INeutronMeteringLabelCRUD;
+import org.opendaylight.neutron.spi.NeutronMeteringLabel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NeutronMeteringLabelInterface implements INeutronMeteringLabelCRUD {
+ private static final Logger logger = LoggerFactory.getLogger(NeutronMeteringLabelInterface.class);
+ private ConcurrentMap<String, NeutronMeteringLabel> meteringLabelDB = new ConcurrentHashMap<String, NeutronMeteringLabel>();
+
+
+
+
+ // this method uses reflection to update an object from it's delta.
+
+ private boolean overwrite(Object target, Object delta) {
+ Method[] methods = target.getClass().getMethods();
+
+ for(Method toMethod: methods){
+ if(toMethod.getDeclaringClass().equals(target.getClass())
+ && toMethod.getName().startsWith("set")){
+
+ String toName = toMethod.getName();
+ String fromName = toName.replace("set", "get");
+
+ try {
+ Method fromMethod = delta.getClass().getMethod(fromName);
+ Object value = fromMethod.invoke(delta, (Object[])null);
+ if(value != null){
+ toMethod.invoke(target, value);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ // IfNBMeteringLabelCRUD methods
+
+ @Override
+ public boolean neutronMeteringLabelExists(String uuid) {
+ return meteringLabelDB.containsKey(uuid);
+ }
+
+ @Override
+ public NeutronMeteringLabel getNeutronMeteringLabel(String uuid) {
+ if (!neutronMeteringLabelExists(uuid)) {
+ return null;
+ }
+ return meteringLabelDB.get(uuid);
+ }
+
+ @Override
+ public List<NeutronMeteringLabel> getAllNeutronMeteringLabels() {
+ Set<NeutronMeteringLabel> allMeteringLabels = new HashSet<NeutronMeteringLabel>();
+ for (Entry<String, NeutronMeteringLabel> entry : meteringLabelDB.entrySet()) {
+ NeutronMeteringLabel meteringLabel = entry.getValue();
+ allMeteringLabels.add(meteringLabel);
+ }
+ logger.debug("Exiting getAllMeteringLabels, Found {} OpenStackMeteringLabels", allMeteringLabels.size());
+ List<NeutronMeteringLabel> ans = new ArrayList<NeutronMeteringLabel>();
+ ans.addAll(allMeteringLabels);
+ return ans;
+ }
+
+ @Override
+ public boolean addNeutronMeteringLabel(NeutronMeteringLabel input) {
+ if (neutronMeteringLabelExists(input.getMeteringLabelUUID())) {
+ return false;
+ }
+ meteringLabelDB.putIfAbsent(input.getMeteringLabelUUID(), input);
+ //TODO: add code to find INeutronMeteringLabelAware services and call newtorkCreated on them
+ return true;
+ }
+
+ @Override
+ public boolean removeNeutronMeteringLabel(String uuid) {
+ if (!neutronMeteringLabelExists(uuid)) {
+ return false;
+ }
+ meteringLabelDB.remove(uuid);
+ //TODO: add code to find INeutronMeteringLabelAware services and call newtorkDeleted on them
+ return true;
+ }
+
+ @Override
+ public boolean updateNeutronMeteringLabel(String uuid, NeutronMeteringLabel delta) {
+ if (!neutronMeteringLabelExists(uuid)) {
+ return false;
+ }
+ NeutronMeteringLabel target = meteringLabelDB.get(uuid);
+ return overwrite(target, delta);
+ }
+
+ @Override
+ public boolean neutronMeteringLabelInUse(String netUUID) {
+ if (!neutronMeteringLabelExists(netUUID)) {
+ return true;
+ }
+ return false;
+ }
+}