Skip to content

Commit

Permalink
Feature/601 swagger api docs (#1762)
Browse files Browse the repository at this point in the history
* #601 Swagger api docs
  • Loading branch information
AdrianOlosutean authored May 5, 2021
1 parent 027f695 commit d3b57a0
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 6 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ There are three models used to do this:
- **Dataset**: Specifies where the dataset will be read from on HDFS (**RAW**), the conformance rules that will be applied to it, and where it will land on HDFS once it is conformed (**PUBLISH**)
- **Schema**: Specifies the schema towards which the dataset will be standardized
- **Mapping Table**: Specifies where tables with master reference data can be found (parquet on HDFS), which are used when applying Mapping conformance rules (e.g. the dataset uses **Germany**, which maps to the master reference **DE** in the mapping table)

The Menas web client calls the REST API to get the needed entities.
The REST API exposes a Swagger Documentation UI which documents all the HTTP endpoints exposed. It can be found at **REST_API_HOST/swagger-ui.html**

### Standardization
This is a Spark job which reads an input dataset in any of the supported formats and **produces a parquet dataset with the Menas-specified schema** as output.
Expand All @@ -69,7 +72,6 @@ Ensure the properties there fit your environment.
- Without tests: `mvn clean package -DskipTests `
- With unit tests: `mvn clean package`
- With integration tests: `mvn clean package -Pintegration`
- With component preload file generated: `mvn clean package -PgenerateComponentPreload`

#### Test coverage:
- Test coverage: `mvn scoverage:report`
Expand All @@ -87,10 +89,9 @@ The coverage reports are written in each module's `target` directory and aggrega
The _Spline UI_ can be omitted; in such case the **Menas** `spline.urlTemplate` setting should be set to empty string.

#### Deploying Menas
Simply copy the **menas.war** file produced when building the project into Tomcat's webapps directory.
Simply copy the **menas.war** and **menas-web.war** files produced when building the project into Tomcat's webapps directory.

#### Speed up initial loading time of menas
- Build the project with the generateComponentPreload profile. Component preload will greatly reduce the number of HTTP requests required for the initial load of Menas
#### Speed up initial loading time of Menas
- Enable the HTTP compression
- Configure `spring.resources.cache.cachecontrol.max-age` in `application.properties` of Menas for caching of static resources

Expand Down
10 changes: 10 additions & 0 deletions menas/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@
<version>${embedded.mongo.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ import org.springframework.scheduling.annotation.EnableAsync
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.scheduling.annotation.EnableScheduling
import springfox.documentation.swagger2.annotations.EnableSwagger2

@SpringBootApplication
@EnableAsync
@EnableScheduling
@Configuration
@EnableSwagger2
class Application() {
private val DefaultCorePoolSize = 12
private val DefaultMaxPoolSize = 24
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2018 ABSA Group Limited
*
* 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 za.co.absa.enceladus.menas

import com.google.common.base.Predicate
import com.google.common.base.Predicates.or
import org.springframework.context.annotation.{Bean, Configuration}
import springfox.documentation.builders.PathSelectors.regex
import springfox.documentation.builders.{ApiInfoBuilder, RequestHandlerSelectors}
import springfox.documentation.spi.DocumentationType
import springfox.documentation.spring.web.plugins.Docket
import springfox.documentation.swagger2.annotations.EnableSwagger2
import za.co.absa.enceladus.utils.general.ProjectMetadata

@Configuration
@EnableSwagger2
class SpringFoxConfig extends ProjectMetadata {
@Bean
def api(): Docket = {
new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo)
.select
.apis(RequestHandlerSelectors.any)
.paths(filteredPaths)
.build
}

private def filteredPaths: Predicate[String] =
or[String](regex("/api/dataset.*"), regex("/api/schema.*"),
regex("/api/mappingTable.*"), regex("/api/properties.*"),
regex("/api/monitoring.*"),regex("/api/runs.*"),
regex("/api/user.*"), regex("/api/spark.*"),
regex("/api/configuration.*")
)

private def apiInfo =
new ApiInfoBuilder()
.title("Menas API")
.description("Menas API reference for developers")
.license("Apache 2.0 License")
.version(projectVersion) // api or project?
.build
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import org.springframework.security.web.authentication._
import za.co.absa.enceladus.menas.auth._
import za.co.absa.enceladus.menas.auth.jwt.JwtAuthenticationFilter
import za.co.absa.enceladus.menas.auth.kerberos.MenasKerberosAuthentication
import za.co.absa.enceladus.utils.general.ProjectMetadata


@EnableWebSecurity
Expand Down Expand Up @@ -62,7 +61,9 @@ class WebSecurityConfig @Autowired()(beanFactory: BeanFactory,
.and()
.authorizeRequests()
.antMatchers("/admin/health", "/api/oozie/isEnabled",
"/api/user/version", "/api/configuration/**")
"/api/user/version", "/api/configuration/**",
"/swagger-ui.html", "/webjars/**", "/v2/api-docs", "/swagger-resources",
"/swagger-resources/configuration/ui", "/swagger-resources/configuration/security")
.permitAll()
.anyRequest()
.authenticated()
Expand Down

0 comments on commit d3b57a0

Please sign in to comment.