Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-97 Handle non-existent items when deleting #134

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@ public static BucketAcl get(Connection connection, String id,
return response.readEntity(BucketAcl.class);
}

}
public static boolean exists(Connection connection, String id,
String namespace) throws EcsManagementClientException {
UriBuilder uri = connection.getUriBuilder()
.segment(OBJECT, BUCKET, id, ACL)
.queryParam(NAMESPACE, namespace);
return connection.existenceQuery(uri, null);
}
}
37 changes: 32 additions & 5 deletions src/main/java/com/emc/ecs/servicebroker/service/EcsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ void initialize() {

CompletableFuture deleteBucket(String id) {
try {
BucketAction.delete(connection, prefix(id), broker.getNamespace());
if (bucketExists(prefix(id))) {
BucketAction.delete(connection, prefix(id), broker.getNamespace());
} else {
logger.info("Bucket {} no longer exists, assume already deleted", prefix(id));
}

return null;
} catch (Exception e) {
Expand All @@ -93,6 +97,11 @@ CompletableFuture deleteBucket(String id) {

CompletableFuture wipeAndDeleteBucket(String id) {
try {
if (!bucketExists(prefix(id))) {
logger.info("Bucket {} no longer exists, assume already deleted", prefix(id));
return null;
}

addUserToBucket(id, broker.getRepositoryUser());

logger.info("Started Wiped of bucket {}", prefix(id));
Expand Down Expand Up @@ -191,6 +200,11 @@ private boolean bucketExists(String id) throws EcsManagementClientException {
broker.getNamespace());
}

private boolean aclExists(String id) throws EcsManagementClientException {
return BucketAclAction.exists(connection, prefix(id),
broker.getNamespace());
}

UserSecretKey createUser(String id) {
try {
logger.info(String.format("Creating user %s", prefix(id)));
Expand Down Expand Up @@ -230,7 +244,11 @@ Boolean userExists(String id) throws ServiceBrokerException {
}

void deleteUser(String id) throws EcsManagementClientException {
ObjectUserAction.delete(connection, prefix(id));
if (userExists(id)) {
ObjectUserAction.delete(connection, prefix(id));
} else {
logger.info("User {} no longer exists, assume already deleted", id);
}
}

void addUserToBucket(String id, String username) {
Expand Down Expand Up @@ -269,6 +287,11 @@ void addUserToBucket(String id, String username,

void removeUserFromBucket(String id, String username)
throws EcsManagementClientException {
if (!aclExists(id)) {
logger.info("ACL {} no longer exists when removing user {}", prefix(id), prefix(username));
return;
}

BucketAcl acl = BucketAclAction.get(connection, prefix(id),
broker.getNamespace());
List<BucketUserAcl> newUserAcl = acl.getAcl().getUserAccessList()
Expand Down Expand Up @@ -468,7 +491,11 @@ Map<String, Object> createNamespace(String id, ServiceDefinitionProxy service,
}

void deleteNamespace(String id) throws EcsManagementClientException {
NamespaceAction.delete(connection, prefix(id));
if (namespaceExists(prefix((id)))) {
NamespaceAction.delete(connection, prefix(id));
} else {
logger.info("Namespace {} no longer exists, assume already deleted", prefix(id));
}
}

/**
Expand All @@ -488,8 +515,8 @@ private void bucketWipeCompleted(BucketWipeResult result, String id) {
// Wipe Succeeded, Attempt Bucket Delete
try {
logger.info("BucketWipe SUCCEEDED, deleted {} objects, Deleting bucket {}", result.getDeletedObjects(), prefix(id));
BucketAction.delete(connection, prefix(id), broker.getNamespace());
} catch (EcsManagementClientException e) {
deleteBucket(id);
} catch (Exception e) {
logger.error("Error deleting bucket "+prefix(id), e);
throw new RuntimeException("Error Deleting Bucket "+prefix(id)+" "+e.getMessage());
}
Expand Down