@Override public void provision(RuntimeIdentity id, InternalEnvironment internalEnvironment) throws InfrastructureException { LOG.debug("Provisioning machine names for workspace '{}'", id.getWorkspaceId()); for (Entry<String, InternalMachineConfig> machineEntry : internalEnvironment.getMachines().entrySet()) { machineEntry.getValue().getEnv().put(CHE_MACHINE_NAME_ENV_VAR, machineEntry.getKey()); } } }
/** * Finds machine in provided environment which contains wsagent server. * * @param environment environment to find a machine with the wsagent server * @return {@link Optional} with name of the machine which contains wsagent server or empty if * such machine is not present in provided environment * @throws IllegalArgumentException if more than 1 machine with the wsagent server are found */ public static Optional<String> getWsAgentServerMachine(InternalEnvironment environment) { List<String> machinesWithWsAgentServer = environment .getMachines() .entrySet() .stream() .filter(entry -> containsWsAgentServer(entry.getValue())) .map(Map.Entry::getKey) .collect(Collectors.toList()); if (machinesWithWsAgentServer.isEmpty()) { return Optional.empty(); } if (machinesWithWsAgentServer.size() == 1) { return Optional.of(machinesWithWsAgentServer.get(0)); } throw new IllegalArgumentException( format( "Environment contains '%s' machines with wsagent server. Machines names: '%s'", machinesWithWsAgentServer.size(), machinesWithWsAgentServer)); }
@Override public void provision(RuntimeIdentity id, InternalEnvironment internalEnvironment) throws InfrastructureException { LOG.debug("Provisioning environment variables for workspace '{}'", id.getWorkspaceId()); for (EnvVarProvider envVarProvider : envVarProviders) { Pair<String, String> envVar = envVarProvider.get(id); if (envVar != null) { internalEnvironment .getMachines() .values() .forEach(m -> m.getEnv().putIfAbsent(envVar.first, envVar.second)); } } LOG.debug("Environment variables provisioning done for workspace '{}'", id.getWorkspaceId()); } }
@Override public void provision(RuntimeIdentity id, InternalEnvironment internalEnvironment) throws InfrastructureException { LOG.debug("Provisioning project volumes for workspace '{}'", id.getWorkspaceId()); Optional<String> wsAgentServerMachine = WsAgentMachineFinderUtil.getWsAgentServerMachine(internalEnvironment); if (wsAgentServerMachine.isPresent()) { InternalMachineConfig machineConfig = internalEnvironment.getMachines().get(wsAgentServerMachine.get()); machineConfig .getVolumes() .put(PROJECTS_VOLUME_NAME, new VolumeImpl().withPath(projectFolderPath)); } } }
/** * Parses (and fetches if needed) recipe of environment and sums RAM size of all machines in * environment in megabytes. */ public long calculate(@Nullable Environment environment) throws ServerException { if (environment == null) { return 0; } try { return getInternalEnvironment(environment) .getMachines() .values() .stream() .mapToLong( m -> parseMemoryAttributeValue(m.getAttributes().get(MEMORY_LIMIT_ATTRIBUTE))) .sum() / BYTES_TO_MEGABYTES_DIVIDER; } catch (InfrastructureException | ValidationException | NotFoundException ex) { throw new ServerException(ex.getMessage(), ex); } }
protected InternalEnvironment(InternalEnvironment internalEnvironment) { this.recipe = internalEnvironment.getRecipe(); this.type = recipe != null ? recipe.getType() : null; this.machines = internalEnvironment.getMachines(); this.warnings = new CopyOnWriteArrayList<>(internalEnvironment.getWarnings()); this.attributes = internalEnvironment.getAttributes(); this.commands = internalEnvironment.getCommands(); }
@Override public void provision(RuntimeIdentity id, InternalEnvironment internalEnvironment) throws InfrastructureException { for (InternalMachineConfig machineConfig : internalEnvironment.getMachines().values()) { LOG.debug("Start provisioning installer configs for workspace '{}'", id.getWorkspaceId()); fillEnv(machineConfig.getEnv(), machineConfig.getInstallers()); fillServers(id.getWorkspaceId(), machineConfig.getServers(), machineConfig.getInstallers()); } }
.getMachines() .values() .forEach(m -> m.getAttributes().put(CONTAINER_SOURCE_ATTRIBUTE, RECIPE_CONTAINER_SOURCE));