Search in sources :

Example 91 with ComponentImpl

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);
}
Also used : DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 92 with ComponentImpl

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);
}
Also used : DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) EndpointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 93 with ComponentImpl

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
}
Also used : DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 94 with ComponentImpl

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);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 95 with ComponentImpl

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));
}
Also used : MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Container(io.fabric8.kubernetes.api.model.Container) DEVFILE_COMPONENT_ALIAS_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.MachineConfig.DEVFILE_COMPONENT_ALIAS_ATTRIBUTE) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) ComponentToWorkspaceApplier(org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ComponentToWorkspaceApplier.convertEndpointsIntoServers(org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier.convertEndpointsIntoServers) Names(org.eclipse.che.workspace.infrastructure.kubernetes.Names) Containers(org.eclipse.che.workspace.infrastructure.kubernetes.util.Containers) MACHINE_NAME_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.Command.MACHINE_NAME_ATTRIBUTE) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) Named(javax.inject.Named) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) DOCKERIMAGE_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.DOCKERIMAGE_COMPONENT_TYPE) ImmutableMap(com.google.common.collect.ImmutableMap) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.VolumeImpl) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) List(java.util.List) SINGLE_HOST_STRATEGY(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.SingleHostExternalServiceExposureStrategy.SINGLE_HOST_STRATEGY) PROJECTS_VOLUME_NAME(org.eclipse.che.api.workspace.shared.Constants.PROJECTS_VOLUME_NAME) Constants(org.eclipse.che.api.workspace.server.devfile.Constants) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KubernetesSize(org.eclipse.che.workspace.infrastructure.kubernetes.util.KubernetesSize) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl)

Aggregations

ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)218 Test (org.testng.annotations.Test)184 DevfileImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl)76 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)56 Container (io.fabric8.kubernetes.api.model.Container)48 MachineConfigImpl (org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl)44 EndpointImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl)42 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)38 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)36 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)26 EntrypointImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.EntrypointImpl)26 Map (java.util.Map)24 EnvImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.EnvImpl)24 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)22 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)20 Collections.emptyMap (java.util.Collections.emptyMap)18 DevfileException (org.eclipse.che.api.workspace.server.devfile.exception.DevfileException)18 ImmutableMap (com.google.common.collect.ImmutableMap)16 ArrayList (java.util.ArrayList)14 List (java.util.List)14