Co-authored-by: joachim kolfen <jochkol@googlemail.com>
This commit is contained in:
parent
08021d2089
commit
1754a5765a
|
@ -1,4 +1,6 @@
|
|||
curl -w "\n" http://localhost:8080/mocktail/search/getrecipesall
|
||||
curl --header "Content-Type: application/json" --request POST --data "{\"id\":\"0\",\"name\":\"Peter\",\"ingredients\":\"guelle\",\"recipe\":\"ruehren\"}" http://localhost:8080/mocktail/create/single
|
||||
curl --header "Content-Type: application/json" --request PUT --data "{\"id\":\"4\",\"name\":\"Peter\",\"ingredients\":\"guelle\",\"recipe\":\"ruehren\"}" http://localhost:8080/mocktail/update/single
|
||||
curl --header "Content-Type: application/json" --request DELETE --data "{\"id\":\"4\"}" http://localhost:8080/mocktail/delete/single
|
||||
curl -w "\n" http://localhost:8080/mocktail/v2/search/caipi
|
||||
curl --header "Content-Type: application/json" --request POST --data "{\"id\":\"0\",\"name\":\"Peter\",\"ingredients\":\"guelle\",\"recipe\":\"ruehren\"}" http://localhost:8080/mocktail/v2/create
|
||||
curl --header "Content-Type: application/json" --request PUT --data "{\"id\":\"4\",\"name\":\"Peter\",\"ingredients\":\"guelle\",\"recipe\":\"ruehren\"}" http://localhost:8080/mocktail/v2/update/1
|
||||
curl --header "Content-Type: application/json" --request DELETE --data "{\"id\":\"4\"}" http://localhost:8080/mocktail/v2/delete/3
|
||||
curl http://localhost:8080/swagger
|
||||
curl --header "Content-Type: application/json" localhost:8080/metrics/application
|
38
pom.xml
38
pom.xml
|
@ -6,17 +6,17 @@
|
|||
<artifactId>code-with-quarkus</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<properties>
|
||||
<surefire-plugin.version>2.22.1</surefire-plugin.version>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<quarkus.platform.version>1.9.1.Final</quarkus.platform.version>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<maven.compiler.parameters>true</maven.compiler.parameters>
|
||||
<quarkus-plugin.version>1.9.1.Final</quarkus-plugin.version>
|
||||
<compiler-plugin.version>3.8.1</compiler-plugin.version>
|
||||
<maven.compiler.parameters>true</maven.compiler.parameters>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<quarkus-plugin.version>1.9.1.Final</quarkus-plugin.version>
|
||||
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
|
||||
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
|
||||
<quarkus.platform.version>1.9.1.Final</quarkus.platform.version>
|
||||
<surefire-plugin.version>2.22.1</surefire-plugin.version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
|
@ -42,6 +42,10 @@
|
|||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-arc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.logmanager</groupId>
|
||||
<artifactId>log4j2-jboss-logmanager</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-junit5</artifactId>
|
||||
|
@ -52,6 +56,22 @@
|
|||
<artifactId>rest-assured</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-smallrye-openapi</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-smallrye-metrics</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-smallrye-fault-tolerance</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-rest-client</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -2,64 +2,120 @@ package de.hsos.swa.ma.api.al;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.inject.Inject;
|
||||
/* import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.DELETE; */
|
||||
import javax.ws.rs.Path;
|
||||
/* import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType; */
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
@Path("/mocktail")
|
||||
public class Barkeeper implements ISearch, ICreate, IUpdate, IDelete{
|
||||
import javax.inject.Inject;
|
||||
// import org.eclipse.microprofile.*;
|
||||
|
||||
// import org.eclipse.microprofile.openapi.annotations.OpenAPIDefinition;
|
||||
// import org.eclipse.microprofile.openapi.annotations.info.Contact;
|
||||
// import org.eclipse.microprofile.openapi.annotations.info.Info;
|
||||
// import org.eclipse.microprofile.openapi.annotations.info.License;
|
||||
// import org.eclipse.microprofile.openapi.annotations.tags.Tag;
|
||||
|
||||
import org.eclipse.microprofile.metrics.MetricUnits;
|
||||
import org.eclipse.microprofile.metrics.annotation.Counted;
|
||||
import org.eclipse.microprofile.metrics.annotation.Gauge;
|
||||
import org.eclipse.microprofile.metrics.annotation.Timed;
|
||||
|
||||
import org.eclipse.microprofile.faulttolerance.Retry;
|
||||
import org.eclipse.microprofile.faulttolerance.Timeout;
|
||||
import org.eclipse.microprofile.faulttolerance.Fallback;
|
||||
|
||||
// import javax.ws.rs.GET;
|
||||
// import javax.ws.rs.POST;
|
||||
// import javax.ws.rs.PUT;
|
||||
// import javax.ws.rs.DELETE;
|
||||
// import javax.ws.rs.Path;
|
||||
// import javax.ws.rs.Produces;
|
||||
// import javax.ws.rs.Consumes;
|
||||
// import javax.ws.rs.core.MediaType;
|
||||
|
||||
// import org.jboss.resteasy.annotations.jaxrs.PathParam;
|
||||
|
||||
//@Path("/mocktail")
|
||||
// @OpenAPIDefinition(
|
||||
// tags = {
|
||||
// @Tag(name="widget", description="Widget operations."),
|
||||
// @Tag(name="gasket", description="Operations related to gaskets")
|
||||
// },
|
||||
// info = @Info(
|
||||
// title="Example API",
|
||||
// version = "1.0.1",
|
||||
// contact = @Contact(
|
||||
// name = "Example API Support",
|
||||
// url = "http://exampleurl.com/contact",
|
||||
// email = "techsupport@example.com"),
|
||||
// license = @License(
|
||||
// name = "Apache 2.0",
|
||||
// url = "http://www.apache.org/licenses/LICENSE-2.0.html"))
|
||||
// )
|
||||
|
||||
public class Barkeeper implements BarkeeperInterface{
|
||||
|
||||
private static final Logger logger = Logger.getLogger(Barkeeper.class);
|
||||
|
||||
@Inject
|
||||
StorageTransport st;
|
||||
|
||||
//@GET
|
||||
//@Produces (MediaType.APPLICATION_JSON)
|
||||
//@Path("/getrecipesall")
|
||||
public ArrayList<Mocktail> getRecipesAll() {
|
||||
ArrayList<Mocktail> mts = st.getRecipesAll();
|
||||
//Metrics
|
||||
@Counted(name = "performedSearchesByName", description = "How many searches by name have been performed.")
|
||||
@Timed(name = "searchTimer", description = "A measure of how long it takes to perform the search.", unit = MetricUnits.MILLISECONDS)
|
||||
//@Gauge(name = "highestPrimeNumberSoFar", unit = MetricUnits.NONE, description = "Highest prime number so far.")
|
||||
//Fault-Tolerance
|
||||
@Retry(maxRetries = 3)
|
||||
@Timeout(250)
|
||||
@Fallback(fallbackMethod = "fallbackGetMocktailByName")
|
||||
public ArrayList<Mocktail> getMocktailByName(String name) {
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->getMocktailByName: started");
|
||||
ArrayList<Mocktail> mts = st.getMocktailByName(name);
|
||||
logger.trace(System.currentTimeMillis() + ": Barkeeper->getMocktailByName: get mocktail by name by REST-CLIENT");
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->getMocktailByName: ended");
|
||||
return mts;
|
||||
}
|
||||
|
||||
/* @POST
|
||||
@Produces (MediaType.TEXT_PLAIN)
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Path("/create") */
|
||||
public String createMocktail(Mocktail m) {
|
||||
System.out.println("action-create -> index: "+ m.id);
|
||||
if(this.st.addMocktail(m)) {
|
||||
return "Mocktail wurde erstellt.";
|
||||
}
|
||||
return "Mocktail konnte nicht erstellt werden.";
|
||||
public ArrayList<Mocktail> fallbackGetMocktailByName(String name) {
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->getMocktailByName: started");
|
||||
ArrayList<Mocktail> mts = st.getAllMocktails();
|
||||
logger.trace(System.currentTimeMillis() + ": Barkeeper->getMocktailByName: get mocktail by name by REST-CLIENT");
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->getMocktailByName: ended");
|
||||
return mts;
|
||||
}
|
||||
|
||||
//Metrics
|
||||
@Counted(name = "performedCreates", description = "How many creates have been performed.")
|
||||
@Timed(name = "createTimer", description = "A measure of how long it takes to perform the mocktail creation.", unit = MetricUnits.MILLISECONDS)
|
||||
//Fault-Tolerance
|
||||
@Retry(maxRetries = 3)
|
||||
public void createMocktail(Mocktail m) {
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->createMocktail: started");
|
||||
this.st.addMocktail(m);
|
||||
logger.trace(System.currentTimeMillis() + ": Barkeeper->createMocktail: create mocktail by REST-CLIENT");
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->createMocktail: ended");
|
||||
}
|
||||
|
||||
/* @PUT
|
||||
@Produces (MediaType.TEXT_PLAIN)
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Path("/update") */
|
||||
public String updateMocktail(Mocktail m) {
|
||||
System.out.println("action-update -> index: "+ m.id);
|
||||
if(this.st.updateMocktail(m)) {
|
||||
return "Mocktail wurde geupdatet.";
|
||||
}
|
||||
return "Mocktail konnte nicht geupdatet werden...";
|
||||
//Metrics
|
||||
@Counted(name = "performedUpdates", description = "How many updates have been performed.")
|
||||
@Timed(name = "updateTimer", description = "A measure of how long it takes to perform the update of a mocktail.", unit = MetricUnits.MILLISECONDS)
|
||||
//Fault-Tolerance
|
||||
@Retry(maxRetries = 3)
|
||||
public void updateMocktail(Mocktail m, long number) {
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->updateMocktail: started");
|
||||
this.st.updateMocktail(m, number);
|
||||
logger.trace(System.currentTimeMillis() + ": Barkeeper->updateMocktail: update mocktail by REST-CLIENT");
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->updateMocktail: ended");
|
||||
}
|
||||
|
||||
/* @DELETE
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Path("/delete") */
|
||||
public String deleteMocktail(Mocktail m) {
|
||||
System.out.println("action-delete -> index: "+ m.id);
|
||||
if(this.st.deleteMocktail(m.id)){
|
||||
return "Mocktail wurde entfernt.";
|
||||
}
|
||||
return "Objekt konnte nicht entfernt werden...";
|
||||
//Metrics
|
||||
@Counted(name = "performedDeletions", description = "How many deletes have been performed.")
|
||||
@Timed(name = "deleteTimer", description = "A measure of how long it takes to delete a mocktail.", unit = MetricUnits.MILLISECONDS)
|
||||
//Fault-Tolerance
|
||||
@Retry(maxRetries = 3)
|
||||
public void deleteMocktail(long id) {
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->deleteMocktail: started");
|
||||
this.st.deleteMocktail(id);
|
||||
logger.trace(System.currentTimeMillis() + ": Barkeeper->deleteMocktail: delete mocktail by REST-CLIENT");
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->deleteMocktail: ended");
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jboss.resteasy.annotations.jaxrs.PathParam;
|
||||
|
||||
@Path("/mocktail/v2")
|
||||
public interface BarkeeperInterface {
|
||||
|
||||
@GET
|
||||
@Produces (MediaType.APPLICATION_JSON)
|
||||
@Path("/search/{name}")
|
||||
public ArrayList<Mocktail> getMocktailByName(@PathParam String name);
|
||||
|
||||
@POST
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Path("/create")
|
||||
public void createMocktail(Mocktail m);
|
||||
|
||||
@DELETE
|
||||
@Path("/delete/{number}")
|
||||
public void deleteMocktail(@PathParam long number);
|
||||
|
||||
@PUT
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Path("/update/{number}")
|
||||
public void updateMocktail(Mocktail m,@PathParam long number);
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
public class Cocktail {
|
||||
public long idDrink;
|
||||
public String strDrink;
|
||||
//public ArrayList<Ingredient> ingredients;
|
||||
public String strInstructionsDE;
|
||||
|
||||
/*public Cocktail() {
|
||||
|
||||
}
|
||||
|
||||
public Cocktail(long id, String name, /*String ingredients, String recipe) {
|
||||
this.idDrink = id;
|
||||
this.strDrink = name;
|
||||
//this.ingredients = ingredients;
|
||||
this.strInstructionsDE = recipe;
|
||||
}
|
||||
|
||||
public long getId(){
|
||||
return this.idDrink;
|
||||
}
|
||||
|
||||
public void setId(long idDrink){
|
||||
this.idDrink = idDrink;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return this.strDrink;
|
||||
}
|
||||
|
||||
public void setName(String strDrink){
|
||||
this.strDrink = strDrink;
|
||||
}
|
||||
|
||||
/*public String getIngredients(){
|
||||
return this.ingredients;
|
||||
}
|
||||
|
||||
public void setIngredients(String ingredients){
|
||||
this.ingredients = ingredients;
|
||||
}
|
||||
|
||||
public String getRecipe(){
|
||||
return this.strInstructionsDE;
|
||||
}
|
||||
|
||||
public void setRecipe(String strInstructionsDE){
|
||||
this.strInstructionsDE = strInstructionsDE;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ID: " + this.idDrink + "\nName: " + this.strDrink + /*"\nZutaten: " + this.ingredients + "\nRezept: " + this.strInstructionsDE;
|
||||
}*/
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
|
||||
|
||||
import org.jboss.resteasy.annotations.jaxrs.PathParam;
|
||||
import org.jboss.resteasy.annotations.jaxrs.QueryParam;
|
||||
//import javax.ws.rs.Path;
|
||||
|
||||
//import javax.enterprise.context.ApplicationScoped;
|
||||
|
||||
@Path("/v1/1")
|
||||
@RegisterRestClient(configKey="cocktailAPI")
|
||||
public interface CocktailGatewayInterface {
|
||||
|
||||
@GET
|
||||
@Path("/random.php")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Drinks getAllCocktails();
|
||||
|
||||
@GET
|
||||
@Path("/search.php")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Drinks getCocktailByName(@QueryParam("s") String name);
|
||||
|
||||
@GET
|
||||
@Path("/filter.php")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Drinks getCocktailByIngredient(@QueryParam("i") String ingredient);
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jboss.resteasy.annotations.jaxrs.PathParam;
|
||||
|
||||
@Path("/barkeeper/v2/cocktail")
|
||||
public interface CocktailInterface {
|
||||
|
||||
@GET
|
||||
@Produces (MediaType.APPLICATION_JSON)
|
||||
@Path("/search")
|
||||
public Drinks getAllCocktails();
|
||||
|
||||
@GET
|
||||
@Produces (MediaType.APPLICATION_JSON)
|
||||
@Path("/search/name/{name}")
|
||||
public Drinks getCocktailByName(@PathParam String name);
|
||||
|
||||
@GET
|
||||
@Produces (MediaType.APPLICATION_JSON)
|
||||
@Path("/search/ingredient/{ingredient}")
|
||||
public Drinks getCocktailByIngredient(@PathParam String ingredient);
|
||||
|
||||
/*@POST
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Path("/create")
|
||||
public void createCocktail(Mocktail m);
|
||||
|
||||
@DELETE
|
||||
@Path("/delete/{number}")
|
||||
public void deleteCocktail(@PathParam long number);
|
||||
|
||||
@PUT
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Path("/update/{number}")
|
||||
public void updateCocktail(Mocktail m,@PathParam long number);*/
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Drinks {
|
||||
public ArrayList<Cocktail> drinks;
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
//@Path("/create")
|
||||
public interface ICreate {
|
||||
|
||||
@POST
|
||||
@Produces (MediaType.TEXT_PLAIN)
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Path("/create/single")
|
||||
public String createMocktail(Mocktail m);
|
||||
//public Mocktail[] showRecipesByName(/*@PathParam */String name);
|
||||
//public Mocktail[] showRecipesById(int id);
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
/**
|
||||
* IDelete
|
||||
*/
|
||||
//@Path("/delete")
|
||||
public interface IDelete {
|
||||
@DELETE
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Produces (MediaType.TEXT_PLAIN)
|
||||
@Path("/delete/single")
|
||||
public String deleteMocktail(Mocktail m);
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
public interface ISearch {
|
||||
|
||||
@GET
|
||||
@Produces (MediaType.APPLICATION_JSON)
|
||||
@Path("search/getrecipesall")
|
||||
public ArrayList<Mocktail> getRecipesAll();
|
||||
//public Mocktail[] showRecipesByName(/*@PathParam */String name);
|
||||
//public Mocktail[] showRecipesById(int id);
|
||||
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
//@Path("/mocktail/update")
|
||||
public interface IUpdate {
|
||||
|
||||
@PUT
|
||||
@Produces (MediaType.TEXT_PLAIN)
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Path("/update/single")
|
||||
public String updateMocktail(Mocktail m);
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
public class Ingredient {
|
||||
public String type;
|
||||
public String measure;
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jboss.resteasy.annotations.jaxrs.PathParam;
|
||||
|
||||
@Path("/barkeeper/v2/mocktail")
|
||||
public interface MocktailInterface {
|
||||
|
||||
@GET
|
||||
@Produces (MediaType.APPLICATION_JSON)
|
||||
@Path("/search")
|
||||
public ArrayList<Mocktail> getAllMocktails();
|
||||
|
||||
@GET
|
||||
@Produces (MediaType.APPLICATION_JSON)
|
||||
@Path("/search/name/{name}")
|
||||
public ArrayList<Mocktail> getMocktailByName(@PathParam String name);
|
||||
|
||||
@GET
|
||||
@Produces (MediaType.APPLICATION_JSON)
|
||||
@Path("/search/ingredient/{ingredient}")
|
||||
public ArrayList<Mocktail> getMocktailByIngredient(@PathParam String ingredient);
|
||||
|
||||
@POST
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Path("/create")
|
||||
public void createMocktail(Mocktail m);
|
||||
|
||||
@DELETE
|
||||
@Path("/delete/{number}")
|
||||
public void deleteMocktail(@PathParam long number);
|
||||
|
||||
@PUT
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Path("/update/{number}")
|
||||
public void updateMocktail(Mocktail m,@PathParam long number);
|
||||
}
|
|
@ -0,0 +1,188 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.eclipse.microprofile.metrics.MetricUnits;
|
||||
import org.eclipse.microprofile.metrics.annotation.Counted;
|
||||
import org.eclipse.microprofile.metrics.annotation.Timed;
|
||||
|
||||
import org.eclipse.microprofile.faulttolerance.Retry;
|
||||
import org.eclipse.microprofile.faulttolerance.Timeout;
|
||||
import org.eclipse.microprofile.faulttolerance.Fallback;
|
||||
|
||||
//import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
|
||||
import org.eclipse.microprofile.rest.client.inject.RestClient;
|
||||
|
||||
import org.jboss.resteasy.annotations.jaxrs.PathParam;
|
||||
|
||||
public class ProperBarkeeper implements CocktailInterface, MocktailInterface{
|
||||
|
||||
private static final Logger logger = Logger.getLogger(Barkeeper.class);
|
||||
|
||||
@Inject
|
||||
StorageTransport st;
|
||||
|
||||
@Inject
|
||||
@RestClient
|
||||
CocktailGatewayInterface cocktailGatewayInterface;
|
||||
|
||||
//Metrics
|
||||
@Counted(name = "performedAllCocktailSearches", description = "How many searches for all cocktails have been performed.")
|
||||
@Timed(name = "searchAllCocktailsTimer", description = "A measure of how long it takes to perform the search.", unit = MetricUnits.MILLISECONDS)
|
||||
//Fault-Tolerance
|
||||
@Retry(maxRetries = 3)
|
||||
@Timeout(250)
|
||||
//@Fallback(fallbackMethod = "getAllMocktails")
|
||||
public Drinks getAllCocktails(){
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->getAllCocktails: started");
|
||||
Drinks drinks = cocktailGatewayInterface.getAllCocktails();
|
||||
logger.trace(System.currentTimeMillis() + ": Barkeeper->getAllCocktails: get all cocktails by REST-CLIENT");
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->getAllCocktails: ended");
|
||||
return drinks;
|
||||
}
|
||||
|
||||
//Metrics
|
||||
@Counted(name = "performedNameCocktailSearches", description = "How many searches for cocktails by name have been performed.")
|
||||
@Timed(name = "searchCocktailsNameTimer", description = "A measure of how long it takes to perform the search.", unit = MetricUnits.MILLISECONDS)
|
||||
//Fault-Tolerance
|
||||
@Retry(maxRetries = 3)
|
||||
@Timeout(250)
|
||||
public Drinks getCocktailByName(String name) {
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->getCocktailByName: started");
|
||||
Drinks drinks = cocktailGatewayInterface.getCocktailByName(name);
|
||||
logger.trace(System.currentTimeMillis() + ": Barkeeper->getCocktailByName: get all cocktails by name REST-CLIENT");
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->getCocktailByName: ended");
|
||||
return drinks;
|
||||
}
|
||||
|
||||
//Metrics
|
||||
@Counted(name = "performedIngredientCocktailSearches", description = "How many searches for cocktails by ingredient have been performed.")
|
||||
@Timed(name = "searchCocktailsIngredientTimer", description = "A measure of how long it takes to perform the search.", unit = MetricUnits.MILLISECONDS)
|
||||
//Fault-Tolerance
|
||||
@Retry(maxRetries = 3)
|
||||
@Timeout(250)
|
||||
public Drinks getCocktailByIngredient(String ingredient){
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->getCocktailByIngredient: started");
|
||||
Drinks drinks = cocktailGatewayInterface.getCocktailByIngredient(ingredient);
|
||||
logger.trace(System.currentTimeMillis() + ": Barkeeper->getCocktailByIngredient: get all cocktails by ingredient REST-CLIENT");
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->getCocktailByIngredient: ended");
|
||||
return drinks;
|
||||
}
|
||||
|
||||
/*public void createCocktail(Mocktail m){
|
||||
|
||||
}
|
||||
|
||||
public void deleteCocktail(@PathParam long number){
|
||||
|
||||
}
|
||||
|
||||
public void updateCocktail(Mocktail m,@PathParam long number){
|
||||
|
||||
}*/
|
||||
|
||||
|
||||
//Metrics
|
||||
@Counted(name = "performedAllMocktailSearches", description = "How many searches for all cocktails have been performed.")
|
||||
@Timed(name = "searchAllMocktailsTimer", description = "A measure of how long it takes to perform the search.", unit = MetricUnits.MILLISECONDS)
|
||||
//Fault-Tolerance
|
||||
@Retry(maxRetries = 3)
|
||||
@Timeout(250)
|
||||
public ArrayList<Mocktail> getAllMocktails(){
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->getAllMocktails: started");
|
||||
ArrayList<Mocktail> mocks = st.getAllMocktails();
|
||||
logger.trace(System.currentTimeMillis() + ": Barkeeper->getAllMocktails: get all mocktails by REST-CLIENT");
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->getAllMocktails: ended");
|
||||
return mocks;
|
||||
}
|
||||
|
||||
//Metrics
|
||||
@Counted(name = "performedSearchesByName", description = "How many searches by name have been performed.")
|
||||
@Timed(name = "searchMocktailsNameTimer", description = "A measure of how long it takes to perform the search.", unit = MetricUnits.MILLISECONDS)
|
||||
//@Gauge(name = "highestPrimeNumberSoFar", unit = MetricUnits.NONE, description = "Highest prime number so far.")
|
||||
//Fault-Tolerance
|
||||
@Retry(maxRetries = 3)
|
||||
@Timeout(250)
|
||||
@Fallback(fallbackMethod = "fallbackGetMocktailByName")
|
||||
public ArrayList<Mocktail> getMocktailByName(String name) {
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->getMocktailByName: started");
|
||||
ArrayList<Mocktail> mts = st.getMocktailByName(name);
|
||||
logger.trace(System.currentTimeMillis() + ": Barkeeper->getMocktailByName: get mocktail by name by REST-CLIENT");
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->getMocktailByName: ended");
|
||||
return mts;
|
||||
}
|
||||
|
||||
//Metrics
|
||||
@Counted(name = "performedSearchesByIngredient", description = "How many searches by ingredient have been performed.")
|
||||
@Timed(name = "searchMocktailsIngredientTimer", description = "A measure of how long it takes to perform the search.", unit = MetricUnits.MILLISECONDS)
|
||||
//@Gauge(name = "highestPrimeNumberSoFar", unit = MetricUnits.NONE, description = "Highest prime number so far.")
|
||||
//Fault-Tolerance
|
||||
@Retry(maxRetries = 3)
|
||||
@Timeout(250)
|
||||
//@Fallback(fallbackMethod = "fallbackGetMocktailByName")
|
||||
public ArrayList<Mocktail> getMocktailByIngredient(String ingredient) {
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->getMocktailByIngredient: started");
|
||||
ArrayList<Mocktail> mts = st.getMocktailByIngredient(ingredient);
|
||||
logger.trace(System.currentTimeMillis() + ": Barkeeper->getMocktailByIngredient: get mocktail by ingredient by REST-CLIENT");
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->getMocktailByIngredient: ended");
|
||||
return mts;
|
||||
}
|
||||
|
||||
public ArrayList<Mocktail> fallbackGetMocktailByName(String name) {
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->getMocktailByName: started");
|
||||
ArrayList<Mocktail> mts = st.getAllMocktails();
|
||||
logger.trace(System.currentTimeMillis() + ": Barkeeper->getMocktailByName: get mocktail by name by REST-CLIENT");
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->getMocktailByName: ended");
|
||||
return mts;
|
||||
}
|
||||
|
||||
//Metrics
|
||||
@Counted(name = "performedCreates", description = "How many creates have been performed.")
|
||||
@Timed(name = "createTimer", description = "A measure of how long it takes to perform the mocktail creation.", unit = MetricUnits.MILLISECONDS)
|
||||
//Fault-Tolerance
|
||||
@Retry(maxRetries = 3)
|
||||
public void createMocktail(Mocktail m) {
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->createMocktail: started");
|
||||
this.st.addMocktail(m);
|
||||
logger.trace(System.currentTimeMillis() + ": Barkeeper->createMocktail: create mocktail by REST-CLIENT");
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->createMocktail: ended");
|
||||
}
|
||||
|
||||
//Metrics
|
||||
@Counted(name = "performedUpdates", description = "How many updates have been performed.")
|
||||
@Timed(name = "updateTimer", description = "A measure of how long it takes to perform the update of a mocktail.", unit = MetricUnits.MILLISECONDS)
|
||||
//Fault-Tolerance
|
||||
@Retry(maxRetries = 3)
|
||||
public void updateMocktail(Mocktail m, long number) {
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->updateMocktail: started");
|
||||
this.st.updateMocktail(m, number);
|
||||
logger.trace(System.currentTimeMillis() + ": Barkeeper->updateMocktail: update mocktail by REST-CLIENT");
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->updateMocktail: ended");
|
||||
}
|
||||
|
||||
//Metrics
|
||||
@Counted(name = "performedDeletions", description = "How many deletes have been performed.")
|
||||
@Timed(name = "deleteTimer", description = "A measure of how long it takes to delete a mocktail.", unit = MetricUnits.MILLISECONDS)
|
||||
//Fault-Tolerance
|
||||
@Retry(maxRetries = 3)
|
||||
public void deleteMocktail(long id) {
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->deleteMocktail: started");
|
||||
this.st.deleteMocktail(id);
|
||||
logger.trace(System.currentTimeMillis() + ": Barkeeper->deleteMocktail: delete mocktail by REST-CLIENT");
|
||||
logger.debug(System.currentTimeMillis() + ": Barkeeper->deleteMocktail: ended");
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@ package de.hsos.swa.ma.api.al;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.microprofile.faulttolerance.CircuitBreaker;
|
||||
//import javax.ws.rs.Path;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
|
@ -10,16 +11,9 @@ import javax.enterprise.context.ApplicationScoped;
|
|||
//@Path("/mocktail/storage")
|
||||
public class StorageTransport {
|
||||
|
||||
//private Mocktail[] mocktails;
|
||||
private ArrayList<Mocktail> mocktails;
|
||||
|
||||
public StorageTransport() {
|
||||
/*this.mocktails = new Mocktail[5];
|
||||
this.mocktails[0] = new Mocktail("caipi", "keineahnung", "ruehren");
|
||||
this.mocktails[1] = new Mocktail("caipi2", "keineahnung", "ruehren");
|
||||
this.mocktails[2] = new Mocktail("caipi3", "keineahnung", "ruehren");
|
||||
this.mocktails[3] = new Mocktail("caipi4", "keineahnung", "ruehren");
|
||||
this.mocktails[4] = new Mocktail("caipi5", "keineahnung", "ruehren");*/
|
||||
this.mocktails = new ArrayList<Mocktail>();
|
||||
this.mocktails.add(new Mocktail(0, "caipi", "keineahnung", "ruehren"));
|
||||
this.mocktails.add(new Mocktail(1, "caipi2", "keineahnung", "ruehren"));
|
||||
|
@ -28,9 +22,31 @@ public class StorageTransport {
|
|||
this.mocktails.add(new Mocktail(4, "caipi5", "keineahnung", "ruehren"));
|
||||
}
|
||||
|
||||
public ArrayList<Mocktail> getRecipesAll() {
|
||||
@CircuitBreaker(requestVolumeThreshold = 4)
|
||||
public ArrayList<Mocktail> getMocktailByName(String name) {
|
||||
ArrayList<Mocktail> transport = new ArrayList<Mocktail>();
|
||||
for(int i = 0; i < this.mocktails.size(); i++){
|
||||
if(this.mocktails.get(i).name.equals(name)){
|
||||
transport.add(this.mocktails.get(i));
|
||||
}
|
||||
}
|
||||
return transport;
|
||||
}
|
||||
|
||||
public ArrayList<Mocktail> getAllMocktails() {
|
||||
return this.mocktails;
|
||||
}
|
||||
|
||||
public ArrayList<Mocktail> getMocktailByIngredient(String ingredient) {
|
||||
ArrayList<Mocktail> transport = new ArrayList<Mocktail>();
|
||||
for(int i = 0; i < this.mocktails.size(); i++){
|
||||
if(this.mocktails.get(i).ingredients.equals(ingredient)){
|
||||
transport.add(this.mocktails.get(i));
|
||||
}
|
||||
}
|
||||
return transport;
|
||||
}
|
||||
|
||||
|
||||
public boolean addMocktail(Mocktail m) {
|
||||
if(this.mocktails.add(m)){
|
||||
|
@ -40,14 +56,14 @@ public class StorageTransport {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean updateMocktail(Mocktail m) {
|
||||
public boolean updateMocktail(Mocktail m, long number) {
|
||||
int index = -1;
|
||||
int i = 0;
|
||||
if(this.mocktails.isEmpty()){
|
||||
return false;
|
||||
}
|
||||
while(i < this.mocktails.size()) {
|
||||
if(this.mocktails.get(i).getId() == m.getId()){
|
||||
if(this.mocktails.get(i).getId() == number){
|
||||
index = i;
|
||||
}
|
||||
i++;
|
||||
|
@ -65,5 +81,5 @@ public class StorageTransport {
|
|||
System.out.println("Test... :D");
|
||||
return this.mocktails.remove(this.mocktails.get((int)index));
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
# HTTP-SERVER: PORTS
|
||||
#quarkus.http.port=8080
|
||||
#%dev.quarkus.http.port=8082
|
||||
|
||||
# Logging
|
||||
# Root-Logger
|
||||
quarkus.log.level=INFO
|
||||
quarkus.log.console.level=INFO
|
||||
|
||||
#Logging: Categories
|
||||
quarkus.log.category."io.quarkus".level = WARN
|
||||
quarkus.log.category."de.hsos.swa".level = DEBUG
|
||||
quarkus.log.category."de.hsos.swa".level = TRACE
|
||||
|
||||
#Logging-Handler: Console
|
||||
quarkus.log.console.enable=true
|
||||
quarkus.log.console.format=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) %s%e%n
|
||||
|
||||
#Mit
|
||||
#%d Datum mit definiertem Format
|
||||
#%c Name der Kategorie
|
||||
#%t Thread-Name
|
||||
#%s Message, falls vorhanden
|
||||
#%e Exception, falls vorhanden
|
||||
#%n Zeilenumbruch
|
||||
|
||||
#Logging-Handler: File
|
||||
quarkus.log.file.enable=true
|
||||
quarkus.log.file.path=quarkus.log
|
||||
quarkus.log.file.level=TRACE
|
||||
quarkus.log.file.format=%d{HH:mm:ss} %-5p [%c{2.}] (%t) %s%e%n
|
||||
quarkus.log.file.rotation.file-suffix=.yyyy-MM-dd
|
||||
quarkus.log.file.rotation.max-backup-index=1
|
||||
quarkus.log.file.rotation.max-file-size=2000
|
||||
quarkus.log.file.async=true
|
||||
|
||||
|
||||
de.hsos.swa.ma.api.al.Barkeeper/getMocktailByName/Retry/maxRetries=6
|
||||
de.hsos.swa.ma.api.al.Barkeeper/getMocktailByName/Timeout/300
|
||||
|
||||
#cocktail API Resco... Res..... -.- Quelle.
|
||||
#cocktailAPI/mp-rest/url=https://www.thecocktaildb.com/api/json
|
||||
|
||||
|
||||
de.hsos.swa.ma.api.al.CocktailGatewayInterface/mp-rest/url=https://www.thecocktaildb.com/api/json
|
||||
de.hsos.swa.ma.api.al.CocktailGatewayInterface/mp-rest/scope=javax.inject.Singleton
|
Loading…
Reference in New Issue