Exemplo n.º 1
0
  @Override
  public Response getAvailableNodes(final String clusterName) {
    Set<String> hostsName = Sets.newHashSet();

    HiveConfig hiveConfig = hiveManager.getCluster(clusterName);
    HadoopClusterConfig hadoopConfig = hadoopManager.getCluster(hiveConfig.getHadoopClusterName());

    Set<String> nodes = new HashSet<>(hadoopConfig.getAllNodes());
    nodes.removeAll(hiveConfig.getAllNodes());
    if (!nodes.isEmpty()) {
      Set<EnvironmentContainerHost> hosts;
      try {
        hosts =
            environmentManager
                .loadEnvironment(hadoopConfig.getEnvironmentId())
                .getContainerHostsByIds(nodes);

        for (final EnvironmentContainerHost host : hosts) {
          hostsName.add(host.getHostname());
        }
      } catch (ContainerHostNotFoundException | EnvironmentNotFoundException e) {
        e.printStackTrace();
      }
    } else {
      LOG.info("All nodes in corresponding Hadoop cluster have Nutch installed");
      //            return Response.status( Response.Status.NOT_FOUND ).build();
    }

    String hosts = JsonUtil.GSON.toJson(hostsName);
    return Response.status(Response.Status.OK).entity(hosts).build();
  }
  @Override
  public void destroyCluster() {
    LuceneConfig config = manager.getCluster(clusterName);
    if (config == null) {
      trackerOperation.addLogFailed(
          String.format("Cluster with name %s does not exist. Operation aborted", clusterName));
      return;
    }

    TrackerOperation po = trackerOperation;
    po.addLog("Uninstalling Lucene...");

    Set<EnvironmentContainerHost> nodes;
    try {
      nodes =
          manager
              .getEnvironmentManager()
              .loadEnvironment(config.getEnvironmentId())
              .getContainerHostsByIds(config.getNodes());
    } catch (ContainerHostNotFoundException e) {
      trackerOperation.addLogFailed(
          String.format("Failed obtaining environment containers: %s", e));
      return;
    } catch (EnvironmentNotFoundException e) {
      trackerOperation.addLogFailed(String.format("Environment not found: %s", e));
      return;
    }
    for (EnvironmentContainerHost containerHost : nodes) {
      CommandResult result;
      try {
        result = containerHost.execute(new RequestBuilder(Commands.uninstallCommand));
        if (!result.hasSucceeded()) {
          po.addLog(result.getStdErr());
          po.addLogFailed("Uninstallation failed");
          return;
        }
      } catch (CommandException e) {
        LOG.error(e.getMessage(), e);
      }
    }
    po.addLog("Updating db...");
    manager.getPluginDao().deleteInfo(LuceneConfig.PRODUCT_KEY, config.getClusterName());
    po.addLogDone("Cluster info deleted from DB\nDone");
  }
Exemplo n.º 3
0
  @Test
  public void testSetup() throws Exception {
    when(solrClusterConfig.getClusterName()).thenReturn("test");
    when(solrClusterConfig.getNumberOfNodes()).thenReturn(1);
    Set<EnvironmentContainerHost> mySet = new HashSet<>();
    mySet.add(containerHost);
    mySet.add(containerHost);
    when(environment.getContainerHosts()).thenReturn(mySet);
    when(containerHost.getTemplateName()).thenReturn(SolrClusterConfig.TEMPLATE_NAME);
    when(containerHost.getId()).thenReturn(UUID.randomUUID().toString());
    when(solrImpl.getPluginDAO()).thenReturn(pluginDAO);

    solrSetupStrategy.setup();

    // assertions
    verify(trackerOperation).addLog("Saving cluster information to database...");
    assertNotNull(solrImpl.getPluginDAO());
    verify(trackerOperation).addLog("Cluster information saved to database");
  }
  @Before
  public void setUp() throws Exception {
    id = UUID.randomUUID().toString();
    mySet = new HashSet<>();
    mySet.add(containerHost);

    myUUID = new HashSet<>();
    myUUID.add(id);

    // mock constructor
    when(stormImpl.getCluster("testClusterName")).thenReturn(stormClusterConfiguration);
    when(stormImpl.getTracker()).thenReturn(tracker);
    when(tracker.createTrackerOperation(anyString(), anyString())).thenReturn(trackerOperation);
    when(trackerOperation.getId()).thenReturn(UUID.randomUUID());

    stormNodeOperationHandler =
        new StormNodeOperationHandler(
            stormImpl, "testClusterName", "testHostName", NodeOperationType.START);
    stormNodeOperationHandler2 =
        new StormNodeOperationHandler(
            stormImpl, "testClusterName", "testHostName", NodeOperationType.STOP);
    stormNodeOperationHandler3 =
        new StormNodeOperationHandler(
            stormImpl, "testClusterName", "testHostName", NodeOperationType.STATUS);
    stormNodeOperationHandler4 =
        new StormNodeOperationHandler(
            stormImpl, "testClusterName", "testHostName", NodeOperationType.DESTROY);

    // mock run method
    when(stormImpl.getCluster(anyString())).thenReturn(stormClusterConfiguration);
    when(stormImpl.getEnvironmentManager()).thenReturn(environmentManager);
    when(environmentManager.loadEnvironment(any(String.class))).thenReturn(environment);
    when(stormClusterConfiguration.getEnvironmentId()).thenReturn(id);
    //        when( stormImpl.getZookeeperManager() ).thenReturn( zookeeper );
    //        when( zookeeper.getCluster( anyString() ) ).thenReturn( zookeeperClusterConfig );
    when(stormClusterConfiguration.getNimbus()).thenReturn(id);
    when(containerHost.getId()).thenReturn(id);
    when(containerHost.execute(any(RequestBuilder.class))).thenReturn(commandResult);
    //        when( zookeeper.getCommand( any( CommandType.class ) ) ).thenReturn( "testCommand" );
  }