@Override public void deleteAllAttributes(String itemName) { if (!initialised) { throw new IllegalStateException("The optimistic persister has not been initialised"); } logger.log("About to delete all attributes from simpledb item: " + itemName); DeleteAttributesRequest deleteAttributesRequest = new DeleteAttributesRequest( simpleDbDomainName, itemName); AmazonSimpleDB client = getSimpleDBClient(); client.deleteAttributes(deleteAttributesRequest); logger.log("Deleted all attributes from simpledb item."); }
@Test public void delete() { CassandraInstance instance = createMock(CassandraInstance.class); Capture<DeleteAttributesRequest> requestCapture = new Capture<DeleteAttributesRequest>(); expect(domainFactory.createFromRing(RING_NAME)).andReturn(domain(RING_NAME)); expect(instance.getId()).andReturn(ID).times(2); expect(instance.getDataCenter()).andReturn(DATACENTER); expect(instance.getRack()).andReturn(RACK); expect(instance.getHostName()).andReturn(HOSTNAME); expect(instance.getPublicIpAddress()).andReturn(PUBLIC_IP_ADDRESS); expect(instance.getFullyQualifiedDomainName()).andReturn(FULLY_QUALIFIED_DOMAIN_NAME); simpleDbClient.deleteAttributes(capture(requestCapture)); replayAll(); dao.delete(RING_NAME, instance); DeleteAttributesRequest request = requestCapture.getValue(); assertEquals(DOMAIN, request.getDomainName()); assertEquals(String.valueOf(ID), request.getItemName()); assertAttributes(request); }
private static void assertAttributes(DeleteAttributesRequest request) { assertEquals(6, request.getAttributes().size()); for (Attribute attr : request.getAttributes()) { if (attr.getName().equals(SdbCassandraInstanceDao.ID_KEY)) { assertEquals(String.valueOf(ID), attr.getValue()); } else if (attr.getName().equals(SdbCassandraInstanceDao.DATACENTER_KEY)) { assertEquals(DATACENTER, attr.getValue()); } else if (attr.getName().equals(SdbCassandraInstanceDao.RACK_KEY)) { assertEquals(RACK, attr.getValue()); } else if (attr.getName().equals(SdbCassandraInstanceDao.HOSTNAME_KEY)) { assertEquals(HOSTNAME, attr.getValue()); } else if (attr.getName().endsWith(SdbCassandraInstanceDao.PUBLIC_IP_ADDRESS_KEY)) { assertEquals(PUBLIC_IP_ADDRESS, attr.getValue()); } else if (attr.getName().endsWith(SdbCassandraInstanceDao.FULLY_QUALIFIED_DOMAIN_NAME_KEY)) { assertEquals(FULLY_QUALIFIED_DOMAIN_NAME, attr.getValue()); } else { assertDuplicateAttribute(attr.getName(), attr.getValue()); } } }
public void testDeleteAllAttributesCorrectlyCallsTheDatabase() throws Exception { // ARRANGE initialiseOptimisticPersister(); DeleteAttributesRequest deleteAttributesRequest = new DeleteAttributesRequest( testSimpleDBDomainName, testItemName); mockery.checking(new Expectations() { { oneOf(mockSimpleDBClient).deleteAttributes(with(equal(deleteAttributesRequest))); } }); // ACT optimisticPersister.deleteAllAttributes(testItemName); }
public void execute() { DeleteAttributesRequest request = new DeleteAttributesRequest() .withDomainName(determineDomainName()) .withItemName(determineItemName()) .withExpected(determineUpdateCondition()) .withAttributes(determineAttributes()); log.trace("Sending request [{}] for exchange [{}]...", request, exchange); this.sdbClient.deleteAttributes(request); log.trace("Request sent"); }
@Override public DeleteAttributesResult deleteAttributes(DeleteAttributesRequest deleteAttributesRequest) throws AmazonServiceException, AmazonClientException { this.deleteAttributesRequest = deleteAttributesRequest; String domainName = deleteAttributesRequest.getDomainName(); if ("MissingDomain".equals(domainName)) { throw new NoSuchDomainException(domainName); } return new DeleteAttributesResult(); }
public <T> void delete(String recordid, Class<T> dataClass) throws WPBIOException { try { DeleteAttributesRequest deleteAttributesRequest = new DeleteAttributesRequest(domainName, createInternalKey(recordid, dataClass)); sdbClient.deleteAttributes(deleteAttributesRequest); } catch (Exception e) { throw new WPBIOException("Cannot delete record " + recordid, e); } }
/** * {@inheritDoc} */ @Override public String remove(final Object key) { final String before = this.get(key); this.credentials.aws().deleteAttributes( new DeleteAttributesRequest() .withDomainName(this.table) .withItemName(this.label) .withAttributes(new Attribute().withName(key.toString())) ); return before; }
/** * {@inheritDoc} */ @Override public void clear() { this.credentials.aws().deleteAttributes( new DeleteAttributesRequest() .withDomainName(this.table) .withItemName(this.label) ); }
@Override public void deleteAttributesImpl(String domainName, String itemName) { LOGGER.debug("Delete Domain\"{}\" ItemName \"{}\"", domainName, itemName); Assert.notNull(domainName, "Domain name should not be null"); Assert.notNull(itemName, "Item name should not be null"); getDB().deleteAttributes(new DeleteAttributesRequest(domainName, itemName)); }
@Override public void delete(String itemName, Attribute attribute) throws Exception { if (!initialised) { throw new IllegalStateException("The optimistic persister has not been initialised"); } logger.log("About to delete attribute from simpledb item: " + itemName); AmazonSimpleDB client = getSimpleDBClient(); // We retry the delete if necessary if we get a // ConditionalCheckFailed exception, i.e. if someone else modifies the // database between us reading and writing it. RetryHelper .DoWithRetries(() -> { try { // Get existing attributes (and version number), via consistent // read: ImmutablePair<Optional<Integer>, Set<Attribute>> versionedAttributes = get(itemName); if (!versionedAttributes.left.isPresent()) { logger .log("A version number attribute did not exist - this means no attributes exist, so we have nothing to delete."); return null; } if (!versionedAttributes.right.contains(attribute)) { logger.log("The attribute did not exist - so we have nothing to delete."); return null; } // Since it seems impossible to update the version number while // deleting an attribute, we first mark the attribute as inactive, // and then delete it. ReplaceableAttribute inactiveAttribute = new ReplaceableAttribute(); inactiveAttribute.setName(attribute.getName()); inactiveAttribute.setValue("Inactive" + attribute.getValue()); inactiveAttribute.setReplace(true); put(itemName, versionedAttributes.left, inactiveAttribute); // Now we can safely delete the attribute, as other readers will now // ignore it. UpdateCondition updateCondition = new UpdateCondition(); updateCondition.setName(inactiveAttribute.getName()); updateCondition.setValue(inactiveAttribute.getValue()); // Update will proceed unless the attribute no longer exists updateCondition.setExists(true); Attribute attributeToDelete = new Attribute(); attributeToDelete.setName(inactiveAttribute.getName()); attributeToDelete.setValue(inactiveAttribute.getValue()); List<Attribute> attributesToDelete = new ArrayList<>(); attributesToDelete.add(attributeToDelete); DeleteAttributesRequest simpleDBDeleteRequest = new DeleteAttributesRequest( simpleDbDomainName, itemName, attributesToDelete, updateCondition); client.deleteAttributes(simpleDBDeleteRequest); logger.log("Deleted attribute from simpledb"); return null; } catch (AmazonServiceException ase) { if (ase.getErrorCode().contains("AttributeDoesNotExist")) { // Case of trying to delete an attribute that no longer exists - // that's ok - it probably just means more than one person was // trying to delete the attribute at once. So swallow this // exception logger .log("Caught AmazonServiceException for AttributeDoesNotExist whilst deleting attribute so" + " swallowing and continuing"); return null; } else { throw ase; } } }, Exception.class, Optional.of("Database put failed - conditional check failed"), logger); }
@Override public void deleteUser(User user,Map<String,Object> request) throws ProvisioningException { int approvalID = 0; if (request.containsKey("APPROVAL_ID")) { approvalID = (Integer) request.get("APPROVAL_ID"); } Workflow workflow = (Workflow) request.get("WORKFLOW"); String userid = user.getAttribs().get(this.uidAttrName).getValues().get(0); this.sdb.deleteAttributes(new DeleteAttributesRequest(this.userDomain,userid)); this.cfgMgr.getProvisioningEngine().logAction(this.name,true, ActionType.Delete, approvalID, workflow, "userName",userid); try { Thread.sleep(1000); } catch (InterruptedException e) { } }
public static void deleteItemAttribute(String domainName, String itemName, String attributeName) { getInstance().deleteAttributes(new DeleteAttributesRequest(domainName, itemName) .withAttributes(new Attribute[]{new Attribute().withName(attributeName)})); }
@Override public void delete(String ring, CassandraInstance instance) { DeleteAttributesRequest request = new DeleteAttributesRequest( domain(ring), String.valueOf(instance.getId()), buildDeleteAttributes(instance)); client.deleteAttributes(request); }
/** * Delete an item * * @param domainName table name * @param itemName itemName for the item */ public static void deleteItem(String domainName, String itemName) { getInstance().deleteAttributes(new DeleteAttributesRequest(domainName, itemName)); }