Red Hat Training

A Red Hat training course is available for Red Hat JBoss Developer Studio

Chapter 3. Developing for the Cloud with OpenShift 2

3.1. Creating Your First OpenShift Online Application

OpenShift Tools provides an all-in-one New OpenShift Application wizard for creating new OpenShift applications from templates and existing projects. This wizard is the starting point for creating all new OpenShift Online applications from the IDE and also for importing OpenShift Online applications to your workspace.

The New OpenShift Application wizard is an ideal starting point for new users to OpenShift and OpenShift Tools as it guides you through all the steps necessary to set up the IDE to use your OpenShift Online account and configure your account ready for applications.

The instructions here demonstrate how to use this wizard and a default OpenShift application template to create a basic OpenShift Online application. This includes one-time steps, such as signing up for an OpenShift Online account, creating an OpenShift Online domain and uploading SSH keys. If you have previously used OpenShift Online or OpenShift Tools, you can omit unnecessary one-time steps as appropriate.

3.1.1. Starting the New OpenShift Application Wizard

  1. In JBoss Central, under Start from scratch, click OpenShift Application.

3.1.2. Signing up for an OpenShift Online Account

If you do not have an OpenShift Online account, you should complete the following steps:

  1. Click the link provided to sign up for an OpenShift account and follow the instructions on the OpenShift website.

    Figure 3.1. Link to Sign up for a New OpenShift Online User Account

    Link to sign up for a new OpenShift Online user account
  2. When you have completed the sign-up process, restart the OpenShift Application wizard from JBoss Central.

3.1.3. Connecting to OpenShift Online

  1. Complete the fields about your OpenShift Online account as follows:

    1. From the Connection list, select New Connection.
    2. Ensure the disabled Server field states https://openshift.redhat.com.
    3. In the Username and Password fields, type your account credentials.

      Figure 3.2. Connection Information Provided for OpenShift Online Account

      Completed OpenShift Online connection fields
  2. Click Next.

3.1.4. Enabling Communication between the IDE and OpenShift

If your OpenShift Online account has no SSH public keys stored, you are prompted with the Add SSH Keys wizard and you should complete the following steps:

  1. Click New.
  2. Complete the fields about the SSH Keys to be created as follows:

    1. In the Name field, type a name for the SSH key pair.
    2. From the Key Type list, ensure SSH_RSA is selected.
    3. In the SSH2 Home field, ensure your .ssh directory path is correct.
    4. In the Private Key File Name field, type a name for the private key file name. The Public Key File Name field populates automatically with the name of the private key file name with .pub appended.

      Figure 3.3. New SSH Key Information for OpenShift Online Provided

      Completed new SSH key fields
  3. Click Finish.
  4. Click Finish to close the Add SSH Keys window.

3.1.5. Creating a Domain

If your OpenShift Online account has no domains, you are prompted with the Create Domain wizard and you should complete the following step:

  1. In the Domain Name field, type an alphanumeric name for your new OpenShift Online domain and click Finish. The provided domain name must be unique across all domains on OpenShift Online; if it is not unique, you are directed back to the Create Domain window to provide a unique domain name.

    Figure 3.4. New OpenShift Domain Name Provided

    Completed new OpenShift Online domain field

3.1.6. Providing Essential New Application Details

  1. Complete the fields about the type of OpenShift application you want to create as follows:

    1. Ensure Create a new OpenShift application is selected.
    2. Expand Basic Cartridges and select JBoss Application Server 7.

      Figure 3.5. Basic Cartridge Selected for the New OpenShift Online Application

      JBoss Application Server 7 selected as the Basic Cartridge
  2. Click Next.
  3. Complete the fields about your OpenShift application as follows:

    1. Ensure the Domain field displays the OpenShift Online domain with which you want to host your application.
    2. In the Name field, type an alphanumeric name for your application.
    3. From the Gear profile list, select small.
    4. Select the Enable scaling check box.

      Figure 3.6. New OpenShift Application Information Provided

      Completed new OpenShift application fields
  4. Click Next.

