diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index d600c2c87b..080463c022 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -48,7 +48,7 @@ wsmaster/** @skabashnyuk wsmaster/che-core-api-factory/** @mshaposhnik wsmaster/che-core-api-factory-shared/** @mshaposhnik wsmaster/che-core-api-workspace-activity/** @mshaposhnik -wsmaster/che-core-api-devfile/** @sleshchenko @mshaposhnik @metlos +wsmaster/che-core-api-workspace/** @sleshchenko @mshaposhnik @metlos # wsagent wsagent/activity/** @skabashnyuk diff --git a/assembly/assembly-wsmaster-war/pom.xml b/assembly/assembly-wsmaster-war/pom.xml index 618e0989d3..6f8fd22c33 100644 --- a/assembly/assembly-wsmaster-war/pom.xml +++ b/assembly/assembly-wsmaster-war/pom.xml @@ -157,10 +157,6 @@ org.eclipse.che.core che-core-api-core - - org.eclipse.che.core - che-core-api-devfile - org.eclipse.che.core che-core-api-factory diff --git a/assembly/assembly-wsmaster-war/src/main/java/org/eclipse/che/api/deploy/WsMasterModule.java b/assembly/assembly-wsmaster-war/src/main/java/org/eclipse/che/api/deploy/WsMasterModule.java index ef2dbf5da4..b8988d9ccf 100644 --- a/assembly/assembly-wsmaster-war/src/main/java/org/eclipse/che/api/deploy/WsMasterModule.java +++ b/assembly/assembly-wsmaster-war/src/main/java/org/eclipse/che/api/deploy/WsMasterModule.java @@ -31,7 +31,6 @@ import org.eclipse.che.api.core.rest.CheJsonProvider; import org.eclipse.che.api.core.rest.MessageBodyAdapter; import org.eclipse.che.api.core.rest.MessageBodyAdapterInterceptor; import org.eclipse.che.api.deploy.jsonrpc.CheJsonRpcWebSocketConfigurationModule; -import org.eclipse.che.api.devfile.server.DevfileModule; import org.eclipse.che.api.factory.server.FactoryAcceptValidator; import org.eclipse.che.api.factory.server.FactoryCreateValidator; import org.eclipse.che.api.factory.server.FactoryEditValidator; @@ -50,6 +49,7 @@ import org.eclipse.che.api.user.server.spi.PreferenceDao; import org.eclipse.che.api.user.server.spi.UserDao; import org.eclipse.che.api.workspace.server.WorkspaceLockService; import org.eclipse.che.api.workspace.server.WorkspaceStatusCache; +import org.eclipse.che.api.workspace.server.devfile.DevfileModule; import org.eclipse.che.api.workspace.server.hc.ServersCheckerFactory; import org.eclipse.che.api.workspace.server.spi.provision.InstallerConfigProvisioner; import org.eclipse.che.api.workspace.server.spi.provision.InternalEnvironmentProvisioner; diff --git a/core/che-core-dynamodule-maven-plugin/src/main/java/org/eclipse/che/plugin/dynamodule/scanner/FindDynaModuleVisitor.java b/core/che-core-dynamodule-maven-plugin/src/main/java/org/eclipse/che/plugin/dynamodule/scanner/FindDynaModuleVisitor.java index ceb5effe11..773d28b824 100644 --- a/core/che-core-dynamodule-maven-plugin/src/main/java/org/eclipse/che/plugin/dynamodule/scanner/FindDynaModuleVisitor.java +++ b/core/che-core-dynamodule-maven-plugin/src/main/java/org/eclipse/che/plugin/dynamodule/scanner/FindDynaModuleVisitor.java @@ -31,7 +31,7 @@ public final class FindDynaModuleVisitor extends ClassVisitor { /** Default constructor. */ public FindDynaModuleVisitor() { - super(Opcodes.ASM5); + super(Opcodes.ASM7); } /** diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/KubernetesInfraModule.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/KubernetesInfraModule.java index 29bf76d5a9..d4ab3fa1c8 100644 --- a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/KubernetesInfraModule.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/KubernetesInfraModule.java @@ -11,6 +11,9 @@ */ package org.eclipse.che.workspace.infrastructure.kubernetes; +import static com.google.inject.name.Names.named; +import static org.eclipse.che.api.workspace.server.devfile.Constants.DOCKERIMAGE_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE; import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.CommonPVCStrategy.COMMON_STRATEGY; import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.PerWorkspacePVCStrategy.PER_WORKSPACE_STRATEGY; import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.UniqueWorkspacePVCStrategy.UNIQUE_STRATEGY; @@ -26,6 +29,8 @@ import com.google.inject.multibindings.Multibinder; import java.util.Map; import org.eclipse.che.api.system.server.ServiceTermination; import org.eclipse.che.api.workspace.server.NoEnvironmentFactory; +import org.eclipse.che.api.workspace.server.devfile.DevfileBindings; +import org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator.NoopComponentIntegrityValidator; import org.eclipse.che.api.workspace.server.spi.RuntimeInfrastructure; import org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironmentFactory; import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiExternalEnvVarProvider; @@ -37,6 +42,12 @@ import org.eclipse.che.workspace.infrastructure.docker.environment.dockerimage.D import org.eclipse.che.workspace.infrastructure.docker.environment.dockerimage.DockerImageEnvironmentFactory; import org.eclipse.che.workspace.infrastructure.kubernetes.bootstrapper.KubernetesBootstrapperFactory; import org.eclipse.che.workspace.infrastructure.kubernetes.cache.jpa.JpaKubernetesRuntimeCacheModule; +import org.eclipse.che.workspace.infrastructure.kubernetes.devfile.DockerimageComponentProvisioner; +import org.eclipse.che.workspace.infrastructure.kubernetes.devfile.DockerimageComponentToWorkspaceApplier; +import org.eclipse.che.workspace.infrastructure.kubernetes.devfile.KubernetesComponentProvisioner; +import org.eclipse.che.workspace.infrastructure.kubernetes.devfile.KubernetesComponentToWorkspaceApplier; +import org.eclipse.che.workspace.infrastructure.kubernetes.devfile.KubernetesComponentValidator; +import org.eclipse.che.workspace.infrastructure.kubernetes.devfile.KubernetesDevfileBindings; import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment; import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironmentFactory; import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.RemoveNamespaceOnWorkspaceRemove; @@ -133,7 +144,7 @@ public class KubernetesInfraModule extends AbstractModule { envVarProviders.addBinding().to(LogsRootEnvVariableProvider.class); bind(new TypeLiteral>() {}) - .annotatedWith(com.google.inject.name.Names.named("infra.kubernetes.ingress.annotations")) + .annotatedWith(named("infra.kubernetes.ingress.annotations")) .toProvider(IngressAnnotationsProvider.class); install(new JpaKubernetesRuntimeCacheModule()); @@ -168,5 +179,31 @@ public class KubernetesInfraModule extends AbstractModule { bind(SidecarToolingProvisioner.class) .to(new TypeLiteral>() {}); + + DevfileBindings.onComponentIntegrityValidatorBinder( + binder(), + binder -> { + binder.addBinding(KUBERNETES_COMPONENT_TYPE).to(KubernetesComponentValidator.class); + binder.addBinding(DOCKERIMAGE_COMPONENT_TYPE).to(NoopComponentIntegrityValidator.class); + }); + + DevfileBindings.onWorkspaceApplierBinder( + binder(), + binder -> { + binder + .addBinding(KUBERNETES_COMPONENT_TYPE) + .to(KubernetesComponentToWorkspaceApplier.class); + binder + .addBinding(DOCKERIMAGE_COMPONENT_TYPE) + .to(DockerimageComponentToWorkspaceApplier.class); + }); + + DevfileBindings.addComponentProvisioners( + binder(), KubernetesComponentProvisioner.class, DockerimageComponentProvisioner.class); + + KubernetesDevfileBindings.addKubernetesBasedEnvironmentTypeBindings( + binder(), KubernetesEnvironment.TYPE); + KubernetesDevfileBindings.addKubernetesBasedComponentTypeBindings( + binder(), KUBERNETES_COMPONENT_TYPE); } } diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/ContainerSearch.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/ContainerSearch.java similarity index 98% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/ContainerSearch.java rename to infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/ContainerSearch.java index 06f19489da..d532992036 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/ContainerSearch.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/ContainerSearch.java @@ -9,7 +9,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.kubernetes; +package org.eclipse.che.workspace.infrastructure.kubernetes.devfile; import static java.util.stream.Collectors.toList; diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentProvisioner.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentProvisioner.java similarity index 93% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentProvisioner.java rename to infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentProvisioner.java index 17273bf7c5..bec7a32930 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentProvisioner.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentProvisioner.java @@ -9,12 +9,12 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.dockerimage; +package org.eclipse.che.workspace.infrastructure.kubernetes.devfile; import static com.google.common.base.Preconditions.checkArgument; import static org.eclipse.che.api.core.model.workspace.config.MachineConfig.MEMORY_LIMIT_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.DOCKERIMAGE_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.PUBLIC_ENDPOINT_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.DOCKERIMAGE_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.PUBLIC_ENDPOINT_ATTRIBUTE; import static org.eclipse.che.api.workspace.shared.Constants.PROJECTS_VOLUME_NAME; import java.util.HashMap; @@ -25,8 +25,8 @@ import java.util.stream.Collectors; import javax.inject.Inject; import org.eclipse.che.api.core.model.workspace.config.MachineConfig; import org.eclipse.che.api.core.model.workspace.config.ServerConfig; -import org.eclipse.che.api.devfile.server.convert.component.ComponentProvisioner; -import org.eclipse.che.api.devfile.server.exception.WorkspaceExportException; +import org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentProvisioner; +import org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException; import org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl; import org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.RecipeImpl; @@ -46,6 +46,8 @@ import org.eclipse.che.workspace.infrastructure.kubernetes.environment.util.Entr * Provision dockerimage component in {@link DevfileImpl} according to the value of environment with * dockerimage recipe if the specified {@link WorkspaceConfigImpl} has such. * + *

