Skip to content

Commit c608d13

Browse files
author
Vitaliy Guliy
committed
CHE-5231 Workspace Loading Sequence
1 parent 1e9e2eb commit c608d13

6 files changed

Lines changed: 146 additions & 193 deletions

File tree

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/ProcessesGinModule.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public class ProcessesGinModule extends AbstractGinModule {
3333
protected void configure() {
3434
bind(WorkspaceLoadingTracker.class).to(WorkspaceLoadingTrackerImpl.class).in(Singleton.class);
3535
bind(ProcessesPanelView.class).to(ProcessesPanelViewImpl.class).in(Singleton.class);
36-
bind(WorkspaceLoadingTrackerView.class).to(WorkspaceLoadingTrackerViewImpl.class).in(Singleton.class);
36+
bind(WorkspaceLoadingTrackerView.class)
37+
.to(WorkspaceLoadingTrackerViewImpl.class)
38+
.in(Singleton.class);
3739
install(new GinFactoryModuleBuilder().build(ConsoleTreeContextMenuFactory.class));
3840
install(new GinFactoryModuleBuilder().build(AddTabMenuFactory.class));
3941

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/loading/WorkspaceLoadingTracker.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,9 @@
1010
*/
1111
package org.eclipse.che.ide.processes.loading;
1212

13-
/**
14-
* Listens workspace events and outputs and visualizes the workspace loading process.
15-
*/
13+
/** Listens workspace events and outputs and visualizes the workspace loading process. */
1614
public interface WorkspaceLoadingTracker {
1715

18-
/**
19-
* Starts tracking of workspace loading.
20-
*/
16+
/** Starts tracking of workspace loading. */
2117
void startTracking();
22-
2318
}

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/loading/WorkspaceLoadingTrackerImpl.java

Lines changed: 53 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,35 @@
1010
*/
1111
package org.eclipse.che.ide.processes.loading;
1212

13-
import com.google.gwt.core.client.Scheduler;
14-
import com.google.gwt.user.client.Timer;
15-
import com.google.gwt.user.client.Window;
1613
import com.google.inject.Inject;
1714
import com.google.inject.Singleton;
1815
import com.google.web.bindery.event.shared.EventBus;
16+
import java.util.HashMap;
17+
import java.util.Map;
1918
import org.eclipse.che.api.core.model.workspace.WorkspaceStatus;
2019
import org.eclipse.che.ide.api.app.AppContext;
2120
import org.eclipse.che.ide.api.workspace.event.MachineRunningEvent;
2221
import org.eclipse.che.ide.api.workspace.event.MachineStartingEvent;
2322
import org.eclipse.che.ide.api.workspace.event.WorkspaceRunningEvent;
2423
import org.eclipse.che.ide.api.workspace.model.EnvironmentImpl;
2524
import org.eclipse.che.ide.api.workspace.model.MachineConfigImpl;
26-
import org.eclipse.che.ide.api.workspace.model.MachineImpl;
27-
import org.eclipse.che.ide.console.CommandConsoleFactory;
2825
import org.eclipse.che.ide.machine.MachineResources;
2926
import org.eclipse.che.ide.processes.panel.EnvironmentOutputEvent;
3027
import org.eclipse.che.ide.processes.panel.ProcessesPanelPresenter;
3128
import org.eclipse.che.ide.processes.panel.ProcessesPanelView;
3229

33-
import java.util.HashMap;
34-
import java.util.Map;
35-
36-
/**
37-
* Created by vetal on 9/29/17.
38-
*/
30+
/** Listens workspace events and outputs and visualizes the workspace loading process. */
3931
@Singleton
40-
public class WorkspaceLoadingTrackerImpl implements WorkspaceLoadingTracker, EnvironmentOutputEvent.Handler {
32+
public class WorkspaceLoadingTrackerImpl
33+
implements WorkspaceLoadingTracker, EnvironmentOutputEvent.Handler {
4134

35+
/** Part of a docker image. */
4236
private class Chunk {
4337
long size = 0;
4438
long downloaded = 0;
45-
boolean waiting = true;
4639
}
4740

41+
/** Docker image. */
4842
private class Image {
4943
private String machineName;
5044
private String sha256;
@@ -97,7 +91,6 @@ public boolean isDownloaded() {
9791

9892
private final WorkspaceLoadingTrackerView view;
9993

100-
//private Map<String, String> downloadProgress = new HashMap<>();
10194
private Map<String, Image> images = new HashMap<>();
10295

10396
@Inject
@@ -106,8 +99,7 @@ public WorkspaceLoadingTrackerImpl(
10699
EventBus eventBus,
107100
ProcessesPanelPresenter processesPanelPresenter,
108101
MachineResources resources,
109-
WorkspaceLoadingTrackerView view
110-
) {
102+
WorkspaceLoadingTrackerView view) {
111103

112104
this.appContext = appContext;
113105
this.eventBus = eventBus;
@@ -116,25 +108,30 @@ public WorkspaceLoadingTrackerImpl(
116108

117109
this.view = view;
118110

119-
eventBus.addHandler(WorkspaceRunningEvent.TYPE, new WorkspaceRunningEvent.Handler() {
120-
@Override
121-
public void onWorkspaceRunning(WorkspaceRunningEvent event) {
122-
onWorkspaceRunnning();
123-
}
124-
});
125-
126-
eventBus.addHandler(MachineStartingEvent.TYPE, new MachineStartingEvent.Handler() {
127-
@Override
128-
public void onMachineStarting(MachineStartingEvent event) {
129-
}
130-
});
131-
132-
eventBus.addHandler(MachineRunningEvent.TYPE, new MachineRunningEvent.Handler() {
133-
@Override
134-
public void onMachineRunning(MachineRunningEvent event) {
135-
view.setStartWorkspaceRuntimeRunning(event.getMachine().getName());
136-
}
137-
});
111+
eventBus.addHandler(
112+
WorkspaceRunningEvent.TYPE,
113+
new WorkspaceRunningEvent.Handler() {
114+
@Override
115+
public void onWorkspaceRunning(WorkspaceRunningEvent event) {
116+
onWorkspaceRunnning();
117+
}
118+
});
119+
120+
eventBus.addHandler(
121+
MachineStartingEvent.TYPE,
122+
new MachineStartingEvent.Handler() {
123+
@Override
124+
public void onMachineStarting(MachineStartingEvent event) {}
125+
});
126+
127+
eventBus.addHandler(
128+
MachineRunningEvent.TYPE,
129+
new MachineRunningEvent.Handler() {
130+
@Override
131+
public void onMachineRunning(MachineRunningEvent event) {
132+
view.setStartWorkspaceRuntimeRunning(event.getMachine().getName());
133+
}
134+
});
138135
}
139136

140137
private void onWorkspaceRunnning() {
@@ -143,54 +140,40 @@ private void onWorkspaceRunnning() {
143140
}
144141

145142
view.showStartingWorkspaceRuntimes();
146-
// view.showInitializingWorkspaceAgents();
147143
view.showWorkspaceStarted();
148144
}
149145

150-
// private void onWorkspaceAlreadyRunning() {
151-
// view.showWorkspaceIsAlreadyRunning();
152-
// }
153-
154-
private static native void log(String msg) /*-{ console.log(msg); }-*/;
155-
156146
@Override
157147
public void startTracking() {
158-
log(">> startTracking");
159-
160148
if (WorkspaceStatus.RUNNING == appContext.getWorkspace().getStatus()) {
161-
// onWorkspaceAlreadyRunning();
162149
return;
163150
}
164151

165152
view.showLoadingStarted();
166153

167154
String defaultEnvironmentName = appContext.getWorkspace().getConfig().getDefaultEnv();
168-
EnvironmentImpl defaultEnvironment = appContext.getWorkspace().getConfig().getEnvironments().get(defaultEnvironmentName);
155+
EnvironmentImpl defaultEnvironment =
156+
appContext.getWorkspace().getConfig().getEnvironments().get(defaultEnvironmentName);
169157

170158
Map<String, MachineConfigImpl> machines = defaultEnvironment.getMachines();
171159
for (final String machineName : machines.keySet()) {
172160
MachineConfigImpl machine = machines.get(machineName);
173-
log(">> machine " + machineName);
174-
175161
view.pullMachine(machineName);
176162

177-
//downloadProgress.put(machineName, "");
178163
images.put(machineName, new Image(machineName));
179164
}
180165

181166
eventBus.addHandler(EnvironmentOutputEvent.TYPE, this);
182-
((ProcessesPanelView)processesPanelPresenter.getView()).addWidget("*", "Workspace-start", resources.output(), view, true);
167+
((ProcessesPanelView) processesPanelPresenter.getView())
168+
.addWidget("*", "Workspace-start", resources.output(), view, true);
183169
}
184170

185171
@Override
186172
public void onEnvironmentOutput(EnvironmentOutputEvent event) {
187-
log(">> onEnvironmentOutput " + event.getMachineName() + " : " + event.getContent());
188-
189-
((ProcessesPanelView)processesPanelPresenter.getView()).showProcessOutput("*");
173+
((ProcessesPanelView) processesPanelPresenter.getView()).showProcessOutput("*");
190174

191175
Image machine = images.get(event.getMachineName());
192176
if (machine == null) {
193-
// TEMPORARY don't handle the machine if it is not exist
194177
return;
195178
}
196179

@@ -219,10 +202,6 @@ private void handleDockerOutput(Image machine, String text) {
219202
// [DOCKER] d010c8cf75d7: Waiting
220203
return;
221204

222-
// } else if (dockerWaitingPullingChunk(machine, text)) {
223-
// // [DOCKER] d010c8cf75d7: Waiting
224-
// return;
225-
226205
} else if (dockerChunkPullingProgress(machine, text)) {
227206
// [DOCKER] 9fb6c798fa41: Downloading 16.22 MB/47.54 MB
228207
// gives how much of chunk has been already downloaded
@@ -235,37 +214,31 @@ private void handleDockerOutput(Image machine, String text) {
235214
}
236215

237216
} catch (Exception e) {
238-
log("ERROR. Unable to parse docker output. " + e.getMessage());
239217
return;
240218
}
241-
242-
// [DOCKER] 6fabefc10853: Verifying Checksum
243-
// skip this
244219
}
245220

246221
/**
247-
* [DOCKER] sha256:40a6dd3c1f3af152d834e66fdf1dbca722dbc8ab4e98e157251c5179e8a6aa44: Pulling from docker.io/eclipse/ubuntu_jdk8
222+
* [DOCKER] sha256:40a6dd3c1f3af152d834e66fdf1dbca722dbc8ab4e98e157251c5179e8a6aa44: Pulling from
223+
* docker.io/eclipse/ubuntu_jdk8
248224
*
249225
* @param machine
250226
* @param text
251-
*
252227
* @return
253228
*/
254229
private boolean dockerPullingStarted(Image machine, String text) {
255230
if (!text.startsWith("[DOCKER] sha256:")) {
256231
return false;
257232
}
258233

259-
String []parts = text.split(":");
234+
String[] parts = text.split(":");
260235

261236
String sha256 = parts[1];
262-
log("SHA [" + sha256 + "]");
263237
machine.setSha256(sha256);
264238

265239
String dockerImage = parts[2];
266240
if (dockerImage.startsWith(" Pulling from ")) {
267241
dockerImage = dockerImage.substring(" Pulling from ".length()).trim();
268-
log("DOCKER IMAGE [" + dockerImage + "]");
269242
machine.setDockerImage(dockerImage);
270243
view.setMachineImage(machine.getMachineName(), dockerImage);
271244
}
@@ -285,44 +258,37 @@ private boolean dockerPullingFinished(Image machine, String text) {
285258
return false;
286259
}
287260

288-
String []parts = text.split(":");
289-
261+
String[] parts = text.split(":");
290262
String sha256 = parts[2].trim();
291-
log("SHA [" + sha256 + "]");
292263

293264
if (sha256.equals(machine.getSha256())) {
294265
machine.setDownloaded(true);
295266
view.setMachinePullingComplete(machine.getMachineName());
296-
} else {
297-
log("ERROR! Image sha256:" + sha256 + " not found!");
298267
}
299268

300269
view.showStartingWorkspaceRuntimes();
301-
302270
view.addStartWorkspaceRuntime(machine.getMachineName(), machine.getDockerImage());
303271

304272
return true;
305273
}
306274

307275
/**
308-
* [DOCKER] 6a447dcfe27d: Pulling fs layer
309-
* [DOCKER] d010c8cf75d7: Waiting
276+
* [DOCKER] 6a447dcfe27d: Pulling fs layer [DOCKER] d010c8cf75d7: Waiting
310277
*
311278
* @param machine
312279
* @param text
313280
* @return
314281
*/
315282
private boolean dockerPreparePullingChunk(Image machine, String text) {
316-
if (!(text.startsWith("[DOCKER] ") && (text.indexOf(": Pulling fs layer") > 0 || text.indexOf(": Waiting") > 0))) {
283+
if (!(text.startsWith("[DOCKER] ")
284+
&& (text.indexOf(": Pulling fs layer") > 0 || text.indexOf(": Waiting") > 0))) {
317285
return false;
318286
}
319287

320288
text = text.substring("[DOCKER] ".length());
321289

322-
String []parts = text.split(":");
323-
290+
String[] parts = text.split(":");
324291
String hash = parts[0];
325-
log(">> docker pulling progress HASH [" + hash + "]");
326292

327293
Chunk chunk = machine.getChunks().get(hash);
328294
if (chunk == null) {
@@ -348,13 +314,13 @@ private boolean dockerChunkPullingProgress(Image machine, String text) {
348314
text = text.substring("[DOCKER] ".length());
349315
// now text must be like `e7cfbd075aa8: Downloading 67.58 MB/244.3 MB`
350316

351-
String []parts = text.split(":");
317+
String[] parts = text.split(":");
352318

353319
String hash = parts[0];
354320
String value = parts[1].substring(" Downloading ".length());
355321
// now value must be like `67.58 MB/244.3 MB`
356322

357-
String []values = value.split("/");
323+
String[] values = value.split("/");
358324

359325
long downloaded = getSizeInBytes(values[0]);
360326
long size = getSizeInBytes(values[1]);
@@ -367,7 +333,6 @@ private boolean dockerChunkPullingProgress(Image machine, String text) {
367333

368334
chunk.downloaded = downloaded;
369335
chunk.size = size;
370-
chunk.waiting = false;
371336

372337
refreshMachineDownloadingProgress(machine);
373338

@@ -378,26 +343,18 @@ private void refreshMachineDownloadingProgress(Image machine) {
378343
long totalDownloaded = 0;
379344
long totalSize = 0;
380345

381-
int waitings = 0;
382-
383346
for (Chunk chunk : machine.chunks.values()) {
384-
if (chunk.waiting) {
385-
waitings++;
386-
}
387-
388347
totalSize += chunk.size;
389348
totalDownloaded += chunk.downloaded;
390349
}
391350

392-
double percents = Math.round(totalDownloaded * 100 / totalSize);
393-
view.setMachinePullingProgress(machine.getMachineName(), percents + "%");
351+
int percents = Math.round(totalDownloaded * 100 / totalSize);
352+
view.setMachinePullingProgress(machine.getMachineName(), percents);
394353
}
395354

396355
/**
397-
* `621 B` -> return 621
398-
* `490.8 kB` -> return 490.8 * 1024
399-
* `1.474 MB` -> return 1.474 * 1024 * 1024
400-
* `244.3 MB` -> return 244.3 * 1024 * 1024
356+
* `621 B` -> return 621 `490.8 kB` -> return 490.8 * 1024 `1.474 MB` -> return 1.474 * 1024 *
357+
* 1024 `244.3 MB` -> return 244.3 * 1024 * 1024
401358
*
402359
* @param value
403360
* @return
@@ -411,10 +368,10 @@ private long getSizeInBytes(String value) {
411368
size = Long.parseLong(value);
412369
} else if (value.endsWith(" KB")) {
413370
value = value.substring(0, value.length() - 3);
414-
size = (long)(Double.parseDouble(value) * 1024);
371+
size = (long) (Double.parseDouble(value) * 1024);
415372
} else if (value.endsWith(" MB")) {
416373
value = value.substring(0, value.length() - 3);
417-
size = (long)(Double.parseDouble(value) * 1024 * 1024);
374+
size = (long) (Double.parseDouble(value) * 1024 * 1024);
418375
}
419376

420377
return size;
@@ -430,5 +387,4 @@ private long getSizeInBytes(String value) {
430387
private boolean dockerChunkPullingCompleted(Image machine, String text) {
431388
return false;
432389
}
433-
434390
}

0 commit comments

Comments
 (0)