Skip to content

Commit 33ae7d9

Browse files
committed
first commit
0 parents  commit 33ae7d9

23 files changed

+1655
-0
lines changed

Dockerfile-cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from openjdk:16
2+
ARG MYSQL_PASSWORD
3+
4+
WORKDIR /usr/app
5+
COPY ms/mysql-connector-java-5.1.45-bin.jar lib/
6+
ENV CLASSPATH=.:lib/mysql-connector-java-5.1.45-bin.jar:${CLASSPATH}
7+
8+
COPY ms/Configuration-tmplt.java ./
9+
RUN sed "s/<PASSWORD>/${MYSQL_PASSWORD}/g" < Configuration-tmplt.java > Configuration.java
10+
RUN rm Configuration-tmplt.java
11+
12+
COPY ms/CreateServices.java ms/CreateServicesAI.java ./
13+
RUN javac *.java
14+
15+
CMD java CreateServices

Dockerfile-msc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from openjdk:16
2+
3+
WORKDIR /usr/app
4+
5+
COPY ms/Configuration-tmplt.java ./
6+
RUN sed "s/<PASSWORD>//g" < Configuration-tmplt.java > Configuration.java
7+
RUN rm Configuration-tmplt.java
8+
COPY ms/registry.properties ms/OrdersUI.java ms/MSClientAPI.java ms/CreateServicesAI.java ms/RetrieveServicesAI.java ./
9+
RUN javac *.java
10+
11+
CMD java OrdersUI

Dockerfile-rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from openjdk:16
2+
ARG MYSQL_PASSWORD
3+
4+
WORKDIR /usr/app
5+
COPY ms/mysql-connector-java-5.1.45-bin.jar lib/
6+
ENV CLASSPATH=.:lib/mysql-connector-java-5.1.45-bin.jar:${CLASSPATH}
7+
8+
COPY ms/Configuration-tmplt.java ./
9+
RUN sed "s/<PASSWORD>/${MYSQL_PASSWORD}/g" < Configuration-tmplt.java > Configuration.java
10+
RUN rm Configuration-tmplt.java
11+
12+
COPY ms/RetrieveServices.java ms/RetrieveServicesAI.java ./
13+
RUN javac *.java
14+
15+
CMD java RetrieveServices

Dockerfile-ws

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from node:10
2+
ARG MYSQL_PASSWORD
3+
WORKDIR /usr/app
4+
RUN npm install express
5+
RUN npm install mysql
6+
RUN npm install body-parser
7+
RUN npm -y init
8+
9+
COPY ws/REST.js ws/
10+
COPY ws/Server.js ws/
11+
COPY ws/config ws/config
12+
WORKDIR /usr/app/ws
13+
RUN sed "s/<PASSWORD>/${MYSQL_PASSWORD}/g" > config/mysql.config.json < config/mysql.config.json-tmplt
14+
RUN mv ../package.json .
15+
RUN npm install
16+
17+
CMD [ "node", "Server.js" ]

