コード例 #1
0
  /**
   * Adds already running runner.
   *
   * @param processDescriptor The descriptor of new runner
   * @return instance of new runner
   */
  @NotNull
  public Runner addRunner(@NotNull ApplicationProcessDescriptor processDescriptor) {
    RunOptions runOptions = dtoFactory.createDto(RunOptions.class);
    Runner runner = modelsFactory.createRunner(runOptions);

    String environmentId = processDescriptor.getEnvironmentId();

    if (environmentId != null && environmentId.startsWith(PROJECT_PREFIX)) {
      runner.setScope(PROJECT);
    }

    runnersId.add(processDescriptor.getProcessId());

    runner.setProcessDescriptor(processDescriptor);
    runner.setRAM(processDescriptor.getMemorySize());
    runner.setStatus(Runner.Status.DONE);
    runner.resetCreationTime();

    history.addRunner(runner);

    onSelectionChanged(RUNNER);

    runnerTimer.schedule(ONE_SEC.getValue());

    LaunchAction launchAction = actionFactory.createLaunch();
    runnerActions.put(runner, launchAction);

    launchAction.perform(runner);

    selectHistoryTab();

    return runner;
  }
コード例 #2
0
ファイル: RunnerImpl.java プロジェクト: riuvshin/che-plugins
  /** {@inheritDoc} */
  @Override
  public void resetCreationTime() {
    if (FAILED.equals(status) || STOPPED.equals(status) || IN_QUEUE.equals(status)) {
      creationTime = System.currentTimeMillis();
      return;
    }

    creationTime = descriptor == null ? System.currentTimeMillis() : descriptor.getCreationTime();
  }
コード例 #3
0
ファイル: RunnerImpl.java プロジェクト: riuvshin/che-plugins
  @Nullable
  private RunnerMetric getRunnerMetricByName(@NotNull String name) {
    if (descriptor == null) {
      return null;
    }

    for (RunnerMetric stat : descriptor.getRunStats()) {
      if (name.equals(stat.getName())) {
        return stat;
      }
    }

    return null;
  }
コード例 #4
0
ファイル: RunnerImpl.java プロジェクト: riuvshin/che-plugins
  /** {@inheritDoc} */
  @Override
  @NotNull
  public String getTimeout() {
    if (!(DONE.equals(status) || RUNNING.equals(status))) {
      return TIMER_STUB;
    }

    RunnerMetric timeoutMetric = getRunnerMetricByName(RunnerMetric.TERMINATION_TIME);

    if (timeoutMetric != null) {
      return getTimeOut(timeoutMetric);
    }

    RunnerMetric lifeTimeMetric = getRunnerMetricByName(RunnerMetric.LIFETIME);

    if (lifeTimeMetric != null && NEW.equals(descriptor.getStatus())) {
      return getLifeTime(lifeTimeMetric);
    }

    return TIMER_STUB;
  }
コード例 #5
0
 private void setDebugPort(Runner runner) {
   ApplicationProcessDescriptor runnerDescriptor = runner.getDescriptor();
   if (runnerDescriptor != null && runnerDescriptor.getDebugPort() != -1) {
     view.setDebugPort(String.valueOf(runnerDescriptor.getDebugPort()));
   }
 }
コード例 #6
0
  /**
   * Check running processes
   *
   * @throws Exception
   */
  @Test
  public void testGetRunningProcesses() throws Exception {

    // two users with tasks, only florent is the current user
    User user =
        new UserImpl("florent", "id-2314", "token-2323", Collections.<String>emptyList(), false);
    User dummy =
        new UserImpl("dummy", "id-2315", "token-2324", Collections.<String>emptyList(), false);
    EnvironmentContext context = EnvironmentContext.getCurrent();
    context.setUser(user);

    // add 5 tasks for 4 projects with Florent and one for dummy user
    String workspaceFlorent = "workspaceFlorent";
    String workspaceCodenvy = "workspaceCodenvy";
    String projectA = "/projectA";
    String projectFlorentA = projectA;
    String projectFlorentB = "projectB";
    String projectCodenvyA = projectA;

    List<RunQueueTask> tasks = new ArrayList<>(4);
    tasks.add(createTask(user, workspaceFlorent, projectFlorentA));
    tasks.add(createTask(user, workspaceFlorent, projectFlorentB));
    tasks.add(createTask(user, workspaceCodenvy, projectCodenvyA));
    tasks.add(createTask(dummy, "dummyWorkspace", "dummyProject"));
    doReturn(tasks).when(runQueue).getTasks();

    // we should have all the processes without specifying anything
    List<ApplicationProcessDescriptor> processes = service.getRunningProcesses(null, null);
    // list is 3 as we don't have task for dummy user
    assertEquals(processes.size(), 3);

    // we should have all the processes without specifying anything
    processes = service.getRunningProcesses(workspaceCodenvy, null);
    // list is 1 for this workspace
    assertEquals(processes.size(), 1);
    ApplicationProcessDescriptor process = processes.get(0);
    assertEquals(process.getWorkspace(), workspaceCodenvy);
    assertEquals(process.getProject(), projectCodenvyA);

    // we should have all the processes without specifying anything
    processes = service.getRunningProcesses(workspaceCodenvy, projectA);
    // list is 1 as we only have one matching workspace + project
    assertEquals(processes.size(), 1);

    // we should have all the processes without specifying anything
    processes = service.getRunningProcesses(null, projectA);
    // list is 2 as we have two workspaces with this project name
    assertEquals(processes.size(), 2);

    // no workspace with that name
    processes = service.getRunningProcesses("dummy", null);
    assertEquals(processes.size(), 0);

    // no project with that name
    processes = service.getRunningProcesses(null, "project");
    assertEquals(processes.size(), 0);

    // no project with that workspace + name
    processes = service.getRunningProcesses("dummy", "project");
    assertEquals(processes.size(), 0);
  }
コード例 #7
0
ファイル: RunnerImpl.java プロジェクト: riuvshin/che-plugins
 /** {@inheritDoc} */
 @Override
 public long getProcessId() {
   Objects.requireNonNull(descriptor);
   return descriptor.getProcessId();
 }