Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
0a7d8c6
added wercker.yml
derekoneil Nov 29, 2017
15eaf37
fixed wercker.yml
derekoneil Nov 29, 2017
f447901
fixed wercker.yml
derekoneil Nov 29, 2017
511477e
fixed wercker.yml
derekoneil Nov 29, 2017
6714f71
fixed wercker.yml
derekoneil Nov 29, 2017
1f3cfba
fixed wercker.yml
derekoneil Nov 29, 2017
72d5b37
Create kubernetes.yml.template
derekoneil Nov 30, 2017
706c6f3
Update wercker.yml
derekoneil Nov 30, 2017
c1b6da2
Update wercker.yml
derekoneil Nov 30, 2017
3475bdf
Update wercker.yml
derekoneil Nov 30, 2017
33b810b
Update kubernetes.yml.template
derekoneil Nov 30, 2017
05db223
Update wercker.yml
derekoneil Nov 30, 2017
8006db7
Update kubernetes.yml.template
derekoneil Nov 30, 2017
bfe8317
Update wercker.yml
derekoneil Nov 30, 2017
ea678ee
update main.java
derekoneil Dec 1, 2017
61c4351
update wercker.yml
derekoneil Dec 1, 2017
81ffbc0
update time string
derekoneil Dec 1, 2017
270ac91
Update kubernetes.yml.template
derekoneil Dec 1, 2017
224242c
Update kubernetes.yml.template
derekoneil Dec 1, 2017
a6dd1e2
update k8s template
derekoneil Dec 1, 2017
3f09fca
Update wercker.yml
derek-oneil Dec 14, 2017
6be22ec
Merge pull request #1 from derek-oneil/patch-1
derekoneil Dec 14, 2017
f37a129
Update wercker.yml
derekoneil Dec 14, 2017
4746490
Update wercker.yml
derekoneil Dec 18, 2017
6e3b294
Update kubernetes.yml.template
derekoneil Dec 18, 2017
643cad9
Update wercker.yml
derekoneil Dec 19, 2017
3167978
Update wercker.yml
derekoneil Dec 19, 2017
6668be3
Update wercker.yml
derekoneil Dec 19, 2017
80906ee
Update kubernetes.yml.template
derekoneil Dec 20, 2017
c41a19a
Rename wercker.yml to wercker.yml.final
derekoneil Dec 20, 2017
f707d2a
Create wercker.yml
derekoneil Dec 20, 2017
b7b7f50
Update wercker.yml
derekoneil Dec 20, 2017
b83d857
Rename kubernetes.yml.template to kubernetes.yml.template.final
derekoneil Dec 21, 2017
e37621d
Create kubernetes.yml.template
derekoneil Dec 22, 2017
68c82c0
Update wercker.yml
derekoneil Dec 22, 2017
3548bc8
added product catalog kubernetes yml
derekoneil Jan 2, 2018
c812ca7
Merge remote-tracking branch 'origin/master'
derekoneil Jan 2, 2018
11529ff
Update StaticTweets.java
derekoneil Jan 4, 2018
0aa96dc
Update StaticTweets.java
derekoneil Jan 4, 2018
4765088
Update kubernetes.yml.template
derekoneil Jan 4, 2018
f31cf7f
Update kubernetes.yml.template
derekoneil Jan 4, 2018
2ac3276
Update kubernetes.yml.template
derekoneil Jan 4, 2018
71bda32
Update kubernetes.yml.template
derekoneil Jan 4, 2018
652585f
Update kubernetes.yml.template
derekoneil Jan 4, 2018
a90e963
Update Main.java
derekoneil Jan 4, 2018
cbe3f69
Update kubernetes.yml.template
derekoneil Jan 5, 2018
ae5d999
Update kubernetes.yml.template
derekoneil Jan 5, 2018
20fcb8d
Update kubernetes.yml.template
derekoneil Jan 8, 2018
e2c2f96
update template
derekoneil Jan 9, 2018
5d5c6e3
Update kubernetes.yml.template
derekoneil Jan 9, 2018
e0afea6
Update kubernetes.yml.template
derekoneil Jan 9, 2018
e168101
Update kubernetes.yml.template
derekoneil Jan 9, 2018
107c808
update java
derekoneil Jan 9, 2018
a71e17b
update java
derekoneil Jan 9, 2018
00d61e9
Update kubernetes.yml.template
derekoneil Jan 9, 2018
fca53f6
Update kubernetes.yml.template
derekoneil Jan 9, 2018
5323b05
Update kubernetes.yml.template
derekoneil Jan 9, 2018
dd78d60
Update kubernetes.yml.template
derekoneil Jan 9, 2018
4e482ae
Update kubernetes.yml.template
derekoneil Jan 9, 2018
e561ce7
Update kubernetes.yml.template
derekoneil Jan 9, 2018
e798402
Update kubernetes.yml.template
derekoneil Jan 9, 2018
aea8501
Update kubernetes.yml.template
derekoneil Jan 10, 2018
02a106e
Update kubernetes.yml.template
derekoneil Jan 10, 2018
bb49470
Update kubernetes.yml.template
derekoneil Jan 10, 2018
620e857
Update alpha-office-product-catalog.kubernetes.yml
derekoneil Jan 16, 2018
9a8fa77
Update alpha-office-product-catalog.kubernetes.yml
derekoneil Jan 16, 2018
e4cad53
reinsert comments around search function
derekoneil Jan 16, 2018
d5df666
Delete wercker.yml
derekoneil Jan 16, 2018
2b0fe7b
Update wercker.yml.final
derekoneil Jan 16, 2018
835da50
Delete kubernetes.yml.template
derekoneil Jan 16, 2018
4449fe1
Update kubernetes.yml.template.final
derekoneil Jan 16, 2018
10c1fd1
Update alpha-office-product-catalog.kubernetes.yml
derekoneil Jan 17, 2018
93648b7
Update alpha-office-product-catalog.kubernetes.yml
derekoneil Jan 17, 2018
d038596
testing
derekoneil Jan 18, 2018
0f7c595
Update StaticTweets.java
derekoneil Jan 18, 2018
263ae21
Update StaticTweets.java
derekoneil Jan 18, 2018
58c90df
Update StaticTweets.java
derekoneil Jan 18, 2018
fce3e0e
remove yml files
derekoneil Jan 18, 2018
2fcdc34
Delete kubernetes.yml.template
derekoneil Jan 24, 2018
b07fcef
Delete wercker.yml
derekoneil Jan 24, 2018
5ec846c
update readme
derekoneil Jan 24, 2018
8e5d9c9
Merge remote-tracking branch 'origin/master'
derekoneil Jan 24, 2018
30ed6cf
Update wercker.yml.final
derekoneil Feb 2, 2018
d7ae29d
Create wercker.yml
derekoneil Feb 2, 2018
005b7b5
Create kubernetes.yml
derekoneil Feb 5, 2018
1c20861
Rename kubernetes.yml to kubernetes.yml.template
derekoneil Feb 5, 2018
e2e4860
Delete wercker.yml
derekoneil Feb 5, 2018
1aaafbd
Delete kubernetes.yml.template
derekoneil Feb 5, 2018
37db41e
test search enable
derekoneil Jun 6, 2018
321c9ef
test search enable
derekoneil Jun 6, 2018
e13eda1
Delete wercker.yml
derekoneil Jun 6, 2018
3bd20c2
remove search functionality
derekoneil Jun 6, 2018
ec41038
specify jdk version
derekoneil Oct 16, 2018
128f09c
Update alpha-office-product-catalog.kubernetes.yml
derekoneil Oct 24, 2018
99a1e1c
Update alpha-office-product-catalog.kubernetes.yml
derekoneil Oct 24, 2018
c4900e1
fix maven build failure
derekoneil Nov 1, 2018
c5556e5
convert to nodeport
derekoneil Dec 3, 2018
0baba00
Merge branch 'master' of https://github.com/derekoneil/twitter-feed
derekoneil Dec 3, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build/
target/
.metadata
.wercker/
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
About
=====

