diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0c1a83c..ac838c8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,7 +24,7 @@ jobs: - name: Build with Maven run: | mvn -B package; - mkdir cellar-dist; cp -r cellar-app/target/libs cellar-dist; cp cellar-app/target/cellar-app.jar cellar-dist + mkdir cellar-dist; cp -r cellar-app/target/libs cellar-dist; cp cellar-app/target/cellar-app.jar cellar-dist; cp scripts/cellar* cellar-dist zip -r cellar.zip cellar-dist env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/cellar-app/src/main/java/nl/lengrand/cellar/GreetResource.java b/cellar-app/src/main/java/nl/lengrand/cellar/GreetResource.java deleted file mode 100644 index 478a62f..0000000 --- a/cellar-app/src/main/java/nl/lengrand/cellar/GreetResource.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package nl.lengrand.cellar; - -import java.util.Collections; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.json.Json; -import javax.json.JsonBuilderFactory; -import javax.json.JsonObject; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.PUT; -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; - -/** - * A simple JAX-RS resource to greet you. Examples: - * - * Get default greeting message: - * curl -X GET http://localhost:8080/greet - * - * Get greeting message for Joe: - * curl -X GET http://localhost:8080/greet/Joe - * - * Change greeting - * curl -X PUT -H "Content-Type: application/json" -d '{"greeting" : "Howdy"}' http://localhost:8080/greet/greeting - * - * The message is returned as a JSON object. - */ -@Path("/greet") -@RequestScoped -public class GreetResource { - - private static final JsonBuilderFactory JSON = Json.createBuilderFactory(Collections.emptyMap()); - - /** - * The greeting message provider. - */ - private final GreetingProvider greetingProvider; - - /** - * Using constructor injection to get a configuration property. - * By default this gets the value from META-INF/microprofile-config - * - * @param greetingConfig the configured greeting message - */ - @Inject - public GreetResource(GreetingProvider greetingConfig) { - this.greetingProvider = greetingConfig; - } - - /** - * Return a wordly greeting message. - * - * @return {@link JsonObject} - */ - @SuppressWarnings("checkstyle:designforextension") - @GET - @Produces(MediaType.APPLICATION_JSON) - public JsonObject getDefaultMessage() { - return createResponse("World"); - } - - /** - * Return a greeting message using the name that was provided. - * - * @param name the name to greet - * @return {@link JsonObject} - */ - @SuppressWarnings("checkstyle:designforextension") - @Path("/{name}") - @GET - @Produces(MediaType.APPLICATION_JSON) - public JsonObject getMessage(@PathParam("name") String name) { - return createResponse(name); - } - - /** - * Set the greeting to use in future messages. - * - * @param jsonObject JSON containing the new greeting - * @return {@link Response} - */ - @SuppressWarnings("checkstyle:designforextension") - @Path("/greeting") - @PUT - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response updateGreeting(JsonObject jsonObject) { - - if (!jsonObject.containsKey("greeting")) { - JsonObject entity = JSON.createObjectBuilder() - .add("error", "No greeting provided") - .build(); - return Response.status(Response.Status.BAD_REQUEST).entity(entity).build(); - } - - String newGreeting = jsonObject.getString("greeting"); - - greetingProvider.setMessage(newGreeting); - return Response.status(Response.Status.NO_CONTENT).build(); - } - - private JsonObject createResponse(String who) { - String msg = String.format("%s %s!", greetingProvider.getMessage(), who); - - return JSON.createObjectBuilder() - .add("message", msg) - .build(); - } -} diff --git a/cellar-app/src/main/java/nl/lengrand/cellar/GreetingProvider.java b/cellar-app/src/main/java/nl/lengrand/cellar/GreetingProvider.java deleted file mode 100644 index 79ec6cf..0000000 --- a/cellar-app/src/main/java/nl/lengrand/cellar/GreetingProvider.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package nl.lengrand.cellar; - -import java.util.concurrent.atomic.AtomicReference; - -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; - -import org.eclipse.microprofile.config.inject.ConfigProperty; - -/** - * Provider for greeting message. - */ -@ApplicationScoped -public class GreetingProvider { - private final AtomicReference message = new AtomicReference<>(); - - /** - * Create a new greeting provider, reading the message from configuration. - * - * @param message greeting to use - */ - @Inject - public GreetingProvider(@ConfigProperty(name = "app.greeting") String message) { - this.message.set(message); - } - - String getMessage() { - return message.get(); - } - - void setMessage(String message) { - this.message.set(message); - } -} diff --git a/cellar-app/src/main/resources/META-INF/microprofile-config.properties b/cellar-app/src/main/resources/META-INF/microprofile-config.properties index 37c45cb..fabd1df 100644 --- a/cellar-app/src/main/resources/META-INF/microprofile-config.properties +++ b/cellar-app/src/main/resources/META-INF/microprofile-config.properties @@ -14,7 +14,6 @@ # limitations under the License. # -app.greeting=Hello monitoring.enabled=true driver.type=dummy diff --git a/scripts/cellar-config.properties b/scripts/cellar-config.properties new file mode 100644 index 0000000..34f54e8 --- /dev/null +++ b/scripts/cellar-config.properties @@ -0,0 +1,36 @@ +# +# Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +monitoring.enabled=true + +driver.type=dummy +sensor.api.type=influx +monitor.time.unit=SECONDS +monitor.time.span=5 + +sensor.api.fauna.key=dummy +#sensor.api.fauna.db=cellar +#sensor.api.fauna.collection=sensors + +#sensor.api.influx.location=http://localhost:8086 +sensor.api.influx.key=dummy +#sensor.api.influx.organization=cellar +#sensor.api.influx.bucket=cellar-data +#sensor.api.influx.precision=S + +# Microprofile server properties +server.port=8080 +server.host=0.0.0.0 \ No newline at end of file diff --git a/cellar.service b/scripts/cellar.service similarity index 100% rename from cellar.service rename to scripts/cellar.service diff --git a/cellar.sh b/scripts/cellar.sh similarity index 100% rename from cellar.sh rename to scripts/cellar.sh