use of org.onosproject.app.ApplicationException in project onos by opennetworkinglab.
the class ApplicationArchive method expandZippedApplication.
// Expands the specified ZIP stream into app-specific directory.
// Returns true of the application is a self-contained jar rather than an oar file.
private boolean expandZippedApplication(InputStream stream, ApplicationDescription desc) throws IOException {
boolean isSelfContained = false;
ZipInputStream zis = new ZipInputStream(stream);
ZipEntry entry;
File appDir = new File(appsDir, desc.name());
if (!FilePathValidator.validateFile(appDir, appsDir)) {
throw new ApplicationException("Application attempting to create files outside the apps directory");
}
while ((entry = zis.getNextEntry()) != null) {
if (!entry.isDirectory()) {
byte[] data = ByteStreams.toByteArray(zis);
zis.closeEntry();
if (FilePathValidator.validateZipEntry(entry, appDir)) {
File file = new File(appDir, entry.getName());
if (isTopLevel(file)) {
createParentDirs(file);
write(data, file);
} else {
isSelfContained = true;
}
} else {
throw new ApplicationException("Application Zip archive is attempting to leave application root");
}
}
}
zis.close();
return isSelfContained;
}
use of org.onosproject.app.ApplicationException in project onos by opennetworkinglab.
the class DistributedApplicationStore method create.
@Override
public Application create(InputStream appDescStream) {
ApplicationDescription appDesc = saveApplication(appDescStream);
if (hasPrerequisites(appDesc)) {
return create(appDesc, true);
}
// Purge bits off disk if we don't have prerequisites to allow app to be
// reinstalled later
purgeApplication(appDesc.name());
throw new ApplicationException("Missing dependencies for app " + appDesc.name());
}
use of org.onosproject.app.ApplicationException in project onos by opennetworkinglab.
the class ApplicationArchive method setActive.
/**
* Marks the app as active by creating token file in the app directory.
*
* @param appName application name
* @return true if file was created
*/
protected boolean setActive(String appName) {
try {
File active = appFile(appName, "active");
createParentDirs(active);
return active.createNewFile() && updateTime(appName);
} catch (IOException e) {
log.warn("Unable to mark app {} as active", appName, e);
throw new ApplicationException("Unable to mark app as active", e);
}
}
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);
}
}
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);
}
}
Aggregations