Search in sources :

Example 26 with NotFoundException

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

the class JpaStackDao method doUpdate.

@Transactional
protected StackImpl doUpdate(StackImpl update) throws NotFoundException {
    final EntityManager manager = managerProvider.get();
    if (manager.find(StackImpl.class, update.getId()) == null) {
        throw new NotFoundException(format("Workspace with id '%s' doesn't exist", update.getId()));
    }
    if (update.getWorkspaceConfig() != null) {
        update.getWorkspaceConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes);
    }
    StackImpl merged = manager.merge(update);
    manager.flush();
    return merged;
}
Also used : EntityManager(javax.persistence.EntityManager) StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) Transactional(com.google.inject.persist.Transactional)

Example 27 with NotFoundException

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

the class JpaWorkspaceDao method get.

@Override
@Transactional
public WorkspaceImpl get(String name, String namespace) throws NotFoundException, ServerException {
    requireNonNull(name, "Required non-null name");
    requireNonNull(namespace, "Required non-null namespace");
    try {
        return new WorkspaceImpl(managerProvider.get().createNamedQuery("Workspace.getByName", WorkspaceImpl.class).setParameter("namespace", namespace).setParameter("name", name).getSingleResult());
    } catch (NoResultException noResEx) {
        throw new NotFoundException(format("Workspace with name '%s' in namespace '%s' doesn't exist", name, namespace));
    } catch (RuntimeException x) {
        throw new ServerException(x.getLocalizedMessage(), x);
    }
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ServerException(org.eclipse.che.api.core.ServerException) NotFoundException(org.eclipse.che.api.core.NotFoundException) NoResultException(javax.persistence.NoResultException) Transactional(com.google.inject.persist.Transactional)

Example 28 with NotFoundException

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

the class CheEnvironmentEngineTest method shouldBeAbleToStartEnvironmentWhenRecoverFailed.

@Test
public void shouldBeAbleToStartEnvironmentWhenRecoverFailed() throws Exception {
    // given
    String machineImage = "che/ubuntu_jdk";
    when(snapshotDao.getSnapshot(anyString(), anyString(), anyString())).thenThrow(new NotFoundException("Snapshot not found"));
    EnvironmentImpl env = createEnv();
    String envName = "env-1";
    String workspaceId = "wsId";
    List<Instance> expectedMachines = new ArrayList<>();
    when(machineProvider.startService(anyString(), eq(workspaceId), eq(envName), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenAnswer(invocationOnMock -> {
        Object[] arguments = invocationOnMock.getArguments();
        String machineName = (String) arguments[3];
        boolean isDev = (boolean) arguments[4];
        CheServiceImpl service = (CheServiceImpl) arguments[6];
        Machine machine = createMachine(workspaceId, envName, service, machineName, isDev);
        NoOpMachineInstance instance = spy(new NoOpMachineInstance(machine));
        expectedMachines.add(instance);
        return instance;
    });
    CheServicesEnvironmentImpl servicesEnvironment = createCheServicesEnv();
    for (CheServiceImpl service : servicesEnvironment.getServices().values()) {
        service.setImage(machineImage);
    }
    when(environmentParser.parse(env)).thenReturn(servicesEnvironment);
    // when
    List<Instance> machines = engine.start(workspaceId, envName, env, true, messageConsumer);
    // then
    assertEquals(machines, expectedMachines);
    ArgumentCaptor<CheServiceImpl> captor = ArgumentCaptor.forClass(CheServiceImpl.class);
    verify(machineProvider).startService(anyString(), anyString(), anyString(), anyString(), eq(false), anyString(), captor.capture(), any(LineConsumer.class));
    CheServiceImpl actualService = captor.getValue();
    assertEquals(actualService.getImage(), machineImage);
}
Also used : Instance(org.eclipse.che.api.machine.server.spi.Instance) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) ArrayList(java.util.ArrayList) NotFoundException(org.eclipse.che.api.core.NotFoundException) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Matchers.anyString(org.mockito.Matchers.anyString) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) Machine(org.eclipse.che.api.core.model.machine.Machine) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) Test(org.testng.annotations.Test)

Example 29 with NotFoundException

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

the class FactoryServiceTest method shouldThrowNotFoundExceptionWhenUpdatingNonExistingFactory.

@Test
public void shouldThrowNotFoundExceptionWhenUpdatingNonExistingFactory() throws Exception {
    final Factory factory = createFactoryWithStorage(FACTORY_NAME, "git", "https://github.com/codenvy/platform-api.git");
    doThrow(new NotFoundException(format("Factory with id %s is not found.", FACTORY_ID))).when(factoryManager).getById(anyString());
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(APPLICATION_JSON).body(JsonHelper.toJson(factory)).when().put(SERVICE_PATH + "/" + FACTORY_ID);
    assertEquals(response.getStatusCode(), 404);
    assertEquals(DTO.createDtoFromJson(response.getBody().asString(), ServiceError.class).getMessage(), format("Factory with id %s is not found.", FACTORY_ID));
}
Also used : Response(com.jayway.restassured.response.Response) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) NotFoundException(org.eclipse.che.api.core.NotFoundException) Test(org.testng.annotations.Test)

Example 30 with NotFoundException

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

the class JpaFactoryDao method doUpdate.

@Transactional
protected FactoryImpl doUpdate(FactoryImpl update) throws NotFoundException {
    final EntityManager manager = managerProvider.get();
    if (manager.find(FactoryImpl.class, update.getId()) == null) {
        throw new NotFoundException(format("Could not update factory with id %s because it doesn't exist", update.getId()));
    }
    if (update.getWorkspace() != null) {
        update.getWorkspace().getProjects().forEach(ProjectConfigImpl::prePersistAttributes);
    }
    FactoryImpl merged = manager.merge(update);
    manager.flush();
    return merged;
}
Also used : EntityManager(javax.persistence.EntityManager) NotFoundException(org.eclipse.che.api.core.NotFoundException) FactoryImpl(org.eclipse.che.api.factory.server.model.impl.FactoryImpl) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) Transactional(com.google.inject.persist.Transactional)

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