Skip to content

Instantly share code, notes, and snippets.

@pbrada
Created February 21, 2011 09:00
Show Gist options
  • Select an option

  • Save pbrada/836830 to your computer and use it in GitHub Desktop.

Select an option

Save pbrada/836830 to your computer and use it in GitHub Desktop.
Extends the org.apache.ace.obr.storage.BundleStore by the ability to version stored bundles
/**
* This is OSGi Bundle Compatibility Checker (OBCC) -- a toolset to verify
* bundle compatibility using type checking on exported and imported
* features.
*
* Copyright (c) 2007-2010 Department of Computer Science and Engineering,
* University of West Bohemia, Pilsen, CZ
*
* This software and this file is available under the Creative Commons
* Attribution-Noncommercial-Share Alike license. You may obtain a copy
* of the License at http://creativecommons.org/licenses/ .
*
* This software is provided 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.
*/
package org.apache.ace.obr.storage.versioning;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.apache.ace.obr.storage.BundleStore;
import org.osgi.framework.Version;
import org.apache.ace.util.VersionRange;
/**
* Extends the @see BundleStore by the ability to version a bundle inserted
* into the repository and query for versions.
*
* @author Premek Brada <brada@kiv.zcu.cz>, Bohdan Mixanek <bohdan.mixanek@gmail.com>
*
*/
public interface VersionedBundleStore extends BundleStore {
/**
* Take the bundle from the provided data, update its version metadata by
* comparing it with the latest revision of equally-named bundle in the repository,
* create correct filename (symbolic name + updated bundle version), store result
* in the repository via BundleStore.put(). Leaves and uses bundle version untouched
* if this is the first revision of the bundle.
*
* @see org.apache.ace.obr.storage.BundleStore
*
* @param bundleData
* Stream with the bundle content
* @return The filename given to the bundle by the repository, null if not stored
*
* @throws IllegalArgumentException
* When the data provided is not a valid bundle archive
*/
public BundleInfo put(InputStream bundleData) throws IOException, IllegalArgumentException;
/**
* Reads the bundle from input stream and stores its modified version in bundle store.
* Bundle is compared with its previous specified version. Given version must be already
* stored there or exception is thrown.
* @param bundleData
* @param referenceVersion
* @return
* @throws IOException
* @throws IllegalArgumentException
* @throws NoSuchVersionException if the referenceVersion is not found in repo
*/
public BundleInfo put(InputStream bundleData, Version referenceVersion) throws IOException, IllegalArgumentException, NoSuchVersionException;
/**
* Lists all bundle symbolic names on the store. All names in list are unique.
* Even if multiple versions of single bundle is in the store, its symbolic name
* is returned only once.
* @return
* @throws IOException
*/
public List<String> listBundles() throws IOException;
/**
* Lists all versions of bundle with given name.
* @param bundleName
* @return
* @throws IOException
*/
public List<Version> listVersions(String bundleName) throws IOException;
/**
* Gets the specified version. Exact name and version must be given.
* @param bundleName
* @param version
* @return
* @throws IOException
*/
public InputStream get(String bundleName, Version version) throws IOException;
/**
* Gets the latest version of the bundle. The one with highest version number
* is returned.
* @param bundleName
* @return
* @throws IOException
*/
public BundleInfo getLatest(String bundleName) throws IOException;
/**
* Gets the latest version of the bundle. The one with highest version number that
* fits the range is returned.
* @param bundleName
* @param range
* @return
* @throws IOException
*/
public BundleInfo getLatest(String bundleName, VersionRange range) throws IOException;
/**
* Removes bundle from store. Removes from store the bundle specified with its
* name and version. Returns whether the bundle was deleted or not. It is not
* deleted only if it is already not in the store.
* @param bundleName symbolic name of the bundle.
* @param version version of bundle.
* @return true if the bundle was deleted, or false.
* @throws IOException
*/
public boolean remove(String bundleName, Version version) throws IOException;
}
/* This is OSGi Bundle Compatibility Checker (OBCC) -- a tool to verify
* bundle compatibility using type checking on exported and imported
* features.
*
* Copyright (c) 2007-2009 Department of Computer Science and Engineering,
* University of West Bohemia, Pilsen, CZ
*
* This software and this file is available under the Creative Commons
* Attribution-Noncommercial-Share Alike license. You may obtain a copy
* of the License at http://creativecommons.org/licenses/ .
*
* This software is provided 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.
*/
package cz.zcu.kiv.osgi.versionGenerator.service;
import cz.zcu.kiv.osgi.bundleTypes.exceptions.JOSGiBundleNotFoundException;
import cz.zcu.kiv.osgi.versionGenerator.exceptions.BundlesIncomparableException;
import cz.zcu.kiv.osgi.versionGenerator.exceptions.VersionGeneratorException;
import java.io.File;
import java.io.IOException;
import org.apache.commons.vfs.FileSystemException;
/**
*
* @author Premek Brada <brada@kiv.zcu.cz, kalwi@students.zcu.cz
*/
public interface VersionService {
/**
* Updates versions in target bundle in dependence on difference to source bundle.
*
* @param sourceBundleFile <code>File</code> of the source bundle whose version and content will be used
* as a base to generate new version.
* @param targetBundleFile <code>File</code> of the target bundle whose version will be updated.
* @param invocationId An identifier of the service invocation, to store in target bundle's manifest
* @return The generated Bundle-Version of the target.
* TODO: change to org.osgi....Version
* @throws IOException
* @throws VersionGeneratorException
* @throws BundlesIncomparableException
*/
public String updateVersion(File sourceBundleFile, File targetBundleFile, String invocationId) throws IOException, VersionGeneratorException, BundlesIncomparableException;
/**
* Updates versions in target bundle in dependence on difference to source bundle.
*
* @param sourceBundleFile <code>File</code> of the source bundle whose version and content will be used
* as a base to generate new version.
* @param targetBundleFile <code>File</code> of the target bundle whose version will be updated.
* @return The generated Bundle-Version of the target.
* @throws IOException
* @throws VersionGeneratorException
* @throws BundlesIncomparableException
*/
public String updateVersion(File sourceBundleFile, File targetBundleFile) throws IOException, VersionGeneratorException, BundlesIncomparableException;
/**
* Creates a copy of the versioned bundle and sets its version data in dependence on difference
* to source bundle. The resulting bundle will be stored in the given output folder, and
* its name will be generated out of bundle's symbolic
* name and the generated Bundle-Version in the format &lt;SymbolicName&gt;-&lt;Version&gt;.jar
*
* @param sourceBundlePath Path to source bundle which will be used
* as base to generate the new version.
* @param sourceBundleFile <code>File</code> of the source bundle whose version and content will be used
* as a base to generate new version.
* @param versionedBundleFile <code>File</code> of the target bundle whose version will be updated.
* @param outputPath Folder name, where to store the resulting bundle.
* @param invocationId An identifier of the service invocation, to store in versioned bundle's manifest.
* @return Path to the resulting bundle.
* @throws IOException
* @throws VersionGeneratorException
* @throws BundlesIncomparableException
*/
String createVersionedBundle(File sourceBundleFile, File versionedBundleFile, String outputPath, String invocationId)
throws IOException, VersionGeneratorException, BundlesIncomparableException;
/**
* Creates a copy of the versioned bundle and sets its version data in dependence on difference
* to source bundle. The resulting bundle will be stored in the given output folder, and
* its name will be generated out of bundle's symbolic
* name and the generated Bundle-Version in the format &lt;SymbolicName&gt;-&lt;Version&gt;.jar
*
* @param sourceBundleFile <code>File</code> of the source bundle whose version and content will be used
* as a base to generate new version.
* @param versionedBundleFile <code>File</code> of the target bundle whose version will be updated.
* @return Path to the resulting bundle.
* @throws IOException
* @throws VersionGeneratorException
* @throws BundlesIncomparableException
*/
public String createVersionedBundle(File sourceBundleFile, File versionedBundleFile) throws IOException, VersionGeneratorException, BundlesIncomparableException;
}
@pbrada
Copy link
Copy Markdown
Author

