PATCH /status

<p>Patches the server status with a JSON patch. Currently used only for entering read-only.
485505
@Patch("/status")
    @Consumes("application/json-patch+json")
    @RequiresAdministrator
    public CompletableFuture<ServerStatus> updateStatus(ServiceRequestContext ctx,
                                                        JsonNode patch) throws Exception {
        // TODO(trustin): Consider extracting this into common utility or Armeria.
        final ServerStatus oldStatus = status();
        final JsonNode oldValue = Jackson.valueToTree(oldStatus);
        final JsonNode newValue;
        try {
            newValue = JsonPatch.fromJson(patch).apply(oldValue);
        } catch (JsonPatchException e) {
            // Failed to apply the given JSON patch.
            return rejectStatusPatch(patch);
        }

        if (!newValue.isObject()) {
            return rejectStatusPatch(patch);
        }

        final JsonNode writableNode = newValue.get("writable");
        final JsonNode replicatingNode = newValue.get("replicating");
        if (!writableNode.isBoolean() || !replicatingNode.isBoolean()) {
            return rejectStatusPatch(patch);
        }

        final boolean writable = writableNode.asBoolean();
        final boolean replicating = replicatingNode.asBoolean();
        if (writable && !replicating) {
            return HttpApiUtil.throwResponse(ctx, HttpStatus.BAD_REQUEST,
                                             "'replicating' must be 'true' if 'writable' is 'true'.");
        }

        if (oldStatus.writable) {
            if (!writable) { // writable -> unwritable
                executor().setWritable(false);
                if (replicating) {
                    logger.warn("Entered read-only mode with replication enabled");
                    return CompletableFuture.completedFuture(status());
                } else {
                    logger.warn("Entering read-only mode with replication disabled ..");
                    return executor().stop().handle((unused, cause) -> {
                        if (cause != null) {
                            logger.warn("Failed to stop the command executor:", cause);
                        } else {
                            logger.info("Entered read-only mode with replication disabled");
                        }
                        return status();
                    });
                }
            }
        } else if (writable) { // unwritable -> writable
            logger.warn("Leaving read-only mode ..");
            executor().setWritable(true);
            return executor().start().handle((unused, cause) -> {
                if (cause != null) {
                    logger.warn("Failed to leave read-only mode:", cause);
                } else {
                    logger.info("Left read-only mode");
                }
                return status();
            });
        }

        throw HttpStatusException.of(HttpStatus.NOT_MODIFIED);
    }
705017
def update(self, title=None, body=None, state=None):
        
        data = {'title': title, 'body': body, 'state': state}
        json = None
        self._remove_none(data)

        if data:
            json = self._json(self._patch(self._api, data=dumps(data)), 200)

        if json:
            self._update_(json)
            return True
        return False
763854
function patch(patchURI, patch, callback) {

  util.patch(patchURI, patch, function(err, res) {
    if (err) {
      callback(err)
    } else {
      callback(null, res)
    }
  })
}
223291
function versionStatusParser(status) {
    var res = status.match(MATCHERS.versionStatus);
    var version = {
        status: null,
        major: null,
        minor: null,
        patch: null
    };
    if (res) {
        version.status = res[1];
        version.major = Number(res[2]);
        version.minor = Number(res[3]);
        version.patch = Number(res[4]);
    }
    return version;
}
28088
private String patchedJsonBody(ActionContext context) {
        String body = context.body();
        if (S.blank(body)) {
            return body;
        }
        if (context.xmlEncoded()) {
            Document doc = XML.read(body);
            JSONObject json = $.convert(doc).to(JSONObject.class);
            body = JSON.toJSONString(json.containsKey(xmlRootTag) ? json.get(xmlRootTag) : json);
        }
        if (1 < fieldsAndParamsCount(context)) {
            return body;
        }
        String theName = singleJsonFieldName(context);
        if (null == theName) {
            return body;
        }
        int theNameLen = theName.length();
        body = body.trim();
        boolean needPatch = body.charAt(0) == '[';
        if (!needPatch) {
            if (body.charAt(0) != '{') {
                throw new IllegalArgumentException("Cannot parse JSON string: " + body);
            }
            boolean startCheckName = false;
            int nameStart = -1;
            for (int i = 1; i < body.length(); ++i) {
                char c = body.charAt(i);
                if (c == ' ') {
                    continue;
                }
                if (startCheckName) {
                    if (c == '"') {
                        break;
                    }
                    int id = i - nameStart - 1;
                    if (id >= theNameLen || theName.charAt(i - nameStart - 1) != c) {
                        needPatch = true;
                        break;
                    }
                } else if (c == '"') {
                    startCheckName = true;
                    nameStart = i;
                }
            }
        }
        return needPatch ? S.fmt("{\"%s\": %s}", theName, body) : body;
    }