3.1.7. Configuring the Corresponding Workspace Project for the New Application

  1. Complete the fields about the corresponding workspace project as follows:

    1. Ensure the Create a new project check box is selected.
    2. Ensure the Create and set up a server for easy publishing check box is selected. This automatically creates an OpenShift server adapter for the application, enabling you to easily publish project changes to the OpenShift server.
  2. Click Next.
  3. Ensure the location in the Git Clone Destination field corresponds to where you want to make a local git repository for the project source code.

    Figure 3.7. Git Clone Destination Specified

    Default Git clone destination check box selected

3.1.8. Creating the OpenShift Online Application

  1. Click Finish for the wizard to start generating the new OpenShift application. This process may take some time to complete.
  2. If you are prompted that the authenticity of the host cannot be established and asked whether you want to continue connecting, ensure that the host name matches that of your application and domain and click Yes.

3.1.9. Viewing the OpenShift Online Application

  1. In the OpenShift Explorer view, expand the connection and domain.
  2. Right-click {application name} and click Show InWeb Browser.

Your OpenShift Online application is displayed in the IDE default web browser.

3.1.10. Some OpenShift Terminology

  • Gear: A server container with a set of resources that allow you to run your application
  • Cartridge: Plug-ins that house the framework or components that can be used to create and run your application

    1. Standalone cartridge: Languages and application servers that serve your application
    2. Embedded cartridge: Functionality to enhance your application
  • Scaling: Enables your application to react to changes in traffic and automatically allocate the necessary resources to handle the current demand

3.1.11. Did You Know?

  • You can also start the New OpenShift Application wizard from the OpenShift Explorer view by right-clicking a connection, domain or existing application and clicking NewApplication or from the IDE main menus by clicking FileNewOpenShift Application.
  • To save time when logging in to OpenShift Online in future, you can click the Save Password check box in the Sign in to OpenShift window. The password is retained in secure storage provided by the IDE and automatically populates the Password field for the associated connection.
  • Using the New OpenShift Application wizard, you can also create a new OpenShift application from an existing workspace project or a Git source.
  • Each time you start the IDE or switch workspaces the IDE is initially disconnected from OpenShift. When you attempt to complete an action that requires an active OpenShift connection, you are automatically prompted to reconnect.

3.2. Developing an Existing OpenShift Application

OpenShift Tools enables you to import existing OpenShift Online applications into the IDE so that you can take advantage of the IDE features in further developing your applications. As illustrated in this article, during the import process you can configure the IDE for easy republishing to OpenShift Online.

Develop an existing OpenShift application by:

3.2.1. Importing an Existing OpenShift Online Application

Applications associated with your OpenShift Online account(s) are listed in the OpenShift Explorer view. The source code for these applications can be individually imported into the IDE using the OpenShift Tools Import OpenShift Application wizard.

To import an existing OpenShift Online application as a new project in the existing IDE workspace, complete the following steps:

  1. In the OpenShift Explorer view, ensure your OpenShift Online connection is listed or click the Connection icon Connection icon and complete your OpenShift Online account details to create a new connection.
  2. In the OpenShift Explorer view, expand the connection and domain to locate the application you want to import.
  3. Right-click {application name} and click Import Application.
  4. Complete the fields about the application to be imported as follows:

    1. Ensure that Use my existing OpenShift application is selected.
    2. Ensure that the name of the application you want to import is listed. If this is not the case, type the name of the application or click Browse to select the application.

      Figure 3.8. Existing OpenShift Online Application Information Provided

      Existing OpenShift Online Application Information Provided
  5. Click Next.
  6. Complete the fields about the corresponding new workspace project as follows:

    1. Ensure the Create a new project check box is selected.
    2. Ensure the Create and set up a server adapter for easy publishing check box is selected.
  7. Click Next.
  8. Ensure the location in the Git Clone Destination field corresponds to where you want to make a local copy of the OpenShift Online application Git repository.
  9. Ensure a public SSH key is uploaded to OpenShift Online and private key location is specified in the IDE preferences by clicking SSH Keys Wizard and reviewing the information.
  10. Click Finish.

If you are prompted that the authenticity of the host cannot be established and asked whether you want to continue connecting, ensure that the host name matches that of your application and domain and click Yes.

