use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project devspaces-images by redhat-developer.
the class KubernetesPluginsToolingApplier method apply.
@Override
public void apply(RuntimeIdentity runtimeIdentity, InternalEnvironment internalEnvironment, Collection<ChePlugin> chePlugins) throws InfrastructureException {
if (chePlugins.isEmpty()) {
return;
}
KubernetesEnvironment k8sEnv = (KubernetesEnvironment) internalEnvironment;
Map<String, PodData> pods = k8sEnv.getPodsData();
switch(pods.size()) {
case 0:
addToolingPod(k8sEnv);
pods = k8sEnv.getPodsData();
break;
case 1:
break;
default:
throw new InfrastructureException("Che plugins tooling configuration can be applied to a workspace with one pod only");
}
PodData pod = pods.values().iterator().next();
CommandsResolver commandsResolver = new CommandsResolver(k8sEnv);
for (ChePlugin chePlugin : chePlugins) {
Map<String, ComponentImpl> devfilePlugins = k8sEnv.getDevfile().getComponents().stream().filter(c -> c.getType().equals("cheEditor") || c.getType().equals("chePlugin")).collect(Collectors.toMap(ComponentImpl::getId, Function.identity()));
if (!devfilePlugins.containsKey(chePlugin.getId())) {
throw new InfrastructureException(String.format("The downloaded plugin '%s' configuration does not have the " + "corresponding component in devfile. Devfile contains the following cheEditor/chePlugins: %s", chePlugin.getId(), devfilePlugins.keySet()));
}
ComponentImpl pluginRelatedComponent = devfilePlugins.get(chePlugin.getId());
for (CheContainer container : chePlugin.getInitContainers()) {
Container k8sInitContainer = toK8sContainer(container);
envVars.apply(k8sInitContainer, pluginRelatedComponent.getEnv());
chePluginsVolumeApplier.applyVolumes(pod, k8sInitContainer, container.getVolumes(), k8sEnv);
pod.getSpec().getInitContainers().add(k8sInitContainer);
}
Collection<CommandImpl> pluginRelatedCommands = commandsResolver.resolve(chePlugin);
for (CheContainer container : chePlugin.getContainers()) {
addSidecar(pod, container, chePlugin, k8sEnv, pluginRelatedCommands, pluginRelatedComponent, runtimeIdentity);
}
}
chePlugins.forEach(chePlugin -> populateWorkspaceEnvVars(chePlugin, k8sEnv));
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project devspaces-images by redhat-developer.
the class FactoryDaoTest method createWorkspaceConfig.
private static WorkspaceConfigImpl createWorkspaceConfig(int index) {
// Project Sources configuration
final SourceStorageImpl source1 = new SourceStorageImpl();
source1.setType("type1");
source1.setLocation("location1");
source1.setParameters(new HashMap<>(ImmutableMap.of("param1", "value1")));
final SourceStorageImpl source2 = new SourceStorageImpl();
source2.setType("type2");
source2.setLocation("location2");
source2.setParameters(new HashMap<>(ImmutableMap.of("param4", "value1")));
// Project Configuration
final ProjectConfigImpl pCfg1 = new ProjectConfigImpl();
pCfg1.setPath("/path1");
pCfg1.setType("type1");
pCfg1.setName("project1");
pCfg1.setDescription("description1");
pCfg1.getMixins().addAll(asList("mixin1", "mixin2"));
pCfg1.setSource(source1);
final ProjectConfigImpl pCfg2 = new ProjectConfigImpl();
pCfg2.setPath("/path2");
pCfg2.setType("type2");
pCfg2.setName("project2");
pCfg2.setDescription("description2");
pCfg2.getMixins().addAll(asList("mixin3", "mixin4"));
pCfg2.setSource(source2);
final List<ProjectConfigImpl> projects = new ArrayList<>(asList(pCfg1, pCfg2));
// Commands
final CommandImpl cmd1 = new CommandImpl("name1", "cmd1", "type1");
cmd1.getAttributes().putAll(ImmutableMap.of("key1", "value1"));
final CommandImpl cmd2 = new CommandImpl("name2", "cmd2", "type2");
cmd2.getAttributes().putAll(ImmutableMap.of("key4", "value4"));
final List<CommandImpl> commands = new ArrayList<>(asList(cmd1, cmd2));
// Machine configs
final MachineConfigImpl exMachine1 = new MachineConfigImpl();
final ServerConfigImpl serverConf1 = new ServerConfigImpl("2265", "http", "/path1", singletonMap("key", "value"));
final ServerConfigImpl serverConf2 = new ServerConfigImpl("2266", "ftp", "/path2", singletonMap("key", "value"));
exMachine1.setServers(ImmutableMap.of("ref1", serverConf1, "ref2", serverConf2));
exMachine1.setAttributes(singletonMap("att1", "val"));
exMachine1.setEnv(singletonMap("CHE_ENV", "value"));
final MachineConfigImpl exMachine2 = new MachineConfigImpl();
final ServerConfigImpl serverConf3 = new ServerConfigImpl("2333", "https", "/path1", singletonMap("key", "value"));
final ServerConfigImpl serverConf4 = new ServerConfigImpl("2334", "wss", "/path2", singletonMap("key", "value"));
exMachine2.setServers(ImmutableMap.of("ref1", serverConf3, "ref2", serverConf4));
exMachine2.setAttributes(singletonMap("att1", "val"));
exMachine2.setEnv(singletonMap("CHE_ENV2", "value"));
final MachineConfigImpl exMachine3 = new MachineConfigImpl();
final ServerConfigImpl serverConf5 = new ServerConfigImpl("2333", "https", "/path3", singletonMap("key", "value"));
exMachine3.setServers(singletonMap("ref1", serverConf5));
exMachine3.setAttributes(singletonMap("att1", "val"));
exMachine3.setEnv(singletonMap("CHE_ENV3", "value"));
// Environments
final RecipeImpl recipe1 = new RecipeImpl();
recipe1.setLocation("https://eclipse.che/Dockerfile");
recipe1.setType("dockerfile");
recipe1.setContentType("text/x-dockerfile");
recipe1.setContent("content");
final EnvironmentImpl env1 = new EnvironmentImpl();
env1.setMachines(new HashMap<>(ImmutableMap.of("machine1", exMachine1, "machine2", exMachine2, "machine3", exMachine3)));
env1.setRecipe(recipe1);
final RecipeImpl recipe2 = new RecipeImpl();
recipe2.setLocation("https://eclipse.che/Dockerfile");
recipe2.setType("dockerfile");
recipe2.setContentType("text/x-dockerfile");
recipe2.setContent("content");
final EnvironmentImpl env2 = new EnvironmentImpl();
env2.setMachines(new HashMap<>(ImmutableMap.of("machine1", exMachine1, "machine3", exMachine3)));
env2.setRecipe(recipe2);
final Map<String, EnvironmentImpl> environments = ImmutableMap.of("env1", env1, "env2", env2);
// Workspace configuration
final WorkspaceConfigImpl wCfg = new WorkspaceConfigImpl();
wCfg.setDefaultEnv("env1");
wCfg.setName("cfgName_" + index);
wCfg.setDescription("description");
wCfg.setCommands(commands);
wCfg.setProjects(projects);
wCfg.setEnvironments(environments);
return wCfg;
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project devspaces-images by redhat-developer.
the class WorkspaceRuntimes method createInternalEnvironment.
@VisibleForTesting
InternalEnvironment createInternalEnvironment(@Nullable Environment environment, Map<String, String> workspaceConfigAttributes, List<? extends Command> commands, DevfileImpl devfile) throws InfrastructureException, ValidationException, NotFoundException {
String recipeType;
if (environment == null) {
recipeType = Constants.NO_ENVIRONMENT_RECIPE_TYPE;
} else {
recipeType = environment.getRecipe().getType();
}
InternalEnvironmentFactory factory = environmentFactories.get(recipeType);
if (factory == null) {
throw new NotFoundException(format("InternalEnvironmentFactory is not configured for recipe type: '%s'", recipeType));
}
InternalEnvironment internalEnvironment = factory.create(environment);
internalEnvironment.setAttributes(new HashMap<>(workspaceConfigAttributes));
internalEnvironment.setCommands(commands.stream().map(CommandImpl::new).collect(toList()));
internalEnvironment.setDevfile(devfile);
return internalEnvironment;
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project devspaces-images by redhat-developer.
the class DevfileConverter method devFileToWorkspaceConfig.
/**
* Converts given {@link Devfile} into {@link WorkspaceConfigImpl workspace config}.
*
* @param devfile initial devfile
* @param contentProvider content provider for recipe-type component or plugin references
* @return constructed workspace config
* @throws DevfileException when general devfile error occurs
* @throws DevfileException when devfile requires additional files content but the specified
* content provider does not support it
* @throws DevfileFormatException when devfile format is invalid
* @throws DevfileRecipeFormatException when content of the file specified in recipe type
* component is empty or its format is invalid
*/
public WorkspaceConfigImpl devFileToWorkspaceConfig(DevfileImpl devfile, FileContentProvider contentProvider) throws DevfileException {
checkArgument(devfile != null, "Devfile must not be null");
checkArgument(contentProvider != null, "Content provider must not be null");
// make copy to avoid modification of original devfile
devfile = new DevfileImpl(devfile);
validateCurrentVersion(devfile);
defaultEditorProvisioner.apply(devfile, contentProvider);
WorkspaceConfigImpl config = new WorkspaceConfigImpl();
config.setName(devfile.getName());
for (Command command : devfile.getCommands()) {
CommandImpl com = commandConverter.toWorkspaceCommand(command, contentProvider);
if (com != null) {
config.getCommands().add(com);
}
}
// so, commands should be already converted
for (ComponentImpl component : devfile.getComponents()) {
ComponentToWorkspaceApplier applier = componentTypeToApplier.get(component.getType());
if (applier == null) {
throw new DevfileException(String.format("Devfile contains component `%s` with type `%s` that can not be converted to workspace", getIdentifiableComponentName(component), component.getType()));
}
applier.apply(config, component, contentProvider);
}
for (ProjectImpl project : devfile.getProjects()) {
ProjectConfigImpl projectConfig = projectConverter.toWorkspaceProject(project);
config.getProjects().add(projectConfig);
}
config.getAttributes().putAll(devfile.getAttributes());
config.setDevfile(devfile);
return config;
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class PreviewUrlExposer method expose.
public void expose(T env) throws InternalInfrastructureException {
List<CommandImpl> previewUrlCommands = env.getCommands().stream().filter(c -> c.getPreviewUrl() != null).collect(Collectors.toList());
List<ServicePort> portsToProvision = new ArrayList<>();
for (CommandImpl command : previewUrlCommands) {
int port = command.getPreviewUrl().getPort();
Optional<Service> foundService = Services.findServiceWithPort(env.getServices().values(), port);
if (foundService.isPresent()) {
if (!hasMatchingEndpoint(env, foundService.get(), port)) {
ServicePort servicePort = Services.findPort(foundService.get(), port).orElseThrow(() -> new InternalInfrastructureException(String.format("Port '%d' in service '%s' not found. This is not expected, please report a bug!", port, foundService.get().getMetadata().getName())));
String serviceName = foundService.get().getMetadata().getName();
externalServerExposer.expose(env, null, serviceName, serviceName, servicePort, Collections.emptyMap());
}
} else {
portsToProvision.add(createServicePort(port));
}
}
if (!portsToProvision.isEmpty()) {
String serverName = generate(SERVER_PREFIX, SERVER_UNIQUE_PART_SIZE) + "-previewUrl";
Service service = new ServerServiceBuilder().withName(serverName).withPorts(portsToProvision).build();
env.getServices().put(serverName, service);
portsToProvision.forEach(port -> externalServerExposer.expose(env, null, service.getMetadata().getName(), service.getMetadata().getName(), port, Collections.emptyMap()));
}
}
Aggregations