[
https://issues.apache.org/jira/browse/BROOKLYN-195?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15013220#comment-15013220
]
ASF GitHub Bot commented on BROOKLYN-195:
-----------------------------------------
Github user tbouron commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/1039#discussion_r45317891
--- Diff:
core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
---
@@ -558,15 +561,34 @@ private void collectCatalogItems(String sourceYaml,
Map<?,?> itemMetadata, List<
throw new IllegalStateException("Could not resolve plan once
id and itemType are known (recursive reference?): "+sourceYaml);
}
String sourcePlanYaml = planInterpreter.getPlanYaml();
-
- CatalogItemDtoAbstract<?, ?> dto = createItemBuilder(itemType,
symbolicName, version)
+
+ CatalogItemBuilder itemBuilder = createItemBuilder(itemType,
symbolicName, version)
.libraries(libraryBundles)
.displayName(displayName)
.description(description)
.deprecated(catalogDeprecated)
.iconUrl(catalogIconUrl)
- .plan(sourcePlanYaml)
- .build();
+ .plan(sourcePlanYaml);
+ if (itemType.equals(CatalogItemType.ENTITY) ||
itemType.equals(CatalogItemType.TEMPLATE)) {
+ String stringServiceType = getFirstAs(itemAsMap, String.class,
"type").orNull();
+ // This is not a single item but a services based YAML
+ if (stringServiceType == null) {
+ final List<Map<?, ?>> services = getFirstAs(itemAsMap,
List.class, "services").orNull();
+ if (services.isEmpty()) {
+ throw new IllegalStateException("Services are empty: "
+ sourceYaml);
+ }
+ stringServiceType = services.get(0).get("type").toString();
--- End diff --
The YAML let you add more than one services but Brooklyn will ultimately
[deploys the entity only if it contains only one
service](https://issues.apache.org/jira/browse/BROOKLYN-195?jql=project%20%3D%20BROOKLYN).
That's why I'm checking only the first one.
> Invalid catalog item can be posted to catalog
> ---------------------------------------------
>
> Key: BROOKLYN-195
> URL: https://issues.apache.org/jira/browse/BROOKLYN-195
> Project: Brooklyn
> Issue Type: Bug
> Reporter: Martin Harris
> Priority: Minor
>
> The following YAML can be posted to the catalog
> {noformat}
> brooklyn.catalog:
> id: invalid-catalog-item
> version: 1.0
> displayName: Invalid Catalog Item
> itemType: template
> services:
> - type: org.apache.brooklyn.entity.stock.BasicApplication
> - type: org.apache.brooklyn.entity.stock.BasicApplication
> {noformat}
> E.g. by using the following curl command
> curl http://localhost:8081/v1/catalog --data-binary @`pwd`/services.yaml
> This will return a 201 and the catalog item will be created. However, when
> trying to deploy the catalog item, the following error is returned:
> {noformat}
> Transformer for Brooklyn OASIS CAMP interpreter gave an error creating this
> plan: Transformer for catalog gave an error creating this plan: Transformer
> for Brooklyn OASIS CAMP interpreter gave an error creating this plan:
> java.lang.UnsupportedOperationException: Single service expected, but got
> [EntitySpec{type=interface
> org.apache.brooklyn.entity.stock.BasicApplication}, EntitySpec{type=interface
> org.apache.brooklyn.entity.stock.BasicApplication}]
> {noformat}
> As the use of multiple services is not supported, Brooklyn should not allow
> the catalog item to be created
> Marked as low priority as the workaround is fairly simple (i.e. use the
> following YAML):
> {noformat}
> brooklyn.catalog:
> id: invalid-catalog-item
> version: 1.0
> displayName: Invalid Catalog Item
> itemType: template
> services:
> - type: org.apache.brooklyn.entity.stock.BasicApplication
> brooklyn.children:
> - type: org.apache.brooklyn.entity.stock.BasicApplication
> - type: org.apache.brooklyn.entity.stock.BasicApplication
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)