I am using spring-cloud-config-server with SVN as repository. When I start the cloud-config-server and client[microservice], configuration value is picked up properly.
After changing a configuration value and SVN commit, I am firing refresh POST call, URL: http://localhost:8080/actuator/refresh [8080 is client port]. The updated value in SVN is not getting refreshed.
It is known that config-server stores the SVN data locally.[In my case, folder location - /tmp/config-repo-5393789580706388886] The strange thing here is that, the committed change in SVN is updated locally, once the 'refresh' REST call is triggered. But it is just that application is not picking it up.
Spring boot version - 2.1.3.
Cloud version - Greenwich Release.
Config-Server Details:
Maven dependency:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
</dependency>
application.yml:
spring:
application:
name: spring-cloud-config-server
profiles:
active: subversion
cloud:
config:
server:
svn:
uri: https://svn.*****.com/repos/****/microservices
username: #####
password: #####
default-label: source
server:
port: 8888
config-client[microservice] details:
Maven dependency:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
application.yml:
spring:
application:
name: [client-app-name]
cloud:
config:
uri: http://localhost:8888
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
security:
enabled: false
server:
port: 8080
While starting the config-client microservice, able to see that it is fetching the values from the expected SVN location via config-server.
c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
c.c.c.ConfigServicePropertySourceLocator : Located environment: name=[client-app-name], profiles=[default], label=null, version=10718, state=null
b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='configClient'}, MapPropertySource {name='https://svn.*****.com/repos/****/microservices/source/[client-app-name].properties'}]}
While invoking the test REST call to get the configuration value from config client, I am getting the value from SVN.
After doing the change in the file , [client-app-name].properties and committing to SVN. While doing the REST call http://localhost:8080/actuator/refresh, getting the following as response, which is as expected.
[]-bash-4.2$ curl -X POST http://localhost:9000/actuator/refresh
["config.client.version","configValue"]-bash-4.2$
At the same time, getting the following message from logs as expected.
c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
c.c.c.ConfigServicePropertySourceLocator : Located environment: name=[client-app-name], profiles=[default], label=null, version=10718, state=null
b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='configClient'}, MapPropertySource {name='https://svn.*****.com/repos/****/microservices/source/[client-app-name].properties'}]}
The REST call to the config-client , to fetch the updated configuration just returning the previous configuration value.
If I restart the client, it is picking up the updated latest configuration. Also, the SVN change in updated locally[In my case, folder location - /tmp/config-repo-5393789580706388886]
I am really not able to find out the mistake I did. Any inputs to resolve this would be very much helpful. Thanks a lot.
Did you set #RefreshScope annotation to your Component?
For example, TestProperties is the #ConfigurationProperites that have configValue.
#Bean
public TestComponent(TestProperties properties) {
return new TestComponent(properties.getConfigValue());
}
If you are using raw configValue like above example, you have to annotate it.
#Bean
public TestComponent(TestProperties properties) {
return new TestComponent(properties);
}
If you are using properties as it is, it would be refreshed.
Related
I'm trying out RedHat's Business Central using a docker-compose file as described in https://github.com/jboss-dockerfiles/business-central. At startup it runs a kie-server (quay.io/kiegroup/kie-server-showcase:7.67.0.Final) and a business-central webserver (quay.io/kiegroup/business-central-workbench-showcase:7.67.0.Final).
Because I'm only interested in the drools part and not the jbpm part, I starting the business-central server with -Dorg.kie.workbench.profile=PLANNER_AND_RULES as described in https://docs.jboss.org/drools/release/7.67.0.Final/drools-docs/html_single/#_selecting_a_profile
After login with admin I receive the following error:
business-central_1 | 18:11:13,321 ERROR [org.kie.workbench.common.services.backend.logger.GenericErrorLoggerServiceImpl] (default task-2) Error from user: admin Error ID: -1427996616 Location: HomePerspective|org.kie.workbench.common.screens.home.client.HomePresenter Exception: Uncaught exception: Client-side exception occurred although RPC call succeeded. Caused by: The profile is not expected and profile to define product name
Below, you can find the docker-compose file used:
version: "3.2"
services:
business-central:
image: quay.io/kiegroup/business-central-workbench-showcase:7.67.0.Final
ports:
- "8090:8080"
- "8091:8001"
environment:
KIE_SERVER_LOCATION: http://kie-server:8080/kie-server/services/rest/server
JAVA_OPTS: "-Xms256m -Xmx2048m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=512m -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8 -Dorg.kie.workbench.profile=PLANNER_AND_RULES"
kie-server:
image: quay.io/kiegroup/kie-server-showcase:7.67.0.Final
environment:
KIE_SERVER_ID: sample-server
KIE_SERVER_LOCATION: http://kie-server:8080/kie-server/services/rest/server
KIE_SERVER_CONTROLLER: http://business-central:8080/business-central/rest/controller
KIE_MAVEN_REPO: http://business-central:8080/business-central/maven2
ports:
- "8092:8080"
depends_on:
- business-central
volumes:
business-central_data:
UPDATE: on 2022-04-07
I also looked at the source code in github but couldn't find any reference to PLANNER_AND_RULES. I looked at several repo's in https://github.com/kiegroup/:
https://github.com/kiegroup/drools
https://github.com/kiegroup/droolsjbpm-build-bootstrap
https://github.com/kiegroup/droolsjbpm-knowledge
https://github.com/kiegroup/kie-soup
I have no idea how where to look for ;-(.
I found a very disturbing picture on explaining all the repo's that are being used, but it would be good if someone pointed out what repo to look for :-).
"ResourceLoader" with AWS S3 works fine with these properties:
cloud:
aws:
s3:
endpoint: s3.amazonaws.com <-- custom endpoint added in spring cloud aws 2.3
credentials:
accessKey: XXXXXX
secretKey: XXXXXX
region:
static: us-east-1
stack:
auto: false
However, when I bring up a localstack container locally and try to use it with these properties(as per this release doc: https://spring.io/blog/2021/03/17/spring-cloud-aws-2-3-is-now-available):
cloud:
aws:
s3:
endpoint: http://localhost:4566
credentials:
accessKey: test
secretKey: test
region:
static: us-east-1
stack:
auto: false
I get this exception:
17:12:12.130 [reactor-http-nio-2] ERROR org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler - [23efd000-1] 500 Server Error for HTTP GET "/getresource/test"
com.amazonaws.SdkClientException: Unable to execute HTTP request: mybucket.localhost
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleRetryableException(AmazonHttpClient.java:1207) ~[aws-java-sdk-core-1.11.951.jar:?]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ HTTP GET "/getresource/test" [ExceptionHandlingWebHandler]
Stack trace:
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleRetryableException(AmazonHttpClient.java:1207) ~[aws-java-sdk-core-1.11.951.jar:?]
Caused by: java.net.UnknownHostException: mybucket.localhost
at java.net.InetAddress$CachedAddresses.get(InetAddress.java:797) ~[?:?]
I can view my localstack bucket files otherwise fine in an S3 browser.
Here is the docker compose config for my localstack:
version: '3.1'
services:
localstack:
image: localstack/localstack:latest
environment:
- AWS_DEFAULT_REGION=us-east-1
- AWS_ACCESS_KEY_ID=test
- AWS_SECRET_ACCESS_KEY=test
- EDGE_PORT=4566
- SERVICES=lambda,s3
ports:
- '4566-4583:4566-4583'
volumes:
- "${TEMPDIR:-/tmp/localstack}:/tmp/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
Here is how I am reading a text file:
public class ResourceTransferManager {
#Autowired
ResourceLoader resourceLoader;
public void resourceLoadingMethod() throws IOException {
Resource resource = resourceLoader.getResource("s3://mybucket/index.txt");
InputStream inputStream = resource.getInputStream();
System.out.println("File content: " + IOUtils.toString(inputStream, StandardCharsets.UTF_8));
}}
By default S3 client creates a path having bucket name as subdomain and this causes the issue.
there are couple of ways to address this issue :
In case of localstack , do not use the endpoint http://localhost:4566 , use the standard formate endpoint i.e : http://s3.localhost.localstack.cloud:4566 , this will actualy reachout to DNS and will resolve into localhost IP internally and thus this will work fine. (only caviate it , it resolve using public DNS thus it either needs internet connection or you will need to make host entries prefixing bucketname for example in host file put 127.0.0.1 <yourexpectedbucketName>.s3.localhost.localstack.cloud).
OR if you are using docker then instead of making host entries , you can also create network alias for your localstack container like : <yourexpectedbucketName>.s3.localhost.localstack.cloud
another better way is extension to first approach , but here instead of using aliases for each of your bucket (which may not always be feasible) , you can spin up local dns container and use wildcard dns config there. refer simplified sample at : https://gist.github.com/paraspatidar/c29e4adb172a5afc92852a57e621323d
( original reference : https://gist.github.com/NAR8789/92da076d0c35b434107fb4f4f198fd12)
I have created a JHipster microservices application and want to do some frontend development on it. Launching the whole microservices stack in the ./docker-compose/ directory with docker-compose up -d works as expected. Registry shows all microservices, the gateway and an UAA instance with status 'up'. No exceptions thrown. Login to http://localhost:8080 works as expected.
Launching yarn start in the gateway project directory launches the development server via webpack and browsersync. Hot reload works as expected when pointing the browser at http://localhost:9000.
Now to my problem/question: logging into http://localhost:9000 as user/user doesn't work, as the account cannot be retrieved. The thrown exception is irrelevant because it just states that the account is null:
webpack-internal:///…fesm5/core.js:16064 ERROR Error: Uncaught (in promise):
TypeError: Cannot read property 'langKey' of null
TypeError: Cannot read property 'langKey' of null
at LoginService.setPreferredLanguage (webpack-internal:///…
login.service.ts:34)
....
But when I point the browser back to http://localhost:8080, I'm logged in as 'user'. Which means that the login on the backend worked.
Being new to docker and microservices, I'm suspecting that I'm conceptually missing something (networks/ports/etc..). Any ideas that could point to finding a solution? Or what is the suggested setup/practices for developing the frontend in a JHipster/microservices configuration.
There has been an error in the webpack.dev.js configuration file and because UAA was added later to the project, the UAA module was missing in the contexts to be proxies:
devServer: {
contentBase: './build/www',
proxy: [{
context: [
'/microservice1',
'/microservice2',
'/microserviceuaa', /* !!! was missing !!! */
/* jhipster-needle-add-entity-to-webpack - JHipster will add entity api paths here */
'/api',
'/management',
'/swagger-resources',
'/v2/api-docs',
'/h2-console',
'/auth'
],
target: `http${options.tls ? 's' : ''}://127.0.0.1:8080`,
secure: false,
changeOrigin: options.tls,
headers: { host: 'localhost:9000' }
}],
I have a ConfigServer, very basic:
#EnableConfigServer
#SpringBootApplication
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
I'm using spring-cloud-config-server:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
And I expect it to work the same when deployed to Pivotal Web Services as when I run it locally.
I deployed my configs to a public server with encrypted keys:
spring:
cloud:
config:
server:
git:
uri: https://mypublic.domain/gitbasedconfig
And in my bootstrap.yml, application.yml I have a property with the key:
encrypt:
key: my.super.secret.symmetric.key
This all works locally:
curl http://localhost:8888/myservice/default
responds with all of my encrypted passwords decrypted properly.
When I deploy the same artifact to PWS with the following manifest.yml:
---
applications:
- name: myservice
memory: 384M
disk: 384M
buildpack: java_buildpack
path: target/myservice.jar
env:
ENCRYPT_KEY: my.super.secret.symmetric.key
If I deploy with or without the env->ENCRYPT_KEY neither work. When I call the service, all of my encrypted keys are returned as
invalid.my.key.name: "<n/a>",
In the PWS logs I can see this:
Fri May 20 2016 13:26:21 GMT-0500 (CDT) [APP] OUT {"timeMillis":1463768781279,"thread":"http-nio-8080-exec-4","level":"WARN","loggerName":"org.springframework.cloud.config.server.encryption.CipherEnvironmentEncryptor","message":"Cannot decrypt key: my.key.name (class java.lang.IllegalArgumentException: Unable to initialize due to invalid secret key)","endOfBatch":false,"loggerFqcn":"org.apache.commons.logging.impl.SLF4JLocationAwareLog","contextMap":[],"source":{"class":"org.springframework.cloud.config.server.encryption.CipherEnvironmentEncryptor","method":"decrypt","file":"CipherEnvironmentEncryptor.java","line":81}}
When I look at the http://myservice.on.pws/env I can see that there are values for encrypt.key in both application.yml, bootstrap.yml and I can also see the environment value. These are all the same value.
Why are my encrypted values not being decrypted properly when I'm providing the symmetric key value in both the properties files and/or the environment? Is there some other property that I need to add to make this work on PWS? The non-encrypted values are working properly within the same configs, so everything is wired properly. It's just the encrypted values that are not working.
I think that Spencergibb and Vinicius Carvalho were both correct.
The Java Cryptopgraphy Extensions can't be distributed with the standard java buildpack.
The Pivotal Support site provided a possible solution which is to fork the javabuildpack and update it to include the proper permissions for JCE. The deploy the application with the custom buildpack. One caveat is that you/I won't get the automatic updates.
https://support.run.pivotal.io/entries/76559625-How-do-I-use-the-JCE-Unlimited-Strength-policy-with-my-Java-app-
I understand that the config server needs to be up to bootstrap any of its clients.
Is there any way we can embed both Spring config Server and client in the same application so that each application could protect its sensitive information easily? If it is possible, I will use server for reading properties from the git and client for the decryption.
This flow works with me:
Step 1: Use only Config Server dependency:
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
Step 2: Enable Config Server via#EnableConfigServer annotation.
Step 3: In bootstrap.yml file (not application.yml), we will configure:
spring:
cloud:
config:
server:
# This flag indicates that the server should configure itself from its own remote repository
bootstrap: true
git:
uri: https://github.com/your-git-account/your-config-repository
username: user
password: secret
searchPaths: foo,bar*
timeout: 10
# prefix string to avoid conflicting with context/server path of application
prefix: config
Step 4: Remove all configurations related to Config Server in application.yml file.
If I understand you correctly, all that you'd need to do is add the #EnableConfigServer annotation and set spring.cloud.config.server.bootstrap=true. For detail see Embedding the Config Server and spring-cloud-config issue 100.