This repository contains the code for the Twitter feed microservice that you will use during the [Oracle Container Native Application Development workshop](http://oracle.github.io/learning-library/workshops/container-native-development).
During the workshop you will Dockerize this Java microservice using Wercker, configure a CI/CD pipeline, and deploy the microservice to Oracle's managed Kubernetes service.


Build
=====

Expand All @@ -13,12 +20,4 @@ On successful build, you can run the app with `sh target/bin/start` which is a s
Deploy
======

Edit config.properties to set your target server, user id, password, and identity domain

Deploy the application archive using `deploy.sh`. This will create the service instance and deploy.


Redeploy
========

Once a service instance has been created, updated archives are deployed
You will create Wercker pipelines to build, publish, and deploy this microservice during the workshop.
45 changes: 45 additions & 0 deletions alpha-office-product-catalog.kubernetes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: product-catalog-app
labels:
commit: 4ca160fd05c003e5067fd6d9c8213656b24b962c
spec:
replicas: 2
selector:
matchLabels:
app: product-catalog-app
template:
metadata:
labels:
app: product-catalog-app
commit: 4ca160fd05c003e5067fd6d9c8213656b24b962c
spec:
containers:
- name: product-catalog-app-container
image: derekoneil/alpha-office-product-catalog:master-4ca160fd05c003e5067fd6d9c8213656b24b962c
imagePullPolicy: Always
ports:
- name: pc-app-port
containerPort: 80
protocol: TCP
imagePullSecrets:
- name: wercker
---
apiVersion: v1
kind: Service
metadata:
name: product-catalog-service
labels:
app: product-catalog-app
commit: 4ca160fd05c003e5067fd6d9c8213656b24b962c
spec:
ports:
- port: 30000
nodePort: 30000
targetPort: 80
selector:
app: product-catalog-app
commit: 4ca160fd05c003e5067fd6d9c8213656b24b962c
type: NodePort
---
Empty file modified deploy.sh
100644 → 100755
Empty file.
56 changes: 56 additions & 0 deletions kubernetes.yml.template.final
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: twitter-feed-v2
labels:
commit: ${WERCKER_GIT_COMMIT}
spec:
replicas: 2
selector:
matchLabels:
app: twitter-feed
template:
metadata:
labels:
app: twitter-feed
commit: ${WERCKER_GIT_COMMIT}
color: green
spec:
containers:
- name: twitter-feed
image: ${DOCKER_REPO}:${WERCKER_GIT_BRANCH}-${WERCKER_GIT_COMMIT}
imagePullPolicy: Always
ports:
- name: twitter-feed
containerPort: 8080
protocol: TCP
volumeMounts:
- name: podinfo
mountPath: /tmp
readOnly: false
volumes:
- name: podinfo
downwardAPI:
items:
- path: "labels"
fieldRef:
fieldPath: metadata.labels
imagePullSecrets:
- name: wercker
---
apiVersion: v1
kind: Service
metadata:
name: twitter-feed
labels:
app: twitter-feed
commit: ${WERCKER_GIT_COMMIT}
spec:
ports:
- port: 30000
targetPort: 8080
selector:
app: twitter-feed
color: green
type: ClusterIP
---
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
34 changes: 21 additions & 13 deletions src/main/java/com/example/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class Main {
*/
public static HttpServer startServer() throws UnknownHostException {
// Base URI the Grizzly HTTP server will listen on
System.out.println("Constructing URI: Hostname: " + System.getenv("HOSTNAME") + ", PORT: " + System.getenv("PORT"));
final Optional<String> port = Optional.ofNullable(System.getenv("PORT"));
final Optional<String> hostName = Optional.ofNullable(System.getenv("HOSTNAME"));
BASE_URI = "http://" + hostName.orElse("localhost") + ":" + port.orElse("8080") + "/";
Expand All @@ -50,32 +51,32 @@ public static HttpServer startServer() throws UnknownHostException {
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
public static void main(String[] args) throws IOException, InterruptedException {
final HttpServer server = startServer();

server.getServerConfiguration().addHttpHandler(new HttpHandler() {
// final SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
//
//
// @Override
// public void service(Request request, Response response) throws Exception {
// final Date now = new Date();
// final String formattedTime;
// synchronized (formatter) {
// formattedTime = formatter.format(now);
// }
//
//
// response.setContentType("text/plain");
// response.getWriter().write("The time using the old Java Date object is: " + formattedTime);
// }
@Override
public void service(Request request, Response response) throws Exception {
response.setContentType("text/plain");
response.getWriter().write("The time using the new java.time API in Java 8 is: " + LocalTime.now().truncatedTo(ChronoUnit.SECONDS));
response.getWriter().write("The NEW time using the new java.time API in Java 8 is: " + LocalTime.now().truncatedTo(ChronoUnit.SECONDS));
}
}, "/time");



// Add the StaticHttpHandler to serve static resources from the static folder
// server.getServerConfiguration().addHttpHandler(
// new StaticHttpHandler("src/main/resources/static/"), "static/");
Expand All @@ -93,10 +94,17 @@ public void service(Request request, Response response) throws Exception {
System.out.println(String.format("%sstatictweets</search> to see a set of stored static tweets", BASE_URI));
System.out.println(String.format("%sjarstatic/index.html to see the jar static resource", BASE_URI));
System.out.println();
System.out.println("Press enter to stop the server...");

System.in.read();
server.shutdown();
System.out.println("Press enter to NOT stop the server...");

try {
System.out.println("Joining current thread...");
Thread.currentThread().join();
System.out.println("Joined current thread.");
}
catch (Exception e) {
System.out.println("Caught Exception: " + e);
}
// System.in.read();
// server.shutdown();
}
}

56 changes: 43 additions & 13 deletions src/main/java/com/example/StaticTweets.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
package com.example;


import java.io.IOException;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.charset.Charset;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import org.glassfish.jersey.server.ChunkedOutput;

/**
* Root resource (exposed at "statictweets" path)
*/
@Path("statictweets")
public class StaticTweets {

private static SampleStreamExample example = new SampleStreamExample();

/**
Expand All @@ -28,9 +31,9 @@ public class StaticTweets {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getIt() {

final ChunkedOutput<String> output = new ChunkedOutput<String>(String.class);

runTask(output,null);
return Response.ok()
.entity(output)
Expand All @@ -45,28 +48,55 @@ public Response getIt() {
*
* @return String that will be returned as an application/json response.
*/
/* --- Remove this comment to allow for Filtered Searching
@Path("{search}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getItWithCount(@PathParam("search") final String search) {
public Response getItWithCount(@PathParam("search") String search) {
System.out.println("Searching for tweets containing: " + search);
final ChunkedOutput<String> output = new ChunkedOutput<String>(String.class);
search = ""; //---Remove this line to enable searching
runTask(output, search);
return Response.ok()
.entity(output)
.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT")
.build();


}

--- Remove this comment to allow for Filtered Searching */



@Path("color")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getColor() throws IOException {
System.out.println("Checking color");
String color = "yellow";
byte[] encoded = Files.readAllBytes(Paths.get("/tmp/labels"));
color = new String(encoded, Charset.defaultCharset());
Pattern p = Pattern.compile("(?<=color=.)(\\w+)");
Matcher m = p.matcher(color);

if (m.find()) {
color = m.group(1);
}

return Response.ok()
.entity(color)
.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT")
.build();


}




private void runTask(ChunkedOutput<String> output, String s) {
new Thread(() -> {
try {
example.runStaticTwitterStream(output, s);
example.runStaticTwitterStream(output, s);
} catch (IOException e) {
e.printStackTrace();
} finally {
Expand All @@ -82,6 +112,6 @@ private void runTask(ChunkedOutput<String> output, String s) {
// the output will be probably returned even before
// a first chunk is written by the new thread
}


}
56 changes: 56 additions & 0 deletions twitter-feed.kubernetes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: twitter-feed-v2
labels:
commit: 9a8fa77277c4a8c3c96d96d4b804e83c26ac6cc0
spec:
replicas: 2
selector:
matchLabels:
app: twitter-feed
template:
metadata:
labels:
app: twitter-feed
commit: 9a8fa77277c4a8c3c96d96d4b804e83c26ac6cc0
color: green
spec:
containers:
- name: twitter-feed
image: wcr.io/derekoneil/twitter-feed:master-9a8fa77277c4a8c3c96d96d4b804e83c26ac6cc0
imagePullPolicy: Always
ports:
- name: twitter-feed
containerPort: 8080
protocol: TCP
volumeMounts:
- name: podinfo
mountPath: /tmp
readOnly: false
volumes:
- name: podinfo
downwardAPI:
items:
- path: "labels"
fieldRef:
fieldPath: metadata.labels
imagePullSecrets:
- name: wercker
---
apiVersion: v1
kind: Service
metadata:
name: twitter-feed
labels:
app: twitter-feed
commit: 9a8fa77277c4a8c3c96d96d4b804e83c26ac6cc0
spec:
ports:
- port: 30000
targetPort: 8080
selector:
app: twitter-feed
color: green
type: ClusterIP
---
Loading