Giter VIP home page Giter VIP logo

sysml-v2-api-services's Introduction

SysML v2 API and Services

Pilot implementation of REST/HTTP Platform-specific model (PSM) of SysML v2 API and Services, managed by the SysML v2 Submission Team (SST).

Usage Scenarios

There are two main usage scenarios.

  1. Scenario 1: Accessing SysML v2 REST/HTTP API deployed on SST servers You do not need to clone this repository or setup anything on your local machine. You can access the REST/HTTP API on one of our deployed servers via Swagger doc, or a REST API client (e.g Postman) on your local machine. Ignore the rest of the instructions if you are interested in this scenario. Contact the SST to learn more.

  2. Scenario 2: Running the SysML v2 REST/HTTP API and Services locally on your machine You can clone this repository, setup the backend database (PostgreSQL), and run the pilot implementation of SysML v2 API & Services locally on your machine. The same REST API that is deployed on the SST servers will be available on localhost. Follow the instructions below if you are interested in this scenario.

Refer to the SysML v2 API Cookbook for examples and patterns to use the SysML v2 API, specifically the REST/HTTP API.

Setting up pilot implementation of SysML v2 API and Services on your local machine

Setup PostgreSQL

This pilot implementation uses PostgreSQL as the backend database. The easiest way to setup PostgreSQL locally is to run it as a Docker container.

  1. Use the docker pull command to download the docker image for the latest version of PostgreSQL available on Docker Hub - https://hub.docker.com/_/postgres

  2. Use the docker run command to start a docker container from the downloaded image, as shown below. This will initialize PostgreSQL database in a Docker container and make it available at port 5432 on your local machine.

    docker run --name sysml2-postgres -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -e POSTGRES_DB=sysml2 -d postgres

  3. Connect to the PostgreSQL database, running as a docker container, from any PostgreSQL client to verify. Use the following connection details.

  • Host = localhost
  • Port = 5432
  • User = postgres
  • Password = mysecretpassword

Setup Java 11

This pilot implementation uses JDK 11 for compiling and running SysML v2 API and Services. Download and setup JDK 11 on your machine. You can use Oracle JDK 11 or OpenJDK 11.

Setup sbt