pbrada commented Mar 21, 2011

The proposed REST API for the versioning OBR; capitalised strings denote placeholders and [*] the original (unversioned) REST API.

GET /obr
=> listBundles(), returns the list of bundle symbolic names delimited by newline in response body

GET /obr/BUNDLE-SYMBOLIC-NAME [*]
=> listVersions(), returns the list of bundle versions delimited by newline in response body
(change of semantics)

GET /obr/BUNDLE-SYMBOLIC-NAME/VERSION
=> get(bundle-symbolic-name, version)

GET /obr/BUNDLE-SYMBOLIC-NAME/latest
=> getLatest(bundle-symbolic-name), plus X-BundleVersion header set

GET /obr/BUNDLE-SYMBOLIC-NAME/latest?VERSION-RANGE
=> getLatest(bundle-symbolic-name, version-range), plus X-BundleVersion header set

POST /obr
=> put(), on success returns 201 Created and the resulting bundle metadata in X-BundleFileName, X-BundleVersion headers

POST /obr/resource [*]
=> same as POST /obr, i.e. ignore the resource name for bundles
(change of semantics)

DELETE /obr/BUNDLE-SYMBOLIC-NAME/VERSION
=> remove(bundle-symbolic-name, version), on success returns 200 OK

DELETE /obr/BUNDLE-SYMBOLIC-NAME/latest
=> remove(bundle-symbolic-name, latest-version), on success returns 200 OK

DELETE /obr/BUNDLE-SYMBOLIC-NAME [*] -- TODO unclear:
=> remove(bundle-symbolic-name, latest-version), on success returns 200 OK
OR
remove all versions of the bundle
OR
returns 400 Bad Request -- refuse to perform "remove latest", client must specify version

(Note: PUT method is not used, unless we find a use case for drop-in replacement of already
stored bundle which would preserve its version id-s, on condition that the current and the PUT bundle
are indistinguishable.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment