Search in sources :

Example 1 with HttpJsonRequest

use of org.eclipse.che.api.core.rest.HttpJsonRequest in project che by eclipse.

the class WsAgentLauncher method launch.

@Override
public void launch(Instance machine, Agent agent) throws ServerException {
    final HttpJsonRequest wsAgentPingRequest;
    try {
        wsAgentPingRequest = createPingRequest(machine);
    } catch (ServerException e) {
        throw new MachineException(e.getServiceError());
    }
    String script = agent.getScript() + "\n" + firstNonNull(wsAgentRunCommand, DEFAULT_WS_AGENT_RUN_COMMAND);
    final String wsAgentPingUrl = wsAgentPingRequest.getUrl();
    try {
        // for server side type of command mean nothing
        // but we will use it as marker on
        // client side for track this command
        CommandImpl command = new CommandImpl(getAgentId(), script, WS_AGENT_PROCESS_NAME);
        machineProcessManagerProvider.get().exec(machine.getWorkspaceId(), machine.getId(), command, getWsAgentProcessOutputChannel(machine.getWorkspaceId()));
        final long pingStartTimestamp = System.currentTimeMillis();
        LOG.debug("Starts pinging ws agent. Workspace ID:{}. Url:{}. Timestamp:{}", machine.getWorkspaceId(), wsAgentPingUrl, pingStartTimestamp);
        while (System.currentTimeMillis() - pingStartTimestamp < wsAgentMaxStartTimeMs) {
            if (pingWsAgent(wsAgentPingRequest)) {
                return;
            } else {
                Thread.sleep(wsAgentPingDelayMs);
            }
        }
    } catch (BadRequestException | ServerException | NotFoundException e) {
        throw new ServerException(e.getServiceError());
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new ServerException("Ws agent pinging is interrupted");
    }
    LOG.error("Fail pinging ws agent. Workspace ID:{}. Url:{}. Timestamp:{}", machine.getWorkspaceId(), wsAgentPingUrl);
    throw new ServerException(pingTimedOutErrorMessage);
}
Also used : CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) ServerException(org.eclipse.che.api.core.ServerException) HttpJsonRequest(org.eclipse.che.api.core.rest.HttpJsonRequest) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) BadRequestException(org.eclipse.che.api.core.BadRequestException) NotFoundException(org.eclipse.che.api.core.NotFoundException)

Example 2 with HttpJsonRequest

use of org.eclipse.che.api.core.rest.HttpJsonRequest in project che by eclipse.

the class ProjectServiceTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    WorkspaceProjectsSyncer workspaceHolder = new WsAgentTestBase.TestWorkspaceHolder();
    File root = new File(FS_PATH);
    if (root.exists()) {
        IoUtil.deleteRecursive(root);
    }
    root.mkdir();
    File indexDir = new File(INDEX_PATH);
    if (indexDir.exists()) {
        IoUtil.deleteRecursive(indexDir);
    }
    indexDir.mkdir();
    Set<PathMatcher> filters = new HashSet<>();
    filters.add(path -> {
        for (java.nio.file.Path pathElement : path) {
            if (pathElement == null || EXCLUDE_SEARCH_PATH.equals(pathElement.toString())) {
                return true;
            }
        }
        return false;
    });
    FSLuceneSearcherProvider sProvider = new FSLuceneSearcherProvider(indexDir, filters);
    vfsProvider = new LocalVirtualFileSystemProvider(root, sProvider);
    final EventService eventService = new EventService();
    // PTs for test
    ProjectTypeDef chuck = new ProjectTypeDef("chuck_project_type", "chuck_project_type", true, false) {

        {
            addConstantDefinition("x", "attr description", new AttributeValue(Arrays.asList("a", "b")));
        }
    };
    Set<ProjectTypeDef> projectTypes = new HashSet<>();
    final LocalProjectType myProjectType = new LocalProjectType("my_project_type", "my project type");
    projectTypes.add(myProjectType);
    projectTypes.add(new LocalProjectType("module_type", "module type"));
    projectTypes.add(chuck);
    ptRegistry = new ProjectTypeRegistry(projectTypes);
    phRegistry = new ProjectHandlerRegistry(new HashSet<>());
    importerRegistry = new ProjectImporterRegistry(Collections.<ProjectImporter>emptySet());
    projectServiceLinksInjector = new ProjectServiceLinksInjector();
    projectRegistry = new ProjectRegistry(workspaceHolder, vfsProvider, ptRegistry, phRegistry, eventService);
    projectRegistry.initProjects();
    FileWatcherNotificationHandler fileWatcherNotificationHandler = new DefaultFileWatcherNotificationHandler(vfsProvider);
    FileTreeWatcher fileTreeWatcher = new FileTreeWatcher(root, new HashSet<>(), fileWatcherNotificationHandler);
    pm = new ProjectManager(vfsProvider, ptRegistry, projectRegistry, phRegistry, importerRegistry, fileWatcherNotificationHandler, fileTreeWatcher, workspaceHolder, fileWatcherManager);
    pm.initWatcher();
    HttpJsonRequest httpJsonRequest = mock(HttpJsonRequest.class, new SelfReturningAnswer());
    //List<ProjectConfigDto> modules = new ArrayList<>();
    projects = new ArrayList<>();
    addMockedProjectConfigDto(myProjectType, "my_project");
    when(httpJsonRequestFactory.fromLink(any())).thenReturn(httpJsonRequest);
    when(httpJsonRequest.request()).thenReturn(httpJsonResponse);
    when(httpJsonResponse.asDto(WorkspaceDto.class)).thenReturn(usersWorkspaceMock);
    when(usersWorkspaceMock.getConfig()).thenReturn(workspaceConfigMock);
    when(workspaceConfigMock.getProjects()).thenReturn(projects);
    //        verify(httpJsonRequestFactory).fromLink(eq(DtoFactory.newDto(Link.class)
    //                                                             .withHref(apiEndpoint + "/workspace/" + workspace + "/project")
    //                                                             .withMethod(PUT)));
    DependencySupplierImpl dependencies = new DependencySupplierImpl();
    dependencies.addInstance(ProjectTypeRegistry.class, ptRegistry);
    dependencies.addInstance(UserDao.class, userDao);
    dependencies.addInstance(ProjectManager.class, pm);
    dependencies.addInstance(ProjectImporterRegistry.class, importerRegistry);
    dependencies.addInstance(ProjectHandlerRegistry.class, phRegistry);
    dependencies.addInstance(EventService.class, eventService);
    dependencies.addInstance(ProjectServiceLinksInjector.class, projectServiceLinksInjector);
    ResourceBinder resources = new ResourceBinderImpl();
    ProviderBinder providers = ProviderBinder.getInstance();
    EverrestProcessor processor = new EverrestProcessor(new EverrestConfiguration(), dependencies, new RequestHandlerImpl(new RequestDispatcher(resources), providers), null);
    launcher = new ResourceLauncher(processor);
    processor.addApplication(new Application() {

        @Override
        public Set<Class<?>> getClasses() {
            return java.util.Collections.<Class<?>>singleton(ProjectService.class);
        }

        @Override
        public Set<Object> getSingletons() {
            return new HashSet<>(Arrays.asList(new ApiExceptionMapper()));
        }
    });
    ApplicationContext.setCurrent(anApplicationContext().withProviders(providers).build());
    env = org.eclipse.che.commons.env.EnvironmentContext.getCurrent();
}
Also used : ProjectTypeRegistry(org.eclipse.che.api.project.server.type.ProjectTypeRegistry) DependencySupplierImpl(org.everrest.core.tools.DependencySupplierImpl) AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) FileWatcherNotificationHandler(org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationHandler) DefaultFileWatcherNotificationHandler(org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler) ProjectImporterRegistry(org.eclipse.che.api.project.server.importer.ProjectImporterRegistry) ProjectTypeDef(org.eclipse.che.api.project.server.type.ProjectTypeDef) ResourceLauncher(org.everrest.core.tools.ResourceLauncher) EverrestConfiguration(org.everrest.core.impl.EverrestConfiguration) EverrestProcessor(org.everrest.core.impl.EverrestProcessor) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) ProjectHandlerRegistry(org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry) HttpJsonRequest(org.eclipse.che.api.core.rest.HttpJsonRequest) ApiExceptionMapper(org.eclipse.che.api.core.rest.ApiExceptionMapper) LocalVirtualFileSystemProvider(org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider) EventService(org.eclipse.che.api.core.notification.EventService) RequestDispatcher(org.everrest.core.impl.RequestDispatcher) ProjectImporter(org.eclipse.che.api.project.server.importer.ProjectImporter) ProviderBinder(org.everrest.core.impl.ProviderBinder) PathMatcher(java.nio.file.PathMatcher) DefaultFileWatcherNotificationHandler(org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler) SelfReturningAnswer(org.eclipse.che.commons.test.mockito.answer.SelfReturningAnswer) RequestHandlerImpl(org.everrest.core.impl.RequestHandlerImpl) ResourceBinderImpl(org.everrest.core.impl.ResourceBinderImpl) ResourceBinder(org.everrest.core.ResourceBinder) FileTreeWatcher(org.eclipse.che.api.vfs.impl.file.FileTreeWatcher) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) File(java.io.File) Application(javax.ws.rs.core.Application) FSLuceneSearcherProvider(org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with HttpJsonRequest

use of org.eclipse.che.api.core.rest.HttpJsonRequest in project che by eclipse.

the class WsAgentHealthCheckerImpl method check.

@Override
public WsAgentHealthStateDto check(Machine machine) throws ServerException {
    Server wsAgent = getWsAgent(machine);
    final WsAgentHealthStateDto agentHealthStateDto = newDto(WsAgentHealthStateDto.class);
    if (wsAgent == null) {
        return agentHealthStateDto.withCode(NOT_FOUND.getStatusCode()).withReason("Workspace Agent not available");
    }
    try {
        final HttpJsonRequest pingRequest = createPingRequest(machine);
        final HttpJsonResponse response = pingRequest.request();
        return agentHealthStateDto.withCode(response.getResponseCode());
    } catch (ApiException | IOException e) {
        return agentHealthStateDto.withCode(SERVICE_UNAVAILABLE.getStatusCode()).withReason(e.getMessage());
    }
}
Also used : Server(org.eclipse.che.api.core.model.machine.Server) HttpJsonRequest(org.eclipse.che.api.core.rest.HttpJsonRequest) IOException(java.io.IOException) WsAgentHealthStateDto(org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto) HttpJsonResponse(org.eclipse.che.api.core.rest.HttpJsonResponse) ApiException(org.eclipse.che.api.core.ApiException)

Example 4 with HttpJsonRequest

use of org.eclipse.che.api.core.rest.HttpJsonRequest in project che by eclipse.

the class MavenProjectTypeTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    Set<ProjectTypeDef> projTypes = new HashSet<>();
    projTypes.add(new JavaProjectType(new JavaValueProviderFactory()));
    projTypes.add(new MavenProjectType(new MavenValueProviderFactory()));
    ptRegistry = new ProjectTypeRegistry(projTypes);
    Set<ProjectHandler> handlers = new HashSet<>();
    handlers.add(new MavenProjectGenerator(Collections.<GeneratorStrategy>emptySet()));
    httpJsonRequest = mock(HttpJsonRequest.class, new SelfReturningAnswer());
}
Also used : ProjectTypeRegistry(org.eclipse.che.api.project.server.type.ProjectTypeRegistry) HttpJsonRequest(org.eclipse.che.api.core.rest.HttpJsonRequest) JavaValueProviderFactory(org.eclipse.che.plugin.java.server.projecttype.JavaValueProviderFactory) ProjectTypeDef(org.eclipse.che.api.project.server.type.ProjectTypeDef) ProjectHandler(org.eclipse.che.api.project.server.handlers.ProjectHandler) GeneratorStrategy(org.eclipse.che.plugin.maven.server.projecttype.handler.GeneratorStrategy) SelfReturningAnswer(org.eclipse.che.commons.test.mockito.answer.SelfReturningAnswer) MavenProjectGenerator(org.eclipse.che.plugin.maven.server.projecttype.handler.MavenProjectGenerator) JavaProjectType(org.eclipse.che.plugin.java.server.projecttype.JavaProjectType) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

