@VisibleForTesting void addRamAttributes( Map<String, InternalMachineConfig> machines, Map<String, ComposeService> services) throws InfrastructureException { for (Entry<String, ComposeService> entry : services.entrySet()) { InternalMachineConfig machineConfig; if ((machineConfig = machines.get(entry.getKey())) == null) { machineConfig = new InternalMachineConfig(); machines.put(entry.getKey(), machineConfig); } memoryProvisioner.provision( machineConfig, entry.getValue().getMemLimit(), entry.getValue().getMemRequest()); } }
@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()); } }
/** * Checks whether provided {@link InternalMachineConfig} contains wsagent installer or server. * * @param machineConfig machine config to check * @return true when wsagent server or installer is found in provided machine, false otherwise */ public static boolean containsWsAgentServerOrInstaller(InternalMachineConfig machineConfig) { return machineConfig.getServers().keySet().contains(SERVER_WS_AGENT_HTTP_REFERENCE) || InstallerFqn.idInInstallerList(WS_AGENT_INSTALLER, machineConfig.getInstallers()); }
new InternalMachineConfig( installers, normalizeServers(machineConfig.getServers()), .getMachines() .values() .forEach(m -> m.getAttributes().put(CONTAINER_SOURCE_ATTRIBUTE, RECIPE_CONTAINER_SOURCE));
machineName); if (machineConfig.getServers() != null) { for (Map.Entry<String, ? extends ServerConfig> serverEntry : machineConfig.getServers().entrySet()) { String serverName = serverEntry.getKey(); ServerConfig server = serverEntry.getValue(); if (machineConfig.getAttributes() != null) { String memoryLimit = machineConfig.getAttributes().get(MEMORY_LIMIT_ATTRIBUTE); String memoryRequest = machineConfig.getAttributes().get(MEMORY_REQUEST_ATTRIBUTE); if (memoryLimit != null && memoryRequest != null) { checkArgument(
final Map<String, String> attributes = machineConfig.getAttributes(); String configuredLimit = attributes.get(MEMORY_LIMIT_ATTRIBUTE); String configuredRequest = attributes.get(MEMORY_REQUEST_ATTRIBUTE);
@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()); } } }
/** * Checks whether provided {@link InternalMachineConfig} contains wsagent server. * * @param machineConfig machine config to check * @return true when wsagent server is found in provided machine, false otherwise */ public static boolean containsWsAgentServer(InternalMachineConfig machineConfig) { return machineConfig.getServers().keySet().contains(SERVER_WS_AGENT_HTTP_REFERENCE); }
@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); } }
@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()); } }
@VisibleForTesting void addRamAttributes(Map<String, InternalMachineConfig> machines, Collection<Pod> pods) { for (Pod pod : pods) { for (Container container : pod.getSpec().getContainers()) { final String machineName = Names.machineName(pod, container); InternalMachineConfig machineConfig; if ((machineConfig = machines.get(machineName)) == null) { machineConfig = new InternalMachineConfig(); machines.put(machineName, machineConfig); } memoryProvisioner.provision( machineConfig, Containers.getRamLimit(container), Containers.getRamRequest(container)); } } }