init-db/dbtemplate.sql

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
-- MySQL dump 10.13 Distrib 5.7.21, for macos10.13 (x86_64)
2+
--
3+
-- Host: localhost Database: orderinfo
4+
-- ------------------------------------------------------
5+
-- Server version 5.7.21
6+
7+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
8+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
9+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
10+
/*!40101 SET NAMES utf8 */;
11+
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
12+
/*!40103 SET TIME_ZONE='+00:00' */;
13+
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
14+
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
15+
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
16+
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
17+
18+
--
19+
-- Table structure for table `orders`
20+
--
21+
22+
DROP TABLE IF EXISTS `orders`;
23+
/*!40101 SET @saved_cs_client = @@character_set_client */;
24+
/*!40101 SET character_set_client = utf8 */;
25+
CREATE TABLE `orders` (
26+
`order_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
27+
`order_date` date DEFAULT NULL,
28+
`first_name` varchar(20) DEFAULT NULL,
29+
`last_name` varchar(20) DEFAULT NULL,
30+
`address` varchar(80) DEFAULT NULL,
31+
`phone` varchar(15) DEFAULT NULL,
32+
PRIMARY KEY (`order_id`)
33+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
34+
/*!40101 SET character_set_client = @saved_cs_client */;
35+
36+
--
37+
-- Dumping data for table `orders`
38+
--
39+
40+
LOCK TABLES `orders` WRITE;
41+
/*!40000 ALTER TABLE `orders` DISABLE KEYS */;
42+
/*!40000 ALTER TABLE `orders` ENABLE KEYS */;
43+
UNLOCK TABLES;
44+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
45+
46+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
47+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
48+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
49+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
50+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
51+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
52+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
53+
54+
-- Dump completed on 2018-02-16 17:26:40

ms/Configuration-tmplt.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import java.rmi.registry.LocateRegistry;
2+
import java.rmi.registry.Registry;
3+
import java.rmi.RemoteException;
4+
5+
public interface Configuration {
6+
public static final String MYSQL_PASSWORD="<PASSWORD>";
7+
8+
static String getRemoteHost() {
9+
final String key = "RMI_REMOTE_HOST";
10+
final String host = System.getenv(key);
11+
12+
if (host == null) throw new IllegalStateException(String.format("env var [%s] is not set", key));
13+
14+
return host;
15+
}
16+
17+
static int getRemotePort() {
18+
final String key = "RMI_REMOTE_PORT";
19+
final String port = System.getenv(key);
20+
21+
if (port == null) throw new IllegalStateException(String.format("env var [%s] is not set", key));
22+
23+
return Integer.valueOf(port);
24+
}
25+
26+
static Registry getRegistry() throws RemoteException {
27+
System.out.println("Getting registry for " + getRemoteHost() + ":" + getRemotePort());
28+
Registry registry;
29+
registry = LocateRegistry.getRegistry(getRemoteHost(), getRemotePort());
30+
return registry;
31+
}
32+
33+
static Registry createRegistry() throws RemoteException {
34+
Registry registry;
35+
try {
36+
registry = LocateRegistry.createRegistry(getRemotePort());
37+
}
38+
catch (Exception e) {
39+
registry = LocateRegistry.getRegistry(getRemotePort());
40+
}
41+
return registry;
42+
}
43+
44+
static String getMySqlHost() {
45+
final String key = "MYSQL_REMOTE_HOST";
46+
final String host = System.getenv(key);
47+
48+
if (host == null) throw new IllegalStateException(String.format("env var [%s] is not set", key));
49+
50+
return host;
51+
}
52+
53+
static int getMySqlPort() {
54+
final String key = "MYSQL_REMOTE_PORT";
55+
final String port = System.getenv(key);
56+
57+
if (port == null) throw new IllegalStateException(String.format("env var [%s] is not set", key));
58+
59+
return Integer.valueOf(port);
60+
}
61+
62+
static String getJDBCConnection() {
63+
return "jdbc:mysql://" + getMySqlHost() + ":" + getMySqlPort() + "/ms_orderinfo?autoReconnect=true&useSSL=false";
64+
}
65+
}

ms/CreateServices.java

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/******************************************************************************************************************
2+
* File: CreateServices.java
3+
* Course: 17655
4+
* Project: Assignment A3
5+
* Copyright: Copyright (c) 2018 Carnegie Mellon University
6+
* Versions:
7+
* 1.0 February 2018 - Initial write of assignment 3 (ajl).
8+
*
9+
* Description: This class provides the concrete implementation of the create micro services. These services run
10+
* in their own process (JVM).
11+
*
12+
* Parameters: None
13+
*
14+
* Internal Methods:
15+
* String newOrder() - creates an order in the ms_orderinfo database from the supplied parameters.
16+
*
17+
* External Dependencies:
18+
* - rmiregistry must be running to start this server
19+
* = MySQL
20+
- orderinfo database
21+
******************************************************************************************************************/
22+
import java.rmi.RemoteException;
23+
import java.rmi.server.UnicastRemoteObject;
24+
import java.rmi.registry.Registry;
25+
import java.sql.*;
26+
27+
public class CreateServices extends UnicastRemoteObject implements CreateServicesAI
28+
{
29+
// Set up the JDBC driver name and database URL
30+
static final String JDBC_CONNECTOR = "com.mysql.jdbc.Driver";
31+
static final String DB_URL = Configuration.getJDBCConnection();
32+
33+
// Set up the orderinfo database credentials
34+
static final String USER = "root";
35+
static final String PASS = Configuration.MYSQL_PASSWORD;
36+
37+
// Do nothing constructor
38+
public CreateServices() throws RemoteException {}
39+
40+
// Main service loop
41+
public static void main(String args[])
42+
{
43+
// What we do is bind to rmiregistry, in this case localhost, port 1099. This is the default
44+
// RMI port. Note that I use rebind rather than bind. This is better as it lets you start
45+
// and restart without having to shut down the rmiregistry.
46+
47+
try
48+
{
49+
CreateServices obj = new CreateServices();
50+
51+
Registry registry = Configuration.createRegistry();
52+
registry.bind("CreateServices", obj);
53+
54+
String[] boundNames = registry.list();
55+
System.out.println("Registered services:");
56+
for (String name : boundNames) {
57+
System.out.println("\t" + name);
58+
}
59+
// Bind this object instance to the name RetrieveServices in the rmiregistry
60+
// Naming.rebind("//" + Configuration.getRemoteHost() + ":1099/CreateServices", obj);
61+
62+
} catch (Exception e) {
63+
64+
System.out.println("CreateServices binding err: " + e.getMessage());
65+
e.printStackTrace();
66+
}
67+
68+
} // main
69+
70+
71+
// Inplmentation of the abstract classes in RetrieveServicesAI happens here.
72+
73+
// This method add the entry into the ms_orderinfo database
74+
75+
public String newOrder(String idate, String ifirst, String ilast, String iaddress, String iphone) throws RemoteException
76+
{
77+
// Local declarations
78+
79+
Connection conn = null; // connection to the orderinfo database
80+
Statement stmt = null; // A Statement object is an interface that represents a SQL statement.
81+
String ReturnString = "Order Created"; // Return string. If everything works you get an 'OK' message
82+
// if not you get an error string
83+
try
84+
{
85+
// Here we load and initialize the JDBC connector. Essentially a static class
86+
// that is used to provide access to the database from inside this class.
87+
88+
Class.forName(JDBC_CONNECTOR);
89+
90+
//Open the connection to the orderinfo database
91+
92+
//System.out.println("Connecting to database...");
93+
conn = DriverManager.getConnection(DB_URL,USER,PASS);
94+
95+
// Here we create the queery Execute a query. Not that the Statement class is part
96+
// of the Java.rmi.* package that enables you to submit SQL queries to the database
97+
// that we are connected to (via JDBC in this case).
98+
99+
stmt = conn.createStatement();
100+
101+
String sql = "INSERT INTO orders(order_date, first_name, last_name, address, phone) VALUES (\""+idate+"\",\""+ifirst+"\",\""+ilast+"\",\""+iaddress+"\",\""+iphone+"\")";
102+
103+
// execute the update
104+
105+
stmt.executeUpdate(sql);
106+
107+
// clean up the environment
108+
109+
stmt.close();
110+
conn.close();
111+
stmt.close();
112+
conn.close();
113+
114+
} catch(Exception e) {
115+
116+
ReturnString = e.toString();
117+
}
118+
119+
return(ReturnString);
120+
121+
} //retrieve all orders
122+
123+
} // RetrieveServices

ms/CreateServicesAI.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/******************************************************************************************************************
2+
* File: CreateServicesAI.java
3+
* Course: 17655
4+
* Project: Assignment A3
5+
* Copyright: Copyright (c) 2018 Carnegie Mellon University
6+
* Versions:
7+
* 1.0 February 2018 - Initial write of assignment 3 (ajl).
8+
*
9+
* Description: This class provides the abstract interface for the create micro services, CreateServices.
10+
* The implementation of these abstract interfaces can be found in the CreateServices.java class.
11+
* The micro services are partitioned as Create, Retrieve, Update, Delete (CRUD) service packages. Each service
12+
* is its own process (eg. executing in a separate JVM). It would be a good practice to follow this convention
13+
* when adding and modifying services. Note that services can be duplicated and differentiated by IP
14+
* and/or port# they are hosted on. For this assignment, create and retrieve services have been provided and are
15+
* services are hosted on the local host, on the default RMI port (1099).
16+
*
17+
* Parameters: None
18+
*
19+
* Internal Methods:
20+
* String newOrder() - creates a new order in the orderinfo database
21+
*
22+
* External Dependencies: None
23+
******************************************************************************************************************/
24+
25+
import java.rmi.*;
26+
27+
public interface CreateServicesAI extends java.rmi.Remote
28+
{
29+
/*******************************************************
30+
* Creates a new order from the provided arguments.
31+
* Returns an OK message or an error string.
32+
*******************************************************/
33+
34+
String newOrder(String Date, String FirstName, String LastName, String Address, String Phone) throws RemoteException;
35+
36+
}

0 commit comments

Comments
 (0)