use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project devspaces-images by redhat-developer.
the class DevfileIntegrityValidatorTest method shouldThrowExceptionOnDuplicateComponentAlias.
@Test(expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Duplicate component alias found:'mvn-stack'")
public void shouldThrowExceptionOnDuplicateComponentAlias() throws Exception {
DevfileImpl broken = new DevfileImpl(initialDevfile);
ComponentImpl component = new ComponentImpl();
component.setAlias(initialDevfile.getComponents().get(0).getAlias());
broken.getComponents().add(component);
// when
integrityValidator.validateDevfile(broken);
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project devspaces-images by redhat-developer.
the class DevfileIntegrityValidatorTest method shouldThrowExceptionOnDuplicateEndpointName.
@Test(expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Duplicated endpoint name 'e1' found in 'dockerimage:latest' component")
public void shouldThrowExceptionOnDuplicateEndpointName() throws Exception {
DevfileImpl broken = new DevfileImpl(initialDevfile);
ComponentImpl component = new ComponentImpl();
component.setType(DOCKERIMAGE_COMPONENT_TYPE);
component.setImage("dockerimage:latest");
component.setEndpoints(ImmutableList.of(new EndpointImpl("e1", 8080, Collections.emptyMap()), new EndpointImpl("e1", 8082, Collections.emptyMap())));
broken.getComponents().add(component);
// when
integrityValidator.validateDevfile(broken);
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project devspaces-images by redhat-developer.
the class DevfileIntegrityValidatorTest method shouldRequireAliasWhenOpenshiftComponentsHaveSameReference.
@Test(expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "There are multiple components 'list.yaml' of type 'openshift' that cannot be" + " uniquely identified. Please add aliases that would distinguish the components.")
public void shouldRequireAliasWhenOpenshiftComponentsHaveSameReference() throws Exception {
// given
DevfileImpl devfile = new DevfileImpl(initialDevfile);
ComponentImpl k8s1 = new ComponentImpl();
k8s1.setType(OPENSHIFT_COMPONENT_TYPE);
k8s1.setReference("list.yaml");
ComponentImpl k8s2 = new ComponentImpl();
k8s2.setType(OPENSHIFT_COMPONENT_TYPE);
k8s2.setReference("list.yaml");
devfile.getComponents().add(k8s1);
devfile.getComponents().add(k8s2);
// when
integrityValidator.validateDevfile(devfile);
// then
// exception is thrown
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project devspaces-images by redhat-developer.
the class DevfileParserTest method shouldResolveReferencesIntoReferenceContentForFactories.
@Test
public void shouldResolveReferencesIntoReferenceContentForFactories() throws Exception {
String referenceContent = "my_content_yaml_v3";
when(contentProvider.fetchContent(anyString())).thenReturn(referenceContent);
ComponentImpl component = new ComponentImpl();
component.setType(KUBERNETES_COMPONENT_TYPE);
component.setReference("myfile.yaml");
devfile.getComponents().add(component);
// when
devfileParser.resolveReference(devfile, contentProvider);
// then
verify(contentProvider).fetchContent(eq("myfile.yaml"));
assertEquals(devfile.getComponents().get(0).getReferenceContent(), referenceContent);
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project devspaces-images by redhat-developer.
the class DockerimageComponentToWorkspaceApplier method apply.
/**
* Applies changes on workspace config according to the specified dockerimage component.
*
* <p>Dockerimage component is provisioned as Deployment in Kubernetes recipe.<br>
* Generated deployment contains container with environment variables, memory limit, docker image,
* arguments and commands specified in component.<br>
* Also, environment is provisioned with machine config with volumes and servers specified, then
* Kubernetes infra will created needed PVC, Services, Ingresses, Routes according to specified
* configuration.
*
* @param workspaceConfig workspace config on which changes should be applied
* @param dockerimageComponent dockerimage component that should be applied
* @param contentProvider optional content provider that may be used for external component
* resource fetching
* @throws DevfileException if specified workspace config already has default environment where
* dockerimage component should be stored
* @throws IllegalArgumentException if specified workspace config or plugin component is null
* @throws IllegalArgumentException if specified component has type different from dockerimage
*/
@Override
public void apply(WorkspaceConfigImpl workspaceConfig, ComponentImpl dockerimageComponent, FileContentProvider contentProvider) throws DevfileException {
checkArgument(workspaceConfig != null, "Workspace config must not be null");
checkArgument(dockerimageComponent != null, "Component must not be null");
checkArgument(DOCKERIMAGE_COMPONENT_TYPE.equals(dockerimageComponent.getType()), format("Plugin must have `%s` type", DOCKERIMAGE_COMPONENT_TYPE));
String componentAlias = dockerimageComponent.getAlias();
String machineName = componentAlias == null ? toMachineName(dockerimageComponent.getImage()) : componentAlias;
MachineConfigImpl machineConfig = createMachineConfig(dockerimageComponent, componentAlias);
List<HasMetadata> componentObjects = createComponentObjects(dockerimageComponent, machineName);
k8sEnvProvisioner.provision(workspaceConfig, KubernetesEnvironment.TYPE, componentObjects, ImmutableMap.of(machineName, machineConfig));
workspaceConfig.getCommands().stream().filter(c -> componentAlias != null && componentAlias.equals(c.getAttributes().get(Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE))).forEach(c -> c.getAttributes().put(MACHINE_NAME_ATTRIBUTE, machineName));
}
Aggregations