Search in sources :

Example 51 with NotFoundException

use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.

the class SshKeyProviderImpl method getPrivateKey.

/**
     * Get private ssh key and upload public ssh key to repository hosting service.
     *
     * @param url
     *         url to the repository
     * @return private ssh key
     * @throws ServerException
     *         if an error occurs while generating or uploading keys
     */
@Override
public byte[] getPrivateKey(String url) throws ServerException {
    String host = UrlUtils.getHost(url);
    SshPair pair;
    try {
        pair = sshService.getPair("vcs", host);
    } catch (ServerException | NotFoundException e) {
        throw new ServerException(DtoFactory.newDto(ExtendedError.class).withMessage("Unable get private ssh key").withErrorCode(ErrorCodes.UNABLE_GET_PRIVATE_SSH_KEY));
    }
    // check keys existence
    String privateKey = pair.getPrivateKey();
    if (privateKey == null) {
        throw new ServerException(DtoFactory.newDto(ExtendedError.class).withMessage("Unable get private ssh key").withErrorCode(ErrorCodes.UNABLE_GET_PRIVATE_SSH_KEY));
    }
    final String publicKey = pair.getPublicKey();
    if (publicKey != null) {
        final Optional<SshKeyUploader> optionalKeyUploader = sshKeyUploaders.stream().filter(keyUploader -> keyUploader.match(url)).findFirst();
        if (optionalKeyUploader.isPresent()) {
            final SshKeyUploader uploader = optionalKeyUploader.get();
            try {
                uploader.uploadKey(publicKey);
            } catch (IOException e) {
                throw new ServerException(e.getMessage(), e);
            } catch (UnauthorizedException e) {
                // action might fail without uploaded public SSH key.
                LOG.warn(String.format("Unable upload public SSH key with %s", uploader.getClass().getSimpleName()), e);
            }
        } else {
            // action might fail without uploaded public SSH key.
            LOG.warn(String.format("Not found ssh key uploader for %s", host));
        }
    }
    return privateKey.getBytes();
}
Also used : Logger(org.slf4j.Logger) ErrorCodes(org.eclipse.che.api.core.ErrorCodes) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) IOException(java.io.IOException) NotFoundException(org.eclipse.che.api.core.NotFoundException) UrlUtils(org.eclipse.che.plugin.ssh.key.utils.UrlUtils) SshPair(org.eclipse.che.api.ssh.shared.model.SshPair) ServerException(org.eclipse.che.api.core.ServerException) Optional(java.util.Optional) SshServiceClient(org.eclipse.che.plugin.ssh.key.SshServiceClient) ExtendedError(org.eclipse.che.api.core.rest.shared.dto.ExtendedError) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) DtoFactory(org.eclipse.che.dto.server.DtoFactory) SshPair(org.eclipse.che.api.ssh.shared.model.SshPair) ServerException(org.eclipse.che.api.core.ServerException) ExtendedError(org.eclipse.che.api.core.rest.shared.dto.ExtendedError) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) NotFoundException(org.eclipse.che.api.core.NotFoundException) IOException(java.io.IOException)

Example 52 with NotFoundException

use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.

the class WorkspaceManagerTest method getWorkspaceShouldThrowNotFoundExceptionWhenWorkspaceDoesNotExist.

@Test(expectedExceptions = NotFoundException.class)
public void getWorkspaceShouldThrowNotFoundExceptionWhenWorkspaceDoesNotExist() throws Exception {
    when(workspaceDao.get(any())).thenThrow(new NotFoundException("not found"));
    workspaceManager.getWorkspace("workspace123");
}
Also used : NotFoundException(org.eclipse.che.api.core.NotFoundException) Test(org.testng.annotations.Test)

Example 53 with NotFoundException

use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.

the class WsAgentLauncherTest method shouldThrowMachineExceptionIfMachineManagerExecInDevMachineThrowsNotFoundException.

