Search in sources :

Example 1 with ConfigurationException

use of com.google.apphosting.utils.config.ConfigurationException 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;
}
Also used : QueueYamlReader(com.google.apphosting.utils.config.QueueYamlReader) ConfigurationException(com.google.apphosting.utils.config.ConfigurationException) QueueXml(com.google.apphosting.utils.config.QueueXml) ByteString(com.google.protobuf.ByteString) QueueXmlReader(com.google.apphosting.utils.config.QueueXmlReader)

Example 2 with ConfigurationException

use of com.google.apphosting.utils.config.ConfigurationException in project appengine-java-standard by GoogleCloudPlatform.

the class LocalTaskQueueConfigTest method testErrorForXmlAndYamlPath.

@Test
public void testErrorForXmlAndYamlPath() {
    ConfigurationException expected = assertThrows(ConfigurationException.class, () -> getQueueConfigFromXmlAndYaml("xml-and-yaml"));
    assertThat(expected).hasMessageThat().contains("Found both queue.xml and queue.yaml");
}
Also used : ConfigurationException(com.google.apphosting.utils.config.ConfigurationException) Test(org.junit.Test)

Aggregations

ConfigurationException (com.google.apphosting.utils.config.ConfigurationException)2 QueueXml (com.google.apphosting.utils.config.QueueXml)1 QueueXmlReader (com.google.apphosting.utils.config.QueueXmlReader)1 QueueYamlReader (com.google.apphosting.utils.config.QueueYamlReader)1 ByteString (com.google.protobuf.ByteString)1 Test (org.junit.Test)1