482569
def update_status(self, new_status):
        """"""
        timestamp = time.time()
        self.status_history[-1]["end"] = timestamp
        self.status_history.append(
            {"start": timestamp, "end": None, "status": new_status}
        )
1321163
def status(self):
        """"""

        hw_type, name, major, minor, patch, status = self.rpc(0x00, 0x04, result_format="H6sBBBB")

        status = {
            'hw_type': hw_type,
            'name': name.decode('utf-8'),
            'version': (major, minor, patch),
            'status': status
        }

        return status
112190
def patch(self, endpoint, json=None, params=None, **kwargs):
        
        json = kwargs['data'] if 'data' in kwargs else json
        return self._make_request('patch', endpoint, data=json, params=params)
248853
ServerMember update(Status status, Instant time) {
    if (this.status != status) {
      this.status = Assert.notNull(status, "status");
      if (time.isAfter(updated)) {
        this.updated = Assert.notNull(time, "time");
      }
      if (statusChangeListeners != null) {
        statusChangeListeners.accept(status);
      }
    }
    return this;
  }
58196
@JavaScriptMethod public final JSONObject news() {
        lastNewsTime = System.currentTimeMillis();
        JSONObject r = new JSONObject();
        try {
            r.put("data", data());
        } catch (RuntimeException x) {
            LOG.log(Level.WARNING, "failed to update " + uri, x);
            status = ERROR;
        }
        Object statusJSON = status == 1 ? "done" : status == CANCELED ? "canceled" : status == ERROR ? "error" : status;
        r.put("status", statusJSON);
        if (statusJSON instanceof String) { // somehow completed
            LOG.log(Level.FINE, "finished in news so releasing {0}", boundId);
            release();
        }
        lastNewsTime = System.currentTimeMillis();
        LOG.log(Level.FINER, "news from {0}", uri);
        return r;
    }
573043
def update(self, status, source=None, params={}):
        ""
        params = params.copy()
        params['status'] = status
        if source:
            params['source'] = source
        return self.__parsed_post(self.__post('/statuses/update.xml', params),
            txml.parseUpdateResponse)
730264
def update_status(self, value, value_set):
        """"""
        self._status = value
        self._status_set = value_set
        self.repaint()
        self.update()
828402
private void updateServerInfo() {
		ServerInfo serverInfo = loadBalance.getServerInfo();
		if (serverInfo == null)
			throw new RuntimeException("'serverInfo' is null !");
		setServerHost(serverInfo.getHost());
		setServerPort(serverInfo.getPort());
		log.debug("Update server info . ({})", serverInfo.toString());
	}
1209826
def _StartStatusUpdateThread(self):
    """"""
    self._status_update_active = True
    self._status_update_thread = threading.Thread(
        name='Status update', target=self._StatusUpdateThreadMain)
    self._status_update_thread.start()
891781
def status(name, init_system, verbose):
    
    try:
        status = Serv(init_system, verbose=verbose).status(name)
    except ServError as ex:
        sys.exit(ex)
    click.echo(json.dumps(status, indent=4, sort_keys=True))
398449
public function checkJsonPatchRequest(array $jsonPatch)
    {
        foreach ($jsonPatch as $operation) {
            if (!is_array($operation)) {
                throw new InvalidJsonPatchException('Patch request should be an array of operations.');
            }
            if (array_key_exists('path', $operation) && trim($operation['path']) == '/id') {
                throw new InvalidJsonPatchException('Change/remove of ID not allowed');
            }
        }
    }
957966
def status(cls):
        """"""
        return cls.json_get('%s/status' % cls.api_url, empty_key=True,
                            send_key=False)