imp: 1. download plugins in directly in plugins folder 2. if plugin of requested type present dont download new plugin but start the one already there
package org.openbaton.nfvo.core.api;
-import java.io.*;
-import java.net.URL;
-import java.util.HashSet;
-import java.util.Set;
import org.openbaton.exceptions.AlreadyExistingException;
import org.openbaton.plugin.mgmt.PluginStartup;
import org.openbaton.utils.rabbit.RabbitManager;
@@ -29,6 +25,14 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Set;
+
/** Created by rvl on 19.10.16. */
@Service
public class PluginManager implements org.openbaton.nfvo.core.interfaces.PluginManager {
@@ -82,17 +86,26 @@ public class PluginManager implements org.openbaton.nfvo.core.interfaces.PluginM
throw new AlreadyExistingException("Plugin of type " + type + " is already installed");
}
}
-
String url = "http://" + marketIp + ":" + marketPort + "/api/v1/vim-drivers/" + id + "/jar";
- String path = pluginDir + "/install-plugin/" + name + ".jar";
- log.info("Download URL: " + url);
-
- File installDir = new File(pluginDir + "/install-plugin");
-
- if (!installDir.exists()) {
- installDir.mkdirs();
+ File pluginFolder = new File(pluginDir);
+ File[] plugins = pluginFolder.listFiles();
+ boolean found = false;
+ if (plugins != null) {
+ for (File plugin : plugins) {
+ if (plugin.getName().toLowerCase().contains(type)) {
+ log.info(
+ "The plugin "
+ + name
+ + " is already downloaded, but is not started. Starting plugin now.");
+ found = true;
+ startPlugin(plugin.getPath(), name);
+ break;
}
-
+ }
+ }
+ if (!found) {
+ log.info("Download URL: " + url);
+ String path = pluginDir + "/" + name + ".jar";
URL pluginURL = new URL(url);
FileOutputStream out = new FileOutputStream(path);
try {
@@ -110,9 +123,9 @@ public class PluginManager implements org.openbaton.nfvo.core.interfaces.PluginM
} finally {
out.flush();
}
-
startPlugin(path, name);
}
+ }
@Override
public void startPlugin(String path, String name) throws IOException {
