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

K8s-like devfile naming #13490

Merged
merged 13 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
/** Defines Devfile. */
public interface Devfile {

/** Returns Specification Version. It is required. */
String getSpecVersion();
/** Returns the name of the devfile. Shortcut for {@code getMetadata().getName()}. */
default String getName() {
return getMetadata() == null ? null : getMetadata().getName();
}

/**
* Returns the name of the devfile. Workspaces created from devfile, will inherit this name. It is
* required.
*/
String getName();
/** Returns Devfile API Version. It is required. */
String getApiVersion();

/**
* Returns projects configurations which are related to the devfile, when devfile doesn't contain
Expand All @@ -46,4 +45,7 @@ public interface Devfile {

/** Returns devfile attributes. Devfile attributes must not contain null keys or values. */
Map<String, String> getAttributes();

/** Returns the metadata of the devfile. */
Metadata getMetadata();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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.core.model.workspace.devfile;

/** Defines the metadata of a devfile. */
public interface Metadata {

/** @return the name of the devfile */
String getName();
}
5 changes: 3 additions & 2 deletions dashboard/devfile.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
specVersion: 0.0.1
name: dashboard-in-che
apiVersion: 1.0.0
metadata:
name: dashboard-in-che
projects:
- name: che
source:
Expand Down
5 changes: 4 additions & 1 deletion dashboard/src/components/typings/che.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,15 @@ declare namespace che {
}

export interface IWorkspaceDevfile {
specVersion: string;
apiVersion: string;
name: string;
components: Array<any>;
projects?: Array <any>;
commands?: Array <any>;
attributes?: che.IWorkspaceConfigAttributes;
metadata: {
name: string
}
}

export interface IWorkspaceEnvironment {
Expand Down
5 changes: 3 additions & 2 deletions devfile.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
specVersion: 0.0.1
name: che-in-che
apiVersion: 1.0.0
metadata:
name: che-in-che
projects:
- name: che
source:
Expand Down
5 changes: 3 additions & 2 deletions workspace-loader/devfile.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
specVersion: 0.0.1
name: workspace-loader
apiVersion: 1.0.0
metadata:
name: workspace-loader
projects:
- name: che
source:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ public class DefaultFactoryParameterResolverTest {

private static final String DEVFILE =
""
+ "specVersion: 0.0.1\n"
+ "name: test\n"
+ "apiVersion: 1.0.0\n"
+ "metadata:\n"
+ " name: test\n"
+ "components:\n"
+ "- type: kubernetes\n"
+ " alias: component\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,11 @@
@DTO
public interface DevfileDto extends Devfile {
@Override
String getSpecVersion();
String getApiVersion();

void setSpecVersion(String specVersion);
void setApiVersion(String apiVersion);

DevfileDto withSpecVersion(String specVersion);

@Override
String getName();

void setName(String name);

DevfileDto withName(String name);
DevfileDto withApiVersion(String apiVersion);

@Override
List<ProjectDto> getProjects();
Expand Down Expand Up @@ -60,4 +53,11 @@ public interface DevfileDto extends Devfile {
void setAttributes(Map<String, String> attributes);

DevfileDto withAttributes(Map<String, String> attributes);

@Override
MetadataDto getMetadata();

void setMetadata(MetadataDto metadata);

DevfileDto withMetadata(MetadataDto metadata);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.shared.dto.devfile;

import org.eclipse.che.api.core.model.workspace.devfile.Metadata;
import org.eclipse.che.dto.shared.DTO;

@DTO
public interface MetadataDto extends Metadata {

@Override
String getName();

void setName(String name);

MetadataDto withName(String name);
}
20 changes: 12 additions & 8 deletions wsmaster/che-core-api-workspace/README-devfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ Example of the minimal devfile with project and standard plugins set (Theia edit
```

---
specVersion: 0.0.1
name: petclinic-dev-environment
apiVersion: 0.0.1
metadata:
name: petclinic-dev-environment
projects:
- name: petclinic
source:
Expand Down Expand Up @@ -74,8 +75,9 @@ cloned to.
As an example, consider this devfile:

```yaml
specVersion: 0.0.1
name: example-devfile
apiVersion: 0.0.1
metadata:
name: example-devfile
projects:
- name: frontend
source:
Expand Down Expand Up @@ -278,8 +280,9 @@ If editor is not specified Devfile then default one will be provided. In case wh
Default value is `false` and means that Devfile needs default editor to be provisioned if no one is defined.
Example of Devfile without editor
```yaml
specVersion: 0.0.1
name: petclinic-dev-environment
apiVersion: 0.0.1
metadata:
name: petclinic-dev-environment
components:
- alias: myApp
type: kubernetes
Expand All @@ -294,8 +297,9 @@ Sometimes it may be needed to disable data persistence for some reasons, like wh
To achieve it the `persistVolumes` devfile attribute should be used. Default value is `true`, and in case of `false` `emptyDir` volumes will be used for configured volumes and PVC.
Example of Devfile with ephemeral mode enabled
```yaml
specVersion: 0.0.1
name: petclinic-dev-environment
apiVersion: 0.0.1
metadata:
name: petclinic-dev-environment
projects:
- name: petclinic
source:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.che.api.core.model.workspace.devfile.Endpoint;
import org.eclipse.che.api.core.model.workspace.devfile.Entrypoint;
import org.eclipse.che.api.core.model.workspace.devfile.Env;
import org.eclipse.che.api.core.model.workspace.devfile.Metadata;
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.core.model.workspace.runtime.Machine;
Expand Down Expand Up @@ -63,6 +64,7 @@
import org.eclipse.che.api.workspace.shared.dto.devfile.EndpointDto;
import org.eclipse.che.api.workspace.shared.dto.devfile.EntrypointDto;
import org.eclipse.che.api.workspace.shared.dto.devfile.EnvDto;
import org.eclipse.che.api.workspace.shared.dto.devfile.MetadataDto;
import org.eclipse.che.api.workspace.shared.dto.devfile.ProjectDto;
import org.eclipse.che.api.workspace.shared.dto.devfile.SourceDto;
import org.eclipse.che.api.workspace.shared.dto.stack.StackComponentDto;
Expand Down Expand Up @@ -110,12 +112,12 @@ private static DevfileDto asDto(Devfile devfile) {
List<ProjectDto> projects =
devfile.getProjects().stream().map(DtoConverter::asDto).collect(toList());
return newDto(DevfileDto.class)
.withName(devfile.getName())
.withSpecVersion(devfile.getSpecVersion())
.withApiVersion(devfile.getApiVersion())
.withCommands(commands)
.withComponents(components)
.withProjects(projects)
.withAttributes(devfile.getAttributes());
.withAttributes(devfile.getAttributes())
.withMetadata(asDto(devfile.getMetadata()));
}

private static ProjectDto asDto(Project project) {
Expand Down Expand Up @@ -416,5 +418,10 @@ public static MachineDto asDto(Machine machine) {
return machineDto;
}

/** Converts {@link Metadata} to {@link MetadataDto}. */
public static MetadataDto asDto(Metadata metadata) {
return newDto(MetadataDto.class).withName(metadata.getName());
}

private DtoConverter() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private Constants() {}

public static final String SCHEMA_LOCATION = "schema/devfile.json";

public static final String CURRENT_SPEC_VERSION = "0.0.1";
public static final String CURRENT_API_VERSION = "1.0.0";

public static final String EDITOR_COMPONENT_TYPE = "cheEditor";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
import static java.util.Collections.singleton;
import static java.util.stream.Collectors.toCollection;
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 static org.eclipse.che.api.workspace.server.devfile.Constants.CURRENT_API_VERSION;

import com.google.common.base.Strings;
import java.util.ArrayList;
Expand Down Expand Up @@ -90,7 +91,7 @@ public DevfileImpl workspaceToDevFile(WorkspaceConfigImpl wsConfig)
}

DevfileImpl devfile = new DevfileImpl();
devfile.setSpecVersion(CURRENT_SPEC_VERSION);
devfile.setApiVersion(CURRENT_API_VERSION);
devfile.setName(wsConfig.getName());

// Manage projects
Expand Down Expand Up @@ -180,12 +181,15 @@ public WorkspaceConfigImpl devFileToWorkspaceConfig(
}

private static void validateCurrentVersion(Devfile devFile) throws DevfileFormatException {
if (Strings.isNullOrEmpty(devFile.getSpecVersion())) {
throw new DevfileFormatException("Provided Devfile has no spec version specified");
if (Strings.isNullOrEmpty(devFile.getApiVersion())) {
throw new DevfileFormatException("Provided Devfile has no API version specified");
}
if (!CURRENT_SPEC_VERSION.equals(devFile.getSpecVersion())) {
if (!CURRENT_API_VERSION.equals(devFile.getApiVersion())) {
throw new DevfileFormatException(
format("Provided Devfile has unsupported version '%s'", devFile.getSpecVersion()));
format(
"Provided Devfile has unsupported version '%s'. The following versions are"
+ " supported: %s",
devFile.getApiVersion(), singleton(CURRENT_API_VERSION)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public String getNamespace() {
/** Returns the name of workspace. It can be stored by workspace config or devfile. */
public String getName() {
if (devfile != null) {
return devfile.getName();
return devfile.getMetadata().getName();
} else if (config != null) {
return config.getName();
} else {
Expand Down
Loading