Che: Values from che.properties are not injected to Workspace, using Eclipse Che 4.7.2

Created on 21 Sep 2016  路  7Comments  路  Source: eclipse/che

According 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?

kinquestion

All 7 comments

@mariosotil - the docs talk about how to inject values into che.properties which go into the Che server. I don't think we ever talked about where you need to configure custom properties that go into a workspace. The workspaces have a different tomcat that is loaded (and thus entirely different properties that are loaded in the workspace itself).

@garagatyi @skabashnyuk @sleshchenko @vparfonov - can one of you take a look? It's not clear to me where to send someone if they want to customize the assembly to have custom properties loaded for the ws-agents instead of the Che server itself.

Get it, but please, I need a way to do that, to be able to pass values to a Server Extension (a ws-agent, right?). It's not necessary to do it with che.properties. I'm open to a different approach as long as it's configurable without need to rebuild the Extension again. Use cases could be to be able to set a webservice's URL, or a secret key.

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.

@eivantsov - can you take a look at the message. Some of the steps were not clear. The CHE_LOCAL_CONF_DIR value is used to configure how the Che server finds its properties. Can you provide some more details on how the ws-agent finds the right properties file? Or perhaps an example that shows how on the directory, you can have both a Che server and a workspace agent properties files - as different files - where to place them and what values to set.

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.

It totally worked. Thank you!

Was this page helpful?
0 / 5 - 0 ratings