public void testZipWithDeploymentScriptAndClassesCanBeDeployed()
      throws FileSystemException, MalformedURLException, ClassNotFoundException,
          IllegalAccessException, NoSuchMethodException, InvocationTargetException,
          InstantiationException {
    DefaultFileSystemManager manager = new DefaultFileSystemManager();
    FileObject applicationFolder = getApplicationArchive(manager);

    Deployer deployer = new NanoContainerDeployer(manager);
    ObjectReference containerRef =
        deployer.deploy(applicationFolder, getClass().getClassLoader(), null);
    PicoContainer pico = (PicoContainer) containerRef.get();
    Object zap = pico.getComponentInstance("zap");
    assertEquals("Groovy Started", zap.toString());
  }
 /**
  * Tests invalid deployment of multiple roots within a WAR Should be started first--arquillian
  * deployments are not perfectly isolated.
  */
 @Test
 @InSequence(-2)
 public void uiPathCollisionBreaksDeployment() throws MalformedURLException {
   assertThat(RootUI.getNumberOfInstances(), is(0));
   deployer.deploy("uiPathCollision");
   openWindowNoWait(deriveMappingForUI(PathCollisionUI.class));
   final String expectedErrorMessage = this.firstWindow.getBodyText();
   assertThat(
       expectedErrorMessage, containsString("VaadinCDIServlet deployment aborted. Reason:"));
   assertThat(RootUI.getNumberOfInstances(), is(0));
 }
 /**
  * Tests invalid deployment of multiple roots within a WAR Should be before the regular
  * tests--arquillian deployments are not perfectly isolated.
  */
 @Test
 @InSequence(-1)
 public void multipleRootsBreakDeployment() throws MalformedURLException {
   assertThat(RootUI.getNumberOfInstances(), is(0));
   deployer.deploy("multipleRoots");
   openWindowNoWait("");
   final String expectedErrorMessage = this.firstWindow.getBodyText();
   assertThat(
       expectedErrorMessage, containsString("VaadinCDIServlet deployment aborted. Reason:"));
   assertThat(RootUI.getNumberOfInstances(), is(0));
 }
Пример #4
0
 private void deployAndLaunch() {
   try {
     LogUtils.i("Kill existing manager process");
     LogUtils.i("try to kill manager process before launch");
     ManagerProcess.kill();
   } catch (Exception e) {
     LogUtils.e("failed to kill manager process before launch", e);
     LogUtils.i("failed to kill manager process before launch");
   }
   Deployer deployer = new Deployer(this);
   String fatalError = deployer.deploy();
   if (!fatalError.isEmpty()) {
     handleFatalError(fatalError);
     return;
   }
   updateConfigFile(this);
   LogUtils.i("Launching...");
   if (ShellUtils.checkRooted()) {
     fatalError = launch(false);
     if (fatalError.isEmpty()) {
       sendBroadcast(new LaunchedIntent(false));
     } else {
       handleFatalError(fatalError);
     }
   } else {
     if (Build.VERSION.SDK_INT < 14) {
       handleFatalError("[ROOT] is required");
       return;
     }
     fatalError = launch(true);
     if (fatalError.isEmpty()) {
       sendBroadcast(new LaunchedIntent(true));
     } else {
       handleFatalError(fatalError);
     }
   }
 }
  public void createCluster() {
    if (log.isDebugEnabled()) {
      log.debug(
          "Installing embedded "
              + deploymentOptions.getNumNodes()
              + " node cluster to "
              + deploymentOptions.getClusterDir());
    } else {
      log.info("Installing embedded cluster");
    }

    File clusterDir = new File(deploymentOptions.getClusterDir());
    File installedMarker = new File(clusterDir, ".installed");

    if (installedMarker.exists()) {
      log.info("It appears that the cluster already exists in " + clusterDir);
      log.info("Skipping cluster creation.");
      getStorageClusterConfiguration();
    }
    FileUtil.purge(clusterDir, false);

    String seeds = collectionToString(calculateLocalIPAddresses(deploymentOptions.getNumNodes()));

    this.nodes = new String[deploymentOptions.getNumNodes()];
    this.jmxPorts = new int[deploymentOptions.getNumNodes()];
    this.cqlPort = deploymentOptions.getCqlPort();

    boolean useRemoteJMX = this.nodes.length > 1;

    for (int i = 0; i < deploymentOptions.getNumNodes(); ++i) {
      File basedir = new File(deploymentOptions.getClusterDir(), "node" + i);
      String address = getLocalIPAddress(i + 1);

      DeploymentOptionsFactory factory = new DeploymentOptionsFactory();
      DeploymentOptions nodeOptions = factory.newDeploymentOptions();
      nodeOptions.setSeeds(seeds);
      nodeOptions.setJmxPort(deploymentOptions.getJmxPort() + i);
      nodeOptions.setBasedir(basedir.getAbsolutePath());
      nodeOptions.setListenAddress(address);
      nodeOptions.setRpcAddress(address);
      nodeOptions.setCommitLogDir(new File(basedir, "commit_log").getAbsolutePath());
      nodeOptions.setDataDir(new File(basedir, "data").getAbsolutePath());
      nodeOptions.setSavedCachesDir(new File(basedir, "saved_caches").getAbsolutePath());

      nodeOptions.merge(deploymentOptions);
      try {
        nodeOptions.load();
        Deployer deployer = new Deployer();
        deployer.setDeploymentOptions(nodeOptions);

        deployer.unzipDistro();
        deployer.applyConfigChanges();
        deployer.updateFilePerms();
        deployer.updateStorageAuthConf(calculateLocalIPAddresses(deploymentOptions.getNumNodes()));

        if (useRemoteJMX) {
          File confDir = new File(nodeOptions.getBasedir(), "conf");
          File cassandraJvmPropsFile = new File(confDir, "cassandra-jvm.properties");
          PropertiesFileUpdate propertiesUpdater =
              new PropertiesFileUpdate(cassandraJvmPropsFile.getAbsolutePath());
          Properties properties = propertiesUpdater.loadExistingProperties();
          String jmxOpts =
              "\"-Djava.rmi.server.hostname="
                  + nodeOptions.getRpcAddress()
                  + " -Dcom.sun.management.jmxremote.port="
                  + nodeOptions.getJmxPort()
                  + " -Dcom.sun.management.jmxremote.rmi.port="
                  + nodeOptions.getJmxPort()
                  + " -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false \"";

          properties.setProperty("JMX_OPTS", jmxOpts);

          propertiesUpdater.update(properties);
        }

        this.nodes[i] = address;
        this.jmxPorts[i] = deploymentOptions.getJmxPort() + i;

        installedNodeDirs.add(basedir);
      } catch (Exception e) {
        log.error("Failed to install node at " + basedir);
        throw new RuntimeException("Failed to install node at " + basedir, e);
      }
    }
    try {
      FileUtil.writeFile(new ByteArrayInputStream(new byte[] {0}), installedMarker);
    } catch (IOException e) {
      log.warn("Failed to write installed file marker to " + installedMarker, e);
    }
  }