When the import process is complete, the project is listed in the Project Explorer view and a server adapter is listed for the application in the Servers view.

OpenShift Tools makes a number of small changes to the application source code on import. It adds several IDE-specific files to the project and modifies the .gitignore file so that you are not prompted about these files each time you commit project changes to the Git repository.

3.2.2. Modifying the Application Source Code

The files contained in your project depend on the type of project that you have imported. Here a common OpenShift application file, index.html, is changed as an example of modifying the project source code. You can opt to change this file or another file of your project.

To modify the index.html file, complete the following steps:

  1. In the Project Explorer view, expand {project name} → src → main → webapp.
  2. Double-click index.html to open it in the JBoss Tools HTML Editor.
  3. After the opening <body> tag add the following line:

    <h1>This is a change made to my OpenShift Online app from the IDE.</h1>
  4. Save the index.html file by pressing Ctrl+S (or Cmd+S).

Note that in the Project Explorer view, index.html has > prepended to show that the source code has changed since the last Git commit.

3.2.3. Republishing the Modified Application

You must commit and push any changes you have made to the project source code and then republish the application before you can see changes reflected in the OpenShift Online application. As an example of committing and pushing source code changes to the OpenShift Online application repository and republishing the application, here the index.html file changed earlier is used. You can opt to use the project file that you changed earlier.

To commit and push the index.html changes and republish the application to OpenShift Online, complete the following steps:

  1. In the Servers view, right-click {application name} at OpenShift and click Publish. Or you can drag the from the Project Explorer view and drop it on the server adapter in the Servers view.
  2. Complete the fields about the project changes to commit and push to the OpenShift Online application Git repository as follows:

    1. In the Commit message field, type the following message

      Added new heading in body of index.html
    2. In the table of files, ensure the index.html file is selected.

      Figure 3.9. Commit Message Provided and Changed Project File Selected

      Commit Message Provided and Changed Project File Selected
  3. Click Commit and Publish.

The republishing process can take some time. When the Console view shows Deployment completed with status: success, the republishing process is complete.

3.2.4. Viewing the Modified Application

After the modified application is republished, you can view the live updated version at the OpenShift Online application URL.

To view the modified OpenShift Online application in the IDE default web browser, complete the following steps:

  1. In the OpenShift Explorer view, expand the connection and the domain.
  2. Right-click {application name} and click Show InWeb Browser.

Your modified and republished OpenShift Online application is displayed in the IDE default web browser.

3.2.5. Did You Know?

  • On the first occasion that you republish your application to OpenShift Online, you may be prompted to provide a username and email address for use by Git. The IDE looks for a default Git configuration file on your system from which to obtain this information and if the IDE cannot find the file it prompts you to provide the values. You can specify the location of your system Git configuration file in the IDE Preferences, under TeamGitConfiguration.
  • You can review the progress of republishing applications to OpenShift Online in the Console view.
  • You can also open the OpenShift application in a web browser from the Servers view by right-clicking {application name} at OpenShift and clicking Show InWeb Browser.
  • You can change the IDE default web browser to be either the IDE internal web browser, BrowserSim (when installed) or an external web browser. Click WindowWeb Browser and select from the available web browser options or click WindowPreferencesGeneralWeb Browser to extend the list of available external web browsers.

3.3. Custom Publishing Your OpenShift Application

Through the IDE you can manage your OpenShift Online application beyond simply its source code. OpenShift Online allows customization of the build and deployment process with markers and action hooks, each of which can be added to the application configuration files using OpenShift Tools and existing IDE functionality. Further, the Git commit and push processes for your changed application source code and configuration files can be customized through the IDE preferences to meet your needs.

Custom publish your OpenShift application by:

3.3.1. Adding a Marker to the Application

OpenShift Tools provides the Configure Markers wizard for adding markers to and removing them from your OpenShift application. The wizard lists markers that are already applied to your application and those that are available to add given the cartridge configuration of your application. The wizard manages the adding and removing of markers from your application, creating or deleting marker files and adding or removing them from the Git index respectively.

As an example, here the hot deploy marker is added to the application, which triggers OpenShift to publish application changes without first restarting the application cartridges and hence making the republishing faster.

