From 22a0c681283f67ffc55d644c39c0eb67033b456d Mon Sep 17 00:00:00 2001 From: Antonio Garcia-Dominguez Date: Fri, 6 Dec 2024 14:49:32 +0000 Subject: [PATCH] Drop gcp-function project --- gcp-function/README.md | 50 ------------ gcp-function/build.gradle | 36 --------- gcp-function/micronaut-cli.yml | 6 -- .../fn/shorturl/ShortURLController.java | 78 ------------------- settings.gradle | 1 - 5 files changed, 171 deletions(-) delete mode 100644 gcp-function/README.md delete mode 100644 gcp-function/build.gradle delete mode 100644 gcp-function/micronaut-cli.yml delete mode 100644 gcp-function/src/main/java/org/eclipse/epsilon/labs/playground/fn/shorturl/ShortURLController.java diff --git a/gcp-function/README.md b/gcp-function/README.md deleted file mode 100644 index cff0076..0000000 --- a/gcp-function/README.md +++ /dev/null @@ -1,50 +0,0 @@ -# Google Cloud Function for Epsilon Playground - -## Deploying the function - -First build the function with: - -```bash -./gradlew clean shadowJar -``` - -Then `cd` into the `build/libs` directory (deployment has to be done from the location where the JAR lives): - -```bash -cd build/libs -``` - -Now run: - -```bash -$ gcloud beta functions deploy playground-backend --entry-point io.micronaut.gcp.function.http.HttpFunction --runtime java17 --trigger-http -``` - -Choose unauthenticated access if you don't need auth. - -To obtain the trigger URL do the following: - -```bash -YOUR_HTTP_TRIGGER_URL=$(gcloud functions describe playground-backend --format='value(httpsTrigger.url)') -``` - -You can then use this variable to test the function invocation: - -```bash -curl -i $YOUR_HTTP_TRIGGER_URL/playground-backend -``` - -- [Shadow Gradle Plugin](https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow) -- [Micronaut Gradle Plugin documentation](https://micronaut-projects.github.io/micronaut-gradle-plugin/latest/) -- [GraalVM Gradle Plugin documentation](https://graalvm.github.io/native-build-tools/latest/gradle-plugin.html) - -## Feature google-cloud-function documentation - -- [Micronaut Google Cloud Function documentation](https://micronaut-projects.github.io/micronaut-gcp/latest/guide/index.html#simpleFunctions) - -## Micronaut 4.1.6 Documentation - -- [User Guide](https://docs.micronaut.io/4.1.6/guide/index.html) -- [API Reference](https://docs.micronaut.io/4.1.6/api/index.html) -- [Configuration Reference](https://docs.micronaut.io/4.1.6/guide/configurationreference.html) -- [Micronaut Guides](https://guides.micronaut.io/index.html) diff --git a/gcp-function/build.gradle b/gcp-function/build.gradle deleted file mode 100644 index 2151ffb..0000000 --- a/gcp-function/build.gradle +++ /dev/null @@ -1,36 +0,0 @@ -plugins { - id 'io.micronaut.library' - id 'com.gradleup.shadow' - id 'io.micronaut.openapi' - id 'backend.java-conventions' -} - -dependencies { - implementation(project(":core")) - implementation(project(":shorturl-api")) - - annotationProcessor(mn.micronaut.serde.processor) - implementation(mn.micronaut.serde.jackson) - - // For using regular Micronaut @Controller annotations to specify functions - implementation(mn.micronaut.gcp.function.http) - - runtimeOnly("com.google.cloud.functions:functions-framework-api") - testImplementation("com.google.cloud.functions:functions-framework-api") - - // For accessing Google Cloud storage - implementation platform('com.google.cloud:libraries-bom:15.0.0') - implementation("com.google.cloud:google-cloud-storage") -} - -micronaut { - runtime("google_function") - testRuntime("junit5") - processing { - incremental(true) - annotations("org.eclipse.epsilon.labs.playground.fn.*") - } -} - - - diff --git a/gcp-function/micronaut-cli.yml b/gcp-function/micronaut-cli.yml deleted file mode 100644 index 9a1507a..0000000 --- a/gcp-function/micronaut-cli.yml +++ /dev/null @@ -1,6 +0,0 @@ -applicationType: function -defaultPackage: org.eclipse.epsilon.labs.playground.fn.flexmi2plantuml -testFramework: junit -sourceLanguage: java -buildTool: gradle -features: [app-name, google-cloud-function, gradle, http-client-test, jackson-databind, java, junit, logback, micronaut-build, properties, readme, shade] diff --git a/gcp-function/src/main/java/org/eclipse/epsilon/labs/playground/fn/shorturl/ShortURLController.java b/gcp-function/src/main/java/org/eclipse/epsilon/labs/playground/fn/shorturl/ShortURLController.java deleted file mode 100644 index 70a18e8..0000000 --- a/gcp-function/src/main/java/org/eclipse/epsilon/labs/playground/fn/shorturl/ShortURLController.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.eclipse.epsilon.labs.playground.fn.shorturl; - -import java.io.FileInputStream; -import java.util.UUID; - -import com.google.auth.oauth2.GoogleCredentials; -import com.google.cloud.storage.Blob; -import com.google.cloud.storage.BlobId; -import com.google.cloud.storage.BlobInfo; -import com.google.cloud.storage.Storage; -import com.google.cloud.storage.StorageOptions; - -import io.micronaut.context.annotation.Value; -import io.micronaut.http.HttpStatus; -import io.micronaut.http.annotation.Body; -import io.micronaut.http.annotation.Controller; -import io.micronaut.http.annotation.Post; -import io.micronaut.http.exceptions.HttpStatusException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Controller("/shorturl") -public class ShortURLController implements IShortURLController { - - @Value("${playground.gcp.projectId:`epsilon-live-gcp`") - private String projectId; - - @Value("${playground.gcp.bucket:`epsilon-live-gcp.appspot.com`") - private String bucket; - - @Value("${playground.gcp.credentials:`epsilon-live-gcp.json`") - private String credentialsPath; - - private static final Logger LOGGER = LoggerFactory.getLogger(ShortURLController.class); - - @Override - @Post - public ShortURLResponse shorten(@Body ShortURLRequest request) { - var response = new ShortURLResponse(); - try { - Storage storage = StorageOptions.newBuilder().setProjectId(projectId) - .setCredentials(GoogleCredentials.fromStream(new FileInputStream(credentialsPath))).build() - .getService(); - - if (request.getContent() != null) { - String content = request.getContent(); - String shortened = getShortened(content); - BlobId blobId = BlobId.of(bucket, shortened); - - Blob blob = storage.get(blobId); - if (blob == null) { - storage.create(BlobInfo.newBuilder(blobId).setContentType("text/plain").build(), - content.getBytes()); - } - - response.setShortened(shortened); - } else if (request.getShortened() != null) { - String shortened = request.getShortened(); - BlobId blobId = BlobId.of(bucket, shortened); - - Blob blob = storage.get(blobId); - if (blob != null) { - response.setContent(new String(blob.getContent())); - } - } - - } catch (Throwable t) { - LOGGER.error(t.getMessage(), t); - throw new HttpStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to store the example"); - } - return response; - } - - protected String getShortened(String content) { - return UUID.nameUUIDFromBytes(content.getBytes()).toString().substring(0, 8); - } - -} diff --git a/settings.gradle b/settings.gradle index 3c5230d..6d3fd3d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -18,5 +18,4 @@ include 'ep-tool-server' include 'backend-server' include 'shorturl-api' include 'shorturl-s3-lambda' -include 'gcp-function' include 'standalone-server'