Skip to content

refactor: Including catalog as a part of Modulith module apiml #4189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: v3.x.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
paths-ignore:
- '**.md'
pull_request:
branches: [ v2.x.x, v3.x.x ]
branches: [ v2.x.x, v3.x.x, reboot/catalog-modulith ]
paths-ignore:
- '**.md'
workflow_dispatch:
Expand Down
82 changes: 0 additions & 82 deletions api-catalog-services/README.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
* Copyright Contributors to the Zowe Project.
*/

package org.zowe.apiml.apicatalog.services.status.listeners;
package org.zowe.apiml.apicatalog.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
Expand All @@ -20,11 +19,6 @@
* This class fires on ApplicationReadyEvent event during Spring context initialization
*/
@Component
@ConditionalOnProperty(
value = "apiml.catalog.standalone.enabled",
havingValue = "false",
matchIfMissing = true
)
public class AppReadyListener {

/**
Expand All @@ -38,4 +32,5 @@ public void onApplicationEvent(ApplicationReadyEvent event) {
new ServiceStartupEventHandler().onServiceStartup("API Catalog Service",
ServiceStartupEventHandler.DEFAULT_DELAY_FACTOR);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ public ServletWebServerFactory servletContainer(List<TomcatConnectorCustomizer>
tomcat.addConnectorCustomizers(connectorCustomizers.toArray(new TomcatConnectorCustomizer[0]));
return tomcat;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
.setCacheControl(CacheControl.maxAge(Duration.ofDays(365L)))
.addResourceLocations("/resources/", "/resources/static/", "/resources/templates/");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,33 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpStatus;
import org.openapitools.openapidiff.core.OpenApiCompare;
import org.openapitools.openapidiff.core.model.ChangedOpenApi;
import org.openapitools.openapidiff.core.output.HtmlRender;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.zowe.apiml.apicatalog.services.status.APIServiceStatusService;
import org.zowe.apiml.apicatalog.exceptions.ApiDiffNotAvailableException;
import org.zowe.apiml.apicatalog.swagger.ApiDocRetrievalService;

/**
* Main API for handling requests from the API Catalog UI, routed through the gateway
*/
@Slf4j
@RestController
@RequestMapping("/apidoc")
@Tag(name = "API Documentation")
public class CatalogApiDocController {

private final APIServiceStatusService apiServiceStatusService;

/**
* Create the controller and autowire in the repository services
*
* @param apiServiceStatusService repo service for registered services
*/
@Autowired
public CatalogApiDocController(APIServiceStatusService apiServiceStatusService) {
this.apiServiceStatusService = apiServiceStatusService;
}
@RequiredArgsConstructor
public class ApiDocController {

private final ApiDocRetrievalService apiDocRetrievalService;

/**
* Retrieve the api-doc info for this service
Expand Down Expand Up @@ -72,7 +70,7 @@ public ResponseEntity<String> getApiDocInfo(
@PathVariable(value = "serviceId") String serviceId,
@Parameter(name = "apiId", description = "The API ID and version, separated by a space, of the API documentation", required = true, example = "zowe.apiml.apicatalog v1.0.0")
@PathVariable(value = "apiId") String apiId) {
return this.apiServiceStatusService.getServiceCachedApiDocInfo(serviceId, apiId);
return ResponseEntity.ok(apiDocRetrievalService.retrieveApiDoc(serviceId, apiId));
}

/**
Expand All @@ -97,7 +95,8 @@ public ResponseEntity<String> getApiDocInfo(
public ResponseEntity<String> getDefaultApiDocInfo(
@Parameter(name = "serviceId", description = "The unique identifier of the registered service", required = true, example = "apicatalog")
@PathVariable(value = "serviceId") String serviceId) {
return this.apiServiceStatusService.getServiceCachedDefaultApiDocInfo(serviceId);

return ResponseEntity.ok(apiDocRetrievalService.retrieveDefaultApiDoc(serviceId));
}

@GetMapping(value = "/{serviceId}/{apiId1}/{apiId2}", produces = MediaType.TEXT_HTML_VALUE)
Expand All @@ -120,6 +119,24 @@ public ResponseEntity<String> getApiDiff(
@PathVariable(value = "apiId1") String apiId1,
@Parameter(name = "apiId2", description = "The API ID and version, separated by a space, of the API documentation", required = true, example = "zowe.apiml.apicatalog v2.0.0")
@PathVariable(value = "apiId2") String apiId2) {
return this.apiServiceStatusService.getApiDiffInfo(serviceId, apiId1, apiId2);

try {
String doc1 = apiDocRetrievalService.retrieveApiDoc(serviceId, apiId1);
String doc2 = apiDocRetrievalService.retrieveApiDoc(serviceId, apiId2);
ChangedOpenApi diff = OpenApiCompare.fromContents(doc1, doc2);
HtmlRender render = new HtmlRender();
String result = render.render(diff);
//Remove external stylesheet
result = result.replace("<link rel=\"stylesheet\" href=\"http://deepoove.com/swagger-diff/stylesheets/demo.css\">", "");
return ResponseEntity
.status(HttpStatus.SC_OK)
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.body(result);
} catch (Exception e) {
String errorMessage = String.format("Error retrieving API diff for '%s' with versions '%s' and '%s'", serviceId, apiId1, apiId2);
log.error(errorMessage, e);
throw new ApiDiffNotAvailableException(errorMessage);
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/

package org.zowe.apiml.apicatalog.controllers.api;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.zowe.apiml.apicatalog.security.OidcUtils;

import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

/**
* Endpoints related to the OIDC integration
*/
@Slf4j
@RestController
@RequestMapping("/oidc")
@Tag(name = "OIDC integration")
public class OidcController {

private AtomicReference<List<String>> oidcProviderCache = new AtomicReference<>();

@GetMapping(value = "/provider", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<String>> getOidcProvider() {
if (oidcProviderCache.get() == null) {
oidcProviderCache.set(OidcUtils.getOidcProvider());
}

return new ResponseEntity<>(oidcProviderCache.get(), oidcProviderCache.get().isEmpty() ? HttpStatus.NO_CONTENT : HttpStatus.OK);
}

}
Loading
Loading