To add the hot deploy marker to the application, complete the following steps:

  1. In the Project Explorer view, right-click {project name} and click OpenShiftConfigure Markers.
  2. From the Marker table, select Hot Deploy and click OK.

    Figure 3.10. Hot Deploy Marker Selected

    Hot Deploy Marker Selected

    An empty .openshift/markers/hot_deploy file is added to the application. OpenShift Tools automatically completes the git add action so that this new file is added to the Git index and can be committed and pushed to the OpenShift application repository when ready.

3.3.2. Adding an Action Hook to the Application

Using IDE features, you can quickly add action hooks to your OpenShift application. Adding an action hook requires creating a script file named according to the phase in which it is to run, locating it in the application .openshift/action_hooks directory, adding the file to the Git index and ensuring the file is executable by all.

As an example, here a post deploy action hook is added to the application, which triggers a simple bash script to execute on the application main gear after the application is deployed.

To add a post deploy action hook to the application, complete the following steps:

Create the post deploy action hook

  1. In the Navigator view, expand {project name} → .openshift.
  2. Right-click action_hooks and click NewFile.
  3. In the File name field, type post_deploy and click Finish.
  4. In the file editor, add the following lines to the post_deploy file:

    #!/bin/bash
    echo "This is my post-deploy bash script”
  1. Save the file by pressing Ctrl+S (or Cmd+S).

Make the post deploy action hook executable

  1. In the Navigator view, right-click the post_deploy file and click Properties.
  2. In the Permissions table, select the Execute check boxes for all user types.

    Figure 3.11. Execute Permissions Check Boxes Selected for All Users

    Execute Permissions Check Boxes Selected for All Users
  3. Click Apply and click OK.

3.3.3. Extending the Git Remote Connection Timeout

As your application source code grows in size, the remote connection from the IDE to the OpenShift Online application Git repository may not remain open long enough for the push process to complete. The default Git remote connection timeout is set to 30 seconds after which the connection is closed. But you can extend the Git timeout through the IDE preferences to ensure that the push process is provided with sufficient time to complete.

To extend the Git remote connection timeout, complete the following steps:

  1. Click WindowPreferencesTeamGit.
  2. In the Remote connection timeout (seconds) field, type a value in seconds.

    Figure 3.12. Git Remote Connection Timeout Set

    Git Remote Connection Timeout Set
  3. Click Apply and click OK to close the Preferences window.

3.3.4. Republishing the Application

Before markers and action hooks take effect on your application building and deployment process you must commit the files and push changes to the OpenShift application repository. OpenShift Tools assists you to perform these Git actions as part of the republishing process.

To republish the application, complete the following steps:

  1. In the Servers view, right-click {application name} at OpenShift and click Publish.
  2. Complete the fields about the application changes to commit and push to the OpenShift Online application repository as follows:

    1. In the Commit message field, type the following message:

      Added hot_deploy marker and post_deploy bash script
    2. In the Files table, ensure the hot_deploy file is selected and select the post_deploy file.

      Figure 3.13. Commit Message Supplied and Files Selected for Committing and Publishing

      Committing and Publishing Changes to OpenShift
  3. Click Commit and Publish.

The Console view becomes the view in focus showing the application publication progress. A snippet of the output demonstrating the effect of the hot deploy marker and post deploy action hook is shown here for the sample application:

Not stopping cartridge xyz because hot deploy is enabled
Building git ref 'master', commit abc123

Activating deployment
Deploying xyz cartridge
Not starting cartridge xyz because hot deploy is enabled
This is my post-deploy bash script
-------------------------
Git Post-Receive Result: success
Activation status: success
Deployment completed with status: success

Note that the server has not been stopped and restarted because hot deploy is enabled and the bash script is run post application deployment as required.

3.3.5. Terminology

  • Git: The revision control system used by OpenShift.
  • Marker: A set-named empty file added in the OpenShift application in the .openshift/markers directory; markers are used to specify configuration to the OpenShift server.
  • Action hook: A user-specified script that is added to the OpenShift application, in the .openshift/action_hooks directory; scripts are run by OpenShift at specified stages of the application build and deploy process as denoted by the file name.

