Java Code Examples for org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl#getRuntime()

The following examples show how to use org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl#getRuntime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ForwardActivityFilter.java    From rh-che with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void onEvent(WorkspaceStatusEvent event) {
  String workspaceId = event.getWorkspaceId();
  if (WorkspaceStatus.STOPPING.equals(event.getStatus())) {
    try {
      final WorkspaceImpl workspace = workspaceManager.getWorkspace(workspaceId);
      Runtime runtime = workspace.getRuntime();
      if (runtime != null) {
        String userId = runtime.getOwner();
        callWorkspaceAnalyticsEndpoint(
            userId, workspaceId, "/fabric8-che-analytics/stopped", "notify stop", workspace);
      } else {
        LOG.warn(
            "Received stopping event for workspace {}/{} with id {} but runtime is null",
            workspace.getNamespace(),
            workspace.getConfig().getName(),
            workspaceId);
      }
    } catch (NotFoundException | ServerException e) {
      LOG.warn("", e);
      return;
    }
  }
}
 
Example 2
Source File: DockerEnvironmentBackupManager.java    From codenvy with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void backupWorkspace(String workspaceId) throws ServerException, NotFoundException {
  try {
    WorkspaceImpl workspace = workspaceManager.getWorkspace(workspaceId);
    if (workspace.getRuntime() == null) {
      throw new NotFoundException("Workspace is not running");
    }
    Machine devMachine = workspace.getRuntime().getDevMachine();
    if (devMachine == null || devMachine.getStatus() != MachineStatus.RUNNING) {
      // may happen if WS is no longer in RUNNING state
      return;
    }
    // machine that is not in running state can be just a stub and should not be casted
    DockerInstance dockerDevMachine =
        (DockerInstance) workspaceManager.getMachineInstance(workspaceId, devMachine.getId());
    String nodeHost = dockerDevMachine.getNode().getHost();
    String destPath =
        workspaceIdHashLocationFinder.calculateDirPath(backupsRootDir, workspaceId).toString();
    String srcUserName = getUserInfo(workspaceId, dockerDevMachine.getContainer()).name;
    int syncPort = getSyncPort(dockerDevMachine);

    backupInsideLock(workspaceId, projectFolderPath, nodeHost, syncPort, srcUserName, destPath);
  } catch (IOException e) {
    throw new ServerException(e.getLocalizedMessage(), e);
  }
}
 
Example 3
Source File: PreviewUrlLinksVariableGenerator.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Takes commands from given {@code workspace}. For all commands that have defined previewUrl,
 * creates variable name in defined format and final preview url link. It updates the command so
 * it's `previewUrl` attribute will contain variable in proper format. Method then returns map of
 * all preview url links with these variables as keys:
 *
 * <pre>
 *   links:
 *     "previewURl/run_123": http://your.domain
 *   command:
 *     attributes:
 *       previewUrl: '${previewUrl/run_123}/some/path'
 * </pre>
 *
 * @return map of all <commandPreviewUrlVariable, previewUrlFullLink>
 */
Map<String, String> genLinksMapAndUpdateCommands(WorkspaceImpl workspace, UriBuilder uriBuilder) {
  if (workspace == null
      || workspace.getRuntime() == null
      || workspace.getRuntime().getCommands() == null
      || uriBuilder == null) {
    return Collections.emptyMap();
  }

  Map<String, String> links = new HashMap<>();
  for (Command command : workspace.getRuntime().getCommands()) {
    Map<String, String> commandAttributes = command.getAttributes();

    if (command.getPreviewUrl() != null
        && commandAttributes != null
        && commandAttributes.containsKey(PREVIEW_URL_ATTRIBUTE)) {
      String previewUrlLinkValue = createPreviewUrlLinkValue(uriBuilder, command);
      String previewUrlLinkKey = createPreviewUrlLinkKey(command);
      links.put(previewUrlLinkKey, previewUrlLinkValue);

      commandAttributes.replace(
          PREVIEW_URL_ATTRIBUTE,
          formatAttributeValue(previewUrlLinkKey, command.getPreviewUrl().getPath()));
    }
  }
  return links;
}