Skip to content
This repository has been archived by the owner on Nov 27, 2017. It is now read-only.

Commit

Permalink
Started to add Swagger integration
Browse files Browse the repository at this point in the history
  • Loading branch information
rhuss committed Apr 26, 2017
1 parent 0b38ee6 commit 451a3f5
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 19 deletions.
15 changes: 14 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,17 @@ It's meant to be used in a synchronous flow.

### Implementation Notes

In the initial version of this service the supported Camel Connectors (Twitter Mention, Salesforce Upsert, Http Get) are called directly from the same JVM in order to perform the validation. In a next step, these connectors are extracted into dedicated Pods which are managed and pooled and called from this Verifier Service on demand. More on this later ...
In the initial version of this service the supported Camel Connectors (Twitter Mention, Salesforce Upsert, Http Get) are called directly from the same JVM in order to perform the validation. In a next step, these connectors are extracted into dedicated Pods which are managed and pooled and called from this Verifier Service on demand. More on this later ...

### Running it

#### Local

For local development purpose the container can be started directly from a Docker container

[source, bash]
----
mvn package fabric8:build docker:start docker:watch
----

This will rebuild and restart your application every time you recompile the code.
100 changes: 97 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,21 @@
<swagger.version>1.5.12</swagger.version>
<resteasy-spring-boot-starter.version>2.3.0-RELEASE</resteasy-spring-boot-starter.version>
<jackson.version>2.8.7</jackson.version>
<redhat-ipaas-connector.version>0.3.7</redhat-ipaas-connector.version>

<fabric8-maven-plugin.version>3.3.0</fabric8-maven-plugin.version>
<docker-maven-plugin.version>0.20.1</docker-maven-plugin.version>
<license-maven-plugin.version>3.0</license-maven-plugin.version>
<redhat-ipaas-connector.version>0.3.7</redhat-ipaas-connector.version>
<swagger-maven-plugin.version>1.0.0</swagger-maven-plugin.version>
<swagger2markup-maven-plugin.version>1.1.0</swagger2markup-maven-plugin.version>

<apidocs.dir>${project.build.directory}/api-docs</apidocs.dir>
<apidocs.schema.dir>${project.build.outputDirectory}/static</apidocs.schema.dir>

<!-- Base image to use for Docker images. Pinned to 1.2.3 since 1.2.4 has issues because
of Java 1.8.0_121 (1.2.3 is running 1.8.0_111) -->
<java-image>fabric8/java-jboss-openjdk8-jdk:1.2.3</java-image>

<verifier-image>rhipaas/ipaas-verifier:%l</verifier-image>
</properties>

<inceptionYear>2017</inceptionYear>
Expand Down Expand Up @@ -312,17 +320,103 @@
<artifactId>fabric8-maven-plugin</artifactId>
<version>${fabric8-maven-plugin.version}</version>
<configuration>
<mode>kubernetes</mode>
<generator>
<config>
<spring-boot>
<name>rhipaas/ipaas-verifier:%l</name>
<name>${verifier-image}</name>
<from>${java-image}</from>
</spring-boot>
</config>
</generator>
</configuration>
</plugin>

<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker-maven-plugin.version}</version>
<configuration>
<images>
<image>
<name>${verifier-image}</name>
<alias>verfier</alias>
<run>
<ports>
<port>8080:8080</port>
</ports>
</run>
</image>
</images>
</configuration>
</plugin>

<plugin>
<groupId>dk.nykredit.swagger</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>${swagger-maven-plugin.version}</version>
<configuration>
<outputDirectory>${apidocs.schema.dir}</outputDirectory>
<outputFormats>
<outputFormat>JSON</outputFormat>
<outputFormat>YAML</outputFormat>
</outputFormats>
<attachSwaggerArtifact>true</attachSwaggerArtifact>
<resourcePackages>
<resourcePackage>com.redhat.ipaas.verifier.v1</resourcePackage>
</resourcePackages>
<swaggerConfig>
<info>
<title>Red Hat iPaaS Verifier API</title>
<version>v1</version>
<description>
The Red Hat iPaaS Verifier API sole purpose is to verify connection parameters for the endpoints of certain connectors.
</description>
<license>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
<name>Apache 2.0</name>
</license>
<contact>
<email>[email protected]</email>
<name>The Red Hat iPaaS Developers</name>
<url>https://redhat-ipaas.github.io</url>
</contact>
</info>
<schemes>http,https</schemes>
<host>localhost:8080</host>
<basePath>/api/v1</basePath>
</swaggerConfig>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.github.swagger2markup</groupId>
<artifactId>swagger2markup-maven-plugin</artifactId>
<version>${swagger2markup-maven-plugin.version}</version>
<configuration>
<swaggerInput>${apidocs.schema.dir}/swagger.json</swaggerInput>
<outputDir>${apidocs.dir}/asciidoc</outputDir>
<config>
<swagger2markup.markupLanguage>ASCIIDOC</swagger2markup.markupLanguage>
</config>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>convertSwagger2markup</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/redhat/ipaas/verifier/VerifierResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

