Load nested yaml properties using spring-boot - spring-boot

I have the following application-errors.yml file defined in src/main/resources of my Java spring-boot application:
client:
badrequest: {code: 001, message: 'Malformed request', status: 400}
configuration: {code: 002, message: 'Invalid EC2 VPC configuration', status: 400}
server:
unexpected.error:
code: 004
message: 'Unexpected error occurred. Please try again'
status: 500
Note that I've tried two different formats for specifying the properties.
I load that property file via the following Bean from a #Configuration annotated class:
#Bean
public static YamlPropertiesFactoryBean getYamlProperties() {
YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
yaml.setResources(new ClassPathResource("application-errors.yml"));
return yaml;
}
I see that the properties are loaded via the Spring Environment variable, but not in the pattern that I would expect. When debugging through, I can see that the source of the loaded property file contains the following values:
{client.badrequest=code:001 message:'Malformed request' status:400, client.configuration=code:002 message:'Invalid EC2 VPC configuration' status:400, server.unexpected.error=code:004 message:'Unexpected error occurred. Please try again' status:500}
It looks like the yaml file was flattened partially (only two levels deep). Instead, I was expecting each end property to be flattened on its own. The format that I was expecting would have been something like this:
{client.badrequest.code=001, client.badrequest.message='Malformed request', client.badrequest.status=400, client.configuration.code=002, client.configuration.message='Invalid EC2 VPC configuration', client.configuration.status=400, server.unexpected.error.code=004, server.unexpected.error.message='Unexpected error occurred. Please try again', server.unexpected.error.status=500}
What do I need to change in order to ensure Spring flattens the properties the entire way? If I'm not understanding either yaml formatting patterns or the pattern that Spring follows to flatten yaml files correctly, please correct my understanding.

I've found the multiple errors I made when arriving at this question this morning:
1) My code was not actually loading any custom named yml property files. Instead, it was picking up the default application.yml file that I also had in my project.
2) That default application.yml file had yml formatted code with the wrong syntax. Specifically, I had omitted the required space after each property identifier:
client:
badrequest:
code:001
message:'Malformed request'
status:400
configuration
code:002
message:'Invalid EC2 VPC configuration'
status:400
server:
unexpected.error
code:004
message:'Unexpected error occurred. Please try again'
status:500
After understanding those two issues, I was able to correctly load properties from application.yml.
The final syntax I landed on for my properties is the following:
# Error Properties
client:
badrequest: {code: 001, message: 'Malformed request', status: 400}
configuration: {code: 002, message: 'Invalid EC2 VPC configuration', status: 400}
server:
unexpected.error: {code: 004, message: 'Unexpected error occurred. Please try again', status: 500}

Related

'provider.deploymentBucket': unrecognized property 'accessLog' error in Serverless.yml

I have been trying to set the "Server access logging" for the deployment bucket in the serverless file with the following code:
deploymentBucket:
accessLog:
bucket: !Ref BucketReference
prefix: 'BucketPrefix'
The layout for the above code was found from using the "serverless-deployment-bucket", link here.
But following the steps that has been laid out in the documentation throws the following error when deploying to AWS:
Warning: Invalid configuration encountered
at 'provider.deploymentBucket': unrecognized property 'accessLog'
Not sure what I'm doing incorrectly

How resolve -API call error https://a.blazemeter.com/api/latest/proxy: {'code': 401, 'message': 'Unauthorized'}

I have one selenium script. Now I want it to convert into a JMX file. Here I used the proxy2jmx converter. I also created an account in Blazemeter. I have one token and a secret key, those values provide in the .bzt-rc file.
Now I provide one config yml file -
execution:
executor: selenium
iterations: 1
scenario: sel
scenarios:
sel:
script: F:\Taurus\HelloSelenium.java
services:
module: proxy2jmx
modules:
proxy2jmx:
token: 707ab10114456ad7af13827f
When execute this file It return Error message-->11:21:24 ERROR: Network Error: API call error https://a.blazemeter.com/api/latest/proxy: {'code': 401, 'message': 'Unauthorized'}
11:21:24 INFO: Post-processing...
11:21:24 INFO: Will not pick converted JMX due to exception: API call error https://a.blazemeter.com/api/latest/proxy: {'code': 401, 'message': 'Unauthorized'}
How is it resolved?
I think the correct way of providing token is
modules:
blazemeter:
token: 756a1345d1c8258a739dd260:1c2f53d2612dc64cb4c9dade311f351916b9e391330c9f6d1a2e1e36da76cabc44be9ce6
More information:
BlazeMeter Reporting Service - Personalized Usage
BlazeMeter API keys

