How do you define a Duration object in Micronaut's application YAML - caching

I'm trying to define a caffiene cache in micronaut and set the expire time via the application yaml.
The documentation indicates that
micronaut.caches.discovery-client.expire-after-write should be defined as a Duration object but it's unclear how to do so in YAML.
---
micronaut:
application:
name: example-service
caches:
example-cache:
expire-after-write: 86400
Gives the following error:
Internal Server Error: Failed to inject value for parameter [expireAfterWrite] of method [setExpireAfterWrite] of class: io.micronaut.cache.caffeine.DefaultCacheConfiguration
Message: Error resolving property value [micronaut.caches.example-cache.expire-after-write]. Property doesn't exist
Path Taken: new $ExampleControllerDefinition$Intercepted(BeanContext beanContext,Qualifier qualifier,[Interceptor[] interceptors]) --> new CacheInterceptor([CacheManager cacheManager],CacheErrorHandler errorHandler,AsyncCacheErrorHandler asyncCacheErrorHandler,ExecutorService ioExecutor,BeanContext beanContext) --> new DefaultCacheManager([List caches],Provider dynamicCacheManager) --> new DefaultSyncCache([CacheConfiguration cacheConfiguration],ApplicationContext applicationContext,ConversionService conversionService) --> DefaultCacheConfiguration.setExpireAfterWrite([Duration expireAfterWrite])
io.micronaut.http.client.exceptions.HttpClientResponseException: Internal Server Error: Failed to inject value for parameter [expireAfterWrite] of method [setExpireAfterWrite] of class: io.micronaut.cache.caffeine.DefaultCacheConfiguration
Presumably as the value is being treated as an Integer not a Duration

It appears you can do it as simply as this:
---
micronaut:
application:
name: example-service
caches:
example-cache:
expire-after-write: 24h

Related

Getting error after entering a value in a text box in karate UI via Firefox

This issue is only when I invoke the scripts via firefox driver, after entering value in a text box getting an error and test is failing
configure driver = {type:'geckodriver' , executable:'C:\Users\dinesh\Downloads\geckodriver-v0.31.0-win64\geckodriver.exe'}
driver 'https://courses.ultimateqa.com/users/sign_in'
screenshot()
driver.maximize()
input("//*[#id='user[email]']","abc#gmail.com")
Error message
* input("//*[#id='user[first_name]']", 'welcome')
js failed:
>>>>
01: input("//*[#id='user[first_name]']", 'welcome')
<<<<
org.graalvm.polyglot.PolyglotException: Expected to find an object with property ['message'] in path $['value'] but found 'null'. This is not a json object according to the JsonProvider: 'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'.
- com.jayway.jsonpath.internal.path.PropertyPathToken.evaluate(PropertyPathToken.java:71)
- com.jayway.jsonpath.internal.path.PathToken.handleObjectProperty(PathToken.java:81)
- com.jayway.jsonpath.internal.path.PropertyPathToken.evaluate(PropertyPathToken.java:79)
- com.jayway.jsonpath.internal.path.RootPathToken.evaluate(RootPathToken.java:62)
- com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:99)
- com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:107)
- com.jayway.jsonpath.JsonPath.read(JsonPath.java:185)
Please help me the xpath is right, karate is writing the value in text box but after that it is failing
For me this code works, both with chromedriver and geckodriver. Of course these executables must be set in the PATH environment variable.
I added also the waitFor method to wait for the web element.
Feature: sample karate test script
for help, see: https://github.com/intuit/karate/wiki/IDE-Support
Background:
#* configure driver = { type: 'chromedriver', executable: 'chromedriver' }
* configure driver = { type: 'geckodriver', executable: 'geckodriver' }
#* def sleep = function(pause){ java.lang.Thread.sleep(pause) }
Scenario: test error
Given driver 'https://courses.ultimateqa.com/users/sign_in'
When waitFor("//*[#id='user[email]']").input('abc#gmail.com')
And waitFor("//*[#id='user[password]']").input('qwerty1234')
And waitFor("//input[#type='submit']").click()
* screenshot()
#* call sleep 3000

Puppet 6 and module puppetlabs/accounts does not create user account in Hiera YAML format

