*/
package org.opendaylight.ovsdb.northbound;
+import java.util.List;
+
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.controller.sal.utils.StatusCode;
+import org.opendaylight.ovsdb.lib.table.internal.Table;
+import org.opendaylight.ovsdb.lib.table.internal.Tables;
import org.opendaylight.ovsdb.plugin.OVSDBConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+ " : Table Name in URL does not match the row name in request body");
}
+ private String getOVSTableName(String tableName) {
+ List<Table> tables = Tables.getTables();
+ for (Table table : tables) {
+ if (table.getTableName().getName().equalsIgnoreCase(tableName)) {
+ return table.getTableName().getName();
+ }
+ }
+ // TODO Auto-generated method stub
+ return null;
+ }
+
/**
* Create a Row
*
throw new UnauthorizedException("User is not authorized to perform this operation");
}
+ String ovsTableName = getOVSTableName(tableName);
+ if (ovsTableName == null) {
+ Status status = new Status(StatusCode.NOTFOUND, "Table "+tableName+" is not currently supported");
+ return NorthboundUtils.getResponse(status);
+ }
+
OVSDBConfigService ovsdbTable = (OVSDBConfigService)ServiceHelper.getGlobalInstance(OVSDBConfigService.class,
this);
if (ovsdbTable == null) {
- throw new ServiceUnavailableException("UserManager " + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("OVS Configuration Service " + RestMessages.SERVICEUNAVAILABLE.toString());
}
if (row != null && row.getRow() != null) {
handleNameMismatch(tableName, row.getRow().getTableName().getName());
Node node = Node.fromString(nodeType, nodeId);
- Status statusWithUUID = ovsdbTable.insertRow(node, tableName, row.getParent_uuid(), row.getRow());
+ Status statusWithUUID = ovsdbTable.insertRow(node, ovsTableName, row.getParent_uuid(), row.getRow());
if (statusWithUUID.isSuccess()) {
return Response.status(Response.Status.CREATED)
return Response.status(Response.Status.BAD_REQUEST).build();
}
+ /**
+ * Read a Row
+ *
+ * @param node OVSDB Node identifier
+ * @param tableName name of the ovsdb table
+ * @param rowUuid UUID of the row being read
+ *
+ * @return Row corresponding to the UUID.
+ *
+ * <pre>
+ * Example:
+ *
+ * Request URL:
+ * https://localhost/controller/nb/v2/ovsdb/tables/bridge/rows/6f4c602c-026f-4390-beea-d50d6d448100
+ * </pre>
+ */
+
+ @Path("/node/{nodeType}/{nodeId}/tables/{tableName}/rows/{rowUuid}")
+ @GET
+ @StatusCodes({ @ResponseCode(code = 200, condition = "Row Updated successfully"),
+ @ResponseCode(code = 400, condition = "Invalid data passed"),
+ @ResponseCode(code = 401, condition = "User not authorized to perform this operation")})
+ @Consumes({ MediaType.APPLICATION_JSON})
+ @TypeHint(String.class)
+ public String getRow(@PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId,
+ @PathParam("tableName") String tableName, @PathParam("rowUuid") String rowUuid) {
+
+ if (!NorthboundUtils.isAuthorized(getUserName(), "default", Privilege.WRITE, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation");
+ }
+
+ String ovsTableName = getOVSTableName(tableName);
+ if (ovsTableName == null) return null;
+
+ OVSDBConfigService ovsdbTable = (OVSDBConfigService)ServiceHelper.getGlobalInstance(OVSDBConfigService.class,
+ this);
+ if (ovsdbTable == null) {
+ throw new ServiceUnavailableException("UserManager " + RestMessages.SERVICEUNAVAILABLE.toString());
+ }
+
+ Node node = Node.fromString(nodeType, nodeId);
+ //Table<?> row = null;
+ String row = null;
+ try {
+ row = ovsdbTable.getRow(node, ovsTableName, rowUuid);
+ } catch (Exception e) {
+ throw new BadRequestException(e.getMessage());
+ }
+ //return new OVSDBRow(null, row);
+ return row;
+ }
+
+ /**
+ * Read all Rows of a table
+ *
+ * @param node OVSDB Node identifier
+ * @param tableName name of the ovsdb table
+ *
+ * @return All the Rows of a table
+ *
+ * <pre>
+ * Example:
+ *
+ * Request URL:
+ * https://localhost/controller/nb/v2/ovsdb/tables/bridge/rows
+ * </pre>
+ */
+
+ @Path("/node/{nodeType}/{nodeId}/tables/{tableName}/rows")
+ @GET
+ @StatusCodes({ @ResponseCode(code = 200, condition = "Row Updated successfully"),
+ @ResponseCode(code = 400, condition = "Invalid data passed"),
+ @ResponseCode(code = 401, condition = "User not authorized to perform this operation")})
+ @Consumes({ MediaType.APPLICATION_JSON})
+ @TypeHint(String.class)
+ public String getAllRows(@PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId,
+ @PathParam("tableName") String tableName) {
+ if (!NorthboundUtils.isAuthorized(getUserName(), "default", Privilege.WRITE, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation");
+ }
+
+ String ovsTableName = getOVSTableName(tableName);
+ if (ovsTableName == null) return null;
+
+ OVSDBConfigService ovsdbTable = (OVSDBConfigService)ServiceHelper.getGlobalInstance(OVSDBConfigService.class,
+ this);
+ if (ovsdbTable == null) {
+ throw new ServiceUnavailableException("UserManager " + RestMessages.SERVICEUNAVAILABLE.toString());
+ }
+
+ Node node = Node.fromString(nodeType, nodeId);
+ //Map<String, Table<?>> rows = null;
+ String rows = null;
+ try {
+ rows = ovsdbTable.getRows(node, ovsTableName);
+ } catch (Exception e) {
+ throw new BadRequestException(e.getMessage());
+ }
+ //return new OVSDBRows(rows);
+ return rows;
+ }
+
/**
* Update a Row
*
* Example:
*
* Request URL:
- * https://localhost/controller/nb/v2/ovsdb/tables/bridge/rows
+ * PUT https://localhost/controller/nb/v2/ovsdb/tables/bridge/rows/6f4c602c-026f-4390-beea-d50d6d448100
+ * BODY
+ * {
+ * "row":{
+ * "Bridge":{
+ * "datapath_type":"OPENFLOWv1.3",
+ * "stp_enable":true
+ * }
+ * }
+ * }
* </pre>
*/
throw new UnauthorizedException("User is not authorized to perform this operation");
}
+ String ovsTableName = getOVSTableName(tableName);
+ if (ovsTableName == null) {
+ Status status = new Status(StatusCode.NOTFOUND, "Table "+tableName+" is not currently supported");
+ return NorthboundUtils.getResponse(status);
+ }
+
OVSDBConfigService ovsdbTable = (OVSDBConfigService)ServiceHelper.getGlobalInstance(OVSDBConfigService.class,
this);
if (ovsdbTable == null) {
if (row != null && row.getRow() != null) {
handleNameMismatch(tableName, row.getRow().getTableName().getName());
Node node = Node.fromString(nodeType, nodeId);
- Status status = ovsdbTable.updateRow(node, rowUuid, row.getRow());
+ Status status = ovsdbTable.updateRow(node, ovsTableName, row.getParent_uuid(), rowUuid, row.getRow());
return NorthboundUtils.getResponse(status);
}
return Response.status(Response.Status.BAD_REQUEST).build();
throw new UnauthorizedException("User is not authorized to perform this operation");
}
+ String ovsTableName = getOVSTableName(tableName);
+ if (ovsTableName == null) {
+ Status status = new Status(StatusCode.NOTFOUND, "Table "+tableName+" is not currently supported");
+ return NorthboundUtils.getResponse(status);
+ }
+
OVSDBConfigService ovsdbTable = (OVSDBConfigService) ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
if (ovsdbTable == null) {
throw new ServiceUnavailableException("UserManager " + RestMessages.SERVICEUNAVAILABLE.toString());
}
Node node = Node.fromString(nodeType, nodeId);
- Status status = ovsdbTable.deleteRow(node, tableName, uuid);
+ Status status = ovsdbTable.deleteRow(node, ovsTableName, uuid);
if (status.isSuccess()) {
return Response.noContent().build();
}
import org.opendaylight.ovsdb.lib.message.operations.MutateOperation;
import org.opendaylight.ovsdb.lib.message.operations.Operation;
import org.opendaylight.ovsdb.lib.message.operations.OperationResult;
+import org.opendaylight.ovsdb.lib.message.operations.UpdateOperation;
import org.opendaylight.ovsdb.lib.notation.Condition;
import org.opendaylight.ovsdb.lib.notation.Function;
import org.opendaylight.ovsdb.lib.notation.Mutation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.util.concurrent.ListenableFuture;
public class ConfigurationService implements IPluginInBridgeDomainConfigService, OVSDBConfigService,
@Override
public Status insertRow(Node node, String tableName, String parent_uuid, Table<?> row) {
- logger.error("tableName : {}, parent_uuid : {} Row : {}", tableName, parent_uuid, row.toString());
+ logger.info("tableName : {}, parent_uuid : {} Row : {}", tableName, parent_uuid, row.toString());
Status statusWithUUID = null;
// Schema based Table handling will help fix this static Table handling.
return statusWithUUID;
}
+
+ @Override
+ public Status updateRow (Node node, String tableName, String parentUUID, String rowUUID, Table<?> row) {
+ try{
+ if (connectionService == null) {
+ logger.error("Couldn't refer to the ConnectionService");
+ return new Status(StatusCode.NOSERVICE);
+ }
+
+ Connection connection = this.getConnection(node);
+ if (connection == null) {
+ return new Status(StatusCode.NOSERVICE, "Connection to ovsdb-server not available");
+ }
+
+ Map<String, Table<?>> ovsTable = inventoryServiceInternal.getTableCache(node, Open_vSwitch.NAME.getName());
+
+ if (ovsTable == null) {
+ return new Status(StatusCode.NOTFOUND, "There are no Open_vSwitch instance in the Open_vSwitch table");
+ }
+
+ UUID uuid = new UUID(rowUUID);
+ Condition condition = new Condition("_uuid", Function.EQUALS, uuid);
+ List<Condition> where = new ArrayList<Condition>();
+ where.add(condition);
+ Operation updateRequest = new UpdateOperation(tableName, where, row);
+
+ TransactBuilder transaction = new TransactBuilder();
+ transaction.addOperations(new ArrayList<Operation>(
+ Arrays.asList(updateRequest)));
+
+ ListenableFuture<List<OperationResult>> transResponse = connection.getRpc().transact(transaction);
+ List<OperationResult> tr = transResponse.get();
+ List<Operation> requests = transaction.getRequests();
+ Status status = new Status(StatusCode.SUCCESS);
+ for (int i = 0; i < tr.size() ; i++) {
+ if (i < requests.size()) requests.get(i).setResult(tr.get(i));
+ if (tr.get(i) != null && tr.get(i).getError() != null && tr.get(i).getError().trim().length() > 0) {
+ OperationResult result = tr.get(i);
+ status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
+ }
+ }
+
+ if (tr.size() > requests.size()) {
+ OperationResult result = tr.get(tr.size()-1);
+ logger.error("Error Updating Row : {}/{}\n Error : {}\n Details : {}", tableName, row,
+ result.getError(),
+ result.getDetails());
+ status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
+ }
+ if (status.isSuccess()) {
+ status = new Status(StatusCode.SUCCESS);
+ }
+ return status;
+ } catch(Exception e){
+ e.printStackTrace();
+ }
+ return new Status(StatusCode.INTERNALERROR);
+ }
+
+ @Override
+ public Status deleteRow(Node node, String tableName, String uuid) {
+ if (tableName.equalsIgnoreCase("Bridge")) {
+ return deleteBridgeRow(node, uuid);
+ }
+ else if (tableName.equalsIgnoreCase("Capbility")) {
+ return deleteCapabilityRow(node, uuid);
+ }
+ else if (tableName.equalsIgnoreCase("Controller")) {
+ return deleteControllerRow(node, uuid);
+ }
+ else if (tableName.equalsIgnoreCase("Interface")) {
+ return deleteInterfaceRow(node, uuid);
+ }
+ else if (tableName.equalsIgnoreCase("Manager")) {
+ return deleteManagerRow(node, uuid);
+ }
+ else if (tableName.equalsIgnoreCase("Mirror")) {
+ return deleteMirrorRow(node, uuid);
+ }
+ else if (tableName.equalsIgnoreCase("NetFlow")) {
+ return deleteNetFlowRow(node, uuid);
+ }
+ else if (tableName.equalsIgnoreCase("Open_vSwitch")) {
+ return deleteOpen_vSwitchRow(node, uuid);
+ }
+ else if (tableName.equalsIgnoreCase("Port")) {
+ return deletePortRow(node, uuid);
+ }
+ else if (tableName.equalsIgnoreCase("QoS")) {
+ return deleteQosRow(node, uuid);
+ }
+ else if (tableName.equalsIgnoreCase("Queue")) {
+ return deleteQueueRow(node, uuid);
+ }
+ else if (tableName.equalsIgnoreCase("sFlow")) {
+ return deleteSflowRow(node, uuid);
+ }
+ else if (tableName.equalsIgnoreCase("SSL")) {
+ return deleteSSLRow(node, uuid);
+ }
+ return new Status(StatusCode.NOTFOUND, "Table "+tableName+" not supported");
+ }
+
+ @Override
+ public String getRows(Node node, String tableName) throws Exception{
+ try{
+ if (inventoryServiceInternal == null) {
+ throw new Exception("Inventory Service is Unavailable.");
+ }
+ Map<String, Table<?>> ovsTable = inventoryServiceInternal.getTableCache(node, tableName);
+ if (ovsTable == null) return null;
+ ObjectMapper mapper = new ObjectMapper();
+ return mapper.writeValueAsString(ovsTable);
+ } catch(Exception e){
+ throw new Exception("Unable to read table due to "+e.getMessage());
+ }
+ }
+
+ @Override
+ public String getRow(Node node, String tableName, String uuid) throws Exception {
+ try{
+ if (inventoryServiceInternal == null) {
+ throw new Exception("Inventory Service is Unavailable.");
+ }
+ Map<String, Table<?>> ovsTable = inventoryServiceInternal.getTableCache(node, tableName);
+ if (ovsTable == null) return null;
+ ObjectMapper mapper = new ObjectMapper();
+ return mapper.writeValueAsString(ovsTable.get(uuid));
+ } catch(Exception e){
+ throw new Exception("Unable to read table due to "+e.getMessage());
+ }
+ }
+
+ @Override
+ public List<String> getTables(Node node) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
private Status insertBridgeRow(Node node, String open_VSwitch_uuid, Bridge bridgeRow) {
try{
if (connectionService == null) {
return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
}
- @Override
- public Status updateRow(Node node, String rowUUID, Table<?> row) {
- return new Status(StatusCode.NOTIMPLEMENTED, "Update Row functionality is not implemented yet.");
+ private Status deleteBridgeRow(Node node, String uuid) {
+
+ try {
+ if (connectionService == null) {
+ logger.error("Couldn't refer to the ConnectionService");
+ return new Status(StatusCode.NOSERVICE);
+ }
+ Connection connection = this.getConnection(node);
+ if (connection == null) {
+ return new Status(StatusCode.NOSERVICE, "Connection to ovsdb-server not available");
+ }
+ Map<String, Table<?>> ovsTable = inventoryServiceInternal.getTableCache(node, Open_vSwitch.NAME.getName());
+ Map<String, Table<?>> brTable = inventoryServiceInternal.getTableCache(node, Bridge.NAME.getName());
+ Operation delBrRequest = null;
+
+ if (ovsTable == null || brTable == null || uuid == null || brTable.get(uuid) == null) {
+ return new Status(StatusCode.NOTFOUND, "");
+ }
+
+ UUID bridgeUuidPair = new UUID(uuid);
+ Mutation bm = new Mutation("bridges", Mutator.DELETE, bridgeUuidPair);
+ List<Mutation> mutations = new ArrayList<Mutation>();
+ mutations.add(bm);
+
+ UUID ovsUuid = new UUID((String) ovsTable.keySet().toArray()[0]);
+ Condition condition = new Condition("_uuid", Function.EQUALS, ovsUuid);
+ List<Condition> where = new ArrayList<Condition>();
+ where.add(condition);
+ delBrRequest = new MutateOperation(Open_vSwitch.NAME.getName(), where, mutations);
+
+ TransactBuilder transaction = new TransactBuilder();
+ transaction.addOperations(new ArrayList<Operation>(Arrays.asList(delBrRequest)));
+
+ ListenableFuture<List<OperationResult>> transResponse = connection.getRpc().transact(transaction);
+ List<OperationResult> tr = transResponse.get();
+ List<Operation> requests = transaction.getRequests();
+ Status status = new Status(StatusCode.SUCCESS);
+ for (int i = 0; i < tr.size(); i++) {
+ if (i < requests.size()) requests.get(i).setResult(tr.get(i));
+ if (tr.get(i) != null && tr.get(i).getError() != null && tr.get(i).getError().trim().length() > 0) {
+ OperationResult result = tr.get(i);
+ status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
+ }
+ }
+
+ if (tr.size() > requests.size()) {
+ OperationResult result = tr.get(tr.size() - 1);
+ logger.error("Error creating Bridge : {}\n Error : {}\n Details : {}",
+ uuid, result.getError(), result.getDetails());
+ status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
+ }
+ return status;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return new Status(StatusCode.INTERNALERROR);
}
- @Override
- public Status deleteRow(Node node, String tableName, String uuid) {
- return new Status(StatusCode.NOTIMPLEMENTED, "Delete Row functionality is not implemented yet.");
+ private Status deletePortRow(Node node, String uuid) {
+ return new Status(StatusCode.INTERNALERROR);
}
- @Override
- public List<Table<?>> getRows(Node node, String tableName) {
- // TODO Auto-generated method stub
- return null;
+ private Status deleteInterfaceRow(Node node, String uuid) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "delete operation for this Table is not implemented yet.");
}
- @Override
- public Table<?> getRow(Node node, String tableName, String uuid) {
- // TODO Auto-generated method stub
- return null;
+ private Status deleteOpen_vSwitchRow(Node node, String uuid) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "delete operation for this Table is not implemented yet.");
}
- @Override
- public List<String> getTables(Node node) {
- // TODO Auto-generated method stub
- return null;
+ private Status deleteControllerRow(Node node, String uuid) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "delete operation for this Table is not implemented yet.");
+ }
+
+ private Status deleteSSLRow(Node node, String uuid) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "delete operation for this Table is not implemented yet.");
+ }
+
+ private Status deleteSflowRow(Node node, String uuid) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "delete operation for this Table is not implemented yet.");
+ }
+
+ private Status deleteQueueRow(Node node, String uuid) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "delete operation for this Table is not implemented yet.");
+ }
+
+ private Status deleteQosRow(Node node, String uuid) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "delete operation for this Table is not implemented yet.");
+ }
+
+ private Status deleteNetFlowRow(Node node, String uuid) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "delete operation for this Table is not implemented yet.");
+ }
+
+ private Status deleteMirrorRow(Node node, String uuid) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "delete operation for this Table is not implemented yet.");
+ }
+
+ private Status deleteManagerRow(Node node, String uuid) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "delete operation for this Table is not implemented yet.");
+ }
+
+ private Status deleteCapabilityRow(Node node, String uuid) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "delete operation for this Table is not implemented yet.");
}
public void _ovsconnect (CommandInterpreter ci) {