3.3.6. Did You Know?

  • You can also access the Configure Markers wizard from the Server view by right-clicking {application name} at OpenShift and clicking OpenShiftConfigure Markers.
  • You can add files to the Git index at any time by right-clicking the file in, for example, the Navigator view and clicking TeamAdd to Index.
  • You can see more information relating to the application Git repository by opening the Git perspective or individual Git views. All of these can be assessed from the Window menu.

3.4. Debugging an OpenShift Java Application

OpenShift Tools enables you to debug your deployed OpenShift applications within the IDE, enabling you to take advantage of the IDE debugging tools. This article specifically details the steps needed to set up an OpenShift Online Java application for debugging. A number of configuration tasks are required both locally and remotely to enable the IDE debugger to connect to the OpenShift server and OpenShift Tools for achieving this. Some tasks only need to be completed once for each OpenShift Online application but others must be completed every time you reconnect to OpenShift Online from the IDE.

Debug an OpenShift Java application by:

This article guides you through each of these configuration requirements and must be completed in the given order.

Note

Your application must be deployed on OpenShift before attempting to configure the OpenShift application for debugging and enabling port forwarding.

3.4.1. Configuring the OpenShift Application for Debugging

You must first configure your OpenShift application for debugging, which requires setting the Enable JPDA (Java Platform Debugger Architecture) marker in your application source code and republishing the application. Marker information is retained with the application so you only need to complete this task once for each OpenShift Online application:

To configure the OpenShift application for debugging, complete the following steps:

  1. In the Project Explorer view, right-click {project name} and click OpenShiftConfigure Markers.
  2. In the Configure OpenShift Markers window, select the Enable JPDA check box and click OK.

    Figure 3.14. OpenShift Enable JPDA Marker Selected

    Enable JPDA check box selected
  3. In the Servers view, right-click {application name} at OpenShift and click Publish.
  4. In the Publish Changes window, in the Commit message field type a message for the commit.
  5. From the Files list, ensure the .openshift/markers/enable_jpda check box is selected and click Commit and Publish.

The project changes are pushed to the remote Git repository and the application is automatically updated on the OpenShift server.

Note

When debugging is enabled on the OpenShift application a debug port is assigned; for default Java applications the debug port is 8787. To perform the remaining tasks, it is important to know which port is the debug port. To identify the debug port for other applications, see the cartridge documentation.

3.4.2. Enabling Port Forwarding for the Local and Remote Debug Ports

After the OpenShift application is configured for debugging, you must enable port forwarding for the local (IDE) and remote (OpenShift server) debug ports. You can achieve this with the OpenShift Tools Application port forwarding wizard, which connects all local ports to their remote counterpart ports, including the local and remote debug ports.

Port forwarding is automatically stopped when your OpenShift Online connection closes; this includes closing the IDE or changing workspaces. You must enable port forwarding every time you reconnect to OpenShift Online from the IDE.

To enable port forwarding, complete the following steps:

  1. In the OpenShift Explorer view, right-click {application name} and click Port Forwarding.
  2. In the Application port forwarding window, click Start All. Ensure the Status value shows Started for the debug ports and click OK to close the Application port forwarding window.

    Figure 3.15. Port Forwarding Started for All Ports

    The Application port forwarding window

3.4.3. Configuring and Connecting the IDE Debugger

With port forwarding configured for the debug ports, you must create a debug configuration for the OpenShift server and connect the IDE debugger. You can then review debug output in the Debug and Console views. The debug configuration is retained with the workspace so you only need to create a new debug configuration once for each OpenShift Online application. But you must restart each debug configuration every time you reconnect to OpenShift Online from the IDE.

To configure and connect the IDE Debugger, complete the following steps:

  1. In the global toolbar of the JBoss perspective, click the drop-down list for the Debug icon and select Debug Configurations.
  2. From the debug configurations list, select Remote Java Application and click the New launch configuration icon New launch configuration icon
  3. In the Connect tab, complete the following fields:

    1. In the Project field, type the name of the workspace project associated with the OpenShift application or click Browse to locate the project.
    2. In the Port field, type the value of the debug port.
    3. Click Apply and then click Debug.

      Figure 3.16. Debug Configuration Ready for Your OpenShift Application

      Configuration completed for the OpenShift application