The {@code dockerimage} devfile components are handled as Kubernetes deployments internally. + * * @author Sergii Leshchenko */ public class DockerimageComponentProvisioner implements ComponentProvisioner { diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentToWorkspaceApplier.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentToWorkspaceApplier.java similarity index 92% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentToWorkspaceApplier.java rename to infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentToWorkspaceApplier.java index 7880e93aef..efb4e5d07b 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentToWorkspaceApplier.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentToWorkspaceApplier.java @@ -9,16 +9,16 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.dockerimage; +package org.eclipse.che.workspace.infrastructure.kubernetes.devfile; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Strings.isNullOrEmpty; import static java.lang.String.format; import static java.util.Collections.singletonList; import static org.eclipse.che.api.core.model.workspace.config.Command.MACHINE_NAME_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.DISCOVERABLE_ENDPOINT_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.DOCKERIMAGE_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.PUBLIC_ENDPOINT_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.DISCOVERABLE_ENDPOINT_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.DOCKERIMAGE_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.PUBLIC_ENDPOINT_ATTRIBUTE; import static org.eclipse.che.api.workspace.shared.Constants.PROJECTS_VOLUME_NAME; import static org.eclipse.che.workspace.infrastructure.kubernetes.Constants.MACHINE_NAME_ANNOTATION_FMT; @@ -43,11 +43,10 @@ import javax.inject.Named; import org.eclipse.che.api.core.model.workspace.config.ServerConfig; import org.eclipse.che.api.core.model.workspace.devfile.Component; import org.eclipse.che.api.core.model.workspace.devfile.Endpoint; -import org.eclipse.che.api.devfile.server.Constants; -import org.eclipse.che.api.devfile.server.FileContentProvider; -import org.eclipse.che.api.devfile.server.convert.component.ComponentToWorkspaceApplier; -import org.eclipse.che.api.devfile.server.convert.component.kubernetes.KubernetesEnvironmentProvisioner; -import org.eclipse.che.api.devfile.server.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.Constants; +import org.eclipse.che.api.workspace.server.devfile.FileContentProvider; +import org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; import org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.VolumeImpl; @@ -58,6 +57,8 @@ import org.eclipse.che.workspace.infrastructure.kubernetes.util.Containers; /** * Applies changes on workspace config according to the specified dockerimage component. * + *

The {@code dockerimage} devfile components are handled as Kubernetes deployments internally. + * * @author Sergii Leshchenko */ public class DockerimageComponentToWorkspaceApplier implements ComponentToWorkspaceApplier { @@ -201,7 +202,7 @@ public class DockerimageComponentToWorkspaceApplier implements ComponentToWorksp .withNewMetadata() .withName(name) .addToLabels(CHE_COMPONENT_NAME_LABEL, name) - .addToAnnotations(String.format(MACHINE_NAME_ANNOTATION_FMT, name), name) + .addToAnnotations(format(MACHINE_NAME_ANNOTATION_FMT, name), name) .endMetadata() .withNewSpec() .withContainers(container) diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentProvisioner.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesComponentProvisioner.java similarity index 73% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentProvisioner.java rename to infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesComponentProvisioner.java index e92a32f162..226e5c9106 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentProvisioner.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesComponentProvisioner.java @@ -9,20 +9,22 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.kubernetes; +package org.eclipse.che.workspace.infrastructure.kubernetes.devfile; import static com.google.common.base.Preconditions.checkArgument; +import static java.lang.String.format; +import com.google.inject.name.Named; import java.util.List; import java.util.Map.Entry; +import java.util.Set; import java.util.stream.Collectors; -import org.eclipse.che.api.devfile.server.convert.component.ComponentProvisioner; -import org.eclipse.che.api.devfile.server.exception.WorkspaceExportException; +import javax.inject.Inject; +import org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentProvisioner; +import org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException; import org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl; -import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment; -import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment; /** * Provision kubernetes/openshift component in {@link DevfileImpl} according to the value of @@ -33,6 +35,15 @@ import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftE */ public class KubernetesComponentProvisioner implements ComponentProvisioner { + private final Set handledEnvironmentTypes; + + @Inject + public KubernetesComponentProvisioner( + @Named(KubernetesDevfileBindings.KUBERNETES_BASED_ENVIRONMENTS_KEY_NAME) + Set handledEnvironmentTypes) { + this.handledEnvironmentTypes = handledEnvironmentTypes; + } + /** * Provision kubernetes/openshift component in {@link DevfileImpl} according to the value of * environment with kubernetes/openshift recipe if the specified {@link WorkspaceConfigImpl} has @@ -58,10 +69,7 @@ public class KubernetesComponentProvisioner implements ComponentProvisioner { .getEnvironments() .entrySet() .stream() - .filter( - e -> - KubernetesEnvironment.TYPE.equals(e.getValue().getRecipe().getType()) - || OpenShiftEnvironment.TYPE.equals(e.getValue().getRecipe().getType())) + .filter(e -> handledEnvironmentTypes.contains(e.getValue().getRecipe().getType())) .collect(Collectors.toList()); if (k8sEnvironments.isEmpty()) { @@ -69,13 +77,16 @@ public class KubernetesComponentProvisioner implements ComponentProvisioner { } if (k8sEnvironments.size() > 1) { + String allEnvs = String.join("/", handledEnvironmentTypes); + throw new WorkspaceExportException( - "Workspace with multiple `kubernetes`/`openshift` environments can not be converted to devfile"); + format( + "Workspace with multiple %s environments can not be converted to devfile", allEnvs)); } EnvironmentImpl env = k8sEnvironments.get(0).getValue(); throw new WorkspaceExportException( - String.format( + format( "Exporting of workspace with `%s` is not supported yet.", env.getRecipe().getType())); } } diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentToWorkspaceApplier.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesComponentToWorkspaceApplier.java similarity index 82% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentToWorkspaceApplier.java rename to infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesComponentToWorkspaceApplier.java index 3ae594abca..b404cf8002 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentToWorkspaceApplier.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesComponentToWorkspaceApplier.java @@ -9,7 +9,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.kubernetes; +package org.eclipse.che.workspace.infrastructure.kubernetes.devfile; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Strings.isNullOrEmpty; @@ -17,9 +17,8 @@ import static java.lang.String.format; import static java.util.Collections.emptyMap; import static java.util.stream.Collectors.toList; import static org.eclipse.che.api.core.model.workspace.config.Command.MACHINE_NAME_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Components.getIdentifiableComponentName; -import static org.eclipse.che.api.devfile.server.Constants.KUBERNETES_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.OPENSHIFT_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Components.getIdentifiableComponentName; +import static org.eclipse.che.workspace.infrastructure.kubernetes.devfile.KubernetesDevfileBindings.KUBERNETES_BASED_COMPONENTS_KEY_NAME; import io.fabric8.kubernetes.api.model.Container; import io.fabric8.kubernetes.api.model.HasMetadata; @@ -28,19 +27,22 @@ import io.fabric8.kubernetes.api.model.apps.Deployment; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Set; import javax.inject.Inject; +import javax.inject.Named; import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; import org.eclipse.che.api.core.model.workspace.config.Command; import org.eclipse.che.api.core.model.workspace.devfile.Component; import org.eclipse.che.api.core.model.workspace.devfile.Entrypoint; -import org.eclipse.che.api.devfile.server.Constants; -import org.eclipse.che.api.devfile.server.DevfileRecipeFormatException; -import org.eclipse.che.api.devfile.server.FileContentProvider; -import org.eclipse.che.api.devfile.server.convert.component.ComponentToWorkspaceApplier; -import org.eclipse.che.api.devfile.server.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.Constants; +import org.eclipse.che.api.workspace.server.devfile.DevfileRecipeFormatException; +import org.eclipse.che.api.workspace.server.devfile.FileContentProvider; +import org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.commons.annotation.Nullable; import org.eclipse.che.workspace.infrastructure.kubernetes.Names; +import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment; import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData; import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesRecipeParser; @@ -53,12 +55,30 @@ public class KubernetesComponentToWorkspaceApplier implements ComponentToWorkspa private final KubernetesRecipeParser objectsParser; private final KubernetesEnvironmentProvisioner k8sEnvProvisioner; + private final String environmentType; + private final Set kubernetesBasedComponentTypes; @Inject public KubernetesComponentToWorkspaceApplier( - KubernetesRecipeParser objectsParser, KubernetesEnvironmentProvisioner k8sEnvProvisioner) { + KubernetesRecipeParser objectsParser, + KubernetesEnvironmentProvisioner k8sEnvProvisioner, + @Named(KUBERNETES_BASED_COMPONENTS_KEY_NAME) Set kubernetesBasedComponentTypes) { + this( + objectsParser, + k8sEnvProvisioner, + KubernetesEnvironment.TYPE, + kubernetesBasedComponentTypes); + } + + protected KubernetesComponentToWorkspaceApplier( + KubernetesRecipeParser objectsParser, + KubernetesEnvironmentProvisioner k8sEnvProvisioner, + String environmentType, + Set kubernetesBasedComponentTypes) { this.objectsParser = objectsParser; this.k8sEnvProvisioner = k8sEnvProvisioner; + this.environmentType = environmentType; + this.kubernetesBasedComponentTypes = kubernetesBasedComponentTypes; } /** @@ -84,11 +104,8 @@ public class KubernetesComponentToWorkspaceApplier implements ComponentToWorkspa checkArgument(workspaceConfig != null, "Workspace config must not be null"); checkArgument(k8sComponent != null, "Component must not be null"); checkArgument( - KUBERNETES_COMPONENT_TYPE.equals(k8sComponent.getType()) - || OPENSHIFT_COMPONENT_TYPE.equals(k8sComponent.getType()), - format( - "Plugin must have `%s` or `%s` type", - KUBERNETES_COMPONENT_TYPE, OPENSHIFT_COMPONENT_TYPE)); + kubernetesBasedComponentTypes.contains(k8sComponent.getType()), + format("Plugin must have %s type", String.join(" or ", kubernetesBasedComponentTypes))); String componentContent = retrieveContent(k8sComponent, contentProvider); @@ -103,8 +120,7 @@ public class KubernetesComponentToWorkspaceApplier implements ComponentToWorkspa applyEntrypoints(k8sComponent.getEntrypoints(), componentObjects); - k8sEnvProvisioner.provision( - workspaceConfig, k8sComponent.getType(), componentObjects, emptyMap()); + k8sEnvProvisioner.provision(workspaceConfig, environmentType, componentObjects, emptyMap()); } private String retrieveContent( diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesComponentValidator.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesComponentValidator.java new file mode 100644 index 0000000000..685501c47f --- /dev/null +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesComponentValidator.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2012-2018 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.workspace.infrastructure.kubernetes.devfile; + +import static java.lang.String.format; +import static org.eclipse.che.api.workspace.server.devfile.Components.getIdentifiableComponentName; + +import io.fabric8.kubernetes.api.model.Container; +import io.fabric8.kubernetes.api.model.HasMetadata; +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.inject.Inject; +import javax.inject.Named; +import org.eclipse.che.api.core.ValidationException; +import org.eclipse.che.api.core.model.workspace.devfile.Component; +import org.eclipse.che.api.core.model.workspace.devfile.Entrypoint; +import org.eclipse.che.api.workspace.server.devfile.FileContentProvider; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException; +import org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator; +import org.eclipse.che.api.workspace.server.spi.InfrastructureException; +import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesRecipeParser; + +public class KubernetesComponentValidator implements ComponentIntegrityValidator { + private final KubernetesRecipeParser kubernetesRecipeParser; + private final Set k8sBasedComponentTypes; + + @Inject + public KubernetesComponentValidator( + KubernetesRecipeParser kubernetesRecipeParser, + @Named(KubernetesDevfileBindings.KUBERNETES_BASED_COMPONENTS_KEY_NAME) + Set k8sBasedComponentTypes) { + this.kubernetesRecipeParser = kubernetesRecipeParser; + this.k8sBasedComponentTypes = k8sBasedComponentTypes; + } + + @Override + public void validateComponent(Component component, FileContentProvider contentProvider) + throws DevfileFormatException { + try { + List selectedObjects = validateSelector(component, contentProvider); + validateEntrypointSelector(component, selectedObjects); + } catch (Exception e) { + throw new DevfileFormatException( + format( + "Failed to validate content reference of component '%s' of type '%s': %s", + getIdentifiableComponentName(component), component.getType(), e.getMessage()), + e); + } + } + + /** + * Validates that the selector, if any, selects some objects from the component's referenced + * content. Only does anything for kubernetes and openshift components. + * + * @param component the component to check + * @param contentProvider the content provider to use when fetching content + * @return the list of referenced objects matching the selector or empty list + * @throws ValidationException on failure to validate the referenced content + * @throws InfrastructureException on failure to parse the referenced content + * @throws IOException on failure to retrieve the referenced content + * @throws DevfileException if the selector filters out all referenced objects + */ + private List validateSelector( + Component component, FileContentProvider contentProvider) + throws ValidationException, InfrastructureException, IOException, DevfileException { + + if (!k8sBasedComponentTypes.contains(component.getType())) { + return Collections.emptyList(); + } + + List content = getReferencedKubernetesList(component, contentProvider); + + Map selector = component.getSelector(); + if (selector == null || selector.isEmpty()) { + return content; + } + + content = SelectorFilter.filter(content, selector); + + if (content.isEmpty()) { + throw new DevfileException( + format( + "The selector of the component '%s' of type '%s' filters out all objects from" + + " the list.", + getIdentifiableComponentName(component), component.getType())); + } + + return content; + } + + private void validateEntrypointSelector(Component component, List filteredObjects) + throws DevfileException { + + if (component.getEntrypoints() == null || component.getEntrypoints().isEmpty()) { + return; + } + + for (Entrypoint ep : component.getEntrypoints()) { + ContainerSearch search = + new ContainerSearch(ep.getParentName(), ep.getParentSelector(), ep.getContainerName()); + + List cs = search.search(filteredObjects); + + if (cs.isEmpty()) { + throw new DevfileFormatException( + format( + "Component '%s' of type '%s' contains an entry point that doesn't match any" + + " container.", + getIdentifiableComponentName(component), component.getType())); + } + } + } + + private List getReferencedKubernetesList( + Component component, FileContentProvider contentProvider) + throws ValidationException, InfrastructureException, IOException, DevfileException { + List content; + if (component.getReferenceContent() != null) { + content = kubernetesRecipeParser.parse(component.getReferenceContent()); + } else if (component.getReference() != null) { + String data = contentProvider.fetchContent(component.getReference()); + content = kubernetesRecipeParser.parse(data); + } else { + content = Collections.emptyList(); + } + + return content; + } +} diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesDevfileBindings.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesDevfileBindings.java new file mode 100644 index 0000000000..64b2a66c15 --- /dev/null +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesDevfileBindings.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2012-2018 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.workspace.infrastructure.kubernetes.devfile; + +import com.google.inject.Binder; +import com.google.inject.multibindings.MapBinder; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.name.Names; + +/** + * A utility class to ease the binding of Kubernetes-related devfile bindings in a Guice module. + * + *

Consult the individual methods to see if you need to use them. + */ +public class KubernetesDevfileBindings { + + public static final String ALLOWED_ENVIRONMENT_TYPE_UPGRADES_KEY_NAME = + "allowedEnvironmentTypeUpgrades"; + public static final String KUBERNETES_BASED_ENVIRONMENTS_KEY_NAME = "kubernetesBasedEnvironments"; + public static final String KUBERNETES_BASED_COMPONENTS_KEY_NAME = "kubernetesBasedComponents"; + + /** + * Any workspace environments based on Kubernetes recipes need to register the binding using this + * method so that the {@link KubernetesComponentProvisioner} and {@link + * KubernetesEnvironmentProvisioner} can work properly with these environments. + * + * @param baseBinder the binder available in the Guice module calling this method. + * @param environmentTypes the environment types to be registered as handled by Kubernetes recipes + */ + public static void addKubernetesBasedEnvironmentTypeBindings( + Binder baseBinder, String... environmentTypes) { + Multibinder binder = + Multibinder.newSetBinder( + baseBinder, String.class, Names.named(KUBERNETES_BASED_ENVIRONMENTS_KEY_NAME)); + for (String envType : environmentTypes) { + binder.addBinding().toInstance(envType); + } + } + + /** + * Any devfile components based on Kubernetes recipes need to register the binding using this + * method so that the {@link KubernetesComponentProvisioner} and {@link + * KubernetesComponentToWorkspaceApplier} can work properly with these components. + * + * @param baseBinder the binder available in the Guice module calling this method. + * @param componentTypes the component types to be registered as handled by Kubernetes recipes + */ + public static void addKubernetesBasedComponentTypeBindings( + Binder baseBinder, String... componentTypes) { + Multibinder binder = + Multibinder.newSetBinder( + baseBinder, String.class, Names.named(KUBERNETES_BASED_COMPONENTS_KEY_NAME)); + for (String envType : componentTypes) { + binder.addBinding().toInstance(envType); + } + } + + /** + * It is possible "upgrade" a kubernetes-based environment to a more specific type (e.g. a + * Kubernetes can be upgraded to Openshift environment, because Openshift is compatible with + * Kubernetes, but an Openshift environment cannot be "upgraded" Kubernetes environment, because + * Kubernetes is not itself compatible with Openshift). + * + * @param baseBinder the binder available in the Guice module calling this method + * @param targetEnvironmentType the environment type to upgrade to, if possible + * @param baseEnvironmentTypes the environments from which it is possible to upgrade to the target + * environment type. + */ + public static void addAllowedEnvironmentTypeUpgradeBindings( + Binder baseBinder, String targetEnvironmentType, String... baseEnvironmentTypes) { + MapBinder binder = + MapBinder.newMapBinder( + baseBinder, + String.class, + String.class, + Names.named(ALLOWED_ENVIRONMENT_TYPE_UPGRADES_KEY_NAME)) + .permitDuplicates(); + + for (String baseType : baseEnvironmentTypes) { + binder.addBinding(targetEnvironmentType).toInstance(baseType); + } + } + + private KubernetesDevfileBindings() {} +} diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesEnvironmentProvisioner.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesEnvironmentProvisioner.java similarity index 78% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesEnvironmentProvisioner.java rename to infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesEnvironmentProvisioner.java index 302fafde36..19e2084fcb 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesEnvironmentProvisioner.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesEnvironmentProvisioner.java @@ -9,11 +9,12 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.kubernetes; +package org.eclipse.che.workspace.infrastructure.kubernetes.devfile; import static java.lang.String.format; import static java.util.Collections.emptyMap; -import static org.eclipse.che.api.devfile.server.Constants.OPENSHIFT_COMPONENT_TYPE; +import static org.eclipse.che.workspace.infrastructure.kubernetes.devfile.KubernetesDevfileBindings.ALLOWED_ENVIRONMENT_TYPE_UPGRADES_KEY_NAME; +import static org.eclipse.che.workspace.infrastructure.kubernetes.devfile.KubernetesDevfileBindings.KUBERNETES_BASED_ENVIRONMENTS_KEY_NAME; import com.google.common.annotations.VisibleForTesting; import io.fabric8.kubernetes.api.model.HasMetadata; @@ -26,17 +27,16 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import javax.inject.Inject; -import org.eclipse.che.api.devfile.server.DevfileRecipeFormatException; -import org.eclipse.che.api.devfile.server.exception.DevfileException; -import org.eclipse.che.api.devfile.server.exception.DevfileFormatException; +import javax.inject.Named; +import org.eclipse.che.api.workspace.server.devfile.DevfileRecipeFormatException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException; import org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl; import org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.RecipeImpl; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.commons.lang.Pair; -import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment; import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesRecipeParser; -import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment; /** * Provisions default K8s/OS environment with specified objects (K8s/OS objects, machines) into @@ -48,10 +48,18 @@ public class KubernetesEnvironmentProvisioner { @VisibleForTesting static final String YAML_CONTENT_TYPE = "application/x-yaml"; private final KubernetesRecipeParser objectsParser; + private final Map> allowedEnvironmentTypeUpgrades; + private final Set k8sBasedEnvTypes; @Inject - public KubernetesEnvironmentProvisioner(KubernetesRecipeParser objectsParser) { + public KubernetesEnvironmentProvisioner( + KubernetesRecipeParser objectsParser, + @Named(ALLOWED_ENVIRONMENT_TYPE_UPGRADES_KEY_NAME) + Map> allowedEnvironmentTypeUpgrades, + @Named(KUBERNETES_BASED_ENVIRONMENTS_KEY_NAME) Set k8sBasedEnvTypes) { this.objectsParser = objectsParser; + this.allowedEnvironmentTypeUpgrades = allowedEnvironmentTypeUpgrades; + this.k8sBasedEnvTypes = k8sBasedEnvTypes; } /** @@ -62,8 +70,8 @@ public class KubernetesEnvironmentProvisioner { * be updated with result or merging existing objects and specified ones. * * @param workspaceConfig workspace where recipe should be provisioned - * @param environmentType type of environment that should be provisioned. Should be {@link - * KubernetesEnvironment#TYPE} or {@link OpenShiftEnvironment#TYPE} + * @param environmentType type of environment that should be provisioned. Should be one of the + * Kubernetes-based environments. * @param componentObjects objects that should be provisioned into the workspace config * @param machines machines that should be provisioned into the workspace config * @throws DevfileRecipeFormatException if exception occurred during existing environment parsing @@ -102,9 +110,10 @@ public class KubernetesEnvironmentProvisioner { // check if it is needed to update recipe type since // kubernetes component is compatible with openshift but not vice versa - if (OPENSHIFT_COMPONENT_TYPE.equals(environmentType) - && KubernetesEnvironment.TYPE.equals(envRecipe.getType())) { - envRecipe.setType(OpenShiftEnvironment.TYPE); + + Set allowedEnvTypeBases = allowedEnvironmentTypeUpgrades.get(environmentType); + if (allowedEnvTypeBases != null) { + envRecipe.setType(environmentType); } // workspace already has k8s/OS recipe @@ -117,13 +126,13 @@ public class KubernetesEnvironmentProvisioner { } private List unmarshalObjects(RecipeImpl k8sRecipe) throws DevfileException { - if (!OpenShiftEnvironment.TYPE.equals(k8sRecipe.getType()) - && !KubernetesEnvironment.TYPE.equals(k8sRecipe.getType())) { + if (!k8sBasedEnvTypes.contains(k8sRecipe.getType())) { + String allowedEnvTypes = String.join(" or ", k8sBasedEnvTypes); throw new DevfileException( format( - "Kubernetes component can only be applied to a workspace with either kubernetes or " - + "openshift recipe type but workspace has a recipe of type '%s'", - k8sRecipe.getType())); + "Kubernetes component can only be applied to a workspace with any of %s recipe type" + + " but workspace has a recipe of type '%s'", + allowedEnvTypes, k8sRecipe.getType())); } return unmarshal(k8sRecipe.getContent()); diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/SelectorFilter.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/SelectorFilter.java similarity index 80% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/SelectorFilter.java rename to infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/SelectorFilter.java index 370b3de229..f3c16499ec 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/SelectorFilter.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/SelectorFilter.java @@ -9,7 +9,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.kubernetes; +package org.eclipse.che.workspace.infrastructure.kubernetes.devfile; import static java.util.stream.Collectors.toCollection; @@ -18,6 +18,7 @@ import io.fabric8.kubernetes.api.model.ObjectMeta; import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.eclipse.che.commons.annotation.Nullable; /** Helper class to filter Kubernetes objects by a selector. */ public class SelectorFilter { @@ -36,12 +37,19 @@ public class SelectorFilter { } /** - * Returns true is specified object is matched by specified selector, false otherwise + * Returns true is specified object is matched by specified selector, false otherwise. + * + *

An empty selector is considered to match anything. * * @param metadata object metadata to check matching * @param selector the selector to match the metadata with */ - public static boolean test(ObjectMeta metadata, Map selector) { + public static boolean test(@Nullable ObjectMeta metadata, Map selector) { + if (selector.isEmpty()) { + // anything matches if we have nothing to select with + return true; + } + if (metadata == null) { return false; } diff --git a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/InconsistentRuntimesDetectorTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/InconsistentRuntimesDetectorTest.java index 550b15f784..1773a1cc81 100644 --- a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/InconsistentRuntimesDetectorTest.java +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/InconsistentRuntimesDetectorTest.java @@ -34,7 +34,6 @@ import org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl; import org.eclipse.che.api.workspace.server.spi.InfrastructureException; import org.eclipse.che.api.workspace.server.spi.InternalRuntime; import org.eclipse.che.workspace.infrastructure.kubernetes.util.RuntimeEventsPublisher; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.testng.MockitoTestNGListener; import org.testng.annotations.BeforeMethod; @@ -57,7 +56,7 @@ public class InconsistentRuntimesDetectorTest { @Mock private KubernetesInternalRuntime k8sRuntime; @Mock private KubernetesRuntimeContext k8sContext; - @InjectMocks private InconsistentRuntimesDetector inconsistentRuntimesDetector; + private InconsistentRuntimesDetector inconsistentRuntimesDetector; @BeforeMethod public void setUp() throws Exception { diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/ContainerSearchTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/ContainerSearchTest.java similarity index 91% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/ContainerSearchTest.java rename to infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/ContainerSearchTest.java index e0cfc292fb..c5bfebc90b 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/ContainerSearchTest.java +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/ContainerSearchTest.java @@ -9,7 +9,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.kubernetes; +package org.eclipse.che.workspace.infrastructure.kubernetes.devfile; import static java.lang.String.format; import static java.util.Arrays.asList; @@ -41,6 +41,7 @@ import io.fabric8.openshift.api.model.DeploymentConfigBuilder; import io.fabric8.openshift.api.model.Template; import io.fabric8.openshift.api.model.TemplateBuilder; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; import org.testng.Assert; @@ -317,7 +318,7 @@ public class ContainerSearchTest { } @Test - public void shouldRestrictByLabels() { + public void shouldRestrictByParentSelector() { Map selector = ImmutableMap.of("app", "che"); ContainerSearch search = new ContainerSearch(null, selector, null); @@ -332,6 +333,27 @@ public class ContainerSearchTest { assertContainsContainer(results, "container11"); } + @Test + public void shouldConsiderEmptySelectorAsNotPresent() { + ContainerSearch search = new ContainerSearch(null, Collections.emptyMap(), null); + + List results = search.search(testList); + + Assert.assertEquals(results.size(), 12); + assertContainsContainer(results, "container1"); + assertContainsContainer(results, "container2"); + assertContainsContainer(results, "container3"); + assertContainsContainer(results, "container4"); + assertContainsContainer(results, "container5"); + assertContainsContainer(results, "container6"); + assertContainsContainer(results, "container7"); + assertContainsContainer(results, "container8"); + assertContainsContainer(results, "container9"); + assertContainsContainer(results, "container10"); + assertContainsContainer(results, "container11"); + assertContainsContainer(results, "container12"); + } + private static void assertContainsContainer(Collection containers, String name) { containers .stream() diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentProvisionerTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentProvisionerTest.java similarity index 98% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentProvisionerTest.java rename to infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentProvisionerTest.java index 367f86a5b9..b082a66a45 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentProvisionerTest.java +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentProvisionerTest.java @@ -9,13 +9,13 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.dockerimage; +package org.eclipse.che.workspace.infrastructure.kubernetes.devfile; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; import static org.eclipse.che.api.core.model.workspace.config.MachineConfig.MEMORY_LIMIT_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.PUBLIC_ENDPOINT_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.PUBLIC_ENDPOINT_ATTRIBUTE; import static org.eclipse.che.api.workspace.shared.Constants.PROJECTS_VOLUME_NAME; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -27,7 +27,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; -import org.eclipse.che.api.devfile.server.exception.WorkspaceExportException; +import org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException; import org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl; import org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.RecipeImpl; diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentToWorkspaceApplierTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentToWorkspaceApplierTest.java similarity index 96% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentToWorkspaceApplierTest.java rename to infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentToWorkspaceApplierTest.java index 210443f4f1..fb84629599 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/dockerimage/DockerimageComponentToWorkspaceApplierTest.java +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentToWorkspaceApplierTest.java @@ -9,16 +9,16 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.dockerimage; +package org.eclipse.che.workspace.infrastructure.kubernetes.devfile; import static java.util.Collections.emptyMap; import static java.util.Collections.singletonList; -import static org.eclipse.che.api.devfile.server.Constants.DISCOVERABLE_ENDPOINT_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.DOCKERIMAGE_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.PUBLIC_ENDPOINT_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.convert.component.dockerimage.DockerimageComponentToWorkspaceApplier.CHE_COMPONENT_NAME_LABEL; +import static org.eclipse.che.api.workspace.server.devfile.Constants.DISCOVERABLE_ENDPOINT_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.DOCKERIMAGE_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.PUBLIC_ENDPOINT_ATTRIBUTE; import static org.eclipse.che.api.workspace.shared.Constants.PROJECTS_VOLUME_NAME; import static org.eclipse.che.workspace.infrastructure.kubernetes.Constants.MACHINE_NAME_ANNOTATION_FMT; +import static org.eclipse.che.workspace.infrastructure.kubernetes.devfile.DockerimageComponentToWorkspaceApplier.CHE_COMPONENT_NAME_LABEL; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; @@ -44,8 +44,7 @@ import java.util.List; import java.util.Map; import org.eclipse.che.api.core.ValidationException; import org.eclipse.che.api.core.model.workspace.config.ServerConfig; -import org.eclipse.che.api.devfile.server.convert.component.kubernetes.KubernetesEnvironmentProvisioner; -import org.eclipse.che.api.devfile.server.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; import org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; diff --git a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesComponentIntegrityValidatorTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesComponentIntegrityValidatorTest.java new file mode 100644 index 0000000000..ed40ea2329 --- /dev/null +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesComponentIntegrityValidatorTest.java @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2012-2018 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.workspace.infrastructure.kubernetes.devfile; + +import static org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import io.fabric8.kubernetes.api.model.PodBuilder; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException; +import org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl; +import org.eclipse.che.api.workspace.server.model.impl.devfile.EntrypointImpl; +import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesRecipeParser; +import org.mockito.Mock; +import org.mockito.testng.MockitoTestNGListener; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Listeners; +import org.testng.annotations.Test; + +@Listeners(MockitoTestNGListener.class) +public class KubernetesComponentIntegrityValidatorTest { + + @Mock private KubernetesRecipeParser kubernetesRecipeParser; + + private KubernetesComponentValidator validator; + + @BeforeMethod + public void setup() { + Set k8sComponentTypes = new HashSet<>(); + k8sComponentTypes.add(KUBERNETES_COMPONENT_TYPE); + validator = new KubernetesComponentValidator(kubernetesRecipeParser, k8sComponentTypes); + } + + @Test + public void shouldApplySelector() throws Exception { + // given + when(kubernetesRecipeParser.parse(any(String.class))) + .thenReturn( + Arrays.asList( + new PodBuilder().withNewMetadata().addToLabels("app", "test").endMetadata().build(), + new PodBuilder() + .withNewMetadata() + .addToLabels("app", "other") + .endMetadata() + .build())); + + Map selector = new HashMap<>(); + selector.put("app", "test"); + + ComponentImpl component = new ComponentImpl(); + component.setType(KUBERNETES_COMPONENT_TYPE); + component.setReference("ref"); + component.setSelector(selector); + component.setReferenceContent("content"); + + // when + validator.validateComponent(component, __ -> ""); + + // then no exception is thrown + } + + @Test + public void shouldApplyEntrypoint() throws Exception { + // given + when(kubernetesRecipeParser.parse(any(String.class))) + .thenReturn( + Arrays.asList( + new PodBuilder() + .withNewSpec() + .addNewContainer() + .withName("container_a") + .endContainer() + .endSpec() + .build(), + new PodBuilder() + .withNewSpec() + .addNewContainer() + .withName("container_b") + .endContainer() + .endSpec() + .build())); + + ComponentImpl component = new ComponentImpl(); + component.setType(KUBERNETES_COMPONENT_TYPE); + component.setReferenceContent("content"); + component.setReference("ref"); + + EntrypointImpl entrypoint = new EntrypointImpl(); + entrypoint.setContainerName("container_a"); + component.setEntrypoints(Collections.singletonList(entrypoint)); + + // when + validator.validateComponent(component, __ -> ""); + + // then no exception is thrown + } + + @Test + public void shouldValidateContainerMatchingEntrypointInPodMatchingSelector() throws Exception { + // given + when(kubernetesRecipeParser.parse(any(String.class))) + .thenReturn( + Arrays.asList( + new PodBuilder() + .withNewMetadata() + .addToLabels("app", "test") + .endMetadata() + .withNewSpec() + .addNewContainer() + .withName("container_a") + .endContainer() + .endSpec() + .build(), + new PodBuilder() + .withNewMetadata() + .addToLabels("app", "other") + .endMetadata() + .withNewSpec() + .addNewContainer() + .withName("container_a") + .endContainer() + .endSpec() + .build())); + + Map selector = new HashMap<>(); + selector.put("app", "test"); + + ComponentImpl component = new ComponentImpl(); + component.setType(KUBERNETES_COMPONENT_TYPE); + component.setReference("ref"); + component.setSelector(selector); + component.setReferenceContent("content"); + + EntrypointImpl entrypoint = new EntrypointImpl(); + entrypoint.setContainerName("container_a"); + component.setEntrypoints(Collections.singletonList(entrypoint)); + + // when + validator.validateComponent(component, __ -> ""); + + // then no exception is thrown + } + + @Test( + expectedExceptions = DevfileFormatException.class, + expectedExceptionsMessageRegExp = + "Failed to validate content reference of component 'ref' of type 'kubernetes': The selector of the component 'ref' of type 'kubernetes' filters out all objects from the list.") + public void shouldThrowExceptionOnSelectorFilteringOutEverything() throws Exception { + // given + when(kubernetesRecipeParser.parse(any(String.class))) + .thenReturn( + Collections.singletonList( + new PodBuilder() + .withNewMetadata() + .addToLabels("app", "test") + .endMetadata() + .build())); + + Map selector = new HashMap<>(); + selector.put("app", "a different value"); + + ComponentImpl component = new ComponentImpl(); + component.setType(KUBERNETES_COMPONENT_TYPE); + component.setReference("ref"); + component.setSelector(selector); + component.setReferenceContent("content"); + + // when + validator.validateComponent(component, __ -> ""); + + // then exception is thrown + } + + @Test( + expectedExceptions = DevfileFormatException.class, + expectedExceptionsMessageRegExp = + "Failed to validate content reference of component 'ref' of type 'kubernetes': Component 'ref' of type 'kubernetes' contains an entry point that doesn't match any container.") + public void shouldThrowExceptionOnEntrypointNotMatchingAnyContainer() throws Exception { + // given + when(kubernetesRecipeParser.parse(any(String.class))) + .thenReturn( + Collections.singletonList( + new PodBuilder() + .withNewSpec() + .addNewContainer() + .withName("container") + .endContainer() + .endSpec() + .build())); + + ComponentImpl component = new ComponentImpl(); + component.setType(KUBERNETES_COMPONENT_TYPE); + component.setReferenceContent("content"); + component.setReference("ref"); + + EntrypointImpl entrypoint = new EntrypointImpl(); + entrypoint.setContainerName("not that container"); + component.setEntrypoints(Collections.singletonList(entrypoint)); + + // when + validator.validateComponent(component, __ -> ""); + + // then exception is thrown + } + + @Test( + expectedExceptions = DevfileFormatException.class, + expectedExceptionsMessageRegExp = + "Failed to validate content reference of component 'ref' of type 'kubernetes': Component 'ref' of type 'kubernetes' contains an entry point that doesn't match any container.") + public void shouldThrowExceptionOnEntrypointNotMatchingAnyContainerOfPodsMatchingSelector() + throws Exception { + // given + when(kubernetesRecipeParser.parse(any(String.class))) + .thenReturn( + Arrays.asList( + new PodBuilder() + .withNewMetadata() + .addToLabels("app", "test") + .endMetadata() + .withNewSpec() + .addNewContainer() + .withName("container_a") + .endContainer() + .endSpec() + .build(), + new PodBuilder() + .withNewMetadata() + .addToLabels("app", "other") + .endMetadata() + .withNewSpec() + .addNewContainer() + .withName("container_b") + .endContainer() + .endSpec() + .build())); + + Map selector = new HashMap<>(); + selector.put("app", "test"); + + ComponentImpl component = new ComponentImpl(); + component.setType(KUBERNETES_COMPONENT_TYPE); + component.setReferenceContent("content"); + component.setReference("ref"); + component.setSelector(selector); + + EntrypointImpl entrypoint = new EntrypointImpl(); + entrypoint.setContainerName("container_b"); + component.setEntrypoints(Collections.singletonList(entrypoint)); + + // when + validator.validateComponent(component, __ -> ""); + + // then exception is thrown + } +} diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentProvisionerTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesComponentProvisionerTest.java similarity index 55% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentProvisionerTest.java rename to infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesComponentProvisionerTest.java index 3ef3055613..b18d8c6cb4 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentProvisionerTest.java +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesComponentProvisionerTest.java @@ -9,33 +9,42 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.kubernetes; +package org.eclipse.che.workspace.infrastructure.kubernetes.devfile; -import org.eclipse.che.api.devfile.server.exception.WorkspaceExportException; +import static java.lang.String.format; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException; import org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl; import org.eclipse.che.api.workspace.server.model.impl.RecipeImpl; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl; import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment; -import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment; +import org.testng.Assert; import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; /** @author Sergii Leshchenko */ public class KubernetesComponentProvisionerTest { private KubernetesComponentProvisioner kubernetesComponentProvisioner; + private static final List HANDLED_TYPES = + Arrays.asList(KubernetesEnvironment.TYPE, "funky"); @BeforeMethod public void setUp() { - kubernetesComponentProvisioner = new KubernetesComponentProvisioner(); + kubernetesComponentProvisioner = + new KubernetesComponentProvisioner(new HashSet<>(HANDLED_TYPES)); } @Test( expectedExceptions = WorkspaceExportException.class, expectedExceptionsMessageRegExp = - "Workspace with multiple `kubernetes`/`openshift` environments can not be converted to devfile") - public void shouldThrowExceptionIfWorkspaceHasMultipleEnvironmentsWithKubernetesOpenShiftRecipes() + "Workspace with multiple kubernetes/funky environments can not be converted to devfile") + public void shouldThrowExceptionIfWorkspaceHasMultipleEnvironmentsWithHandledRecipes() throws Exception { // given WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); @@ -44,15 +53,15 @@ public class KubernetesComponentProvisionerTest { workspaceConfig.getEnvironments().put("k8sEnv", k8sEnv); EnvironmentImpl osEnv = new EnvironmentImpl(); - osEnv.setRecipe(new RecipeImpl(OpenShiftEnvironment.TYPE, null, null, null)); - workspaceConfig.getEnvironments().put("osEnv", osEnv); + osEnv.setRecipe(new RecipeImpl("funky", null, null, null)); + workspaceConfig.getEnvironments().put("funkyEnv", osEnv); // when kubernetesComponentProvisioner.provision(new DevfileImpl(), workspaceConfig); } @Test - public void shouldNoNothingIfWorkspaceDoesNotHaveEnvironmentsWithKubernetesOpenShiftRecipes() + public void shouldNoNothingIfWorkspaceDoesNotHaveEnvironmentsWithHandledRecipes() throws Exception { // given WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); @@ -64,34 +73,29 @@ public class KubernetesComponentProvisionerTest { kubernetesComponentProvisioner.provision(new DevfileImpl(), workspaceConfig); } - @Test( - expectedExceptions = WorkspaceExportException.class, - expectedExceptionsMessageRegExp = - "Exporting of workspace with `kubernetes` is not supported yet.") - public void shouldThrowExceptionIfWorkspaceHasEnvironmentWithKubernetesRecipe() throws Exception { + @Test(dataProvider = "handledTypes") + public void shouldThrowExceptionIfWorkspaceHasEnvironmentWithExactlyOneHandledType( + String handledType) { // given WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); EnvironmentImpl k8sEnv = new EnvironmentImpl(); - k8sEnv.setRecipe(new RecipeImpl(KubernetesEnvironment.TYPE, null, null, null)); - workspaceConfig.getEnvironments().put("k8sEnv", k8sEnv); + k8sEnv.setRecipe(new RecipeImpl(handledType, null, null, null)); + workspaceConfig.getEnvironments().put("Env", k8sEnv); - // when - kubernetesComponentProvisioner.provision(new DevfileImpl(), workspaceConfig); + try { + // when + kubernetesComponentProvisioner.provision(new DevfileImpl(), workspaceConfig); + } catch (WorkspaceExportException e) { + // then + String expectedMessage = + format("Exporting of workspace with `%s` is not supported yet.", handledType); + + Assert.assertEquals(e.getMessage(), expectedMessage); + } } - @Test( - expectedExceptions = WorkspaceExportException.class, - expectedExceptionsMessageRegExp = - "Exporting of workspace with `openshift` is not supported yet.") - public void shouldThrowExceptionIfWorkspaceHasEnvironmentWithOpenShiftRecipe() throws Exception { - // given - WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); - - EnvironmentImpl osEnv = new EnvironmentImpl(); - osEnv.setRecipe(new RecipeImpl(OpenShiftEnvironment.TYPE, null, null, null)); - workspaceConfig.getEnvironments().put("osEnv", osEnv); - - // when - kubernetesComponentProvisioner.provision(new DevfileImpl(), workspaceConfig); + @DataProvider + public static Object[][] handledTypes() { + return HANDLED_TYPES.stream().map(t -> new Object[] {t}).toArray(Object[][]::new); } } diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentToWorkspaceApplierTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesComponentToWorkspaceApplierTest.java similarity index 85% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentToWorkspaceApplierTest.java rename to infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesComponentToWorkspaceApplierTest.java index 2a8afc52b0..ff644a46a3 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesComponentToWorkspaceApplierTest.java +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesComponentToWorkspaceApplierTest.java @@ -9,7 +9,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.kubernetes; +package org.eclipse.che.workspace.infrastructure.kubernetes.devfile; import static io.fabric8.kubernetes.client.utils.Serialization.unmarshal; import static java.util.Arrays.asList; @@ -17,9 +17,9 @@ import static java.util.Collections.emptyMap; import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; import static org.eclipse.che.api.core.model.workspace.config.Command.MACHINE_NAME_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.KUBERNETES_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.OPENSHIFT_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.OPENSHIFT_COMPONENT_TYPE; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @@ -35,18 +35,19 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.KubernetesList; import io.fabric8.kubernetes.api.model.Pod; import java.io.IOException; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.eclipse.che.api.core.ValidationException; -import org.eclipse.che.api.devfile.server.URLFileContentProvider; -import org.eclipse.che.api.devfile.server.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; import org.eclipse.che.api.workspace.server.model.impl.CommandImpl; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.EntrypointImpl; import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment; import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesRecipeParser; -import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; @@ -73,7 +74,12 @@ public class KubernetesComponentToWorkspaceApplierTest { @BeforeMethod public void setUp() { - applier = new KubernetesComponentToWorkspaceApplier(k8sRecipeParser, k8sEnvProvisioner); + Set k8sBasedComponents = new HashSet<>(); + k8sBasedComponents.add(KUBERNETES_COMPONENT_TYPE); + k8sBasedComponents.add("openshift"); // so that we can work with the petclinic.yaml + applier = + new KubernetesComponentToWorkspaceApplier( + k8sRecipeParser, k8sEnvProvisioner, k8sBasedComponents); workspaceConfig = new WorkspaceConfigImpl(); } @@ -145,7 +151,7 @@ public class KubernetesComponentToWorkspaceApplierTest { public void shouldProvisionEnvironmentWithCorrectRecipeTypeAndContentFromK8SList() throws Exception { // given - String yamlRecipeContent = getResource("petclinic.yaml"); + String yamlRecipeContent = getResource("devfile/petclinic.yaml"); doReturn(toK8SList(yamlRecipeContent).getItems()).when(k8sRecipeParser).parse(anyString()); ComponentImpl component = new ComponentImpl(); component.setType(KUBERNETES_COMPONENT_TYPE); @@ -166,7 +172,7 @@ public class KubernetesComponentToWorkspaceApplierTest { @Test public void shouldUseReferenceContentAsRecipeIfPresent() throws Exception { - String yamlRecipeContent = getResource("petclinic.yaml"); + String yamlRecipeContent = getResource("devfile/petclinic.yaml"); doReturn(toK8SList(yamlRecipeContent).getItems()).when(k8sRecipeParser).parse(anyString()); ComponentImpl component = new ComponentImpl(); component.setType(KUBERNETES_COMPONENT_TYPE); @@ -184,37 +190,14 @@ public class KubernetesComponentToWorkspaceApplierTest { emptyMap()); } - @Test - public void shouldProvisionEnvironmentWithCorrectRecipeTypeAndContentFromOSList() - throws Exception { - // given - String yamlRecipeContent = getResource("petclinic.yaml"); - doReturn(toK8SList(yamlRecipeContent).getItems()).when(k8sRecipeParser).parse(anyString()); - ComponentImpl component = new ComponentImpl(); - component.setType(OPENSHIFT_COMPONENT_TYPE); - component.setReference(REFERENCE_FILENAME); - component.setAlias(COMPONENT_NAME); - - // when - applier.apply(workspaceConfig, component, s -> yamlRecipeContent); - - // then - verify(k8sEnvProvisioner) - .provision( - workspaceConfig, - OpenShiftEnvironment.TYPE, - toK8SList(yamlRecipeContent).getItems(), - emptyMap()); - } - @Test public void shouldFilterRecipeWithGivenSelectors() throws Exception { // given - String yamlRecipeContent = getResource("petclinic.yaml"); + String yamlRecipeContent = getResource("devfile/petclinic.yaml"); final Map selector = singletonMap("app.kubernetes.io/component", "webapp"); ComponentImpl component = new ComponentImpl(); - component.setType(OPENSHIFT_COMPONENT_TYPE); + component.setType(KUBERNETES_COMPONENT_TYPE); component.setReference(REFERENCE_FILENAME); component.setAlias(COMPONENT_NAME); component.setSelector(selector); @@ -227,7 +210,7 @@ public class KubernetesComponentToWorkspaceApplierTest { verify(k8sEnvProvisioner) .provision( eq(workspaceConfig), - eq(OpenShiftEnvironment.TYPE), + eq(KubernetesEnvironment.TYPE), objectsCaptor.capture(), eq(emptyMap())); List resultItemsList = objectsCaptor.getValue(); @@ -241,7 +224,7 @@ public class KubernetesComponentToWorkspaceApplierTest { public void shouldSetMachineNameAttributeToCommandConfiguredInOpenShiftComponentWithOneContainer() throws Exception { // given - String yamlRecipeContent = getResource("petclinic.yaml"); + String yamlRecipeContent = getResource("devfile/petclinic.yaml"); doReturn(toK8SList(yamlRecipeContent).getItems()).when(k8sRecipeParser).parse(anyString()); final Map selector = singletonMap("app.kubernetes.io/component", "webapp"); @@ -267,7 +250,7 @@ public class KubernetesComponentToWorkspaceApplierTest { shouldNotSetMachineNameAttributeToCommandConfiguredInOpenShiftComponentWithMultipleContainers() throws Exception { // given - String yamlRecipeContent = getResource("petclinic.yaml"); + String yamlRecipeContent = getResource("devfile/petclinic.yaml"); doReturn(toK8SList(yamlRecipeContent).getItems()).when(k8sRecipeParser).parse(anyString()); ComponentImpl component = new ComponentImpl(); @@ -290,7 +273,7 @@ public class KubernetesComponentToWorkspaceApplierTest { @Test public void shouldChangeEntrypointsOnMatchingContainers() throws Exception { // given - String yamlRecipeContent = getResource("petclinic.yaml"); + String yamlRecipeContent = getResource("devfile/petclinic.yaml"); doReturn(toK8SList(yamlRecipeContent).getItems()).when(k8sRecipeParser).parse(anyString()); List command = asList("teh", "command"); diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesEnvironmentProvisionerTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesEnvironmentProvisionerTest.java similarity index 87% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesEnvironmentProvisionerTest.java rename to infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesEnvironmentProvisionerTest.java index 5cb1124baa..a4d144bceb 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/kubernetes/KubernetesEnvironmentProvisionerTest.java +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/KubernetesEnvironmentProvisionerTest.java @@ -9,13 +9,13 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.kubernetes; +package org.eclipse.che.workspace.infrastructure.kubernetes.devfile; import static io.fabric8.kubernetes.client.utils.Serialization.unmarshal; import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; -import static org.eclipse.che.api.devfile.server.Constants.KUBERNETES_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.convert.component.kubernetes.KubernetesEnvironmentProvisioner.YAML_CONTENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE; +import static org.eclipse.che.workspace.infrastructure.kubernetes.devfile.KubernetesEnvironmentProvisioner.YAML_CONTENT_TYPE; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doReturn; import static org.testng.Assert.assertEquals; @@ -32,17 +32,19 @@ import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; -import org.eclipse.che.api.devfile.server.exception.DevfileException; -import org.eclipse.che.api.devfile.server.exception.DevfileFormatException; +import java.util.Map; +import java.util.Set; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException; import org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl; import org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.RecipeImpl; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment; import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesRecipeParser; -import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.testng.MockitoTestNGListener; import org.testng.annotations.BeforeMethod; @@ -61,18 +63,31 @@ public class KubernetesEnvironmentProvisionerTest { private WorkspaceConfigImpl workspaceConfig; @Mock private KubernetesRecipeParser k8sRecipeParser; - @InjectMocks private KubernetesEnvironmentProvisioner k8sEnvProvisioner; + private KubernetesEnvironmentProvisioner k8sEnvProvisioner; @BeforeMethod public void setUp() { workspaceConfig = new WorkspaceConfigImpl(); + + // "openshift" is what we use in the test devfile files and what we need to test the upgrade + // and multiple k8s-based types + Map> allowedUpgrades = new HashMap<>(); + allowedUpgrades + .compute("openshift", (__, ___) -> new HashSet<>()) + .add(KubernetesEnvironment.TYPE); + Set k8sEnvTypes = new HashSet<>(); + k8sEnvTypes.add(KubernetesEnvironment.TYPE); + k8sEnvTypes.add("openshift"); + + k8sEnvProvisioner = + new KubernetesEnvironmentProvisioner(k8sRecipeParser, allowedUpgrades, k8sEnvTypes); } @Test public void shouldProvisionEnvironmentWithCorrectRecipeTypeAndContentFromK8SList() throws Exception { // given - String yamlRecipeContent = getResource("petclinic.yaml"); + String yamlRecipeContent = getResource("devfile/petclinic.yaml"); List componentsObjects = toK8SList(yamlRecipeContent).getItems(); // when @@ -138,14 +153,13 @@ public class KubernetesEnvironmentProvisionerTest { doReturn(new ArrayList<>()).when(k8sRecipeParser).parse(anyString()); // when - k8sEnvProvisioner.provision( - workspaceConfig, OpenShiftEnvironment.TYPE, componentsObject, emptyMap()); + k8sEnvProvisioner.provision(workspaceConfig, "openshift", componentsObject, emptyMap()); // then EnvironmentImpl resultEnv = workspaceConfig.getEnvironments().get(workspaceConfig.getDefaultEnv()); RecipeImpl resultRecipe = resultEnv.getRecipe(); - assertEquals(resultRecipe.getType(), OpenShiftEnvironment.TYPE); + assertEquals(resultRecipe.getType(), "openshift"); } @Test @@ -201,7 +215,7 @@ public class KubernetesEnvironmentProvisionerTest { @Test( expectedExceptions = DevfileException.class, expectedExceptionsMessageRegExp = - "Kubernetes component can only be applied to a workspace with either kubernetes or openshift " + "Kubernetes component can only be applied to a workspace with any of kubernetes or openshift " + "recipe type but workspace has a recipe of type 'any'") public void shouldThrowAnExceptionIfWorkspaceAlreadyContainNonK8sNorOSRecipe() throws Exception { // given diff --git a/wsmaster/che-core-api-devfile/src/test/resources/petclinic.yaml b/infrastructures/kubernetes/src/test/resources/devfile/petclinic.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/petclinic.yaml rename to infrastructures/kubernetes/src/test/resources/devfile/petclinic.yaml diff --git a/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/OpenShiftInfraModule.java b/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/OpenShiftInfraModule.java index 5d543f14e5..111ea8a661 100644 --- a/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/OpenShiftInfraModule.java +++ b/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/OpenShiftInfraModule.java @@ -11,6 +11,9 @@ */ package org.eclipse.che.workspace.infrastructure.openshift; +import static org.eclipse.che.api.workspace.server.devfile.Constants.DOCKERIMAGE_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.OPENSHIFT_COMPONENT_TYPE; import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.CommonPVCStrategy.COMMON_STRATEGY; import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.PerWorkspacePVCStrategy.PER_WORKSPACE_STRATEGY; import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.UniqueWorkspacePVCStrategy.UNIQUE_STRATEGY; @@ -22,6 +25,8 @@ import com.google.inject.multibindings.MapBinder; import com.google.inject.multibindings.Multibinder; import org.eclipse.che.api.system.server.ServiceTermination; import org.eclipse.che.api.workspace.server.NoEnvironmentFactory; +import org.eclipse.che.api.workspace.server.devfile.DevfileBindings; +import org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator.NoopComponentIntegrityValidator; import org.eclipse.che.api.workspace.server.spi.RuntimeInfrastructure; import org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironmentFactory; import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiExternalEnvVarProvider; @@ -37,6 +42,12 @@ import org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesEnvironment import org.eclipse.che.workspace.infrastructure.kubernetes.StartSynchronizerFactory; import org.eclipse.che.workspace.infrastructure.kubernetes.bootstrapper.KubernetesBootstrapperFactory; import org.eclipse.che.workspace.infrastructure.kubernetes.cache.jpa.JpaKubernetesRuntimeCacheModule; +import org.eclipse.che.workspace.infrastructure.kubernetes.devfile.DockerimageComponentProvisioner; +import org.eclipse.che.workspace.infrastructure.kubernetes.devfile.DockerimageComponentToWorkspaceApplier; +import org.eclipse.che.workspace.infrastructure.kubernetes.devfile.KubernetesComponentProvisioner; +import org.eclipse.che.workspace.infrastructure.kubernetes.devfile.KubernetesComponentToWorkspaceApplier; +import org.eclipse.che.workspace.infrastructure.kubernetes.devfile.KubernetesComponentValidator; +import org.eclipse.che.workspace.infrastructure.kubernetes.devfile.KubernetesDevfileBindings; import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment; import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironmentFactory; import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespaceFactory; @@ -59,6 +70,7 @@ import org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.PluginBroke import org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.SidecarToolingProvisioner; import org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.BrokerEnvironmentFactory; import org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.events.BrokerService; +import org.eclipse.che.workspace.infrastructure.openshift.devfile.OpenshiftComponentToWorkspaceApplier; import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment; import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironmentFactory; import org.eclipse.che.workspace.infrastructure.openshift.project.OpenShiftProjectFactory; @@ -146,5 +158,39 @@ public class OpenShiftInfraModule extends AbstractModule { bind(new TypeLiteral>() {}) .to(OpenShiftEnvironmentProvisioner.class); + + DevfileBindings.onComponentIntegrityValidatorBinder( + binder(), + binder -> { + binder.addBinding(KUBERNETES_COMPONENT_TYPE).to(KubernetesComponentValidator.class); + binder.addBinding(OPENSHIFT_COMPONENT_TYPE).to(KubernetesComponentValidator.class); + binder.addBinding(DOCKERIMAGE_COMPONENT_TYPE).to(NoopComponentIntegrityValidator.class); + }); + + DevfileBindings.onWorkspaceApplierBinder( + binder(), + binder -> { + binder + .addBinding(KUBERNETES_COMPONENT_TYPE) + .to(KubernetesComponentToWorkspaceApplier.class); + binder + .addBinding(DOCKERIMAGE_COMPONENT_TYPE) + .to(DockerimageComponentToWorkspaceApplier.class); + binder + .addBinding(OPENSHIFT_COMPONENT_TYPE) + .to(OpenshiftComponentToWorkspaceApplier.class); + }); + + DevfileBindings.addComponentProvisioners( + binder(), KubernetesComponentProvisioner.class, DockerimageComponentProvisioner.class); + + KubernetesDevfileBindings.addKubernetesBasedEnvironmentTypeBindings( + binder(), KubernetesEnvironment.TYPE, OpenShiftEnvironment.TYPE); + + KubernetesDevfileBindings.addKubernetesBasedComponentTypeBindings( + binder(), KUBERNETES_COMPONENT_TYPE, OPENSHIFT_COMPONENT_TYPE); + + KubernetesDevfileBindings.addAllowedEnvironmentTypeUpgradeBindings( + binder(), OpenShiftEnvironment.TYPE, KubernetesEnvironment.TYPE); } } diff --git a/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/devfile/OpenshiftComponentToWorkspaceApplier.java b/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/devfile/OpenshiftComponentToWorkspaceApplier.java new file mode 100644 index 0000000000..ca02c9eefe --- /dev/null +++ b/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/devfile/OpenshiftComponentToWorkspaceApplier.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012-2018 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.workspace.infrastructure.openshift.devfile; + +import static org.eclipse.che.workspace.infrastructure.kubernetes.devfile.KubernetesDevfileBindings.KUBERNETES_BASED_COMPONENTS_KEY_NAME; + +import java.util.Set; +import javax.inject.Inject; +import javax.inject.Named; +import org.eclipse.che.workspace.infrastructure.kubernetes.devfile.KubernetesComponentToWorkspaceApplier; +import org.eclipse.che.workspace.infrastructure.kubernetes.devfile.KubernetesEnvironmentProvisioner; +import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesRecipeParser; +import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment; + +public class OpenshiftComponentToWorkspaceApplier extends KubernetesComponentToWorkspaceApplier { + @Inject + public OpenshiftComponentToWorkspaceApplier( + KubernetesRecipeParser objectsParser, + KubernetesEnvironmentProvisioner k8sEnvProvisioner, + @Named(KUBERNETES_BASED_COMPONENTS_KEY_NAME) Set kubernetesBasedComponentTypes) { + super( + objectsParser, k8sEnvProvisioner, OpenShiftEnvironment.TYPE, kubernetesBasedComponentTypes); + } +} diff --git a/infrastructures/openshift/src/test/java/org/eclipse/che/workspace/infrastructure/openshift/devfile/OpenshiftComponentToWorkspaceApplierTest.java b/infrastructures/openshift/src/test/java/org/eclipse/che/workspace/infrastructure/openshift/devfile/OpenshiftComponentToWorkspaceApplierTest.java new file mode 100644 index 0000000000..aebefb8ade --- /dev/null +++ b/infrastructures/openshift/src/test/java/org/eclipse/che/workspace/infrastructure/openshift/devfile/OpenshiftComponentToWorkspaceApplierTest.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2012-2018 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.workspace.infrastructure.openshift.devfile; + +import static java.util.Collections.emptyList; +import static java.util.Collections.emptyMap; +import static org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import java.util.HashSet; +import java.util.Set; +import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; +import org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl; +import org.eclipse.che.workspace.infrastructure.kubernetes.devfile.KubernetesComponentToWorkspaceApplier; +import org.eclipse.che.workspace.infrastructure.kubernetes.devfile.KubernetesEnvironmentProvisioner; +import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesRecipeParser; +import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment; +import org.mockito.Mock; +import org.mockito.testng.MockitoTestNGListener; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Listeners; +import org.testng.annotations.Test; + +@Listeners(MockitoTestNGListener.class) +public class OpenshiftComponentToWorkspaceApplierTest { + public static final String REFERENCE_FILENAME = "reference.yaml"; + public static final String COMPONENT_NAME = "foo"; + + private WorkspaceConfigImpl workspaceConfig; + + private KubernetesComponentToWorkspaceApplier applier; + @Mock private KubernetesEnvironmentProvisioner k8sEnvProvisioner; + @Mock private KubernetesRecipeParser k8sRecipeParser; + + @BeforeMethod + public void setUp() { + Set k8sBasedComponents = new HashSet<>(); + k8sBasedComponents.add(KUBERNETES_COMPONENT_TYPE); + applier = + new OpenshiftComponentToWorkspaceApplier( + k8sRecipeParser, k8sEnvProvisioner, k8sBasedComponents); + + workspaceConfig = new WorkspaceConfigImpl(); + } + + @Test + public void shouldProvisionEnvironmentWithCorrectRecipeTypeAndContentFromOSList() + throws Exception { + // given + doReturn(emptyList()).when(k8sRecipeParser).parse(anyString()); + ComponentImpl component = new ComponentImpl(); + component.setType(KUBERNETES_COMPONENT_TYPE); + component.setReference(REFERENCE_FILENAME); + component.setAlias(COMPONENT_NAME); + + // when + applier.apply(workspaceConfig, component, s -> "content"); + + // then + verify(k8sEnvProvisioner) + .provision(workspaceConfig, OpenShiftEnvironment.TYPE, emptyList(), emptyMap()); + } +} diff --git a/multiuser/api/che-multiuser-api-resource/src/main/java/org/eclipse/che/multiuser/resource/api/workspace/LimitsCheckingWorkspaceManager.java b/multiuser/api/che-multiuser-api-resource/src/main/java/org/eclipse/che/multiuser/resource/api/workspace/LimitsCheckingWorkspaceManager.java index 49a25e3d4a..06d9a1e7d9 100644 --- a/multiuser/api/che-multiuser-api-resource/src/main/java/org/eclipse/che/multiuser/resource/api/workspace/LimitsCheckingWorkspaceManager.java +++ b/multiuser/api/che-multiuser-api-resource/src/main/java/org/eclipse/che/multiuser/resource/api/workspace/LimitsCheckingWorkspaceManager.java @@ -32,10 +32,10 @@ import org.eclipse.che.api.core.model.workspace.Workspace; import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; import org.eclipse.che.api.core.model.workspace.config.Environment; import org.eclipse.che.api.core.notification.EventService; -import org.eclipse.che.api.workspace.server.DevfileToWorkspaceConfigConverter; import org.eclipse.che.api.workspace.server.WorkspaceManager; import org.eclipse.che.api.workspace.server.WorkspaceRuntimes; import org.eclipse.che.api.workspace.server.WorkspaceValidator; +import org.eclipse.che.api.workspace.server.devfile.convert.DevfileConverter; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl; import org.eclipse.che.api.workspace.server.spi.WorkspaceDao; @@ -84,9 +84,8 @@ public class LimitsCheckingWorkspaceManager extends WorkspaceManager { EnvironmentRamCalculator environmentRamCalculator, ResourceManager resourceManager, ResourcesLocks resourcesLocks, - DevfileToWorkspaceConfigConverter devfileConverter) { - super( - workspaceDao, runtimes, eventService, accountManager, workspaceValidator, devfileConverter); + DevfileConverter devfileConverter) { + super(workspaceDao, runtimes, eventService, accountManager, workspaceValidator); this.environmentRamCalculator = environmentRamCalculator; this.maxRamPerEnvMB = "-1".equals(maxRamPerEnv) ? -1 : Size.parseSizeToMegabytes(maxRamPerEnv); this.resourceManager = resourceManager; diff --git a/multiuser/integration-tests/che-multiuser-cascade-removal/src/test/java/org/eclipse/che/multiuser/integration/jpa/cascaderemoval/JpaEntitiesCascadeRemovalTest.java b/multiuser/integration-tests/che-multiuser-cascade-removal/src/test/java/org/eclipse/che/multiuser/integration/jpa/cascaderemoval/JpaEntitiesCascadeRemovalTest.java index 476e0acc28..33400caa60 100644 --- a/multiuser/integration-tests/che-multiuser-cascade-removal/src/test/java/org/eclipse/che/multiuser/integration/jpa/cascaderemoval/JpaEntitiesCascadeRemovalTest.java +++ b/multiuser/integration-tests/che-multiuser-cascade-removal/src/test/java/org/eclipse/che/multiuser/integration/jpa/cascaderemoval/JpaEntitiesCascadeRemovalTest.java @@ -75,11 +75,11 @@ import org.eclipse.che.api.user.server.spi.ProfileDao; import org.eclipse.che.api.user.server.spi.UserDao; import org.eclipse.che.api.workspace.server.DefaultWorkspaceLockService; import org.eclipse.che.api.workspace.server.DefaultWorkspaceStatusCache; -import org.eclipse.che.api.workspace.server.DevfileToWorkspaceConfigConverter; import org.eclipse.che.api.workspace.server.WorkspaceLockService; import org.eclipse.che.api.workspace.server.WorkspaceManager; import org.eclipse.che.api.workspace.server.WorkspaceSharedPool; import org.eclipse.che.api.workspace.server.WorkspaceStatusCache; +import org.eclipse.che.api.workspace.server.devfile.DevfileModule; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl; import org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl; import org.eclipse.che.api.workspace.server.spi.RuntimeInfrastructure; @@ -238,6 +238,7 @@ public class JpaEntitiesCascadeRemovalTest { install(new OrganizationJpaModule()); install(new MultiuserWorkspaceJpaModule()); install(new MachineAuthModule()); + install(new DevfileModule()); bind(FreeResourcesLimitDao.class).to(JpaFreeResourcesLimitDao.class); bind(RemoveFreeResourcesLimitSubscriber.class).asEagerSingleton(); @@ -263,14 +264,6 @@ public class JpaEntitiesCascadeRemovalTest { .toInstance(new String[0]); bind(RemoveOrganizationOnLastUserRemovedEventSubscriber.class).asEagerSingleton(); - // is not used in a scope of integration tests - // but instance is needed for setting WorkspaceManager up - bind(DevfileToWorkspaceConfigConverter.class) - .toInstance( - devfile -> { - throw new UnsupportedOperationException("Operation is not implemented"); - }); - Multibinder.newSetBinder(binder(), ResourceLockKeyProvider.class); Multibinder.newSetBinder(binder(), ResourceUsageTracker.class); MapBinder.newMapBinder(binder(), String.class, AvailableResourcesProvider.class); @@ -297,6 +290,17 @@ public class JpaEntitiesCascadeRemovalTest { RamResourceType.ID, 1024, RamResourceType.UNIT))))); bindConstant().annotatedWith(Names.named("che.workspace.probe_pool_size")).to(1); + + // setup bindings for the devfile that would otherwise be read from the config + bindConstant() + .annotatedWith(Names.named("che.workspace.devfile.default_editor")) + .to("default/editor/0.0.1"); + bindConstant() + .annotatedWith(Names.named("che.websocket.endpoint")) + .to("che.websocket.endpoint"); + bind(String[].class) + .annotatedWith(Names.named("che.workspace.devfile.default_editor.plugins")) + .toInstance(new String[] {"default/plugin/0.0.1"}); } }); diff --git a/multiuser/permission/che-multiuser-permission-devfile/pom.xml b/multiuser/permission/che-multiuser-permission-devfile/pom.xml index 8f44a5fd58..1fa0d2b940 100644 --- a/multiuser/permission/che-multiuser-permission-devfile/pom.xml +++ b/multiuser/permission/che-multiuser-permission-devfile/pom.xml @@ -34,10 +34,6 @@ org.eclipse.che.core che-core-api-core - - org.eclipse.che.core - che-core-api-devfile - org.eclipse.che.core che-core-api-workspace @@ -111,7 +107,6 @@ org.eclipse.che.multiuser:che-multiuser-api-permission - org.eclipse.che.core:che-core-api-devfile diff --git a/multiuser/permission/che-multiuser-permission-devfile/src/main/java/org/eclipse/che/multiuser/permission/devfile/DevfilePermissionsFilter.java b/multiuser/permission/che-multiuser-permission-devfile/src/main/java/org/eclipse/che/multiuser/permission/devfile/DevfilePermissionsFilter.java index 3600f4f0be..4293b4f9fd 100644 --- a/multiuser/permission/che-multiuser-permission-devfile/src/main/java/org/eclipse/che/multiuser/permission/devfile/DevfilePermissionsFilter.java +++ b/multiuser/permission/che-multiuser-permission-devfile/src/main/java/org/eclipse/che/multiuser/permission/devfile/DevfilePermissionsFilter.java @@ -16,8 +16,8 @@ import javax.ws.rs.Path; import org.eclipse.che.api.core.ForbiddenException; import org.eclipse.che.api.core.NotFoundException; import org.eclipse.che.api.core.ServerException; -import org.eclipse.che.api.devfile.server.DevfileService; import org.eclipse.che.api.workspace.server.WorkspaceManager; +import org.eclipse.che.api.workspace.server.devfile.DevfileService; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl; import org.eclipse.che.commons.env.EnvironmentContext; import org.eclipse.che.commons.subject.Subject; diff --git a/multiuser/permission/che-multiuser-permission-devfile/src/test/java/org/eclipse/che/multiuser/permissions/devfile/DevfilePermissionsFilterTest.java b/multiuser/permission/che-multiuser-permission-devfile/src/test/java/org/eclipse/che/multiuser/permissions/devfile/DevfilePermissionsFilterTest.java index 09048af0e0..980b9c05c3 100644 --- a/multiuser/permission/che-multiuser-permission-devfile/src/test/java/org/eclipse/che/multiuser/permissions/devfile/DevfilePermissionsFilterTest.java +++ b/multiuser/permission/che-multiuser-permission-devfile/src/test/java/org/eclipse/che/multiuser/permissions/devfile/DevfilePermissionsFilterTest.java @@ -26,8 +26,8 @@ import static org.testng.Assert.assertEquals; import com.jayway.restassured.response.Response; import org.eclipse.che.api.core.ForbiddenException; -import org.eclipse.che.api.devfile.server.DevfileService; import org.eclipse.che.api.workspace.server.WorkspaceManager; +import org.eclipse.che.api.workspace.server.devfile.DevfileService; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl; import org.eclipse.che.commons.env.EnvironmentContext; import org.eclipse.che.commons.subject.Subject; diff --git a/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-ide/pom.xml b/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-ide/pom.xml index 26a253202e..96ff05feb7 100644 --- a/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-ide/pom.xml +++ b/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-ide/pom.xml @@ -46,10 +46,12 @@ org.eclipse.che.core che-core-api-project - - - org.eclipse.che.core - che-core-api-workspace + + + icu4j + com.ibm.icu + + org.eclipse.che.core diff --git a/pom.xml b/pom.xml index 1b889e79d4..4ab70496c8 100644 --- a/pom.xml +++ b/pom.xml @@ -335,11 +335,6 @@ ${che.version} sources - - org.eclipse.che.core - che-core-api-devfile - ${che.version} - org.eclipse.che.core che-core-api-dto diff --git a/wsmaster/che-core-api-devfile/pom.xml b/wsmaster/che-core-api-devfile/pom.xml deleted file mode 100644 index 9a4f6f0148..0000000000 --- a/wsmaster/che-core-api-devfile/pom.xml +++ /dev/null @@ -1,184 +0,0 @@ - - - - 4.0.0 - - che-master-parent - org.eclipse.che.core - 7.0.0-RC-1.0-SNAPSHOT - - che-core-api-devfile - jar - Che Core :: API :: Devfile - - - com.fasterxml.jackson.core - jackson-core - - - com.fasterxml.jackson.core - jackson-databind - - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - - - com.google.guava - guava - - - com.google.inject - guice - - - io.fabric8 - kubernetes-client - - - io.fabric8 - kubernetes-model - - - io.swagger - swagger-annotations - - - javax.inject - javax.inject - - - javax.validation - validation-api - - - org.eclipse.che.core - che-core-api-core - - - org.eclipse.che.core - che-core-api-model - - - org.eclipse.che.core - che-core-api-workspace - - - org.eclipse.che.core - che-core-api-workspace-shared - - - org.eclipse.che.core - che-core-commons-annotations - - - org.eclipse.che.core - che-core-commons-lang - - - org.eclipse.che.infrastructure - infrastructure-kubernetes - - - org.eclipse.che.infrastructure - infrastructure-openshift - - - org.eclipse.che.infrastructure.docker - docker-environment - - - org.glassfish - javax.json - - - org.leadpony.justify - justify - - - org.slf4j - slf4j-api - - - javax.ws.rs - javax.ws.rs-api - provided - - - ch.qos.logback - logback-classic - test - - - com.jayway.restassured - rest-assured - test - - - org.eclipse.che.core - che-core-api-account - test - - - org.eclipse.che.core - che-core-api-dto - test - - - org.eclipse.che.core - che-core-commons-json - test - - - org.everrest - everrest-assured - test - - - org.everrest - everrest-core - test - - - org.mockito - mockito-core - test - - - org.mockito - mockito-testng - test - - - org.testng - testng - test - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - **/Dockerfile - **/*.sh - - - - - - diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/DevfileModule.java b/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/DevfileModule.java deleted file mode 100644 index 18819eb33d..0000000000 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/DevfileModule.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2012-2018 Red Hat, Inc. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ -package org.eclipse.che.api.devfile.server; - -import static com.google.inject.multibindings.MapBinder.newMapBinder; -import static com.google.inject.multibindings.Multibinder.newSetBinder; -import static org.eclipse.che.api.devfile.server.Constants.DOCKERIMAGE_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.KUBERNETES_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.OPENSHIFT_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.PLUGIN_COMPONENT_TYPE; - -import com.google.inject.AbstractModule; -import com.google.inject.multibindings.MapBinder; -import com.google.inject.multibindings.Multibinder; -import org.eclipse.che.api.devfile.server.convert.DevfileConverter; -import org.eclipse.che.api.devfile.server.convert.component.ComponentProvisioner; -import org.eclipse.che.api.devfile.server.convert.component.ComponentToWorkspaceApplier; -import org.eclipse.che.api.devfile.server.convert.component.dockerimage.DockerimageComponentProvisioner; -import org.eclipse.che.api.devfile.server.convert.component.dockerimage.DockerimageComponentToWorkspaceApplier; -import org.eclipse.che.api.devfile.server.convert.component.editor.EditorComponentProvisioner; -import org.eclipse.che.api.devfile.server.convert.component.editor.EditorComponentToWorkspaceApplier; -import org.eclipse.che.api.devfile.server.convert.component.kubernetes.KubernetesComponentProvisioner; -import org.eclipse.che.api.devfile.server.convert.component.kubernetes.KubernetesComponentToWorkspaceApplier; -import org.eclipse.che.api.devfile.server.convert.component.plugin.PluginComponentToWorkspaceApplier; -import org.eclipse.che.api.devfile.server.convert.component.plugin.PluginProvisioner; -import org.eclipse.che.api.devfile.server.validator.DevfileSchemaValidator; -import org.eclipse.che.api.workspace.server.DevfileToWorkspaceConfigConverter; - -/** @author Sergii Leshchenko */ -public class DevfileModule extends AbstractModule { - - @Override - protected void configure() { - bind(DevfileSchemaValidator.class); - bind(DevfileService.class); - - Multibinder workspaceToDevfileAppliers = - newSetBinder(binder(), ComponentProvisioner.class); - workspaceToDevfileAppliers.addBinding().to(EditorComponentProvisioner.class); - workspaceToDevfileAppliers.addBinding().to(PluginProvisioner.class); - workspaceToDevfileAppliers.addBinding().to(DockerimageComponentProvisioner.class); - workspaceToDevfileAppliers.addBinding().to(KubernetesComponentProvisioner.class); - - MapBinder componentToWorkspaceApplier = - newMapBinder(binder(), String.class, ComponentToWorkspaceApplier.class); - componentToWorkspaceApplier - .addBinding(EDITOR_COMPONENT_TYPE) - .to(EditorComponentToWorkspaceApplier.class); - componentToWorkspaceApplier - .addBinding(PLUGIN_COMPONENT_TYPE) - .to(PluginComponentToWorkspaceApplier.class); - componentToWorkspaceApplier - .addBinding(OPENSHIFT_COMPONENT_TYPE) - .to(KubernetesComponentToWorkspaceApplier.class); - componentToWorkspaceApplier - .addBinding(KUBERNETES_COMPONENT_TYPE) - .to(KubernetesComponentToWorkspaceApplier.class); - componentToWorkspaceApplier - .addBinding(DOCKERIMAGE_COMPONENT_TYPE) - .to(DockerimageComponentToWorkspaceApplier.class); - - bind(DevfileToWorkspaceConfigConverter.class).to(DevfileConverter.class); - } -} diff --git a/wsmaster/che-core-api-factory-github/pom.xml b/wsmaster/che-core-api-factory-github/pom.xml index e7d4647075..59f8a7314c 100644 --- a/wsmaster/che-core-api-factory-github/pom.xml +++ b/wsmaster/che-core-api-factory-github/pom.xml @@ -42,10 +42,6 @@ org.eclipse.che.core che-core-api-core - - org.eclipse.che.core - che-core-api-devfile - org.eclipse.che.core che-core-api-dto @@ -58,6 +54,10 @@ org.eclipse.che.core che-core-api-factory-shared + + org.eclipse.che.core + che-core-api-workspace + org.eclipse.che.core che-core-api-workspace-shared diff --git a/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubFactoryParametersResolver.java b/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubFactoryParametersResolver.java index 8b8f848ff9..efe3963acc 100644 --- a/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubFactoryParametersResolver.java +++ b/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubFactoryParametersResolver.java @@ -21,11 +21,11 @@ import javax.inject.Singleton; import javax.validation.constraints.NotNull; import org.eclipse.che.api.core.BadRequestException; import org.eclipse.che.api.core.ServerException; -import org.eclipse.che.api.devfile.server.URLFetcher; import org.eclipse.che.api.factory.server.FactoryParametersResolver; import org.eclipse.che.api.factory.server.urlfactory.ProjectConfigDtoMerger; import org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder; import org.eclipse.che.api.factory.shared.dto.FactoryDto; +import org.eclipse.che.api.workspace.server.devfile.URLFetcher; import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto; /** diff --git a/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubURLParser.java b/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubURLParser.java index d04ef6dd44..5142a02b9b 100644 --- a/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubURLParser.java +++ b/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubURLParser.java @@ -16,7 +16,7 @@ import java.util.regex.Pattern; import javax.inject.Inject; import javax.inject.Singleton; import javax.validation.constraints.NotNull; -import org.eclipse.che.api.devfile.server.URLFetcher; +import org.eclipse.che.api.workspace.server.devfile.URLFetcher; /** * Parser of String Github URLs and provide {@link GithubUrl} objects. diff --git a/wsmaster/che-core-api-factory-github/src/test/java/org/eclipse/che/api/factory/server/github/GithubFactoryParametersResolverTest.java b/wsmaster/che-core-api-factory-github/src/test/java/org/eclipse/che/api/factory/server/github/GithubFactoryParametersResolverTest.java index 74ea162299..0d149ae45e 100644 --- a/wsmaster/che-core-api-factory-github/src/test/java/org/eclipse/che/api/factory/server/github/GithubFactoryParametersResolverTest.java +++ b/wsmaster/che-core-api-factory-github/src/test/java/org/eclipse/che/api/factory/server/github/GithubFactoryParametersResolverTest.java @@ -32,6 +32,7 @@ import org.eclipse.che.api.factory.server.urlfactory.ProjectConfigDtoMerger; import org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl; import org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder; import org.eclipse.che.api.factory.shared.dto.FactoryDto; +import org.eclipse.che.api.workspace.server.devfile.FileContentProvider; import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto; import org.eclipse.che.api.workspace.shared.dto.SourceStorageDto; import org.mockito.ArgumentCaptor; @@ -70,8 +71,7 @@ public class GithubFactoryParametersResolverTest { /** * Capturing the location parameter when calling {@link * URLFactoryBuilder#createFactoryFromJson(RemoteFactoryUrl)} or {@link - * URLFactoryBuilder#createFactoryFromDevfile(RemoteFactoryUrl, - * org.eclipse.che.api.devfile.server.FileContentProvider)} + * URLFactoryBuilder#createFactoryFromDevfile(RemoteFactoryUrl, FileContentProvider)} */ @Captor private ArgumentCaptor factoryUrlArgumentCaptor; diff --git a/wsmaster/che-core-api-factory-github/src/test/java/org/eclipse/che/api/factory/server/github/GithubURLParserTest.java b/wsmaster/che-core-api-factory-github/src/test/java/org/eclipse/che/api/factory/server/github/GithubURLParserTest.java index 5931dd9d45..e7c3e8aff1 100644 --- a/wsmaster/che-core-api-factory-github/src/test/java/org/eclipse/che/api/factory/server/github/GithubURLParserTest.java +++ b/wsmaster/che-core-api-factory-github/src/test/java/org/eclipse/che/api/factory/server/github/GithubURLParserTest.java @@ -17,7 +17,7 @@ import static org.mockito.Mockito.when; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; -import org.eclipse.che.api.devfile.server.URLFetcher; +import org.eclipse.che.api.workspace.server.devfile.URLFetcher; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.testng.MockitoTestNGListener; diff --git a/wsmaster/che-core-api-factory/pom.xml b/wsmaster/che-core-api-factory/pom.xml index 88406a38f0..6cfcf69e1a 100644 --- a/wsmaster/che-core-api-factory/pom.xml +++ b/wsmaster/che-core-api-factory/pom.xml @@ -54,10 +54,6 @@ org.eclipse.che.core che-core-api-core - - org.eclipse.che.core - che-core-api-devfile - org.eclipse.che.core che-core-api-dto diff --git a/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/DefaultFactoryParameterResolver.java b/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/DefaultFactoryParameterResolver.java index c32a6ee6fe..3e7d755295 100644 --- a/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/DefaultFactoryParameterResolver.java +++ b/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/DefaultFactoryParameterResolver.java @@ -20,11 +20,11 @@ import javax.inject.Singleton; import javax.validation.constraints.NotNull; import org.eclipse.che.api.core.BadRequestException; import org.eclipse.che.api.core.ServerException; -import org.eclipse.che.api.devfile.server.URLFetcher; -import org.eclipse.che.api.devfile.server.URLFileContentProvider; import org.eclipse.che.api.factory.server.urlfactory.DefaultFactoryUrl; import org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder; import org.eclipse.che.api.factory.shared.dto.FactoryDto; +import org.eclipse.che.api.workspace.server.devfile.URLFetcher; +import org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider; /** * Default {@link FactoryParametersResolver} implementation. Tries to resolve factory based on diff --git a/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/urlfactory/URLFactoryBuilder.java b/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/urlfactory/URLFactoryBuilder.java index 4783046288..dae832fa6c 100644 --- a/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/urlfactory/URLFactoryBuilder.java +++ b/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/urlfactory/URLFactoryBuilder.java @@ -25,12 +25,12 @@ import javax.inject.Named; import javax.inject.Singleton; import org.eclipse.che.api.core.BadRequestException; import org.eclipse.che.api.core.ServerException; -import org.eclipse.che.api.devfile.server.DevfileManager; -import org.eclipse.che.api.devfile.server.FileContentProvider; -import org.eclipse.che.api.devfile.server.URLFetcher; -import org.eclipse.che.api.devfile.server.exception.DevfileException; import org.eclipse.che.api.factory.shared.dto.FactoryDto; import org.eclipse.che.api.workspace.server.DtoConverter; +import org.eclipse.che.api.workspace.server.devfile.DevfileManager; +import org.eclipse.che.api.workspace.server.devfile.FileContentProvider; +import org.eclipse.che.api.workspace.server.devfile.URLFetcher; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl; import org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto; diff --git a/wsmaster/che-core-api-factory/src/test/java/org/eclipse/che/api/factory/server/DefaultFactoryParameterResolverTest.java b/wsmaster/che-core-api-factory/src/test/java/org/eclipse/che/api/factory/server/DefaultFactoryParameterResolverTest.java index 412c40db80..6ef3dd1b35 100644 --- a/wsmaster/che-core-api-factory/src/test/java/org/eclipse/che/api/factory/server/DefaultFactoryParameterResolverTest.java +++ b/wsmaster/che-core-api-factory/src/test/java/org/eclipse/che/api/factory/server/DefaultFactoryParameterResolverTest.java @@ -11,8 +11,11 @@ */ package org.eclipse.che.api.factory.server; -import static java.util.Collections.singletonList; import static org.eclipse.che.api.factory.shared.Constants.URL_PARAMETER_NAME; +import static org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.OPENSHIFT_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.PLUGIN_COMPONENT_TYPE; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; @@ -20,28 +23,28 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import io.fabric8.kubernetes.api.model.PodBuilder; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.eclipse.che.api.devfile.server.DevfileManager; -import org.eclipse.che.api.devfile.server.FileContentProvider; -import org.eclipse.che.api.devfile.server.URLFetcher; -import org.eclipse.che.api.devfile.server.convert.CommandConverter; -import org.eclipse.che.api.devfile.server.convert.DefaultEditorProvisioner; -import org.eclipse.che.api.devfile.server.convert.DevfileConverter; -import org.eclipse.che.api.devfile.server.convert.ProjectConverter; -import org.eclipse.che.api.devfile.server.convert.component.ComponentProvisioner; -import org.eclipse.che.api.devfile.server.convert.component.ComponentToWorkspaceApplier; -import org.eclipse.che.api.devfile.server.schema.DevfileSchemaProvider; -import org.eclipse.che.api.devfile.server.validator.DevfileIntegrityValidator; -import org.eclipse.che.api.devfile.server.validator.DevfileSchemaValidator; import org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder; import org.eclipse.che.api.workspace.server.WorkspaceManager; +import org.eclipse.che.api.workspace.server.devfile.DevfileManager; +import org.eclipse.che.api.workspace.server.devfile.FileContentProvider; +import org.eclipse.che.api.workspace.server.devfile.URLFetcher; +import org.eclipse.che.api.workspace.server.devfile.convert.CommandConverter; +import org.eclipse.che.api.workspace.server.devfile.convert.DefaultEditorProvisioner; +import org.eclipse.che.api.workspace.server.devfile.convert.DevfileConverter; +import org.eclipse.che.api.workspace.server.devfile.convert.ProjectConverter; +import org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentProvisioner; +import org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier; +import org.eclipse.che.api.workspace.server.devfile.schema.DevfileSchemaProvider; +import org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator; +import org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator.NoopComponentIntegrityValidator; +import org.eclipse.che.api.workspace.server.devfile.validator.DevfileIntegrityValidator; +import org.eclipse.che.api.workspace.server.devfile.validator.DevfileSchemaValidator; import org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl; import org.eclipse.che.api.workspace.server.wsplugins.PluginFQNParser; -import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesRecipeParser; import org.mockito.Mock; import org.mockito.testng.MockitoTestNGListener; import org.testng.annotations.Listeners; @@ -60,7 +63,6 @@ public class DefaultFactoryParameterResolverTest { + " reference: ../localfile\n"; @Mock private URLFetcher urlFetcher; - @Mock private KubernetesRecipeParser kubernetesRecipeParser; private PluginFQNParser fqnParser = new PluginFQNParser(); @Test @@ -69,8 +71,14 @@ public class DefaultFactoryParameterResolverTest { // we need to set up an "almost real" devfile converter which is a little bit involved DevfileSchemaValidator validator = new DevfileSchemaValidator(new DevfileSchemaProvider()); - DevfileIntegrityValidator integrityValidator = - new DevfileIntegrityValidator(kubernetesRecipeParser); + + Map validators = new HashMap<>(); + validators.put(EDITOR_COMPONENT_TYPE, new NoopComponentIntegrityValidator()); + validators.put(PLUGIN_COMPONENT_TYPE, new NoopComponentIntegrityValidator()); + validators.put(KUBERNETES_COMPONENT_TYPE, new NoopComponentIntegrityValidator()); + validators.put(OPENSHIFT_COMPONENT_TYPE, new NoopComponentIntegrityValidator()); + + DevfileIntegrityValidator integrityValidator = new DevfileIntegrityValidator(validators); Set componentProvisioners = new HashSet<>(); Map appliers = new HashMap<>(); ComponentToWorkspaceApplier applier = mock(ComponentToWorkspaceApplier.class); @@ -113,20 +121,6 @@ public class DefaultFactoryParameterResolverTest { factoryParameters.put(URL_PARAMETER_NAME, "scheme:/myloc/devfile"); doReturn(DEVFILE).when(urlFetcher).fetchSafely(eq("scheme:/myloc/devfile")); doReturn("localfile").when(urlFetcher).fetch("scheme:/localfile"); - doReturn( - singletonList( - new PodBuilder() - .withNewMetadata() - .withName("pod") - .endMetadata() - .withNewSpec() - .addNewContainer() - .withImage("image") - .endContainer() - .endSpec() - .build())) - .when(kubernetesRecipeParser) - .parse("localfile"); // when res.createFactory(factoryParameters); diff --git a/wsmaster/che-core-api-factory/src/test/java/org/eclipse/che/api/factory/server/urlfactory/URLFactoryBuilderTest.java b/wsmaster/che-core-api-factory/src/test/java/org/eclipse/che/api/factory/server/urlfactory/URLFactoryBuilderTest.java index 8be0b50053..8dabceb110 100644 --- a/wsmaster/che-core-api-factory/src/test/java/org/eclipse/che/api/factory/server/urlfactory/URLFactoryBuilderTest.java +++ b/wsmaster/che-core-api-factory/src/test/java/org/eclipse/che/api/factory/server/urlfactory/URLFactoryBuilderTest.java @@ -13,9 +13,9 @@ package org.eclipse.che.api.factory.server.urlfactory; import static java.util.Collections.emptyMap; import static java.util.Collections.singletonMap; -import static org.eclipse.che.api.devfile.server.Constants.KUBERNETES_COMPONENT_TYPE; import static org.eclipse.che.api.factory.shared.Constants.CURRENT_VERSION; import static org.eclipse.che.api.workspace.server.DtoConverter.asDto; +import static org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE; import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_EDITOR_ATTRIBUTE; import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE; import static org.eclipse.che.dto.server.DtoFactory.newDto; @@ -26,9 +26,9 @@ import static org.testng.Assert.assertEquals; import java.util.HashMap; import java.util.Map; -import org.eclipse.che.api.devfile.server.DevfileManager; -import org.eclipse.che.api.devfile.server.URLFetcher; import org.eclipse.che.api.factory.shared.dto.FactoryDto; +import org.eclipse.che.api.workspace.server.devfile.DevfileManager; +import org.eclipse.che.api.workspace.server.devfile.URLFetcher; import org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl; import org.eclipse.che.api.workspace.server.model.impl.RecipeImpl; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; diff --git a/wsmaster/che-core-api-devfile/README.md b/wsmaster/che-core-api-workspace/README-devfile.md similarity index 100% rename from wsmaster/che-core-api-devfile/README.md rename to wsmaster/che-core-api-workspace/README-devfile.md diff --git a/wsmaster/che-core-api-workspace/pom.xml b/wsmaster/che-core-api-workspace/pom.xml index af45fb6318..f604d6079f 100644 --- a/wsmaster/che-core-api-workspace/pom.xml +++ b/wsmaster/che-core-api-workspace/pom.xml @@ -30,6 +30,18 @@ com.fasterxml.jackson.core jackson-annotations + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + com.google.code.gson gson @@ -74,6 +86,10 @@ javax.inject javax.inject + + javax.validation + validation-api + org.eclipse.che.core che-core-api-account @@ -114,6 +130,10 @@ org.eclipse.che.core che-core-commons-annotations + + org.eclipse.che.core + che-core-commons-json + org.eclipse.che.core che-core-commons-lang @@ -122,6 +142,20 @@ org.eclipse.che.core che-core-commons-tracing + + org.glassfish + javax.json + + + org.leadpony.justify + justify + + + javax.json-api + javax.json + + + org.slf4j slf4j-api diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/DevfileToWorkspaceConfigConverter.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/DevfileToWorkspaceConfigConverter.java deleted file mode 100644 index ea928b626e..0000000000 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/DevfileToWorkspaceConfigConverter.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2012-2018 Red Hat, Inc. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ -package org.eclipse.che.api.workspace.server; - -import org.eclipse.che.api.core.ServerException; -import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; -import org.eclipse.che.api.core.model.workspace.devfile.Devfile; - -/** - * Converts Devfile to WorkspaceConfig. - * - * @author Sergii Leshchenko - */ -public interface DevfileToWorkspaceConfigConverter { - - /** - * Converts Devfile to workspace config. - * - *

Converted workspace config should be used for Workspace start only and should not be - * persisted. - * - * @param devfile the devfile to convert - * @return converted workspace config - * @throws ServerException if the specified devfile can not be converted to workspace config for - * some reasons - */ - WorkspaceConfig convert(Devfile devfile) throws ServerException; -} diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceManager.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceManager.java index 25e05d397e..336ecc4db2 100644 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceManager.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceManager.java @@ -80,8 +80,7 @@ public class WorkspaceManager { WorkspaceRuntimes runtimes, EventService eventService, AccountManager accountManager, - WorkspaceValidator validator, - DevfileToWorkspaceConfigConverter devfileConverter) { + WorkspaceValidator validator) { this.workspaceDao = workspaceDao; this.runtimes = runtimes; this.accountManager = accountManager; diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimes.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimes.java index 6aed584087..88a7c6f553 100644 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimes.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimes.java @@ -60,6 +60,7 @@ import org.eclipse.che.api.core.model.workspace.config.Environment; import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity; import org.eclipse.che.api.core.notification.EventService; import org.eclipse.che.api.core.notification.EventSubscriber; +import org.eclipse.che.api.workspace.server.devfile.convert.DevfileConverter; import org.eclipse.che.api.workspace.server.event.RuntimeAbnormalStoppedEvent; import org.eclipse.che.api.workspace.server.event.RuntimeAbnormalStoppingEvent; import org.eclipse.che.api.workspace.server.hc.probe.ProbeScheduler; @@ -112,7 +113,7 @@ public class WorkspaceRuntimes { private final Map environmentFactories; private final RuntimeInfrastructure infrastructure; private final ProbeScheduler probeScheduler; - private final DevfileToWorkspaceConfigConverter devfileConverter; + private final DevfileConverter devfileConverter; // Unique identifier for this workspace runtimes private final String workspaceRuntimesId; @@ -128,7 +129,7 @@ public class WorkspaceRuntimes { ProbeScheduler probeScheduler, WorkspaceStatusCache statuses, WorkspaceLockService lockService, - DevfileToWorkspaceConfigConverter devfileConverter) { + DevfileConverter devfileConverter) { this( eventService, envFactories, @@ -154,7 +155,7 @@ public class WorkspaceRuntimes { ProbeScheduler probeScheduler, WorkspaceStatusCache statuses, WorkspaceLockService lockService, - DevfileToWorkspaceConfigConverter devfileConverter) { + DevfileConverter devfileConverter) { this.probeScheduler = probeScheduler; this.runtimes = new ConcurrentHashMap<>(); this.statuses = statuses; diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/Components.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/Components.java similarity index 78% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/Components.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/Components.java index 273f631b07..bbabf8c3eb 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/Components.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/Components.java @@ -9,14 +9,14 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server; +package org.eclipse.che.api.workspace.server.devfile; import static java.lang.String.format; -import static org.eclipse.che.api.devfile.server.Constants.DOCKERIMAGE_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.KUBERNETES_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.OPENSHIFT_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.PLUGIN_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.DOCKERIMAGE_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.OPENSHIFT_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.PLUGIN_COMPONENT_TYPE; import org.eclipse.che.api.core.model.workspace.devfile.Component; diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/Constants.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/Constants.java similarity index 77% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/Constants.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/Constants.java index f452017cc0..5948c4baea 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/Constants.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/Constants.java @@ -9,7 +9,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server; +package org.eclipse.che.api.workspace.server.devfile; public class Constants { @@ -52,17 +52,17 @@ public class Constants { public static final String COMPONENT_ALIAS_COMMAND_ATTRIBUTE = "componentAlias"; /** - * {@link Endpoint} attribute name which can identify endpoint as public or internal. Attribute - * value {@code false} makes a endpoint internal, any other value or lack of the attribute makes - * the endpoint public. + * {@link org.eclipse.che.api.core.model.workspace.devfile.Endpoint} attribute name which can + * identify endpoint as public or internal. Attribute value {@code false} makes a endpoint + * internal, any other value or lack of the attribute makes the endpoint public. */ public static final String PUBLIC_ENDPOINT_ATTRIBUTE = "public"; /** - * {@link Endpoint} attribute name which can identify endpoint as discoverable(means that it is - * accessible by its name from workspace's containers). Attribute value {@code true} makes a - * endpoint discoverable, any other value or lack of the attribute makes the endpoint - * non-discoverable. + * {@link org.eclipse.che.api.core.model.workspace.devfile.Endpoint} attribute name which can + * identify endpoint as discoverable(i.e. it is accessible by its name from workspace's + * containers). Attribute value {@code true} makes a endpoint discoverable, any other value or + * lack of the attribute makes the endpoint non-discoverable. */ public static final String DISCOVERABLE_ENDPOINT_ATTRIBUTE = "discoverable"; diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/DevfileBindings.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/DevfileBindings.java new file mode 100644 index 0000000000..12ec823f45 --- /dev/null +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/DevfileBindings.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2012-2018 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.api.workspace.server.devfile; + +import com.google.inject.Binder; +import com.google.inject.multibindings.MapBinder; +import com.google.inject.multibindings.Multibinder; +import java.util.function.Consumer; +import org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentProvisioner; +import org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier; +import org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator; + +/** + * Utility class to ease the adding of devfile-related bindings in a guice module configuration. + * + *

Consult the individual methods on this class to see if you need to use them in a particular + * module. + */ +public class DevfileBindings { + + /** + * The {@code binder} consumer can be used to bind {@link ComponentToWorkspaceApplier} + * implementations to component types. I.e. the keys of the binder are component type strings and + * the bindings are the deemed implementations. + * + * @param baseBinder the binder available in the Guice module calling this method + * @param binder a consumer to accept a new binder for the workspace appliers + */ + public static void onWorkspaceApplierBinder( + Binder baseBinder, Consumer> binder) { + binder.accept( + MapBinder.newMapBinder(baseBinder, String.class, ComponentToWorkspaceApplier.class)); + } + + /** + * The {@code binder} consumer can be used to bind {@link ComponentIntegrityValidator} + * implementations to component types. I.e. the keys of the binder are component type strings and + * the bindings are the deemed implementations. + * + * @param baseBinder the binder available in the Guice module calling this method + * @param binder a consumer to accept a new binder for the component integrity validators + */ + public static void onComponentIntegrityValidatorBinder( + Binder baseBinder, Consumer> binder) { + binder.accept( + MapBinder.newMapBinder(baseBinder, String.class, ComponentIntegrityValidator.class)); + } + + /** + * Binds {@link ComponentProvisioner} implementations to be used in the {@link + * org.eclipse.che.api.workspace.server.devfile.convert.DevfileConverter}. + * + * @param baseBinder the binder available in the Guice module calling this method + * @param impls the classes to register as component provisioners + */ + @SafeVarargs + public static void addComponentProvisioners( + Binder baseBinder, Class... impls) { + Multibinder binder = + Multibinder.newSetBinder(baseBinder, ComponentProvisioner.class); + + for (Class i : impls) { + binder.addBinding().to(i); + } + } + + private DevfileBindings() {} +} diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/DevfileManager.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/DevfileManager.java similarity index 92% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/DevfileManager.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/DevfileManager.java index 18fe631552..2fc4f27ba5 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/DevfileManager.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/DevfileManager.java @@ -9,7 +9,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server; +package org.eclipse.che.api.workspace.server.devfile; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Collections.emptyMap; @@ -26,13 +26,13 @@ import org.eclipse.che.api.core.ConflictException; import org.eclipse.che.api.core.NotFoundException; import org.eclipse.che.api.core.ServerException; import org.eclipse.che.api.core.ValidationException; -import org.eclipse.che.api.devfile.server.convert.DevfileConverter; -import org.eclipse.che.api.devfile.server.exception.DevfileException; -import org.eclipse.che.api.devfile.server.exception.DevfileFormatException; -import org.eclipse.che.api.devfile.server.exception.WorkspaceExportException; -import org.eclipse.che.api.devfile.server.validator.DevfileIntegrityValidator; -import org.eclipse.che.api.devfile.server.validator.DevfileSchemaValidator; import org.eclipse.che.api.workspace.server.WorkspaceManager; +import org.eclipse.che.api.workspace.server.devfile.convert.DevfileConverter; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException; +import org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException; +import org.eclipse.che.api.workspace.server.devfile.validator.DevfileIntegrityValidator; +import org.eclipse.che.api.workspace.server.devfile.validator.DevfileSchemaValidator; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl; @@ -161,7 +161,7 @@ public class DevfileManager { * @throws NotFoundException when no workspace can be found by given key * @throws ConflictException when workspace cannot be exported into devfile * @throws ServerException when other error occurs - * @see WorkspaceManager#getByKey(String) + * @see WorkspaceManager#getWorkspace(String) */ public DevfileImpl exportWorkspace(String key) throws NotFoundException, ServerException, ConflictException { diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/DevfileModule.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/DevfileModule.java new file mode 100644 index 0000000000..5bafd942af --- /dev/null +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/DevfileModule.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2012-2018 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.api.workspace.server.devfile; + +import static org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.PLUGIN_COMPONENT_TYPE; + +import com.google.inject.AbstractModule; +import org.eclipse.che.api.workspace.server.devfile.convert.component.editor.EditorComponentProvisioner; +import org.eclipse.che.api.workspace.server.devfile.convert.component.editor.EditorComponentToWorkspaceApplier; +import org.eclipse.che.api.workspace.server.devfile.convert.component.plugin.PluginComponentToWorkspaceApplier; +import org.eclipse.che.api.workspace.server.devfile.convert.component.plugin.PluginProvisioner; +import org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator.NoopComponentIntegrityValidator; + +/** @author Sergii Leshchenko */ +public class DevfileModule extends AbstractModule { + + @Override + protected void configure() { + bind(DevfileService.class); + + DevfileBindings.addComponentProvisioners( + binder(), EditorComponentProvisioner.class, PluginProvisioner.class); + + DevfileBindings.onWorkspaceApplierBinder( + binder(), + binder -> { + binder.addBinding(EDITOR_COMPONENT_TYPE).to(EditorComponentToWorkspaceApplier.class); + binder.addBinding(PLUGIN_COMPONENT_TYPE).to(PluginComponentToWorkspaceApplier.class); + }); + + DevfileBindings.onComponentIntegrityValidatorBinder( + binder(), + binder -> { + binder.addBinding(PLUGIN_COMPONENT_TYPE).to(NoopComponentIntegrityValidator.class); + binder.addBinding(EDITOR_COMPONENT_TYPE).to(NoopComponentIntegrityValidator.class); + }); + } +} diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/DevfileRecipeFormatException.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/DevfileRecipeFormatException.java similarity index 83% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/DevfileRecipeFormatException.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/DevfileRecipeFormatException.java index ce73d8b5ae..8c5a65819c 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/DevfileRecipeFormatException.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/DevfileRecipeFormatException.java @@ -9,9 +9,9 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server; +package org.eclipse.che.api.workspace.server.devfile; -import org.eclipse.che.api.devfile.server.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; /** Thrown when the provided content of recipe-type component is empty or invalid. */ public class DevfileRecipeFormatException extends DevfileException { diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/DevfileService.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/DevfileService.java similarity index 96% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/DevfileService.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/DevfileService.java index 6c74c42389..4f3b1968ba 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/DevfileService.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/DevfileService.java @@ -9,7 +9,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server; +package org.eclipse.che.api.workspace.server.devfile; import static javax.ws.rs.core.MediaType.APPLICATION_JSON; import static org.eclipse.che.api.workspace.server.DtoConverter.asDto; @@ -40,9 +40,9 @@ import org.eclipse.che.api.core.NotFoundException; import org.eclipse.che.api.core.ServerException; import org.eclipse.che.api.core.ValidationException; import org.eclipse.che.api.core.rest.Service; -import org.eclipse.che.api.devfile.server.exception.DevfileException; -import org.eclipse.che.api.devfile.server.schema.DevfileSchemaProvider; import org.eclipse.che.api.workspace.server.WorkspaceLinksGenerator; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.schema.DevfileSchemaProvider; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl; import org.eclipse.che.api.workspace.shared.dto.WorkspaceDto; diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/FileContentProvider.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/FileContentProvider.java similarity index 95% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/FileContentProvider.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/FileContentProvider.java index ac410bda48..4bee07dfc8 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/FileContentProvider.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/FileContentProvider.java @@ -9,13 +9,13 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server; +package org.eclipse.che.api.workspace.server.devfile; import java.io.IOException; import java.lang.ref.SoftReference; import java.util.HashMap; import java.util.Map; -import org.eclipse.che.api.devfile.server.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; /** * Some types of {@link org.eclipse.che.api.core.model.workspace.devfile.Component} may have diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/URLFetcher.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/URLFetcher.java similarity index 98% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/URLFetcher.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/URLFetcher.java index c7b9a435d5..fb1242da45 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/URLFetcher.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/URLFetcher.java @@ -9,7 +9,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server; +package org.eclipse.che.api.workspace.server.devfile; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Objects.requireNonNull; diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/URLFileContentProvider.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/URLFileContentProvider.java similarity index 94% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/URLFileContentProvider.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/URLFileContentProvider.java index 3e700609bc..20d96d5f82 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/URLFileContentProvider.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/URLFileContentProvider.java @@ -9,14 +9,14 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server; +package org.eclipse.che.api.workspace.server.devfile; import static java.lang.String.format; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import org.eclipse.che.api.devfile.server.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; /** * A simple implementation of the FileContentProvider that merely uses the function resolve relative diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/CommandConverter.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/CommandConverter.java similarity index 92% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/CommandConverter.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/CommandConverter.java index d383651446..e74579fff8 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/CommandConverter.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/CommandConverter.java @@ -9,7 +9,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert; +package org.eclipse.che.api.workspace.server.devfile.convert; import static java.lang.String.format; import static org.eclipse.che.api.core.model.workspace.config.Command.COMMAND_ACTION_REFERENCE_ATTRIBUTE; @@ -19,11 +19,11 @@ import static org.eclipse.che.api.core.model.workspace.config.Command.WORKING_DI import java.io.IOException; import org.eclipse.che.api.core.model.workspace.devfile.Action; import org.eclipse.che.api.core.model.workspace.devfile.Command; -import org.eclipse.che.api.devfile.server.Constants; -import org.eclipse.che.api.devfile.server.FileContentProvider; -import org.eclipse.che.api.devfile.server.exception.DevfileException; -import org.eclipse.che.api.devfile.server.exception.DevfileFormatException; -import org.eclipse.che.api.devfile.server.exception.WorkspaceExportException; +import org.eclipse.che.api.workspace.server.devfile.Constants; +import org.eclipse.che.api.workspace.server.devfile.FileContentProvider; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException; +import org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException; import org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl; diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/DefaultEditorProvisioner.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/DefaultEditorProvisioner.java similarity index 90% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/DefaultEditorProvisioner.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/DefaultEditorProvisioner.java index 3c21aa6c44..b2e09b5eca 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/DefaultEditorProvisioner.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/DefaultEditorProvisioner.java @@ -9,11 +9,11 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert; +package org.eclipse.che.api.workspace.server.devfile.convert; -import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.EDITOR_FREE_DEVFILE_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.PLUGIN_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_FREE_DEVFILE_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.PLUGIN_COMPONENT_TYPE; import com.google.common.base.Strings; import java.util.HashMap; @@ -23,7 +23,7 @@ import java.util.Optional; import javax.inject.Inject; import javax.inject.Named; import org.eclipse.che.api.core.model.workspace.devfile.Component; -import org.eclipse.che.api.devfile.server.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; import org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl; import org.eclipse.che.api.workspace.server.spi.InfrastructureException; diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/DevfileConverter.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/DevfileConverter.java similarity index 86% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/DevfileConverter.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/DevfileConverter.java index beb5ccae7e..e523610431 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/DevfileConverter.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/DevfileConverter.java @@ -9,13 +9,13 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert; +package org.eclipse.che.api.workspace.server.devfile.convert; import static com.google.common.base.Preconditions.checkArgument; import static java.lang.String.format; import static java.util.stream.Collectors.toCollection; -import static org.eclipse.che.api.devfile.server.Components.getIdentifiableComponentName; -import static org.eclipse.che.api.devfile.server.Constants.CURRENT_SPEC_VERSION; +import static org.eclipse.che.api.workspace.server.devfile.Components.getIdentifiableComponentName; +import static org.eclipse.che.api.workspace.server.devfile.Constants.CURRENT_SPEC_VERSION; import com.google.common.base.Strings; import java.util.ArrayList; @@ -27,16 +27,15 @@ import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; import org.eclipse.che.api.core.model.workspace.devfile.Command; import org.eclipse.che.api.core.model.workspace.devfile.Component; import org.eclipse.che.api.core.model.workspace.devfile.Devfile; -import org.eclipse.che.api.devfile.server.DevfileRecipeFormatException; -import org.eclipse.che.api.devfile.server.FileContentProvider; -import org.eclipse.che.api.devfile.server.URLFetcher; -import org.eclipse.che.api.devfile.server.URLFileContentProvider; -import org.eclipse.che.api.devfile.server.convert.component.ComponentProvisioner; -import org.eclipse.che.api.devfile.server.convert.component.ComponentToWorkspaceApplier; -import org.eclipse.che.api.devfile.server.exception.DevfileException; -import org.eclipse.che.api.devfile.server.exception.DevfileFormatException; -import org.eclipse.che.api.devfile.server.exception.WorkspaceExportException; -import org.eclipse.che.api.workspace.server.DevfileToWorkspaceConfigConverter; +import org.eclipse.che.api.workspace.server.devfile.DevfileRecipeFormatException; +import org.eclipse.che.api.workspace.server.devfile.FileContentProvider; +import org.eclipse.che.api.workspace.server.devfile.URLFetcher; +import org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider; +import org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentProvisioner; +import org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException; +import org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException; import org.eclipse.che.api.workspace.server.model.impl.CommandImpl; import org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; @@ -49,7 +48,7 @@ import org.eclipse.che.api.workspace.server.model.impl.devfile.ProjectImpl; * @author Max Shaposhnyk * @author Sergii Leshchenko */ -public class DevfileConverter implements DevfileToWorkspaceConfigConverter { +public class DevfileConverter { private final ProjectConverter projectConverter; private final CommandConverter commandConverter; @@ -113,7 +112,6 @@ public class DevfileConverter implements DevfileToWorkspaceConfigConverter { return devfile; } - @Override public WorkspaceConfig convert(Devfile devfile) throws ServerException { try { return devFileToWorkspaceConfig(new DevfileImpl(devfile), urlFileContentProvider); diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/ProjectConverter.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/ProjectConverter.java similarity index 97% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/ProjectConverter.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/ProjectConverter.java index d1f5c29f52..476bea814e 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/ProjectConverter.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/ProjectConverter.java @@ -9,7 +9,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert; +package org.eclipse.che.api.workspace.server.devfile.convert; import static java.lang.String.format; import static org.eclipse.che.api.core.model.workspace.config.SourceStorage.BRANCH_PARAMETER_NAME; @@ -21,7 +21,7 @@ import java.net.URI; import java.net.URISyntaxException; import org.eclipse.che.api.core.model.workspace.devfile.Project; import org.eclipse.che.api.core.model.workspace.devfile.Source; -import org.eclipse.che.api.devfile.server.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; import org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.ProjectImpl; diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/ComponentProvisioner.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/component/ComponentProvisioner.java similarity index 89% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/ComponentProvisioner.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/component/ComponentProvisioner.java index fb11341a53..ed186dcf6d 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/ComponentProvisioner.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/component/ComponentProvisioner.java @@ -9,9 +9,9 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component; +package org.eclipse.che.api.workspace.server.devfile.convert.component; -import org.eclipse.che.api.devfile.server.exception.WorkspaceExportException; +import org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl; diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/ComponentToWorkspaceApplier.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/component/ComponentToWorkspaceApplier.java similarity index 87% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/ComponentToWorkspaceApplier.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/component/ComponentToWorkspaceApplier.java index 1f6a6dac9c..b7f5956909 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/ComponentToWorkspaceApplier.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/component/ComponentToWorkspaceApplier.java @@ -9,11 +9,11 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component; +package org.eclipse.che.api.workspace.server.devfile.convert.component; import org.eclipse.che.api.core.model.workspace.devfile.Component; -import org.eclipse.che.api.devfile.server.FileContentProvider; -import org.eclipse.che.api.devfile.server.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.FileContentProvider; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; /** diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentProvisioner.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/component/editor/EditorComponentProvisioner.java similarity index 86% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentProvisioner.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/component/editor/EditorComponentProvisioner.java index beab49a081..4aba8664b3 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentProvisioner.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/component/editor/EditorComponentProvisioner.java @@ -9,17 +9,17 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.editor; +package org.eclipse.che.api.workspace.server.devfile.convert.component.editor; import static java.lang.String.format; -import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_ALIAS_WORKSPACE_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_ALIAS_WORKSPACE_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE; import static org.eclipse.che.api.workspace.shared.Constants.SIDECAR_MEMORY_LIMIT_ATTR_TEMPLATE; import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_EDITOR_ATTRIBUTE; import javax.inject.Inject; -import org.eclipse.che.api.devfile.server.convert.component.ComponentProvisioner; -import org.eclipse.che.api.devfile.server.exception.WorkspaceExportException; +import org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentProvisioner; +import org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl; diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentToWorkspaceApplier.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/component/editor/EditorComponentToWorkspaceApplier.java similarity index 85% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentToWorkspaceApplier.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/component/editor/EditorComponentToWorkspaceApplier.java index 80b1df48a8..82446a9c7f 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentToWorkspaceApplier.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/component/editor/EditorComponentToWorkspaceApplier.java @@ -9,22 +9,22 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.editor; +package org.eclipse.che.api.workspace.server.devfile.convert.component.editor; import static com.google.common.base.Preconditions.checkArgument; import static java.lang.String.format; import static org.eclipse.che.api.core.model.workspace.config.Command.PLUGIN_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_ALIAS_WORKSPACE_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_ALIAS_WORKSPACE_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE; import static org.eclipse.che.api.workspace.shared.Constants.SIDECAR_MEMORY_LIMIT_ATTR_TEMPLATE; import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_EDITOR_ATTRIBUTE; import javax.inject.Inject; import org.eclipse.che.api.core.model.workspace.devfile.Component; -import org.eclipse.che.api.devfile.server.FileContentProvider; -import org.eclipse.che.api.devfile.server.convert.component.ComponentToWorkspaceApplier; -import org.eclipse.che.api.devfile.server.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.FileContentProvider; +import org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.api.workspace.server.spi.InfrastructureException; import org.eclipse.che.api.workspace.server.wsplugins.PluginFQNParser; diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginComponentToWorkspaceApplier.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/component/plugin/PluginComponentToWorkspaceApplier.java similarity index 88% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginComponentToWorkspaceApplier.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/component/plugin/PluginComponentToWorkspaceApplier.java index 9bb0e6317d..c317e75b9f 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginComponentToWorkspaceApplier.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/component/plugin/PluginComponentToWorkspaceApplier.java @@ -9,15 +9,15 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.plugin; +package org.eclipse.che.api.workspace.server.devfile.convert.component.plugin; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Strings.isNullOrEmpty; import static java.lang.String.format; import static org.eclipse.che.api.core.model.workspace.config.Command.PLUGIN_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.PLUGINS_COMPONENTS_ALIASES_WORKSPACE_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.PLUGIN_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.PLUGINS_COMPONENTS_ALIASES_WORKSPACE_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.PLUGIN_COMPONENT_TYPE; import static org.eclipse.che.api.workspace.shared.Constants.PLUGIN_PREFERENCE_ATTR_TEMPLATE; import static org.eclipse.che.api.workspace.shared.Constants.SIDECAR_MEMORY_LIMIT_ATTR_TEMPLATE; import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE; @@ -25,9 +25,9 @@ import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_P import java.util.Map.Entry; import javax.inject.Inject; import org.eclipse.che.api.core.model.workspace.devfile.Component; -import org.eclipse.che.api.devfile.server.FileContentProvider; -import org.eclipse.che.api.devfile.server.convert.component.ComponentToWorkspaceApplier; -import org.eclipse.che.api.devfile.server.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.FileContentProvider; +import org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; import org.eclipse.che.api.workspace.server.model.impl.CommandImpl; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.api.workspace.server.spi.InfrastructureException; diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginProvisioner.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/component/plugin/PluginProvisioner.java similarity index 89% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginProvisioner.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/component/plugin/PluginProvisioner.java index cd3aa53711..96ffad6b23 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginProvisioner.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/convert/component/plugin/PluginProvisioner.java @@ -9,14 +9,14 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.plugin; +package org.eclipse.che.api.workspace.server.devfile.convert.component.plugin; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Strings.isNullOrEmpty; import static java.lang.String.format; import static java.util.stream.Collectors.toMap; -import static org.eclipse.che.api.devfile.server.Constants.PLUGINS_COMPONENTS_ALIASES_WORKSPACE_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.PLUGIN_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.PLUGINS_COMPONENTS_ALIASES_WORKSPACE_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.PLUGIN_COMPONENT_TYPE; import static org.eclipse.che.api.workspace.shared.Constants.SIDECAR_MEMORY_LIMIT_ATTR_TEMPLATE; import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE; @@ -24,8 +24,8 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; import javax.inject.Inject; -import org.eclipse.che.api.devfile.server.convert.component.ComponentProvisioner; -import org.eclipse.che.api.devfile.server.exception.WorkspaceExportException; +import org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentProvisioner; +import org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl; diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/exception/DevfileException.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/exception/DevfileException.java similarity index 90% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/exception/DevfileException.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/exception/DevfileException.java index a7f66c127f..e8871d366f 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/exception/DevfileException.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/exception/DevfileException.java @@ -9,7 +9,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.exception; +package org.eclipse.che.api.workspace.server.devfile.exception; /** Describes general devfile exception. */ public class DevfileException extends Exception { diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/exception/DevfileFormatException.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/exception/DevfileFormatException.java similarity index 91% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/exception/DevfileFormatException.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/exception/DevfileFormatException.java index c2cc72929c..ce8c631c98 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/exception/DevfileFormatException.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/exception/DevfileFormatException.java @@ -9,7 +9,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.exception; +package org.eclipse.che.api.workspace.server.devfile.exception; /** Thrown when devfile schema or integrity validation is failed. */ public class DevfileFormatException extends DevfileException { diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/exception/WorkspaceExportException.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/exception/WorkspaceExportException.java similarity index 91% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/exception/WorkspaceExportException.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/exception/WorkspaceExportException.java index 2c5c8383d8..f20435647a 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/exception/WorkspaceExportException.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/exception/WorkspaceExportException.java @@ -9,7 +9,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.exception; +package org.eclipse.che.api.workspace.server.devfile.exception; /** Thrown when workspace can not be exported into devfile by some reason. */ public class WorkspaceExportException extends Exception { diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/schema/DevfileSchemaProvider.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/schema/DevfileSchemaProvider.java similarity index 89% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/schema/DevfileSchemaProvider.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/schema/DevfileSchemaProvider.java index 81f038f859..04b55ec118 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/schema/DevfileSchemaProvider.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/schema/DevfileSchemaProvider.java @@ -9,9 +9,9 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.schema; +package org.eclipse.che.api.workspace.server.devfile.schema; -import static org.eclipse.che.api.devfile.server.Constants.SCHEMA_LOCATION; +import static org.eclipse.che.api.workspace.server.devfile.Constants.SCHEMA_LOCATION; import static org.eclipse.che.commons.lang.IoUtil.getResource; import static org.eclipse.che.commons.lang.IoUtil.readAndCloseQuietly; diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/validator/ComponentIntegrityValidator.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/validator/ComponentIntegrityValidator.java new file mode 100644 index 0000000000..4a202f94ae --- /dev/null +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/validator/ComponentIntegrityValidator.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2012-2018 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.api.workspace.server.devfile.validator; + +import org.eclipse.che.api.core.model.workspace.devfile.Component; +import org.eclipse.che.api.workspace.server.devfile.FileContentProvider; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException; + +/** + * There are several types of components that are handled in an infrastructure-specific way. This + * interface provides the devfile validator with component-specific validators. + */ +public interface ComponentIntegrityValidator { + + /** + * Validates the component. The component is guaranteed to be of the type that can be handled by + * this validator. + * + * @param component the devfile component to validate + * @param contentProvider content provider that can be used to resolve references + */ + void validateComponent(Component component, FileContentProvider contentProvider) + throws DevfileFormatException; + + final class NoopComponentIntegrityValidator implements ComponentIntegrityValidator { + + @Override + public void validateComponent(Component component, FileContentProvider contentProvider) {} + } +} diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/validator/DevfileIntegrityValidator.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/validator/DevfileIntegrityValidator.java similarity index 56% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/validator/DevfileIntegrityValidator.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/validator/DevfileIntegrityValidator.java index ebac323363..886c8a0956 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/validator/DevfileIntegrityValidator.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/validator/DevfileIntegrityValidator.java @@ -9,43 +9,30 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.validator; +package org.eclipse.che.api.workspace.server.devfile.validator; import static java.lang.String.format; -import static org.eclipse.che.api.devfile.server.Components.getIdentifiableComponentName; -import static org.eclipse.che.api.devfile.server.Constants.DOCKERIMAGE_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.KUBERNETES_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.OPENSHIFT_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.PLUGIN_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Components.getIdentifiableComponentName; +import static org.eclipse.che.api.workspace.server.devfile.Constants.DOCKERIMAGE_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.OPENSHIFT_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.PLUGIN_COMPONENT_TYPE; -import io.fabric8.kubernetes.api.model.Container; -import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.kubernetes.client.utils.Serialization; -import java.io.IOException; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.regex.Pattern; import javax.inject.Inject; import javax.inject.Singleton; -import org.eclipse.che.api.core.ValidationException; import org.eclipse.che.api.core.model.workspace.devfile.Action; import org.eclipse.che.api.core.model.workspace.devfile.Command; import org.eclipse.che.api.core.model.workspace.devfile.Component; import org.eclipse.che.api.core.model.workspace.devfile.Devfile; -import org.eclipse.che.api.core.model.workspace.devfile.Entrypoint; import org.eclipse.che.api.core.model.workspace.devfile.Project; -import org.eclipse.che.api.devfile.server.FileContentProvider; -import org.eclipse.che.api.devfile.server.convert.component.kubernetes.ContainerSearch; -import org.eclipse.che.api.devfile.server.convert.component.kubernetes.SelectorFilter; -import org.eclipse.che.api.devfile.server.exception.DevfileException; -import org.eclipse.che.api.devfile.server.exception.DevfileFormatException; -import org.eclipse.che.api.workspace.server.spi.InfrastructureException; -import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesRecipeParser; +import org.eclipse.che.api.workspace.server.devfile.FileContentProvider; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException; /** Validates devfile logical integrity. */ @Singleton @@ -57,11 +44,11 @@ public class DevfileIntegrityValidator { */ private static final Pattern PROJECT_NAME_PATTERN = Pattern.compile("^[\\w\\d]+[\\w\\d_.-]*$"); - private final KubernetesRecipeParser kubernetesRecipeParser; + private final Map validators; @Inject - public DevfileIntegrityValidator(KubernetesRecipeParser kubernetesRecipeParser) { - this.kubernetesRecipeParser = kubernetesRecipeParser; + public DevfileIntegrityValidator(Map validators) { + this.validators = validators; } /** @@ -102,16 +89,12 @@ public class DevfileIntegrityValidator { public void validateContentReferences(Devfile devfile, FileContentProvider provider) throws DevfileFormatException { for (Component component : devfile.getComponents()) { - try { - List selectedObjects = validateSelector(component, provider); - validateEntrypointSelector(component, selectedObjects); - } catch (Exception e) { - throw new DevfileFormatException( - format( - "Failed to validate content reference of component '%s' of type '%s': %s", - getIdentifiableComponentName(component), component.getType(), e.getMessage()), - e); + ComponentIntegrityValidator validator = validators.get(component.getType()); + if (validator == null) { + throw new DevfileFormatException(format("Unknown component type: %s", component.getType())); } + + validator.validateComponent(component, provider); } } @@ -223,92 +206,4 @@ public class DevfileIntegrityValidator { } } } - - /** - * Validates that the selector, if any, selects some objects from the component's referenced - * content. Only does anything for kubernetes and openshift components. - * - * @param component the component to check - * @param contentProvider the content provider to use when fetching content - * @return the list of referenced objects matching the selector or empty list - * @throws ValidationException on failure to validate the referenced content - * @throws InfrastructureException on failure to parse the referenced content - * @throws IOException on failure to retrieve the referenced content - * @throws DevfileException if the selector filters out all referenced objects - */ - private List validateSelector( - Component component, FileContentProvider contentProvider) - throws ValidationException, InfrastructureException, IOException, DevfileException { - - if (!component.getType().equals(KUBERNETES_COMPONENT_TYPE) - && !component.getType().equals(OPENSHIFT_COMPONENT_TYPE)) { - return Collections.emptyList(); - } - - List content = getReferencedKubernetesList(component, contentProvider); - - Map selector = component.getSelector(); - if (selector == null || selector.isEmpty()) { - return content; - } - - content = SelectorFilter.filter(content, selector); - - if (content.isEmpty()) { - throw new DevfileException( - format( - "The selector of the component '%s' of type '%s' filters out all objects from" - + " the list.", - getIdentifiableComponentName(component), component.getType())); - } - - return content; - } - - private void validateEntrypointSelector(Component component, List filteredObjects) - throws DevfileException { - - if (component.getEntrypoints() == null || component.getEntrypoints().isEmpty()) { - return; - } - - for (Entrypoint ep : component.getEntrypoints()) { - ContainerSearch search = - new ContainerSearch(ep.getParentName(), ep.getParentSelector(), ep.getContainerName()); - - List cs = search.search(filteredObjects); - - if (cs.isEmpty()) { - throw new DevfileFormatException( - format( - "Component '%s' of type '%s' contains an entry point that doesn't match any" - + " container:\n%s", - getIdentifiableComponentName(component), component.getType(), toYAML(ep))); - } - } - } - - private List getReferencedKubernetesList( - Component component, FileContentProvider contentProvider) - throws ValidationException, InfrastructureException, IOException, DevfileException { - List content; - if (component.getReferenceContent() != null) { - content = kubernetesRecipeParser.parse(component.getReferenceContent()); - } else if (component.getReference() != null) { - String data = contentProvider.fetchContent(component.getReference()); - content = kubernetesRecipeParser.parse(data); - } else { - content = Collections.emptyList(); - } - - return content; - } - - private String toYAML(Entrypoint ep) throws DevfileException { - try { - return Serialization.asYaml(ep); - } catch (Exception e) { - throw new DevfileException(e.getMessage(), e); - } - } } diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/validator/DevfileSchemaValidator.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/validator/DevfileSchemaValidator.java similarity index 91% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/validator/DevfileSchemaValidator.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/validator/DevfileSchemaValidator.java index 9e3e26737e..eb8ab9b920 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/validator/DevfileSchemaValidator.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/validator/DevfileSchemaValidator.java @@ -9,7 +9,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.validator; +package org.eclipse.che.api.workspace.server.devfile.validator; import static java.lang.String.format; @@ -23,8 +23,8 @@ import java.util.List; import javax.inject.Inject; import javax.inject.Singleton; import javax.json.JsonReader; -import org.eclipse.che.api.devfile.server.exception.DevfileFormatException; -import org.eclipse.che.api.devfile.server.schema.DevfileSchemaProvider; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException; +import org.eclipse.che.api.workspace.server.devfile.schema.DevfileSchemaProvider; import org.leadpony.justify.api.JsonSchema; import org.leadpony.justify.api.JsonValidationService; import org.leadpony.justify.api.Problem; diff --git a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/validator/ErrorMessageComposer.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/validator/ErrorMessageComposer.java similarity index 96% rename from wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/validator/ErrorMessageComposer.java rename to wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/validator/ErrorMessageComposer.java index 992afe6876..1b95e37f24 100644 --- a/wsmaster/che-core-api-devfile/src/main/java/org/eclipse/che/api/devfile/server/validator/ErrorMessageComposer.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/devfile/validator/ErrorMessageComposer.java @@ -9,7 +9,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.validator; +package org.eclipse.che.api.workspace.server.devfile.validator; import static com.google.common.base.Strings.isNullOrEmpty; diff --git a/wsmaster/che-core-api-devfile/src/main/resources/Dockerfile b/wsmaster/che-core-api-workspace/src/main/resources/Dockerfile similarity index 100% rename from wsmaster/che-core-api-devfile/src/main/resources/Dockerfile rename to wsmaster/che-core-api-workspace/src/main/resources/Dockerfile diff --git a/wsmaster/che-core-api-devfile/src/main/resources/build_docs.sh b/wsmaster/che-core-api-workspace/src/main/resources/build_docs.sh similarity index 99% rename from wsmaster/che-core-api-devfile/src/main/resources/build_docs.sh rename to wsmaster/che-core-api-workspace/src/main/resources/build_docs.sh index 9081ff449f..a04390c1b4 100755 --- a/wsmaster/che-core-api-devfile/src/main/resources/build_docs.sh +++ b/wsmaster/che-core-api-workspace/src/main/resources/build_docs.sh @@ -32,7 +32,7 @@ build() { build_native fi cd $RUN_DIR - cp ../../../README.md ${TMP_DIR}/docs/index.md + cp ../../../README-devfile.md ${TMP_DIR}/docs/index.md } build_with_docker() { diff --git a/wsmaster/che-core-api-devfile/src/main/resources/schema/devfile.json b/wsmaster/che-core-api-workspace/src/main/resources/schema/devfile.json similarity index 100% rename from wsmaster/che-core-api-devfile/src/main/resources/schema/devfile.json rename to wsmaster/che-core-api-workspace/src/main/resources/schema/devfile.json diff --git a/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceManagerTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceManagerTest.java index 91c2a99000..00a9a976d5 100644 --- a/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceManagerTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceManagerTest.java @@ -72,6 +72,7 @@ import org.eclipse.che.api.core.model.workspace.devfile.Devfile; import org.eclipse.che.api.core.model.workspace.runtime.Machine; import org.eclipse.che.api.core.model.workspace.runtime.MachineStatus; import org.eclipse.che.api.core.notification.EventService; +import org.eclipse.che.api.workspace.server.devfile.convert.DevfileConverter; import org.eclipse.che.api.workspace.server.model.impl.CommandImpl; import org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl; import org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl; @@ -118,7 +119,7 @@ public class WorkspaceManagerTest { @Mock private AccountManager accountManager; @Mock private EventService eventService; @Mock private WorkspaceValidator validator; - @Mock private DevfileToWorkspaceConfigConverter devfileConverter; + @Mock private DevfileConverter devfileConverter; @Captor private ArgumentCaptor workspaceCaptor; @@ -127,8 +128,7 @@ public class WorkspaceManagerTest { @BeforeMethod public void setUp() throws Exception { workspaceManager = - new WorkspaceManager( - workspaceDao, runtimes, eventService, accountManager, validator, devfileConverter); + new WorkspaceManager(workspaceDao, runtimes, eventService, accountManager, validator); lenient() .when(accountManager.getByName(NAMESPACE_1)) .thenReturn(new AccountImpl("accountId", NAMESPACE_1, "test")); diff --git a/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimesTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimesTest.java index 21f170a782..d2f02fe545 100644 --- a/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimesTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimesTest.java @@ -58,6 +58,7 @@ import org.eclipse.che.api.core.model.workspace.runtime.Machine; import org.eclipse.che.api.core.model.workspace.runtime.MachineStatus; import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity; import org.eclipse.che.api.core.notification.EventService; +import org.eclipse.che.api.workspace.server.devfile.convert.DevfileConverter; import org.eclipse.che.api.workspace.server.event.RuntimeAbnormalStoppedEvent; import org.eclipse.che.api.workspace.server.event.RuntimeAbnormalStoppingEvent; import org.eclipse.che.api.workspace.server.hc.probe.ProbeScheduler; @@ -109,7 +110,7 @@ public class WorkspaceRuntimesTest { @Mock private WorkspaceStatusCache statuses; - @Mock private DevfileToWorkspaceConfigConverter devfileConverter; + @Mock private DevfileConverter devfileConverter; private RuntimeInfrastructure infrastructure; diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/DevfileManagerTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/DevfileManagerTest.java similarity index 92% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/DevfileManagerTest.java rename to wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/DevfileManagerTest.java index 7296b193fe..1a499efd0e 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/DevfileManagerTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/DevfileManagerTest.java @@ -9,7 +9,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server; +package org.eclipse.che.api.workspace.server.devfile; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyMap; @@ -30,13 +30,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import org.eclipse.che.account.spi.AccountImpl; import org.eclipse.che.api.core.NotFoundException; -import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; import org.eclipse.che.api.core.model.workspace.WorkspaceStatus; -import org.eclipse.che.api.devfile.server.convert.DevfileConverter; -import org.eclipse.che.api.devfile.server.exception.DevfileFormatException; -import org.eclipse.che.api.devfile.server.validator.DevfileIntegrityValidator; -import org.eclipse.che.api.devfile.server.validator.DevfileSchemaValidator; import org.eclipse.che.api.workspace.server.WorkspaceManager; +import org.eclipse.che.api.workspace.server.devfile.convert.DevfileConverter; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException; +import org.eclipse.che.api.workspace.server.devfile.validator.DevfileIntegrityValidator; +import org.eclipse.che.api.workspace.server.devfile.validator.DevfileSchemaValidator; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl; @@ -148,8 +147,6 @@ public class DevfileManagerTest { current.setSubject(TEST_SUBJECT); EnvironmentContext.setCurrent(current); - when(workspaceManager.createWorkspace(any(WorkspaceConfig.class), anyString(), anyMap())) - .thenReturn(createWorkspace(WorkspaceStatus.STOPPED)); when(workspaceManager.getWorkspace(anyString(), anyString())) .thenAnswer( invocation -> { @@ -160,6 +157,7 @@ public class DevfileManagerTest { } throw new NotFoundException("ws not found"); }); + WorkspaceConfigImpl wsConfig = mock(WorkspaceConfigImpl.class); when(wsConfig.getName()).thenReturn("petclinic-dev-environment"); doReturn(new WorkspaceConfigImpl(wsConfig)) diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/DevfileServiceTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/DevfileServiceTest.java similarity index 95% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/DevfileServiceTest.java rename to wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/DevfileServiceTest.java index 69aa0720d6..001a83669e 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/DevfileServiceTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/DevfileServiceTest.java @@ -9,7 +9,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server; +package org.eclipse.che.api.workspace.server.devfile; import static com.jayway.restassured.RestAssured.given; import static org.everrest.assured.JettyHttpServer.ADMIN_USER_NAME; @@ -30,8 +30,8 @@ import com.jayway.restassured.response.Response; import java.io.IOException; import org.eclipse.che.account.spi.AccountImpl; import org.eclipse.che.api.core.model.workspace.WorkspaceStatus; -import org.eclipse.che.api.devfile.server.schema.DevfileSchemaProvider; import org.eclipse.che.api.workspace.server.WorkspaceLinksGenerator; +import org.eclipse.che.api.workspace.server.devfile.schema.DevfileSchemaProvider; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl; @@ -86,7 +86,7 @@ public class DevfileServiceTest { public void shouldAcceptDevFileContentAndCreateWorkspace() throws Exception { ArgumentCaptor captor = ArgumentCaptor.forClass(DevfileImpl.class); String yamlContent = - Files.readFile(getClass().getClassLoader().getResourceAsStream("devfile.yaml")); + Files.readFile(getClass().getClassLoader().getResourceAsStream("devfile/devfile.yaml")); DevfileImpl devfile = createDevfile(yamlContent); WorkspaceImpl ws = createWorkspace(WorkspaceStatus.STOPPED); when(devfileManager.parse(anyString())).thenReturn(devfile); @@ -139,7 +139,8 @@ public class DevfileServiceTest { private WorkspaceConfigImpl createConfig() throws IOException, JsonParseException { String jsonContent = - Files.readFile(getClass().getClassLoader().getResourceAsStream("workspace_config.json")); + Files.readFile( + getClass().getClassLoader().getResourceAsStream("devfile/workspace_config.json")); return JsonHelper.fromJson(jsonContent, WorkspaceConfigImpl.class, null); } } diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/URLFetcherTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/URLFetcherTest.java similarity index 88% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/URLFetcherTest.java rename to wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/URLFetcherTest.java index 5d3a44bed6..c234649d31 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/URLFetcherTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/URLFetcherTest.java @@ -9,10 +9,10 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server; +package org.eclipse.che.api.workspace.server.devfile; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.eclipse.che.api.devfile.server.URLFetcher.MAXIMUM_READ_BYTES; +import static org.eclipse.che.api.workspace.server.devfile.URLFetcher.MAXIMUM_READ_BYTES; import static org.mockito.Mockito.when; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; @@ -30,7 +30,7 @@ import org.testng.annotations.Listeners; import org.testng.annotations.Test; /** - * Testing {@link org.eclipse.che.api.devfile.server.URLFetcher} + * Testing {@link org.eclipse.che.api.workspace.server.devfile.URLFetcher} * * @author Florent Benoit */ @@ -51,7 +51,7 @@ public class URLFetcherTest { public void checkGetContent() { // test to download this class object - URL urlJson = getClass().getClassLoader().getResource(".che.json"); + URL urlJson = getClass().getClassLoader().getResource("devfile/.che.json"); Assert.assertNotNull(urlJson); String content = URLFetcher.fetchSafely(urlJson.toString()); @@ -89,7 +89,7 @@ public class URLFetcherTest { public void checkMissingContent() { // test to download this class object - URL urlJson = getClass().getClassLoader().getResource(".che.json"); + URL urlJson = getClass().getClassLoader().getResource("devfile/.che.json"); Assert.assertNotNull(urlJson); // add extra path to make url not found @@ -104,7 +104,7 @@ public class URLFetcherTest { public void checkMissingContentUnsafeGet() throws Exception { // test to download this class object - URL urlJson = getClass().getClassLoader().getResource(".che.json"); + URL urlJson = getClass().getClassLoader().getResource("devfile/.che.json"); Assert.assertNotNull(urlJson); // add extra path to make url not found @@ -115,7 +115,7 @@ public class URLFetcherTest { /** Check when we reach custom limit */ @Test public void checkPartialContent() { - URL urlJson = getClass().getClassLoader().getResource(".che.json"); + URL urlJson = getClass().getClassLoader().getResource("devfile/.che.json"); Assert.assertNotNull(urlJson); String content = new OneByteURLFetcher().fetchSafely(urlJson.toString()); diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/URLFileContentProviderTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/URLFileContentProviderTest.java similarity index 94% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/URLFileContentProviderTest.java rename to wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/URLFileContentProviderTest.java index 7119e8a248..0c279f0d46 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/URLFileContentProviderTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/URLFileContentProviderTest.java @@ -9,13 +9,13 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server; +package org.eclipse.che.api.workspace.server.devfile; import static org.mockito.Mockito.verify; import static org.testng.Assert.assertEquals; import java.net.URI; -import org.eclipse.che.api.devfile.server.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.testng.MockitoTestNGListener; diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/CommandConverterTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/CommandConverterTest.java similarity index 94% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/CommandConverterTest.java rename to wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/CommandConverterTest.java index b5928f4c8a..96716f7c12 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/CommandConverterTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/CommandConverterTest.java @@ -9,11 +9,11 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert; +package org.eclipse.che.api.workspace.server.devfile.convert; import static org.eclipse.che.api.core.model.workspace.config.Command.WORKING_DIRECTORY_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.EXEC_ACTION_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.EXEC_ACTION_TYPE; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNull; @@ -21,8 +21,8 @@ import static org.testng.Assert.assertNull; import com.google.common.collect.ImmutableMap; import java.util.HashMap; import org.eclipse.che.api.core.model.workspace.config.Command; -import org.eclipse.che.api.devfile.server.exception.DevfileFormatException; -import org.eclipse.che.api.devfile.server.exception.WorkspaceExportException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException; +import org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException; import org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl; import org.testng.annotations.BeforeMethod; diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/DefaultEditorProvisionerTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/DefaultEditorProvisionerTest.java similarity index 96% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/DefaultEditorProvisionerTest.java rename to wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/DefaultEditorProvisionerTest.java index c2d21e270f..196ff71c66 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/DefaultEditorProvisionerTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/DefaultEditorProvisionerTest.java @@ -9,18 +9,18 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert; +package org.eclipse.che.api.workspace.server.devfile.convert; -import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.EDITOR_FREE_DEVFILE_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.PLUGIN_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_FREE_DEVFILE_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.PLUGIN_COMPONENT_TYPE; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; import java.util.List; -import org.eclipse.che.api.devfile.server.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; import org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl; import org.eclipse.che.api.workspace.server.wsplugins.PluginFQNParser; diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/DevfileConverterTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/DevfileConverterTest.java similarity index 94% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/DevfileConverterTest.java rename to wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/DevfileConverterTest.java index c189983fd0..9c89c68eb7 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/DevfileConverterTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/DevfileConverterTest.java @@ -9,9 +9,9 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert; +package org.eclipse.che.api.workspace.server.devfile.convert; -import static org.eclipse.che.api.devfile.server.Constants.CURRENT_SPEC_VERSION; +import static org.eclipse.che.api.workspace.server.devfile.Constants.CURRENT_SPEC_VERSION; import static org.eclipse.che.api.workspace.shared.Constants.PERSIST_VOLUMES_ATTRIBUTE; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; @@ -29,13 +29,13 @@ import java.util.HashMap; import java.util.Map; import org.eclipse.che.api.core.ServerException; import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; -import org.eclipse.che.api.devfile.server.FileContentProvider; -import org.eclipse.che.api.devfile.server.URLFetcher; -import org.eclipse.che.api.devfile.server.convert.component.ComponentProvisioner; -import org.eclipse.che.api.devfile.server.convert.component.ComponentToWorkspaceApplier; -import org.eclipse.che.api.devfile.server.exception.DevfileException; -import org.eclipse.che.api.devfile.server.exception.DevfileFormatException; -import org.eclipse.che.api.devfile.server.exception.WorkspaceExportException; +import org.eclipse.che.api.workspace.server.devfile.FileContentProvider; +import org.eclipse.che.api.workspace.server.devfile.URLFetcher; +import org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentProvisioner; +import org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException; +import org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException; import org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl; import org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/ProjectConverterTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/ProjectConverterTest.java similarity index 98% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/ProjectConverterTest.java rename to wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/ProjectConverterTest.java index 76ee358773..5c130fa515 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/ProjectConverterTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/ProjectConverterTest.java @@ -9,7 +9,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert; +package org.eclipse.che.api.workspace.server.devfile.convert; import static org.eclipse.che.api.core.model.workspace.config.SourceStorage.BRANCH_PARAMETER_NAME; import static org.eclipse.che.api.core.model.workspace.config.SourceStorage.COMMIT_ID_PARAMETER_NAME; @@ -21,7 +21,7 @@ import static org.testng.AssertJUnit.assertFalse; import com.google.common.collect.ImmutableMap; import org.eclipse.che.api.core.model.workspace.devfile.Project; import org.eclipse.che.api.core.model.workspace.devfile.Source; -import org.eclipse.che.api.devfile.server.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; import org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.ProjectImpl; diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentProvisionerTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/component/editor/EditorComponentProvisionerTest.java similarity index 89% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentProvisionerTest.java rename to wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/component/editor/EditorComponentProvisionerTest.java index 7c211594a3..bc05629b99 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentProvisionerTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/component/editor/EditorComponentProvisionerTest.java @@ -9,16 +9,16 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.editor; +package org.eclipse.che.api.workspace.server.devfile.convert.component.editor; import static java.lang.String.format; -import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_ALIAS_WORKSPACE_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_ALIAS_WORKSPACE_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE; import static org.eclipse.che.api.workspace.shared.Constants.SIDECAR_MEMORY_LIMIT_ATTR_TEMPLATE; import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_EDITOR_ATTRIBUTE; import static org.testng.Assert.assertEquals; -import org.eclipse.che.api.devfile.server.exception.WorkspaceExportException; +import org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl; diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentToWorkspaceApplierTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/component/editor/EditorComponentToWorkspaceApplierTest.java similarity index 89% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentToWorkspaceApplierTest.java rename to wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/component/editor/EditorComponentToWorkspaceApplierTest.java index dcc2ac3c80..2c204390b6 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/editor/EditorComponentToWorkspaceApplierTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/component/editor/EditorComponentToWorkspaceApplierTest.java @@ -9,18 +9,18 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.editor; +package org.eclipse.che.api.workspace.server.devfile.convert.component.editor; import static java.lang.String.format; import static org.eclipse.che.api.core.model.workspace.config.Command.PLUGIN_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_ALIAS_WORKSPACE_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_ALIAS_WORKSPACE_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE; import static org.eclipse.che.api.workspace.shared.Constants.SIDECAR_MEMORY_LIMIT_ATTR_TEMPLATE; import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_EDITOR_ATTRIBUTE; import static org.testng.Assert.assertEquals; -import org.eclipse.che.api.devfile.server.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; import org.eclipse.che.api.workspace.server.model.impl.CommandImpl; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl; diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginComponentToWorkspaceApplierTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/component/plugin/PluginComponentToWorkspaceApplierTest.java similarity index 91% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginComponentToWorkspaceApplierTest.java rename to wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/component/plugin/PluginComponentToWorkspaceApplierTest.java index 5df8c4456c..f2a5141f22 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginComponentToWorkspaceApplierTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/component/plugin/PluginComponentToWorkspaceApplierTest.java @@ -9,20 +9,20 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.plugin; +package org.eclipse.che.api.workspace.server.devfile.convert.component.plugin; import static java.lang.String.format; import static org.eclipse.che.api.core.model.workspace.config.Command.PLUGIN_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.PLUGINS_COMPONENTS_ALIASES_WORKSPACE_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.PLUGIN_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.PLUGINS_COMPONENTS_ALIASES_WORKSPACE_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.PLUGIN_COMPONENT_TYPE; import static org.eclipse.che.api.workspace.shared.Constants.PLUGIN_PREFERENCE_ATTR_TEMPLATE; import static org.eclipse.che.api.workspace.shared.Constants.SIDECAR_MEMORY_LIMIT_ATTR_TEMPLATE; import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; -import org.eclipse.che.api.devfile.server.exception.DevfileException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException; import org.eclipse.che.api.workspace.server.model.impl.CommandImpl; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl; diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginProvisionerTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/component/plugin/PluginProvisionerTest.java similarity index 90% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginProvisionerTest.java rename to wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/component/plugin/PluginProvisionerTest.java index 6a7d2793da..e7104ff8c8 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/convert/component/plugin/PluginProvisionerTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/convert/component/plugin/PluginProvisionerTest.java @@ -9,17 +9,17 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.convert.component.plugin; +package org.eclipse.che.api.workspace.server.devfile.convert.component.plugin; import static java.lang.String.format; -import static org.eclipse.che.api.devfile.server.Constants.PLUGINS_COMPONENTS_ALIASES_WORKSPACE_ATTRIBUTE; -import static org.eclipse.che.api.devfile.server.Constants.PLUGIN_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.PLUGINS_COMPONENTS_ALIASES_WORKSPACE_ATTRIBUTE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.PLUGIN_COMPONENT_TYPE; import static org.eclipse.che.api.workspace.shared.Constants.SIDECAR_MEMORY_LIMIT_ATTR_TEMPLATE; import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; -import org.eclipse.che.api.devfile.server.exception.WorkspaceExportException; +import org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException; import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl; diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/validator/DevfileIntegrityValidatorTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/validator/DevfileIntegrityValidatorTest.java similarity index 77% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/validator/DevfileIntegrityValidatorTest.java rename to wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/validator/DevfileIntegrityValidatorTest.java index 684e8d5675..abb2b4ea02 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/validator/DevfileIntegrityValidatorTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/validator/DevfileIntegrityValidatorTest.java @@ -9,30 +9,25 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.validator; +package org.eclipse.che.api.workspace.server.devfile.validator; -import static org.eclipse.che.api.devfile.server.Constants.DOCKERIMAGE_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.KUBERNETES_COMPONENT_TYPE; -import static org.eclipse.che.api.devfile.server.Constants.OPENSHIFT_COMPONENT_TYPE; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; +import static org.eclipse.che.api.workspace.server.devfile.Constants.DOCKERIMAGE_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.OPENSHIFT_COMPONENT_TYPE; +import static org.eclipse.che.api.workspace.server.devfile.Constants.PLUGIN_COMPONENT_TYPE; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import io.fabric8.kubernetes.api.model.PodBuilder; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import org.eclipse.che.api.devfile.server.exception.DevfileFormatException; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException; import org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl; -import org.eclipse.che.api.workspace.server.model.impl.devfile.EntrypointImpl; import org.eclipse.che.api.workspace.server.model.impl.devfile.ProjectImpl; -import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesRecipeParser; import org.mockito.Mock; import org.mockito.testng.MockitoTestNGListener; import org.testng.annotations.BeforeClass; @@ -49,13 +44,19 @@ public class DevfileIntegrityValidatorTest { private DevfileIntegrityValidator integrityValidator; - @Mock private KubernetesRecipeParser kubernetesRecipeParser; + @Mock private ComponentIntegrityValidator dummyComponentValidator; @BeforeClass public void setUp() throws Exception { - integrityValidator = new DevfileIntegrityValidator(kubernetesRecipeParser); + Map componentValidators = new HashMap<>(); + componentValidators.put(KUBERNETES_COMPONENT_TYPE, dummyComponentValidator); + componentValidators.put(OPENSHIFT_COMPONENT_TYPE, dummyComponentValidator); + componentValidators.put(PLUGIN_COMPONENT_TYPE, dummyComponentValidator); + componentValidators.put(EDITOR_COMPONENT_TYPE, dummyComponentValidator); + + integrityValidator = new DevfileIntegrityValidator(componentValidators); String devFileYamlContent = - Files.readFile(getClass().getClassLoader().getResourceAsStream("devfile.yaml")); + Files.readFile(getClass().getClassLoader().getResourceAsStream("devfile/devfile.yaml")); initialDevfile = objectMapper.readValue(devFileYamlContent, DevfileImpl.class); } @@ -166,60 +167,6 @@ public class DevfileIntegrityValidatorTest { integrityValidator.validateDevfile(broken); } - @Test(expectedExceptions = DevfileFormatException.class) - public void shouldThrowExceptionOnSelectorFilteringOutEverything() throws Exception { - // given - when(kubernetesRecipeParser.parse(any(String.class))) - .thenReturn( - Collections.singletonList( - new PodBuilder() - .withNewMetadata() - .addToLabels("app", "test") - .endMetadata() - .build())); - - Map selector = new HashMap<>(); - selector.put("app", "a different value"); - - DevfileImpl devfile = new DevfileImpl(initialDevfile); - // this is the openshift component which is the only one sensitive to the selector in our - // example - // devfile - devfile.getComponents().get(3).setReferenceContent("content"); - devfile.getComponents().get(3).setSelector(selector); - - // when - integrityValidator.validateContentReferences(devfile, __ -> ""); - - // then exception is thrown - } - - @Test(expectedExceptions = DevfileFormatException.class) - public void shouldThrowExceptionOnEntrypointNotMatchingAnyContainer() throws Exception { - // given - when(kubernetesRecipeParser.parse(any(String.class))) - .thenReturn( - Collections.singletonList( - new PodBuilder() - .withNewSpec() - .addNewContainer() - .withName("container") - .endContainer() - .endSpec() - .build())); - - DevfileImpl devfile = new DevfileImpl(initialDevfile); - devfile.getComponents().get(0).setReferenceContent("content"); - EntrypointImpl entrypoint = new EntrypointImpl(); - entrypoint.setContainerName("not that container"); - devfile.getComponents().get(0).setEntrypoints(Collections.singletonList(entrypoint)); - - // when - integrityValidator.validateContentReferences(devfile, __ -> ""); - - // then exception is thrown - } - @Test public void shouldNotValidateContentReferencesOnNonKuberenetesComponents() throws Exception { // given diff --git a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/validator/DevfileSchemaValidatorTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/validator/DevfileSchemaValidatorTest.java similarity index 95% rename from wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/validator/DevfileSchemaValidatorTest.java rename to wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/validator/DevfileSchemaValidatorTest.java index d63a4376d4..055d85726e 100644 --- a/wsmaster/che-core-api-devfile/src/test/java/org/eclipse/che/api/devfile/server/validator/DevfileSchemaValidatorTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/devfile/validator/DevfileSchemaValidatorTest.java @@ -9,15 +9,15 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.che.api.devfile.server.validator; +package org.eclipse.che.api.workspace.server.devfile.validator; import static java.lang.String.format; import static org.testng.Assert.assertEquals; import static org.testng.Assert.fail; import java.io.IOException; -import org.eclipse.che.api.devfile.server.exception.DevfileFormatException; -import org.eclipse.che.api.devfile.server.schema.DevfileSchemaProvider; +import org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException; +import org.eclipse.che.api.workspace.server.devfile.schema.DevfileSchemaProvider; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -173,6 +173,7 @@ public class DevfileSchemaValidatorTest { } private String getResource(String name) throws IOException { - return Files.readFile(getClass().getClassLoader().getResourceAsStream("schema_test/" + name)); + return Files.readFile( + getClass().getClassLoader().getResourceAsStream("devfile/schema_test/" + name)); } } diff --git a/wsmaster/che-core-api-devfile/src/test/resources/.che.json b/wsmaster/che-core-api-workspace/src/test/resources/devfile/.che.json similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/.che.json rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/.che.json diff --git a/wsmaster/che-core-api-devfile/src/test/resources/devfile.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/devfile.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/devfile.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/devfile.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/logback-test.xml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/logback-test.xml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/logback-test.xml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/logback-test.xml diff --git a/wsmaster/che-core-api-workspace/src/test/resources/devfile/petclinic.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/petclinic.yaml new file mode 100644 index 0000000000..75adc7a33d --- /dev/null +++ b/wsmaster/che-core-api-workspace/src/test/resources/devfile/petclinic.yaml @@ -0,0 +1,112 @@ +# +# Copyright (c) 2012-2018 Red Hat, Inc. +# This program and the accompanying materials are made +# available under the terms of the Eclipse Public License 2.0 +# which is available at https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# Red Hat, Inc. - initial API and implementation +# + +--- +apiVersion: v1 +kind: List +items: +- apiVersion: v1 + kind: Pod + metadata: + name: petclinic + labels: + app.kubernetes.io/name: petclinic + app.kubernetes.io/component: webapp + app.kubernetes.io/part-of: petclinic + spec: + containers: + - name: server + image: mariolet/petclinic + ports: + - containerPort: 8080 + protocol: TCP + resources: + limits: + memory: 512Mi +- apiVersion: v1 + kind: Pod + metadata: + name: mysql + labels: + app.kubernetes.io/name: mysql + app.kubernetes.io/component: database + app.kubernetes.io/part-of: petclinic + spec: + containers: + - name: mysql + image: centos/mysql-57-centos7 + env: + - name: MYSQL_USER + value: petclinic + - name: MYSQL_PASSWORD + value: petclinic + - name: MYSQL_ROOT_PASSWORD + value: petclinic + - name: MYSQL_DATABASE + value: petclinic + ports: + - containerPort: 3306 + protocol: TCP + resources: + limits: + memory: 512Mi +- apiVersion: v1 + kind: Pod + metadata: + name: withoutLabels +- kind: Service + apiVersion: v1 + metadata: + name: mysql + labels: + app.kubernetes.io/name: mysql + app.kubernetes.io/component: database + app.kubernetes.io/part-of: petclinic + spec: + ports: + - name: mysql + port: 3306 + targetPort: 3360 + selector: + app.kubernetes.io/name: mysql + app.kubernetes.io/component: database + app.kubernetes.io/part-of: petclinic +- kind: Service + apiVersion: v1 + metadata: + name: petclinic + labels: + app.kubernetes.io/name: petclinic + app.kubernetes.io/component: webapp + app.kubernetes.io/part-of: petclinic + spec: + ports: + - name: web + port: 8080 + targetPort: 8080 + selector: + app: petclinic + component: webapp +- kind: Route + apiVersion: v1 + metadata: + name: petclinic + labels: + app.kubernetes.io/name: petclinic + app.kubernetes.io/component: webapp + app.kubernetes.io/part-of: petclinic + spec: + to: + kind: Service + name: petclinic + port: + targetPort: web diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/command/devfile_action_without_commandline_and_reference.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/command/devfile_action_without_commandline_and_reference.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/command/devfile_action_without_commandline_and_reference.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/command/devfile_action_without_commandline_and_reference.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/command/devfile_missing_command_actions.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/command/devfile_missing_command_actions.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/command/devfile_missing_command_actions.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/command/devfile_missing_command_actions.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/command/devfile_missing_command_name.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/command/devfile_missing_command_name.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/command/devfile_missing_command_name.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/command/devfile_missing_command_name.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/command/devfile_multiple_commands_actions.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/command/devfile_multiple_commands_actions.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/command/devfile_multiple_commands_actions.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/command/devfile_multiple_commands_actions.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_component_with_undeclared_field.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/component/devfile_component_with_undeclared_field.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_component_with_undeclared_field.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/component/devfile_component_with_undeclared_field.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_missing_component_type.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/component/devfile_missing_component_type.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_missing_component_type.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/component/devfile_missing_component_type.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_unknown_component_type.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/component/devfile_unknown_component_type.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_unknown_component_type.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/component/devfile_unknown_component_type.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_without_any_component.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/component/devfile_without_any_component.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/component/devfile_without_any_component.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/component/devfile_without_any_component.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/devfile/devfile_missing_name.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/devfile/devfile_missing_name.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/devfile/devfile_missing_name.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/devfile/devfile_missing_name.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/devfile/devfile_missing_spec_version.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/devfile/devfile_missing_spec_version.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/devfile/devfile_missing_spec_version.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/devfile/devfile_missing_spec_version.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/devfile/devfile_with_undeclared_field.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/devfile/devfile_with_undeclared_field.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/devfile/devfile_with_undeclared_field.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/devfile/devfile_with_undeclared_field.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/dockerimage_component/devfile_dockerimage_component.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/dockerimage_component/devfile_dockerimage_component.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_with_indistinctive_field_selector.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/dockerimage_component/devfile_dockerimage_component_with_indistinctive_field_selector.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_with_indistinctive_field_selector.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/dockerimage_component/devfile_dockerimage_component_with_indistinctive_field_selector.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_with_missing_image.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/dockerimage_component/devfile_dockerimage_component_with_missing_image.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_with_missing_image.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/dockerimage_component/devfile_dockerimage_component_with_missing_image.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_with_missing_memory_limit.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/dockerimage_component/devfile_dockerimage_component_with_missing_memory_limit.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_with_missing_memory_limit.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/dockerimage_component/devfile_dockerimage_component_with_missing_memory_limit.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_without_entry_point.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/dockerimage_component/devfile_dockerimage_component_without_entry_point.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/dockerimage_component/devfile_dockerimage_component_without_entry_point.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/dockerimage_component/devfile_dockerimage_component_without_entry_point.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_custom_registry.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_component_with_custom_registry.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_custom_registry.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_component_with_custom_registry.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_indistinctive_field_reference.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_component_with_indistinctive_field_reference.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_indistinctive_field_reference.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_component_with_indistinctive_field_reference.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_missing_id.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_component_with_missing_id.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_missing_id.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_component_with_missing_id.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_multiple_colons_in_id.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_component_with_multiple_colons_in_id.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_with_multiple_colons_in_id.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_component_with_multiple_colons_in_id.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_without_version.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_component_without_version.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_component_without_version.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_component_without_version.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_plugins.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_plugins.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_plugins.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_plugins.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_plugins_components_with_invalid_memory_limit.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_plugins_components_with_invalid_memory_limit.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_plugins_components_with_invalid_memory_limit.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_plugins_components_with_invalid_memory_limit.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_plugins_components_with_memory_limit.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_plugins_components_with_memory_limit.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_editor_plugins_components_with_memory_limit.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_plugins_components_with_memory_limit.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_plugin_components_with_preferences.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_plugin_components_with_preferences.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/editor_plugin_component/devfile_plugin_components_with_preferences.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_plugin_components_with_preferences.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_absolute_reference.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_absolute_reference.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_absolute_reference.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_absolute_reference.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_content_without_reference.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_content_without_reference.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_content_without_reference.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_content_without_reference.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_reference.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_reference.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_reference.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_reference.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_reference_and_content_as_block.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_reference_and_content_as_block.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_reference_and_content_as_block.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_kubernetes_component_reference_and_content_as_block.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_openshift_component.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_openshift_component.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_content_without_reference.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_openshift_component_content_without_reference.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_content_without_reference.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_openshift_component_content_without_reference.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_reference_and_content.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_openshift_component_reference_and_content.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_reference_and_content.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_openshift_component_reference_and_content.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_reference_and_content_as_block.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_openshift_component_reference_and_content_as_block.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_reference_and_content_as_block.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_openshift_component_reference_and_content_as_block.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_with_indistinctive_field_id.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_openshift_component_with_indistinctive_field_id.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_with_indistinctive_field_id.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_openshift_component_with_indistinctive_field_id.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_with_missing_reference_and_referenceContent.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_openshift_component_with_missing_reference_and_referenceContent.yaml similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/schema_test/kubernetes_openshift_component/devfile_openshift_component_with_missing_reference_and_referenceContent.yaml rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/kubernetes_openshift_component/devfile_openshift_component_with_missing_reference_and_referenceContent.yaml diff --git a/wsmaster/che-core-api-devfile/src/test/resources/workspace_config.json b/wsmaster/che-core-api-workspace/src/test/resources/devfile/workspace_config.json similarity index 100% rename from wsmaster/che-core-api-devfile/src/test/resources/workspace_config.json rename to wsmaster/che-core-api-workspace/src/test/resources/devfile/workspace_config.json diff --git a/wsmaster/integration-tests/cascade-removal/src/test/java/org/eclipse/che/core/db/jpa/CascadeRemovalTest.java b/wsmaster/integration-tests/cascade-removal/src/test/java/org/eclipse/che/core/db/jpa/CascadeRemovalTest.java index 863810c49a..4c8168a117 100644 --- a/wsmaster/integration-tests/cascade-removal/src/test/java/org/eclipse/che/core/db/jpa/CascadeRemovalTest.java +++ b/wsmaster/integration-tests/cascade-removal/src/test/java/org/eclipse/che/core/db/jpa/CascadeRemovalTest.java @@ -67,10 +67,10 @@ import org.eclipse.che.api.workspace.activity.WorkspaceActivityDao; import org.eclipse.che.api.workspace.activity.inject.WorkspaceActivityModule; import org.eclipse.che.api.workspace.server.DefaultWorkspaceLockService; import org.eclipse.che.api.workspace.server.DefaultWorkspaceStatusCache; -import org.eclipse.che.api.workspace.server.DevfileToWorkspaceConfigConverter; import org.eclipse.che.api.workspace.server.WorkspaceManager; import org.eclipse.che.api.workspace.server.WorkspaceRuntimes; import org.eclipse.che.api.workspace.server.WorkspaceSharedPool; +import org.eclipse.che.api.workspace.server.devfile.convert.DevfileConverter; import org.eclipse.che.api.workspace.server.hc.probe.ProbeScheduler; import org.eclipse.che.api.workspace.server.jpa.JpaWorkspaceDao.RemoveWorkspaceBeforeAccountRemovedEventSubscriber; import org.eclipse.che.api.workspace.server.jpa.WorkspaceJpaModule; @@ -241,14 +241,6 @@ public class CascadeRemovalTest { install(new JpaKubernetesRuntimeCacheModule()); bind(WorkspaceManager.class); - // is not used in a scope of integration tests - // but instance is needed for setting WorkspaceManager up - bind(DevfileToWorkspaceConfigConverter.class) - .toInstance( - devfile -> { - throw new UnsupportedOperationException("Operation is not implemented"); - }); - RuntimeInfrastructure infra = mock(RuntimeInfrastructure.class); doReturn(emptySet()).when(infra).getRecipeTypes(); bind(RuntimeInfrastructure.class).toInstance(infra); @@ -265,7 +257,7 @@ public class CascadeRemovalTest { mock(ProbeScheduler.class), new DefaultWorkspaceStatusCache(), new DefaultWorkspaceLockService(), - mock(DevfileToWorkspaceConfigConverter.class))); + mock(DevfileConverter.class))); when(wR.hasRuntime(anyString())).thenReturn(false); bind(WorkspaceRuntimes.class).toInstance(wR); bind(AccountManager.class); diff --git a/wsmaster/pom.xml b/wsmaster/pom.xml index 7310c049b1..b7b5a1eadd 100644 --- a/wsmaster/pom.xml +++ b/wsmaster/pom.xml @@ -29,7 +29,6 @@ che-core-api-auth-shared che-core-api-auth che-core-api-auth-github - che-core-api-devfile che-core-api-project-templates-shared che-core-api-project-templates che-core-api-workspace-shared