Values from che.properties are not injected to Workspace, using Eclipse Che 4.7.2
See original GitHub issueAccording to https://eclipse-che.readme.io/docs/che-properties, I should be able to inject values using che.properties
. It turns out it’s not working. The service which is running into a Workspace, can’t find the variable.
This is what I did:
I added this line to che.properties
important.variable=some_value
I modified my service
@Path("api")
class MyExtensionService {
@Inject
@Named("important.variable")
String importantVariable;
[...]
}
When I tried to fire up a Workspace, I got this error on the Default window.
2016-09-20 21:50:06,039[ost-startStop-1] [ERROR] [o.m.c.c.C.[.[.[/wsagent] 4818] - Exception sending context initialized event to listener instance of class org.eclipse.che.inject.CheBootstrap
com.google.inject.CreationException: Unable to create injector, see the following errors:
1) No implementation for java.lang.String annotated with @com.google.inject.name.Named(value=important.variable) was bound.
while locating java.lang.String annotated with @com.google.inject.name.Named(value=important.variable)
for field at com.mycompany.che.plugins.MyExtensionService.importantVariable(MyExtensionService.java:26)
at com.mycompany.che.plugins.MyExtensionGuiceModule.configure(MyExtensionGuiceModule.java:13)
1 error
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:470) ~[guice-4.1.0.jar:na]
at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:155) ~[guice-4.1.0.jar:na]
To be sure about what was happening, I modified CheBootstrap.java
adding a few logging lines
public class CheBootstrap extends EverrestGuiceContextListener {
// […]
protected <K, V> void bindProperties(String prefix, Iterable<Map.Entry<K, V>> properties, boolean skipUnresolved) {
LOG.info(String.format("PROPERTIES=%s", properties.toString())); // <====
StringBuilder buf = null;
for (Map.Entry<K, V> e : properties) {
String pValue = (String)e.getValue();
if ("NULL".equals(pValue)) {
LOG.info(String.format("PROPERTY %s%s = %s", prefix == null ? "": prefix, e.getKey(), "NULL")); // <====
bind(String.class).annotatedWith(Names.named(prefix == null ? (String)e.getKey() : (prefix + e.getKey())))
.toProvider(Providers.<String>of(null));
} else {
// […]
LOG.info(String.format("PROPERTY %s%s = %s", prefix == null ? "": prefix, e.getKey(), pValue)); // <====
bindConstant().annotatedWith(Names.named(prefix == null ? (String)e.getKey() : (prefix + e.getKey()))).to(pValue);
}
}
}
}
}
I rebuilt Eclipse Che and ran it again.
In the console log of Che Server, you can see Che reads the che.properties
file and inject the property.
2016-09-20 17:20:23,025[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 224] - PROPERTIES=[machine.logs.location=${che.logs.dir}/machine/logs, che.stacks.images.storage=${che.home}/stacks/images, oauth.github.tokenuri=https://github.com/login/oauth/access_token, machine.server.terminal.path_to_archive.linux_amd64=${che.home}/lib/linux_amd64/terminal, che.conf.storage=${che.home}/storage, machine.ws_agent.ping_timed_out_error_msg=Timeout reached. The Che server has been unable to verify that your workspace's agent has successfully booted. Either the workspace is unreachable, the agent had an error during startup, or your workspace is starting slowly. You can configure machine.ws_agent.max_start_time_ms in Che properties to increase the timeout., che.machine.java_opts=-Xms256m -Xmx2048m -Djava.security.egd=file:/dev/./urandom, docker.api.version=1.20, machine.docker.registry=${CHE_REGISTRY_HOST}:5000, che.machine.projects.internal.storage=/projects, workspace.runtime.auto_restore=true, machine.docker.unused_containers_cleanup_period_min=60, machine.ws_agent.ping_delay_ms=2000, user.reserved_names=, che.stacks.default=${che.home}/stacks/stacks.json, machine.docker.machine_extra_hosts=NULL, org.everrest.asynchronous.queue.size=500, auth.oauth.access_denied_error_page=/error-oauth, docker.connection.tcp.connection_timeout_ms=600000, machine.docker.snapshot.registry_namespace=NULL, oauth.github.authuri=https://github.com/login/oauth/authorize, machine.docker.privilege_mode=false, schedule.core_pool_size=10, user.self.creation.allowed=false, machine.server.ext.archive=${che.home}/lib/ws-agent.zip, machine.docker.memory_swap_multiplier=-1, https.proxy=, workspace.runtime.auto_snapshot=true, org.everrest.asynchronous=false, oauth.github.redirecturis=http://localhost:${SERVER_PORT}/wsmaster/api/oauth/callback, org.everrest.asynchronous.pool.size=20, machine.ws_agent.max_start_time_ms=60000, docker.connection.tcp.read_timeout_ms=600000, important.variable=some_value, machine.ws_agent.ping_conn_timeout_ms=2000, org.everrest.asynchronous.cache.size=1024, che.workspace.storage=${che.home}/workspaces, no_proxy=, oauth.github.clientid=xxxxxxx, machine.ssh.connection_timeout_ms=10000, machine.docker.snapshot_use_registry=false, project.template_description.location_dir=${che.home}/templates, org.everrest.asynchronous.service.path=/async/, machine.docker.che_api.endpoint=http://che-host:${SERVER_PORT}/wsmaster/api, org.everrest.asynchronous.job.timeout=10, oauth.github.clientsecret=xxxxxxxx, notification.server.propagate_events=, machine.server.terminal.path_to_archive.linux_arm7=${che.home}/lib/linux_arm7/terminal, machine.default_mem_size_mb=1024, http.proxy=, machine.docker.local_node_host=NULL, machine.docker.pull_image=true, api.endpoint=http://localhost:${SERVER_PORT}/wsmaster/api]
[...]
2016-09-20 17:20:23,034[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY important.variable = some_value
BUT at the Workspace’s log, the property is not injected. It looks like the Workspace uses a totally different che.properties
file.
2016-09-20 21:50:04,145[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 224] - PROPERTIES=[vfs.local.tmp_workspace_fs_root_dir=${catalina.base}/temp/tmp-ws-fs-root, oauth.github.clientid=***, vfs.local.fs_index_root_dir=${catalina.base}/temp/indexes, oauth.github.redirecturis=http://localhost:${SERVER_PORT}/che/api/oauth/callback, oauth.github.tokenuri=https://github.com/login/oauth/access_token, org.everrest.asynchronous.job.timeout=10, git.server.uri.prefix=git, org.everrest.asynchronous.queue.size=500, org.everrest.asynchronous.cache.size=1024, project.importer.default_importer_id=git, vfs.local.directory_mapping_file=${catalina.base}/temp/vfs, org.everrest.asynchronous.pool.size=20, vfs.local.id=1q2w3e, user.local.db=NULL, che.user.workspaces.storage=/projects, che.maven.server.path=${catalina.base}/maven-server, che.workspace.metadata=che/.workspace, org.everrest.asynchronous.service.path=/async/, oauth.github.clientsecret=***, schedule.core_pool_size=10, oauth.github.authuri=https://github.com
login/oauth/authorize, org.everrest.asynchronous=false]
2016-09-20 21:50:04,150[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY vfs.local.tmp_workspace_fs_root_dir = /home/user/che/ws-agent/temp/tmp-ws-fs-root
2016-09-20 21:50:04,152[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY oauth.github.clientid = ***
2016-09-20 21:50:04,154[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY vfs.local.fs_index_root_dir = /home/user/che/ws-agent/temp/indexes
2016-09-20 21:50:04,156[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY oauth.github.redirecturis = http://localhost:8080/che/api/oauth/callback
2016-09-20 21:50:04,158[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY oauth.github.tokenuri = https://github.com/login/oauth/access_token
2016-09-20 21:50:04,159[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY org.everrest.asynchronous.job.timeout = 10
2016-09-20 21:50:04,160[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY git.server.uri.prefix = git
2016-09-20 21:50:04,161[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY org.everrest.asynchronous.queue.size = 500
2016-09-20 21:50:04,165[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY org.everrest.asynchronous.cache.size = 1024
2016-09-20 21:50:04,166[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY project.importer.default_importer_id = git
2016-09-20 21:50:04,168[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY vfs.local.directory_mapping_file = /home/user/che/ws-agent/temp/vfs
2016-09-20 21:50:04,171[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY org.everrest.asynchronous.pool.size = 20
2016-09-20 21:50:04,173[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY vfs.local.id = 1q2w3e
2016-09-20 21:50:04,175[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 230] - PROPERTY user.local.db = NULL
2016-09-20 21:50:04,177[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY che.user.workspaces.storage = /projects
2016-09-20 21:50:04,178[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY che.maven.server.path = /home/user/che/ws-agent/maven-server
2016-09-20 21:50:04,179[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY che.workspace.metadata = che/.workspace
2016-09-20 21:50:04,182[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY org.everrest.asynchronous.service.path = /async/
2016-09-20 21:50:04,183[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY oauth.github.clientsecret = ***
2016-09-20 21:50:04,184[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY schedule.core_pool_size = 10
2016-09-20 21:50:04,187[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY oauth.github.authuri = https://github.com/login/oauth/authorize
2016-09-20 21:50:04,189[ost-startStop-1] [INFO ] [o.e.che.inject.CheBootstrap 266] - PROPERTY org.everrest.asynchronous = false
As you can see, the value added to che.properties
is injected in the server, but not in the Workspace. Am I doing wrong? May you help me, please?
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
Ok - it is clear for me now.
Che server (in the docker container) loads its properties from:
CHE_LOCAL_CONF_DIR
.If you are using the CLI, this value is
CHE_CONF_DIR
, as the name is simpler.If you want custom properties to be loaded within a workspace, then those properties must be saved in:
CHE_CONF_DIR\plugin-conf\
.I will add some notes to the docs about this point.
If you need to provide custom properties to ws-agent, you should either add it in your assembly here https://github.com/eclipse/che/blob/master/assembly/assembly-wsagent-war/src/main/webapp/WEB-INF/classes/codenvy/che-machine-configuration.properties or inject it yourself:
Create a directory to host conf files
`mkdir -p /home/$user/.che/plugin-conf
export CHE_LOCAL_CONF_DIR=/home/$user/.che
Create props file
~/.che/plugin-conf/che.properties
Provide your property and its value there.
Restart Che. When launching a workspace, this file should be mounted into a workspace container and ws-agent should pick it up.