Skip to content

Commit

Permalink
update template
Browse files Browse the repository at this point in the history
  • Loading branch information
derekoneil committed Jan 9, 2018
1 parent 20fcb8d commit e2c2f96
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
Empty file modified deploy.sh
100644 → 100755
Empty file.
9 changes: 4 additions & 5 deletions kubernetes.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ spec:
labels:
app: twitter-feed
commit: ${WERCKER_GIT_COMMIT}
color: ${COLOR}
color: blue
spec:
containers:
- name: twitter-feed
image: ${DOCKER_REPO}:${WERCKER_GIT_BRANCH}-${WERCKER_GIT_COMMIT}
imagePullPolicy: Always
ports:
- name: twitter-feed
containerPort: ${PORT}
containerPort: 8080
protocol: TCP
volumeMounts:
- name: podinfo
Expand All @@ -48,10 +48,9 @@ metadata:
spec:
ports:
- port: 30000
targetPort: ${PORT}
targetPort: 8080
selector:
app: twitter-feed
color: ${COLOR}
commit: ${WERCKER_GIT_COMMIT}
color: green
type: ClusterIP
---
43 changes: 33 additions & 10 deletions src/main/java/com/example/StaticTweets.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
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 org.glassfish.jersey.server.ChunkedOutput;

Expand All @@ -16,7 +19,7 @@
*/
@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,7 +48,7 @@ public Response getIt() {
*
* @return String that will be returned as an application/json response.
*/

@Path("{search}")
@GET
@Produces(MediaType.APPLICATION_JSON)
Expand All @@ -59,15 +62,35 @@ public Response getItWithCount(@PathParam("search") final String search) {
.header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT")
.build();


}





@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());
System.out.println(color);
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 @@ -83,6 +106,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
}


}
8 changes: 4 additions & 4 deletions wercker.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#Use OpenJDK base docker image from dockerhub and open the application port on the docker container
#Use OpenJDK base docker image from dockerhub and open the application port on the docker container
box:
id: openjdk
ports:
- $PORT
- 8080

#Build our application using Maven, just as we always have
build:
steps:
steps:
- install-packages:
packages: maven
- script:
Expand All @@ -19,7 +19,7 @@ push-release:
- internal/docker-push:
tag: $WERCKER_GIT_BRANCH-$WERCKER_GIT_COMMIT
working-dir: /pipeline/source
ports: $PORT
ports: 8080
cmd: sh target/bin/start
#Inject our Wercker application token into Kubernetes to authenticate container pulls
#delete any existing Wercker secret before creating, to accommodate secret changes
Expand Down

0 comments on commit e2c2f96

Please sign in to comment.