/**
* A verification response.
*
* @author roland
* @since 20/03/2017
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Copyright (C) 2016 Red Hat, Inc.
*
* 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 com.redhat.ipaas.verifier.config;

import java.util.Arrays;
import java.util.List;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CorsFilter;

@Configuration
@EnableConfigurationProperties
@ConfigurationProperties("cors")
public class CorsConfiguration {

private List<String> allowedOrigins = Arrays.asList(org.springframework.web.cors.CorsConfiguration.ALL);

public List<String> getAllowedOrigins() {
return allowedOrigins;
}

public void setAllowedOrigins(List<String> allowedOrigins) {
this.allowedOrigins = allowedOrigins;
}

@Bean
public CorsFilter corsFilter() {
return new CorsFilter(request -> {
if (request.getPathInfo().endsWith("/swagger.json") || request.getPathInfo().endsWith("/swagger.yaml")) {
return new org.springframework.web.cors.CorsConfiguration().applyPermitDefaultValues();
}

org.springframework.web.cors.CorsConfiguration config = new org.springframework.web.cors.CorsConfiguration();
config.setAllowedOrigins(allowedOrigins);
config.setAllowedMethods(Arrays.asList("HEAD", "GET", "POST", "PUT", "DELETE", "PATCH"));
config.applyPermitDefaultValues();
return config;
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.redhat.ipaas.verifier;
package com.redhat.ipaas.verifier.config;

import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
Expand All @@ -29,10 +29,10 @@

@Provider
@Component
public class JacksonContextResolver implements ContextResolver<ObjectMapper> {
public class JacksonContext implements ContextResolver<ObjectMapper> {
private ObjectMapper objectMapper;

public JacksonContextResolver() throws Exception {
public JacksonContext() throws Exception {
this.objectMapper = new ObjectMapper()
.registerModule(new Jdk8Module())
.setSerializationInclusion(JsonInclude.Include.NON_ABSENT)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (C) 2016 Red Hat, Inc.
*
* 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 com.redhat.ipaas.verifier.config;

import io.swagger.jaxrs.listing.ApiListingResource;
import io.swagger.jaxrs.listing.SwaggerSerializers;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfiguration {

@Bean
public ApiListingResource apiListingResource() {
return new ApiListingResource();
}

@Bean
public SwaggerSerializers swaggerSerializers() {
return new SwaggerSerializers();
}

}
24 changes: 14 additions & 10 deletions src/main/java/com/redhat/ipaas/verifier/impl/BaseVerifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,13 @@ public List<VerifierResponse> verify(Map<String, Object> params) {

customize(params);

// the connector must support ping check if its verifiable
List<VerifierResponse> resp = new ArrayList<VerifierResponse>();
List<VerifierResponse> resp = new ArrayList<>();
// Verify for all scopes
for (Verifier.Scope scope : Verifier.Scope.values()) {
ComponentVerifier.Result result = verifier.verify(toComponentScope(scope), params);
resp.add(toVerifierResponse(result));
log.info("PING: {} === {}",
getConnectorAction(), result.getStatus());
if (result.getStatus() == ComponentVerifier.Result.Status.ERROR) {
log.error("{} --> ", getConnectorAction());
for (ComponentVerifier.VerificationError error : result.getErrors()) {
log.error(" {} : {}", error.getCode(), error.getDescription());
}
}
logResult(result);
// the connector must support ping check if its verifiable
if (result.getStatus() == ComponentVerifier.Result.Status.ERROR ||
result.getStatus() == ComponentVerifier.Result.Status.UNSUPPORTED) {
break;
Expand All @@ -90,6 +84,16 @@ public List<VerifierResponse> verify(Map<String, Object> params) {
return resp;
}

private void logResult(ComponentVerifier.Result result) {
log.info("PING: {} === {}", getConnectorAction(), result.getStatus());
if (result.getStatus() == ComponentVerifier.Result.Status.ERROR) {
log.error("{} --> ", getConnectorAction());
for (ComponentVerifier.VerificationError error : result.getErrors()) {
log.error(" {} : {}", error.getCode(), error.getDescription());
}
}
}

// Hook for customizing params
protected void customize(Map<String, Object> params) {

Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/redhat/ipaas/verifier/v1/V1.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
@ApplicationPath("/api/v1")
@Component
public class V1 extends Application {

public V1() {
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("v1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import javax.ws.rs.core.MediaType;

import com.redhat.ipaas.verifier.*;
import io.swagger.annotations.Api;
import org.springframework.stereotype.Component;

@Component
@Path("/verifier")
@Api(value = "verifier")
public class VerifierEndpoint {

private VerifierRegistry verifierRegistry;
Expand Down Expand Up @@ -72,7 +74,8 @@ private List<VerifierResponse> filterExceptions(List<VerifierResponse> responses
private VerifierResponse createUnsupportedResponse(String connectorId) {
return new VerifierResponse.Builder(Verifier.Status.UNSUPPORTED,
Verifier.Scope.PARAMETERS)
.error("unknown-connector", String.format("No connector for ID %s registered", connectorId))
.error("unknown-connector",
String.format("No connector for ID %s registered", connectorId))
.build();
}
}

0 comments on commit 451a3f5

Please sign in to comment.