HttpJsonRequest (org.eclipse.che.api.core.rest.HttpJsonRequest)4 HashSet (java.util.HashSet)2 ProjectTypeDef (org.eclipse.che.api.project.server.type.ProjectTypeDef)2 ProjectTypeRegistry (org.eclipse.che.api.project.server.type.ProjectTypeRegistry)2 SelfReturningAnswer (org.eclipse.che.commons.test.mockito.answer.SelfReturningAnswer)2 File (java.io.File)1 IOException (java.io.IOException)1 PathMatcher (java.nio.file.PathMatcher)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 Application (javax.ws.rs.core.Application)1 ApiException (org.eclipse.che.api.core.ApiException)1 BadRequestException (org.eclipse.che.api.core.BadRequestException)1 NotFoundException (org.eclipse.che.api.core.NotFoundException)1 ServerException (org.eclipse.che.api.core.ServerException)1 Server (org.eclipse.che.api.core.model.machine.Server)1 EventService (org.eclipse.che.api.core.notification.EventService)1 ApiExceptionMapper (org.eclipse.che.api.core.rest.ApiExceptionMapper)1 HttpJsonResponse (org.eclipse.che.api.core.rest.HttpJsonResponse)1 MachineException (org.eclipse.che.api.machine.server.exception.MachineException)1