Hello Alissa Bonas,
I'd like you to do a code review. Please visit
http://gerrit.ovirt.org/23487
to review the following change.
Change subject: restapi: del storage conn if domain creation fails
......................................................................
restapi: del storage conn if domain creation fails
Delete storage connection if storage domain creation fails
in order not to leave leftovers in db from a failed operation.
Note - the connection will be deleted only if it was created as part
of the domain creation call. If it was created in the past and just
reused with its connection id in the domain creation call, then
it will not be deleted.
Change-Id: I71c689ccdbcd038d1b92629b3e46691be0885321
Bug-Url: https://bugzilla.redhat.com/991470
Signed-off-by: Alissa Bonas <[email protected]>
Signed-off-by: Daniel Erez <[email protected]>
---
M
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendStorageDomainsResource.java
M
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendStorageDomainsResourceTest.java
2 files changed, 26 insertions(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/87/23487/1
diff --git
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendStorageDomainsResource.java
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendStorageDomainsResource.java
index 13ffd3d..50b505c 100644
---
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendStorageDomainsResource.java
+++
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendStorageDomainsResource.java
@@ -76,7 +76,10 @@
}
private Response addDomain(VdcActionType action, StorageDomain model,
StorageDomainStatic entity, Guid hostId, StorageServerConnections connection) {
+ Response response = null;
+ boolean isConnNew = false;
if (connection.getstorage_type().isFileDomain() &&
StringUtils.isEmpty(connection.getid())) {
+ isConnNew = true;
connection.setid(addStorageServerConnection(connection,
hostId));
}
entity.setStorage(connection.getid());
@@ -96,7 +99,16 @@
validateParameters(model, 2, "name");
}
- return performCreate(action, getAddParams(entity, hostId),
ID_RESOLVER);
+ try {
+ response = performCreate(action, getAddParams(entity, hostId),
ID_RESOLVER);
+ } catch (WebFaultException e) {
+ // cleanup of created connection
+ if (isConnNew) {
+ removeStorageServerConnection(connection, hostId);
+ }
+ throw e;
+ }
+ return response;
}
@@ -361,6 +373,12 @@
String.class);
}
+ private String removeStorageServerConnection(StorageServerConnections cnx,
Guid hostId) {
+ return performAction(VdcActionType.RemoveStorageServerConnection,
+ new StorageServerConnectionParametersBase(cnx,
hostId),
+ String.class);
+ }
+
private StorageServerConnections getStorageServerConnection(String id) {
return getEntity(StorageServerConnections.class,
VdcQueryType.GetStorageServerConnectionById,
diff --git
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendStorageDomainsResourceTest.java
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendStorageDomainsResourceTest.java
index 14c5fba..9272f3d 100644
---
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendStorageDomainsResourceTest.java
+++
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendStorageDomainsResourceTest.java
@@ -558,6 +558,13 @@
GUIDS[0].toString(),
false));
+ setUpActionExpectations(VdcActionType.RemoveStorageServerConnection,
+ StorageServerConnectionParametersBase.class,
+ new String[] { },
+ new Object[] { },
+ true,
+ true, null, false);
+
setUpGetEntityExpectations(VdcQueryType.GetExistingStorageDomainList,
GetExistingStorageDomainListParameters.class,
new String[] { "VdsId", "StorageType",
"StorageDomainType", "Path" },
--
To view, visit http://gerrit.ovirt.org/23487
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I71c689ccdbcd038d1b92629b3e46691be0885321
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Daniel Erez <[email protected]>
Gerrit-Reviewer: Alissa Bonas <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches