use of org.eclipse.che.api.core.model.workspace.config.MachineConfig in project devspaces-images by redhat-developer.
the class KubernetesComponentToWorkspaceApplierTest method shouldProvisionDevfileVolumesIfSpecifiedIntoMachineConfig.
@Test
public void shouldProvisionDevfileVolumesIfSpecifiedIntoMachineConfig() throws Exception {
// given
String yamlRecipeContent = getResource("devfile/petclinic.yaml");
List<HasMetadata> k8sList = toK8SList(yamlRecipeContent).getItems();
doReturn(k8sList).when(k8sRecipeParser).parse(anyString());
ComponentImpl component = new ComponentImpl();
component.setType(KUBERNETES_COMPONENT_TYPE);
component.setReference(REFERENCE_FILENAME);
component.setAlias(COMPONENT_NAME);
component.setVolumes(asList(new VolumeImpl("foo", "/foo1"), new VolumeImpl("bar", "/bar1")));
ArgumentCaptor<Map<String, MachineConfigImpl>> mapCaptor = ArgumentCaptor.forClass(Map.class);
// when
applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
// then
verify(k8sEnvProvisioner).provision(any(), any(), any(), mapCaptor.capture());
Map<String, MachineConfigImpl> configMaps = mapCaptor.getValue();
for (MachineConfig config : configMaps.values()) {
assertEquals(config.getVolumes().size(), 2);
assertTrue(config.getVolumes().entrySet().stream().anyMatch(entry -> entry.getKey().equals("foo") && entry.getValue().getPath().equals("/foo1")));
assertTrue(config.getVolumes().entrySet().stream().anyMatch(entry -> entry.getKey().equals("bar") && entry.getValue().getPath().equals("/bar1")));
}
}
use of org.eclipse.che.api.core.model.workspace.config.MachineConfig in project devspaces-images by redhat-developer.
the class TestObjects method createEnvironment.
public static EnvironmentImpl createEnvironment(String... machineRams) throws Exception {
final Map<String, MachineConfig> machines = new HashMap<>();
for (String machineRam : machineRams) {
final MachineConfigImpl machineConfig = new MachineConfigImpl();
machineConfig.setAttributes(ImmutableMap.of(MachineConfig.MEMORY_LIMIT_ATTRIBUTE, machineRam));
machines.put("dev-machine", machineConfig);
}
final RecipeImpl recipe = new RecipeImpl("compose", "application/x-yaml", "", null);
return new EnvironmentImpl(recipe, machines);
}
use of org.eclipse.che.api.core.model.workspace.config.MachineConfig in project devspaces-images by redhat-developer.
the class InternalEnvironmentFactory method create.
/**
* Creates a valid instance of InternalEnvironment.
*
* <p>To construct a valid instance it performs the following actions:
*
* <ul>
* <li>download recipe content if it is needed;
* <li>retrieve the configured installers from installers registry;
* <li>normalize servers port by adding default protocol in port if it is absent;
* <li>validate the environment machines;
* <li>invoke implementation specific method that should validate and parse recipe;
* <li>ensure there are environment variables pointing to machine names;
* </ul>
*
* @param sourceEnv the environment
* @return InternalEnvironment a valid InternalEnvironment instance
* @throws InfrastructureException if exception occurs on recipe downloading
* @throws InfrastructureException if infrastructure specific error occurs
* @throws ValidationException if validation fails
*/
public T create(@Nullable final Environment sourceEnv) throws InfrastructureException, ValidationException {
Map<String, InternalMachineConfig> machines = new HashMap<>();
List<Warning> warnings = new ArrayList<>();
InternalRecipe recipe = null;
if (sourceEnv != null) {
recipe = recipeRetriever.getRecipe(sourceEnv.getRecipe());
for (Map.Entry<String, ? extends MachineConfig> machineEntry : sourceEnv.getMachines().entrySet()) {
MachineConfig machineConfig = machineEntry.getValue();
machines.put(machineEntry.getKey(), new InternalMachineConfig(normalizeServers(machineConfig.getServers()), machineConfig.getEnv(), machineConfig.getAttributes(), machineConfig.getVolumes()));
}
machinesValidator.validate(machines);
}
T internalEnv = doCreate(recipe, machines, warnings);
internalEnv.getMachines().values().forEach(m -> m.getAttributes().put(CONTAINER_SOURCE_ATTRIBUTE, RECIPE_CONTAINER_SOURCE));
return internalEnv;
}
use of org.eclipse.che.api.core.model.workspace.config.MachineConfig in project che-server by eclipse-che.
the class InternalEnvironmentFactory method create.
/**
* Creates a valid instance of InternalEnvironment.
*
* <p>To construct a valid instance it performs the following actions:
*
* <ul>
* <li>download recipe content if it is needed;
* <li>retrieve the configured installers from installers registry;
* <li>normalize servers port by adding default protocol in port if it is absent;
* <li>validate the environment machines;
* <li>invoke implementation specific method that should validate and parse recipe;
* <li>ensure there are environment variables pointing to machine names;
* </ul>
*
* @param sourceEnv the environment
* @return InternalEnvironment a valid InternalEnvironment instance
* @throws InfrastructureException if exception occurs on recipe downloading
* @throws InfrastructureException if infrastructure specific error occurs
* @throws ValidationException if validation fails
*/
public T create(@Nullable final Environment sourceEnv) throws InfrastructureException, ValidationException {
Map<String, InternalMachineConfig> machines = new HashMap<>();
List<Warning> warnings = new ArrayList<>();
InternalRecipe recipe = null;
if (sourceEnv != null) {
recipe = recipeRetriever.getRecipe(sourceEnv.getRecipe());
for (Map.Entry<String, ? extends MachineConfig> machineEntry : sourceEnv.getMachines().entrySet()) {
MachineConfig machineConfig = machineEntry.getValue();
machines.put(machineEntry.getKey(), new InternalMachineConfig(normalizeServers(machineConfig.getServers()), machineConfig.getEnv(), machineConfig.getAttributes(), machineConfig.getVolumes()));
}
machinesValidator.validate(machines);
}
T internalEnv = doCreate(recipe, machines, warnings);
internalEnv.getMachines().values().forEach(m -> m.getAttributes().put(CONTAINER_SOURCE_ATTRIBUTE, RECIPE_CONTAINER_SOURCE));
return internalEnv;
}
use of org.eclipse.che.api.core.model.workspace.config.MachineConfig in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplierTest method shouldProvisionDevfileVolumesIfSpecifiedIntoMachineConfig.
@Test
public void shouldProvisionDevfileVolumesIfSpecifiedIntoMachineConfig() throws Exception {
// given
String yamlRecipeContent = getResource("devfile/petclinic.yaml");
List<HasMetadata> k8sList = toK8SList(yamlRecipeContent).getItems();
doReturn(k8sList).when(k8sRecipeParser).parse(anyString());
ComponentImpl component = new ComponentImpl();
component.setType(KUBERNETES_COMPONENT_TYPE);
component.setReference(REFERENCE_FILENAME);
component.setAlias(COMPONENT_NAME);
component.setVolumes(asList(new VolumeImpl("foo", "/foo1"), new VolumeImpl("bar", "/bar1")));
ArgumentCaptor<Map<String, MachineConfigImpl>> mapCaptor = ArgumentCaptor.forClass(Map.class);
// when
applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
// then
verify(k8sEnvProvisioner).provision(any(), any(), any(), mapCaptor.capture());
Map<String, MachineConfigImpl> configMaps = mapCaptor.getValue();
for (MachineConfig config : configMaps.values()) {
assertEquals(config.getVolumes().size(), 2);
assertTrue(config.getVolumes().entrySet().stream().anyMatch(entry -> entry.getKey().equals("foo") && entry.getValue().getPath().equals("/foo1")));
assertTrue(config.getVolumes().entrySet().stream().anyMatch(entry -> entry.getKey().equals("bar") && entry.getValue().getPath().equals("/bar1")));
}
}
Aggregations