Connecting to the OpenShift server may take some time to complete and you can monitor the progress in the Progress bar or Progress view.

3.4.4. Did You Know?

  • Setting the Enable JPDA marker adds an .openshift/markers/enable_jpda file to your project. To locate the hidden .openshift directory and access the file, open the Navigator view.
  • You can also access the Port Forwarding wizard by right-clicking {application name} at OpenShift in the Servers view, and clicking OpenShiftPort forwarding.
  • The Debug perspective automatically arranges useful views for debugging. To open the Debug perspective, click WindowOpen PerspectiveDebug.
  • You can set the debugger to look up source code for classes it encounters that are not contained in your project, for example classes used by application servers defined in the IDE. When inputing values for the launch configuration, in the Source tab click Add. From the list of source containers, select JBoss Maven Source Container and click OK. The JBoss Maven Source Container uses indexes available from Maven repositories to locate the source code. From the list, select a runtime server, the libraries of which will be indexed in the JBoss Maven Source Container, and click OK.

3.5. Deploying a Workspace Project to OpenShift Online

OpenShift Tools enables you to deploy existing workspace projects to OpenShift Online using the OpenShift Application wizard. The wizard creates a templated OpenShift application based on your cartridge choices, modifies the project as necessary for use with OpenShift Online and commits the project code to the local application Git repository ready for publishing. The wizard can also generate a server adapter for easy publishing of the application both for first deployment and for future changes.

Deploy a workspace project to OpenShift Online by:

3.5.1. Preparing a Workspace Project for OpenShift Online Deployment

In preparing workspace projects for OpenShift Online, the OpenShift Application wizard merges the existing project content with the key metadata files from a new OpenShift application and connects the project to the OpenShift application Git repository.

To prepare an existing workspace project for OpenShift Online, complete the following steps:

  1. In the Project Explorer, right-click {project name} and click ConfigureNew/Import OpenShift Application.
  2. Complete the fields about your OpenShift Online account as follows:

    1. In the Connection list, select the connection.
    2. In the Password field, type your OpenShift Online account password.
  3. Click Next.
  4. Complete the fields about the type of OpenShift application you want to create as follows:

    1. Ensure Create a new OpenShift application is selected.
    2. Expand Basic Cartridges and select the core cartridge to match the application type; for example, for applications with Java-based server-side functionality select jbossas-7, jboss-wildfly-8, or jbosseap-6.
  5. Click Next.
  6. Complete the fields about your OpenShift application as follows:

    1. Ensure that the 'Domain' list displays the domain in which you want to host your application.
    2. Ensure the Name field contains a valid alphanumeric name for your application.
    3. In the Gear profile field, select the gear size that you want for your application or leave blank to use the default gear profile.
    4. Select the Enable Scaling check box to make your application scalable.
  7. Click Next.
  8. Complete the fields about the corresponding workspace project as follows:

    1. Ensure the Create a new project check box is clear.
    2. Ensure the Use existing project field lists the workspace project that you want to deploy on OpenShift.
    3. Ensure the Create and set up a server adapter for easy publishing check box is selected.

      Figure 3.17. Existing Workspace Project Selected for the New OpenShift Application

      Selecting an Existing Workspace Project
  9. Click Next.
  10. Ensure the location in the Git Clone Destination field exists and corresponds to where you want to make a local git repository for the project source code.
  11. Ensure a public SSH key is uploaded to OpenShift Online and private key location specified in the IDE preferences by clicking SSH Keys wizard and reviewing the information.
  12. Click Finish.
  13. At the prompt informing that changes will be made to the workspace project, click OK.

If you are prompted that the authenticity of the host cannot be established and asked whether you want to continue connecting, ensure that the host name matches that of your application and domain and click Yes.

3.5.2. Deploying the OpenShift Online Application

When the workspace project is prepared, you must republish the OpenShift Online application to push the project source code to your waiting OpenShift Online application and trigger a build and redeployment of the application. Republishing can be achieved using the server adapter created by the OpenShift Application wizard and completes the deployment of the workspace project to OpenShift Online.

