public NodeSelectorReplicationService(Service parent) {
   this.parent = parent;
   super.setHost(parent.getHost());
   super.setSelfLink(
       UriUtils.buildUriPath(parent.getSelfLink(), ServiceHost.SERVICE_URI_SUFFIX_REPLICATION));
   super.setProcessingStage(ProcessingStage.AVAILABLE);
 }
    private void handleEnrollInTransaction(Operation request) {
      String serviceSelfLink = this.service.getSelfLink();
      if (Action.POST == request.getAction()) {
        ServiceDocument body = request.getBody(this.service.getStateType());
        if (body.documentSelfLink == null) {
          body.documentSelfLink = UUID.randomUUID().toString();
          request.setBody(body);
        }
        serviceSelfLink = UriUtils.buildUriPath(serviceSelfLink, body.documentSelfLink);
      }

      long servicePreviousVersion =
          this.service.getState(request) == null
              ? -1
              : this.service.getState(request).documentVersion;
      Operation enrollRequest =
          SimpleTransactionService.TxUtils.buildEnrollRequest(
                  this.service.getHost(),
                  request.getTransactionId(),
                  serviceSelfLink,
                  request.getAction(),
                  servicePreviousVersion)
              .setCompletion(
                  (o, e) -> {
                    if (e != null) {
                      request.fail(e);
                      return;
                    }
                    this.service
                        .getOperationProcessingChain()
                        .resumeProcessingRequest(request, this);
                  });
      this.service.sendRequest(enrollRequest);
    }
Exemplo n.º 3
0
  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));
  }
Exemplo n.º 4
0
 private NodeState buildLocalNodeState(NodeState body) {
   if (body == null) {
     body = new NodeState();
   }
   body.id = getHost().getId();
   body.status = NodeStatus.SYNCHRONIZING;
   body.groupReference = UriUtils.buildPublicUri(getHost(), getSelfLink());
   body.documentSelfLink = UriUtils.buildUriPath(getSelfLink(), body.id);
   body.documentKind = Utils.buildKind(NodeState.class);
   body.documentUpdateTimeMicros = Utils.getNowMicrosUtc();
   return body;
 }
Exemplo n.º 5
0
  /**
   * Handles a POST to either join this service to a group using a peer existing member
   * (JoinPeerRequest as the body) or add a new local monitor service to track the state of a remote
   * peer
   *
   * @param post
   */
  @Override
  public void handlePost(Operation post) {
    if (!post.hasBody()) {
      post.fail(new IllegalArgumentException("body is required"));
      return;
    }

    CheckConvergenceRequest cr = post.getBody(CheckConvergenceRequest.class);
    if (CheckConvergenceRequest.KIND.equals(cr.kind)) {
      handleCheckConvergencePost(post, cr);
      return;
    }

    JoinPeerRequest joinBody = post.getBody(JoinPeerRequest.class);
    if (joinBody != null && joinBody.memberGroupReference != null) {
      handleJoinPost(joinBody, post, getState(post), null);
      return;
    }

    NodeState body = post.getBody(NodeState.class);
    if (body.id == null) {
      post.fail(new IllegalArgumentException("id is required"));
      return;
    }

    adjustStat(post.getAction() + STAT_NAME_REFERER_SEGMENT + body.id, 1);

    boolean isLocalNode = body.id.equals(getHost().getId());

    if (body.groupReference == null) {
      post.fail(new IllegalArgumentException("groupReference is required"));
      return;
    }

    if (isLocalNode) {
      // this is a node instance representing us
      buildLocalNodeState(body);
    } else {
      body.documentSelfLink = UriUtils.buildUriPath(getSelfLink(), body.id);
    }

    NodeGroupState localState = getState(post);
    localState.nodes.put(body.id, body);

    post.setBody(body).complete();
  }