Source:
<code>public Response clusterResize(final ClusterResizeRequest data) { int desired = data.getInstances(); if (desired == 0) { return Response.status(Response.Status.FORBIDDEN).entity(new GenericAPIResponse() { @Override public int getStatus() { return Response.Status.FORBIDDEN.getStatusCode(); } @Override public Object getMessage() { return "Could not change the number of instances. Scaling down to zero instances is not allowed. Please use '/cluster/shutdown' instead."; } }).build(); } CrateClient client = client(); if (client != null) { if (desired < store.state().crateInstances().size()) { int maxReplicas = getMaxReplicas(client); LOGGER.debug("max replicas = desired instances = {}", maxReplicas, desired); if (maxReplicas > 0 && desired < maxReplicas + 1) { client.close(); return Response.status(Response.Status.FORBIDDEN).entity(new GenericAPIResponse() { @Override public int getStatus() { return Response.Status.FORBIDDEN.getStatusCode(); } @Override public Object getMessage() { return "Could not change the number of instances. The number of desired instances is lower than the number of replicas + 1."; } }).build(); } } int quorum = CrateInstances.calculateQuorum(desired); LOGGER.debug("update cluster settings: desired={} quorum={}", desired, quorum); setClusterSetting(client, "discovery.zen.minimum_master_nodes", quorum); client.close(); } <START> JSONObject address = mesosMasterAddress(); <END> int activeMesosSlaves = 0; if (address != null) { activeMesosSlaves = numActiveSlaves(address); } if (activeMesosSlaves > 0 && desired > activeMesosSlaves) { return Response.status(Response.Status.FORBIDDEN).entity(new GenericAPIResponse() { @Override public int getStatus() { return Response.Status.FORBIDDEN.getStatusCode(); } @Override public Object getMessage() { return "Could not initialize more Crate nodes than existing number of mesos agents"; } }).build(); } store.state().desiredInstances(desired); return Response.ok(new GenericAPIResponse() {}).build(); }</code><technical_language>this block needs L188 new cluster setting is applied, return error change number of desired instances</technical_language>

Target:
public Response clusterResize(final ClusterResizeRequest data) { int desired = data.getInstances(); if (desired == 0) { return Response.status(Response.Status.FORBIDDEN).entity(new GenericAPIResponse() { @Override public int getStatus() { return Response.Status.FORBIDDEN.getStatusCode(); } @Override public Object getMessage() { return "Could not change the number of instances. Scaling down to zero instances is not allowed. Please use '/cluster/shutdown' instead."; } }).build(); } String address = mesosMasterAddress(); if (address != null) { int activeMesosSlaves = numActiveSlaves(address); if (desired > activeMesosSlaves) { return Response.status(Response.Status.FORBIDDEN).entity(new GenericAPIResponse() { @Override public int getStatus() { return Response.Status.FORBIDDEN.getStatusCode(); } @Override public Object getMessage() { return "Could not initialize more Crate nodes than existing number of mesos agents"; } }).build(); } } CrateClient client = client(); if (client != null) { if (desired < store.state().crateInstances().size()) { int maxReplicas = getMaxReplicas(client); LOGGER.debug("max replicas = desired instances = {}", maxReplicas, desired); if (maxReplicas > 0 && desired < maxReplicas + 1) { client.close(); return Response.status(Response.Status.FORBIDDEN).entity(new GenericAPIResponse() { @Override public int getStatus() { return Response.Status.FORBIDDEN.getStatusCode(); } @Override public Object getMessage() { return "Could not change the number of instances. The number of desired instances is lower than the number of replicas + 1."; } }).build(); } } int quorum = CrateInstances.calculateQuorum(desired); LOGGER.debug("update cluster settings: desired={} quorum={}", desired, quorum); setClusterSetting(client, "discovery.zen.minimum_master_nodes", quorum); client.close(); } store.state().desiredInstances(desired); return Response.ok(new GenericAPIResponse() {}).build(); }