@@ -0,0 +1,3486 @@
+package com.google.sps.servlets;%0A%0Aimport com.google.appengine.api.datastore.DatastoreService;%0Aimport com.google.appengine.api.datastore.DatastoreServiceFactory;%0Aimport com.google.appengine.api.datastore.Entity;%0Aimport com.google.appengine.api.datastore.KeyFactory;%0Aimport com.google.cloud.tasks.v2.AppEngineHttpRequest;%0Aimport com.google.cloud.tasks.v2.CloudTasksClient;%0Aimport com.google.cloud.tasks.v2.HttpMethod;%0Aimport com.google.cloud.tasks.v2.QueueName;%0Aimport com.google.cloud.tasks.v2.Task;%0Aimport com.google.common.annotations.VisibleForTesting;%0Aimport com.google.firebase.auth.FirebaseAuth;%0Aimport com.google.protobuf.ByteString;%0Aimport com.google.sps.firebase.FirebaseAppManager;%0Aimport com.google.sps.workspace.WorkspaceFactory;%0Aimport java.io.IOException;%0Aimport java.nio.charset.Charset;%0Aimport javax.servlet.ServletException;%0Aimport javax.servlet.annotation.WebServlet;%0Aimport javax.servlet.http.HttpServlet;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0A%0A@WebServlet(%22/queueEnvPull%22)%0Apublic class QueueEnvPull extends HttpServlet %7B%0A  private WorkspaceFactory workspaceFactory;%0A  private FirebaseAuth auth;%0A%0A  public QueueEnvPull() %7B%7D%0A%0A  protected QueueEnvPull(WorkspaceFactory workspaceFactory, FirebaseAuth auth) %7B%0A    this.workspaceFactory = workspaceFactory;%0A    this.auth = auth;%0A  %7D%0A%0A  @Override%0A  public void init() throws ServletException %7B%0A    super.init();%0A    workspaceFactory = WorkspaceFactory.getInstance();%0A    try %7B%0A      auth = FirebaseAuth.getInstance(FirebaseAppManager.getApp());%0A    %7D catch (IOException e) %7B%0A      throw new ServletException(e);%0A    %7D%0A  %7D%0A%0A  @VisibleForTesting%0A  protected CloudTasksClient getClient() throws IOException %7B%0A    return CloudTasksClient.create();%0A  %7D%0A%0A  @VisibleForTesting%0A  protected String getProjectID() %7B%0A    return System.getenv(%22GOOGLE_CLOUD_PROJECT%22);%0A  %7D%0A%0A  @VisibleForTesting%0A  protected String getQueueName() %7B%0A    return System.getenv(%22EXECUTION_QUEUE_ID%22);%0A  %7D%0A%0A  @VisibleForTesting%0A  protected String getLocation() %7B%0A    return System.getenv(%22LOCATION_ID%22);%0A  %7D%0A%0A  @Override%0A  protected void doGet(HttpServletRequest req, HttpServletResponse resp)%0A      throws ServletException, IOException %7B%0A    String classID = req.getParameter(%22classID%22);%0A    String registry = req.getParameter(%22registry%22);%0A    String image = req.getParameter(%22image%22);%0A    String tag = req.getParameter(%22tag%22);%0A%0A    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();%0A    Entity e = new Entity(%22Environment%22);%0A    e.setProperty(%22status%22, %22pulling%22);%0A    e.setProperty(%22class%22, KeyFactory.stringToKey(classID));%0A    datastore.put(e);%0A    String envID = KeyFactory.keyToString(e.getKey());%0A%0A    try (CloudTasksClient client = getClient()) %7B%0A      String queuePath = QueueName.of(getProjectID(), getLocation(), getQueueName()).toString();%0A%0A      Task.Builder taskBuilder =%0A          Task.newBuilder()%0A              .setAppEngineHttpRequest(%0A                  AppEngineHttpRequest.newBuilder()%0A                      .setBody(%0A                          ByteString.copyFrom(%0A                              String.join(%22,%22, envID, classID, registry, image, tag),%0A                              Charset.defaultCharset()))%0A                      .setRelativeUri(%22/tasks/pullEnv%22)%0A                      .setHttpMethod(HttpMethod.POST)%0A                      .build());%0A%0A      client.createTask(queuePath, taskBuilder.build());%0A%0A      resp.getWriter().print(envID);%0A    %7D%0A  %7D%0A%7D%0A

Add a servlet to queue an image pull.