@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Test exception")
public void shouldThrowMachineExceptionIfMachineManagerExecInDevMachineThrowsNotFoundException() throws Exception {
    Mockito.when(machineProcessManager.exec(Matchers.anyString(), Matchers.anyString(), Matchers.any(Command.class), Matchers.anyString())).thenThrow(new NotFoundException("Test exception"));
    wsAgentLauncher.launch(machine, agent);
    Mockito.verify(machineProcessManager).exec(Matchers.anyString(), Matchers.anyString(), Matchers.any(Command.class), Matchers.anyString());
}
Also used : Command(org.eclipse.che.api.core.model.machine.Command) NotFoundException(org.eclipse.che.api.core.NotFoundException) Test(org.testng.annotations.Test)

Example 54 with NotFoundException

use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.

the class Workspace method standardMoveFolder.

public void standardMoveFolder(IFolder folder, IFolder destination, int updateFlags, IProgressMonitor monitor) throws CoreException {
    VirtualFileEntry child = null;
    try {
        child = getProjectsRoot().getChild(folder.getFullPath().toOSString());
        projectManager.get().moveTo(child.getPath().toString(), destination.getFullPath().removeLastSegments(1).toOSString(), destination.getName(), true);
    } catch (ForbiddenException | NotFoundException | ServerException | ConflictException e) {
        throw new CoreException(new Status(IStatus.ERROR, "", "Can't move folder: " + folder.getFullPath() + " to: " + destination.getFullPath(), e));
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IResourceStatus(org.eclipse.core.resources.IResourceStatus) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) CoreException(org.eclipse.core.runtime.CoreException) ConflictException(org.eclipse.che.api.core.ConflictException) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) NotFoundException(org.eclipse.che.api.core.NotFoundException)

Example 55 with NotFoundException

use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.

the class Workspace method standardMoveFile.

public void standardMoveFile(IFile file, IFile destination, int updateFlags, IProgressMonitor monitor) throws CoreException {
    VirtualFileEntry child = null;
    try {
        child = getProjectsRoot().getChild(file.getFullPath().toOSString());
        projectManager.get().moveTo(child.getPath().toString(), destination.getFullPath().removeLastSegments(1).toOSString(), destination.getName(), true);
    } catch (ForbiddenException | ServerException | NotFoundException | ConflictException e) {
        throw new CoreException(new Status(IStatus.ERROR, "", "Can't move file: " + file.getFullPath() + " to: " + destination.getFullPath(), e));
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IResourceStatus(org.eclipse.core.resources.IResourceStatus) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) CoreException(org.eclipse.core.runtime.CoreException) ConflictException(org.eclipse.che.api.core.ConflictException) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) NotFoundException(org.eclipse.che.api.core.NotFoundException)

Aggregations

NotFoundException (org.eclipse.che.api.core.NotFoundException)72 ServerException (org.eclipse.che.api.core.ServerException)29 ConflictException (org.eclipse.che.api.core.ConflictException)19 Transactional (com.google.inject.persist.Transactional)16 IOException (java.io.IOException)13 EntityManager (javax.persistence.EntityManager)13 Path (javax.ws.rs.Path)13 Test (org.testng.annotations.Test)12 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)11 Produces (javax.ws.rs.Produces)10 ApiOperation (io.swagger.annotations.ApiOperation)9 ApiResponses (io.swagger.annotations.ApiResponses)9 ArrayList (java.util.ArrayList)9 BadRequestException (org.eclipse.che.api.core.BadRequestException)9 Instance (org.eclipse.che.api.machine.server.spi.Instance)9 GET (javax.ws.rs.GET)7 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)7 SourceNotFoundException (org.eclipse.che.api.machine.server.exception.SourceNotFoundException)6 MachineImpl (org.eclipse.che.api.machine.server.model.impl.MachineImpl)6 SnapshotImpl (org.eclipse.che.api.machine.server.model.impl.SnapshotImpl)6