private NodeGroupState getStateFromBody(Operation o) { if (!o.hasBody()) { return new NodeGroupState(); } NodeGroupState rsp = o.getBody(NodeGroupState.class); if (rsp != null) { if (rsp.nodes == null) { rsp.nodes = new HashMap<>(); } } return rsp; } }
/** * Create a node group service instance on each of the attached hosts */ public TestNodeGroupManager createNodeGroup() { List<Operation> ops = this.hosts.stream() .map(host -> UriUtils.buildUri(host.getUri(), ServiceUriPaths.NODE_GROUP_FACTORY)) .map(uri -> { NodeGroupState body = new NodeGroupState(); body.documentSelfLink = this.nodeGroupName; return Operation.createPost(uri).setBodyNoCloning(body); }) .collect(toList()); // choose one peer and send all request in parallel then wait. getTestRequestSender().sendAndWait(ops); return this; }
/** * Create a node group service instance on each of the attached hosts */ public TestNodeGroupManager createNodeGroup() { List<Operation> ops = this.hosts.stream() .map(host -> UriUtils.buildUri(host.getUri(), ServiceUriPaths.NODE_GROUP_FACTORY)) .map(uri -> { NodeGroupState body = new NodeGroupState(); body.documentSelfLink = this.nodeGroupName; return Operation.createPost(uri).setBodyNoCloning(body); }) .collect(toList()); // choose one peer and send all request in parallel then wait. getTestRequestSender().sendAndWait(ops); return this; }
localState.documentOwner = getHost().getId(); NodeGroupState patchBody = new NodeGroupState(); patchBody.documentOwner = getHost().getId(); patchBody.documentUpdateTimeMicros = localNode.documentUpdateTimeMicros;
public void getNodeState(URI nodeGroup, Map<URI, NodeGroupState> nodesPerHost, TestContext ctx) { URI u = UriUtils.buildExpandLinksQueryUri(nodeGroup); Operation get = Operation.createGet(u).setCompletion((o, e) -> { NodeGroupState ngs = null; if (e != null) { // failure is OK, since we might have just stopped a host log("Host %s failed GET with %s", nodeGroup, e.getMessage()); ngs = new NodeGroupState(); } else { ngs = o.getBody(NodeGroupState.class); } synchronized (nodesPerHost) { nodesPerHost.put(nodeGroup, ngs); } if (ctx == null) { completeIteration(); } else { ctx.completeIteration(); } }); send(get); }
public void getNodeState(URI nodeGroup, Map<URI, NodeGroupState> nodesPerHost, TestContext ctx) { URI u = UriUtils.buildExpandLinksQueryUri(nodeGroup); Operation get = Operation.createGet(u).setCompletion((o, e) -> { NodeGroupState ngs = null; if (e != null) { // failure is OK, since we might have just stopped a host log("Host %s failed GET with %s", nodeGroup, e.getMessage()); ngs = new NodeGroupState(); } else { ngs = o.getBody(NodeGroupState.class); } synchronized (nodesPerHost) { nodesPerHost.put(nodeGroup, ngs); } if (ctx == null) { completeIteration(); } else { ctx.completeIteration(); } }); send(get); }
@Override public void handleStart(Operation startPost) { NodeGroupState initState = null; if (startPost.hasBody()) { initState = startPost.getBody(NodeGroupState.class); } else { initState = new NodeGroupState(); } initState.documentOwner = getHost().getId(); if (initState.config == null) { initState.config = new NodeGroupConfig(); } NodeState self = initState.nodes.get(getHost().getId()); self = buildLocalNodeState(self); if (!validateNodeOptions(startPost, self.options)) { return; } initState.nodes.put(self.id, self); this.cachedState = Utils.clone(initState); startPost.setBody(this.cachedState).complete(); }
public void setNodeGroupConfig(NodeGroupConfig config) { setSystemAuthorizationContext(); List<Operation> ops = new ArrayList<>(); for (URI nodeGroup : getNodeGroupMap().values()) { NodeGroupState body = new NodeGroupState(); body.config = config; body.nodes = null; ops.add(Operation.createPatch(nodeGroup).setBody(body)); } this.sender.sendAndWait(ops); resetAuthorizationContext(); }
public void setNodeGroupConfig(NodeGroupConfig config) { setSystemAuthorizationContext(); List<Operation> ops = new ArrayList<>(); for (URI nodeGroup : getNodeGroupMap().values()) { NodeGroupState body = new NodeGroupState(); body.config = config; body.nodes = null; ops.add(Operation.createPatch(nodeGroup).setBody(body)); } this.sender.sendAndWait(ops); resetAuthorizationContext(); }
private Operation getCreateCustomNodeGroupOperation(String customGroupName, URI nodeGroupFactoryUri, NodeState selfState) { NodeGroupState body = new NodeGroupState(); body.documentSelfLink = customGroupName; if (selfState != null) { body.nodes.put(selfState.id, selfState); } return Operation.createPost(nodeGroupFactoryUri).setBody(body); }
private Operation getCreateCustomNodeGroupOperation(String customGroupName, URI nodeGroupFactoryUri, NodeState selfState) { NodeGroupState body = new NodeGroupState(); body.documentSelfLink = customGroupName; if (selfState != null) { body.nodes.put(selfState.id, selfState); } return Operation.createPost(nodeGroupFactoryUri).setBody(body); }
private void sendAvailableSelfPatch(NodeState local) { // mark self as available by issuing self PATCH NodeGroupState body = new NodeGroupState(); body.config = null; body.documentOwner = getHost().getId(); body.documentSelfLink = UriUtils.buildUriPath(getSelfLink(), body.documentOwner); local.status = NodeStatus.AVAILABLE; body.nodes.put(local.id, local); sendRequest(Operation.createPatch(getUri()).setBody( body)); }