To deploy the OpenShift Online application, complete the following steps:

  1. In the Servers view, right-click {application name} at OpenShift and click Full Publish.
  2. When prompted if you want to publish the committed project changes to OpenShift, click Yes.

The Console view becomes the view in focus showing the application publication progress. After the workspace project is published at OpenShift Online, the following message displays in the Console view:

Deployment completed with status: success

3.5.3. Viewing the Deployed OpenShift Online Application

After the application is published, you can view the live version at the OpenShift Online application URL.

To view the OpenShift Online application in a web browser, complete the following steps:

  1. In the OpenShift Explorer view, expand the connection and the domain.
  2. Right-click {application name} and click Show InWeb Browser.

Your deployed OpenShift Online application is displayed in the IDE default web browser.

3.5.4. Did You Know?

  • You can find the URL of your OpenShift Online application from the OpenShift Explorer view by right-clicking {application name} and clicking Details or from the Servers view by right-clicking {application name} on OpenShift and clicking OpenShiftDetails.
  • You can set the preference for which type of web browser the IDE opens by default. Click WindowWeb Browser and click the type of web browser.
  • If your project is large, it may require more time than the default set by the IDE to push changes to the application OpenShift Online Git repository. You can increase the Git timeout by clicking WindowsPreferencesJBoss ToolsOpenShift and changing the OpenShift request timeout (in seconds) value.
  • You can also access the same wizard for deploying an existing workspace project to OpenShift Online from JBoss Central by click OpenShift Application under Start from scratch.

3.6. Configuring SSH Keys for OpenShift

OpenShift Online uses SSH authentication for development tasks that interact directly with gears such as pushing code changes to application OpenShift Online Git repositories, reading application log files, listing and setting environment variables, and port forwarding.

You must have an SSH key pair configured for your OpenShift Online account before using OpenShift Tools features to create, edit and manage OpenShift Online applications. This requires a private-public key pair, with the private key stored on your local system and its location specified in the IDE and the associated public key stored on the OpenShift Online server and associated with your account.

OpenShift Tools enables you to quickly complete these requirements with the assistance of a multipurpose SSH wizard. If you are new to OpenShift Online, the wizards can help you configure a new or existing SSH key pair. If you are already using OpenShift Online through the web interface or RHC client tools, you only need to specify the private key location in the IDE preferences to complete the SSH key configuration.

Configure the SSH keys for OpenShift by:

3.6.1. Option A: Creating and Using a New SSH Key Pair

You can use the OpenShift Tools Manage SSH Keys wizard to create a new SSH key pair. In addition to creating an SSH key pair, this wizard completes the OpenShift Online SSH configuration process by automatically uploading the public key to the OpenShift Online server and setting the location of the corresponding private key in the IDE preferences. This option may be applicable if you have not used your system with OpenShift Online before.

To create and use a new SSH key pair, complete the following steps:

  1. In the OpenShift Explorer view, right-click the connection and click Manage SSH Keys.
  2. In the Manage SSH Keys wizard, click New.
  3. Complete the fields about the new SSH keys as follows:

    • In the Name field, type a name to distinguish the key pair from any other keys associated with the connection.
    • From the Key Type list, select SSH_RSA.
    • Ensure that the SSH2 Home field contains the location where you want to create the files associated with the key pair. To change the location, clear the Default check box and type the location in the SSH2 Home field or click Browse to navigate to the desired location.
    • In the Private Key File Name field, type a name for the private key file. The Public Key File Name field is automatically completed and displays the private key file name appended with .pub.

      Figure 3.18. Completed Fields for the New SSH Key Pair

      Completed Fields for the New SSH Key Pair
  4. Click Finish and click OK to close the Manage SSH Keys wizard.

3.6.2. Option B: Using an Existing SSH Key Pair

You can use the OpenShift Tools Manage SSH Keys wizard to use an already generated SSH key pair with OpenShift Online. This wizard uploads the public key to the OpenShift Online server and sets the location of the corresponding private key in the IDE preferences. This option may be applicable if you have removed a SSH key pair from your OpenShift account, still have the generated key files available on your system and want to reassociate them with your OpenShift account.

