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

Deprecate workspaces with Devfile stored as workspace config #13588

Merged
merged 10 commits into from
Jul 3, 2019
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ public interface Factory {
/** Returns creator of this factory instance. */
Author getCreator();

/**
* Returns a workspace configuration of this factory instance, it is mandatory for every factory
* instance.
*/
/** Returns a workspace configuration of this factory instance. */
mkuznyetsov marked this conversation as resolved.
Show resolved Hide resolved
WorkspaceConfig getWorkspace();

/** Returns restrictions of this factory instance. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public interface Component {
* optional and applicable only for 'dockerimage' component type. `CHE_PROJECTS_ROOT` environment
* variable should contains a path where projects sources are mount.
*/
boolean getMountSources();
Boolean getMountSources();
metlos marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns the command to run in the dockerimage component instead of the default one provided in
Expand Down
57 changes: 38 additions & 19 deletions dashboard/src/app/factories/load-factory/load-factory.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
'use strict';
import {CheAPI} from '../../../components/api/che-api.factory';
import {CheWorkspace} from '../../../components/api/workspace/che-workspace.factory';
import {LoadFactoryService, FactoryLoadingStep} from './load-factory.service';
import {CheNotification} from '../../../components/notification/che-notification.factory';
import {RouteHistory} from '../../../components/routing/route-history.service';
Expand All @@ -25,9 +26,10 @@ const WS_AGENT_STEP: number = 4;
*/
export class LoadFactoryController {

static $inject = ['cheAPI', 'cheJsonRpcApi', '$route', '$timeout', '$mdDialog', 'loadFactoryService', 'lodash', 'cheNotification', '$location', 'routeHistory', '$window', 'loadFactoryService'];
static $inject = ['cheAPI', 'cheWorkspace','cheJsonRpcApi', '$route', '$timeout', '$mdDialog', 'loadFactoryService', 'lodash', 'cheNotification', '$location', 'routeHistory', '$window', 'loadFactoryService'];

private cheAPI: CheAPI;
cheWorkspace: CheWorkspace;
private $timeout: ng.ITimeoutService;
private $mdDialog: ng.material.IDialogService;
private loadFactoryService: LoadFactoryService;
Expand All @@ -49,6 +51,7 @@ export class LoadFactoryController {
* Default constructor that is using resource
*/
constructor(cheAPI: CheAPI,
cheWorkspace: CheWorkspace,
cheJsonRpcApi: CheJsonRpcApi,
$route: ng.route.IRouteService,
$timeout: ng.ITimeoutService,
Expand All @@ -60,6 +63,7 @@ export class LoadFactoryController {
routeHistory: RouteHistory,
$window: ng.IWindowService) {
this.cheAPI = cheAPI;
this.cheWorkspace = cheWorkspace;
this.$timeout = $timeout;
this.$mdDialog = $mdDialog;
this.loadFactoryService = loadFactoryService;
Expand Down Expand Up @@ -121,9 +125,9 @@ export class LoadFactoryController {
}

// check factory contains compatible workspace config:
if (!this.factory.workspace || !this.isSupportedVersion()) {
if (!(Boolean(this.factory.workspace) !== Boolean(this.factory.devfile)) || !this.isSupportedVersion()) {
this.getLoadingSteps()[this.getCurrentProgressStep()].hasError = true;
this.getLoadingSteps()[this.getCurrentProgressStep()].logs = 'Factory has no compatible workspace config.';
this.getLoadingSteps()[this.getCurrentProgressStep()].logs = 'Factory has no compatible workspace config or devfile.';
} else {
this.loadFactoryService.goToNextStep();
this.$timeout(() => {
Expand Down Expand Up @@ -272,20 +276,35 @@ export class LoadFactoryController {
* Create workspace from factory config.
*/
createWorkspace(): any {
let config = this.factory.workspace;
// set factory attribute:
let attrs = {factoryId: this.factory.id};
config.name = this.getWorkspaceName(config.name);

// todo: fix account when ready:
let creationPromise = this.cheAPI.getWorkspace().createWorkspaceFromConfig(null, config, attrs);
creationPromise.then((data: any) => {
this.$timeout(() => {
this.startWorkspace(data);
}, 1000);
}, (error: any) => {
this.handleError(error);
});
if (this.factory.workspace) {
let config = this.factory.workspace;
// set factory attribute:
let attrs = {factoryId: this.factory.id};
config.name = this.getWorkspaceName(config.name);

// todo: fix account when ready:
let creationPromise = this.cheAPI.getWorkspace().createWorkspaceFromConfig(null, config, attrs);
creationPromise.then((data: any) => {
this.$timeout(() => {
this.startWorkspace(data);
}, 1000);
}, (error: any) => {
this.handleError(error);
});
} else if (this.factory.devfile) {
let devfile = this.factory.devfile;
// set factory attribute:
let attrs = {factoryId: this.factory.id};

let creationPromise = this.cheAPI.getWorkspace().createWorkspaceFromDevfile(null, devfile, attrs);
Copy link
Contributor

Choose a reason for hiding this comment

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

add the the todo here as well just to be sure?

creationPromise.then((data: any) => {
this.$timeout(() => {
this.startWorkspace(data);
}, 1000);
}, (error: any) => {
this.handleError(error);
});
}
}

/**
Expand Down Expand Up @@ -340,7 +359,7 @@ export class LoadFactoryController {
* @param workspace
*/
doStartWorkspace(workspace: che.IWorkspace): void {
let startWorkspacePromise = this.cheAPI.getWorkspace().startWorkspace(workspace.id, workspace.config.defaultEnv);
let startWorkspacePromise = this.cheAPI.getWorkspace().startWorkspace(workspace.id);
this.loadFactoryService.goToNextStep();

startWorkspacePromise.then((data: any) => {
Expand Down Expand Up @@ -668,7 +687,7 @@ export class LoadFactoryController {
* @returns {string} IDE application link
*/
getIDELink() {
return '/ide/' + this.workspace.namespace + '/' + this.workspace.config.name;
return '/ide/' + this.workspace.namespace + '/' + this.cheWorkspace.getWorkspaceDataManager().getName(this.workspace);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ export class CheAccordion implements ng.IDirective {
continue;
}

let siblingBodyEl = siblingEl.find('.che-accordion-body'),
siblingBodyHeight = siblingBodyEl[0].clientHeight;
let siblingBodyEl = siblingEl.find('.che-accordion-body');
if (siblingBodyEl.length === 0) {
continue;
}

let siblingBodyHeight = siblingBodyEl[0].clientHeight;
siblingBodyEl.css('height', siblingBodyHeight);
panesToClose.push(siblingEl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void apply(
.getVolumes()
.put(v.getName(), new VolumeImpl().withPath(v.getContainerPath())));

if (dockerimageComponent.getMountSources()) {
if (Boolean.TRUE.equals(dockerimageComponent.getMountSources())) {
machineConfig
.getVolumes()
.put(PROJECTS_VOLUME_NAME, new VolumeImpl().withPath(projectFolderPath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void apply(

estimateCommandsMachineName(workspaceConfig, k8sComponent, podsData);

if (k8sComponent.getMountSources()) {
if (Boolean.TRUE.equals(k8sComponent.getMountSources())) {
applyProjectsVolumes(podsData, componentObjects);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.che.api.factory.shared.dto.IdeDto;
import org.eclipse.che.api.factory.shared.dto.PoliciesDto;
import org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto;
import org.eclipse.che.api.workspace.shared.dto.devfile.DevfileDto;
import org.eclipse.che.commons.lang.IoUtil;
import org.eclipse.che.commons.lang.NameGenerator;
import org.eclipse.che.dto.server.DtoFactory;
Expand Down Expand Up @@ -177,6 +178,21 @@ public FactoryDto withV(String v) {
return factoryDto.withV(v);
}

@Override
public DevfileDto getDevfile() {
mkuznyetsov marked this conversation as resolved.
Show resolved Hide resolved
return factoryDto.getDevfile();
}

@Override
public void setDevfile(DevfileDto workspace) {
factoryDto.setDevfile(workspace);
}

@Override
public FactoryDto withDevfile(DevfileDto devfileDto) {
return factoryDto.withDevfile(devfileDto);
}

@Override
public WorkspaceConfigDto getWorkspace() {
Copy link
Member

Choose a reason for hiding this comment

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

Please add @nullable and describe when it may be such. The same for workspace config field

return factoryDto.getWorkspace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static org.eclipse.che.api.factory.shared.Constants.URL_PARAMETER_NAME;
import static org.eclipse.che.dto.server.DtoFactory.newDto;

import java.util.Collections;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
Expand All @@ -27,6 +28,7 @@
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;
import org.eclipse.che.api.workspace.shared.dto.devfile.ProjectDto;

/**
* Provides Factory Parameters resolver for github repositories.
Expand Down Expand Up @@ -105,21 +107,28 @@ public FactoryDto createFactory(@NotNull final Map<String, String> factoryParame
newDto(FactoryDto.class)
.withV(CURRENT_VERSION)
.withSource("repo")));
// add workspace configuration if not defined
if (factory.getWorkspace() == null) {
factory.setWorkspace(
urlFactoryBuilder.buildDefaultWorkspaceConfig(githubUrl.getRepository()));
}

// apply merging operation from existing and computed settings if needed
return projectConfigDtoMerger.merge(
factory,
() -> {
// Compute project configuration
return newDto(ProjectConfigDto.class)
.withSource(githubSourceStorageBuilder.build(githubUrl))
.withName(githubUrl.getRepository())
.withPath("/".concat(githubUrl.getRepository()));
});
if (factory.getWorkspace() != null) {
return projectConfigDtoMerger.merge(
factory,
() -> {
// Compute project configuration
return newDto(ProjectConfigDto.class)
.withSource(githubSourceStorageBuilder.buildWorkspaceConfigSource(githubUrl))
.withName(githubUrl.getRepository())
.withPath("/".concat(githubUrl.getRepository()));
});
} else if (factory.getDevfile() == null) {
// initialize default devfile and github project
factory.setDevfile(urlFactoryBuilder.buildDefaultDevfile(githubUrl.getRepository()));
factory
.getDevfile()
.setProjects(
Collections.singletonList(
newDto(ProjectDto.class)
.withSource(githubSourceStorageBuilder.buildDevfileSource(githubUrl))
.withName(githubUrl.getRepository())));
}
return factory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javax.inject.Singleton;
import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto;
import org.eclipse.che.api.workspace.shared.dto.SourceStorageDto;
import org.eclipse.che.api.workspace.shared.dto.devfile.SourceDto;

/**
* Create {@link ProjectConfigDto} object from objects
Expand All @@ -34,7 +35,7 @@ public class GithubSourceStorageBuilder {
* @param githubUrl an instance of {@link GithubUrl}
* @return newly created source storage DTO object
*/
public SourceStorageDto build(GithubUrl githubUrl) {
public SourceStorageDto buildWorkspaceConfigSource(GithubUrl githubUrl) {
// Create map for source storage dto
Map<String, String> parameters = new HashMap<>(2);
parameters.put("branch", githubUrl.getBranch());
Expand All @@ -47,4 +48,18 @@ public SourceStorageDto build(GithubUrl githubUrl) {
.withType("github")
.withParameters(parameters);
}

/**
* Create SourceStorageDto DTO by using data of a github url
*
* @param githubUrl an instance of {@link GithubUrl}
* @return newly created source DTO object
*/
public SourceDto buildDevfileSource(GithubUrl githubUrl) {
// T_O_D_O add keepDir support when Devfile will support it
return newDto(SourceDto.class)
.withLocation(githubUrl.repositoryLocation())
.withType("github")
.withBranch(githubUrl.getBranch());
}
}
Loading