private void waitOperationDone(Operation operation) { AtomicReference<Operation> operationRef = Atomics.newReference(operation); // wait for the operation to complete if (!retryOperationDonePredicate.apply(operationRef)) { throw new UncheckedTimeoutException("operation did not reach DONE state" + operationRef.get()); } // check if the operation failed if (operationRef.get().getHttpError().isPresent()) { HttpResponse response = operationRef.get().getHttpError().get(); throw new IllegalStateException("operation failed. Http Error Code: " + response.getStatusCode() + " HttpError: " + response.getMessage()); } }
private void waitOperationDone(Operation operation) { AtomicReference<Operation> operationRef = Atomics.newReference(operation); // wait for the operation to complete if (!retryOperationDonePredicate.apply(operationRef)) { throw new UncheckedTimeoutException("operation did not reach DONE state" + operationRef.get()); } // check if the operation failed if (operationRef.get().getHttpError().isPresent()) { HttpResponse response = operationRef.get().getHttpError().get(); throw new IllegalStateException("operation failed. Http Error Code: " + response.getStatusCode() + " HttpError: " + response.getMessage()); } }
MILLISECONDS).apply(operation); if (operation.get().getHttpError().isPresent()) { HttpResponse response = operation.get().getHttpError().get(); logger.warn("delete orphaned firewall %s failed. Http Error Code: %d HttpError: %s", operation.get().getTargetId(), response.getStatusCode(), response.getMessage()); 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());
MILLISECONDS).apply(operation); if (operation.get().getHttpError().isPresent()) { HttpResponse response = operation.get().getHttpError().get(); logger.warn("delete orphaned firewall %s failed. Http Error Code: %d HttpError: %s", operation.get().getTargetId(), response.getStatusCode(), response.getMessage()); 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());
@Override public boolean removeSecurityGroup(String id) { checkNotNull(id, "id"); if (api.getNetworkApiForProject(userProject.get()).get(id) == null) { return false; } ListOptions options = new ListOptions.Builder().filter("network eq .*/" + id); FluentIterable<Firewall> fws = api.getFirewallApiForProject(userProject.get()).list(options).concat(); for (Firewall fw : fws) { AtomicReference<Operation> operation = Atomics.newReference(api.getFirewallApiForProject(userProject.get()) .delete(fw.getName())); retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS).apply(operation); checkState(!operation.get().getHttpError().isPresent(), "Could not delete firewall, operation failed" + operation); } AtomicReference<Operation> operation = Atomics.newReference( api.getNetworkApiForProject(userProject.get()).delete(id)); retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS).apply(operation); checkState(!operation.get().getHttpError().isPresent(), "Could not create network, operation failed" + operation); return true; }
@Override public boolean removeSecurityGroup(String id) { checkNotNull(id, "id"); if (api.getNetworkApiForProject(userProject.get()).get(id) == null) { return false; } ListOptions options = new ListOptions.Builder().filter("network eq .*/" + id); FluentIterable<Firewall> fws = api.getFirewallApiForProject(userProject.get()).list(options).concat(); for (Firewall fw : fws) { AtomicReference<Operation> operation = Atomics.newReference(api.getFirewallApiForProject(userProject.get()) .delete(fw.getName())); retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS).apply(operation); checkState(!operation.get().getHttpError().isPresent(), "Could not delete firewall, operation failed" + operation); } AtomicReference<Operation> operation = Atomics.newReference( api.getNetworkApiForProject(userProject.get()).delete(id)); retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS).apply(operation); checkState(!operation.get().getHttpError().isPresent(), "Could not create network, operation failed" + operation); return true; }
@Override public Network apply(NetworkAndAddressRange input) { checkNotNull(input, "input"); Network nw = api.getNetworkApiForProject(userProject.get()).get(input.getName()); if (nw != null) { return nw; } if (input.getGateway().isPresent()) { AtomicReference<Operation> operation = Atomics.newReference(api.getNetworkApiForProject(userProject .get()).createInIPv4RangeWithGateway(input.getName(), input.getIpV4Range(), input.getGateway().get())); retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS).apply(operation); checkState(!operation.get().getHttpError().isPresent(), "Could not create network, operation failed" + operation); } else { AtomicReference<Operation> operation = Atomics.newReference(api.getNetworkApiForProject(userProject .get()).createInIPv4Range(input.getName(), input.getIpV4Range())); retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS).apply(operation); checkState(!operation.get().getHttpError().isPresent(), "Could not create network, operation failed" + operation); } return checkNotNull(api.getNetworkApiForProject(userProject.get()).get(input.getName()), "no network with name %s was found", input.getName()); } }
@Override public Network apply(NetworkAndAddressRange input) { checkNotNull(input, "input"); Network nw = api.getNetworkApiForProject(userProject.get()).get(input.getName()); if (nw != null) { return nw; } if (input.getGateway().isPresent()) { AtomicReference<Operation> operation = Atomics.newReference(api.getNetworkApiForProject(userProject .get()).createInIPv4RangeWithGateway(input.getName(), input.getIpV4Range(), input.getGateway().get())); retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS).apply(operation); checkState(!operation.get().getHttpError().isPresent(), "Could not create network, operation failed" + operation); } else { AtomicReference<Operation> operation = Atomics.newReference(api.getNetworkApiForProject(userProject .get()).createInIPv4Range(input.getName(), input.getIpV4Range())); retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS).apply(operation); checkState(!operation.get().getHttpError().isPresent(), "Could not create network, operation failed" + operation); } return checkNotNull(api.getNetworkApiForProject(userProject.get()).get(input.getName()), "no network with name %s was found", input.getName()); } }
@Override public SecurityGroup removeIpPermission(IpPermission ipPermission, SecurityGroup group) { checkNotNull(group, "group"); checkNotNull(ipPermission, "ipPermission"); checkNotNull(api.getNetworkApiForProject(userProject.get()).get(group.getId()) == null, "network for group is null"); ListOptions options = new ListOptions.Builder().filter("network eq .*/" + group.getName()); FluentIterable<Firewall> fws = api.getFirewallApiForProject(userProject.get()).list(options).concat(); for (Firewall fw : fws) { if (equalsIpPermission(ipPermission).apply(fw)) { AtomicReference<Operation> operation = Atomics.newReference(api.getFirewallApiForProject(userProject.get()) .delete(fw.getName())); retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS).apply(operation); checkState(!operation.get().getHttpError().isPresent(), "Could not delete firewall, operation failed" + operation); } } return getSecurityGroupById(group.getId()); }
@Override public SecurityGroup removeIpPermission(IpPermission ipPermission, SecurityGroup group) { checkNotNull(group, "group"); checkNotNull(ipPermission, "ipPermission"); checkNotNull(api.getNetworkApiForProject(userProject.get()).get(group.getId()) == null, "network for group is null"); ListOptions options = new ListOptions.Builder().filter("network eq .*/" + group.getName()); FluentIterable<Firewall> fws = api.getFirewallApiForProject(userProject.get()).list(options).concat(); for (Firewall fw : fws) { if (equalsIpPermission(ipPermission).apply(fw)) { AtomicReference<Operation> operation = Atomics.newReference(api.getFirewallApiForProject(userProject.get()) .delete(fw.getName())); retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS).apply(operation); checkState(!operation.get().getHttpError().isPresent(), "Could not delete firewall, operation failed" + operation); } } return getSecurityGroupById(group.getId()); }
public Builder fromOperation(Operation in) { return super.fromResource(in) .targetLink(in.getTargetLink()) .targetId(in.getTargetId().orNull()) .clientOperationId(in.getClientOperationId().orNull()) .status(in.getStatus()) .statusMessage(in.getStatusMessage().orNull()) .user(in.getUser()) .progress(in.getProgress().get()) .insertTime(in.getInsertTime()) .startTime(in.getStartTime().orNull()) .endTime(in.getEndTime().orNull()) .httpErrorStatusCode(in.getHttpError().isPresent() ? in.getHttpError().get().getStatusCode() : null) .httpErrorMessage(in.getHttpError().isPresent() ? in.getHttpError().get().getMessage() : null) .operationType(in.getOperationType()).errors(in.getErrors()) .zone(in.getZone().orNull()).region(in.getRegion().orNull()); } }
public Builder fromOperation(Operation in) { return super.fromResource(in) .targetLink(in.getTargetLink()) .targetId(in.getTargetId().orNull()) .clientOperationId(in.getClientOperationId().orNull()) .status(in.getStatus()) .statusMessage(in.getStatusMessage().orNull()) .user(in.getUser()) .progress(in.getProgress().get()) .insertTime(in.getInsertTime()) .startTime(in.getStartTime().orNull()) .endTime(in.getEndTime().orNull()) .httpErrorStatusCode(in.getHttpError().isPresent() ? in.getHttpError().get().getStatusCode() : null) .httpErrorMessage(in.getHttpError().isPresent() ? in.getHttpError().get().getMessage() : null) .operationType(in.getOperationType()).errors(in.getErrors()) .zone(in.getZone().orNull()).region(in.getRegion().orNull()); } }
retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS).apply(operation); checkState(!operation.get().getHttpError().isPresent(),"Could not create firewall, operation failed" + operation);
retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS).apply(operation); checkState(!operation.get().getHttpError().isPresent(), "Could not create firewall, operation failed" + operation);
MILLISECONDS).apply(operation); checkState(!operation.get().getHttpError().isPresent(), "Could not create firewall, operation failed" + operation);
MILLISECONDS).apply(operation); checkState(!operation.get().getHttpError().isPresent(), "Could not create firewall, operation failed" + operation);