use of alien4cloud.plugin.exception.MissingPlugingDescriptorFileException in project alien4cloud by alien4cloud.
the class PluginManager method uploadPlugin.
/**
* Upload a plugin from a given path.
*
* @param uploadedPluginPath The path of the plugin to upload.<br>
* The state of the new uploaded plugin will be determined as follow:
* <ul>
* <li>plugin doesn't exists: load and enable</li>
* <li>plugin exists: keep the state (reload if enabled)</li>
* </ul>
* @return the uploaded plugin
* @throws IOException In case there is an issue with the access to the plugin file.
* @throws PluginLoadingException
* @throws AlreadyExistException if a plugin with the same id already exists in the repository
* @throws MissingPlugingDescriptorFileException
*/
public Plugin uploadPlugin(Path uploadedPluginPath) throws PluginLoadingException, IOException, MissingPlugingDescriptorFileException {
// load the plugin descriptor
FileSystem fs = FileSystems.newFileSystem(uploadedPluginPath, null);
PluginDescriptor descriptor;
try {
try {
descriptor = YamlParserUtil.parseFromUTF8File(fs.getPath(PLUGIN_DESCRIPTOR_FILE), PluginDescriptor.class);
} catch (IOException e) {
if (e instanceof NoSuchFileException) {
throw new MissingPlugingDescriptorFileException();
} else {
throw e;
}
}
String pluginPathId = getPluginPathId();
Plugin plugin = new Plugin(descriptor, pluginPathId);
// check plugin already exists and is loaded
if (pluginContexts.get(plugin.getId()) != null) {
log.warn("Uploading Plugin [ {} ] impossible (already exists and enabled)", plugin.getId());
throw new AlreadyExistException("A plugin with the given id already exists and is enabled.");
}
Plugin oldPlugin = alienDAO.findById(Plugin.class, plugin.getId());
if (oldPlugin != null) {
// remove all files for the old plugin but keep configuration.
removePlugin(plugin.getId(), false);
}
Path pluginPath = getPluginPath(pluginPathId);
FileUtil.unzip(uploadedPluginPath, pluginPath);
// copy ui directory in case it exists
Path pluginUiSourcePath = pluginPath.resolve(UI_DIRECTORY);
Path pluginUiPath = getPluginUiPath(pluginPathId);
if (Files.exists(pluginUiSourcePath)) {
FileUtil.copy(pluginUiSourcePath, pluginUiPath);
}
alienDAO.save(plugin);
if (oldPlugin == null || oldPlugin.isEnabled()) {
enablePlugin(plugin);
}
return plugin;
} finally {
fs.close();
}
}
use of alien4cloud.plugin.exception.MissingPlugingDescriptorFileException in project alien4cloud by alien4cloud.
the class PluginController method upload.
@ApiOperation(value = "Upload a plugin archive.", notes = "Content of the zip file must be compliant with the expected alien 4 cloud plugin structure.", authorizations = { @Authorization("ADMIN") })
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
@Audit
public RestResponse<Void> upload(@ApiParam(value = "Zip file that contains the plugin.", required = true) @RequestParam("file") MultipartFile pluginArchive) {
Path pluginPath = null;
try {
// save the plugin archive in the temp directory
pluginPath = Files.createTempFile(tempDirPath, null, ".zip");
FileUploadUtil.safeTransferTo(pluginPath, pluginArchive);
// upload the plugin archive
Plugin plugin = pluginManager.uploadPlugin(pluginPath);
// TODO as we do not manage many version of a same plugin, is this still relevant ?
if (plugin.isConfigurable()) {
tryReusePreviousVersionConf(plugin);
}
} catch (MissingPlugingDescriptorFileException e) {
log.error("Your plugin don't have the META-INF/plugin.yml file.", e);
return RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.MISSING_PLUGIN_DESCRIPTOR_FILE_EXCEPTION.getCode(), "Your plugin don't have the META-INF/plugin.yml file.")).build();
} catch (IOException e) {
log.error("Unexpected IO error on plugin upload.", e);
return RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.INDEXING_SERVICE_ERROR.getCode(), "A technical issue occurred during the plugin upload <" + e.getMessage() + ">.")).build();
} catch (PluginLoadingException e) {
log.error("Fail to enable and load the plugin. The plugin will remain disabled", e);
return RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.ENABLE_PLUGIN_ERROR.getCode(), e.getMessage())).build();
} finally {
if (pluginPath != null) {
try {
FileUtil.delete(pluginPath);
} catch (IOException e) {
log.error("Failed to cleanup temporary file <" + pluginPath.toString() + ">", e);
}
}
}
return RestResponseBuilder.<Void>builder().build();
}
Aggregations