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

Added attributes field to workspace config object #10721

Merged
merged 4 commits into from
Aug 13, 2018
Merged
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 @@ -57,4 +57,10 @@ public interface WorkspaceConfig {
* least 1 default environment and may contain N environments.
*/
Map<String, ? extends Environment> getEnvironments();

/**
* Returns workspace config attributes. Workspace config attributes must not contain null keys or
* values.
*/
Map<String, String> getAttributes();
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class StackValidationService {
*/
getWorkspaceConfigValidation(workspaceConfig: che.IWorkspaceConfig): che.IValidation {
let mandatoryKeys: Array<string> = ['name', 'environments', 'defaultEnv'];
let additionalKeys: Array<string> = ['commands', 'projects', 'description', 'links'];
let additionalKeys: Array<string> = ['commands', 'projects', 'description', 'links', 'attributes'];
let validKeys: Array<string> = mandatoryKeys.concat(additionalKeys);
let errors: Array<string> = [];
let isValid: boolean = true;
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/components/typings/che.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ declare namespace che {
};
projects?: Array <any>;
commands?: Array <any>;
attributes?: {[attrName: string]: string};
}

export interface IWorkspaceEnvironment {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ public class WorkspaceConfigImpl implements WorkspaceConfig {
private List<CommandImpl> commands;
private List<ProjectConfigImpl> projects;
private Map<String, EnvironmentImpl> environments;
private Map<String, String> attributes;

public WorkspaceConfigImpl(
String name,
String description,
String defaultEnv,
List<? extends Command> commands,
List<? extends ProjectConfig> projects,
Map<String, ? extends Environment> environments) {
Map<String, ? extends Environment> environments,
Map<String, String> attributes) {
this.name = name;
this.defaultEnv = defaultEnv;
this.description = description;
Expand All @@ -59,6 +61,9 @@ public WorkspaceConfigImpl(
if (projects != null) {
this.projects = projects.stream().map(ProjectConfigImpl::new).collect(toList());
}
if (attributes != null) {
this.attributes = new HashMap<>(attributes);
}
}

public WorkspaceConfigImpl(WorkspaceConfig workspaceConfig) {
Expand All @@ -68,7 +73,8 @@ public WorkspaceConfigImpl(WorkspaceConfig workspaceConfig) {
workspaceConfig.getDefaultEnv(),
workspaceConfig.getCommands(),
workspaceConfig.getProjects(),
workspaceConfig.getEnvironments());
workspaceConfig.getEnvironments(),
workspaceConfig.getAttributes());
}

@Override
Expand Down Expand Up @@ -111,6 +117,14 @@ public Map<String, EnvironmentImpl> getEnvironments() {
return environments;
}

@Override
public Map<String, String> getAttributes() {
if (attributes == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attrs are initialized in constructor, so they probably shouldn't be null

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not actually true.
Attributes are initialized in constructor only if the corresponding constructor parameter is not null. Also, there is a setter method that may receive null and set it into the attributes field.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no setter here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mshaposhnik You're right =) It though it is WorkspaceConfigImpl from workspace-api module.
BTW Comment about constructor parameter is actual for ide workspace config impl too.

return new HashMap<>();
}
return attributes;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
Expand All @@ -125,7 +139,8 @@ public boolean equals(Object obj) {
&& Objects.equals(defaultEnv, that.defaultEnv)
&& getCommands().equals(that.getCommands())
&& getProjects().equals(that.getProjects())
&& getEnvironments().equals(that.getEnvironments());
&& getEnvironments().equals(that.getEnvironments())
&& getAttributes().equals(that.getAttributes());
}

@Override
Expand All @@ -137,6 +152,7 @@ public int hashCode() {
hash = 31 * hash + getCommands().hashCode();
hash = 31 * hash + getProjects().hashCode();
hash = 31 * hash + getEnvironments().hashCode();
hash = 31 * hash + getAttributes().hashCode();
return hash;
}

Expand All @@ -158,6 +174,8 @@ public String toString() {
+ projects
+ ", environments="
+ environments
+ ", attributes="
+ attributes
+ '}';
}
}
4 changes: 0 additions & 4 deletions ide/commons-gwt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-core</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-commons-annotations</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ public static WorkspaceImpl createWorkspace() {
generate("wsId", 8),
createAccount(),
new WorkspaceConfigImpl(
generate("wsName", 8), "description", "defEnv", emptyList(), emptyList(), emptyMap()));
generate("wsName", 8),
"description",
"defEnv",
emptyList(),
emptyList(),
emptyMap(),
emptyMap()));
}

public static KubernetesRuntimeState createRuntimeState(WorkspaceImpl workspace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static Map<String, String> createPreferences() {

public static WorkspaceConfigImpl createWorkspaceConfig(String id) {
return new WorkspaceConfigImpl(
id + "_name", id + "description", "default-env", null, null, null);
id + "_name", id + "description", "default-env", null, null, null, null);
}

public static WorkspaceImpl createWorkspace(String id, Account account) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ public void setupEntities() throws Exception {
workspaces =
new WorkspaceImpl[] {
new WorkspaceImpl(
"ws1", account, new WorkspaceConfigImpl("wrksp1", "", "cfg1", null, null, null)),
"ws1",
account,
new WorkspaceConfigImpl("wrksp1", "", "cfg1", null, null, null, null)),
new WorkspaceImpl(
"ws2", account, new WorkspaceConfigImpl("wrksp2", "", "cfg2", null, null, null)),
"ws2",
account,
new WorkspaceConfigImpl("wrksp2", "", "cfg2", null, null, null, null)),
new WorkspaceImpl(
"ws3", account, new WorkspaceConfigImpl("wrksp3", "", "cfg3", null, null, null))
"ws3", account, new WorkspaceConfigImpl("wrksp3", "", "cfg3", null, null, null, null))
};
Injector injector = Guice.createInjector(new WorkspaceTckModule());
manager = injector.getInstance(EntityManager.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void setupEntities() throws Exception {

workspace =
new WorkspaceImpl(
"ws1", account, new WorkspaceConfigImpl("", "", "cfg1", null, null, null));
"ws1", account, new WorkspaceConfigImpl("", "", "cfg1", null, null, null, null));

workers =
new WorkerImpl[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,17 @@ public void setUp() throws TckRepositoryException {
workspaceRepository.createAll(
Arrays.asList(
new WorkspaceImpl(
"ws0", account, new WorkspaceConfigImpl("ws-name0", "", "cfg0", null, null, null)),
"ws0",
account,
new WorkspaceConfigImpl("ws-name0", "", "cfg0", null, null, null, null)),
new WorkspaceImpl(
"ws1", account, new WorkspaceConfigImpl("ws-name1", "", "cfg1", null, null, null)),
"ws1",
account,
new WorkspaceConfigImpl("ws-name1", "", "cfg1", null, null, null, null)),
new WorkspaceImpl(
"ws2",
account,
new WorkspaceConfigImpl("ws-name2", "", "cfg2", null, null, null))));
new WorkspaceConfigImpl("ws-name2", "", "cfg2", null, null, null, null))));

