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