use of org.eclipse.che.plugin.docker.client.ProgressMonitor in project che by eclipse.
the class MachineProviderImpl method startService.
@Override
public Instance startService(String namespace, String workspaceId, String envName, String machineName, boolean isDev, String networkName, CheServiceImpl service, LineConsumer machineLogger) throws ServerException {
// copy to not affect/be affected by changes in origin
service = new CheServiceImpl(service);
ProgressLineFormatterImpl progressLineFormatter = new ProgressLineFormatterImpl();
ProgressMonitor progressMonitor = currentProgressStatus -> {
try {
machineLogger.writeLine(progressLineFormatter.format(currentProgressStatus));
} catch (IOException e) {
LOG.error(e.getLocalizedMessage(), e);
}
};
String container = null;
try {
String image = prepareImage(machineName, service, progressMonitor);
container = createContainer(workspaceId, machineName, isDev, image, networkName, service);
connectContainerToAdditionalNetworks(container, service);
docker.startContainer(StartContainerParams.create(container));
readContainerLogsInSeparateThread(container, workspaceId, service.getId(), machineLogger);
DockerNode node = dockerMachineFactory.createNode(workspaceId, container);
dockerInstanceStopDetector.startDetection(container, service.getId(), workspaceId);
final String userId = EnvironmentContext.getCurrent().getSubject().getUserId();
MachineImpl machine = new MachineImpl(MachineConfigImpl.builder().setDev(isDev).setName(machineName).setType("docker").setLimits(new MachineLimitsImpl((int) Size.parseSizeToMegabytes(service.getMemLimit() + "b"))).setSource(new MachineSourceImpl(service.getBuild() != null ? "context" : "image").setLocation(service.getBuild() != null ? service.getBuild().getContext() : service.getImage())).build(), service.getId(), workspaceId, envName, userId, MachineStatus.RUNNING, null);
return dockerMachineFactory.createInstance(machine, container, image, node, machineLogger);
} catch (SourceNotFoundException e) {
throw e;
} catch (RuntimeException | ServerException | NotFoundException | IOException e) {
cleanUpContainer(container);
throw new ServerException(e.getLocalizedMessage(), e);
}
}
Aggregations