com.google.appengine.api.backends.BackendServiceFactory Java Examples

The following examples show how to use com.google.appengine.api.backends.BackendServiceFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BackendsApiServlet.java    From appengine-java-vm-runtime with Apache License 2.0 6 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse res) throws IOException {
  BackendService backends = BackendServiceFactory.getBackendService();
  String server = req.getParameter("server");
  PrintWriter writer = res.getWriter();
  if (server == null) {
    String currentServerName = backends.getCurrentBackend();
    if (currentServerName == null) {
      currentServerName = "<default>";
    }
    int currentInstance = backends.getCurrentInstance();
    writer.append(currentInstance + "." + currentServerName + "\n");
  } else {
    String instance = req.getParameter("instance");
    if (instance != null) {
      writer.append(backends.getBackendAddress(server, Integer.parseInt(instance)) + "\n");
    } else {
      writer.append(backends.getBackendAddress(server) + "\n");
    }
  }
}
 
Example #2
Source File: JobRecord.java    From appengine-pipelines with Apache License 2.0 5 votes vote down vote up
private static String getCurrentBackend() {
  if (Boolean.parseBoolean(System.getenv("GAE_VM"))) {
    // MVM can't be a backend.
    return null;
  }
  BackendService backendService = BackendServiceFactory.getBackendService();
  String currentBackend = backendService.getCurrentBackend();
  // If currentBackend contains ':' it is actually a B type module (see b/12893879)
  if (currentBackend != null && currentBackend.indexOf(':') != -1) {
    currentBackend = null;
  }
  return currentBackend;
}
 
Example #3
Source File: AppEngineTaskQueue.java    From appengine-pipelines with Apache License 2.0 5 votes vote down vote up
private TaskOptions toTaskOptions(Task task) {
  final QueueSettings queueSettings = task.getQueueSettings();

  TaskOptions taskOptions = TaskOptions.Builder.withUrl(TaskHandler.handleTaskUrl());
  if (queueSettings.getOnBackend() != null) {
    taskOptions.header("Host", BackendServiceFactory.getBackendService().getBackendAddress(
        queueSettings.getOnBackend()));
  } else {

    String versionHostname = RetryHelper.runWithRetries(new Callable<String>() {
      @Override
      public String call() {
        ModulesService service = ModulesServiceFactory.getModulesService();
        String module = queueSettings.getOnModule();
        String version = queueSettings.getModuleVersion();
        if (module == null) {
          module = service.getCurrentModule();
          version = service.getCurrentVersion();
        }
        return service.getVersionHostname(module, version);
      }
    }, RetryParams.getDefaultInstance(), MODULES_EXCEPTION_HANDLER);
    taskOptions.header("Host", versionHostname);
  }

  Long delayInSeconds = queueSettings.getDelayInSeconds();
  if (null != delayInSeconds) {
    taskOptions.countdownMillis(delayInSeconds * 1000L);
    queueSettings.setDelayInSeconds(null);
  }
  addProperties(taskOptions, task.toProperties());
  String taskName = task.getName();
  if (null != taskName) {
    taskOptions.taskName(taskName);
  }
  return taskOptions;
}
 
Example #4
Source File: TestServlet.java    From wt1 with Apache License 2.0 5 votes vote down vote up
private String newFileName() {
	long now = System.currentTimeMillis();
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd/HH/mm-ss");
	String name = "trackerz/" + 
	BackendServiceFactory.getBackendService().getCurrentBackend() + "-" +
	BackendServiceFactory.getBackendService().getCurrentInstance() + "/" +
	sdf.format(new Date(now)) + ".log";
	return name;
}
 
Example #5
Source File: GCSGAEStorageProcessor.java    From wt1 with Apache License 2.0 5 votes vote down vote up
private synchronized void flushBuffer(boolean reinit) throws IOException {
	if (curBuf == null) {
		// processor has already been shutdown
		return;
	}
	curBufGZ.flush();
	curBufGZ.close();

	if (writtenEvents > 0) {
		String name = CSVFormatWriter.newFileName("b" + BackendServiceFactory.getBackendService().getCurrentInstance());

		logger.info("Opening new file name=" + name);
		AppEngineFile file = newFile(name);
		FileWriteChannel channel = fileService.openWriteChannel(file, true);

		logger.info("Writing new file name=" + name + " inSize=" + writtenBeforeGZ + " gzSize=" +  curBuf.size() + ")");
		channel.write(ByteBuffer.wrap(curBuf.toByteArray()));
		logger.info("Closing new file");
		channel.closeFinally();
		logger.info("Closed new file");

		Stats stats = ProcessingQueue.getInstance().getStats();
		synchronized (stats) {
			stats.createdFiles++;
			stats.savedEvents += writtenEvents;
			stats.savedEventsGZippedSize += curBuf.size();
			stats.savedEventsInputSize += writtenBeforeGZ;
		}
	} else {
		logger.info("No events to flush");
	}

	curBuf = null;
	curBufGZ = null;
	if (reinit) {
		initBuffer();
	}
}
 
Example #6
Source File: ServersStartServlet.java    From appengine-java-vm-runtime with Apache License 2.0 4 votes vote down vote up
@Override
public void init() {
  backendService = BackendServiceFactory.getBackendService();
}