import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.controller.sal.utils.Status;
import org.opendaylight.controller.affinity.IAffinityManager;
-import org.opendaylight.controller.affinity.AffinityConfig;
-import org.opendaylight.controller.affinity.AffinityGroup;
import org.opendaylight.controller.affinity.AffinityLink;
+import org.opendaylight.controller.affinity.AffinityGroup;
/**
* The class provides Northbound REST APIs to access affinity configuration.
}
throw new InternalServerErrorException(ret.getDescription());
}
-
-
- /**
- * Add an affinity group to the configuration database
- *
- * @param containerName
- * Name of the Container
- * @param affinityGroup
- * Name of the new affinity being added
- * @return Response as dictated by the HTTP Response Status code
- */
-
- @Path("/{containerName}/create/group/{name}")
- @PUT
- @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- @TypeHint(Response.class)
- @StatusCodes({
- @ResponseCode(code = 200, condition = "Operation successful"),
- @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
- @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
- public Response addAffinityGroup(
- @PathParam("containerName") String containerName,
- @PathParam("groupName") String groupName) {
-
- if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
- throw new UnauthorizedException("User is not authorized to perform this operation on container "
- + containerName);
- }
-
- IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
- if (affinityManager == null) {
- throw new ServiceUnavailableException("Affinity Manager "
- + RestMessages.SERVICEUNAVAILABLE.toString());
- }
-
- AffinityGroup ag = new AffinityGroup(groupName);
- Status ret = affinityManager.addAffinityGroup(ag);
- if (ret.isSuccess()) {
- return Response.status(Response.Status.CREATED).build();
- }
- throw new InternalServerErrorException(ret.getDescription());
- }
-
- /**
- * Add an element to an affinity group.
- *
- * @param containerName
- * Name of the Container
- * @param affinityGroup
- * Name of the group
- * @param address
- * IP or Mac address of the
- * @return Response as dictated by the HTTP Response Status code
- */
-
- @Path("/{containerName}/{groupname}/add/ip/{address}")
- @PUT
- @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- @TypeHint(Response.class)
- @StatusCodes({
- @ResponseCode(code = 200, condition = "Operation successful"),
- @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
- @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
- public Response addIpAddress(
- @PathParam("containerName") String containerName,
- @PathParam("groupName") String groupName,
- @PathParam("address") String ipaddress) {
-
- IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
- if (affinityManager == null) {
- throw new ServiceUnavailableException("Affinity Manager "
- + RestMessages.SERVICEUNAVAILABLE.toString());
- }
-
- AffinityGroup ag = affinityManager.getGroup(groupName);
- Status ret = ag.addAffinityElement(ipaddress);
-
- if (ret.isSuccess()) {
- return Response.status(Response.Status.CREATED).build();
- }
- throw new InternalServerErrorException(ret.getDescription());
- }
-
-
- /**
- * Delete an element from an affinity group.
- *
- * @param containerName
- * Name of the Container
- * @param affinityGroup
- * Name of the group
- * @param address
- * IP or Mac address of the
- * @return Response as dictated by the HTTP Response Status code
- */
-
- @Path("/{containerName}/{groupname}/delete/ip/{address}")
- @PUT
- @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- @TypeHint(Response.class)
- @StatusCodes({
- @ResponseCode(code = 200, condition = "Operation successful"),
- @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
- @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
- public Response deleteIpAddress(
- @PathParam("containerName") String containerName,
- @PathParam("groupName") String groupName,
- @PathParam("address") String ipaddress) {
-
- IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
- if (affinityManager == null) {
- throw new ServiceUnavailableException("Affinity Manager "
- + RestMessages.SERVICEUNAVAILABLE.toString());
- }
-
- AffinityGroup ag = affinityManager.getGroup(groupName);
- Status ret = ag.removeAffinityElement(ipaddress);
-
- if (ret.isSuccess()) {
- return Response.status(Response.Status.CREATED).build();
- }
- throw new InternalServerErrorException(ret.getDescription());
- }
-
-
-
- /**
- * Add an affinity link to the database and set its from/to groups.
- *
- * @param containerName
- * Name of the Container
- * @param affinityLink
- * Name of the affinity link
- * @param group1
- * Name of the affinity group
- * @param group2
- * Name of the affinity group
- * @return Response as dictated by the HTTP Response Status code
- */
-
- @Path("/{containerName}/create/link/{linkName}/from/{group1}/to/{group2}")
- @PUT
- @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- @TypeHint(Response.class)
- @StatusCodes({
- @ResponseCode(code = 200, condition = "Operation successful"),
- @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
- @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
- public Response addAffinityLink(
- @PathParam("containerName") String containerName,
- @PathParam("linkName") String linkName,
- @PathParam("group1") String group1,
- @PathParam("group2") String group2) {
- IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
- if (affinityManager == null) {
- throw new ServiceUnavailableException("Affinity Manager "
- + RestMessages.SERVICEUNAVAILABLE.toString());
- }
-
- /* Add the new link object. */
- AffinityLink al = new AffinityLink(linkName);
- Status ret = affinityManager.addAffinityLink(al);
- if (!ret.isSuccess()) {
- throw new InternalServerErrorException(ret.getDescription());
- }
- AffinityGroup ag1 = affinityManager.getAffinityGroup(ag1);
- AffinityGroup ag2 = affinityManager.getAffinityGroup(ag2);
-
- al.setFromGroup(ag1);
- al.setToGroup(ag2);
-
- return Response.status(Response.Status.CREATED).build();
- }
}
-