- 
                Notifications
    You must be signed in to change notification settings 
- Fork 73
Helidon v2.1.0 #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Helidon v2.1.0 #36
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            16 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      29b00cb
              
                Create serial-config.properties
              
              
                aberinnj f7f3794
              
                Update pom.xml
              
              
                aberinnj eea3d1b
              
                Added appdatasource
              
              
                aberinnj 7f75e39
              
                Added serial-config
              
              
                aberinnj 56c8a3e
              
                Updated database access to support other methods of connecting
              
              
                aberinnj 58d5669
              
                Updated manifest to support new environment variables
              
              
                aberinnj 1c6ecee
              
                Removing target files
              
              
                aberinnj 3e55afe
              
                Sample SQL file
              
              
                aberinnj 82ef51e
              
                Added README
              
              
                aberinnj 41b4879
              
                updated README
              
              
                aberinnj c0fe59d
              
                Updated port
              
              
                aberinnj f4a1faa
              
                Updated scripts to reflect new table
              
              
                aberinnj 86ca738
              
                Updated formatting and indentation
              
              
                aberinnj 9d39d70
              
                Formatted file
              
              
                aberinnj 832e3dc
              
                Updated indentation
              
              
                aberinnj feb456a
              
                Updated Java files
              
              
                aberinnj File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| # Todolist Helidon backend | ||
|  | ||
| Todolist application backend built with Helidon SE, using Oracle JDBC | ||
| - __App Version `v2.1.0`__ | ||
| - __Oracle JDBC Version `v23.4.0.24.05`__ | ||
| - __Helidon SE Version `v2.4.2`__ | ||
|  | ||
| ## Environment Variables | ||
| The following environment variables are expected by the application. | ||
| In order to successfully run the application, the environment variables below are __REQUIRED__. | ||
|  | ||
| | Variable | Name | Default | Description | | ||
| |---------------------|-------------------|---------|-----------------------------------------------------------------| | ||
| | `database.url` | Database URL | - | Connection to URL, in the form of `jdbc:oracle:thin:@<details>` | | ||
| | `database.user` | Database User | - | Database user with access to the necessary tables | | ||
| | `database.password` | Database Password | - | Database user credentials | | ||
|  | ||
| ## API Endpoints | ||
|  | ||
| The following endpoints are endpoints used by the application. | ||
|  | ||
| | Method | REST Endpoint | Sample Data | Description | | ||
| |--------|-------------------------------------------|----------------------------------------|-----------------------| | ||
| | GET | `http://localhost:8080/api/todolist` | - | Retrieves all Todos | | ||
| | POST | `http://localhost:8080/api/todolist` | `{"description" : "Second new task!"}` | Saves a new Todo | | ||
| | GET | `http://localhost:8080/api/todolist/{id}` | - | Retrieves a Todo item | | ||
| | PUT | `http://localhost:8080/api/todolist/{id}` | `{"description": "...", "done": true}` | Updates a Todo item | | ||
| | DELETE | `http://localhost:8080/api/todolist/{id}` | - | Deletes a Todo item | | ||
|  | ||
|  | ||
| ## SQL Schema, Tables and Queries | ||
|  | ||
| The application expects and makes use of the following: | ||
|  | ||
| - __Database Schemas__: `TODOOWNER` | ||
| - __Database Tables__: `TODOITEM` | ||
| - __Database Queries and Privilege__: | ||
| - `select, insert, update, delete` on `TODOOWNER.TODOITEM` | ||
|  | ||
|  | ||
| # Building the Application | ||
| The application uses Maven to build and manage the project with its dependencies. | ||
| Since the [Dockerfile](./src/main/docker/Dockerfile) expects the JAR, you need to run mvn first. | ||
| ```bash | ||
| mvn clean package | ||
| ``` | ||
|  | ||
| When building for docker, you can use the following command: | ||
| ```bash | ||
| docker build -f src/main/docker/Dockerfile -t <image> . | ||
| ``` | ||
|  | ||
| # Deploying to Kubernetes | ||
| To deploy the application on Kubernetes, | ||
| the environment variables and image must be replaced. | ||
|  | ||
| For example, you can create the following manifest.yaml file: | ||
| ```yaml | ||
| # manifest | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: backend-deployment | ||
| labels: | ||
| app: backendapp | ||
| spec: | ||
| replicas: 1 | ||
| selector: | ||
| matchLabels: | ||
| app: backendapp | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: backendapp | ||
| spec: | ||
| containers: | ||
| - name: app | ||
| image: example:v1 # update with your container image | ||
| env: | ||
| - name: database.user | ||
| value: myUser # update with your database user | ||
| - name: database.url | ||
| value: "jdbc:oracle:thin:@<details>" # update with your database URL | ||
| - name: database.password | ||
| valueFrom: | ||
| secretKeyRef: | ||
| name: myDatabasePWDSecret # update with your database secret | ||
| key: password | ||
| ports: | ||
| - containerPort: 8080 | ||
|  | ||
| # if database wallet is required | ||
| volumeMounts: | ||
| - name: creds | ||
| mountPath: /app/creds # update with the right path to the wallet | ||
| # end if | ||
|  | ||
| restartPolicy: Always | ||
|  | ||
| # if database wallet is required | ||
| volumes: | ||
| - name: creds | ||
| secret: | ||
| secretName: db-wallet-secret # update with the actual secret | ||
| # end if | ||
|  | ||
|  | ||
| --- | ||
|  | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: backend-service | ||
| spec: | ||
| type: ClusterIP | ||
| ports: | ||
| - port: 8080 | ||
| targetPort: 8080 | ||
| selector: | ||
| app: backendapp | ||
| ``` | ||
|  | ||
| This configuration requires the following secret to be created: | ||
| ```bash | ||
| kubectl create secret generic myDatabasePWDSecret --from-literal=password=<value> | ||
| ``` | ||
|  | ||
| If a wallet is necessary, you can run the following command to create the wallet secret | ||
| ```bash | ||
| kubectl create secret generic wallet --from-file=<wallet_location> | ||
| ``` | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| CREATE TABLE TODOOWNER.TODOITEM ( | ||
| ID NUMBER GENERATED ALWAYS AS IDENTITY, | ||
| DESCRIPTION VARCHAR2(4000), | ||
| CREATION_TS TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, | ||
| DONE NUMBER(1, 0) DEFAULT 0, | ||
| PRIMARY KEY (ID) | ||
| ); | ||
|  | ||
| INSERT INTO TODOOWNER.TODOITEM (DESCRIPTION) VALUES ('My first task!'); | 
        
          
          
            71 changes: 71 additions & 0 deletions
          
          71 
        
  mtdrworkshop/backend/src/main/java/com/oracle/database/AppDatasource.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| ## MyToDoReact version 2.1.0 | ||
