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

Add an ability to specify Devfile in Stack #13346

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -25,6 +25,7 @@
import org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl;
import org.eclipse.che.api.workspace.server.spi.StackDao;
import org.eclipse.che.api.workspace.server.stack.StackLoader;
import org.eclipse.che.api.workspace.server.stack.StackValidator;
import org.eclipse.che.api.workspace.server.stack.image.StackIcon;
import org.eclipse.che.api.workspace.shared.stack.Stack;
import org.eclipse.che.core.db.DBInitializer;
Expand Down Expand Up @@ -54,10 +55,11 @@ public class MultiuserStackLoader extends StackLoader {
public MultiuserStackLoader(
@Named("che.predefined.stacks.reload_on_start") boolean reloadStacksOnStart,
@Named(CHE_PREDEFINED_STACKS) Map<String, String> stacks2images,
StackValidator stackValidator,
StackDao stackDao,
JpaStackPermissionsDao permissionsDao,
DBInitializer dbInitializer) {
super(reloadStacksOnStart, stacks2images, stackDao, dbInitializer);
super(reloadStacksOnStart, stacks2images, stackValidator, stackDao, dbInitializer);
this.permissionsDao = permissionsDao;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public void setupEntities() throws Exception {

stacks =
new StackImpl[] {
new StackImpl("stack1", "st1", null, null, null, null, null, null, null),
new StackImpl("stack2", "st2", null, null, null, null, null, null, null)
new StackImpl("stack1", "st1", null, null, null, null, null, null, null, null),
new StackImpl("stack2", "st2", null, null, null, null, null, null, null, null)
};

Injector injector = Guice.createInjector(new WorkspaceTckModule());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,29 @@ public void setupEntities() throws Exception {
stacks =
new StackImpl[] {
new StackImpl(
"stack1", "st1", null, null, null, Arrays.asList("tag1", "tag2"), null, null, null),
new StackImpl("stack2", "st2", null, null, null, null, null, null, null),
"stack1",
"st1",
null,
null,
null,
Arrays.asList("tag1", "tag2"),
null,
null,
null,
null),
new StackImpl("stack2", "st2", null, null, null, null, null, null, null, null),
new StackImpl(
"stack3", "st3", null, null, null, Arrays.asList("tag1", "tag2"), null, null, null),
new StackImpl("stack4", "st4", null, null, null, null, null, null, null)
"stack3",
"st3",
null,
null,
null,
Arrays.asList("tag1", "tag2"),
null,
null,
null,
null),
new StackImpl("stack4", "st4", null, null, null, null, null, null, null, null)
};

Injector injector = Guice.createInjector(new WorkspaceTckModule());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public void setUp() throws TckRepositoryException {
wCfg.setDescription("description");
stackRepository.createAll(
asList(
new StackImpl("stack1", "st1", null, null, null, null, wCfg, null, null),
new StackImpl("stack2", "st2", null, null, null, null, wCfg, null, null)));
new StackImpl("stack1", "st1", null, null, null, null, wCfg, null, null, null),
new StackImpl("stack2", "st2", null, null, null, null, wCfg, null, null, null)));

permissionsRepository.createAll(
Stream.of(permissions).map(StackPermissionsImpl::new).collect(Collectors.toList()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.che.api.core.rest.shared.dto.Hyperlinks;
import org.eclipse.che.api.core.rest.shared.dto.Link;
import org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto;
import org.eclipse.che.api.workspace.shared.dto.devfile.DevfileDto;
import org.eclipse.che.api.workspace.shared.stack.Stack;
import org.eclipse.che.dto.shared.DTO;

Expand Down Expand Up @@ -53,6 +54,13 @@ public interface StackDto extends Stack, Hyperlinks {

StackDto withWorkspaceConfig(WorkspaceConfigDto workspaceConfigDto);

@Override
DevfileDto getDevfile();

void setDevfile(DevfileDto devfile);

StackDto withDevfile(DevfileDto devfile);

@Override
List<StackComponentDto> getComponents();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.util.List;
import org.eclipse.che.api.core.model.workspace.WorkspaceConfig;
import org.eclipse.che.api.core.model.workspace.devfile.Devfile;
import org.eclipse.che.commons.annotation.Nullable;

/**
Expand Down Expand Up @@ -55,12 +56,23 @@ public interface Stack {
List<String> getTags();

/**
* Return the {@link WorkspaceConfig} for creation workspace. This workspaceConfig can be used for
* store machine source, list predefined commands, projects etc.
* Return the {@link WorkspaceConfig} for creation workspace.
*
* <p>The only one format (workspace config or devfile) may be used for workspace at the same
* time.
*/
@Nullable
WorkspaceConfig getWorkspaceConfig();

/**
* Return the {@link Devfile} for creation workspace.
*
* <p>The only one format (workspace config or devfile) may be used for workspace at the same
* time.
*/
@Nullable
Devfile getDevfile();

/**
* Return the list of the components that stack consist of.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ public static StackDto asDto(Stack stack) {
workspaceConfigDto = asDto(stack.getWorkspaceConfig());
}

DevfileDto devfileDto = null;
if (stack.getDevfile() != null) {
devfileDto = asDto(stack.getDevfile());
}

List<StackComponentDto> componentsDto = null;
if (stack.getComponents() != null) {
componentsDto =
Expand All @@ -265,7 +270,8 @@ public static StackDto asDto(Stack stack) {
.withScope(stack.getScope())
.withTags(stack.getTags())
.withComponents(componentsDto)
.withWorkspaceConfig(workspaceConfigDto);
.withWorkspaceConfig(workspaceConfigDto)
.withDevfile(devfileDto);
}

/** Converts {@link ProjectConfig} to {@link ProjectConfigDto}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import static java.util.stream.Collectors.toCollection;

import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class ComponentImpl implements Component {
@Column(name = "id")
private Long generatedId;

@SerializedName("id")
@Column(name = "component_id", nullable = false)
private String componentId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.eclipse.che.api.core.model.workspace.WorkspaceConfig;
import org.eclipse.che.api.core.model.workspace.devfile.Devfile;
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.server.stack.image.StackIcon;
import org.eclipse.che.api.workspace.shared.stack.Stack;
import org.eclipse.che.api.workspace.shared.stack.StackComponent;
Expand Down Expand Up @@ -86,6 +88,10 @@ public static StackBuilder builder() {
@JoinColumn(name = "workspaceconfig_id")
private WorkspaceConfigImpl workspaceConfig;

@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "devfile_id")
private DevfileImpl devfile;

@ElementCollection
@CollectionTable(name = "stack_components", joinColumns = @JoinColumn(name = "stack_id"))
private List<StackComponentImpl> components;
Expand All @@ -103,6 +109,7 @@ public StackImpl(StackImpl stack) {
stack.getCreator(),
stack.getTags(),
stack.getWorkspaceConfig(),
stack.getDevfile(),
stack.getComponents(),
stack.getStackIcon());
}
Expand All @@ -116,6 +123,7 @@ public StackImpl(Stack stack) {
stack.getCreator(),
stack.getTags(),
stack.getWorkspaceConfig(),
stack.getDevfile(),
stack.getComponents(),
null);
}
Expand All @@ -128,6 +136,7 @@ public StackImpl(
String creator,
List<String> tags,
WorkspaceConfig workspaceConfig,
Devfile devfile,
List<? extends StackComponent> components,
StackIcon stackIcon) {
this.id = id;
Expand All @@ -144,6 +153,9 @@ public StackImpl(
if (workspaceConfig != null) {
this.workspaceConfig = new WorkspaceConfigImpl(workspaceConfig);
}
if (devfile != null) {
this.devfile = new DevfileImpl(devfile);
}
if (components != null) {
this.components = components.stream().map(StackComponentImpl::new).collect(toList());
}
Expand Down Expand Up @@ -215,6 +227,15 @@ public void setWorkspaceConfig(WorkspaceConfigImpl workspaceConfig) {
this.workspaceConfig = workspaceConfig;
}

@Override
public DevfileImpl getDevfile() {
return devfile;
}

public void setDevfile(DevfileImpl devfile) {
this.devfile = devfile;
}

@Override
public List<StackComponentImpl> getComponents() {
if (components == null) {
Expand Down Expand Up @@ -251,6 +272,7 @@ public boolean equals(Object obj) {
&& Objects.equals(creator, that.creator)
&& getTags().equals(that.getTags())
&& Objects.equals(workspaceConfig, that.workspaceConfig)
&& Objects.equals(devfile, that.devfile)
&& getComponents().equals(that.getComponents())
&& Objects.equals(stackIcon, that.stackIcon);
}
Expand All @@ -265,6 +287,7 @@ public int hashCode() {
hash = 31 * hash + Objects.hashCode(creator);
hash = 31 * hash + getTags().hashCode();
hash = 31 * hash + Objects.hashCode(workspaceConfig);
hash = 31 * hash + Objects.hashCode(devfile);
hash = 31 * hash + getComponents().hashCode();
hash = 31 * hash + Objects.hashCode(stackIcon);
return hash;
Expand Down Expand Up @@ -292,6 +315,8 @@ public String toString() {
+ tags
+ ", workspaceConfig="
+ workspaceConfig
+ ", devfile="
+ devfile
+ ", components="
+ components
+ ", stackIcon="
Expand All @@ -308,6 +333,7 @@ public static class StackBuilder {
private String creator;
private List<String> tags;
private WorkspaceConfig workspaceConfig;
private Devfile devfile;
private StackSource source;
private List<? extends StackComponent> components;
private StackIcon stackIcon;
Expand Down Expand Up @@ -352,6 +378,11 @@ public StackBuilder setWorkspaceConfig(WorkspaceConfig workspaceConfig) {
return this;
}

public StackBuilder setDevfile(Devfile devfile) {
this.devfile = devfile;
return this;
}

public StackBuilder setSource(StackSource source) {
this.source = source;
return this;
Expand All @@ -369,7 +400,16 @@ public StackBuilder setStackIcon(StackIcon stackIcon) {

public StackImpl build() {
return new StackImpl(
id, name, description, scope, creator, tags, workspaceConfig, components, stackIcon);
id,
name,
description,
scope,
creator,
tags,
workspaceConfig,
devfile,
components,
stackIcon);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import javax.inject.Named;
import javax.inject.Singleton;
import org.apache.commons.io.IOUtils;
import org.eclipse.che.api.core.BadRequestException;
import org.eclipse.che.api.core.ConflictException;
import org.eclipse.che.api.core.NotFoundException;
import org.eclipse.che.api.core.ServerException;
Expand Down Expand Up @@ -62,16 +63,19 @@ public class StackLoader {
private final Map<String, String> stacks2images;
private final DBInitializer dbInitializer;
private final Boolean reloadStacksOnStart;
private final StackValidator stackValidator;

@Inject
@SuppressWarnings("unused")
public StackLoader(
@Named("che.predefined.stacks.reload_on_start") boolean reloadStacksOnStart,
@Named(CHE_PREDEFINED_STACKS) Map<String, String> stacks2images,
StackValidator stackValidator,
StackDao stackDao,
DBInitializer dbInitializer) {
this.reloadStacksOnStart = reloadStacksOnStart;
this.stacks2images = stacks2images;
this.stackValidator = stackValidator;
this.stackDao = stackDao;
this.dbInitializer = dbInitializer;
GSON = new GsonBuilder().create();
Expand All @@ -98,7 +102,7 @@ public void start() {
final Path imagesDirPath = !isNullOrEmpty(imagesDir) ? Paths.get(imagesDir) : null;
stacks.forEach(stack -> loadStack(stack, imagesDirPath));
} catch (Exception ex) {
LOG.error("Failed to store stacks from '{}'", stackFile);
LOG.error("Failed to store stacks from '{}'. Cause: %s", stackFile, ex.getMessage());
}
}
LOG.info("Stacks initialization finished");
Expand All @@ -108,13 +112,15 @@ public void start() {
protected void loadStack(StackImpl stack, Path imagePath) {
setIconData(stack, imagePath);
try {
stackValidator.check(stack);
try {
stackDao.update(stack);
} catch (NotFoundException ex) {
stackDao.create(stack);
}
} catch (ServerException | ConflictException ex) {
LOG.warn(format("Failed to load stack with id '%s' ", stack.getId()), ex.getMessage());
} catch (BadRequestException | ServerException | NotFoundException | ConflictException ex) {
LOG.warn(
format("Failed to load stack with id '%s'. Cause: %s", stack.getId(), ex.getMessage()));
}
}

Expand Down
Loading