To use an existing SSH key pair, complete the following steps:

  1. In the OpenShift Explorer view, right-click the connection and click Manage SSH Keys.
  2. Click Add Existing.
  3. Complete the fields about the existing public SSH key as follows:

    • In the Name field, type a name for the SSH key.
    • In the Public Key field, type the path of the public key file or click Browse to locate the public key file.

      Figure 3.19. Completed Fields for Adding an Existing SSH Public Key

      Completed Fields for Adding an Existing SSH Public Key
  4. Click the SSH2 Preferences link.
  5. In the Private keys field, click Add Private Key and locate the private key file.
  6. Click Apply and click OK to close the Preferences window.
  7. Click Finish and click OK.

3.6.3. Option C: Specifying an Existing Private Key File

When using a public key that is already uploaded to OpenShift Online, you must ensure the location of the corresponding private key is set in the IDE preferences. This option may be applicable if you are an existing OpenShift Online user and you have not yet accessed OpenShift Online from your IDE workspace or you are using multiple IDE workspaces.

To specify an existing private key file, complete the following steps:

  1. Click WindowPreferencesGeneralNetwork ConnectionsSSH2.
  2. In the General tab, click Add Private Key and locate the private key file.
  3. Click Apply and click OK to close the Preferences window.

3.6.4. Did You Know?

  • To quickly open the OpenShift Explorer view, in the IDE Quick Access field type OpenShift Explorer and choose OpenShift Explorer view from the list of items.
  • For added security, you can add a passphrase to the private SSH keys associated with your OpenShift account when you create them. You must enter the passphrase for the specific key for each OpenShift Tools action that uses the SSH key for authentication with OpenShift Online.
  • IDE preferences are workspace specific and therefore you must specify private key location under Preferences for each workspace.
  • You can remove an existing public SSH key from your OpenShift Online account with the Manage SSH Keys wizard. Note that this only disassociates keys with your OpenShift account. The files associated with a removed SSH key pair still exist in the local location where they were generated and the private key is still set in the IDE preferences.
  • If you are using the OpenShift Online web interface or RHC client tools to manage SSH keys simultaneously with OpenShift Tools, the information specified by OpenShift Tools about keys may be out of sync. You can resync the information in the Manage SSH Keys wizard with the Refresh button.
  • You can change the default location used by the IDE to store newly created SSH keys. Click WindowPreferencesGeneralNetwork ConnectionsSSH2. In the General tab, in the SSH2 home field type the new location.

3.6.5. Troubleshoot SSH Key Issues

3.6.5.1. “You have no SSH public keys in your OpenShift account”

Error Message

You have no SSH public keys in your OpenShift account user@example.com yet, please add your key(s) or create new one(s).

Figure 3.20. No SSH Keys Window Displaying the Error Message

No SSH Key Window Displaying the Error Message

Issue

There are no SSH public keys assigned to your OpenShift account. After you have connected to OpenShift Online from the IDE, the No SSH Keys window appears informing you that there are no SSH public keys associated with your account.

Resolution

In the No SSH Keys window, click Add Existing or New and add an SSH public key to your OpenShift Online account as detailed in Option A, Create and Use a New SSH Key Pair and Option B, Use an Existing SSH Key Pair above.

3.6.5.2. “Please make sure that you added your private key to the ssh preferences.”

Error Message

Could not clone the repository. Authentication failed. Please make sure that you added your private key to the ssh preferences.

Figure 3.21. Problem Occured Window Displaying the Error Message

Problem Occured Window Displaying the Error Message

Issue

An SSH public key is associated with your OpenShift Online account but the IDE cannot locate the companion private key. Consequently, the IDE cannot complete actions for the OpenShift applications associated with your account. This error may be encountered when creating new OpenShift applications or importing existing OpenShift applications into the IDE.

Resolution

Click OK to close the Problem Occurred window. The OpenShift Application wizard opens. Click the SSH2 Preferences link to add the private key as detailed in Option C, Specify an Existing Private Key Location above.