| ## | ||
| ## Copyright (c) 2024 Oracle, Inc. | ||
| ## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ | ||
| */ | ||
| package com.oracle.database; | ||
|  | ||
| import io.helidon.config.Config; | ||
| import oracle.ucp.jdbc.PoolDataSource; | ||
| import oracle.ucp.jdbc.PoolDataSourceFactory; | ||
|  | ||
| import javax.sql.DataSource; | ||
| import java.sql.Connection; | ||
| import java.sql.SQLException; | ||
|  | ||
| public class AppDatasource { | ||
|  | ||
| // connection pooling using UCP | ||
| private final PoolDataSource pds; | ||
| private static AppDatasource instance = null; | ||
|  | ||
| // static get | ||
| public synchronized static AppDatasource get(Config c) { | ||
| if (instance == null) { | ||
| instance = new AppDatasource(c); | ||
| } | ||
| return instance; | ||
| } | ||
|  | ||
| // constructor, initialize datasource | ||
| private AppDatasource(Config c) { | ||
| this.pds = PoolDataSourceFactory.getPoolDataSource(); | ||
| String url = c.get("url").asString().orElse(""); | ||
| String username = c.get("user").asString().orElse(""); | ||
| String password = c.get("password").asString().orElse(""); | ||
|  | ||
| try { | ||
|  | ||
| // In this application, we don't set any init, min or max size in UCP. We | ||
| // also don't start the pool explicitly. This means that the very first | ||
| // connection request will start the pool. The default maximum pool size | ||
| // is MAX_INT which isn't appropriate and should be configured properly in | ||
| // production. | ||
| this.pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource"); | ||
| this.pds.setConnectionPoolName("JDBC_UCP_POOL"); | ||
| this.pds.setInactiveConnectionTimeout(60); | ||
| this.pds.setMaxStatements(10); | ||
|  | ||
| // if provided, set | ||
| if (!url.isEmpty()) { | ||
| this.pds.setURL(url); | ||
| } | ||
| if (!username.isEmpty()) { | ||
| this.pds.setUser(username); | ||
| } | ||
| if (!password.isEmpty()) { | ||
| this.pds.setPassword(password); | ||
| } | ||
|  | ||
| } catch (SQLException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|  | ||
| // retrieve connection | ||
| public Connection getConnection() throws SQLException { | ||
| return this.pds.getConnection(); | ||
| } | ||
|  | ||
| } | ||
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.