When I run puppet agent --test I have no errors output but the user did not create.
My puppet hira.yaml configuration is:
---
version: 5
datadir: "/etc/puppetlabs/code/environments"
data_hash: yaml_data
hierarchy:
- name: "Per-node data (yaml version)"
path: "%{::environment}/nodes/%{::trusted.certname}.yaml"
- name: "Common YAML hierarchy levels"
paths:
- "defaults/common.yaml"
- "defaults/users.yaml"
users.yaml is:
accounts::user:
joed:
locked: false
comment: System Operator
uid: '1700'
gid: '1700'
groups:
- admin
- sudonopw
sshkeys:
- ssh-rsa ...Hw== sysop+moduledevkey#puppetlabs.com
I use this module
Nothing in Hiera data itself causes anything to be applied to target nodes. Some kind of declaration is required in a manifest somewhere or in the output of an external node classifier script. Moreover, the puppetlabs/accounts module provides only defined types, not classes. You can store defined-type data in Hiera and read it back, but automated parameter binding via Hiera applies only to classes, not defined types.
In short, then, no user is created (and no error is reported) because no relevant resources are declared into the target node's catalog. You haven't given Puppet anything to do.
If you want to apply the stored user data presented to your nodes, you would want something along these lines:
$user_data = lookup('accounts::user', Hash[String,Hash], 'hash', {})
$user_data.each |$user,$props| {
accounts::user { $user: * => $props }
}
That would go into the node block matched to your target node, or, better, into a class that is declared by that node block or an equivalent. It's fairly complicated for so few lines, but in brief:
the lookup function looks up key 'accounts::user' in your Hiera data
performing a hash merge of results appearing at different levels of the hierarchy
expecting the result to be a hash with string keys and hash values
and defaulting to an empty hash if no results are found;
the mappings in the result hash are iterated, and for each one, an instance of the accounts::user defined type is declared
using the (outer) hash key as the user name,
and the value associated with that key as a mapping from parameter names to parameter values.
There are a few problems here.
You are missing a line in your hiera.yaml namely the defaults key. It should be:
---
version: 5
defaults: ## add this line
datadir: "/etc/puppetlabs/code/environments"
data_hash: yaml_data
hierarchy:
- name: "Per-node data (yaml version)"
path: "%{::environment}/nodes/%{::trusted.certname}.yaml"
- name: "Common YAML hierarchy levels"
paths:
- "defaults/common.yaml"
- "defaults/users.yaml"
I detected that using the puppet-syntax gem (included if you use PDK, which is recommended):
▶ bundle exec rake validate
Syntax OK
---> syntax:manifests
---> syntax:templates
---> syntax:hiera:yaml
ERROR: Failed to parse hiera.yaml: (hiera.yaml): mapping values are not allowed in this context at line 3 column 10
Also, in addition to what John mentioned, the simplest class to read in your data would be this:
class test (Hash[String,Hash] $users) {
create_resources(accounts::user, $users)
}
Or if you want to avoid using create_resources*:
class test (Hash[String,Hash] $users) {
$users.each |$user,$props| {
accounts::user { $user: * => $props }
}
}
Note that I have relied on the Automatic Parameter Lookup feature for that. See the link below.
Then, in your Hiera data, you would have a key named test::users to correspond (class name "test", key name "users"):
---
test::users: ## Note that this line changed.
joed:
locked: false
comment: System Operator
uid: '1700'
gid: '1700'
groups:
- admin
- sudonopw
sshkeys:
- ssh-rsa ...Hw== sysop+moduledevkey#puppetlabs.com
Use of automatic parameter lookup is generally the more idiomatic way of writing Puppet code compared to calling the lookup function explicitly.
For more info:
PDK
Automatic Parameter Lookup
create_resources
(*Note that create_resources is "controversial". Many in the Puppet community prefer not to use it.)

Getting exception while running SaltStack module.run function with name dsc.apply_config

I'm getting the following error while trying to state.apply sls on windows machine.
ID: ProvisionADDC
Function: module.run
Name: dsc.apply_config
Result: False
Comment: Module function dsc.apply_config threw an exception. Exception: No JSON results from powershell. Additional info follows:
retcode:
0
stderr:
stdout:
Started: 12:06:08.044000
Duration: 2684.0 ms
Changes:
Since win_dsc is execution module, then I'm forced to use state.module module to run this function on minion:
C:\DSC:
file.directory:
- makedirs: True
allprofiles:
win_firewall.disabled
CopyDSCModules:
file.recurse:
- name: 'C:\Program Files\WindowsPowerShell\Modules'
- source: salt://windows/dsc/
InstallADDomainServices:
win_servermanager.installed:
- name: AD-Domain-Services
- restart: True
- require:
- file: CopyDSCModules
ProvisionADDC:
module.run:
- name: dsc.apply_config
- path: C:\DSC\
- source: salt://windows/mof
- require:
- file: 'C:\DSC'
- file: CopyDSCModules
- win_servermanager: InstallADDomainServices
Anybody have experience with win_dsc and SaltStack ?
I think it's a case of the documentation lacking a bit, but you need to actually run the configuration in the same ps1 file, eg.
Configuration myconfig {
Node 'localhost' {
WindowsFeature 'DNS' {
Name = 'DNS'
Ensure = Present
}
}
}
myconfig
I'm playing with this a litle at the moment and hopefully I can come up with a helpful issue/PR because it is lacking a bit (even if just for better error logging).
I'm not sure how this works in terms of determining a specific config as I'e not tested that yet (using the config_name param).

Error while running hiera hash

I'm trying to call hiera_hash in my module but I am getting an error while excecuting. This is how I'm calling from my module:
$data = hiera_hash('profile')
Below is my yaml file:
profile:
container:
- default
- full
Below is my error:
Error: Evaluation Error: Error while evaluating a Function Call, (): could not find expected ':' while scanning
a simple key at line 2 column 1 at C:/manifests/init
.pp:3:15 on node xxxxx

Rancher error when setting a boolean field with an environment variable

I have a rancher-compose.yml file where I set the upgrade_strategy.start_first field using an environment variable like this:
upgrade_strategy:
start_first: ${START_FIRST}
batch_size: 1
When running using the rancher-compose CLI, I get the following error:
ERRO[0000] Failed to open project origami-svcproxy: yaml: unmarshal errors:
line 28: cannot unmarshal !!str `false` into bool
When running in debug I see the following yaml:
upgrade_strategy:
batch_size: 1
start_first: "false" # <-- notice the surrounding quotes, missing from the rest of the variable replacements
How can I set this field dynamically?
I had the same problem and used a different strategy to fix the issue. First step is to convert docker-compose.yml to a template, docker-compose.yml.tpl. Second, use template logic to fetch the value of the boolean variable.
upgrade_strategy:
start_first: {{ .Values.START_FIRST }}
batch_size: 1
Reference: https://github.com/rancher/rancher-catalog/blob/v1.6-development/infra-templates/ipsec/9/docker-compose.yml.tpl#L21

Resources