public void updateServiceManualInstances()

in src/main/java/com/google/cloud/run/kafkascaler/clients/CloudRunClientWrapper.java [281:312]


  public void updateServiceManualInstances(String serviceName, int instances) throws IOException {
    GoogleCloudRunV2ServiceScaling scaling = new GoogleCloudRunV2ServiceScaling();
    scaling.setManualInstanceCount(instances);
    scaling.setScalingMode(MANUAL_SCALING_MODE);

    GoogleCloudRunV2Service service = getService(serviceName);

    service.setScaling(scaling);
    service.setLaunchStage(ALPHA_LAUNCH_STAGE);

    GoogleLongrunningOperation operation =
        this.cloudRun
            .projects()
            .locations()
            .services()
            .patch(
                String.format(
                    "projects/%s/locations/%s/services/%s",
                    this.projectId, this.region, serviceName),
                service)
            .setUpdateMask(SCALING_AND_LAUNCH_STAGE_UPDATE_MASK)
            .execute();

    if (operation.getError() != null) {
      throw new IOException(
          "Request failed to Cloud Run to update service instances: " + operation.getError());
    } else {
      logger.atInfo().log(
          "Sent update service request to set instances to %d for service %s",
          instances, serviceName);
    }
  }