This pilot implementation uses the Play framework (https://www.playframework.com/) for the web-application and sbt (https://www.scala-sbt.org/) as the build tool. You need to setup sbt to be able to compile and run SysML v2 API and Services. There are two options to do this:

1. Option 1 - Use IntelliJ as your IDE and install the Scala plugin as shown here - https://www.jetbrains.com/help/idea/discover-intellij-idea-for-scala.html. This will setup sbt and related infrastructure for compiling and running the SysML v2 API and Services web-application, either from within IntelliJ or from the command line.

2. Option 2 - Install sbt as a standalone on your machine from here - https://www.scala-sbt.org/. You will be compiling and running SysML v2 API and Services web-application from the command line.

Clone this repository

Clone this repository (SysML-v2-API-Services). Check out the latest release/tag (e.g. 2020-10) or the develop branch.

Run SysML v2 API & Services

  1. Run sbt clean command to clean the project, as shown below.

  2. Run sbt run command to compile and run the SysML v2 API and Services web-application, as shown below.

User@Machine MINGW64 ~/MyGitRepos/SysML-v2-API-Services (develop)
$ sbt clean
[info] Loading global plugins from C:\Users\User\.sbt\1.0\plugins
[info] Loading settings for project sysml-v2-api-services-build from plugins.sbt,scaffold.sbt ...
[info] Loading project definition from C:\Users\User\MyGitRepos\SysML-v2-API-Services\project
[info] Loading settings for project root from build.sbt ...
[info] Set current project to SysML-v2-API-Services (in build file:/C:/Users/User/MyGitRepos/SysML-v2-API-Services/)
[success] Total time: 0 s, completed Nov 11, 2020, 10:54:27 AM

User@Machine MINGW64 ~/MyGitRepos/SysML-v2-API-Services (develop)
$ sbt run
[info] Loading global plugins from C:\Users\User\.sbt\1.0\plugins
[info] Loading settings for project sysml-v2-api-services-build from plugins.sbt,scaffold.sbt ...
[info] Loading project definition from C:\Users\User\MyGitRepos\SysML-v2-API-Services\project
[info] Loading settings for project root from build.sbt ...
[info] Set current project to SysML-v2-API-Services (in build file:/C:/Users/User/MyGitRepos/SysML-v2-API-Services/)
[info] Updating ...
[info] Done updating.
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.

--- (Running the application, auto-reloading is enabled) ---

[info] p.c.s.AkkaHttpServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000

(Server started, use Enter to stop and go back to the console...)
  1. Open a web-browser and go to localhost:9000/docs/. This will start to load the application and compile the web-application which may take a few minutes. Once loaded, you will see the Swagger doc for the SysML v2 REST/HTTP API as shown below.

REST/HTTP API

  1. You can now make REST/HTTP requests to your local SysML v2 API and Services web application either via Swagger doc, or via any REST/HTTP client such as Postman.

sysml-v2-api-services's People

Contributors

ivan-gomes avatar manasbajaj avatar seidewitz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sysml-v2-api-services's Issues

Project dependencies are not updated

It's unfortunate that the dependencies of this project have not been updated - sbt 1.2.8 vs 1.8.2 etc.
Users could of course do this themselves, but it's not as simple as just changing the sbt version number and things will continue to work. For example, sbt 1.7.2 is the latest version that can be loaded without errors (after fixes to the build.sbt syntax), but it won't compile due to internal errors in twirl.
Using sbt 1.2.8 is problematic due to its dependency on a vulnerable version of log4j.

API Services default port 9000 conflicts with MinIO

Hello,

I noticed that the current default port in the SysML-v2-API-Services implementation is 9000, which is the also the default port used by MinIO, a very popular open-source S3-compliant object storage. Might be worth considering a different default port for the final implementation?

Seed Data

I have the system up and running on my local machine, but the database is empty so there are no projects to work with. Is there a way to seed the database from a .sysml file I already have?

add junixsocket to deps to enable socket file based postgresql connection

See c85217b

This commit adds the junixsocket library to the dependencies. This
allows the usage of a UNIX domain socket connection to a postgresql
server. This promises both better performance, and it allows to use
a Linux user identity for authentication against the DB (versus
username/password auth for TCP/IP based communication to the DB).

The change is non-intrusive, i.e. per default TCP/IP is still used and
works as intended.

For more information, checkout:

In particular, setting the following two properties in the
persistence.xml suffices to connect to a postgresql via a socket file:

javax.persistence.jdbc.url='jdbc:postgresql://localhost/db-name?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory$SystemProperty'
org.newsclub.net.unix.socket.default=/run/postgresql/.s.PGSQL.5432
diff --git a/build.sbt b/build.sbt
index 80054dd..12ec88b 100644
--- a/build.sbt
+++ b/build.sbt
@@ -18,6 +18,7 @@ libraryDependencies += "com.fasterxml.jackson.core" % "jackson-databind" % "2.9.
 libraryDependencies += "com.fasterxml.jackson.datatype" % "jackson-datatype-hibernate5" % "2.9.8"
 libraryDependencies += "io.swagger" % "swagger-play2_2.12" % "1.6.0"
 libraryDependencies += "org.reflections" % "reflections" % "0.9.10"
+libraryDependencies += "com.kohlschutter.junixsocket" % "junixsocket-core" % "2.8.3"
 
 javacOptions ++= Seq("-s", "app")

Open Api scheme model not exist.

Open Api scheme model not exist, i need to prepare the TFG and prepare a diagram drawing from python client on it.

Thanks and Regards

potential issues found in openapi.json - body should be required on POST and PUT methods, document states that these are not required

Dear All,

I am studying the openapi.json file at https://raw.githubusercontent.com/Systems-Modeling/SysML-v2-API-Services/master/public/docs/openapi.json.

The postProject operation as specified between lines 80 and 100:

      "post": {
        "tags": [
          "Project"
        ],
        "summary": "Create project",
        "operationId": "postProject",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProjectRequest"
              },
              "examples": {
                "ProjectRequest": {
                  "$ref": "#/components/examples/ProjectRequest"
                }
              }
            }
          },
          "required": false
        }

states that a POST body is not required (see "required": false. Since one has to specify at least the name and an optional description that seems to be a bit odd. I think it should be "required": true.

The same can be found on the PUT method

Project `PUT` method does not work.

SysML v2 API and Services version: 2022-06 (on Jul 18, 2022)

Steps to reproduce:

  • Using the api client, create a project.
  • Modify the name/description of the project with the project PUT method.
  • Get the project details. The returned value of the properties name and description are null.

The following simple Kotlin snippet reproduces the problem: api-client-bug-report.zip (the project uses the SysML v2 API Java Client. Essential part:

val projectApi = ProjectApi(defaultClient)
//...
val project = projectApi.postProject(Project().apply { name = "demo project" })
val MODIFIED_NAME = "modified name"
projectApi.putProjectById(project.atId, project.apply { name = MODIFIED_NAME })
val modifiedProject = projectApi.getProjectById(project.atId)
assert(modifiedProject.name == MODIFIED_NAME) // false: AssertionError (if -ea flag is provided for JVM), modifiedProject.name = null

Expected output: the project name/description is the updated name/description

Actual output: these properties are null

Dockerfile, if anyone finds it useful...

Hi,
I do not know if this has any value for you, but I created a dockerfile for it.
If there is interest, then I also have some files for installing a postgres and creating a docker network between the postgres and the sysml-v2-api-services.

FROM sbtscala/scala-sbt:graalvm-ce-22.3.3-b1-java11_1.9.8_3.3.1
WORKDIR /app
COPY ./ /app

RUN sbt clean && sbt compile
EXPOSE  9000
CMD ["sbt","run"]

Non-empty project cannot be deleted due to foreign key constraints in the database

SysML v2 API and Services version: 2022-05 (on Jun 17, 2022)

Steps to reproduce:

  • Using the api client, create a non-empty project (e.g. an empty commit).
  • Send a request to delete this project.

The following simple project reproduces the problem: api-client-bug-report.zip (the project uses the SysML v2 API Java Client). Essential part:

val projectApi = ProjectApi(defaultClient)
val commitApi = CommitApi(defaultClient)
//...
val project = projectApi.postProject(Project().apply {
    name = "demo project"
})
commitApi.postCommitByProject(project.atId, Commit(), null) // An empty commit is added
projectApi.deleteProjectById(project.atId) // Exception: Internal Server Error (update or delete on table "project" violates foreign key constraint)

Expected output: the project is deleted from the database with all of its contents (commits, branches, elements, etc.).

Actual output:
on the demo project side: ApiException: Internal Server Error
in the pilot implementation server:

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[RollbackException: Error while committing the transaction]]
        at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:351)
        at play.api.http.HttpErrorHandlerExceptions.throwableToUsefulException(HttpErrorHandler.scala)
        at play.http.JsonHttpErrorHandler.throwableToUsefulException(JsonHttpErrorHandler.java:93)
        at play.http.JsonHttpErrorHandler.onServerError(JsonHttpErrorHandler.java:67)
        at play.core.j.JavaHttpErrorHandlerAdapter.$anonfun$onServerError$1(JavaHttpErrorHandlerAdapter.scala:24)
        at play.core.j.JavaHelpers.$anonfun$invokeWithContext$1(JavaHelpers.scala:290)
        at play.core.j.JavaHelpers.withContext(JavaHelpers.scala:302)
        at play.core.j.JavaHelpers.withContext$(JavaHelpers.scala:298)
        at play.core.j.JavaHelpers$.withContext(JavaHelpers.scala:311)
        at play.core.j.JavaHelpers.invokeWithContext(JavaHelpers.scala:289)