Exported resources not working with puppet

I've written a module to set up the Prometheus node_exporter (in here called ni_trending). Now I need to add all FQDNs of the nodes to a simple file: So declaring an exported resource makes much sense here. PuppetDB is configured and working.
Here's the declaration, within my config.pp:
##node_exporter { "${listen_address}":
hostname => $ni_trending::hostname,
listen_port => $ni_trending::listen_port,
}
When the module is applied on the node I get following error:
Error: Could not retrieve catalog from remote server: Error 500 on
SERVER: Server Error: Evaluation Error: Error while evaluating a
Resource Statement, Invalid export in Class[Ni_trending]: {} is not a
resource on node ydixken-dev01.berlin.ni
Within the ni_trending module I'm retrieving all collected resources via:
Node_exporter <<| |>>
What is missing here?

Failed to bind properties under 'server' to org.springframework.boot.autoconfigure.web.ServerProperties:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-09-04 12:23:24.383 ERROR 12320 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'server' to org.springframework.boot.autoconfigure.web.ServerProperties:
Property: server
Value:
Origin: class path resource [application.properties]:2:0
Reason: No converter found capable of converting from type [java.lang.String] to type [#org.springframework.boot.context.properties.ConfigurationProperties org.springframework.boot.autoconfigure.web.ServerProperties]
Action:
Update your application's configuration
My application.properties file look like this:
server:
port: ${PORT:9191}
spring:
datasource:
url: jdbc:sqlserver://PC382682:1433;databaseName=imvenkat
username: imvenkat
password: imvenkat
driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
I know the issue is related to Spring boot, but how should I change my application.properties file to address this issue?
The problem is that you're using YAML format within a properties file. The properties are being parsed line by line, so the properties parser reads server:, and doesn't know how to bind to server directly, which causes the error you see.
Either rename your file to application.yml or change the properties:
server.port=${PORT:9191}
spring.datasource.url=jdbc:sqlserver://PC382682:1433;databaseName=imvenkat
spring.datasource.username=imvenkat
spring.datasource.password=imvenkat
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
This Error can occur when there is mis match between parent version and your spring-boot-devtools dependency.
Remove the version from spring-boot-devtools dependency, that will solve the issue.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
This error can also occur if your config file is in yaml format but you have an error in your yaml so one line looks like a property. Happened to me, previous this was just a broken configuration line, now it breaks the application.
So if you have something broken (look at the url=) like:
server:
port: ${PORT:9191}
spring:
datasource:
url=jdbc:sqlserver://PC382682:1433;databaseName=imvenkat
the same cryptic error can occur. Fixing the config line fixes this error.

How to set the "cluster" property in prisma.yml

Thanks for reading my question in advance. I am just start to use graphql and prisma following this tutorial.
I have the following Error when Deploying the Prisma database service:
Error: No cluster set. Please set the "cluster" property in your prisma.yml
at /Users/judy/howtographql/server/node_modules/graphql-config-extension-prisma/src/index.ts:89:11
at step (/Users/judy/howtographql/server/node_modules/graphql-config-extension-prisma/dist/index.js:40:23)
at Object.next (/Users/judy/howtographql/server/node_modules/graphql-config-extension-prisma/dist/index.js:21:53)
at fulfilled (/Users/judy/howtographql/server/node_modules/graphql-config-extension-prisma/dist/index.js:12:58)
at <anonymous>
error Command failed with exit code 1.
ERROR: "playground" exited with 1.
error Command failed with exit code 1.
I looked over the tutorial to find that there is nothing about how to set the cluster. I wonder how to fix this problem.
The default prisma.yaml is:
# the name for the service (will be part of the service's HTTP endpoint)
service: hackernews-graphql-js
# the cluster and stage the service is deployed to
stage: dev
# to disable authentication:
# disableAuth: true
secret: mysecret123
# the file path pointing to your data model
datamodel: datamodel.graphql
It could be just that you may have entered an incorrect endpoint address. Please refer https://github.com/prisma/graphql-config-extension-graphcool/issues/8

Resources