workerRepository.createAll(
Stream.of(workers).map(WorkerImpl::new).collect(Collectors.toList()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ public interface WorkspaceConfigDto extends WorkspaceConfig, Hyperlinks {

WorkspaceConfigDto withEnvironments(Map<String, EnvironmentDto> environments);

@Override
@FactoryParameter(obligation = OPTIONAL)
Map<String, String> getAttributes();

void setAttributes(Map<String, String> attributes);

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

@Override
WorkspaceConfigDto withLinks(List<Link> links);
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public static WorkspaceConfigDto asDto(WorkspaceConfig workspace) {
.withCommands(commands)
.withProjects(projects)
.withEnvironments(environments)
.withAttributes(workspace.getAttributes())
.withDescription(workspace.getDescription());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public CompletableFuture<Void> startAsync(
final RuntimeIdentity runtimeId = new RuntimeIdentityImpl(workspaceId, envName, ownerId);
try {
InternalEnvironment internalEnv =
createInternalEnvironment(environment, workspace.getAttributes());
createInternalEnvironment(environment, workspace.getConfig().getAttributes());
RuntimeContext runtimeContext = infrastructure.prepare(runtimeId, internalEnv);
InternalRuntime runtime = runtimeContext.getRuntime();

Expand Down Expand Up @@ -587,7 +587,7 @@ InternalRuntime<?> recoverOne(RuntimeInfrastructure infra, RuntimeIdentity ident
InternalRuntime runtime;
try {
InternalEnvironment internalEnv =
createInternalEnvironment(environment, workspace.getAttributes());
createInternalEnvironment(environment, workspace.getConfig().getAttributes());
runtime = infra.prepare(identity, internalEnv).getRuntime();

try (Unlocker ignored = lockService.writeLock(workspace.getId())) {
Expand Down Expand Up @@ -741,7 +741,7 @@ public Set<String> getSupportedRecipes() {
}

private InternalEnvironment createInternalEnvironment(
Environment environment, Map<String, String> workspaceAttributes)
Environment environment, Map<String, String> workspaceConfigAttributes)
throws InfrastructureException, ValidationException, NotFoundException {
String recipeType = environment.getRecipe().getType();
InternalEnvironmentFactory factory = environmentFactories.get(recipeType);
Expand All @@ -751,7 +751,7 @@ private InternalEnvironment createInternalEnvironment(
}
InternalEnvironment internalEnvironment = factory.create(environment);

applyWorkspaceNext(internalEnvironment, workspaceAttributes, recipeType);
applyWorkspaceNext(internalEnvironment, workspaceConfigAttributes, recipeType);

return internalEnvironment;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import java.util.Map;
import java.util.Objects;
import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
Expand Down Expand Up @@ -77,6 +79,14 @@ public static WorkspaceConfigImplBuilder builder() {
@MapKeyColumn(name = "environments_key")
private Map<String, EnvironmentImpl> environments;

@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(
name = "che_workspace_cfg_attributes",
joinColumns = @JoinColumn(name = "workspace_id"))
@MapKeyColumn(name = "attributes_key")
@Column(name = "attributes")
private Map<String, String> attributes;

public WorkspaceConfigImpl() {}

public WorkspaceConfigImpl(
Expand All @@ -85,7 +95,8 @@ public WorkspaceConfigImpl(
String defaultEnv,
List<? extends Command> commands,
List<? extends ProjectConfig> projects,
Map<String, ? extends Environment> environments) {
Map<String, ? extends Environment> environments,
Map<String, String> attributes) {
this.name = name;
this.defaultEnv = defaultEnv;
this.description = description;
Expand All @@ -102,6 +113,9 @@ public WorkspaceConfigImpl(
if (projects != null) {
this.projects = projects.stream().map(ProjectConfigImpl::new).collect(toList());
}
if (attributes != null) {
this.attributes = new HashMap<>(attributes);
}
}

public WorkspaceConfigImpl(WorkspaceConfig workspaceConfig) {
Expand All @@ -111,7 +125,8 @@ public WorkspaceConfigImpl(WorkspaceConfig workspaceConfig) {
workspaceConfig.getDefaultEnv(),
workspaceConfig.getCommands(),
workspaceConfig.getProjects(),
workspaceConfig.getEnvironments());
workspaceConfig.getEnvironments(),
workspaceConfig.getAttributes());
}

@Override
Expand Down Expand Up @@ -178,6 +193,18 @@ public void setEnvironments(Map<String, EnvironmentImpl> environments) {
this.environments = environments;
}

@Override
public Map<String, String> getAttributes() {
if (attributes == null) {
attributes = new HashMap<>();
}
return attributes;
}

public void setAttributes(Map<String, String> attributes) {
this.attributes = attributes;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
Expand All @@ -193,7 +220,8 @@ public boolean equals(Object obj) {
&& Objects.equals(defaultEnv, that.defaultEnv)
&& getCommands().equals(that.getCommands())
&& getProjects().equals(that.getProjects())
&& getEnvironments().equals(that.getEnvironments());
&& getEnvironments().equals(that.getEnvironments())
&& getAttributes().equals(that.getAttributes());
}

@Override
Expand All @@ -206,6 +234,7 @@ public int hashCode() {
hash = 31 * hash + getCommands().hashCode();
hash = 31 * hash + getProjects().hashCode();
hash = 31 * hash + getEnvironments().hashCode();
hash = 31 * hash + getAttributes().hashCode();
return hash;
}

Expand All @@ -229,6 +258,8 @@ public String toString() {
+ projects
+ ", environments="
+ environments
+ ", attributes="
+ attributes
+ '}';
}

Expand All @@ -241,16 +272,17 @@ public static class WorkspaceConfigImplBuilder {

private String name;
private String defaultEnvName;
private String description;
private List<? extends Command> commands;
private List<? extends ProjectConfig> projects;
private Map<String, ? extends Environment> environments;
private String description;
private Map<String, String> attributes;

private WorkspaceConfigImplBuilder() {}

public WorkspaceConfigImpl build() {
return new WorkspaceConfigImpl(
name, description, defaultEnvName, commands, projects, environments);
name, description, defaultEnvName, commands, projects, environments, attributes);
}

public WorkspaceConfigImplBuilder fromConfig(WorkspaceConfig workspaceConfig) {
Expand Down Expand Up @@ -293,5 +325,10 @@ public WorkspaceConfigImplBuilder setDescription(String description) {
this.description = description;
return this;
}

public WorkspaceConfigImplBuilder setAttributes(Map<String, String> attributes) {
this.attributes = attributes;
return this;
}
}
}
Loading