5

I have created an application using GAE Flexible. I could deploy and use the app without any problem. Then I have added the Upload file to Google Cloud Storage using JSON service_account and it works correctly in localhost. I have deployed it without any error but when deploy is completed, and I try to browse my app I see the following error which is 502 server error:

Error: Server Error
The server encountered a temporary error and could not complete your request.
Please try again in 30 seconds.

My app is very simple app without alot of requests, so i don't need backoff. In log from console I see the following error :

[error] 32#32: *9771 connect() failed (113: No route to host) while connecting to upstream, client: 130.211.3.171, server: , request: "GET /_ah/health HTTP/1.1", upstream: "http://172.18.0.2:8080/_ah/health", host: "10.128.0.2"

here is my class to put images in Cloud storage:

    @SuppressWarnings("serial")
@WebServlet(name = "upload", value = "/upload")
@MultipartConfig()
public class UploadServlet extends HttpServlet {

  private static final Logger logger = LoggerFactory.getLogger(UploadServlet.class); 
    
  private static final String BUCKET_NAME ="myBUCKET_NAME";// System.getenv("BUCKET_NAME");
  private static Storage storage = null;

  @Override
  public void init() {
      try {
        logger.debug("bucket name: " + BUCKET_NAME  );
        InputStream is = getClass().getResourceAsStream("/Shelfcheck-9faaa7cbc5a5.json");
        storage = StorageOptions.newBuilder()
                  .setCredentials(ServiceAccountCredentials.fromStream(is))
                  .build()
                  .getService();
        logger.debug("set credential correctly!"  );

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }          
 
//  Storage  storage_service = StorageOptions.defaultInstance().service();
//  Iterator<Bucket> bucketIterator = storage_service.list().iterateAll();
//  while (bucketIterator.hasNext()) {
//    System.out.println(bucketIterator.next());
//  }
      
      
//    storage = StorageOptions.getDefaultInstance().getService();
  }

  @Override
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException,
      ServletException {
      
      logger.debug("Start uploading the files...");

    final Part filePart = req.getPart("file");
    final String fileName = filePart.getSubmittedFileName();

    // Modify access list to allow all users with link to read file
    List<Acl> acls = new ArrayList<>();
    acls.add(Acl.of(Acl.User.ofAllUsers(), Acl.Role.READER));
    // the inputstream is closed by default, so we don't need to close it here
    Blob blob =
        storage.create(
            BlobInfo.newBuilder(BUCKET_NAME, fileName).setAcl(acls).build(),
            filePart.getInputStream());

    // return the public download link
    logger.debug(blob.getMediaLink());

    resp.getWriter().print(blob.getMediaLink());
    logger.debug(resp.toString());
    logger.debug(blob.getMediaLink());
  }
}

Anyone knows how I can resolve this problem ? Thanks

Community
  • 1
  • 1
Majico
  • 3,810
  • 2
  • 24
  • 36
  • check the debug in gae board you will have more info – Khalil M Apr 05 '17 at 14:24
  • I have added the error which I have found from logs in console! Any idea ? – Majico Apr 05 '17 at 14:49
  • are you using FTP? do you have a proxy? – Khalil M Apr 05 '17 at 14:59
  • No, I don't use nither FTP nor proxy. I use com.google.cloud.storage.Storage to create elements in Cloud Storage. I have updated the post with my code. – Majico Apr 05 '17 at 15:39
  • 1
    Can you check the logs for you application to see if your health checks are passing after deployment? Also do you have custom health check, i.e., did you handle /_ah/health route in your application ? – ankitk May 02 '17 at 23:00
  • The error message indicates that the health check from the Flexible environment fails. Can you share your app.yaml to see how health checks are configured? – András Kerekes Mar 09 '18 at 15:18

0 Answers0