public void run() { if (deploymentID == null) { throw new NullPointerException("deploymentID cannot be null"); } final Deployment dep = deployments.get(deploymentID); if (dep == null) { throw new PlatformManagerException("There is no deployment with id " + deploymentID); } doUndeploy(dep, doneHandler); } }, wrapDoneHandler(doneHandler));
private JsonObject loadModuleConfig(File modJSON, ModuleIdentifier modID) { // Checked the byte code produced, .close() is called correctly, so the warning can be suppressed try (Scanner scanner = new Scanner(modJSON, "UTF-8").useDelimiter("\\A")) { String conf = scanner.next(); return new JsonObject(conf); } catch (FileNotFoundException e) { throw new PlatformManagerException("Module " + modID + " does not contain a mod.json file"); } catch (NoSuchElementException e) { throw new PlatformManagerException("Module " + modID + " contains an empty mod.json file"); } catch (DecodeException e) { throw new PlatformManagerException("Module " + modID + " mod.json contains invalid json"); } }
private JsonObject loadModJSONFromURL(ModuleIdentifier modID, URL url) { try { try (Scanner scanner = new Scanner(url.openStream(), "UTF-8").useDelimiter("\\A")) { String conf = scanner.next(); return new JsonObject(conf); } catch (NoSuchElementException e) { throw new PlatformManagerException("Module " + modID + " contains an empty mod.json file"); } catch (DecodeException e) { throw new PlatformManagerException("Module " + modID + " mod.json contains invalid json"); } } catch (IOException e) { return null; } }
private void zipDir(String zipFile, String dirToZip) { File dir = new File(dirToZip); try (ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFile))) { addDirToZip(dir, dir, out); } catch (Exception e) { throw new PlatformManagerException("Failed to unzip module", e); } }
private LanguageImplInfo parseLangImplInfo(String line) { // value is made up of an optional module name followed by colon followed by the // FQCN of the factory int colonIndex = line.lastIndexOf(COLON); String moduleName; String factoryName; if (colonIndex != -1) { moduleName = line.substring(0, colonIndex); factoryName = line.substring(colonIndex + 1); } else { throw new PlatformManagerException("Language mapping: " + line + " does not specify an implementing module"); } return new LanguageImplInfo(moduleName, factoryName); }
private List<URL> getModuleLibClasspath(File modDir) { List<URL> urls = new ArrayList<>(); // Add the classpath for this module try { if (modDir.exists()) { urls.add(modDir.toURI().toURL()); File libDir = new File(modDir, "lib"); if (libDir.exists()) { File[] jars = libDir.listFiles(); for (File jar: jars) { URL jarURL = jar.toURI().toURL(); urls.add(jarURL); } } } return urls; } catch (MalformedURLException e) { //Won't happen throw new PlatformManagerException(e); } }
private void doCreateModuleLink(File modRoot, ModuleIdentifier modID) { File cpFile = new File(CLASSPATH_FILE); if (!cpFile.exists()) { throw new PlatformManagerException("Must create a vertx_classpath.txt file first before creating a module link"); } File modDir = new File(modRoot, modID.toString()); if (modDir.exists()) { throw new PlatformManagerException("Module directory " + modDir + " already exists."); } if (!modDir.mkdirs()) { throw new PlatformManagerException("Failed to make directory " + modDir); } try { File currentDir = new File(".").getCanonicalFile(); vertx.fileSystem().writeFileSync(modDir.getPath() + "/" + MODULE_LINK_FILE, new Buffer(currentDir.getCanonicalPath() + "\n")); } catch (IOException e) { throw new PlatformManagerException(e); } }
private void checkCreateRoot(File modRoot) { if (!modRoot.exists()) { String smodRoot; try { smodRoot = modRoot.getCanonicalPath(); } catch (IOException e) { throw new PlatformManagerException(e); } vertx.fileSystem().mkdirSync(smodRoot, true); } }
static File unzipIntoTmpDir(ModuleZipInfo zipInfo, boolean deleteZip) { String tdir = generateTmpFileName(); File tdest = new File(tdir); if (!tdest.mkdir()) { throw new PlatformManagerException("Failed to create directory " + tdest); } unzipModuleData(tdest, zipInfo, deleteZip); return tdest; }
private void doInstallMod(final ModuleIdentifier modID) { checkWorkerContext(); if (repos.isEmpty()) { throw new PlatformManagerException("No repositories configured!"); } if (locateModule(modRoot, null, modID) != null) { throw new PlatformManagerException("Module is already installed"); } ModuleZipInfo info = getModule(modID); unzipModule(modID, info, true); }
private void deployModuleFromCP(String depName, ModuleIdentifier modID, JsonObject config, int instances, URL[] classpath, final Handler<AsyncResult<String>> doneHandler) { checkWorkerContext(); JsonObject modJSON = loadModJSONFromClasspath(modID, new URLClassLoader(classpath, platformClassLoader)); if (modJSON == null) { throw new PlatformManagerException("Failed to find mod.json on classpath"); } List<URL> cpList = new ArrayList<>(Arrays.asList(classpath)); deployModuleFromModJson(modJSON, depName, modID, config, instances, null, null, cpList, modRoot, false, doneHandler); }
if (entry.isDirectory()) { if (!entryFile.exists() && !entryFile.mkdirs()) { throw new PlatformManagerException("Failed to create directory"); throw new PlatformManagerException("Failed to create parent directory"); throw new PlatformManagerException("Failed to unzip module", e); } finally { if (deleteZip) {
File cpFile = new File(path, CLASSPATH_FILE); if (!cpFile.exists()) { throw new PlatformManagerException("Module link file: " + linkFile + " points to path without vertx_classpath.txt"); throw new PlatformManagerException(e); modJSON = loadModJSONFromURL(modID, url); } else { throw new PlatformManagerException("Cannot find mod.json"); throw new PlatformManagerException(e); throw new PlatformManagerException("Module directory " + modDir + " contains no mod.json nor module.link file");
public void run() { ModuleIdentifier modID = new ModuleIdentifier(moduleName); // Validates it File modDir = new File(modRoot, modID.toString()); if (!modDir.exists()) { throw new PlatformManagerException("Cannot find module to uninstall: " + moduleName); } else { vertx.fileSystem().deleteSync(modDir.getAbsolutePath(), true); } doneHandler.handle(new DefaultFutureResult<>((Void) null)); } }, wrapped);
throw new PlatformManagerException(e);
private void doPullInDependencies(File modRoot, ModuleIdentifier modID) { File modDir = new File(modRoot, modID.toString()); if (!modDir.exists()) { throw new PlatformManagerException("Cannot find module"); throw new PlatformManagerException("Module " + modID + " does not contain a mod.json"); if (!internalModsDir.exists()) { if (!internalModsDir.mkdir()) { throw new PlatformManagerException("Failed to create directory " + internalModsDir); if (zipInfo.filename != null) { if (!internalModDir.mkdir()) { throw new PlatformManagerException("Failed to create directory " + internalModDir);
@Override public void undeployModuleAs(final String deploymentID, final Handler<AsyncResult<Void>> doneHandler) { synchronized (haInfo) { // Undeploy the deployment. String internalID = internalIDs.getString(deploymentID); internalIDs.removeField(deploymentID); if (internalID != null) { container.undeployModule(internalID, doneHandler); deploymentIDs.removeField(internalID); } else { new DefaultFutureResult<Void>(new PlatformManagerException("Invalid deployment.")).setHandler(doneHandler); } // Remove the deployment from HA. Iterator<Object> iter = deployments.iterator(); while (iter.hasNext()) { JsonObject deploymentInfo = (JsonObject) iter.next(); if (deploymentInfo.getString("id").equals(deploymentID)) { iter.remove(); } } } clusterMap.put(node, haInfo.encode()); }
@Override public void undeployVerticleAs(final String deploymentID, final Handler<AsyncResult<Void>> doneHandler) { synchronized (haInfo) { // Undeploy the deployment. String internalID = internalIDs.getString(deploymentID); internalIDs.removeField(deploymentID); if (internalID != null) { container.undeployVerticle(internalID, doneHandler); deploymentIDs.removeField(internalID); } else { new DefaultFutureResult<Void>(new PlatformManagerException("Invalid deployment.")).setHandler(doneHandler); } // Remove the deployment from HA. Iterator<Object> iter = deployments.iterator(); while (iter.hasNext()) { JsonObject deploymentInfo = (JsonObject) iter.next(); if (deploymentInfo.getString("id").equals(deploymentID)) { iter.remove(); } } } clusterMap.put(node, haInfo.encode()); }
private ModuleZipInfo getModule(ModuleIdentifier modID) { String fileName = generateTmpFileName() + ".zip"; for (RepoResolver resolver: repos) { if (resolver.getModule(fileName, modID)) { return new ModuleZipInfo(resolver.isOldStyle(), fileName); } } throw new PlatformManagerException("Module " + modID + " not found in any repositories"); }
private void doMakeFatJar(File modRoot, ModuleIdentifier modID, String directory) { File modDir = new File(modRoot, modID.toString()); if (!modDir.exists()) { throw new PlatformManagerException("Cannot find module"); throw new PlatformManagerException(e);