use of org.eclipse.che.api.core.ApiException in project che by eclipse.
the class SubversionApi method listTags.
/**
* Returns list of the tags of the project.
*
* @param request
* the request
*
* @see #list(ListRequest)
* @see #info(InfoRequest)
*/
public ListResponse listTags(final ListRequest request) throws ApiException {
InfoResponse info = info(newDto(InfoRequest.class).withProjectPath(request.getProjectPath()).withTarget(".").withPassword(request.getPassword()).withUsername(request.getUsername()));
final List<String> args = defaultArgs();
args.add("list");
String repositoryRoot = getRepositoryRoot(info.getOutput());
String projectRelativeUrl = getRelativeUrl(info.getOutput());
String projectUri = recognizeProjectUri(repositoryRoot, projectRelativeUrl);
String branchesPath = projectUri == null ? "^/tags" : (projectUri + "/tags");
final CommandLineResult result = runCommand(null, args, new File(request.getProjectPath()), singletonList(branchesPath), request.getUsername(), request.getPassword());
return newDto(ListResponse.class).withCommand(result.getCommandLine().toString()).withOutput(result.getStdout().stream().filter(s -> s.endsWith("/")).map(s -> s.substring(0, s.length() - 1)).collect(Collectors.toList())).withErrorOutput(result.getStderr());
}
use of org.eclipse.che.api.core.ApiException in project che by eclipse.
the class SubversionApi method listBranches.
/**
* Returns list of the branches of the project.
*
* @param request
* the request
*
* @see #list(ListRequest)
* @see #info(InfoRequest)
*/
public ListResponse listBranches(final ListRequest request) throws ApiException {
InfoResponse info = info(newDto(InfoRequest.class).withProjectPath(request.getProjectPath()).withTarget(".").withPassword(request.getPassword()).withUsername(request.getUsername()));
final List<String> args = defaultArgs();
args.add("list");
String repositoryRoot = getRepositoryRoot(info.getOutput());
String projectRelativeUrl = getRelativeUrl(info.getOutput());
String projectUri = recognizeProjectUri(repositoryRoot, projectRelativeUrl);
String path = projectUri == null ? "^/branches" : (projectUri + "/branches");
final CommandLineResult result = runCommand(null, args, new File(request.getProjectPath()), singletonList(path), request.getUsername(), request.getPassword());
return newDto(ListResponse.class).withCommand(result.getCommandLine().toString()).withOutput(result.getStdout().stream().filter(s -> s.endsWith("/")).map(s -> s.substring(0, s.length() - 1)).collect(Collectors.toList())).withErrorOutput(result.getStderr());
}
use of org.eclipse.che.api.core.ApiException in project che by eclipse.
the class ApiEndpointAccessibilityChecker method start.
@PostConstruct
public void start() {
try {
final HttpJsonResponse pingResponse = httpJsonRequestFactory.fromUrl(apiEndpoint).setMethod(HttpMethod.GET).setTimeout(2000).request();
if (pingResponse.getResponseCode() == HttpURLConnection.HTTP_OK) {
return;
}
} catch (ApiException | IOException e) {
LOG.error(e.getLocalizedMessage(), e);
}
LOG.error("The workspace agent has attempted to start, but it is unable to ping the Che server at " + apiEndpoint);
LOG.error("The workspace agent has been forcefully stopped. " + "This error happens when the agent cannot resolve the location of the Che server. " + "This error can usually be fixed with additional configuration settings in /conf/che.properties. " + "The Che server will stop this workspace after a short timeout. " + "You can get help by posting your config, stacktrace and workspace /etc/hosts below as a GitHub issue.");
// content of /etc/hosts file may provide clues on why the connection failed, e.g. how che-host is resolved
try {
LOG.info("Workspace /etc/hosts: " + IoUtil.readAndCloseQuietly(new FileInputStream(new File("/etc/hosts"))));
} catch (Exception e) {
LOG.info(e.getLocalizedMessage(), e);
}
System.exit(0);
}
use of org.eclipse.che.api.core.ApiException in project che by eclipse.
the class CheEnvironmentEngine method startInstance.
private Instance startInstance(boolean recover, MessageConsumer<MachineLogMessage> environmentLogger, MachineImpl machine, MachineStarter machineStarter) throws ServerException, EnvironmentException {
LineConsumer machineLogger = null;
Instance instance = null;
try {
addMachine(machine);
eventService.publish(newDto(MachineStatusEvent.class).withEventType(MachineStatusEvent.EventType.CREATING).withDev(machine.getConfig().isDev()).withMachineName(machine.getConfig().getName()).withMachineId(machine.getId()).withWorkspaceId(machine.getWorkspaceId()));
machineLogger = getMachineLogger(environmentLogger, machine.getId(), machine.getConfig().getName());
MachineImpl originMachine = new MachineImpl(machine);
try {
MachineSourceImpl machineSource = null;
if (recover) {
try {
SnapshotImpl snapshot = snapshotDao.getSnapshot(machine.getWorkspaceId(), machine.getEnvName(), machine.getConfig().getName());
machineSource = snapshot.getMachineSource();
// Snapshot image location has SHA-256 digest which needs to be removed,
// otherwise it will be pulled without tag and cause problems
String imageName = machineSource.getLocation();
if (imageName.contains("@sha256:")) {
machineSource.setLocation(imageName.substring(0, imageName.indexOf('@')));
}
} catch (NotFoundException e) {
try {
machineLogger.writeLine("Failed to boot machine from snapshot: snapshot not found. " + "Machine will be created from origin source.");
} catch (IOException ignore) {
}
}
}
instance = machineStarter.startMachine(machineLogger, machineSource);
} catch (SourceNotFoundException e) {
if (recover) {
LOG.error("Image of snapshot for machine " + machine.getConfig().getName() + " not found. " + "Machine will be created from origin source.");
machine = originMachine;
instance = machineStarter.startMachine(machineLogger, null);
} else {
throw e;
}
}
replaceMachine(instance);
eventService.publish(newDto(MachineStatusEvent.class).withEventType(MachineStatusEvent.EventType.RUNNING).withDev(machine.getConfig().isDev()).withMachineName(machine.getConfig().getName()).withMachineId(instance.getId()).withWorkspaceId(machine.getWorkspaceId()));
return instance;
} catch (ApiException | RuntimeException e) {
boolean interrupted = Thread.interrupted();
removeMachine(machine.getWorkspaceId(), machine.getId());
if (instance != null) {
try {
instance.destroy();
} catch (Exception destroyingExc) {
LOG.error(destroyingExc.getLocalizedMessage(), destroyingExc);
}
}
if (machineLogger != null) {
try {
machineLogger.writeLine("[ERROR] " + e.getLocalizedMessage());
} catch (IOException ioEx) {
LOG.error(ioEx.getLocalizedMessage(), ioEx);
}
try {
machineLogger.close();
} catch (IOException ioEx) {
LOG.error(ioEx.getLocalizedMessage(), ioEx);
}
}
eventService.publish(newDto(MachineStatusEvent.class).withEventType(MachineStatusEvent.EventType.ERROR).withDev(machine.getConfig().isDev()).withMachineName(machine.getConfig().getName()).withMachineId(machine.getId()).withWorkspaceId(machine.getWorkspaceId()));
if (interrupted) {
Thread.currentThread().interrupt();
}
throw new ServerException(e.getLocalizedMessage(), e);
}
}
use of org.eclipse.che.api.core.ApiException in project che by eclipse.
the class LocalGitUserResolver method getUser.
@Override
public GitUser getUser() {
String name = null;
String email = null;
try {
Map<String, String> preferences = requestFactory.fromUrl(apiUrl + "/preferences").useGetMethod().addQueryParam("filter", "git.committer.\\w+").request().asProperties();
name = preferences.get("git.committer.name");
email = preferences.get("git.committer.email");
} catch (ApiException | IOException e) {
LOG.error(e.getLocalizedMessage(), e);
}
GitUser gitUser = newDto(GitUser.class);
if (!isNullOrEmpty(name)) {
gitUser.setName(name);
}
if (!isNullOrEmpty(email)) {
gitUser.setEmail(email);
}
return gitUser;
}
Aggregations