private void removeTags(final String imageId) throws Exception { final ImageInfo image = Images.lookupImage(imageId); final String imageOwnerId = image.getOwnerUserId(); DeleteTagsTask task = new DeleteTagsTask( imageOwnerId, Lists.newArrayList(image.getDisplayName()), Lists.newArrayList(TAG_KEY_STATE, TAG_KEY_MESSAGE)); CheckedListenableFuture<Boolean> result = task.dispatch(); if (result.get()) {; } final List<VmInstance> instances = this.lookupInstances(imageId); for (final VmInstance instance : instances) { final String instanceId = instance.getInstanceId(); final String instanceOwnerId = instance.getOwnerUserId(); try { task = new DeleteTagsTask( instanceOwnerId, Lists.newArrayList(instanceId), Lists.newArrayList(TAG_KEY_STATE, TAG_KEY_MESSAGE)); result = task.dispatch(); if (result.get()) {; } } catch (final Exception ex) {; } } }
private void resetTag( final String userId, final String resourceId, final String tagKey, final String tagValue) throws Exception { /// try deleting tags try { final DeleteTagsTask task = new DeleteTagsTask(userId, Lists.newArrayList(resourceId), Lists.newArrayList(tagKey)); final CheckedListenableFuture<Boolean> result = task.dispatch(); if (result.get()) {; } } catch (final Exception ex) {; } // create tag final Map<String, String> tag = Maps.newHashMap(); tag.put(tagKey, tagValue); final CreateTagsTask task = new CreateTagsTask(userId, Lists.newArrayList(resourceId), tag); final CheckedListenableFuture<Boolean> result = task.dispatch(); if (result.get()) {; } else throw new Exception( String.format("Failed to create tag (%s-%s:%s)", resourceId, tagKey, tagValue)); }