CodenvyInContainerInfrastructureProvisioner extends DefaultInfrastructureProvisioner { @Override public void provision(EnvironmentImpl envConfig, CheServicesEnvironmentImpl internalEnv) throws EnvironmentException { String devMachineName = getDevMachineName(envConfig); if (devMachineName == null) { throw new EnvironmentException("ws-machine is not found on agents applying"); } CheServiceImpl devMachine = internalEnv.getServices().get(devMachineName); HashMap<String, String> environmentVars = new HashMap<>(devMachine.getEnvironment()); environmentVars.put(SYNC_KEY_ENV_VAR_NAME, pubSyncKey); environmentVars.put( CheBootstrap.CHE_LOCAL_CONF_DIR, DockerExtConfBindingProvider.EXT_CHE_LOCAL_CONF_DIR); devMachine.setEnvironment(environmentVars); ExtendedMachineImpl extendedMachine = envConfig.getMachines().get(devMachineName); List<String> agents = new ArrayList<>(extendedMachine.getAgents()); agents.add(agents.indexOf("org.eclipse.che.ws-agent"), "com.codenvy.rsync_in_machine"); extendedMachine.setAgents(agents); List<String> volumes = new ArrayList<>(devMachine.getVolumes()); volumes.add(projectFolder); devMachine.setVolumes(volumes); for (CheServiceImpl service : internalEnv.getServices().values()) { volumes = new ArrayList<>(service.getVolumes()); volumes.addAll( SNAPSHOT_EXCLUDED_DIRECTORIES); service.setVolumes(volumes); } super.provision(envConfig, internalEnv); } @Inject  CodenvyInContainerInfrastructureProvisioner(
      AgentConfigApplier agentConfigApplier,
      @Named("workspace.backup.public_key") String pubSyncKey,
      @Named("che.workspace.projects.storage") String projectFolder); @Override void provision(EnvironmentImpl envConfig, CheServicesEnvironmentImpl internalEnv); @Override void provision(ExtendedMachineImpl machineConfig, CheServiceImpl internalMachine); static final String SYNC_KEY_ENV_VAR_NAME; static final List<String> SNAPSHOT_EXCLUDED_DIRECTORIES; }
@Test public void shouldApplyAgentConfigOnSingleMachineProvisioning() throws Exception { provisioner.provision(extendedMachine, cheService); verify(agentConfigApplier).apply(extendedMachine, cheService); }
@Test( expectedExceptions = EnvironmentException.class, expectedExceptionsMessageRegExp = "test exception" ) public void shouldThrowEnvironmentExceptionIfAgentApplierThrowsAgentExceptionOnSingleMachineProvisioning() throws Exception { doThrow(new AgentException("test exception")) .when(agentConfigApplier) .apply(extendedMachine, cheService); provisioner.provision(extendedMachine, cheService); }
@Test( expectedExceptions = EnvironmentException.class, expectedExceptionsMessageRegExp = "ws-machine is not found on agents applying" ) public void shouldThrowEnvExceptionIfNoMachinesFoundInEnvironment() throws Exception { environment.setMachines(Collections.emptyMap()); provisioner.provision(environment, internalEnv); }
@Test( expectedExceptions = EnvironmentException.class, expectedExceptionsMessageRegExp = "ws-machine is not found on agents applying" ) public void shouldThrowEnvExceptionIfNoMachinesWithDevAgentFoundInEnvironment() throws Exception { environment.setMachines(singletonMap("machine1", extendedMachine)); extendedMachine.setAgents( asList( "org.eclipse.che.ws-agent2", "not.che.ws-agent", "org.eclipse.che.terminal", "org.eclipse.che.exec")); provisioner.provision(environment, internalEnv); }
@Test public void shouldAddSyncKeyEnvVariableInDevMachineOnEnvProvision() throws Exception { internalEnv.getServices().get(DEV_MACHINE_NAME).getEnvironment().put("test", "test1"); provisioner.provision(environment, internalEnv); assertEquals( internalEnv.getServices().get(DEV_MACHINE_NAME).getEnvironment().get("test"), "test1"); assertEquals( internalEnv .getServices() .get(DEV_MACHINE_NAME) .getEnvironment() .get(CodenvyInContainerInfrastructureProvisioner.SYNC_KEY_ENV_VAR_NAME), SYNC_KEY); }
@Test public void shouldAddLocalConfDirEnvVariableInDevMachineOnEnvProvision() throws Exception { internalEnv.getServices().get(DEV_MACHINE_NAME).getEnvironment().put("test", "test1"); provisioner.provision(environment, internalEnv); assertEquals( internalEnv.getServices().get(DEV_MACHINE_NAME).getEnvironment().get("test"), "test1"); assertEquals( internalEnv .getServices() .get(DEV_MACHINE_NAME) .getEnvironment() .get(CheBootstrap.CHE_LOCAL_CONF_DIR), DockerExtConfBindingProvider.EXT_CHE_LOCAL_CONF_DIR); }
@Test public void shouldAddRsyncAgentBeforeWsAgentInDevMachineOnEnvProvision() throws Exception { devExtendedMachine.setAgents( asList("org.eclipse.che.exec", "org.eclipse.che.terminal", "org.eclipse.che.ws-agent")); List<String> expectedAgents = asList( "org.eclipse.che.exec", "org.eclipse.che.terminal", "com.codenvy.rsync_in_machine", "org.eclipse.che.ws-agent"); provisioner.provision(environment, internalEnv); assertEquals(devExtendedMachine.getAgents(), expectedAgents); }
@Test public void shouldAddVolumeForProjectsFolderOnEnvironmentProvision() throws Exception { internalEnv.getServices().get(DEV_MACHINE_NAME).getVolumes().add("/some/volume"); internalEnv.getServices().get(DEV_MACHINE_NAME).getVolumes().add("/some/bind:/mount/volume"); provisioner.provision(environment, internalEnv); assertTrue( internalEnv.getServices().get(DEV_MACHINE_NAME).getVolumes().contains("/some/volume")); assertTrue( internalEnv .getServices() .get(DEV_MACHINE_NAME) .getVolumes() .contains("/some/bind:/mount/volume")); }
@Test public void shouldAddVolumesForExcludedFromSnapshotFoldersOnEnvironmentProvision() throws Exception { provisioner.provision(environment, internalEnv); assertTrue( internalEnv .getServices() .get(DEV_MACHINE_NAME) .getVolumes() .containsAll(SNAPSHOT_EXCLUDED_DIRECTORIES)); assertTrue( internalEnv .getServices() .get(NON_DEV_MACHINE_NAME) .getVolumes() .containsAll(SNAPSHOT_EXCLUDED_DIRECTORIES)); }
@Test public void shouldApplyAgentConfigToEnvironmentOnEnvironmentProvision() throws Exception { provisioner.provision(environment, internalEnv); verify(agentConfigApplier).apply(environment, internalEnv); }
@Test( expectedExceptions = EnvironmentException.class, expectedExceptionsMessageRegExp = "test exception" ) public void shouldThrowEnvironmentExceptionIfAgentApplierThrowsAgentExceptionOnEnvironmentProvisioning() throws Exception { doThrow(new AgentException("test exception")) .when(agentConfigApplier) .apply(environment, internalEnv); provisioner.provision(environment, internalEnv); }