diff --git a/DRAFT_RELEASE_NOTES.md b/DRAFT_RELEASE_NOTES.md index 7ba94256a..3e6f08b30 100644 --- a/DRAFT_RELEASE_NOTES.md +++ b/DRAFT_RELEASE_NOTES.md @@ -101,4 +101,5 @@ If you added any custom configurations to the `sparkoperator` service account pe # What's Changed - `pyproject.toml` files updated to allow for Python version `>=3.8`. -- All SageMaker modules and corresponding references were removed in commit bdcbb409. +- All SageMaker modules and corresponding references were removed in commit 8ce393f. +- The Service Discovery module and corresponding references were removed in commit d10db5d0. diff --git a/foundation/foundation-service-discovery/LICENSE.txt b/foundation/foundation-service-discovery/LICENSE.txt deleted file mode 100644 index a9bd80cda..000000000 --- a/foundation/foundation-service-discovery/LICENSE.txt +++ /dev/null @@ -1,49 +0,0 @@ -Booz Allen Public License v1.0 ------------------------------- - -INTRODUCTION -The Booz Allen Public License allows government, non-profit academic, other non-profit, and commercial entities access to distinctive, disruptive, and robust code with the goal of Empowering People to Change the World(SM). Products licensed under the Booz Allen Public License are founded on the basis that collective ingenuity can make the largest impact in the community. - -DEFINITIONS -* **Commercial Entity.** “Commercial Entity” means any individual or entity other than a government, non-profit academic, or other non-profit entity. -* **Derivative.** “Derivative” means any work of authorship in Source Code or Object Code form that results from an addition to, deletion from, or modification of the Source Code of the Product. -* **License.** “License” means this Booz Allen Public License. -* **Object Code.** “Object Code” means the form resulting from transformation or translation of Source Code into machine readable code, including but not limited to, compiled object code. -* **Originator.** “Originator” means each individual or legal entity that creates, contributes to the creation of, or owns the Product. -* **Patent Claims.** “Patent Claims” means any patent claim(s) in any patent to which Originator has a right to grant a license that would be infringed by Your making, using, selling, offering for sale, having made, or importing of the Product, but for the grant of this License. -* **Product.** “Product” means the Source Code of the software which the initial Originator made available under this License, and any Derivative of such Source Code. -* **Source Code.** “Source Code” means software in human-readable form. -* **You.** “You” means either an individual or an entity (if you are taking this license on behalf of an entity) that exercises the rights granted under this License. - -LICENSE -**Government/Non-Profit Academic/Other Non-Profit.** -This Section applies if You are not a Commercial Entity. - -* **License.** Subject to the terms and conditions of this License, each Originator hereby grants You a perpetual, worldwide, non-exclusive, royalty-free license to reproduce, display, perform, modify, distribute and otherwise use the Product and Derivatives, in Source Code and Object Code form, in accordance with the terms and conditions of this License in order to support the general public good and for your internal business purposes. -* **Distribution.** You may distribute to third parties copies of the Product, including any Derivative that You create, in Source Code or Object Code form. If You distribute copies of the Product, including any Derivative that You create, in Source Code form, such distribution must be under the terms of this License and You must inform recipients of the Source Code that the Product is governed under this License and how they can obtain a copy of this License. You may distribute to third parties copies of the Product, including any Derivative that You create, in Object Code form, or allow third parties to access or use the Product, including any Derivative that You create, under a license of Your choice. -* **Commercial Sales.** You may not distribute, or allow third parties to access or use, the Product or any Derivative for a fee, unless You first obtain permission from the Originator. If Booz Allen Hamilton is the Originator, please contact Booz Allen Hamilton at . - -**Commercial Entities**. -This Section applies if You are a Commercial Entity. - -* **License.** Subject to the terms and conditions of this License, each Originator hereby grants You a perpetual, worldwide, non-exclusive, royalty-free license to reproduce, display, perform, modify, distribute and otherwise use the Product and Derivatives, in Source Code and Object Code form, in accordance with the terms and conditions of this License for the sole purpose of Your internal business purposes and the provision of services to government, non-profit academic, and other non-profit entities. -* **Distribution and Derivatives.** You may distribute to third parties copies of the Product, including any Derivative that You create, in Source Code or Object Code form. If You distribute copies of the Product, including any Derivative that You create, in Source Code form, such distribution must be under the terms of this License and You must inform recipients of the Source Code that the Product is governed under this License and how they can obtain a copy of this License. You may distribute to third parties copies of the Product, including any Derivative that You create, in Object Code form, or allow third parties to access or use the Product, including any Derivative that You create, under a license of Your choice, provided that You make available, and inform the recipient of such distribution how they can obtain, a copy of the Source Code thereof, at no charge, and inform the recipient of the Source Code that the Product is governed under this License and how they can obtain a copy of this License. -* **Commercial Sales.** You may not distribute, or allow third parties to access or use, the Product or any Derivative for a fee, unless You first obtain permission from the Originator. If Booz Allen Hamilton, please contact Booz Allen Hamilton at . - - -**Patent Claim(s)**. -This Section applies regardless of whether You are a government, non-profit academic, or other non-profit entity or a Commercial Entity. - -* **Patent License.** Subject to the limitations in the Sections above, each Originator hereby grants You a perpetual, worldwide, non-exclusive, royalty-free license under Patent Claims of such Originator to make, use, sell, offer for sale, have made, and import the Product. The foregoing patent license does not apply (a) to any code that an Originator has removed from the Product, or (b) for infringement caused by Your modifications of the Product or the combination of any Derivative created by You or on Your behalf with other software. - -GENERAL TERMS -This Section applies regardless of whether You are a government, non-profit academic, or other non-profit entity or a Commercial Entity. - -* **Required Notices.** If You distribute the Product or a Derivative, in Object Code or Source Code form, You shall not remove or otherwise modify any proprietary markings or notices contained within or placed upon the Product or any Derivative. Any distribution of the Product or a Derivative, in Object Code or Source Code form, shall contain a clear and conspicuous Originator copyright and license reference in accordance with the below: - * *Unmodified Product Notice*: “This software package is licensed under the Booz Allen Public License. Copyright © 20__ [Copyright Holder Name]. All Rights Reserved.” - * *Derivative Notice*: “This software package is licensed under the Booz Allen Public License. Portions of this code are Copyright © 20__ [Copyright Holder Name]. All Rights Reserved.” -* **Compliance with Laws.** You agree that You shall not reproduce, display, perform, modify, distribute and otherwise use the Product in any way that violates applicable law or regulation or infringes or violates the rights of others, including, but not limited to, third party intellectual property, privacy, and publicity rights. -* **Disclaimer.** You understand that the Product is licensed to You, and not sold. The Product is provided on an “As Is” basis, without any warranties, representations, and guarantees, whether oral or written, express, implied or statutory, with regard to the Product, including without limitation, warranties of merchantability, fitness for a particular purpose, title, non-infringement, non-interference, and warranties arising from course of dealing or usage of trade, to the maximum extent permitted by applicable law. Originator does not warrant that (i) the Product will meet your needs; (ii) the Product will be error-free or accessible at all times; or (iii) the use or the results of the use of the Product will be correct, accurate, timely, or otherwise reliable. You acknowledge that the Product has not been prepared to meet Your individual requirements, whether or not such requirements have been communicated to Originator. You assume all responsibility for use of the Product. -* **Limitation of Liability.** Under no circumstances and under no legal theory, whether tort (including negligence), contract, or otherwise, shall any Originator, or anyone who distributes the Product in accordance with this License, be liable to You for any direct, indirect, special, incidental, or consequential damages of any character including, without limitation, damages for lost profits, loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses, even if informed of the possibility of such damages. -* **Export Control.** The Product is subject to U.S. export control laws and may be subject to export or import regulations in other countries. You agree to strictly comply with all such laws and regulations and acknowledges that You are responsible for obtaining such licenses to export, re-export, or import as may be required. -* **Severability.** If the application of any provision of this License to any particular facts or circumstances shall be held to be invalid or unenforceable, then the validity and enforceability of other provisions of this License shall not in any way be affected or impaired thereby. diff --git a/foundation/foundation-service-discovery/README.md b/foundation/foundation-service-discovery/README.md deleted file mode 100644 index eb5735103..000000000 --- a/foundation/foundation-service-discovery/README.md +++ /dev/null @@ -1,170 +0,0 @@ -# service-discovery-core - -## Before we begin (notes) - -This module provides an example of how Service Discovery can be implemented using [Quarkus](https://quarkus.io) and [Vert.x Service Discovery](https://vertx.io/docs/vertx-service-discovery/java). - -### Available REST endpoints - -The **ServiceDiscoveryResource** class exposes the following REST endpoints: -- POST `/service-discovery/registry` - - Registers a service in Service Discovery. - - The details of the service must be provided in the request body: - ```json - { - "name": "service-name", - "type": "service-type", - "endpoint": "/service-endpoint", - "metadata": { - "key1": "val1", - "key2": "val2", - ...any number of key/value pairs - } - } - ``` - - A response containing the registered service record will be returned upon successful registration. - -- PUT `/service-discovery/registry/{registrationId}` - - Updates a service in Service Discovery with the given `registrationId`. - - The details of the service must be provided in the request body: - ```json - { - "name": "service-name", - "type": "service-type", - "endpoint": "/service-endpoint", - "metadata": { - "key1": "val1", - "key2": "val2", - ...any number of key/value pairs - } - } - ``` - - A response indicating whether the updated was successful or not will be returned (true if successful, false if not). - - -- DELETE `/service-discovery/registry/{registrationId}` - - Unregisters (removes) a service from Service Discovery. - - The registration ID from the service registration record must be passed in the `{registrationId}` parameter. - - A response indicating whether the unregistration was successful or not will be returned (true if successful, false if not). - -- GET `/service-discovery/service/{name}` - - Retrieves the registered services with the given name passed in the `{name}` parameter. - - Optional Query Param `includeOutOfService` will add services that are unavailable to the results if set to true - - A response containing a list of the matching services' registration records will be returned. - -- GET `/service-discovery/service/{type}` - - Retrieves the registered services with the given type passed in the `{type}` parameter. - - Optional Query Param `includeOutOfService` will add services that are unavailable to the results if set to true - - A response containing a list of the matching services' registration records will be returned. - -## Building the project - -### Run the build - -`./mvnw clean install` - -### Verify unit tests - -Unit tests to verify registering, unregistering, and retrieving services are executed during the build. If the tests are successful, you will see output similar to the following: - -``` -[INFO] ------------------------------------------------------- -[INFO] T E S T S -[INFO] ------------------------------------------------------- -[INFO] Running com.boozallen.servicediscovery.core.ServiceDiscoveryResourceTest -2021-03-08 12:38:14,747 INFO [io.quarkus] (main) Quarkus 1.12.1.Final on JVM started in 1.615s. Listening on: http://localhost:8081 -2021-03-08 12:38:14,748 INFO [io.quarkus] (main) Profile test activated. -2021-03-08 12:38:14,749 INFO [io.quarkus] (main) Installed features: [cdi, mutiny, resteasy, resteasy-jsonb, resteasy-mutiny, smallrye-context-propagation, vertx] -2021-03-08 12:38:16,167 INFO [com.boo.ser.cor.ServiceDiscoveryProvider] (executor-thread-1) Successfully registered service 'keJoK': eea8211f-92a7-4235-80f5-7aa4039f70fc -2021-03-08 12:38:16,680 INFO [com.boo.ser.cor.ServiceDiscoveryProvider] (executor-thread-1) Successfully unregistered service eea8211f-92a7-4235-80f5-7aa4039f70fc -2021-03-08 12:38:16,750 INFO [com.boo.ser.cor.ServiceDiscoveryProvider] (executor-thread-1) Successfully registered service '5Ooq9': 54d4494e-34fd-43c8-bda7-0a4351ef2788 -2021-03-08 12:38:16,841 INFO [com.boo.ser.cor.ServiceDiscoveryProvider] (executor-thread-1) Successfully registered service 'PW9az': 297c07b4-4497-4f0f-a97d-1f100cb2330b -2021-03-08 12:38:16,855 INFO [com.boo.ser.cor.ServiceDiscoveryProvider] (executor-thread-1) 1 services found with name 'PW9az' -2021-03-08 12:38:16,900 ERROR [com.boo.ser.cor.ServiceDiscoveryProvider] (executor-thread-1) Failed to unregister service 4NPra: io.vertx.core.impl.NoStackTraceThrowable: Record '4NPra' not found - -[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.403 s - in com.boozallen.servicediscovery.core.ServiceDiscoveryResourceTest -2021-03-08 12:38:16,928 INFO [io.ver.ser.imp.DiscoveryImpl] (main) Stopping service discovery -2021-03-08 12:38:16,932 INFO [io.ver.ser.imp.DiscoveryImpl] (main) Discovery bridges stopped -2021-03-08 12:38:16,945 INFO [io.quarkus] (main) Quarkus stopped in 0.031s -[INFO] -[INFO] Results: -[INFO] -[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0 -``````` - -## Running manually - -1. Run the following to start the Quarkus application in development-mode: - - `./mvnw quarkus:dev -pl :service-discovery-core` - - The following output will indicate when the application is up and running: - ``` - __ ____ __ _____ ___ __ ____ ______ - --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ - -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \ - --\___\_\____/_/ |_/_/|_/_/|_|\____/___/ - 2021-03-08 13:15:13,348 INFO [io.quarkus] (Quarkus Main Thread) service-discovery-core 1.0.0-SNAPSHOT on JVM (powered by Quarkus 1.12.1.Final) started in 1.309s. Listening on: http://localhost:8000 - 2021-03-08 13:15:13,351 INFO [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated. - 2021-03-08 13:15:13,351 INFO [io.quarkus] (Quarkus Main Thread) Installed features: [cdi, mutiny, resteasy, resteasy-jsonb, resteasy-mutiny, smallrye-context-propagation, vertx] - ```` - -2. Using a REST client such as Postman, send a POST request to `http://localhost:8000/service-discovery/registry` with the following request body to register a service: - - ```json - { - "name": "MyService", - "type": "MyServiceType", - "endpoint": "/my-service-endpoint", - "metadata": { - "key1": "val1", - "key2": "val2" - } - } - ``` - - - Make sure to set request header 'Content-Type' to 'application/json'. - -3. Verify that a successful response containing the service registration record is returned: - - ```json - { - "location": { - "endpoint": "/my-service-endpoint" - }, - "metadata": { - "key1": "val1", - "key2": "val2" - }, - "name": "MyService", - "registration": "357f6b9f-e1fd-4cb3-bf8f-cabd581ed406", - "status": "UP", - "type": "MyServiceType" - } - ``` - -4. Send a GET request to `http://localhost:8000/service-discovery/service/MyService` to retrieve the registered service. - -5. Verify that the service's registration record is returned in the response list: - - ```json - [ - { - "location": { - "endpoint": "/my-service-endpoint" - }, - "metadata": { - "key1": "val1", - "key2": "val2" - }, - "name": "MyService", - "registration": "357f6b9f-e1fd-4cb3-bf8f-cabd581ed406", - "status": "UP", - "type": "MyServiceType" - } - ] - ``` - -6. Send a DELETE request to `http://localhost:8000/service-discovery/registry/{registrationId}` with the registration ID of the service (unique identifier in the `registration` field) to unregister it. - -7. Re-run step 4 and verify that the service is no longer returned in the response list. - -8. The application can be stopped using ctrl+c in the window in which it was started (from step 1). diff --git a/foundation/foundation-service-discovery/pom.xml b/foundation/foundation-service-discovery/pom.xml deleted file mode 100644 index b1e6bd18e..000000000 --- a/foundation/foundation-service-discovery/pom.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - 4.0.0 - - - com.boozallen.aissemble - foundation - 1.10.0-SNAPSHOT - - - foundation-service-discovery - aiSSEMBLE::Foundation::Service Discovery - - - - - ${project.groupId} - aissemble-quarkus-bom - ${project.version} - pom - import - - - - - - - - io.quarkus - quarkus-resteasy-reactive - - - - io.quarkus - quarkus-resteasy-reactive-jackson - - - - - io.quarkus - quarkus-vertx - - - io.vertx - vertx-service-discovery - - - - - io.quarkus - quarkus-junit5 - test - - - io.rest-assured - rest-assured - test - - - - - - - io.quarkus - quarkus-maven-plugin - true - - - - build - - - - - - maven-surefire-plugin - - - org.jboss.logmanager.LogManager - ${maven.home} - - - - - org.apache.maven.plugins - maven-source-plugin - - - - diff --git a/foundation/foundation-service-discovery/src/main/java/com/boozallen/servicediscovery/core/ServiceDiscoveryProvider.java b/foundation/foundation-service-discovery/src/main/java/com/boozallen/servicediscovery/core/ServiceDiscoveryProvider.java deleted file mode 100644 index 031c5fddf..000000000 --- a/foundation/foundation-service-discovery/src/main/java/com/boozallen/servicediscovery/core/ServiceDiscoveryProvider.java +++ /dev/null @@ -1,259 +0,0 @@ -package com.boozallen.servicediscovery.core; - -/*- - * #%L - * Service Discovery::Core - * %% - * Copyright (C) 2021 Booz Allen - * %% - * This software package is licensed under the Booz Allen Public License. All Rights Reserved. - * #L% - */ - -import java.util.List; - -import jakarta.annotation.PostConstruct; -import jakarta.annotation.PreDestroy; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.inject.Inject; - -import io.smallrye.mutiny.Uni; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.vertx.core.Vertx; -import io.vertx.mutiny.core.Promise; -import io.vertx.servicediscovery.Record; -import io.vertx.servicediscovery.ServiceDiscovery; -import io.vertx.servicediscovery.ServiceDiscoveryOptions; - -/** - * Service Discovery provider to handle service registration. - */ -@ApplicationScoped -public class ServiceDiscoveryProvider { - - private static final Logger logger = LoggerFactory.getLogger(ServiceDiscoveryProvider.class); - - @Inject - Vertx vertx; - - private ServiceDiscovery discovery; - - /** - * Creates an instance of the vert.x Service Discovery upon initialization. - */ - @PostConstruct - void initialize() { - final ServiceDiscoveryOptions options = new ServiceDiscoveryOptions(); - options.setAnnounceAddress("service-discovery-announce"); - options.setName("service-discovery-provider"); - - discovery = ServiceDiscovery.create(vertx, options); - } - - /** - * Closes the vert.x Service Discovery instance upon teardown. - */ - @PreDestroy - void cleanup() { - discovery.close(); - } - - /** - * Registers the given service in Service Discovery. - * - * @param service - * the service to register - * @return an asynchronous result containing the service registration record - * if registration was successful - */ - public Uni registerService(final ServiceRegistration service) { - // promise object to handle asynchronous registration - final Promise promise = Promise.promise(); - final Record serviceRecord = service.mapToServiceDiscoveryRecord(); - - // register service in service discovery - discovery.publish(serviceRecord, handler -> { - if (handler.succeeded()) { - Record publishedRecord = handler.result(); - logger.info("Successfully registered service '{}': {}", publishedRecord.getName(), - publishedRecord.getRegistration()); - // notify that registration is completed successfully - promise.complete(publishedRecord); - } else { - String message = "Failed to register service " + service.getName(); - logger.error(message, handler.cause()); - // notify that registration completed in failure - promise.fail(message); - } - }); - - // return future object which will be aware of when the registration - // completes and will contain the registered service record if - // successful - return promise.future(); - } - - /** - * Unregisters the service in Service Discovery with the given registration - * id. - * - * @param registrationId - * the registration id of the service to unregister - * @return an asynchronous result indicating whether or not the - * unregistration was successful - */ - public Uni unregisterService(final String registrationId) { - // promise object to handle asynchronous unregistration - final Promise promise = Promise.promise(); - - // unregister service from service discovery - discovery.unpublish(registrationId, handler -> { - if (handler.succeeded()) { - logger.info("Successfully unregistered service {}", registrationId); - // notify that unregistration was successful - promise.complete(true); - } else { - logger.error("Failed to unregister service {}", registrationId, handler.cause()); - // notify that unregistration was not successful - promise.complete(false); - } - }); - - // return future object that will be aware of when unregistration is complete - return promise.future(); - } - - /** - * Returns a list of registered services in Service Discovery with the given - * name. - * - * @param name - * the name of the services to retrieve - * @return an asynchronous result containing the list of registered services - * with the given name - */ - public Uni> getServicesByName(final String name) { - return getServicesByName(name, false); - } - - /** - * Returns a list of registered services in Service Discovery with the given - * name. - * - * @param name - * the name of the services to retrieve - * @param includeOutOfService - * whether or not to include services with out of service statuses - * @return an asynchronous result containing the list of registered services - * with the given name - */ - public Uni> getServicesByName(final String name, final boolean includeOutOfService) { - // promise object to handle asynchronous search - final Promise> promise = Promise.promise(); - - // filter registered records by name - discovery.getRecords(filter -> name.equalsIgnoreCase(filter.getName()), includeOutOfService, handler -> { - if (handler.succeeded()) { - List results = handler.result(); - logger.info("{} services found with name '{}'", results.size(), name); - // notify that the search completed successfully - promise.complete(results); - } else { - String message = "Failed to retrieve services with name '" + name + "'"; - logger.error(message, handler.cause()); - // notify that the search completed in failure - promise.fail(message); - } - }); - - // return future object that will be aware of when the search is - // complete and will contain the list of matched service records if - // successful - return promise.future(); - } - - /** - * Returns a list of registered services in Service Discovery with the given - * type. - * - * @param type - * the type of the services to retrieve - * @return an asynchronous result containing the list of registered services - * with the given type - */ - public Uni> getServiceByType(final String type) { - return getServiceByType(type, false); - } - - /** - * Returns a list of registered services in Service Discovery with the given - * type. - * - * @param type - * the type of the services to retrieve - * @param includeOutOfService - * whether or not to include services with out of service status - * @return an asynchronous result containing the list of registered services - * with the given type - */ - public Uni> getServiceByType(final String type, final Boolean includeOutOfService) { - // promise object to handle asynchronous search - final Promise> promise = Promise.promise(); - - if (type != null) { - // filter registered records by name - discovery.getRecords(filter -> type.equalsIgnoreCase(filter.getType()), includeOutOfService, handler -> { - if (handler.succeeded()) { - List results = handler.result(); - logger.info("{} services found with type '{}'", results.size(), type); - // notify that the search completed successfully - promise.complete(results); - } else { - String message = "Failed to retrieve services with name {}"; - logger.error(message, type, handler.cause()); - // notify that the search completed in failure - promise.fail(message); - } - }); - } else { - promise.fail("Must provide a type"); - } - - // return future object that will be aware of when the search is - // complete and will contain the list of matched service records if - // successful - return promise.future(); - } - - /** - * Update an existing record. Record must be published and have a registration ID - * @param record the record to update - * @return true if successfully updated, false otherwise - */ - public Uni update(final Record record) { - final Promise promise = Promise.promise(); - - if (record != null) { - discovery.update(record, handler -> { - if (handler.succeeded()) { - logger.info("{} service updated", record.getName()); - final Record result = handler.result(); - // notify that the search completed successfully - promise.complete(true); - } else { - String message = "Failed to update service with name {}"; - logger.error(message, record.getName(), handler.cause()); - // notify that the search completed in failure - promise.complete(false); - } - }); - } else { - promise.fail("Record must not be null"); - } - - return promise.future(); - } - -} diff --git a/foundation/foundation-service-discovery/src/main/java/com/boozallen/servicediscovery/core/ServiceDiscoveryResource.java b/foundation/foundation-service-discovery/src/main/java/com/boozallen/servicediscovery/core/ServiceDiscoveryResource.java deleted file mode 100644 index 61d978a10..000000000 --- a/foundation/foundation-service-discovery/src/main/java/com/boozallen/servicediscovery/core/ServiceDiscoveryResource.java +++ /dev/null @@ -1,126 +0,0 @@ -package com.boozallen.servicediscovery.core; - -/*- - * #%L - * Service Discovery::Core - * %% - * Copyright (C) 2021 Booz Allen - * %% - * This software package is licensed under the Booz Allen Public License. All Rights Reserved. - * #L% - */ - -import java.util.List; - -import jakarta.inject.Inject; -import jakarta.ws.rs.DELETE; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.POST; -import jakarta.ws.rs.PUT; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.PathParam; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.QueryParam; -import jakarta.ws.rs.core.MediaType; - -import io.smallrye.mutiny.Uni; -import io.vertx.servicediscovery.Record; - -/** - * Resource for service discovery REST calls. - */ -@Path("/service-discovery") -public class ServiceDiscoveryResource { - - @Inject - ServiceDiscoveryProvider provider; - - /** - * Endpoint to register a service in Service Discovery. - * - * @param service - * the service to register - * @return the registered service record if registration was successful - */ - @POST - @Path("/registry") - public Uni register(ServiceRegistration service) { - return provider.registerService(service); - } - - /** - * Endpoint to update services - * - * @param registrationId - * the ID of the service to update - * @param record - * the record with the values to use for the service - * @return the list of services with the given type - */ - @PUT - @Path("/registry/{registrationId}") - @Produces(MediaType.TEXT_PLAIN) - public Uni update(@PathParam("registrationId") String registrationId, final Record record) { - record.setRegistration(registrationId); - return provider.update(record); - } - - /** - * Endpoint to unregister a service in Service Discovery. - * - * @param registrationId - * the registration id of the service to unregister - * @return whether the unregistration was successful or not - */ - @DELETE - @Path("/registry/{registrationId}") - @Produces(MediaType.TEXT_PLAIN) - public Uni unregister(@PathParam("registrationId") String registrationId) { - return provider.unregisterService(registrationId); - } - - /** - * Endpoint to retrieve registered services in Service Discovery with the - * given name. - * - * @param name - * the name of the services to retrieve - * @return the list of services with the given name - */ - @GET - @Path("/service/{name}") - public Uni> getByName(@PathParam("name") String name, - @QueryParam("includeOutOfService") Boolean includeOutOfService) { - Uni> results; - if (includeOutOfService != null) { - results = provider.getServicesByName(name, includeOutOfService); - } else { - results = provider.getServicesByName(name); - } - - return results; - } - - /** - * Endpoint to retrieve registered services in Service Discovery with the - * given type. - * - * @param type - * the type of the services to retrieve - * @return the list of services with the given type - */ - @GET - @Path("/service") - public Uni> getByType(@QueryParam("type") String type, - @QueryParam("includeOutOfService") Boolean includeOutOfService) { - Uni> results; - if (includeOutOfService != null) { - results = provider.getServiceByType(type, includeOutOfService); - } else { - results = provider.getServiceByType(type); - } - - return results; - } - -} diff --git a/foundation/foundation-service-discovery/src/main/java/com/boozallen/servicediscovery/core/ServiceRegistration.java b/foundation/foundation-service-discovery/src/main/java/com/boozallen/servicediscovery/core/ServiceRegistration.java deleted file mode 100644 index 9a8521941..000000000 --- a/foundation/foundation-service-discovery/src/main/java/com/boozallen/servicediscovery/core/ServiceRegistration.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.boozallen.servicediscovery.core; - -/*- - * #%L - * Service Discovery::Core - * %% - * Copyright (C) 2021 Booz Allen - * %% - * This software package is licensed under the Booz Allen Public License. All Rights Reserved. - * #L% - */ - -import java.util.Map; - -import io.vertx.core.json.JsonObject; -import io.vertx.servicediscovery.Record; - -/** - * Represents a service to be registered in Service Discovery. - */ -public class ServiceRegistration { - - private String name; - private String type; - private String endpoint; - private Map metadata; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getEndpoint() { - return endpoint; - } - - public void setEndpoint(String endpoint) { - this.endpoint = endpoint; - } - - public Map getMetadata() { - return metadata; - } - - public void setMetadata(Map metadata) { - this.metadata = metadata; - } - - /** - * Convenience method to map the service registration to a vert.x Service - * Discovery record. - * - * @return the service registration mapped to a vert.x Service Discovery - * record - */ - public Record mapToServiceDiscoveryRecord() { - Record record = new Record(); - record.setName(getName()); - record.setType(getType()); - record.setLocation(new JsonObject().put("endpoint", getEndpoint())); - record.setMetadata(new JsonObject()); - if (getMetadata() != null) { - for (String key : getMetadata().keySet()) { - String value = getMetadata().get(key); - record.getMetadata().put(key, value); - } - } - - return record; - } - -} diff --git a/foundation/foundation-service-discovery/src/main/resources/application.properties b/foundation/foundation-service-discovery/src/main/resources/application.properties deleted file mode 100644 index 7086a0e7f..000000000 --- a/foundation/foundation-service-discovery/src/main/resources/application.properties +++ /dev/null @@ -1,11 +0,0 @@ -### -# #%L -# Service Discovery::Core -# %% -# Copyright (C) 2021 Booz Allen -# %% -# This software package is licensed under the Booz Allen Public License. All Rights Reserved. -# #L% -### -quarkus.http.port=8000 -quarkus.http.test-port=14800 diff --git a/foundation/foundation-service-discovery/src/test/java/com/boozallen/servicediscovery/core/ServiceDiscoveryResourceTest.java b/foundation/foundation-service-discovery/src/test/java/com/boozallen/servicediscovery/core/ServiceDiscoveryResourceTest.java deleted file mode 100644 index 016528da0..000000000 --- a/foundation/foundation-service-discovery/src/test/java/com/boozallen/servicediscovery/core/ServiceDiscoveryResourceTest.java +++ /dev/null @@ -1,211 +0,0 @@ -package com.boozallen.servicediscovery.core; - -/*- - * #%L - * Service Discovery::Core - * %% - * Copyright (C) 2021 Booz Allen - * %% - * This software package is licensed under the Booz Allen Public License. All Rights Reserved. - * #L% - */ - -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.response.Response; -import io.restassured.specification.RequestSpecification; -import io.vertx.servicediscovery.Status; -import org.apache.commons.lang3.RandomStringUtils; -import org.junit.jupiter.api.Test; - -import jakarta.ws.rs.core.MediaType; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static io.restassured.RestAssured.given; -import static io.restassured.RestAssured.when; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.jupiter.api.Assertions.assertEquals; - -@QuarkusTest -@SuppressWarnings("unchecked") -public class ServiceDiscoveryResourceTest { - - @Test - public void testRegister() { - ServiceRegistration service = createTestService(); - - // create register request for service - RequestSpecification registerRequest = given() - .body(service) - .contentType(MediaType.APPLICATION_JSON); - - // send the register request - Response registerResponse = registerRequest - .when() - .post("/service-discovery/registry"); - - // verify expected response from register request - registerResponse.then() - .statusCode(200) - .body("registration", notNullValue()) - .body("status", notNullValue()) - .body("name", is(service.getName())) - .body("type", is(service.getType())) - .body("location.map.endpoint", is(service.getEndpoint())) - .body("metadata.map", is(service.getMetadata())); - } - - @Test - public void testUnregister_serviceExists() { - ServiceRegistration service = createTestService(); - - // register the service - Response registerResponse = given() - .body(service) - .contentType(MediaType.APPLICATION_JSON) - .post("/service-discovery/registry"); - - // get the registration id of the registered service - String registrationId = registerResponse - .jsonPath().getString("registration"); - - // send request to unregister the service - Response unregisterResponse = when() - .delete("/service-discovery/registry/{registrationId}", registrationId); - - // verify expected response from unregister request - unregisterResponse.then() - .statusCode(200) - .body(is(Boolean.TRUE.toString())); - } - - @Test - public void testUnregister_serviceDoesNotExist() { - // send request to unregister service that doesn't exist - Response unregisterResponse = when() - .delete("/service-discovery/registry/{registrationId}", RandomStringUtils.randomAlphanumeric(5)); - - // verify expected response from unregister request - unregisterResponse.then() - .statusCode(200) - .body(is(Boolean.FALSE.toString())); - } - - @Test - public void testGetByName() { - ServiceRegistration service = createTestService(); - - // register the service - Response registerResponse = given() - .body(service) - .contentType(MediaType.APPLICATION_JSON) - .post("/service-discovery/registry"); - - // send request to get services by name - Response getResponse = when() - .get("service-discovery/service/{name}", service.getName()); - - // verify expected response and extract the returned list - List> results = getResponse.then() - .statusCode(200) - .extract().as(List.class); - - // verify expected results from the get request - assertEquals(1, results.size(), "Unexpected number of services returned"); - - Object expectedRegistrationId = registerResponse.jsonPath().get("registration"); - Object actualRegistrationId = results.get(0).get("registration"); - assertEquals(expectedRegistrationId, actualRegistrationId, "Unexpected service returned"); - } - - @Test - public void testGetByType() { - ServiceRegistration service = createTestService(); - - // register the service - Response registerResponse = given() - .body(service) - .contentType(MediaType.APPLICATION_JSON) - .post("/service-discovery/registry"); - - // send request to get services by name - Response getResponse = given() - .queryParam("type", service.getType()) - .when() - .get("service-discovery/service"); - - // verify expected response and extract the returned list - List> results = getResponse.then() - .statusCode(200) - .extract() - .as(List.class); - - // verify expected results from the get request - assertEquals(1, results.size(), "Unexpected number of services returned"); - - Object expectedRegistrationId = registerResponse.jsonPath().get("registration"); - Object actualRegistrationId = results.get(0).get("registration"); - assertEquals(expectedRegistrationId, actualRegistrationId, "Unexpected service returned"); - } - - @Test - public void testUpdate() { - final ServiceRegistration service = createTestService(); - - final Response registerResponse = given() - .body(service) - .contentType(MediaType.APPLICATION_JSON) - .post("/service-discovery/registry"); - - final Response getResponse = when() - .get("service-discovery/service/{name}", service.getName()); - - // verify expected response and extract the returned list - List> results = (List>) getResponse.then() - .statusCode(200) - .extract() - .as(List.class); - - Map record = results.get(0); - record.put("status", Status.DOWN.toString()); - - final Response updateResponse = given() - .body(record) - .contentType(MediaType.APPLICATION_JSON) - .put("/service-discovery/registry/{registrationId}", record.get("registration")); - - updateResponse.then() - .statusCode(200) - .body(is(Boolean.TRUE.toString())); - - final Response getResult = given() - .queryParam("includeOutOfService", true) - .when() - .get("service-discovery/service/{name}", service.getName()); - - // verify expected response and extract the returned list - List> updatedResults = (List>) getResult.then() - .statusCode(200) - .extract() - .as(List.class); - - Map updatedRecord = updatedResults.get(0); - assertEquals(Status.DOWN.toString(), updatedRecord.get("status"), "Updated record does not have a down status"); - } - - private ServiceRegistration createTestService() { - ServiceRegistration service = new ServiceRegistration(); - service.setName(RandomStringUtils.randomAlphanumeric(5)); - service.setType(RandomStringUtils.randomAlphanumeric(5)); - service.setEndpoint(RandomStringUtils.randomAlphanumeric(5)); - service.setMetadata(new HashMap<>()); - for (int i = 0; i < 5; i++) { - service.getMetadata().put(RandomStringUtils.randomAlphanumeric(5), RandomStringUtils.randomAlphanumeric(5)); - } - - return service; - } - -} diff --git a/foundation/pom.xml b/foundation/pom.xml index df6fdd5a5..66dafd0ca 100644 --- a/foundation/pom.xml +++ b/foundation/pom.xml @@ -29,7 +29,6 @@ foundation-data-access foundation-metadata foundation-transform - foundation-service-discovery foundation-messaging foundation-alerting foundation-drift-detection