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();
}
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");
}
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());
}
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));
}
}
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));
}
}
Aggregations