public synchronized void uninstallModule(String moduleName) {
   log.info("Uninstalling module " + moduleName + " from directory " + modRoot);
   File modDir = new File(modRoot, moduleName);
   if (!modDir.exists()) {
     log.error("Cannot find module to uninstall");
   } else {
     try {
       vertx.fileSystem().deleteSync(modDir.getAbsolutePath(), true);
       log.info("Module " + moduleName + " successfully uninstalled");
     } catch (Exception e) {
       log.error("Failed to delete directory: " + e.getMessage());
     }
   }
 }
 /** Called when a node leaves the cluster. */
 private synchronized void doNodeLeft(final String nodeID) {
   log.info(String.format("%s - %s left the cluster", this, nodeID));
   context.run(
       new Runnable() {
         @Override
         public void run() {
           // Redeploy any failed deployments.
           synchronized (deployments) {
             Collection<String> sdeploymentsInfo = deployments.get(group);
             for (final String sdeploymentInfo : sdeploymentsInfo) {
               final JsonObject deploymentInfo = new JsonObject(sdeploymentInfo);
               // If the deployment node is equal to the node that left the cluster then
               // remove the deployment from the deployments list and attempt to redeploy it.
               if (deploymentInfo.getString("node").equals(nodeID)) {
                 // If the deployment is an HA deployment then attempt to redeploy it on this node.
                 if (deployments.remove(group, sdeploymentInfo)
                     && deploymentInfo.getBoolean("ha", false)) {
                   doRedeploy(deploymentInfo);
                 }
               }
             }
           }
         }
       });
 }
 public boolean pullInDependencies(String moduleName) {
   log.info("Attempting to pull in dependencies for module: " + moduleName);
   ModuleIdentifier modID = new ModuleIdentifier(moduleName);
   try {
     return doPullInDependencies(modRoot, modID);
   } catch (Exception e) {
     log.error("Failed to pull in dependencies", e);
     return false;
   }
 }
 /** Redeploys a deployment. */
 private void doRedeploy(final JsonObject deploymentInfo) {
   if (deploymentInfo.getString("type").equals("module")) {
     log.info(
         String.format(
             "%s - redeploying module %s",
             DefaultGroupManager.this, deploymentInfo.getString("module")));
     final CountDownLatch latch = new CountDownLatch(1);
     platform.deployModule(
         deploymentInfo.getString("module"),
         deploymentInfo.getObject("config", new JsonObject()),
         deploymentInfo.getInteger("instances", 1),
         createRedeployHandler(deploymentInfo, latch));
     try {
       latch.await(10, TimeUnit.SECONDS);
     } catch (InterruptedException e) {
     }
   } else if (deploymentInfo.getString("type").equals("verticle")) {
     log.info(
         String.format(
             "%s - redeploying verticle %s",
             DefaultGroupManager.this, deploymentInfo.getString("main")));
     final CountDownLatch latch = new CountDownLatch(1);
     if (deploymentInfo.getBoolean("worker", false)) {
       platform.deployWorkerVerticle(
           deploymentInfo.getString("main"),
           deploymentInfo.getObject("config", new JsonObject()),
           deploymentInfo.getInteger("instances", 1),
           deploymentInfo.getBoolean("multi-threaded"),
           createRedeployHandler(deploymentInfo, latch));
     } else {
       platform.deployVerticle(
           deploymentInfo.getString("main"),
           deploymentInfo.getObject("config", new JsonObject()),
           deploymentInfo.getInteger("instances", 1),
           createRedeployHandler(deploymentInfo, latch));
     }
     try {
       latch.await(10, TimeUnit.SECONDS);
     } catch (InterruptedException e) {
     }
   }
 }
 @Override
 public void handle(HttpServerRequest request) {
   request.response().setStatusCode(200);
   request.response().putHeader(WebStrings.CONTENT_TYPE, WebStrings.APP_JSON);
   log.info("Put Object Request");
   String reqId = UUID.randomUUID().toString();
   UploadEncObjectReplyHandler replyHandler = new UploadEncObjectReplyHandler(reqId, request);
   UploadEncObjectBodyHandler bodyHanlder = new UploadEncObjectBodyHandler(reqId, replyHandler);
   replyHandlers.put(reqId, replyHandler);
   bodyHandlers.put(reqId, bodyHanlder);
   request.bodyHandler(bodyHanlder);
 }
  private boolean unzipModule(
      final ModuleIdentifier modID, final ModuleZipInfo zipInfo, boolean deleteZip) {
    // We synchronize to prevent a race whereby it tries to unzip the same module at the
    // same time (e.g. deployModule for the same module name has been called in parallel)
    String modName = modID.toString();
    synchronized (modName.intern()) {
      if (!checkModDirs()) {
        return false;
      }

      File fdest = new File(modRoot, modName);
      File sdest = new File(systemModRoot, modName);
      if (fdest.exists() || sdest.exists()) {
        // This can happen if the same module is requested to be installed
        // at around the same time
        // It's ok if this happens
        log.warn("Module " + modID + " is already installed");
        return true;
      }

      // Unzip into temp dir first
      File tdest = unzipIntoTmpDir(zipInfo, deleteZip);
      if (tdest == null) {
        return false;
      }

      // Check if it's a system module
      JsonObject conf = loadModuleConfig(modID, tdest);
      ModuleFields fields = new ModuleFields(conf);

      boolean system = fields.isSystem();

      // Now copy it to the proper directory
      String moveFrom = tdest.getAbsolutePath();
      try {
        vertx
            .fileSystem()
            .moveSync(moveFrom, system ? sdest.getAbsolutePath() : fdest.getAbsolutePath());
      } catch (Exception e) {
        log.error("Failed to move module", e);
        return false;
      }

      log.info("Module " + modID + " successfully installed");
      return true;
    }
  }
 private boolean doPullInDependencies(File modRoot, ModuleIdentifier modID) {
   File modDir = new File(modRoot, modID.toString());
   if (!modDir.exists()) {
     log.error("Cannot find module to uninstall");
   }
   JsonObject conf = loadModuleConfig(modID, modDir);
   if (conf == null) {
     log.error("Module " + modID + " does not contain a mod.json");
   }
   ModuleFields fields = new ModuleFields(conf);
   List<String> mods = new ArrayList<>();
   String includes = fields.getIncludes();
   if (includes != null) {
     mods.addAll(Arrays.asList(parseIncludeString(includes)));
   }
   String deploys = fields.getDeploys();
   if (deploys != null) {
     mods.addAll(Arrays.asList(parseIncludeString(deploys)));
   }
   if (!mods.isEmpty()) {
     File internalModsDir = new File(modDir, "mods");
     if (!internalModsDir.exists()) {
       internalModsDir.mkdir();
     }
     for (String modName : mods) {
       File internalModDir = new File(internalModsDir, modName);
       if (!internalModDir.exists()) {
         ModuleIdentifier theModID = new ModuleIdentifier(modName);
         ModuleZipInfo zipInfo = getModule(theModID);
         if (zipInfo.filename != null) {
           internalModDir.mkdir();
           if (!unzipModuleData(internalModDir, zipInfo, true)) {
             return false;
           } else {
             log.info("Module " + modName + " successfully installed in mods dir of " + modName);
             // Now recurse so we bring in all of the deps
             doPullInDependencies(internalModsDir, theModID);
           }
         }
       }
     }
   }
   return true;
 }
 /** Called when a node joins the cluster. */
 private void doNodeJoined(final String nodeID) {
   log.info(String.format("%s - %s joined the cluster", this, nodeID));
 }