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

Add group label methods to Kamelets Catalog #256

Merged
merged 1 commit into from
May 7, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.fabric8.kubernetes.api.model.apiextensions.v1.JSONSchemaProps;
import io.github.classgraph.ClassGraph;
import io.github.classgraph.ScanResult;
import org.apache.camel.kamelets.catalog.model.KameletAnnotationsNames;
import org.apache.camel.kamelets.catalog.model.KameletLabelNames;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -101,6 +102,14 @@ public List<Kamelet> getKameletsByType(String type) {
return collect;
}

public List<Kamelet> getKameletsByGroups(String group) {
List<Kamelet> collect = kameletModels.entrySet().stream()
.filter(x -> x.getValue().getMetadata().getAnnotations().get(KameletAnnotationsNames.KAMELET_ANNOTATION_GROUP).contains(group))
.map(Map.Entry::getValue)
.collect(Collectors.toList());
return collect;
}

public JSONSchemaProps getKameletDefinition(String name) {
Kamelet kamelet = kameletModels.get(name);
if (kamelet != null) {
Expand All @@ -112,7 +121,7 @@ public JSONSchemaProps getKameletDefinition(String name) {

public List<Kamelet> getKameletByProvider(String provider) {
List<Kamelet> collect = kameletModels.entrySet().stream()
.filter(x -> x.getValue().getMetadata().getAnnotations().get(KameletLabelNames.KAMELET_LABEL_PROVIDER).equalsIgnoreCase(provider))
.filter(x -> x.getValue().getMetadata().getAnnotations().get(KameletAnnotationsNames.KAMELET_ANNOTATION_PROVIDER).equalsIgnoreCase(provider))
.map(Map.Entry::getValue)
.collect(Collectors.toList());
if (!collect.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.camel.kamelets.catalog.model;

public interface KameletAnnotationsNames {

String KAMELET_ANNOTATION_ICON = "camel.apache.org/kamelet.icon";
String KAMELET_ANNOTATION_PROVIDER = "camel.apache.org/provider";
String KAMELET_ANNOTATION_GROUP = "camel.apache.org/kamelet.group";
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,5 @@
public interface KameletLabelNames {

String KAMELET_LABEL_TYPE = "camel.apache.org/kamelet.type";
String KAMELET_LABEL_PROVIDER = "camel.apache.org/provider";
String KAMELET_LABEL_ICON = "camel.apache.org/kamelet.icon";

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.fabric8.kubernetes.api.model.apiextensions.v1.JSONSchemaProps;
import io.github.classgraph.ClassGraph;

import org.apache.camel.kamelets.catalog.model.KameletTypeEnum;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -80,6 +81,26 @@ void testGetKameletsByProvider() throws Exception {
assertTrue(c.isEmpty());
}

@Test
void testGetKameletsByType() throws Exception {
List<Kamelet> c = catalog.getKameletsByType(KameletTypeEnum.SOURCE.type());
assertTrue(!c.isEmpty());
c = catalog.getKameletsByType(KameletTypeEnum.SINK.type());
assertTrue(!c.isEmpty());
c = catalog.getKameletsByType(KameletTypeEnum.ACTION.type());
assertTrue(!c.isEmpty());
}

@Test
void testGetKameletsByGroup() throws Exception {
List<Kamelet> c = catalog.getKameletsByGroups("AWS S3");
assertTrue(!c.isEmpty());
c = catalog.getKameletsByGroups("AWS SQS");
assertTrue(!c.isEmpty());
c = catalog.getKameletsByGroups("Not-existing-group");
assertTrue(c.isEmpty());
}

@Test
void testGetKameletsDependencies() throws Exception {
List<String> deps = catalog.getKameletDependencies("aws-sqs-source");
Expand Down