From b21584f249de08054d908b7f929993678df9d2be Mon Sep 17 00:00:00 2001 From: Jacob Berger Date: Tue, 7 Jul 2020 13:41:41 -0400 Subject: [PATCH 1/2] added developing a microservice section to the existing CRW guide. Signed-off-by: Jacob Berger --- docs/_guides/codewind-crw-quick-guide.md | 111 ++++++++++++++++++++++- 1 file changed, 108 insertions(+), 3 deletions(-) diff --git a/docs/_guides/codewind-crw-quick-guide.md b/docs/_guides/codewind-crw-quick-guide.md index 61015723..7bfc3ef5 100644 --- a/docs/_guides/codewind-crw-quick-guide.md +++ b/docs/_guides/codewind-crw-quick-guide.md @@ -5,14 +5,13 @@ title: "Getting Started with Codewind in CodeReady Workspaces" categories: guides description: "Use CodeReady Workspaces to develop cloud-native applications from an OpenShift cluster." permalink: codewind-crw-quick-guide.html -duration: 10 minutes +duration: 15 minutes keywords: Codewind, CodeReady Workspaces, OpenShift -objectives: ["Install CodeReady Workspaces and Codewind.", "Create a Codewind workspace within CodeReady Workspaces."] +objectives: ["Install CodeReady Workspaces and Codewind.", "Create a Codewind workspace within CodeReady Workspaces.", Develop a simple microservice with the Codewind workspace."] icon: images/learn/icon_cloud.svg --- ## Overview - Use Eclipse Codewind to develop microservice applications from application stacks in an integrated developer environment (IDE). CodeReady Workspaces provides a containerized IDE for cloud-native application development on an OpenShift cluster. ## Developing with CodeReady Workspaces @@ -124,11 +123,117 @@ After you set up Codewind, log in to your CodeReady Workspaces account and creat 6\. Click **Create & Open**. +### Configuring Codewind to use application stacks +Configure Codewind to use Appsody templates so you can focus exclusively on your code. Complete the following steps to select the Appsody templates: + +1. Select **Codewind**. +2. Right-click **Projects**. +3. Select **Template Source Manager**. +4. Enable **Appsody Stacks - incubator** and **Default templates**. + +After you configured Codewind to use Appsody templates, continue to develop your microservice within Codewind. + +### Creating an Appsody project +Throughout the application lifestyle, Appsody helps you develop containerized applications and maximize containers curated for your usage. + +1. Under the Explorer pane, select **Codewind**. +2. Expand **Codewind** by clicking the drop-down arrow. +3. Hover over the **Projects** entry underneath Codewind in the Explorer pane, and press the **+** icon to create a project. + * **Note:** Make sure that Docker is running. Otherwise, you get an error. +4. Choose the **Appsody Open Liberty default template (Appsody Stacks - incubator)**. +5. Name your project **appsody-calculator**. + * If you don't see Appsody templates, find and select **Template Source Manager** and enable **Appsody Stacks - incubator**. + * The templates are refreshed, and the Appsody templates are available. +6. Press **Enter**. + * To monitor your project's progress, right-click your project, and select **Show all logs**. Then, an **Output** tab is displayed where you see your project's build logs. + +Your project is complete when you see that your application status is running and your build status is successful. + +### Accessing the application endpoint in a browser +1. Return to your project under the **Explorer** pane. +2. Select the Open App icon next to your project's name, or right-click your project and select **Open App**. + +Your application is now opened in a browser, showing the welcome to your Appsody microservice page. + +### Adding a REST service to your application + 1. Go to your project's workspace under the **Explorer** pane. + 2. Go to `src`>`main`>`java`>`dev`>`appsody`>`starter`. + 3. Right-click **starter** and select **New File**. + 4. Create a file, name it `Calculator.java`, and press **Enter**. This file is your JAX-RS resource. + 5. Before you input any code, make sure that the file is empty. + 6. Populate the file with the following code and then **save** the file: + +```java +package dev.appsody.starter; + +import javax.ws.rs.core.Application; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import javax.ws.rs.PathParam; + +@Path("/calculator") +public class Calculator extends Application { + + @GET + @Path("/aboutme") + @Produces(MediaType.TEXT_PLAIN) + public String aboutme() { + return "You can add (+), subtract (-), and multiply (*) with this simple calculator."; + } + + @GET + @Path("/{op}/{a}/{b}") + @Produces(MediaType.TEXT_PLAIN) + public Response calculate(@PathParam("op") String op, @PathParam("a") String a, @PathParam("b") String b) { + int numA = Integer.parseInt(a); + int numB = Integer.parseInt(b); + + switch (op) { + case "+": + return Response.ok(a + "+" + b + "=" + (Integer.toString((numA + numB)))).build(); + + case "-": + return Response.ok(a + "-" + b + "=" + (Integer.toString((numA - numB)))).build(); + + case "*": + return Response.ok(a + "*" + b + "=" + (Integer.toString((numA * numB)))).build(); + + default: + return Response.ok("Invalid operation. Please Try again").build(); + } + } +} +``` + +Any changes that you make to your code are automatically built and redeployed by Codewind, and you can view them in your browser. + +### Working with the example calculator microservice +You now can work with the example calculator microservice. + +1. Use the URL that you saw when you first opened the application. +2. Make sure to remove the `< >` symbol in the URL. +3. `/starter/calculator/aboutme` +4. You see the following response: + +``` +You can add (+), subtract (-), and multiply (*) with this simple calculator. +``` + +You can also try a few of the sample calculator functions: + +* `/starter/calculator/{op}/{a}/{b}`, where you can input one of the available operations `(+, _, *)`, and an integer a, and an integer b. +* So for `/starter/calculator/+/10/3` you see: `10+3=13`. + ## What you have learned Now that you have completed this quick guide, you have learned to: 1. Install CodeReady Workspaces and Codewind. 2. Create a Codewind workspace within CodeReady Workspaces. +3. Develop a simple microservice with the Codewind workspace. ## Next Steps See other quick guides to learn how to develop with Codewind: From 2711104cc945f3958737b80325ccbc83261cde7c Mon Sep 17 00:00:00 2001 From: Jacob Berger Date: Wed, 8 Jul 2020 09:04:27 -0400 Subject: [PATCH 2/2] added quotation to objecties in metadata Signed-off-by: Jacob Berger --- docs/_guides/codewind-crw-quick-guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_guides/codewind-crw-quick-guide.md b/docs/_guides/codewind-crw-quick-guide.md index 7bfc3ef5..4e5d8a66 100644 --- a/docs/_guides/codewind-crw-quick-guide.md +++ b/docs/_guides/codewind-crw-quick-guide.md @@ -7,7 +7,7 @@ description: "Use CodeReady Workspaces to develop cloud-native applications from permalink: codewind-crw-quick-guide.html duration: 15 minutes keywords: Codewind, CodeReady Workspaces, OpenShift -objectives: ["Install CodeReady Workspaces and Codewind.", "Create a Codewind workspace within CodeReady Workspaces.", Develop a simple microservice with the Codewind workspace."] +objectives: ["Install CodeReady Workspaces and Codewind.", "Create a Codewind workspace within CodeReady Workspaces.", "Develop a simple microservice with the Codewind workspace."] icon: images/learn/icon_cloud.svg ---