use of com.google.apphosting.utils.config.QueueYamlReader in project appengine-java-standard by GoogleCloudPlatform.
the class LocalTaskQueue method parseQueueConfiguration.
/**
* Parse the queue configuration from application directory, either from xml or yaml configuration
*
* @param appDir the application war directory.
* @param queueXmlPath a user provided path that overrides the default path of queue.xml. This is
* used by local unit tests.
* @param queueYamlPath a user provided path that overrides the default path of queue.yaml. This
* is used by local unit tests.
* @return the parsed queue configuration.
* @throws ConfigurationException if both yaml and xml path are not null.
*/
QueueXml parseQueueConfiguration(String appDir, @Nullable final String queueXmlPath, @Nullable final String queueYamlPath) {
if (queueXmlPath != null && queueYamlPath != null) {
throw new ConfigurationException("Found both queue.xml and queue.yaml. Please use queue.yaml and remove queue.xml. " + "For more information: " + DOC_LINK);
}
QueueXml resultFromXml = null;
QueueXml resultFromYaml = null;
if (queueXmlPath != null) {
// user wants a custom queue.xml loaded
QueueXmlReader xmlReader = new QueueXmlReader(appDir) {
@Override
public String getFilename() {
return queueXmlPath;
}
};
resultFromXml = xmlReader.readQueueXml();
} else if (queueYamlPath != null) {
// user wants a custom queue.yaml loaded
QueueYamlReader yamlReader = new QueueYamlReader(appDir) {
@Override
public String getFilename() {
return queueYamlPath;
}
};
resultFromYaml = yamlReader.parse();
} else {
// Tries default path for xml or yaml configuration.
QueueXmlReader xmlReader = new QueueXmlReader(appDir);
// TODO Consider reloading queue.xml if changed.
// resultFromXml would be null iff the xml file does not exist.
resultFromXml = xmlReader.readQueueXml();
QueueYamlReader yamlReader = new QueueYamlReader(Paths.get(appDir, "WEB-INF").toString());
resultFromYaml = yamlReader.parse();
}
if (!ApiUtils.isPromotingYaml()) {
return (resultFromXml != null) ? resultFromXml : resultFromYaml;
}
// When promoting yaml, given proper messages if queue.xml is present.
if (resultFromXml != null && resultFromYaml == null) {
logger.warning("Using queue.xml. Please migrate to queue.yaml. For more information: " + DOC_LINK);
}
return (resultFromYaml != null) ? resultFromYaml : resultFromXml;
}
Aggregations