Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AB0F6200D08 for ; Thu, 21 Sep 2017 19:58:59 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id A9C1C1609DB; Thu, 21 Sep 2017 17:58:59 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E94A31609E6 for ; Thu, 21 Sep 2017 19:58:58 +0200 (CEST) Received: (qmail 57394 invoked by uid 500); 21 Sep 2017 17:58:57 -0000 Mailing-List: contact dev-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list dev@brooklyn.apache.org Received: (qmail 56761 invoked by uid 99); 21 Sep 2017 17:58:57 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Sep 2017 17:58:57 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0DEBDF5A5F; Thu, 21 Sep 2017 17:58:55 +0000 (UTC) From: aledsage To: dev@brooklyn.apache.org Reply-To: dev@brooklyn.apache.org References: In-Reply-To: Subject: [GitHub] brooklyn-server pull request #810: REST API for bundles, types, and subtypes Content-Type: text/plain Message-Id: <20170921175856.0DEBDF5A5F@git1-us-west.apache.org> Date: Thu, 21 Sep 2017 17:58:55 +0000 (UTC) archived-at: Thu, 21 Sep 2017 17:58:59 -0000 Github user aledsage commented on a diff in the pull request: https://github.com/apache/brooklyn-server/pull/810#discussion_r140310844 --- Diff: rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/BundleResource.java --- @@ -0,0 +1,186 @@ +/* + * 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.brooklyn.rest.resources; + +import java.io.ByteArrayInputStream; +import java.io.InputStreamReader; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + +import org.apache.brooklyn.api.typereg.ManagedBundle; +import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog; +import org.apache.brooklyn.core.mgmt.entitlement.Entitlements; +import org.apache.brooklyn.core.mgmt.ha.OsgiBundleInstallationResult; +import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal; +import org.apache.brooklyn.rest.api.BundleApi; +import org.apache.brooklyn.rest.domain.ApiError; +import org.apache.brooklyn.rest.domain.BundleInstallationRestResult; +import org.apache.brooklyn.rest.domain.BundleSummary; +import org.apache.brooklyn.rest.filter.HaHotStateRequired; +import org.apache.brooklyn.rest.transform.TypeTransformer; +import org.apache.brooklyn.rest.util.WebResourceUtils; +import org.apache.brooklyn.util.collections.MutableList; +import org.apache.brooklyn.util.exceptions.Exceptions; +import org.apache.brooklyn.util.exceptions.ReferenceWithError; +import org.apache.brooklyn.util.osgi.VersionedName; +import org.apache.brooklyn.util.osgi.VersionedName.VersionedNameComparator; +import org.apache.brooklyn.util.yaml.Yamls; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; + +@HaHotStateRequired +public class BundleResource extends AbstractBrooklynRestResource implements BundleApi { + + private static final Logger log = LoggerFactory.getLogger(BundleResource.class); + private static final String LATEST = "latest"; + + @Override + public List list(String versions) { + return list(TypeResource.isLatestOnly(versions, true), Predicates.alwaysTrue()); + } + + private List list(boolean onlyLatest, Predicate symbolicNameFilter) { + + Map bundles = new TreeMap<>(VersionedNameComparator.INSTANCE); + for (ManagedBundle b: ((ManagementContextInternal)mgmt()).getOsgiManager().get().getManagedBundles().values()) { + if (symbolicNameFilter.apply(b.getSymbolicName())) { + // TODO entitlements for bundles + VersionedName key = onlyLatest ? new VersionedName(b.getSymbolicName(), LATEST) : b.getVersionedName(); + ManagedBundle oldBundle = bundles.get(key); + if (oldBundle==null || oldBundle.getVersionedName().compareTo(b.getVersionedName()) > 0) { + bundles.put(key, b); + } + } + } + return toBundleSummary(bundles.values()); + } + + private List toBundleSummary(Iterable sortedItems) { + List result = MutableList.of(); + for (ManagedBundle t: sortedItems) { + result.add(TypeTransformer.bundleSummary(brooklyn(), t, ui.getBaseUriBuilder(), mgmt())); --- End diff -- Does this use anything like `filters.add(RegisteredTypePredicates.entitledToSee(mgmt()));`? ---