private String parseGroupFrom(final RunningInstance instance, final Set<String> data) { String group = null; try { Predicate<String> containsAnyGroup = namingConvention.create().containsAnyGroup(); String encodedGroup = Iterables.getOnlyElement(Iterables.filter(data, containsAnyGroup)); group = namingConvention.create().extractGroup(encodedGroup); } catch (NoSuchElementException e) { logger.debug("no group parsed from %s's data: %s", instance.getId(), data); } catch (IllegalArgumentException e) { logger.debug( "too many groups match naming convention; %s's data: %s", instance.getId(), data); } return group; }
protected void cleanUpNetworksAndFirewallsForGroup(String groupName) { String resourceName = namingConvention.create().sharedNameForGroup(groupName); AtomicReference<Operation> operation = new AtomicReference<Operation>( api.getFirewallApiForProject(project.get()).delete(resourceName)); retry( operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS) .apply(operation); if (operation.get().getHttpError().isPresent()) { HttpResponse response = operation.get().getHttpError().get(); logger.warn( "delete orphaned firewall failed. Http Error Code: " + response.getStatusCode() + " HttpError: " + response.getMessage()); } operation = new AtomicReference<Operation>( api.getNetworkApiForProject(project.get()).delete(resourceName)); retry( operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS) .apply(operation); if (operation.get().getHttpError().isPresent()) { HttpResponse response = operation.get().getHttpError().get(); logger.warn( "delete orphaned network failed. Http Error Code: " + response.getStatusCode() + " HttpError: " + response.getMessage()); } }
public FirewallTagNamingConvention get(String groupName) { return new FirewallTagNamingConvention( namingConvention.create().sharedNameForGroup(groupName)); }