Search in sources :

Example 6 with ApplicationException

use of org.onosproject.app.ApplicationException in project onos by opennetworkinglab.

the class ApplicationArchive method saveApplication.

/**
 * Loads the application descriptor from the specified application archive
 * stream and saves the stream in the appropriate application archive
 * directory.
 *
 * @param stream application archive stream
 * @return application descriptor
 * @throws org.onosproject.app.ApplicationException if unable to read the
 *                                                  archive stream or store
 *                                                  the application archive
 */
public synchronized ApplicationDescription saveApplication(InputStream stream) {
    try (InputStream ais = stream) {
        byte[] cache = toByteArray(ais);
        InputStream bis = new ByteArrayInputStream(cache);
        boolean plainXml = isPlainXml(cache);
        ApplicationDescription desc = plainXml ? parsePlainAppDescription(bis) : parseZippedAppDescription(bis);
        checkState(!appFile(desc.name(), APP_XML).exists(), "Application %s already installed", desc.name());
        if (plainXml) {
            expandPlainApplication(cache, desc);
        } else {
            bis.reset();
            boolean isSelfContainedJar = expandZippedApplication(bis, desc);
            if (isSelfContainedJar) {
                bis.reset();
                stageSelfContainedJar(bis, desc);
            }
            /*
                 * Reset the ZIP file and reparse the app description now
                 * that the ZIP is expanded onto the filesystem. This way any
                 * file referenced as part of the description (i.e. app.png)
                 * can be loaded into the app description.
                 */
            bis.reset();
            desc = parseZippedAppDescription(bis);
            bis.reset();
            saveApplication(bis, desc, isSelfContainedJar);
        }
        installArtifacts(desc);
        return desc;
    } catch (IOException e) {
        throw new ApplicationException("Unable to save application", e);
    }
}
Also used : ApplicationException(org.onosproject.app.ApplicationException) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) ApplicationDescription(org.onosproject.app.ApplicationDescription) DefaultApplicationDescription(org.onosproject.app.DefaultApplicationDescription)

Example 7 with ApplicationException

use of org.onosproject.app.ApplicationException in project onos by opennetworkinglab.

the class ApplicationArchive method getApplicationDescription.

/**
 * Loads the application descriptor from the specified application archive
 * stream and saves the stream in the appropriate application archive
 * directory.
 *
 * @param appName application name
 * @return application descriptor
 * @throws org.onosproject.app.ApplicationException if unable to read application description
 */
public ApplicationDescription getApplicationDescription(String appName) {
    try {
        XMLConfiguration cfg = new XMLConfiguration();
        cfg.setAttributeSplittingDisabled(true);
        cfg.setDelimiterParsingDisabled(true);
        cfg.load(appFile(appName, APP_XML));
        return loadAppDescription(cfg);
    } catch (Exception e) {
        throw new ApplicationException("Unable to get app description", e);
    }
}
Also used : XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) ApplicationException(org.onosproject.app.ApplicationException) NoSuchFileException(java.nio.file.NoSuchFileException) ApplicationException(org.onosproject.app.ApplicationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ConfigurationException(org.apache.commons.configuration.ConfigurationException)

Aggregations

ApplicationException (org.onosproject.app.ApplicationException)7 IOException (java.io.IOException)4 ApplicationDescription (org.onosproject.app.ApplicationDescription)3 File (java.io.File)2 ZipInputStream (java.util.zip.ZipInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 ZipEntry (java.util.zip.ZipEntry)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)1 DefaultApplicationDescription (org.onosproject.app.DefaultApplicationDescription)1 Application (org.onosproject.core.Application)1 ApplicationId (org.onosproject.core.ApplicationId)1 DefaultApplication (org.onosproject.core.DefaultApplication)1 StorageException (org.onosproject.store.service.StorageException)1 Activate (org.osgi.service.component.annotations.Activate)1