Caused by: javax.persistence.RollbackException: Error while committing the transaction
        at org.hibernate.internal.ExceptionConverterImpl.convertCommitException(ExceptionConverterImpl.java:81)
        at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:107)
        at dao.impl.jpa.JpaDao.lambda$deleteById$2(JpaDao.java:91)
        at jpa.manager.impl.HibernateManager.transact(HibernateManager.java:58)
        at dao.impl.jpa.JpaDao.lambda$deleteById$3(JpaDao.java:86)
        at java.base/java.util.Optional.map(Optional.java:265)
        at dao.impl.jpa.JpaDao.deleteById(JpaDao.java:86)
        at services.BaseService.deleteById(BaseService.java:61)
        at controllers.ProjectController.deleteProjectById(ProjectController.java:79)
        at router.Routes$$anonfun$routes$1.$anonfun$applyOrElse$17(Routes.scala:819)
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181)
        at org.hibernate.internal.ExceptionConverterImpl.convertCommitException(ExceptionConverterImpl.java:65)
        at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:107)
        at dao.impl.jpa.JpaDao.lambda$deleteById$2(JpaDao.java:91)
        at jpa.manager.impl.HibernateManager.transact(HibernateManager.java:58)
        at dao.impl.jpa.JpaDao.lambda$deleteById$3(JpaDao.java:86)
        at java.base/java.util.Optional.map(Optional.java:265)
        at dao.impl.jpa.JpaDao.deleteById(JpaDao.java:86)
        at services.BaseService.deleteById(BaseService.java:61)
Caused by: org.hibernate.exception.ConstraintViolationException: could not execute statement
        at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:112)
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:178)
        at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45)
        at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3481)
        at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3738)
        at org.hibernate.action.internal.EntityDeleteAction.execute(EntityDeleteAction.java:99)
        at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604)
Caused by: org.postgresql.util.PSQLException: ERROR: update or delete on table "project" violates foreign key constraint "fkga25en2ho7o502qrcucb6vgtc" on table "commit"
  Detail: Key (id)=(9810543c-d38c-46e5-b3db-b55b787aaf4a) is still referenced from table "commit".
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)
        at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
        at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
        at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143)
        at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:120)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:175)
        at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45)
        at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3481)

allow overriding of persistence properties with system properties

See 809037c

Prior to this change, the only way to change the persistence settings
was to edit the persistence.xml. In case of a pre-build .jar, the
persistence.xml has to be contained in the .jar with the persistence
module [1], and can not be overridden. However, the current repo
hard-codes the DB connection details in the persistence.xml, which
makes it impossible to override the DB connection details for a fully
built .jar without changing that .jar file.

This change enable the overriding of the properties used for the JPA
EntityManagerFactory with system properties, so that DB connection
details can be altered without changing the .jar file.

diff --git a/app/jpa/manager/impl/HibernateManager.java b/app/jpa/manager/impl/HibernateManager.java
index 793d29c..bf8df83 100644
--- a/app/jpa/manager/impl/HibernateManager.java
+++ b/app/jpa/manager/impl/HibernateManager.java
@@ -38,7 +38,8 @@ public class HibernateManager implements JPAManager {
     private final EntityManagerFactory entityManagerFactory;
 
     public HibernateManager() {
-        entityManagerFactory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
+        entityManagerFactory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME,
+            System.getProperties());
     }
 
     @Override

question: POST for elements

Hello, is there an option to use a POST request to add elements to a specific commit? Thanks for your attention

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.