Refine search
private DeferredResult<Operation> patchContainerState(ContainerState cs) { Operation operation = Operation.createPatch(host, UriUtils.buildUriPath(cs.documentSelfLink)) .setBody(cs) .setReferer(host.getUri()) .setCompletion((o, ex) -> { if (ex != null) { logger.warning(String.format("Error patching container state [%s]. Error: [%s]", cs.documentSelfLink, ex.getMessage())); } }); return host.sendWithDeferredResult(operation); } }
/** * Creates an operation with ServiceStateMapUpdateRequest for updating customProperties.__endpointLink * in ResourceGroupStates and AuthCredentialsServiceState */ private Operation createResourceGroupEndpointLinkPatchOp(String documentLink, String endpointLink) { Map<Object, Object> customProperty = new HashMap<>(); customProperty.put(CUSTOM_PROP_ENDPOINT_LINK, endpointLink); Map<String, Map<Object, Object>> entriesToAdd = new HashMap<>(); entriesToAdd.put(ResourceGroupState.FIELD_NAME_CUSTOM_PROPERTIES, customProperty); ServiceStateMapUpdateRequest request = ServiceStateMapUpdateRequest.create(entriesToAdd, null); return Operation.createPatch(this.getHost(), documentLink) .setReferer(this.getUri()) .setBody(request); }
private Operation createDeleteOperationForAutogeneratedResource(String documentLink) { return Operation.createDelete(this, documentLink) .setReferer(getUri()) .setCompletion((o, e) -> { if (e != null) { logWarning("Could not delete auto-generated resource %s: %s", documentLink, Utils.toString(e)); // do not fail the compute removal task } else { logFine("Successfully deleted auto-generated resource %s", documentLink); } }); }
public void requestNetworkInspection(ContainerNetworkState networkState) { AdapterRequest request = new AdapterRequest(); request.resourceReference = UriUtils.buildPublicUri(host, networkState.documentSelfLink); request.operationTypeId = NetworkOperationType.INSPECT.id; request.serviceTaskCallback = ServiceTaskCallback.createEmpty(); host.sendRequest(Operation .createPatch(host, networkState.adapterManagementReference.toString()) .setBodyNoCloning(request) .setReferer(UriUtils.buildUri(host, SERVICE_REFERRER_PATH)) .setCompletion((o, ex) -> { if (ex != null) { Utils.log(getClass(), SERVICE_REFERRER_PATH, Level.WARNING, "Exception while inspect request for network: %s. Error: %s", networkState.documentSelfLink, Utils.toString(ex)); } })); }
private DeferredResult patchComputeState(String documentSelfLink, ComputeState computeState) { URI uri = UriUtils.buildUri(host, documentSelfLink); Operation op = Operation.createPatch(uri) .setBody(computeState) .setReferer(host.getUri()) .setCompletion((o, e) -> { if (e != null) { logger.warning(String.format("Failed to patch compute state: [%s]", Utils.toString(e))); return; } logger.info(String.format("Successfully patched compute state [%s]", documentSelfLink)); }); return host.sendWithDeferredResult(op); }
public static Operation patchNicDescriptionOperation(ServiceHost host, String staticIp, String nicDescLink) { NetworkInterfaceDescription patch = new NetworkInterfaceDescription(); patch.assignment = IpAssignment.STATIC; patch.address = staticIp; return Operation.createPatch(host, nicDescLink) .setBody(patch) .setReferer(host.getUri()); }
void doHealthCheck(ServiceHost host, String containerDescriptionLink) { host.sendRequest(Operation .createGet(host, containerDescriptionLink) .setReferer(UriUtils.buildUri(host, SERVICE_REFERRER_PATH)) .setCompletion((o, ex) -> { if (ex != null) { host.log(Level.SEVERE, "Failed to fetch %s : %s", containerDescriptionLink, Utils.toJson(ex)); } else { processContainerHealth(host, o.getBody(ContainerDescription.class)); } })); }
private static void registerEventTopic(ServiceHost host, EventTopicState topic) { host.sendRequest(Operation.createPost(host, EventTopicService.FACTORY_LINK) .setReferer(host.getUri()) .setBody(topic) .addPragmaDirective( Operation.PRAGMA_DIRECTIVE_QUEUE_FOR_SERVICE_AVAILABILITY) .setCompletion((o, e) -> { if (e != null) { host.log(Level.SEVERE, String.format( "Unable to register '%s' topic. " + "Exception: %s", topic.name, e.getMessage())); } })); }
public static Operation patchNicStateOperation(ServiceHost host, SubnetState subnet, String staticIp, String nicLink) { NetworkInterfaceState patch = new NetworkInterfaceState(); patch.networkLink = null; patch.subnetLink = subnet.documentSelfLink; patch.address = staticIp; return (Operation.createPatch(host, nicLink) .setBody(patch) .setReferer(host.getUri())); }
private void deleteUserGroupState(LocalPrincipalState state, Operation delete) { String userGroupLink = UriUtils.buildUriPath(UserGroupService.FACTORY_LINK, Service.getId(state.documentSelfLink)); sendRequest(Operation.createDelete(getHost(), userGroupLink) .setReferer(delete.getUri()) .setCompletion((o, ex) -> { if (ex != null) { delete.fail(ex); return; } removeUsersFromDeletedGroup(state, userGroupLink, delete); })); }
private void updateCreatedContainerStateWithId(RequestContext context, String id) { context.containerState.id = id; sendRequest(Operation.createPatch(this, context.containerState.documentSelfLink) .setBody(context.containerState) .setReferer(getSelfLink()) .setCompletion((op, e) -> { if (e != null) { logWarning( "Could not patch container state for created container %s", context.computeState.name); } processCreatedContainer(context); })); }
private static DeferredResult<Operation> createGroup(ServiceHost host, Group group) { host.log(Level.INFO, "createGroup - Group '%s'...", group.name); LocalPrincipalState state = new LocalPrincipalState(); state.name = group.name; state.type = LocalPrincipalType.GROUP; state.groupMembersLinks = group.members.stream() .map(u -> UriUtils.buildUriPath(LocalPrincipalFactoryService.SELF_LINK, encode(u))) .collect(Collectors.toList()); Operation op = Operation.createPost(host, LocalPrincipalFactoryService.SELF_LINK) .setBody(state) .setReferer(host.getUri()); return host.sendWithDeferredResult(op); }
private void sendServiceStop(final CompletionHandler removeServiceCompletion, final Service s) { Operation delete = Operation.createDelete(s.getUri()) .addPragmaDirective(Operation.PRAGMA_DIRECTIVE_NO_INDEX_UPDATE) .addPragmaDirective(Operation.PRAGMA_DIRECTIVE_NO_FORWARDING) .setCompletion(removeServiceCompletion) .setReferer(getUri()); try { queueOrScheduleRequest(s, delete); } catch (Exception e) { log(Level.WARNING, Utils.toString(e)); removeServiceCompletion.handle(delete, e); } }
private void sendJoinPeerRequest(JoinPeerRequest joinBody, URI localNodeGroupUri) { Operation peerRequestOp = Operation .createPost(localNodeGroupUri) .setReferer(UriUtils.buildUri(this, "")) .setBody(joinBody) .setCompletion((o, e) -> { if (e == null) { return; } if (e != null) { log(Level.WARNING, "Failure from local node group for join to: %s: %s", joinBody.memberGroupReference, e.toString()); } }); peerRequestOp.setAuthorizationContext(getSystemAuthorizationContext()); sendRequest(peerRequestOp); }
/** * Creates an operation with PatchEndpointLinkObject for updating endpointLink in resources except * resource groups and auth credentials. */ private Operation createEndpointLinkPatchOp(String documentLink, String endpointLink) { PatchEndpointLinkObject state = new PatchEndpointLinkObject(); state.endpointLink = endpointLink; return Operation.createPatch(this.getHost(), documentLink) .setReferer(this.getUri()) .setBody(state); }
@Override public void handleStop(Operation op) { // Delete the node group subscription which was created at handleStart. sendRequest(Operation.createGet(this, getPeerNodeSelectorPath()).setCompletion( (o, e) -> { if (e != null) { op.fail(e); return; } NodeSelectorState nss = o.getBody(NodeSelectorState.class); Operation delete = Operation.createDelete(this, nss.nodeGroupLink).setReferer(getUri()); getHost().stopSubscriptionService(delete, this.nodeGroupCallbackUri); op.complete(); })); }
private void sendSynchRequest(URI parentUri, String documentSelfLink, CompletionHandler ch) { ServiceDocument synchState = new ServiceDocument(); synchState.documentSelfLink = documentSelfLink; Operation synchOp = Operation .createPost(this.host, parentUri.getPath()) .setBody(synchState) .addPragmaDirective(Operation.PRAGMA_DIRECTIVE_SYNCH_OWNER) .setReferer(this.host.getUri()) .setExpiration(Utils.fromNowMicrosUtc(NodeGroupService.PEER_REQUEST_TIMEOUT_MICROS)) .setCompletion((o, e) -> ch.handle(o, e)); this.host.handleRequest(null, synchOp); }
/** * Updates the state of the shouldPopulate flag. * * @param flagState The new state of the flag. * @return The update operation to be invoked. */ private Operation updateShouldPopulateFlagState(FavoriteImagePopulateFlag flagState) { return Operation.createPut(UriUtils.buildUri(getHost(),flagState.documentSelfLink)) .setReferer(getSelfLink()) .setBody(flagState); }
@After public void tearDown() { MockKubernetesAdapterService.clearKubernetesEntities(); if (forDelete.size() != 0) { host.testStart(forDelete.size()); forDelete.forEach(link -> host.sendRequest( Operation .createDelete(UriUtils.buildUri(host, link)) .setReferer(host.getUri()) .setCompletion(host.getCompletion()) )); forDelete.clear(); host.testWait(); } }
private static void registerServiceForMigration(ServiceHost host, Set<String> services) { NodeMigrationService nodeMigration = new NodeMigrationService(); nodeMigration.services = services; host.sendRequest(Operation .createPatch(UriUtils.buildUri(host, NodeMigrationService.SELF_LINK)) .setBody(nodeMigration) .setReferer(host.getUri()) .setCompletion((o, e) -> { if (e != null) { host.log(Level.SEVERE, "Exception while register services for migration: %s", e); } })); }