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

CHE-12918 add checks for incompatible factories #13446

Merged
merged 1 commit into from
May 31, 2019
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 @@ -12,6 +12,7 @@
'use strict';
import {CheAPI} from '../../../../components/api/che-api.factory';
import {CheNotification} from '../../../../components/notification/che-notification.factory';
import {WorkspacesService} from '../../../workspaces/workspaces.service';

/**
* Controller for creating factory from a workspace.
Expand All @@ -20,7 +21,7 @@ import {CheNotification} from '../../../../components/notification/che-notificat
*/
export class FactoryFromWorkspaceCtrl {

static $inject = ['$filter', 'cheAPI', 'cheNotification'];
static $inject = ['$filter', 'cheAPI', 'cheNotification', 'workspacesService'];

private $filter: ng.IFilterService;
private cheAPI: CheAPI;
Expand All @@ -32,16 +33,20 @@ export class FactoryFromWorkspaceCtrl {
private isLoading: boolean;
private isImporting: boolean;
private factoryContent: any;
private workspacesService: WorkspacesService;

/**
* Default constructor that is using resource injection
*/
constructor($filter: ng.IFilterService, cheAPI: CheAPI, cheNotification: CheNotification) {
constructor($filter: ng.IFilterService, cheAPI: CheAPI, cheNotification: CheNotification, workspacesService: WorkspacesService) {
this.$filter = $filter;
this.cheAPI = cheAPI;
this.cheNotification = cheNotification;
this.workspacesService = workspacesService;

this.workspaces = cheAPI.getWorkspace().getWorkspaces();
this.workspaces = cheAPI.getWorkspace().getWorkspaces().filter((workspace: che.IWorkspace) => {
return this.workspacesService.isSupported(workspace);
});
this.workspacesById = cheAPI.getWorkspace().getWorkspacesById();

this.filtersWorkspaceSelected = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,29 @@
'use strict';
import {CheNotification} from '../../../components/notification/che-notification.factory';
import {CheFactory} from '../../../components/api/che-factory.factory';
import {LoadFactoryService} from '../../factories/load-factory/load-factory.service';

/**
* Controller for a factory details.
* @author Florent Benoit
*/
export class FactoryDetailsController {

static $inject = ['$route', 'cheFactory', 'cheNotification'];
static $inject = ['$route', 'cheFactory', 'cheNotification', 'loadFactoryService'];

private cheFactory: CheFactory;
private factory: che.IFactory;
private loadFactoryService: LoadFactoryService;

/**
* Default constructor that is using resource injection
*/
constructor($route: ng.route.IRouteService, cheFactory: CheFactory, cheNotification: CheNotification) {
constructor($route: ng.route.IRouteService, cheFactory: CheFactory, cheNotification: CheNotification, loadFactoryService: LoadFactoryService) {

this.cheFactory = cheFactory;
let factoryId = $route.current.params.id;
this.factory = this.cheFactory.getFactoryById(factoryId);
this.loadFactoryService = loadFactoryService;

cheFactory.fetchFactoryById(factoryId).then((factory: che.IFactory) => {
this.factory = factory;
Expand All @@ -40,6 +43,14 @@ export class FactoryDetailsController {
});
}

/**
* Returns `true` if supported version of factory workspace.
* @returns {boolean}
*/
isSupportedVersion(): boolean {
return this.loadFactoryService.isSupportedVersion(this.factory);
}

/**
* Returns the factory url based on id.
* @returns {link.href|*} link value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@
Red Hat, Inc. - initial API and implementation

-->
<che-description ng-hide="factoryDetailsController.isSupportedVersion()" class="workspace-details-warning-info">
This factory is using old workspace definition format which is not compatible anymore.
Please follow the <a ng-href="{{branding.docs.workspace}}" target="_blank">documentation</a> to update the definition of the workspace and benefits from the latest capabilities.
</che-description>
<che-toolbar
ng-if="factoryDetailsController.factory !== undefined"
che-title="{{factoryDetailsController.factory.name ? factoryDetailsController.factory.name : factoryDetailsController.factory.id}}"
che-title-icons-controller="factoryDetailsController"
che-button-name="Open"
che-button-href="{{factoryDetailsController.getFactoryIdUrl()}}"
che-button-href-target="_blank"
che-breadcrumb-title="All factories"
che-breadcrumb-href="#/factories">
che-breadcrumb-href="#/factories"
che-button-disabled="{{factoryDetailsController.isSupportedVersion() === false}}">
</che-toolbar>
<md-content md-scroll-y flex class="factory-details factory-details-content">
<cdvy-factory-information cdvy-factory="factoryDetailsController.factory"></cdvy-factory-information>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,44 @@
'use strict';
import {CheFactory} from '../../../../components/api/che-factory.factory';
import {CheEnvironmentRegistry} from '../../../../components/api/environment/che-environment-registry.factory';
import {LoadFactoryService} from '../../../factories/load-factory/load-factory.service';

/**
* Controller for a factory item.
* @author Oleksii Orel
*/
export class FactoryItemController {

static $inject = ['$location', 'cheFactory', 'cheEnvironmentRegistry', 'lodash'];
static $inject = ['$location', 'cheFactory', 'cheEnvironmentRegistry', 'lodash', 'loadFactoryService'];

private $location: ng.ILocationService;
private cheFactory: CheFactory;
private cheEnvironmentRegistry: CheEnvironmentRegistry;
private lodash: any;
private factory: che.IFactory;
private loadFactoryService: LoadFactoryService;

/**
* Default constructor that is using resource injection
*/
constructor($location: ng.ILocationService,
cheFactory: CheFactory,
cheEnvironmentRegistry: CheEnvironmentRegistry,
lodash: any) {
lodash: any,
loadFactoryService: LoadFactoryService) {
this.$location = $location;
this.cheFactory = cheFactory;
this.cheEnvironmentRegistry = cheEnvironmentRegistry;
this.lodash = lodash;
this.loadFactoryService = loadFactoryService;
}

/**
* Returns `true` if supported version of factory workspace.
* @returns {boolean}
*/
isSupportedVersion(): boolean {
return this.loadFactoryService.isSupportedVersion(this.factory);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,21 @@
</div>
<div flex-gt-xs="15">
<span class="che-xs-header noselect" name="open-factory" hide-gt-xs>Actions</span>
<span class="che-list-actions">
<span class="che-list-actions" ng-if="factoryItemController.isSupportedVersion() === true">
<a uib-tooltip="Open in IDE" ng-href="#/load-factory/{{factoryItemController.factory.id}}">
<span class="fa fa-chevron-circle-right factory-action"></span>
</a>
</span>
<div class="che-list-item-secondary workspace-item-not-supported" ng-if="factoryItemController.isSupportedVersion() === false">
<div>
<span>Not compatible</span>
<span class="che-list-actions">
<i class="fa fa-question-circle"
uib-tooltip="This factory is using old workspace definition format which is not compatible anymore.
Please follow the documentation to update the definition of the workspace and benefits from the latest capabilities."></i>
</span>
</div>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const WS_AGENT_STEP: number = 4;
*/
export class LoadFactoryController {

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

private cheAPI: CheAPI;
private $timeout: ng.ITimeoutService;
Expand Down Expand Up @@ -116,14 +116,14 @@ export class LoadFactoryController {
this.factory = factory;

// check factory polices:
if (!this.checkPolicies(this.factory)) {
if (!this.factory || !this.checkPolicies(this.factory)) {
return;
}

// check factory contains workspace config:
if (!this.factory.workspace) {
// check factory contains compatible workspace config:
if (!this.factory.workspace || !this.isSupportedVersion()) {
this.getLoadingSteps()[this.getCurrentProgressStep()].hasError = true;
this.getLoadingSteps()[this.getCurrentProgressStep()].logs = 'Factory has no workspace config.';
this.getLoadingSteps()[this.getCurrentProgressStep()].logs = 'Factory has no compatible workspace config.';
} else {
this.loadFactoryService.goToNextStep();
this.$timeout(() => {
Expand Down Expand Up @@ -679,6 +679,21 @@ export class LoadFactoryController {
this.$location.path('/');
}

/**
* Returns `true` if supported version of factory workspace.
* @returns {boolean}
*/
isSupportedVersion(): boolean {
return this.loadFactoryService.isSupportedVersion(this.factory);
}

/**
* Redirects to create workspace flow.
*/
redirectToCreateWorkspace(): void {
this.$location.path('/create-workspace').search({});
}

/**
* Performs downloading of the logs.
*/
Expand Down
18 changes: 14 additions & 4 deletions dashboard/src/app/factories/load-factory/load-factory.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
flex="auto">
<che-steps-container class="load-factory-working-log"
che-all-steps="loadFactoryController.getLoadingSteps()"
che-current-step="loadFactoryController.getCurrentProgressStep()"></che-steps-container>
che-current-step="loadFactoryController.getCurrentProgressStep()">
<che-description ng-hide="loadFactoryController.isSupportedVersion()" class="load-factory-warning-info">
This factory is using old workspace definition format which is not compatible anymore.
Please follow the <a ng-href="{{branding.docs.workspace}}" target="_blank">documentation</a> to update the definition of the workspace and benefits from the latest capabilities.
</che-description>
</che-steps-container>
</div>
</div>
<!--bottom bar-->
Expand All @@ -44,9 +49,14 @@
<div flex="50" layout="column" layout-align="end end" class="load-factory-bottom-bar-right">
<div class="load-factory-retry-block"
layout="column" layout-align="start end">
<che-button-danger che-button-title="{{loadFactoryController.isResourceProblem() ? 'Stop running workspaces' : 'Retry'}}"
ng-click="loadFactoryController.resetLoadFactoryInProgress()"
ng-show="loadFactoryController.getLoadingSteps()[loadFactoryController.getCurrentProgressStep()].hasError"></che-button-danger>
<div layout="row" layout-align="center stretch">
<che-button-primary che-button-title="Continue the process manually"
ng-hide="loadFactoryController.isSupportedVersion()"
ng-click="loadFactoryController.redirectToCreateWorkspace()"></che-button-primary>
<che-button-danger che-button-title="{{loadFactoryController.isResourceProblem() ? 'Stop running workspaces' : 'Retry'}}"
ng-click="loadFactoryController.resetLoadFactoryInProgress()"
ng-show="loadFactoryController.getLoadingSteps()[loadFactoryController.getCurrentProgressStep()].hasError"></che-button-danger>
</div>
<che-link class="load-factory-download-link"
ng-click="loadFactoryController.downloadLogs()"
che-link-text="Problem? download logs"></che-link>
Expand Down
23 changes: 22 additions & 1 deletion dashboard/src/app/factories/load-factory/load-factory.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Red Hat, Inc. - initial API and implementation
*/
'use strict';
import {WorkspacesService} from '../../workspaces/workspaces.service';

export interface FactoryLoadingStep {
text: string;
Expand All @@ -23,14 +24,19 @@ export interface FactoryLoadingStep {
* @author Ann Shumilova
*/
export class LoadFactoryService {

static $inject = ['workspacesService'];

private loadFactoryInProgress: boolean;
private currentProgressStep: number;
private loadingSteps: Array<FactoryLoadingStep>;
private workspacesService: WorkspacesService;

/**
* Default constructor that is using resource
*/
constructor () {
constructor (workspacesService: WorkspacesService) {
this.workspacesService = workspacesService;
this.loadFactoryInProgress = false;
this.currentProgressStep = 0;

Expand Down Expand Up @@ -123,4 +129,19 @@ export class LoadFactoryService {
setLoadFactoryInProgress(value: boolean): void {
this.loadFactoryInProgress = value;
}

/**
* Returns `true` if supported version of factory workspace.
* @param factory {che.IFactory}
* @returns {boolean}
*/
isSupportedVersion(factory: che.IFactory): boolean {
if (!factory) {
return false;
}
return this.workspacesService.isSupportedVersion({
config: factory.workspace,
devfile: factory.devfile
});
}
}
8 changes: 8 additions & 0 deletions dashboard/src/app/factories/load-factory/load-factory.styl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
.load-factory-working-log
margin 35px 0

div.load-factory-warning-info
border none
color inherit
max-width 448px
padding-left 20px
margin-bottom 20px
background-color $warning-color

.load-factory-bottom-bar
height 90px

Expand Down
6 changes: 4 additions & 2 deletions dashboard/src/app/workspaces/workspaces.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ export class WorkspacesService {
* @returns {boolean}
*/
isSupportedVersion(workspace: che.IWorkspace): boolean {
if (!workspace){
return false;
}
if (workspace.devfile) {
return true;
}

if (!workspace || !workspace.config) {
if (!workspace.config) {
return false;
}
const config = workspace.config;
Expand Down
Loading