You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by ahgittin <gi...@git.apache.org> on 2017/06/05 09:54:54 UTC

[GitHub] brooklyn-server pull request #672: Bundle uninstall and snapshot

Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/672#discussion_r120077094
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java ---
    @@ -0,0 +1,429 @@
    +/*
    + * 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.core.mgmt.ha;
    +
    +import java.io.File;
    +import java.io.FileInputStream;
    +import java.io.FileOutputStream;
    +import java.io.IOException;
    +import java.io.InputStream;
    +import java.util.jar.Attributes;
    +import java.util.jar.Manifest;
    +import java.util.zip.ZipEntry;
    +import java.util.zip.ZipFile;
    +
    +import org.apache.brooklyn.api.catalog.CatalogItem;
    +import org.apache.brooklyn.api.typereg.ManagedBundle;
    +import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
    +import org.apache.brooklyn.core.mgmt.ha.OsgiBundleInstallationResult.ResultCode;
    +import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
    +import org.apache.brooklyn.core.typereg.BasicManagedBundle;
    +import org.apache.brooklyn.util.core.ResourceUtils;
    +import org.apache.brooklyn.util.core.osgi.BundleMaker;
    +import org.apache.brooklyn.util.core.osgi.Osgis;
    +import org.apache.brooklyn.util.exceptions.Exceptions;
    +import org.apache.brooklyn.util.exceptions.ReferenceWithError;
    +import org.apache.brooklyn.util.guava.Maybe;
    +import org.apache.brooklyn.util.os.Os;
    +import org.apache.brooklyn.util.osgi.VersionedName;
    +import org.apache.brooklyn.util.stream.Streams;
    +import org.apache.brooklyn.util.text.Strings;
    +import org.apache.brooklyn.util.text.VersionComparator;
    +import org.osgi.framework.Bundle;
    +import org.osgi.framework.BundleException;
    +import org.osgi.framework.Constants;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import com.google.common.base.Objects;
    +
    +// package-private so we can move this one if/when we move OsgiManager
    +class OsgiArchiveInstaller {
    +
    +    private static final Logger log = LoggerFactory.getLogger(OsgiArchiveInstaller.class);
    +    
    +    final private OsgiManager osgiManager;
    +    private ManagedBundle suppliedKnownBundleMetadata;
    +    private InputStream zipIn;
    +    
    +    private boolean start = true;
    +    private boolean loadCatalogBom = true;
    +    private boolean force = false;
    +    private boolean deferredStart = false;
    +    
    +    private File zipFile;
    +    private Manifest discoveredManifest;
    +    private VersionedName discoveredBomVersionedName;
    +    OsgiBundleInstallationResult result;
    +    
    +    private ManagedBundle inferredMetadata;
    +    private final boolean inputStreamSupplied;
    +    
    +    OsgiArchiveInstaller(OsgiManager osgiManager, ManagedBundle knownBundleMetadata, InputStream zipIn) {
    +        this.osgiManager = osgiManager;
    +        this.suppliedKnownBundleMetadata = knownBundleMetadata;
    +        this.zipIn = zipIn;
    +        inputStreamSupplied = zipIn!=null;
    +    }
    +
    +    public void setStart(boolean start) {
    +        this.start = start;
    +    }
    +    
    +    public void setLoadCatalogBom(boolean loadCatalogBom) {
    +        this.loadCatalogBom = loadCatalogBom;
    +    }
    +    
    +    public void setForce(boolean force) {
    +        this.force = force;
    +    }
    +
    +    public void setDeferredStart(boolean deferredStart) {
    +        this.deferredStart = deferredStart;
    +    }    
    +
    +    private ManagementContextInternal mgmt() {
    +        return (ManagementContextInternal) osgiManager.mgmt;
    +    }
    +    
    +    private synchronized void init() {
    +        if (result!=null) {
    +            if (zipFile!=null || zipIn==null) return;
    +            throw new IllegalStateException("This installer instance has already been used and the input stream discarded");
    +        }
    +        result = new OsgiBundleInstallationResult();
    +        inferredMetadata = suppliedKnownBundleMetadata==null ? new BasicManagedBundle() : suppliedKnownBundleMetadata;
    +    }
    +    
    +    private synchronized void makeLocalZipFileFromInputStreamOrUrl() {
    +        if (zipIn==null) {
    +            Maybe<Bundle> installedBundle = Maybe.absent();
    +            if (suppliedKnownBundleMetadata!=null) {
    +                // if no input stream, look for a URL and/or a matching bundle
    +                if (!suppliedKnownBundleMetadata.isNameResolved()) {
    +                    ManagedBundle mbFromUrl = osgiManager.getManagedBundleFromUrl(suppliedKnownBundleMetadata.getUrl());
    +                    if (mbFromUrl!=null) {
    +                        // user supplied just a URL (eg brooklyn.libraries), but we recognise it,
    +                        // so don't try to reload it, just record the info we know about it to retrieve the bundle
    +                        ((BasicManagedBundle)suppliedKnownBundleMetadata).setSymbolicName(mbFromUrl.getSymbolicName());
    +                        ((BasicManagedBundle)suppliedKnownBundleMetadata).setVersion(mbFromUrl.getVersion());
    +                    }
    +                }
    +                if (installedBundle.isAbsent() && suppliedKnownBundleMetadata.getOsgiUniqueUrl()!=null) {
    --- End diff --
    
    there's an `isAbsent` check in each `if` test and the result of each body might be an absent so `else wouldn't be sufficient


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---