Пример #6
0
 public void deploy(DeploymentEntity deployment, Map<String, Object> deploymentSettings) {
   for (Deployer deployer : deployers) {
     deployer.deploy(deployment, deploymentSettings);
   }
 }
 public void deploy(DeploymentEntity deployment) {
   for (Deployer deployer : deployers) {
     deployer.deploy(deployment);
   }
 }
Пример #8
0
  private MineCloudDaemon(Properties properties) {
    redis = MineCloud.instance().redis();
    mongo = MineCloud.instance().mongo();
    dockerClient = new DefaultDockerClient("unix:///var/run/docker.sock");

    node = (String) properties.get("node-name");
    instance = this;

    redis.addChannel(
        SimpleRedisChannel.create("server-create", redis)
            .addCallback(
                (message) -> {
                  if (message.type() != MessageType.BINARY) {
                    return;
                  }

                  MessageInputStream stream = message.contents();

                  if (!stream.readString().equalsIgnoreCase(node)) {
                    return;
                  }

                  Network network =
                      mongo.repositoryBy(Network.class).findFirst(stream.readString());
                  ServerType type =
                      mongo.repositoryBy(ServerType.class).findFirst(stream.readString());
                  List<ServerMetadata> metadata = new ArrayList<>();
                  int size = stream.readVarInt32();

                  for (int i = 0; i < size; i++) {
                    metadata.add(new ServerMetadata(stream.readString(), stream.readString()));
                  }

                  Deployer.deployServer(network, type, metadata);
                }));

    redis.addChannel(
        SimpleRedisChannel.create("server-kill", redis)
            .addCallback(
                (message) -> {
                  if (message.type() != MessageType.BINARY) {
                    return;
                  }

                  MessageInputStream stream = message.contents();

                  if (!stream.readString().equalsIgnoreCase(node)) return;

                  Server server = mongo.repositoryBy(Server.class).findFirst(stream.readString());

                  if (!server.node().name().equals(node)) {
                    MineCloud.logger()
                        .log(
                            Level.SEVERE,
                            "Invalid request was sent to kill a server "
                                + "not on the current node");
                    return;
                  }

                  try {
                    dockerClient.killContainer(server.containerId());
                    MineCloud.logger()
                        .info(
                            "Killed server "
                                + server.name()
                                + " with container id "
                                + server.containerId());

                    mongo.repositoryBy(Server.class).delete(server);
                  } catch (DockerException | InterruptedException e) {
                    MineCloud.logger().log(Level.SEVERE, "Was unable to kill a server", e);
                  }
                }));

    redis.addChannel(
        SimpleRedisChannel.create("bungee-create", redis)
            .addCallback(
                (message) -> {
                  if (message.type() != MessageType.BINARY) {
                    return;
                  }

                  MessageInputStream stream = message.contents();

                  if (!stream.readString().equalsIgnoreCase(node)) return;

                  Network network =
                      mongo.repositoryBy(Network.class).findFirst(stream.readString());
                  BungeeType type =
                      mongo.repositoryBy(BungeeType.class).findFirst(stream.readString());

                  Deployer.deployBungee(network, type);
                }));

    redis.addChannel(
        SimpleRedisChannel.create("bungee-kill", redis)
            .addCallback(
                (message) -> {
                  if (message.type() != MessageType.BINARY) {
                    return;
                  }

                  MessageInputStream stream = message.contents();

                  if (!stream.readString().equalsIgnoreCase(node)) return;

                  Bungee bungee = mongo.repositoryBy(Bungee.class).findFirst(stream.readString());

                  if (!bungee.node().name().equals(node)) {
                    MineCloud.logger()
                        .log(
                            Level.SEVERE,
                            "Invalid request was sent to kill a bungee "
                                + "not on the current node");
                    return;
                  }

                  try {
                    dockerClient.killContainer(bungee.containerId());
                    MineCloud.logger()
                        .info(
                            "Killed bungee "
                                + bungee.name()
                                + " with container id "
                                + bungee.containerId());

                    mongo.repositoryBy(Bungee.class).delete(bungee);
                  } catch (DockerException | InterruptedException e) {
                    MineCloud.logger().log(Level.SEVERE, "Was unable to kill a server", e);
                  }
                }));

    redis.addChannel(
        SimpleRedisChannel.create("server-start-notif", redis)
            .addCallback(
                (message) -> {
                  if (message.type() != MessageType.BINARY) return;

                  MessageInputStream stream = message.contents();

                  Server server = mongo.repositoryBy(Server.class).findFirst(stream.readString());

                  if (!server.node().name().equals(node)) return;

                  if (server.port() != -1) return; // don't even know how this would happen

                  try {
                    ContainerInfo info = dockerClient.inspectContainer(server.containerId());

                    info.networkSettings()
                        .ports()
                        .forEach(
                            (s, l) -> {
                              if (!s.contains("25565")) return;

                              server.setPort(Integer.parseInt(l.get(0).hostPort()));
                              MineCloud.logger()
                                  .log(
                                      Level.INFO,
                                      "Set " + server.name() + "'s port to " + server.port());
                            });

                    mongo.repositoryBy(Server.class).save(server);
                  } catch (Exception e) {
                    MineCloud.logger()
                        .log(Level.SEVERE, "Was unable to set the port of a started server", e);
                  }
                }));

    redis.addChannel(SimpleRedisChannel.create("server-shutdown-notif", redis));

    new StatisticsWatcher().start();

    while (!Thread.currentThread().isInterrupted()) {
      try {
        dockerClient
            .listContainers(DockerClient.ListContainersParam.allContainers())
            .stream()
            .filter(
                (container) ->
                    !container.status().toLowerCase().contains("up")
                        && ((System.currentTimeMillis() / 1000L) - container.created()) > 5L)
            .forEach(
                (container) -> {
                  try {
                    String name =
                        container.names() == null || container.names().isEmpty()
                            ? "null"
                            : container.names().get(0);
                    dockerClient.removeContainer(container.id());

                    if (container.image().contains("minecloud")) {
                      String type = container.image().substring(9);

                      switch (type.toLowerCase()) {
                        case "bungee":
                          AbstractMongoRepository<Bungee> repository =
                              mongo.repositoryBy(Bungee.class);
                          Query<Bungee> query =
                              repository.createQuery().field("_id").equal(node().publicIp());
                          repository.deleteByQuery(query);
                          break;

                        case "server":
                          Server server =
                              mongo
                                  .repositoryBy(Server.class)
                                  .findOne("containerId", container.names().get(0));

                          if (server != null) {
                            mongo.repositoryBy(Server.class).delete(server);
                          }
                          break;
                      }
                    }

                    MineCloud.logger()
                        .info("Killed dead container " + container.id() + " (" + name + ")");
                  } catch (DockerException | InterruptedException e) {
                    MineCloud.logger()
                        .log(
                            Level.SEVERE,
                            "Was unable to kill exited container " + container.id(),
                            e);
                  }
                });
        ServerRepository repository = mongo.repositoryBy(Server.class);
        Query<Server> query =
            repository
                .createQuery()
                .field("node")
                .equal(node())
                .field("port")
                .notEqual(-1)
                .field("tps")
                .notEqual(-1);

        repository
            .find(query)
            .asList()
            .forEach(
                (server) -> {
                  boolean exists;

                  try {
                    dockerClient.inspectContainer(server.containerId());
                    exists = true;
                  } catch (DockerException | InterruptedException ex) {
                    exists = false;
                  }

                  if (exists) {
                    return;
                  }

                  repository.delete(server);
                  MineCloud.logger()
                      .info(
                          "Removed "
                              + server.containerId()
                              + " from DB due to not existing as a container");
                });
      } catch (DockerException | InterruptedException e) {
        MineCloud.logger().log(Level.SEVERE, "Was unable to list containers for update", e);
      }

      try {
        Thread.sleep(2000L);
      } catch (InterruptedException ignored) {
        // I don't care
      }
    }
  }