Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devfile local features implenentation with schema validation and automated model build. #11998

Merged
merged 54 commits into from
Dec 6, 2018
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
8317bd0
Initial commit
mshaposhnik Nov 1, 2018
76a381f
Initial implementation
mshaposhnik Nov 2, 2018
94754e2
fixup
mshaposhnik Nov 2, 2018
df92cac
Merge branch 'master' into devfile
mshaposhnik Nov 5, 2018
e9f8e95
Added create workspace from yaml method
mshaposhnik Nov 6, 2018
05c26ec
Apply devfile schema refacorings;
mshaposhnik Nov 8, 2018
c3ace6a
Apply new schema
mshaposhnik Nov 9, 2018
d428140
Merge branch 'master' into devfile
mshaposhnik Nov 9, 2018
137c52b
Add tests
mshaposhnik Nov 13, 2018
96ba661
Add tests & model fixups
mshaposhnik Nov 15, 2018
8e35675
fixup! Add tests & model fixups
mshaposhnik Nov 15, 2018
989e70c
Add n\l;
mshaposhnik Nov 15, 2018
0014ef6
Add schema & validation
mshaposhnik Nov 19, 2018
9a4c9d7
Merge branch 'master' into devfile
mshaposhnik Nov 19, 2018
984f964
Add pojo gen from schema
mshaposhnik Nov 19, 2018
b53b516
Add schema generation
mshaposhnik Nov 20, 2018
0a91ba7
Review fix
mshaposhnik Nov 21, 2018
71f5d17
Minor code refactorings
mshaposhnik Nov 21, 2018
93ce24c
Fixup
mshaposhnik Nov 22, 2018
aed2ec0
Merge branch 'master' into devfile-new
mshaposhnik Nov 22, 2018
8a3e5f0
Review fixes
mshaposhnik Nov 22, 2018
4e8ff8f
Merge branch 'master' into devfile-new
mshaposhnik Nov 22, 2018
b968538
Merge branch 'master' into devfile-new
mshaposhnik Nov 27, 2018
db334a4
Review fixes
mshaposhnik Nov 27, 2018
78ec48c
Review fixups;
mshaposhnik Nov 28, 2018
f2b5a80
Added ws name validation and verbose mode
mshaposhnik Nov 28, 2018
a786998
Chavge version -> spec version
mshaposhnik Nov 29, 2018
781134e
Review fixes
mshaposhnik Nov 29, 2018
f992bc4
Minor fixup
mshaposhnik Nov 30, 2018
ed8e224
Use schema provider in validator
mshaposhnik Nov 30, 2018
eab5132
Added tests
mshaposhnik Dec 1, 2018
ce0de4d
Fmt fix
mshaposhnik Dec 1, 2018
decb524
Rename class
mshaposhnik Dec 1, 2018
80c7382
Minor fixes
mshaposhnik Dec 2, 2018
c99c3bc
Code fix
mshaposhnik Dec 2, 2018
62c4012
Code fix
mshaposhnik Dec 2, 2018
786fc90
Code fix
mshaposhnik Dec 2, 2018
0c9f2ce
Review fixes
mshaposhnik Dec 3, 2018
a392a65
Merge branch 'master' into devfile-new
mshaposhnik Dec 3, 2018
1a3c281
Review fixes
mshaposhnik Dec 3, 2018
414800b
Review fixes
mshaposhnik Dec 3, 2018
d6c5df1
Add swagger docs
mshaposhnik Dec 3, 2018
8fc4213
Review fixes
mshaposhnik Dec 3, 2018
e90cb39
Fix javadocs
mshaposhnik Dec 3, 2018
cd9c8d2
Code fixups
mshaposhnik Dec 3, 2018
dbd754b
Review fixes
mshaposhnik Dec 4, 2018
b0165f3
Add permissions for devfile export method
mshaposhnik Dec 5, 2018
1cc89bf
Fixup
mshaposhnik Dec 5, 2018
1d7f5c4
Minor fixups
mshaposhnik Dec 5, 2018
5fb7f9f
Merge branch 'master' into devfile-new
mshaposhnik Dec 6, 2018
ff05d07
Upgrade version
mshaposhnik Dec 6, 2018
597bb77
Rename test method
mshaposhnik Dec 6, 2018
a1bbe9f
Use IOutil to read file
mshaposhnik Dec 6, 2018
33116b0
Use IOutil to read file
mshaposhnik Dec 6, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions assembly/assembly-wsmaster-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-devfile</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-factory</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ protected void configure() {
bind(org.eclipse.che.api.user.server.PreferencesService.class);
bind(org.eclipse.che.security.oauth.OAuthAuthenticationService.class);

bind(org.eclipse.che.api.devfile.server.DevFileSchemaValidator.class);
bind(org.eclipse.che.api.devfile.server.DevFileService.class);

MapBinder<String, String> stacks =
MapBinder.newMapBinder(
binder(), String.class, String.class, Names.named(StackLoader.CHE_PREDEFINED_STACKS));
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@
<version>${che.version}</version>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-devfile</artifactId>
<version>${che.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-dto</artifactId>
Expand Down
149 changes: 149 additions & 0 deletions wsmaster/che-core-api-devfile/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

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

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>che-master-parent</artifactId>
<groupId>org.eclipse.che.core</groupId>
<version>6.15.0-SNAPSHOT</version>
</parent>
<artifactId>che-core-api-devfile</artifactId>
<packaging>jar</packaging>
<name>Che Core :: API :: Devfile</name>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>
<dependency>
<groupId>com.github.java-json-tools</groupId>
<artifactId>json-schema-validator</artifactId>
<version>2.2.10</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-model</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-workspace</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-workspace-shared</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-json</artifactId>
</dependency>
<dependency>
<groupId>org.everrest</groupId>
<artifactId>everrest-core</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>test</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/target/java-gen</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>0.5.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
<targetPackage>org.eclipse.che.api.devfile.model</targetPackage>
<includeAdditionalProperties>false</includeAdditionalProperties>
<includeHashcodeAndEquals>false</includeHashcodeAndEquals>
<includeToString>false</includeToString>
<initializeCollections>true</initializeCollections>
<generateBuilders>true</generateBuilders>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>analyze</id>
<configuration>
<ignoredDependencies>
<ignoredDependency>org.everrest:everrest-core</ignoredDependency>
</ignoredDependencies>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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;

public class Constants {

public static final String CURRENT_SPEC_VERSION = "0.0.1";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
/*
* 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.common.base.Strings.isNullOrEmpty;
import static java.lang.String.format;
import static java.util.Collections.singletonMap;
import static org.eclipse.che.api.devfile.server.Constants.CURRENT_SPEC_VERSION;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.StringJoiner;
import org.eclipse.che.api.devfile.model.Action;
import org.eclipse.che.api.devfile.model.Command;
import org.eclipse.che.api.devfile.model.Devfile;
import org.eclipse.che.api.devfile.model.Project;
import org.eclipse.che.api.devfile.model.Source;
import org.eclipse.che.api.devfile.model.Tool;
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;
import org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl;
import org.eclipse.che.api.workspace.server.model.impl.RecipeImpl;
import org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl;
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl;

public class DevFileConverter {

static Devfile workspaceToDevFile(WorkspaceConfigImpl wsConfig) {

Devfile devFile = new Devfile().withVersion(CURRENT_SPEC_VERSION).withName(wsConfig.getName());

// Manage projects
List<Project> projects = new ArrayList<>();
for (ProjectConfigImpl project : wsConfig.getProjects()) {
Source source =
new Source()
.withType(project.getSource().getType())
.withLocation(project.getSource().getLocation());
Project devProject = new Project().withName(project.getName()).withSource(source);
projects.add(devProject);
}
devFile.setProjects(projects);

// Manage commands
List<Command> commands = new ArrayList<>();
for (CommandImpl command : wsConfig.getCommands()) {
Command devCommand = new Command().withName(command.getName());
Action action =
new Action().withCommand(command.getCommandLine()).withType(command.getType());
if (!isNullOrEmpty(command.getAttributes().get("workingDir"))) {
action.setWorkdir(command.getAttributes().get("workingDir"));
}
// Remove internal attributes
command.getAttributes().remove("workingDir");
command.getAttributes().remove("pluginId");
// Put others
if (devCommand.getAttributes() == null) {
devCommand.withAttributes(command.getAttributes());
} else {
devCommand.getAttributes().putAll(command.getAttributes());
}

commands.add(devCommand);
}
devFile.setCommands(commands);

// Manage tools
List<Tool> tools = new ArrayList<>();
for (Map.Entry entry : wsConfig.getAttributes().entrySet()) {
if (entry.getKey().equals("editor")) {
String editorId = wsConfig.getAttributes().get("editor");
Tool editorTool =
new Tool()
.withType("cheEditor")
.withId(editorId)
.withName(wsConfig.getAttributes().get(editorId));
tools.add(editorTool);
} else if (entry.getKey().equals("plugins")) {
for (String pluginId : wsConfig.getAttributes().get("plugins").split(",")) {
Tool pluginTool =
new Tool()
.withId(pluginId)
.withType("chePlugin")
.withName(wsConfig.getAttributes().get(pluginId));
tools.add(pluginTool);
}
}
}

devFile.setTools(tools);
return devFile;
}

static WorkspaceConfigImpl devFileToWorkspaceConfig(Devfile devFile)
throws DevFileFormatException {
validateCurrentVersion(devFile);
WorkspaceConfigImpl config = new WorkspaceConfigImpl();

config.setName(devFile.getName());

// Manage projects
List<ProjectConfigImpl> projects = new ArrayList<>();
for (Project devProject : devFile.getProjects()) {
ProjectConfigImpl projectConfig = new ProjectConfigImpl();
projectConfig.setName(devProject.getName());
projectConfig.setPath("/" + projectConfig.getName());
SourceStorageImpl sourceStorage = new SourceStorageImpl();
sourceStorage.setType(devProject.getSource().getType());
sourceStorage.setLocation(devProject.getSource().getLocation());
projectConfig.setSource(sourceStorage);
projects.add(projectConfig);
}
config.setProjects(projects);

// Manage tools
Map<String, String> attributes = new HashMap<>();
StringJoiner pluginsStringJoiner = new StringJoiner(",");
for (Tool tool : devFile.getTools()) {
if (tool.getType().equals("cheEditor")) {
attributes.put("editor", tool.getId());
} else if (tool.getType().equals("chePlugin")) {
pluginsStringJoiner.add(tool.getId());
}
attributes.put(tool.getId(), tool.getName());
}
attributes.put("plugins", pluginsStringJoiner.toString());
config.setAttributes(attributes);

// Manage commands
List<CommandImpl> commands = new ArrayList<>();
for (Command devCommand : devFile.getCommands()) {
for (Action devAction : devCommand.getActions()) {
CommandImpl command = new CommandImpl();
command.setName(devCommand.getName() + ":" + devAction.getTool());
command.setType(devAction.getType());
command.setCommandLine(devAction.getCommand());
if (devAction.getWorkdir() != null) {
command.getAttributes().put("workingDir", devAction.getWorkdir());
}
Optional<Tool> toolOfCommand =
devFile
.getTools()
.stream()
.filter(tool -> tool.getName().equals(devAction.getTool()))
.findFirst();
if (toolOfCommand.isPresent() && !isNullOrEmpty(toolOfCommand.get().getId())) {
command.getAttributes().put("pluginId", toolOfCommand.get().getId());
}
if (devCommand.getAttributes() != null) {
command.getAttributes().putAll(devCommand.getAttributes());
}
commands.add(command);
}
}

config.setCommands(commands);

// TODO: Add default environment. Remove when it will be possible
config.setDefaultEnv("default");
EnvironmentImpl environment = new EnvironmentImpl();
RecipeImpl recipe = new RecipeImpl();
recipe.setType("dockerimage");
recipe.setContent("eclipse/ubuntu_jdk8");
environment.setRecipe(recipe);
MachineConfigImpl machine = new MachineConfigImpl();
machine.setAttributes(singletonMap("memoryLimitBytes", "2147483648"));
environment.setMachines(singletonMap("dev-machine", machine));
config.setEnvironments(singletonMap("default", environment));
return config;
}

private static void validateCurrentVersion(Devfile devFile) throws DevFileFormatException {
if (!CURRENT_SPEC_VERSION.equals(devFile.getVersion())) {
throw new DevFileFormatException(
format("Provided devfile has unsupported version %s", devFile.getVersion()));
}
}
}
Loading