Skip to content

Commit

Permalink
Workspace loader (#8838)
Browse files Browse the repository at this point in the history
Adding workspace loader application.
  • Loading branch information
Vitaliy Guliy authored and ashumilova committed Mar 5, 2018
1 parent d39ca3e commit 3da13d5
Show file tree
Hide file tree
Showing 38 changed files with 2,285 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ maven-eclipse.xml
*.iws
.idea/

.vscode/

# Compiled source #
###################
!*.com/
Expand Down
5 changes: 5 additions & 0 deletions assembly/assembly-main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
<artifactId>assembly-ide-war</artifactId>
<type>war</type>
</dependency>
<dependency>
<groupId>org.eclipse.che</groupId>
<artifactId>assembly-workspace-loader-war</artifactId>
<type>war</type>
</dependency>
<dependency>
<groupId>org.eclipse.che</groupId>
<artifactId>assembly-wsagent-server</artifactId>
Expand Down
9 changes: 9 additions & 0 deletions assembly/assembly-main/src/assembly/assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@
<include>org.eclipse.che.dashboard:che-dashboard-war</include>
</includes>
</dependencySet>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<unpack>false</unpack>
<outputDirectory>tomcat/webapps</outputDirectory>
<outputFileNameMapping>workspace-loader.war</outputFileNameMapping>
<includes>
<include>org.eclipse.che:assembly-workspace-loader-war</include>
</includes>
</dependencySet>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<unpack>false</unpack>
Expand Down
72 changes: 72 additions & 0 deletions assembly/assembly-workspace-loader-war/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2018-2018 Red Hat, Inc.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
Contributors:
Red Hat, Inc. - initial API and implementation
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>che-assembly-parent</artifactId>
<groupId>org.eclipse.che</groupId>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>assembly-workspace-loader-war</artifactId>
<packaging>war</packaging>
<name>Che Workspace Loader :: War Packaging</name>
<description>Packages Che Workspace Loader application as a Java web app</description>
<inceptionYear>2018</inceptionYear>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.che.workspace.loader</groupId>
<artifactId>che-workspace-loader</artifactId>
<type>zip</type>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<overlays>
<overlay>
<groupId>org.eclipse.che.workspace.loader</groupId>
<artifactId>che-workspace-loader</artifactId>
<type>zip</type>
</overlay>
</overlays>
<packagingExcludes>/webapp/</packagingExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>analyze</id>
<configuration>
<ignoredUnusedDeclaredDependencies>
<!-- dependency is required just to overlay it's content -->
<dep>org.eclipse.che.workspace.loader:che-workspace-loader</dep>
</ignoredUnusedDeclaredDependencies>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2018-2018 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Defines a controller that is serving the index.html page of a workspace loader.
*
* @author Florent Benoit
*/
public class WSLoaderController extends HttpServlet {

/** Use the default dispatcher to serve the resource. */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

RequestDispatcher dispatcher = request.getRequestDispatcher("/loader/index.html");
dispatcher.forward(request, response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2018-2018 Red Hat, Inc.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
Contributors:
Red Hat, Inc. - initial API and implementation
-->
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0"
metadata-complete="true">
<absolute-ordering></absolute-ordering>

<servlet>
<servlet-name>WSLoader</servlet-name>
<servlet-class>org.eclipse.che.WSLoaderController</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>WSLoader</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/loader/*</url-pattern>
</servlet-mapping>

</web-app>
1 change: 1 addition & 0 deletions assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<module>assembly-wsagent-server</module>
<module>assembly-ide-war</module>
<module>assembly-wsmaster-war</module>
<module>assembly-workspace-loader-war</module>
<module>assembly-main</module>
</modules>
</project>
4 changes: 3 additions & 1 deletion dashboard/gulp/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var serverOptions = {

var options = minimist(process.argv.slice(2), serverOptions);

var patterns = ['/api', '/ext', '/ws', '/datasource', '/java-ca', '/im', '/che', '/admin'];
var patterns = ['/api', '/ext', '/ws', '/datasource', '/java-ca', '/im', '/che', '/admin', '/workspace-loader'];

var proxies = [];

Expand All @@ -36,6 +36,8 @@ patterns.forEach(function(pattern) {
proxyOptions.route = '/admin';
} else if (pattern === '/ext') {
proxyOptions.route = '/ext';
} else if (pattern === '/workspace-loader') {
proxyOptions.route = '/workspace-loader';
} else {
proxyOptions.route = '/api';
}
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/app/ide/ide.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ class IdeSvc {
let inDevMode = this.userDashboardConfig.developmentMode;
let randVal = Math.floor((Math.random() * 1000000) + 1);
let appendUrl = '?uid=' + randVal;

let workspace = this.cheWorkspace.getWorkspaceById(workspaceId);
this.openedWorkspace = workspace;

let ideUrlLink = workspace.links.ide;
let workspaceLoaderUrl = this.cheWorkspace.getWorkspaceLoaderUrl(workspace.namespace, workspace.config.name);
let ideUrlLink = workspaceLoaderUrl || workspace.links.ide;

if (this.ideAction != null) {
appendUrl = appendUrl + '&action=' + this.ideAction;
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/components/api/che-organizations.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ export class CheOrganization implements che.api.ICheOrganization {
return this.cheResourcesDistribution.fetchAvailableOrganizationResources(organization.id).then(() => {
let resource = this.cheResourcesDistribution.getOrganizationAvailableResourceByType(organization.id, this.resourceLimits.RAM);
if (resource.amount === -1) {
return 'RAM is not limited'
return 'RAM is not limited';
}

return resource ? 'Available RAM: ' + (resource.amount / 1024) + 'GB' : null;
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/components/api/test/che-http-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class CheHttpBackend {
this.$httpBackend.when('GET', '/api/').respond(200, {rootResources: []});

this.$httpBackend.when('GET', '/api/keycloak/settings').respond(404);
this.$httpBackend.when('GET', '/workspace-loader/').respond(404);

// add the remote call
let workspaceReturn = [];
Expand Down
20 changes: 20 additions & 0 deletions dashboard/src/components/api/workspace/che-workspace.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class CheWorkspace {
private statusDefers: Object;
private workspaceSettings: any;
private jsonRpcApiLocation: string;
private workspaceLoaderUrl: string;
/**
* Map with instance of Observable by workspaceId.
*/
Expand Down Expand Up @@ -164,6 +165,8 @@ export class CheWorkspace {
cheBranding.unregisterCallback(CONTEXT_FETCHER_ID);
};
cheBranding.registerCallback(CONTEXT_FETCHER_ID, callback.bind(this));

this.checkWorkspaceLoader(userDashboardConfig.developmentMode, proxySettings);
}

/**
Expand Down Expand Up @@ -648,6 +651,10 @@ export class CheWorkspace {
return '/ide/' + namespace + '/' + workspaceName;
}

getWorkspaceLoaderUrl(namespace: string, workspaceName: string): string {
return this.workspaceLoaderUrl ? this.workspaceLoaderUrl + namespace + '/' + workspaceName : null;
}

/**
* Creates deferred object which will be resolved
* when workspace change it's status to given
Expand Down Expand Up @@ -797,4 +804,17 @@ export class CheWorkspace {
}
return wsUrl;
}

private checkWorkspaceLoader(devmode: boolean, proxySettings: string): void {
let url = '/workspace-loader/';

let promise = this.$http.get(url);
promise.then((response: {data: any}) => {
this.workspaceLoaderUrl = devmode ? proxySettings + url : url;
}, (error: any) => {
if (error.status !== 304) {
this.workspaceLoaderUrl = null;
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@

script.onerror = script.onabort = function() {
console.error("Cannot load " + script.src);
Loader.startLoading();
};

document.head.appendChild(script);
Expand Down Expand Up @@ -135,10 +136,14 @@
* Show loader and load compilation-mapping.txt file to determine which IDE JavaScript file will be loaded
*/
this.startLoading = function() {
setTimeout(function() {
setTimeout(() => {
document.getElementById("ide-loader").style.opacity = 1;
}, 1);

setTimeout(() => {
window.parent.postMessage("show-ide", "*");
}, 250);

var msg = "Cannot load compilation mappings";

try {
Expand Down Expand Up @@ -362,9 +367,8 @@
};
};

setTimeout(function() {
setTimeout(() => {
Loader.loadKeycloakSettings();
window.parent.postMessage("show-ide", "*");
}, 1);

</script>
Expand Down
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<module>ide/che-ide-full</module>
<module>ide/che-ide-gwt-app</module>
<module>dashboard</module>
<module>workspace-loader</module>
<module>assembly</module>
<module>selenium</module>
</modules>
Expand Down Expand Up @@ -89,6 +90,12 @@
<artifactId>assembly-main</artifactId>
<version>${che.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.che</groupId>
<artifactId>assembly-workspace-loader-war</artifactId>
<version>${che.version}</version>
<type>war</type>
</dependency>
<dependency>
<groupId>org.eclipse.che</groupId>
<artifactId>assembly-wsagent-server</artifactId>
Expand Down Expand Up @@ -1876,6 +1883,12 @@
<artifactId>che-selenium-test</artifactId>
<version>${che.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.che.workspace.loader</groupId>
<artifactId>che-workspace-loader</artifactId>
<version>${che.version}</version>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-test</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions workspace-loader/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Dockerfile
node_modules
target
dist
package-lock.json
3 changes: 3 additions & 0 deletions workspace-loader/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
dist/
package-lock.json
24 changes: 24 additions & 0 deletions workspace-loader/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2018-2018 Red Hat, Inc
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html

# This is a Dockerfile allowing to build workspace loader by using a docker container.
# Build step: $ docker build -t eclipse-che-workspace-loader .
# It builds an archive file that can be used by doing later
# $ docker run --rm eclipse-che-workspace-loader | tar -C target/ -zxf -
FROM node:6.11.2

COPY package.json /workspace-loader/
RUN cd /workspace-loader && npm install

COPY . /workspace-loader/

RUN cd /workspace-loader && \
npm run build && \
npm run test && \
cd target && \
tar zcf /tmp/workspace-loader.tar.gz dist

CMD zcat /tmp/workspace-loader.tar.gz
Loading

0 comments on commit 3da13d5

Please sign in to comment.