Skip to content
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

fix: Fixes for API Catalog standalone mode #3050

Merged
merged 9 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
package org.zowe.apiml.apicatalog.services.cached;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.zowe.apiml.apicatalog.services.cached.model.ApiDocCacheKey;
import org.zowe.apiml.apicatalog.services.cached.model.ApiDocInfo;
Expand Down Expand Up @@ -43,7 +42,6 @@ public class CachedApiDocService {

private static final UnaryOperator<String> exceptionMessage = serviceId -> "No API Documentation was retrieved for the service " + serviceId + ".";

@Autowired
public CachedApiDocService(APIDocRetrievalService apiDocRetrievalService, TransformApiDocService transformApiDocService) {
this.apiDocRetrievalService = apiDocRetrievalService;
this.transformApiDocService = transformApiDocService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@

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

import org.zowe.apiml.product.service.ServiceStartupEventHandler;
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;
import org.zowe.apiml.product.service.ServiceStartupEventHandler;

/**
* This class fires on ApplicationReadyEvent event during Spring context initialization
*/
@Component
@ConditionalOnProperty(
value = "apiml.catalog.standalone.enabled",
havingValue = "false",
matchIfMissing = true
)
public class AppReadyListener {


/**
* Fires on ApplicationReadyEvent
* triggers ServiceStartupEventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.zowe.apiml.product.service.ServiceStartupEventHandler;

import java.util.concurrent.atomic.AtomicBoolean;

Expand All @@ -39,6 +40,8 @@ public class StandaloneInitializer {
public void onApplicationEvent(ApplicationReadyEvent event) {
if (isStandalone(event.getApplicationContext()) && hasRun.compareAndSet(false, true)) {
standaloneLoaderService.initializeCache();
new ServiceStartupEventHandler().onServiceStartup("API Catalog Service Standalone",
ServiceStartupEventHandler.DEFAULT_DELAY_FACTOR);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,42 @@ public void initializeCache() {

private void loadApplicationCache() {
File[] appFiles = getFiles(servicesDirectory + "/apps");
log.debug("Found {} files", appFiles.length);
if (appFiles.length == 0) {
log.error("No service definition files found.");
return;
}

for (File file : appFiles) {
createContainerFromFile(file);
log.debug("Processing file {}", file.getName());
try {
createContainerFromFile(file);
} catch (Exception e) {
log.error("Failed to load file {} because {}", file.getName(), e.getMessage());
}
}
}

private void loadOpenAPICache() {
File[] openAPIFiles = getFiles(servicesDirectory + "/apiDocs");
log.debug("Found {} API Doc files", openAPIFiles.length);
if (openAPIFiles.length == 0) {
log.error("No apiDocs files found.");
return;
}

for (File openAPIFile : openAPIFiles) {
loadApiDocCache(openAPIFile);
log.debug("Processing {}", openAPIFile.getName());
try {
loadApiDocCache(openAPIFile);
} catch (Exception e) {
log.error("Fail to load API Doc from {} because {}", openAPIFile.getName(), e.getMessage());
pablocarle marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

private void createContainerFromFile(File file) {
log.info("Initialising services from '{}' file.", file.getName());
log.debug("Initialising services from '{}' file.", file.getName());

try {
Applications apps = objectMapper.readValue(file, Applications.class);
Expand All @@ -95,6 +107,8 @@ private void createContainerFromFile(File file) {
});
} catch (IOException e) {
log.error("Unable to parse service definition '{}' because {}", file.getName(), e.getMessage());
} catch (Exception e) {
log.error("Exception encountered while loading '{}' because {}", file.getName(), e.getMessage());
}
}

Expand All @@ -119,7 +133,6 @@ private void loadApiDocCache(File file) {
String serviceId = name[0];
String apiVersion = name[1];


String apiDoc = IOUtils.toString(Files.newInputStream(file.toPath()), StandardCharsets.UTF_8);

ApiDocInfo apiDocInfo = createApiDocInfo(serviceId, apiDoc);
Expand Down
3 changes: 2 additions & 1 deletion api-catalog-ui/frontend/src/components/App/_app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ body {
.MuiDialogTitle-root {
padding: var( --spaceSmaller ) var( --spaceMedium );
color: var(--controlText15);

h2 {
margin: 0px;
}
Expand Down Expand Up @@ -111,6 +111,7 @@ body {
flex-direction: column;
align-items: center;
max-width: 368px;
min-width: 19.3%;
pablocarle marked this conversation as resolved.
Show resolved Hide resolved
width: var( --sideNavWidth );
padding: var( --spaceSmall ) var( --spaceSmaller ) var( --spaceSmall ) var( --spaceSmall );
position: relative;
Expand Down
1 change: 1 addition & 0 deletions api-catalog-ui/frontend/src/selectors/selectors.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const getFilteredServices = (tiles, searchCriteria) => {
const filteredTiles = JSON.parse(JSON.stringify(tiles));

return filteredTiles
.filter((tile) => tile?.title)
.filter((tile) => {
const filteredServices = tile.services.filter((service) => filterService(searchCriteria, service));

Expand Down