Maor Lipchuk has uploaded a new change for review.
Change subject: restapi:Fix CRUD operations for iSCSI Storage connection.
......................................................................
restapi:Fix CRUD operations for iSCSI Storage connection.
1) renaming class BackendIscsiBondStorageServerConnection to
BackendIscsiBondStorageConnectionResource to be compatible with the
plural resource name
2) Fix remove and get operations for Storage Connection in IscsiBond
3) Adding appropriate tests for resource commands in REST.
Usages:
Get a list of Storage Connections contained in the iSCSI bond:
Get
/api/datacenters/{datacenter_id}/iscsibonds/{iscsibond_id}/storageconnections/
Get a specific Storage Connection in the iSCSI bond:
Get
/api/datacenters/{datacenter_id}/iscsibonds/{iscsibond_id}/storageconnections/{storage_id}/
Adding a new Storage Connection to an existing iSCSI Bond:
POST /api/datacenters/{datacenter_id}/iscsibonds HTTP/1.1
Accept: application/xml
<storage_connection id="{connection_id}"></storage_connection>
Remove a Storage Connection from the existing iSCSi Bond:
DELETE
/api/datacenters/{datacenter_id}/iscsibonds/{iscsibond_id}/storageconnections/{storage_id}/
HTTP/1.1
Change-Id: I2424067b4371b6a99f61ea687155c4082855aff5
Bug-Url: https://bugzilla.redhat.com/1133896
Signed-off-by: Maor Lipchuk <[email protected]>
---
A
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageConnectionResource.java
M
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageConnectionsResource.java
D
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageServerConnection.java
A
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageConnectionResourceTest.java
A
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageConnectionsResourceTest.java
5 files changed, 288 insertions(+), 30 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/29/32129/1
diff --git
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageConnectionResource.java
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageConnectionResource.java
new file mode 100644
index 0000000..cf4e562
--- /dev/null
+++
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageConnectionResource.java
@@ -0,0 +1,36 @@
+package org.ovirt.engine.api.restapi.resource;
+
+import org.ovirt.engine.api.model.StorageConnection;
+import org.ovirt.engine.core.common.businessentities.IscsiBond;
+import org.ovirt.engine.core.common.businessentities.StorageServerConnections;
+import
org.ovirt.engine.core.common.queries.StorageServerConnectionQueryParametersBase;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
+
+public class BackendIscsiBondStorageConnectionResource extends
BackendStorageServerConnectionResource {
+
+ private BackendIscsiBondStorageConnectionsResource parent;
+
+ public BackendIscsiBondStorageConnectionResource(String id,
BackendIscsiBondStorageConnectionsResource parent) {
+ super(id, parent);
+ this.parent = parent;
+ }
+
+ @Override
+ public StorageConnection get() {
+ IscsiBond iscsiBond = parent.getIscsiBond();
+ if (!iscsiBond.getStorageConnectionIds().contains(guid.toString())) {
+ return notFound();
+ }
+
+ StorageServerConnections entity =
+
getEntity(org.ovirt.engine.core.common.businessentities.StorageServerConnections.class,
+ VdcQueryType.GetStorageServerConnectionById,
+ new StorageServerConnectionQueryParametersBase(guid),
+ guid.toString());
+
+ if (entity == null) {
+ return notFound();
+ }
+ return addLinks(map(entity));
+ }
+}
diff --git
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageConnectionsResource.java
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageConnectionsResource.java
index 11344ab..d1a2465 100644
---
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageConnectionsResource.java
+++
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageConnectionsResource.java
@@ -4,7 +4,6 @@
import javax.ws.rs.core.Response;
-import org.ovirt.engine.api.model.Host;
import org.ovirt.engine.api.model.StorageConnection;
import org.ovirt.engine.api.model.StorageConnections;
import org.ovirt.engine.api.resource.StorageServerConnectionResource;
@@ -43,18 +42,8 @@
}
@Override
- public Response remove(String id, Host host) {
- // TODO should return BadRequest error
- return null;
- }
-
- public Response remove(String id) {
- return performRemove(id);
- }
-
- @Override
public StorageServerConnectionResource
getStorageConnectionSubResource(String id) {
- return inject(new BackendIscsiBondStorageServerConnection(id, this));
+ return inject(new BackendIscsiBondStorageConnectionResource(id, this));
}
@Override
@@ -64,7 +53,7 @@
return performAction(VdcActionType.EditIscsiBond, new
EditIscsiBondParameters(iscsiBond));
}
- private IscsiBond getIscsiBond() {
+ protected IscsiBond getIscsiBond() {
return getEntity(IscsiBond.class, VdcQueryType.GetIscsiBondById, new
IdQueryParameters(iscsiBondId), iscsiBondId.toString());
}
diff --git
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageServerConnection.java
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageServerConnection.java
deleted file mode 100644
index a61c329..0000000
---
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageServerConnection.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.ovirt.engine.api.restapi.resource;
-
-import org.ovirt.engine.api.model.StorageConnection;
-import
org.ovirt.engine.core.common.queries.StorageServerConnectionQueryParametersBase;
-import org.ovirt.engine.core.common.queries.VdcQueryType;
-
-public class BackendIscsiBondStorageServerConnection extends
BackendStorageServerConnectionResource {
-
- public BackendIscsiBondStorageServerConnection(String id,
BackendStorageServerConnectionsResource parent) {
- super(id, parent);
- }
-
- @Override
- public StorageConnection get() {
- return
performGet(VdcQueryType.GetStorageServerConnectionByIscsiBondId, new
StorageServerConnectionQueryParametersBase(guid.toString()));
- }
-}
diff --git
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageConnectionResourceTest.java
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageConnectionResourceTest.java
new file mode 100644
index 0000000..519f54f
--- /dev/null
+++
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageConnectionResourceTest.java
@@ -0,0 +1,115 @@
+package org.ovirt.engine.api.restapi.resource;
+
+import javax.ws.rs.WebApplicationException;
+
+import org.junit.Test;
+import org.ovirt.engine.api.model.StorageConnection;
+import org.ovirt.engine.core.common.businessentities.IscsiBond;
+import org.ovirt.engine.core.common.businessentities.StorageServerConnections;
+import org.ovirt.engine.core.common.queries.IdQueryParameters;
+import
org.ovirt.engine.core.common.queries.StorageServerConnectionQueryParametersBase;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
+import org.ovirt.engine.core.compat.Guid;
+
+public class BackendIscsiBondStorageConnectionResourceTest extends
AbstractBackendSubResourceTest<StorageConnection, StorageServerConnections,
BackendIscsiBondStorageConnectionResource> {
+
+ protected static final Guid ISCSI_BOND_ID = GUIDS[1];
+ protected static final Guid STORAGE_CONNECTION_ID = GUIDS[2];
+
+ @Override
+ protected void init() {
+ super.init();
+ initResource(resource.getParent());
+ }
+
+ public BackendIscsiBondStorageConnectionResourceTest() {
+ super(new
BackendIscsiBondStorageConnectionResource(STORAGE_CONNECTION_ID.toString(),
+ new
BackendIscsiBondStorageConnectionsResource(ISCSI_BOND_ID.toString())));
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ setUriInfo(setUpBasicUriExpectations());
+ setUpEntityQueryExpectations(1,
getIscsiBondContainingStorageConnection());
+
+
setUpEntityQueryExpectations(VdcQueryType.GetStorageServerConnectionById,
+ StorageServerConnectionQueryParametersBase.class,
+ new String[] { "ServerConnectionId" },
+ new Object[] { STORAGE_CONNECTION_ID.toString() },
+ getEntity(0));
+
+ control.replay();
+
+ StorageConnection model = resource.get();
+ assertEquals(GUIDS[0].toString(), model.getId());
+ verifyLinks(model);
+ }
+
+ @Test
+ public void testGetWithInvalidStorageId() throws Exception {
+ setUriInfo(setUpBasicUriExpectations());
+ setUpEntityQueryExpectations(1, getIscsiBondWithNoMatchingStorages());
+ control.replay();
+
+ try {
+ resource.get();
+ fail("expected WebApplicationException");
+ } catch (WebApplicationException wae) {
+ verifyNotFoundException(wae);
+ }
+ }
+
+ @Test
+ public void testGetStorageConnectionNotFound() throws Exception {
+ setUriInfo(setUpBasicUriExpectations());
+ setUpEntityQueryExpectations(1,
getIscsiBondContainingStorageConnection());
+
+
setUpEntityQueryExpectations(VdcQueryType.GetStorageServerConnectionById,
+ StorageServerConnectionQueryParametersBase.class,
+ new String[] { "ServerConnectionId" },
+ new Object[] { STORAGE_CONNECTION_ID.toString() },
+ null);
+ control.replay();
+
+ try {
+ resource.get();
+ fail("expected WebApplicationException");
+ } catch (WebApplicationException wae) {
+ verifyNotFoundException(wae);
+ }
+ }
+
+ protected void setUpEntityQueryExpectations(int times, IscsiBond
iscsiBond) throws Exception {
+ while (times-- > 0) {
+ setUpEntityQueryExpectations(VdcQueryType.GetIscsiBondById,
+ IdQueryParameters.class,
+ new String[] { "Id" },
+ new Object[] { ISCSI_BOND_ID },
+ iscsiBond);
+ }
+ }
+
+ private org.ovirt.engine.core.common.businessentities.IscsiBond
getIscsiBondContainingStorageConnection() {
+ org.ovirt.engine.core.common.businessentities.IscsiBond iscsiBond =
+ new org.ovirt.engine.core.common.businessentities.IscsiBond();
+ iscsiBond.setId(ISCSI_BOND_ID);
+
iscsiBond.getStorageConnectionIds().add(STORAGE_CONNECTION_ID.toString());
+ return iscsiBond;
+ }
+
+ private org.ovirt.engine.core.common.businessentities.IscsiBond
getIscsiBondWithNoMatchingStorages() {
+ org.ovirt.engine.core.common.businessentities.IscsiBond iscsiBond =
+ new org.ovirt.engine.core.common.businessentities.IscsiBond();
+ iscsiBond.setId(ISCSI_BOND_ID);
+ iscsiBond.getStorageConnectionIds().add(GUIDS[0].toString());
+ return iscsiBond;
+ }
+
+ @Override
+ protected StorageServerConnections getEntity(int index) {
+ StorageServerConnections cnx = new StorageServerConnections();
+ cnx.setid(GUIDS[index].toString());
+ cnx.setconnection("10.11.12.13" + ":" + "/1");
+ return cnx;
+ }
+}
diff --git
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageConnectionsResourceTest.java
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageConnectionsResourceTest.java
new file mode 100644
index 0000000..8acad7e
--- /dev/null
+++
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendIscsiBondStorageConnectionsResourceTest.java
@@ -0,0 +1,135 @@
+package org.ovirt.engine.api.restapi.resource;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+import org.ovirt.engine.api.model.StorageConnection;
+import org.ovirt.engine.core.common.action.EditIscsiBondParameters;
+import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.businessentities.StorageServerConnections;
+import org.ovirt.engine.core.common.queries.IdQueryParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
+import org.ovirt.engine.core.compat.Guid;
+
+public class BackendIscsiBondStorageConnectionsResourceTest
+ extends AbstractBackendCollectionResourceTest<StorageConnection,
org.ovirt.engine.core.common.businessentities.StorageServerConnections,
BackendStorageServerConnectionsResource> {
+
+ protected static final Guid ISCSI_BOND_ID = GUIDS[1];
+ protected static final Guid STORAGE_CONNECTION_ID = GUIDS[2];
+
+ public BackendIscsiBondStorageConnectionsResourceTest() {
+ super(new
BackendIscsiBondStorageConnectionsResource(ISCSI_BOND_ID.toString()), null, "");
+ }
+
+ @Override
+ protected List<StorageConnection> getCollection() {
+ return collection.list().getStorageConnections();
+ }
+
+ @Override
+ protected StorageServerConnections getEntity(int index) {
+ StorageServerConnections cnx = new StorageServerConnections();
+ cnx.setid(GUIDS[index].toString());
+ cnx.setconnection("10.11.12.13" + ":" + "/1");
+ return cnx;
+ }
+
+ protected StorageConnection getDummyStorageConnection() {
+ StorageConnection cnx = new StorageConnection();
+ cnx.setId(STORAGE_CONNECTION_ID.toString());
+ return cnx;
+ }
+
+ @Test
+ public void testAddStorageConnectionToIscsiBond() throws Exception {
+ setUriInfo(setUpBasicUriExpectations());
+
+ setUpGetEntityExpectations(VdcQueryType.GetIscsiBondById,
+ IdQueryParameters.class,
+ new String[] { "Id" },
+ new Object[] { ISCSI_BOND_ID },
+ getIscsiBond());
+
+ setUpActionExpectations(VdcActionType.EditIscsiBond,
+ EditIscsiBondParameters.class,
+ new String[] { "IscsiBond" },
+ new Object[] { getIscsiBondContainingStorageConnection() },
+ true,
+ true,
+ null);
+
+ Response response = collection.add(getDummyStorageConnection());
+ assertEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void testRemove() throws Exception {
+ setUriInfo(setUpBasicUriExpectations());
+ StorageConnection storageConnection = new StorageConnection();
+ storageConnection.setId(STORAGE_CONNECTION_ID.toString());
+
+ setUpGetEntityExpectations(VdcQueryType.GetIscsiBondById,
+ IdQueryParameters.class,
+ new String[] { "Id" },
+ new Object[] { ISCSI_BOND_ID },
+ getIscsiBondContainingStorageConnection());
+
+ setUpActionExpectations(VdcActionType.EditIscsiBond,
+ EditIscsiBondParameters.class,
+ new String[] { "IscsiBond" },
+ new Object[] { getIscsiBond() },
+ true,
+ true,
+ null);
+
+ Response response =
collection.performRemove(storageConnection.getId());
+ assertEquals(200, response.getStatus());
+ }
+
+ @Override
+ protected void setUpQueryExpectations(String query, Object failure) throws
Exception {
+
setUpEntityQueryExpectations(VdcQueryType.GetStorageServerConnectionByIscsiBondId,
+ IdQueryParameters.class,
+ new String[] { "Id" },
+ new Object[] { ISCSI_BOND_ID },
+ setUpStorageConnections(),
+ failure);
+ control.replay();
+ }
+
+ protected List<StorageServerConnections> setUpStorageConnections() {
+ List<StorageServerConnections> storageConnections = new ArrayList<>();
+ for (int i = 0; i < NAMES.length; i++) {
+ storageConnections.add(getEntity(i));
+ }
+ return storageConnections;
+ }
+
+ /**
+ * There is no name and description in StorageConnection, that is why the
method is overridden
+ */
+ @Override
+ protected void verifyModel(StorageConnection model, int index) {
+ assertEquals(GUIDS[index].toString(), model.getId());
+ verifyLinks(model);
+ }
+
+ private org.ovirt.engine.core.common.businessentities.IscsiBond
getIscsiBond() {
+ org.ovirt.engine.core.common.businessentities.IscsiBond iscsiBond =
+ new org.ovirt.engine.core.common.businessentities.IscsiBond();
+ iscsiBond.setId(ISCSI_BOND_ID);
+ return iscsiBond;
+ }
+
+ private org.ovirt.engine.core.common.businessentities.IscsiBond
getIscsiBondContainingStorageConnection() {
+ org.ovirt.engine.core.common.businessentities.IscsiBond iscsiBond =
+ new org.ovirt.engine.core.common.businessentities.IscsiBond();
+ iscsiBond.setId(ISCSI_BOND_ID);
+
iscsiBond.getStorageConnectionIds().add(STORAGE_CONNECTION_ID.toString());
+ return iscsiBond;
+ }
+
+}
--
To view, visit http://gerrit.ovirt.org/32129
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2424067b4371b6a99f61ea687155c4082855aff5
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.4
Gerrit-Owner: Maor Lipchuk <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches