Search in sources :

Example 1 with ApiException

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());
}
Also used : CheckoutRequest(org.eclipse.che.plugin.svn.shared.CheckoutRequest) PropertySetRequest(org.eclipse.che.plugin.svn.shared.PropertySetRequest) UpdateRequest(org.eclipse.che.plugin.svn.shared.UpdateRequest) Arrays(java.util.Arrays) LineConsumerFactory(org.eclipse.che.api.core.util.LineConsumerFactory) InfoRequest(org.eclipse.che.plugin.svn.shared.InfoRequest) PropertyGetRequest(org.eclipse.che.plugin.svn.shared.PropertyGetRequest) ListResponse(org.eclipse.che.plugin.svn.shared.ListResponse) Date(java.util.Date) CopyRequest(org.eclipse.che.plugin.svn.shared.CopyRequest) LoggerFactory(org.slf4j.LoggerFactory) RemoveRequest(org.eclipse.che.plugin.svn.shared.RemoveRequest) CLIOutputResponse(org.eclipse.che.plugin.svn.shared.CLIOutputResponse) Collections.singletonList(java.util.Collections.singletonList) SubversionUtils(org.eclipse.che.plugin.svn.server.utils.SubversionUtils) ZipUtils(org.eclipse.che.commons.lang.ZipUtils) ListRequest(org.eclipse.che.plugin.svn.shared.ListRequest) CleanupRequest(org.eclipse.che.plugin.svn.shared.CleanupRequest) Map(java.util.Map) CommitRequest(org.eclipse.che.plugin.svn.shared.CommitRequest) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) Path(java.nio.file.Path) PropertyDeleteRequest(org.eclipse.che.plugin.svn.shared.PropertyDeleteRequest) RepositoryUrlProvider(org.eclipse.che.plugin.svn.server.repository.RepositoryUrlProvider) ResolveRequest(org.eclipse.che.plugin.svn.shared.ResolveRequest) SwitchRequest(org.eclipse.che.plugin.svn.shared.SwitchRequest) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Nullable(org.eclipse.che.commons.annotation.Nullable) IoUtil(org.eclipse.che.commons.lang.IoUtil) SshScriptProvider(org.eclipse.che.plugin.ssh.key.script.SshScriptProvider) List(java.util.List) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) Predicate(com.google.common.base.Predicate) MergeRequest(org.eclipse.che.plugin.svn.shared.MergeRequest) InfoUtils.getRelativeUrl(org.eclipse.che.plugin.svn.server.utils.InfoUtils.getRelativeUrl) ShowLogRequest(org.eclipse.che.plugin.svn.shared.ShowLogRequest) InfoResponse(org.eclipse.che.plugin.svn.shared.InfoResponse) CommandLineResult(org.eclipse.che.plugin.svn.server.upstream.CommandLineResult) SubversionItem(org.eclipse.che.plugin.svn.shared.SubversionItem) Singleton(com.google.inject.Singleton) SubversionUtils.recognizeProjectUri(org.eclipse.che.plugin.svn.server.utils.SubversionUtils.recognizeProjectUri) Iterables(com.google.common.collect.Iterables) LockRequest(org.eclipse.che.plugin.svn.shared.LockRequest) CLIOutputResponseList(org.eclipse.che.plugin.svn.shared.CLIOutputResponseList) GetRevisionsRequest(org.eclipse.che.plugin.svn.shared.GetRevisionsRequest) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) HashMap(java.util.HashMap) CLIOutputWithRevisionResponse(org.eclipse.che.plugin.svn.shared.CLIOutputWithRevisionResponse) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ApiException(org.eclipse.che.api.core.ApiException) Files(com.google.common.io.Files) SshEnvironment(org.eclipse.che.plugin.svn.server.utils.SshEnvironment) InfoUtils.getRepositoryRoot(org.eclipse.che.plugin.svn.server.utils.InfoUtils.getRepositoryRoot) DtoFactory(org.eclipse.che.dto.server.DtoFactory) MediaType(com.google.common.net.MediaType) GetRevisionsResponse(org.eclipse.che.plugin.svn.shared.GetRevisionsResponse) Logger(org.slf4j.Logger) ErrorCodes(org.eclipse.che.api.core.ErrorCodes) Iterator(java.util.Iterator) IOException(java.io.IOException) StatusRequest(org.eclipse.che.plugin.svn.shared.StatusRequest) File(java.io.File) InfoUtils(org.eclipse.che.plugin.svn.server.utils.InfoUtils) PropertyListRequest(org.eclipse.che.plugin.svn.shared.PropertyListRequest) ShowDiffRequest(org.eclipse.che.plugin.svn.shared.ShowDiffRequest) ServerException(org.eclipse.che.api.core.ServerException) UpstreamUtils(org.eclipse.che.plugin.svn.server.upstream.UpstreamUtils) AddRequest(org.eclipse.che.plugin.svn.shared.AddRequest) RevertRequest(org.eclipse.che.plugin.svn.shared.RevertRequest) DeleteOnCloseFileInputStream(org.eclipse.che.api.vfs.util.DeleteOnCloseFileInputStream) MoveRequest(org.eclipse.che.plugin.svn.shared.MoveRequest) InfoResponse(org.eclipse.che.plugin.svn.shared.InfoResponse) InfoRequest(org.eclipse.che.plugin.svn.shared.InfoRequest) CommandLineResult(org.eclipse.che.plugin.svn.server.upstream.CommandLineResult) ListResponse(org.eclipse.che.plugin.svn.shared.ListResponse) File(java.io.File)

Example 2 with ApiException

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());
}
Also used : CheckoutRequest(org.eclipse.che.plugin.svn.shared.CheckoutRequest) PropertySetRequest(org.eclipse.che.plugin.svn.shared.PropertySetRequest) UpdateRequest(org.eclipse.che.plugin.svn.shared.UpdateRequest) Arrays(java.util.Arrays) LineConsumerFactory(org.eclipse.che.api.core.util.LineConsumerFactory) InfoRequest(org.eclipse.che.plugin.svn.shared.InfoRequest) PropertyGetRequest(org.eclipse.che.plugin.svn.shared.PropertyGetRequest) ListResponse(org.eclipse.che.plugin.svn.shared.ListResponse) Date(java.util.Date) CopyRequest(org.eclipse.che.plugin.svn.shared.CopyRequest) LoggerFactory(org.slf4j.LoggerFactory) RemoveRequest(org.eclipse.che.plugin.svn.shared.RemoveRequest) CLIOutputResponse(org.eclipse.che.plugin.svn.shared.CLIOutputResponse) Collections.singletonList(java.util.Collections.singletonList) SubversionUtils(org.eclipse.che.plugin.svn.server.utils.SubversionUtils) ZipUtils(org.eclipse.che.commons.lang.ZipUtils) ListRequest(org.eclipse.che.plugin.svn.shared.ListRequest) CleanupRequest(org.eclipse.che.plugin.svn.shared.CleanupRequest) Map(java.util.Map) CommitRequest(org.eclipse.che.plugin.svn.shared.CommitRequest) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) Path(java.nio.file.Path) PropertyDeleteRequest(org.eclipse.che.plugin.svn.shared.PropertyDeleteRequest) RepositoryUrlProvider(org.eclipse.che.plugin.svn.server.repository.RepositoryUrlProvider) ResolveRequest(org.eclipse.che.plugin.svn.shared.ResolveRequest) SwitchRequest(org.eclipse.che.plugin.svn.shared.SwitchRequest) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Nullable(org.eclipse.che.commons.annotation.Nullable) IoUtil(org.eclipse.che.commons.lang.IoUtil) SshScriptProvider(org.eclipse.che.plugin.ssh.key.script.SshScriptProvider) List(java.util.List) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) Predicate(com.google.common.base.Predicate) MergeRequest(org.eclipse.che.plugin.svn.shared.MergeRequest) InfoUtils.getRelativeUrl(org.eclipse.che.plugin.svn.server.utils.InfoUtils.getRelativeUrl) ShowLogRequest(org.eclipse.che.plugin.svn.shared.ShowLogRequest) InfoResponse(org.eclipse.che.plugin.svn.shared.InfoResponse) CommandLineResult(org.eclipse.che.plugin.svn.server.upstream.CommandLineResult) SubversionItem(org.eclipse.che.plugin.svn.shared.SubversionItem) Singleton(com.google.inject.Singleton) SubversionUtils.recognizeProjectUri(org.eclipse.che.plugin.svn.server.utils.SubversionUtils.recognizeProjectUri) Iterables(com.google.common.collect.Iterables) LockRequest(org.eclipse.che.plugin.svn.shared.LockRequest) CLIOutputResponseList(org.eclipse.che.plugin.svn.shared.CLIOutputResponseList) GetRevisionsRequest(org.eclipse.che.plugin.svn.shared.GetRevisionsRequest) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) HashMap(java.util.HashMap) CLIOutputWithRevisionResponse(org.eclipse.che.plugin.svn.shared.CLIOutputWithRevisionResponse) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ApiException(org.eclipse.che.api.core.ApiException) Files(com.google.common.io.Files) SshEnvironment(org.eclipse.che.plugin.svn.server.utils.SshEnvironment) InfoUtils.getRepositoryRoot(org.eclipse.che.plugin.svn.server.utils.InfoUtils.getRepositoryRoot) DtoFactory(org.eclipse.che.dto.server.DtoFactory) MediaType(com.google.common.net.MediaType) GetRevisionsResponse(org.eclipse.che.plugin.svn.shared.GetRevisionsResponse) Logger(org.slf4j.Logger) ErrorCodes(org.eclipse.che.api.core.ErrorCodes) Iterator(java.util.Iterator) IOException(java.io.IOException) StatusRequest(org.eclipse.che.plugin.svn.shared.StatusRequest) File(java.io.File) InfoUtils(org.eclipse.che.plugin.svn.server.utils.InfoUtils) PropertyListRequest(org.eclipse.che.plugin.svn.shared.PropertyListRequest) ShowDiffRequest(org.eclipse.che.plugin.svn.shared.ShowDiffRequest) ServerException(org.eclipse.che.api.core.ServerException) UpstreamUtils(org.eclipse.che.plugin.svn.server.upstream.UpstreamUtils) AddRequest(org.eclipse.che.plugin.svn.shared.AddRequest) RevertRequest(org.eclipse.che.plugin.svn.shared.RevertRequest) DeleteOnCloseFileInputStream(org.eclipse.che.api.vfs.util.DeleteOnCloseFileInputStream) MoveRequest(org.eclipse.che.plugin.svn.shared.MoveRequest) InfoResponse(org.eclipse.che.plugin.svn.shared.InfoResponse) InfoRequest(org.eclipse.che.plugin.svn.shared.InfoRequest) CommandLineResult(org.eclipse.che.plugin.svn.server.upstream.CommandLineResult) ListResponse(org.eclipse.che.plugin.svn.shared.ListResponse) File(java.io.File)

Example 3 with ApiException

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);
}
Also used : IOException(java.io.IOException) HttpJsonResponse(org.eclipse.che.api.core.rest.HttpJsonResponse) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) ApiException(org.eclipse.che.api.core.ApiException) ApiException(org.eclipse.che.api.core.ApiException) PostConstruct(javax.annotation.PostConstruct)

Example 4 with ApiException

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);
    }
}
Also used : SourceNotFoundException(org.eclipse.che.api.machine.server.exception.SourceNotFoundException) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) MachineImpl(org.eclipse.che.api.machine.server.model.impl.MachineImpl) MachineStatusEvent(org.eclipse.che.api.machine.shared.dto.event.MachineStatusEvent) ServerException(org.eclipse.che.api.core.ServerException) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) Instance(org.eclipse.che.api.machine.server.spi.Instance) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) SourceNotFoundException(org.eclipse.che.api.machine.server.exception.SourceNotFoundException) NotFoundException(org.eclipse.che.api.core.NotFoundException) IOException(java.io.IOException) AgentException(org.eclipse.che.api.agent.server.exception.AgentException) EnvironmentStartInterruptedException(org.eclipse.che.api.environment.server.exception.EnvironmentStartInterruptedException) EnvironmentNotRunningException(org.eclipse.che.api.environment.server.exception.EnvironmentNotRunningException) SourceNotFoundException(org.eclipse.che.api.machine.server.exception.SourceNotFoundException) EnvironmentException(org.eclipse.che.api.environment.server.exception.EnvironmentException) ApiException(org.eclipse.che.api.core.ApiException) ConflictException(org.eclipse.che.api.core.ConflictException) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) IOException(java.io.IOException) NotFoundException(org.eclipse.che.api.core.NotFoundException) ServerException(org.eclipse.che.api.core.ServerException) ConcurrentCompositeLineConsumer(org.eclipse.che.api.core.util.lineconsumer.ConcurrentCompositeLineConsumer) ConcurrentFileLineConsumer(org.eclipse.che.api.core.util.lineconsumer.ConcurrentFileLineConsumer) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) AbstractLineConsumer(org.eclipse.che.api.core.util.AbstractLineConsumer) ApiException(org.eclipse.che.api.core.ApiException)

Example 5 with ApiException

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;
}
Also used : IOException(java.io.IOException) ApiException(org.eclipse.che.api.core.ApiException) GitUser(org.eclipse.che.api.git.shared.GitUser)

Aggregations

IOException (java.io.IOException)10 ApiException (org.eclipse.che.api.core.ApiException)10 ServerException (org.eclipse.che.api.core.ServerException)7 UriBuilder (javax.ws.rs.core.UriBuilder)4 WorkspaceService (org.eclipse.che.api.workspace.server.WorkspaceService)4 File (java.io.File)3 Predicate (com.google.common.base.Predicate)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)2 Iterables (com.google.common.collect.Iterables)2 Files (com.google.common.io.Files)2 MediaType (com.google.common.net.MediaType)2 Singleton (com.google.inject.Singleton)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections.singletonList (java.util.Collections.singletonList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 List (java.util.List)2