@Override public boolean apply(AtomicReference<Operation> input) { checkNotNull(input.get(), "operation"); Operation current = resources.operation(input.get().selfLink()); input.set(current); checkState(current.error().errors().isEmpty(), "Task ended in error %s", current); // ISE will break the loop. switch (current.status()) { case DONE: return true; case PENDING: case RUNNING: default: return false; } } }
private void cleanUpFirewallsForGroup(final String groupName) { GroupNamingConvention namingScheme = namingConvention.create(); FirewallApi firewallApi = api.firewalls(); for (Firewall firewall : concat(firewallApi.list())) { String foundGroup = namingScheme.groupInUniqueNameOrNull(firewall.name()); if ((foundGroup != null) && foundGroup.equals(groupName)){ AtomicReference<Operation> operation = Atomics.newReference(firewallApi.delete(firewall.name())); operationDone.apply(operation); if (operation.get().httpErrorStatusCode() != null) { logger.warn("delete orphaned firewall %s failed. Http Error Code: %d HttpError: %s", operation.get().targetId(), operation.get().httpErrorStatusCode(), operation.get().httpErrorMessage()); } } } }
public Operation build() { return new Operation(super.id, super.creationTimestamp, super.selfLink, super.name, super.description, targetLink, targetId, clientOperationId, status, statusMessage, user, progress, insertTime, startTime, endTime, httpErrorStatusCode, httpErrorMessage, operationType, errors.build(), region, zone); }
private void waitOperationDone(Operation operation) { AtomicReference<Operation> operationRef = Atomics.newReference(operation); // wait for the operation to complete if (!operationDone.apply(operationRef)) { throw new UncheckedTimeoutException("operation did not reach DONE state" + operationRef.get()); } // check if the operation failed if (operationRef.get().httpErrorStatusCode() != null) { throw new IllegalStateException( "operation failed. Http Error Code: " + operationRef.get().httpErrorStatusCode() + " HttpError: " + operationRef.get().httpErrorMessage()); } }
create.targetLink(), // selfLink create.zone(), // zone Map<String, ?> params = ImmutableMap.of("instance", instance, "zone", zone, "email", create.user(), "userName", credentials.getUser()); String password = windowsPasswordGenerator.apply(params); credentials = LoginCredentials.builder(credentials)
protected void assertOperationDoneSuccessfully(Operation operation) { AtomicReference<Operation> ref = Atomics.newReference(checkNotNull(operation, "operation")); checkState(operationDone.apply(ref), "Timeout waiting for operation: %s", operation); assertEquals(ref.get().status(), Operation.Status.DONE); assertTrue(ref.get().error().errors().isEmpty()); }
@Override public Network apply(NetworkAndAddressRange input) { checkNotNull(input, "input"); Network nw = api.networks().get(input.name()); if (nw != null) { return nw; } if (input.gateway() != null) { NetworkCreationOptions options = new NetworkCreationOptions.Builder(input.name(), input.rangeIPv4()) .gatewayIPv4(input.gateway()).build(); AtomicReference<Operation> operation = Atomics.newReference(api.networks() .createInIPv4Range(options)); operationDone.apply(operation); checkState(operation.get().httpErrorStatusCode() == null, "Could not insert network, operation failed" + operation); } else { AtomicReference<Operation> operation = Atomics .newReference(api.networks().createInIPv4Range(input.name(), input.rangeIPv4())); operationDone.apply(operation); checkState(operation.get().httpErrorStatusCode() == null, "Could not insert network, operation failed" + operation); } return checkNotNull(api.networks().get(input.name()), "no network with name %s was found", input.name()); } }
create.targetLink(), // selfLink create.zone(), // zone Map<String, ?> params = ImmutableMap.of("instance", instance, "zone", zone, "email", create.user(), "userName", credentials.getUser()); String password = windowsPasswordGenerator.apply(params); credentials = LoginCredentials.builder(credentials)
private void waitOperationDone(Operation operation) { AtomicReference<Operation> operationRef = Atomics.newReference(operation); // wait for the operation to complete if (!operationDone.apply(operationRef)) { throw new UncheckedTimeoutException("operation did not reach DONE state" + operationRef.get()); } // check if the operation failed if (operationRef.get().httpErrorStatusCode() != null) { throw new IllegalStateException( "operation failed. Http Error Code: " + operationRef.get().httpErrorStatusCode() + " HttpError: " + operationRef.get().httpErrorMessage()); } }
@Test(groups = "live", dependsOnMethods = "getProject") public void testSetUsageExportBucket() { AtomicReference<Operation> o = new AtomicReference<Operation>(api.project().setUsageExportBucket( "unexisting-bucket", "test-")); retry(new Predicate<AtomicReference<Operation>>() { @Override public boolean apply(AtomicReference<Operation> input) { input.set(api.operations().get(input.get().selfLink())); return Status.DONE == input.get().status(); } }, operationDoneTimeout, operationDoneInterval, MILLISECONDS).apply(o); assertEquals(o.get().status(), Status.DONE); assertEquals(o.get().error().errors().get(0).code(), "EXTERNAL_RESOURCE_NOT_FOUND"); } }
checkState(operation.get().httpErrorStatusCode() == null, "Could not insert firewall, operation failed %s", operation);
private void cleanUpFirewallsForGroup(final String groupName) { GroupNamingConvention namingScheme = namingConvention.create(); FirewallApi firewallApi = api.firewalls(); for (Firewall firewall : concat(firewallApi.list())) { String foundGroup = namingScheme.groupInUniqueNameOrNull(firewall.name()); if ((foundGroup != null) && foundGroup.equals(groupName)){ AtomicReference<Operation> operation = Atomics.newReference(firewallApi.delete(firewall.name())); operationDone.apply(operation); if (operation.get().httpErrorStatusCode() != null) { logger.warn("delete orphaned firewall %s failed. Http Error Code: %d HttpError: %s", operation.get().targetId(), operation.get().httpErrorStatusCode(), operation.get().httpErrorMessage()); } } } }
@Override public boolean apply(AtomicReference<Operation> input) { checkNotNull(input.get(), "operation"); Operation current = resources.operation(input.get().selfLink()); input.set(current); checkState(current.error().errors().isEmpty(), "Task ended in error %s", current); // ISE will break the loop. switch (current.status()) { case DONE: return true; case PENDING: case RUNNING: default: return false; } } }
create.targetLink(), // selfLink create.zone(), // zone Map<String, ?> params = ImmutableMap.of("instance", instance, "zone", zone, "email", create.user(), "userName", credentials.getUser()); String password = windowsPasswordGenerator.apply(params); credentials = LoginCredentials.builder(credentials)
private void waitOperationDone(Operation operation) { AtomicReference<Operation> operationRef = Atomics.newReference(operation); // wait for the operation to complete if (!operationDone.apply(operationRef)) { throw new UncheckedTimeoutException("operation did not reach DONE state" + operationRef.get()); } // check if the operation failed if (operationRef.get().httpErrorStatusCode() != null) { throw new IllegalStateException( "operation failed. Http Error Code: " + operationRef.get().httpErrorStatusCode() + " HttpError: " + operationRef.get().httpErrorMessage()); } }
checkState(operation.get().httpErrorStatusCode() == null, "Could not insert firewall, operation failed %s", operation);
public Operation build() { return new Operation(super.id, super.creationTimestamp, super.selfLink, super.name, super.description, targetLink, targetId, clientOperationId, status, statusMessage, user, progress, insertTime, startTime, endTime, httpErrorStatusCode, httpErrorMessage, operationType, errors.build(), region, zone); }
private void cleanUpFirewallsForGroup(final String groupName) { GroupNamingConvention namingScheme = namingConvention.create(); FirewallApi firewallApi = api.firewalls(); for (Firewall firewall : concat(firewallApi.list())) { String foundGroup = namingScheme.groupInUniqueNameOrNull(firewall.name()); if ((foundGroup != null) && foundGroup.equals(groupName)){ AtomicReference<Operation> operation = Atomics.newReference(firewallApi.delete(firewall.name())); operationDone.apply(operation); if (operation.get().httpErrorStatusCode() != null) { logger.warn("delete orphaned firewall %s failed. Http Error Code: %d HttpError: %s", operation.get().targetId(), operation.get().httpErrorStatusCode(), operation.get().httpErrorMessage()); } } } }